hal_efuse.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file hal_efuse.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of eFuse HAL library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 /** @addtogroup PERIPHERAL Peripheral Driver
39  * @{
40  */
41 
42 /** @addtogroup HAL_DRIVER HAL Driver
43  * @{
44  */
45 
46 /** @defgroup HAL_EFUSE EFUSE
47  * @brief eFuse HAL module driver.
48  * @{
49  */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef HAL_EFUSE_H
53 #define HAL_EFUSE_H
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "hal_def.h"
61 #include "ll_efuse.h"
62 
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_EFUSE_ENUMERATIONS Enumerations
65  * @{
66  */
67 
68 /** @defgroup HAL_EFUSE_state HAL EFUSE state
69  * @{
70  */
71 
72 /**
73  * @brief HAL eFuse State Enumerations definition
74  */
75 typedef enum
76 {
77  HAL_EFUSE_STATE_RESET = 0x00, /**< Peripheral not yet initialized or disabled */
78  HAL_EFUSE_STATE_READY = 0x01, /**< Peripheral Initialized and ready for use */
79  HAL_EFUSE_STATE_BUSY = 0x02, /**< An internal process is ongoing */
80  HAL_EFUSE_STATE_ERROR = 0x04 /**< Reception process is error */
82 /** @} */
83 
84 /** @} */
85 
86 /** @addtogroup HAL_EFUSE_STRUCTURES Structures
87  * @{
88  */
89 
90 /** @defgroup EFUSE_Configuration EFUSE Configuration
91  * @{
92  */
93 
94 /** @} */
95 
96 /** @defgroup EFUSE_handle EFUSE handle
97  * @{
98  */
99 
100 /**
101  * @brief eFuse handle Structure definition
102  */
103 typedef struct _efuse_handle
104 {
105  efuse_regs_t *p_instance; /**< Register base address */
106 
107  __IO hal_efuse_state_t state; /**< eFuse operation state */
108 
109  __IO uint32_t error_code; /**< eFuse Error code */
110 
112 /** @} */
113 
114 
115 /** @addtogroup HAL_EFUSE_CALLBACK_STRUCTURES Callback Structures
116  * @{
117  */
118 
119 /** @defgroup HAL_EFUSE_Callback Callback
120  * @{
121  */
122 
123 /**
124  * @brief HAL_EFUSE Callback function definition
125  */
126 
127 typedef struct _hal_efuse_callback
128 {
129  void (*efuse_msp_init)(efuse_handle_t *p_efuse); /**< EFUSE init MSP callback */
130  void (*efuse_msp_deinit)(efuse_handle_t *p_efuse); /**< EFUSE de-init MSP callback */
132 
133 /** @} */
134 
135 /** @} */
136 
137 /** @} */
138 
139 /**
140  * @defgroup HAL_EFUSE_MACRO Defines
141  * @{
142  */
143 
144 /* Exported macro ------------------------------------------------------------*/
145 /** @defgroup EFUSE_Exported_Macros EFUSE Exported Macros
146  * @{
147  */
148 
149 /** @defgroup EFUSE_Error_Code EFUSE Error Code
150  * @{
151  */
152 #define HAL_EFUSE_ERROR_NONE ((uint32_t)0x00000000) /**< No error */
153 #define HAL_EFUSE_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */
154 #define HAL_EFUSE_ERROR_INVALID_PARAM ((uint32_t)0x00000002) /**< Invalid parameters error */
155 /** @} */
156 
157 /** @defgroup EFUSE_Flags EFUSE Flags
158  * @{
159  */
160 #define EFUSE_FLAG_INIT_CHECK_DONE LL_EFUSE_INIT_CHECK_DONE /**< eFuse initial value check done */
161 #define EFUSE_FLAG_INIT_CHECK_SUCCESS LL_EFUSE_INIT_CHECK_SUCCESS /**< eFuse initial value check succeeded */
162 #define EFUSE_FLAG_WRITE_DONE LL_EFUSE_WRITE_DONE /**< eFuse one word write done */
163 /** @} */
164 
165 /** @defgroup EFUSE_Loyout_Map EFUSE Loyout Map
166  * @{
167  */
168 #define EFUSE_LAYOUT_UID_FAB (0x00) /**< Store UID-FAB information */
169 #define EFUSE_LAYOUT_UID_YEAR (0x03) /**< Store Year information */
170 #define EFUSE_LAYOUT_UID_MON (0x04) /**< Store month information */
171 #define EFUSE_LAYOUT_UID_LOT_ID (0x05) /**< Store LOT ID information */
172 #define EFUSE_LAYOUT_UID_WAFER_ID (0x0D) /**< Store Wafer ID information */
173 #define EFUSE_LAYOUT_UID_WAFER_X (0x0E) /**< Store Wafer X information */
174 #define EFUSE_LAYOUT_UID_WAFER_Y (0x0F) /**< Store Wafer Y information */
175 
176 #define EFUSE_LAYOUT_FLASH_SE_ADDR1 (0x10) /**< start address for Flash security registers 1 */
177 #define EFUSE_LAYOUT_FLASH_SE_ADDR2 (0x14) /**< start address for Flash security registers 2 */
178 
179 #define EFUSE_LAYOUT_USER_START (0x18) /**< start address for user eFuse space */
180 #define EFUSE_LAYOUT_USER_END (0x1F) /**< end address for user eFuse space */
181 
182 /** @} */
183 
184 /** @} */
185 
186 /* Exported macro ------------------------------------------------------------*/
187 /** @defgroup EFUSE_Exported_Macros EFUSE Exported Macros
188  * @{
189  */
190 
191 /** @brief Enable the eFuse PGENB.
192  * @param __HANDLE__ Specifies the eFuse Handle.
193  * @retval None.
194  */
195 #define __HAL_EFUSE_ENABLE_PGENB(__HANDLE__) ll_efuse_enable_pgenb((__HANDLE__)->p_instance)
196 
197 /** @brief Disable the eFuse PGENB.
198  * @param __HANDLE__ Specifies the eFuse Handle.
199  * @retval None.
200  */
201 #define __HAL_EFUSE_DISABLE_PGENB(__HANDLE__) ll_efuse_disable_pgenb((__HANDLE__)->p_instance)
202 
203 /** @brief Check whether the specified eFuse flag is set or not.
204  * @param __HANDLE__ specifies the eFuse Handle.
205  * @param __FLAG__ specifies the flag to check.
206  * This parameter can be one of the following values:
207  * @arg @ref EFUSE_FLAG_INIT_CHECK_DONE eFuse initial value check done
208  * @arg @ref EFUSE_FLAG_INIT_CHECK_SUCCESS eFuse initial value check succeeded
209  * @arg @ref EFUSE_FLAG_WRITE_DONE eFuse one word write done
210  * @retval The new state of __FLAG__ (TRUE or FALSE).
211  */
212 #define __HAL_EFUSE_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->STAT, (__FLAG__)) != 0) ? SET : RESET)
213 /** @} */
214 
215 /** @} */
216 
217 /* Exported functions --------------------------------------------------------*/
218 /** @addtogroup HAL_EFUSE_DRIVER_FUNCTIONS Functions
219  * @{
220  */
221 
222 /** @defgroup EFUSE_Exported_Functions_Group1 Initialization and de-initialization functions
223  * @brief Initialization and de-initialization functions
224  *
225 @verbatim
226  ===============================================================================
227  ##### Initialization and de-initialization functions #####
228  ===============================================================================
229  [..] This subsection provides a set of functions allowing to initialize and
230  de-initialize the EFUSEx peripheral:
231 
232  (+) User must implement hal_efuse_msp_init() function in which he configures
233  all related peripherals resources (GPIO, DMA, IT and NVIC ).
234 
235  (+) Call the function hal_efuse_init() to configure the selected device with
236  the selected configuration:
237  (++) info_mode
238 
239  (+) Call the function hal_efuse_deinit() to restore the default configuration
240  of the selected EFUSEx peripheral.
241 
242 @endverbatim
243  * @{
244  */
245 
246 /**
247  ****************************************************************************************
248  * @brief Initialize the eFuse according to the specified parameters
249  * in the efuse_init_t and initialize the associated handle.
250  *
251  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
252  *
253  * @retval ::HAL_OK: Operation is OK.
254  * @retval ::HAL_ERROR: Parameter error or operation not supported.
255  * @retval ::HAL_BUSY: Driver is busy.
256  * @retval ::HAL_TIMEOUT: Timeout occurred.
257  ****************************************************************************************
258  */
260 
261 /**
262  ****************************************************************************************
263  * @brief De-initialize the eFuse peripheral.
264  *
265  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
266  *
267  * @retval ::HAL_OK: Operation is OK.
268  * @retval ::HAL_ERROR: Parameter error or operation not supported.
269  * @retval ::HAL_BUSY: Driver is busy.
270  * @retval ::HAL_TIMEOUT: Timeout occurred.
271  ****************************************************************************************
272  */
274 
275 /**
276  ****************************************************************************************
277  * @brief Initialize the eFuse MSP.
278  *
279  * @note This function should not be modified. When the callback is needed,
280  * the hal_efuse_msp_deinit can be implemented in the user file.
281  *
282  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
283  ****************************************************************************************
284  */
286 
287 /**
288  ****************************************************************************************
289  * @brief De-initialize the eFuse MSP.
290  *
291  * @note This function should not be modified. When the callback is needed,
292  * the hal_efuse_msp_deinit can be implemented in the user file.
293  *
294  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
295  ****************************************************************************************
296  */
298 
299 /** @} */
300 
301 /** @defgroup EFUSE_Exported_Functions_Group2 IO operation functions
302  * @brief eFuse Data manage functions
303  *
304  * @{
305  */
306 
307 /**
308  ****************************************************************************************
309  * @brief Write the eFuse memory data.
310  *
311  * @note Address should be eFuse memory address.
312  *
313  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
314  * @param[in] word_offset: eFuse memory offset, unit word, this parament can be a value between: 0x00 ~ 0x80.
315  * @param[in] p_data: Pointer to data buffer for storage eFuse data.
316  * @param[in] nword: Size of data to be write, unit word.
317  *
318  * @retval ::HAL_OK: Operation is OK.
319  * @retval ::HAL_ERROR: Parameter error or operation not supported.
320  * @retval ::HAL_BUSY: Driver is busy.
321  * @retval ::HAL_TIMEOUT: Timeout occurred.
322  ****************************************************************************************
323  */
324 hal_status_t hal_efuse_write(efuse_handle_t *p_efuse, uint32_t word_offset, const uint32_t *p_data, uint32_t nword);
325 
326 /**
327  ****************************************************************************************
328  * @brief Read the eFuse memory data.
329  *
330  * @note Address should be eFuse memory address.
331  *
332  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
333  * @param[in] word_offset: eFuse memory offset, unit word, this parament can be a value between: 0x000 ~ 0x80.
334  * @param[in] p_data: Pointer to data buffer for storage eFuse data.
335  * @param[in] nword: Size of data to be read, unit word.
336  *
337  * @retval ::HAL_OK: Operation is OK.
338  * @retval ::HAL_ERROR: Parameter error or operation not supported.
339  * @retval ::HAL_BUSY: Driver is busy.
340  * @retval ::HAL_TIMEOUT: Timeout occurred.
341  ****************************************************************************************
342  */
343 hal_status_t hal_efuse_read(efuse_handle_t *p_efuse, uint32_t word_offset, uint32_t *p_data, uint32_t nword);
344 
345 /**
346  ****************************************************************************************
347  * @brief Check the eFuse memory with 0, if memory are all 0, return HAL_OK, then return HAL_ERROR.
348  *
349  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
350  *
351  * @retval ::HAL_OK: Operation is OK.
352  * @retval ::HAL_ERROR: Parameter error or operation not supported.
353  * @retval ::HAL_BUSY: Driver is busy.
354  * @retval ::HAL_TIMEOUT: Timeout occurred.
355  ****************************************************************************************
356  */
358 
359 /** @} */
360 
361 /** @} */
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 
367 #endif /* HAL_EFUSE_H */
368 
369 /** @} */
370 
371 /** @} */
372 
373 /** @} */
hal_efuse_read
hal_status_t hal_efuse_read(efuse_handle_t *p_efuse, uint32_t word_offset, uint32_t *p_data, uint32_t nword)
Read the eFuse memory data.
efuse_handle_t
struct _efuse_handle efuse_handle_t
eFuse handle Structure definition
_efuse_handle
eFuse handle Structure definition
Definition: hal_efuse.h:104
_hal_efuse_callback::efuse_msp_init
void(* efuse_msp_init)(efuse_handle_t *p_efuse)
Definition: hal_efuse.h:129
hal_efuse_callback_t
struct _hal_efuse_callback hal_efuse_callback_t
HAL_EFUSE Callback function definition.
hal_efuse_write
hal_status_t hal_efuse_write(efuse_handle_t *p_efuse, uint32_t word_offset, const uint32_t *p_data, uint32_t nword)
Write the eFuse memory data.
HAL_EFUSE_STATE_RESET
@ HAL_EFUSE_STATE_RESET
Definition: hal_efuse.h:77
hal_efuse_init
hal_status_t hal_efuse_init(efuse_handle_t *p_efuse)
Initialize the eFuse according to the specified parameters in the efuse_init_t and initialize the ass...
_hal_efuse_callback
HAL_EFUSE Callback function definition.
Definition: hal_efuse.h:128
_efuse_handle::p_instance
efuse_regs_t * p_instance
Definition: hal_efuse.h:105
hal_efuse_msp_deinit
void hal_efuse_msp_deinit(efuse_handle_t *p_efuse)
De-initialize the eFuse MSP.
hal_efuse_initial_value_check
hal_status_t hal_efuse_initial_value_check(efuse_handle_t *p_efuse)
Check the eFuse memory with 0, if memory are all 0, return HAL_OK, then return HAL_ERROR.
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr_common.h:140
hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
ll_efuse.h
Header file containing functions prototypes of eFuse LL library.
HAL_EFUSE_STATE_READY
@ HAL_EFUSE_STATE_READY
Definition: hal_efuse.h:78
_efuse_handle::state
__IO hal_efuse_state_t state
Definition: hal_efuse.h:107
_efuse_handle::error_code
__IO uint32_t error_code
Definition: hal_efuse.h:109
hal_efuse_deinit
hal_status_t hal_efuse_deinit(efuse_handle_t *p_efuse)
De-initialize the eFuse peripheral.
hal_efuse_msp_init
void hal_efuse_msp_init(efuse_handle_t *p_efuse)
Initialize the eFuse MSP.
HAL_EFUSE_STATE_BUSY
@ HAL_EFUSE_STATE_BUSY
Definition: hal_efuse.h:79
HAL_EFUSE_STATE_ERROR
@ HAL_EFUSE_STATE_ERROR
Definition: hal_efuse.h:80
hal_efuse_state_t
hal_efuse_state_t
HAL eFuse State Enumerations definition.
Definition: hal_efuse.h:76
_hal_efuse_callback::efuse_msp_deinit
void(* efuse_msp_deinit)(efuse_handle_t *p_efuse)
Definition: hal_efuse.h:130