1 /**
2  * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3  *
4  *  SPDX-License-Identifier: Apache-2.0
5  */
6 #pragma once
7 
8 #include <stdint.h>
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /** Group: Memory */
14 
15 /** Group: Control / Configuration Registers */
16 /** Type of m_prime register
17  *  Represents M'
18  */
19 typedef union {
20     struct {
21         /** m_prime : R/W; bitpos: [31:0]; default: 0;
22          *  Represents M'
23          */
24         uint32_t m_prime:32;
25     };
26     uint32_t val;
27 } rsa_m_prime_reg_t;
28 
29 /** Type of mode register
30  *  Configures RSA length
31  */
32 typedef union {
33     struct {
34         /** mode : R/W; bitpos: [6:0]; default: 0;
35          *  Configures the RSA length.
36          */
37         uint32_t mode:7;
38         uint32_t reserved_7:25;
39     };
40     uint32_t val;
41 } rsa_mode_reg_t;
42 
43 /** Type of set_start_modexp register
44  *  Starts modular exponentiation
45  */
46 typedef union {
47     struct {
48         /** set_start_modexp : WT; bitpos: [0]; default: 0;
49          *  Configure whether or not to start the modular exponentiation.
50          *
51          *  0: No effect
52          *
53          *  1: Start
54          *
55          */
56         uint32_t set_start_modexp:1;
57         uint32_t reserved_1:31;
58     };
59     uint32_t val;
60 } rsa_set_start_modexp_reg_t;
61 
62 /** Type of set_start_modmult register
63  *  Starts modular multiplication
64  */
65 typedef union {
66     struct {
67         /** set_start_modmult : WT; bitpos: [0]; default: 0;
68          *  Configure whether or not to start the modular multiplication.
69          *
70          *  0: No effect
71          *
72          *  1: Start
73          *
74          */
75         uint32_t set_start_modmult:1;
76         uint32_t reserved_1:31;
77     };
78     uint32_t val;
79 } rsa_set_start_modmult_reg_t;
80 
81 /** Type of set_start_mult register
82  *  Starts multiplication
83  */
84 typedef union {
85     struct {
86         /** set_start_mult : WT; bitpos: [0]; default: 0;
87          *  Configure whether or not to start the multiplication.
88          *
89          *  0: No effect
90          *
91          *  1: Start
92          *
93          */
94         uint32_t set_start_mult:1;
95         uint32_t reserved_1:31;
96     };
97     uint32_t val;
98 } rsa_set_start_mult_reg_t;
99 
100 /** Type of query_idle register
101  *  Represents the RSA status
102  */
103 typedef union {
104     struct {
105         /** query_idle : RO; bitpos: [0]; default: 0;
106          *  Represents the RSA status.
107          *
108          *  0: Busy
109          *
110          *  1: Idle
111          *
112          */
113         uint32_t query_idle:1;
114         uint32_t reserved_1:31;
115     };
116     uint32_t val;
117 } rsa_query_idle_reg_t;
118 
119 /** Type of constant_time register
120  *  Configures the constant_time option
121  */
122 typedef union {
123     struct {
124         /** constant_time : R/W; bitpos: [0]; default: 1;
125          *  Configures the constant_time option.
126          *
127          *  0: Acceleration
128          *
129          *  1: No acceleration (default)
130          *
131          */
132         uint32_t constant_time:1;
133         uint32_t reserved_1:31;
134     };
135     uint32_t val;
136 } rsa_constant_time_reg_t;
137 
138 /** Type of search_enable register
139  *  Configures the search option
140  */
141 typedef union {
142     struct {
143         /** search_enable : R/W; bitpos: [0]; default: 0;
144          *  Configure the search option.
145          *
146          *  0: No acceleration (default)
147          *
148          *  1: Acceleration
149          *
150          *  This option should be used together with RSA_SEARCH_POS.
151          */
152         uint32_t search_enable:1;
153         uint32_t reserved_1:31;
154     };
155     uint32_t val;
156 } rsa_search_enable_reg_t;
157 
158 /** Type of search_pos register
159  *  Configures the search position
160  */
161 typedef union {
162     struct {
163         /** search_pos : R/W; bitpos: [11:0]; default: 0;
164          *  Configures the starting address to start search. This field should be used together
165          *  with RSA_SEARCH_ENABLE. The field is only valid when RSA_SEARCH_ENABLE is high.
166          */
167         uint32_t search_pos:12;
168         uint32_t reserved_12:20;
169     };
170     uint32_t val;
171 } rsa_search_pos_reg_t;
172 
173 
174 /** Group: Status Register */
175 /** Type of query_clean register
176  *  RSA clean register
177  */
178 typedef union {
179     struct {
180         /** query_clean : RO; bitpos: [0]; default: 0;
181          *  Represents whether or not the RSA memory completes initialization.
182          *
183          *  0: Not complete
184          *
185          *  1: Completed
186          *
187          */
188         uint32_t query_clean:1;
189         uint32_t reserved_1:31;
190     };
191     uint32_t val;
192 } rsa_query_clean_reg_t;
193 
194 
195 /** Group: Interrupt Registers */
196 /** Type of int_clr register
197  *  Clears RSA interrupt
198  */
199 typedef union {
200     struct {
201         /** clear_interrupt : WT; bitpos: [0]; default: 0;
202          *  Write 1 to clear the RSA interrupt.
203          */
204         uint32_t clear_interrupt:1;
205         uint32_t reserved_1:31;
206     };
207     uint32_t val;
208 } rsa_int_clr_reg_t;
209 
210 /** Type of int_ena register
211  *  Enables the RSA interrupt
212  */
213 typedef union {
214     struct {
215         /** int_ena : R/W; bitpos: [0]; default: 0;
216          *  Write 1 to enable the RSA interrupt.
217          */
218         uint32_t int_ena:1;
219         uint32_t reserved_1:31;
220     };
221     uint32_t val;
222 } rsa_int_ena_reg_t;
223 
224 
225 /** Group: Version Control Register */
226 /** Type of date register
227  *  Version control register
228  */
229 typedef union {
230     struct {
231         /** date : R/W; bitpos: [29:0]; default: 538969624;
232          *  Version control register.
233          */
234         uint32_t date:30;
235         uint32_t reserved_30:2;
236     };
237     uint32_t val;
238 } rsa_date_reg_t;
239 
240 
241 typedef struct rsa_dev_t {
242     volatile uint32_t m[4];
243     uint32_t reserved_010[124];
244     volatile uint32_t z[4];
245     uint32_t reserved_210[124];
246     volatile uint32_t y[4];
247     uint32_t reserved_410[124];
248     volatile uint32_t x[4];
249     uint32_t reserved_610[124];
250     volatile rsa_m_prime_reg_t m_prime;
251     volatile rsa_mode_reg_t mode;
252     volatile rsa_query_clean_reg_t query_clean;
253     volatile rsa_set_start_modexp_reg_t set_start_modexp;
254     volatile rsa_set_start_modmult_reg_t set_start_modmult;
255     volatile rsa_set_start_mult_reg_t set_start_mult;
256     volatile rsa_query_idle_reg_t query_idle;
257     volatile rsa_int_clr_reg_t int_clr;
258     volatile rsa_constant_time_reg_t constant_time;
259     volatile rsa_search_enable_reg_t search_enable;
260     volatile rsa_search_pos_reg_t search_pos;
261     volatile rsa_int_ena_reg_t int_ena;
262     volatile rsa_date_reg_t date;
263 } rsa_dev_t;
264 
265 extern rsa_dev_t RSA;
266 
267 #ifndef __cplusplus
268 _Static_assert(sizeof(rsa_dev_t) == 0x834, "Invalid size of rsa_dev_t structure");
269 #endif
270 
271 #ifdef __cplusplus
272 }
273 #endif
274