InPlay API
hal_efuse.h
1 
13 #ifndef HAL_EFUSE_H
14 #define HAL_EFUSE_H
15 
25 #include <stdint.h>
26 #include "in_mmap.h"
27 
28 /*
29  ****************************************************************************************
30  * Efuse Define Structures
31  ****************************************************************************************
32  */
33 
34 typedef union {
35  struct {
36  uint32_t efuse_lock:1;
37  uint32_t flash_present:1;
38  uint32_t pn_0:1;
39  uint32_t pn_1:1;
40  uint32_t pn_2:1;
41  uint32_t pn_3:1;
42  uint32_t sec_key_sel:4;
43  uint32_t sec_key_alg:3;
44  uint32_t qspi_0_pin_mux:3;
45  uint32_t qspi_2_pin_mux:3;
46  uint32_t qspi_3_pin_mux:3;
47  uint32_t qspi_4_pin_mux:3;
48  uint32_t qspi_5_pin_mux:3;
49  uint32_t reserved:1;
50  uint32_t qspi_tvs:3;
51  } u;
52  uint32_t w0;
53 } efuse_w0_t;
54 
55 typedef union {
56  struct {
57  uint32_t dbv:5;
58  uint32_t dbv_present:1;
59  uint32_t drf:4;
60  uint32_t drf_present:1;
61  uint32_t tx_cal:12;
62  uint32_t tx_cal_present:1;
63  uint32_t bod:7;
64  uint32_t bod_present:1;
65  } u;
66  uint32_t w3; // word 3
67 } efuse_w3_t;
68 
69 typedef union {
70  struct {
71  uint32_t pn_4:1;
72  uint32_t pn_5:1;
73  uint32_t sw_0:1;
74  uint32_t sw_1:1;
75  uint32_t sw_2:1;
76  uint32_t sw_3:1;
77  uint32_t sw_4:1;
78  uint32_t sw_5:1;
79  uint32_t reserved:8;
80  uint32_t vtemp_offset:16;
81  } u;
82  uint32_t w4;
83 } efuse_w4_t;
84 
85 typedef union {
86  struct {
87  uint32_t vbat_v0:16;
88  uint32_t vbat_v1:16;
89  } u;
90  uint32_t w5; // word 5
91 } efuse_w5_t;
92 
93 typedef union {
94  struct {
95  uint32_t adc_v0:16;
96  uint32_t adc_v1:16;
97  } u;
98  uint32_t w6; // word 6
99 } efuse_w6_t;
100 
101 typedef union {
102  struct {
103  uint32_t efuse_lock:1;
104  uint32_t dbg_disable:1;
105  uint32_t flash_encrypt:1;
106  uint32_t flash_secure_boot:1;
107  uint32_t ecc_length:1;
108  uint32_t dft_if_en:1;
109  uint32_t dft_if:3;
110  uint32_t ram_secure_boot:1;
111  uint32_t host_auth:1;
112  uint32_t spi_init_speed:2;
113  uint32_t secure_boot_w_uuid:1;
114  uint32_t xo_dly:2;
115  uint32_t cpll_en:1;
116  uint32_t aon_wdt_dis:1;
117  uint32_t aon_wdt_win:1;
118  uint32_t aon_wdt_rst:2;
119  uint32_t bod_en:1;
120  uint32_t bod_thrd:3;
121  uint32_t bod_sel:1;
122  uint32_t bod_reset:1;
123  uint32_t flash_exception:2;
124  uint32_t reset_option:1;
125  } u;
126  uint32_t word;
127  uint32_t w7;
128 } efuse_w7_t;
129 
130 /*
131  ****************************************************************************************
132  * Enum
133  ****************************************************************************************
134  */
135 
137 typedef enum {
147 
148 
149 /*
150  ****************************************************************************************
151  * Inline Functions
152  ****************************************************************************************
153  */
154 
155 static __inline int efuse_intr_read_done(void)
156 {
157  return ((RD_WORD(EFUSECTRL_REG_INTR_STATUS) & EFUSECTRL_REG_INTR_STATUS_READ_DONE) ? 1: 0);
158 }
159 
160 static __inline int efuse_intr_prog_done(void)
161 {
162  return ((RD_WORD(EFUSECTRL_REG_INTR_STATUS) & EFUSECTRL_REG_INTR_STATUS_PROG_DONE) ? 1 : 0);
163 }
164 
165 static __inline void efuse_intr_read_done_clr(void)
166 {
167  WR_WORD(EFUSECTRL_REG_INTR_CLR, EFUSECTRL_REG_INTR_CLR_READ_DONE);
168 }
169 
170 static __inline void efuse_intr_prog_done_clr(void)
171 {
172  WR_WORD(EFUSECTRL_REG_INTR_CLR, EFUSECTRL_REG_INTR_CLR_PROG_DONE);
173 }
174 
175 static __inline void efuse_enable(void)
176 {
177  WR_WORD(EFUSECTRL_REG_MISC_CTRL, EFUSECTRL_REG_MISC_CTRL_CTL_EFUSE_EN);
178 }
179 
180 static __inline void efuse_disable(void)
181 {
182  WR_WORD(EFUSECTRL_REG_MISC_CTRL, 0);
183 }
184 
185 static __inline void efuse_prog_enable(void)
186 {
187  WR_WORD(EFUSECTRL_REG_MISC_CTRL, EFUSECTRL_REG_MISC_CTRL_CTL_EFUSE_EN | EFUSECTRL_REG_MISC_CTRL_CTL_EFUSE_PROG_EN);
188 }
189 
190 static __inline void efuse_prog_disable(void)
191 {
192  WR_WORD(EFUSECTRL_REG_MISC_CTRL, 0);
193 }
194 
195 static __inline void efuse_prog_bit_start(uint32_t bit_adr)
196 {
197  WR_WORD(EFUSECTRL_REG_PROG_CTRL,
198  (EFUSECTRL_REG_PROG_CTRL_CTL_EFUSE_PROG_REQ | (bit_adr << EFUSECTRL_REG_PROG_CTRL_CTL_EFUSE_PROG_BIT_ADDR_SHIFT)));
199 }
200 
201 static __inline void efuse_prog_bit_end(void)
202 {
203  WR_WORD(EFUSECTRL_REG_PROG_CTRL, 0);
204 }
205 
206 #define EFUSE_READ_HWORD 0
207 #define EFUSE_READ_WORD 1
208 
209 static __inline void efuse_read_bit_start(uint32_t addr, int size)
210 {
211  WR_WORD(EFUSECTRL_REG_READ_CTRL, (EFUSECTRL_REG_READ_CTRL_CTL_EFUSE_READ_REQ |
212  ((addr & EFUSECTRL_REG_READ_CTRL_CTL_EFUSE_READ_ADDR_MASK) << EFUSECTRL_REG_READ_CTRL_CTL_EFUSE_READ_ADDR_SHIFT) |
213  (size ? EFUSECTRL_REG_READ_CTRL_CTL_EFUSE_READ_MODE : 0)));
214 }
215 
216 static __inline void efuse_read_bit_end(void)
217 {
218  WR_WORD(EFUSECTRL_REG_READ_CTRL, 0);
219 }
220 
221 static __inline uint32_t efuse_read_value(void)
222 {
223  return RD_WORD(EFUSECTRL_REG_READ_VAL);
224 }
225 
226 static __inline void efuse_set_prog_ctrl_reg(uint32_t val)
227 {
228  WR_WORD(EFUSECTRL_REG_PROG_CTRL, val);
229 }
230 
231 static __inline uint32_t efuse_get_prog_ctrl_reg(void)
232 {
233  return RD_WORD(EFUSECTRL_REG_PROG_CTRL);
234 }
235 
236 static uint32_t efuse_read_word(uint8_t addr)
237 {
238  uint32_t data;
239 
240  efuse_enable();
241  efuse_read_bit_start(addr, EFUSE_READ_WORD);
242  while (!efuse_intr_read_done());
243  data = efuse_read_value();
244  efuse_intr_read_done_clr();
245  efuse_read_bit_end();
246  efuse_disable();
247 
248  return data;
249 }
250 
251 static __inline uint32_t efuse_init_rd_val_w0(void)
252 {
253  return RD_WORD(EFUSECTRL_REG_INPLAY_INIT_RD_VAL_W0);
254 }
255 
256 static __inline uint32_t efuse_init_rd_val_w1(void)
257 {
258  return RD_WORD(EFUSECTRL_REG_INPLAY_INIT_RD_VAL_W1);
259 }
260 
261 static __inline uint32_t efuse_init_rd_val_w2(void)
262 {
263  return RD_WORD(EFUSECTRL_REG_INPLAY_INIT_RD_VAL_W2);
264 }
265 
266 static __inline uint32_t efuse_init_rd_val_w3(void)
267 {
268  return RD_WORD(EFUSECTRL_REG_INPLAY_INIT_RD_VAL_W3);
269 }
270 
271 static __inline uint32_t efuse_init_rd_val_w4(void)
272 {
273  return RD_WORD(EFUSECTRL_REG_INPLAY_INIT_RD_VAL_W4);
274 }
275 
276 static __inline uint32_t efuse_init_rd_val_w5(void)
277 {
278  return RD_WORD(EFUSECTRL_REG_INPLAY_INIT_RD_VAL_W5);
279 }
280 
281 static __inline uint32_t efuse_init_rd_val_w6(void)
282 {
283  return RD_WORD(EFUSECTRL_REG_INPLAY_INIT_RD_VAL_W6);
284 }
285 
286 static __inline uint32_t efuse_init_rd_val_w7(void)
287 {
288  return RD_WORD(EFUSECTRL_REG_CUSTOMER_INIT_RD_VALUE_W0);
289 }
290 
291 static __inline void efuse_tpp(uint32_t tpp)
292 {
293  uint32_t reg = RD_WORD(EFUSECTRL_REG_COUNTER_CTRL_1);
294  reg &= ~EFUSECTRL_REG_COUNTER_CTRL_1_CTL_EFUSE_CNT_TPP_MASK;
295  reg |= (tpp << EFUSECTRL_REG_COUNTER_CTRL_1_CTL_EFUSE_CNT_TPP_SHIFT);
296  WR_WORD(EFUSECTRL_REG_COUNTER_CTRL_1, reg);
297 }
298 
299 static __inline int efuse_load_done(void)
300 {
301  return ((((RD_WORD(EFUSECTRL_REG_MISC_STS) >> EFUSECTRL_REG_MISC_STS_STS_EFUSE_CURR_STATE_SHIFT) & 0xF) == 0xF) ? 1 : 0);
302 }
303 
304 
312 int hal_efuse_open(void);
313 
321 int hal_efuse_close(void);
322 
334 int hal_efuse_read_word(int word_num, uint32_t* out);
335 
347 int hal_efuse_write_word(int word_num, uint32_t data);
348 
359 uint32_t hal_efuse_read_hw_param(void) ;
360 
372 void hal_efuse_read_uuid(uint32_t uuid[3]) ;
373 
384 uint32_t hal_efuse_read_feature_param(void) ;
385 
396 uint32_t hal_efuse_read_vbat_param(void) ;
397 
408 uint32_t hal_efuse_read_temp_param(void) ;
409 
420 uint32_t hal_efuse_read_usr_param(void) ;
421 
432 void hal_efuse_read_public_keys(uint8_t x[32], uint8_t y[32]) ;
433 
434 
436 
437 
438 #endif
uint32_t hal_efuse_read_hw_param(void)
Read HW configuration parameters in efuse from the register Note: efuse&#39;s word 0, by default...
efuse_result_status
eFuse status result
Definition: hal_efuse.h:137
int hal_efuse_write_word(int word_num, uint32_t data)
Write eFuse word.
uint32_t hal_efuse_read_feature_param(void)
Read feature parameters in efuse from the register Note: efuse&#39;s word 4, by default, will be read by the HW and store in the register, so SW can retrieve it without accessing efuse directly..
int hal_efuse_open(void)
Initialize eFuse driver.
void hal_efuse_read_public_keys(uint8_t x[32], uint8_t y[32])
Read public keys from efuse.
Error. Os apis failed.
Definition: hal_efuse.h:143
void hal_efuse_read_uuid(uint32_t uuid[3])
Read UUID in efuse from the registers Note: efuse&#39;s word 1 - 3, by default, will be read by the HW an...
int hal_efuse_read_word(int word_num, uint32_t *out)
Read eFuse word.
uint32_t hal_efuse_read_temp_param(void)
Read temperature parameters in efuse from the register Note: efuse&#39;s word 6, by default, will be read by the HW and store in the register, so SW can retrieve it without accessing efuse directly..
No error. Good.
Definition: hal_efuse.h:139
Error. driver is not open, call hal_efuse_open.
Definition: hal_efuse.h:141
Error, already been used.
Definition: hal_efuse.h:145
uint32_t hal_efuse_read_vbat_param(void)
Read vbat parameters in efuse from the register Note: efuse&#39;s word 5, by default, will be read by the...
uint32_t hal_efuse_read_usr_param(void)
Read user configuration parameters in efuse from the register Note: efuse&#39;s word 7, by default, will be read by the HW and store in the register, so SW can retrieve it without accessing efuse directly..
int hal_efuse_close(void)
Stop and cleanup eFuse driver.