gr533x_hal_efuse.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file gr533x_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 __GR533x_HAL_EFUSE_H__
53 #define __GR533x_HAL_EFUSE_H__
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr533x_hal_def.h"
61 #include "gr533x_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_lock_t lock; /**< Locking object */
108 
109  __IO hal_efuse_state_t state; /**< eFuse operation state */
110 
111  __IO uint32_t error_code; /**< eFuse Error code */
112 
114 /** @} */
115 
116 
117 /** @addtogroup HAL_EFUSE_CALLBACK_STRUCTURES Callback Structures
118  * @{
119  */
120 
121 /** @defgroup HAL_EFUSE_Callback Callback
122  * @{
123  */
124 
125 /**
126  * @brief HAL_EFUSE Callback function definition
127  */
128 
129 typedef struct _hal_efuse_callback
130 {
131  void (*efuse_msp_init)(efuse_handle_t *p_efuse); /**< EFUSE init MSP callback */
132  void (*efuse_msp_deinit)(efuse_handle_t *p_efuse); /**< EFUSE de-init MSP callback */
134 
135 /** @} */
136 
137 /** @} */
138 
139 /** @} */
140 
141 /**
142  * @defgroup HAL_EFUSE_MACRO Defines
143  * @{
144  */
145 
146 /* Exported macro ------------------------------------------------------------*/
147 /** @defgroup EFUSE_Exported_Macros EFUSE Exported Macros
148  * @{
149  */
150 
151 /** @defgroup EFUSE_Error_Code EFUSE Error Code
152  * @{
153  */
154 #define HAL_EFUSE_ERROR_NONE ((uint32_t)0x00000000) /**< No error */
155 #define HAL_EFUSE_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */
156 #define HAL_EFUSE_ERROR_INVALID_PARAM ((uint32_t)0x00000002) /**< Invalid parameters error */
157 /** @} */
158 
159 /** @defgroup EFUSE_Flags EFUSE Flags
160  * @{
161  */
162 #define EFUSE_FLAG_INIT_CHECK_DONE LL_EFUSE_INIT_CHECK_DONE /**< eFuse initial value check done */
163 #define EFUSE_FLAG_INIT_CHECK_SUCCESS LL_EFUSE_INIT_CHECK_SUCCESS /**< eFuse initial value check succeeded */
164 #define EFUSE_FLAG_WRITE_DONE LL_EFUSE_WRITE_DONE /**< eFuse one word write done */
165 /** @} */
166 
167 /** @defgroup EFUSE_Loyout_Map EFUSE Loyout Map
168  * @{
169  */
170 #define EFUSE_LAYOUT_UID_FAB (0x00) /**< Store UID-FAB information */
171 #define EFUSE_LAYOUT_UID_YEAR (0x03) /**< Store Year information */
172 #define EFUSE_LAYOUT_UID_MON (0x04) /**< Store month information */
173 #define EFUSE_LAYOUT_UID_LOT_ID (0x05) /**< Store LOT ID information */
174 #define EFUSE_LAYOUT_UID_WAFER_ID (0x0D) /**< Store Wafer ID information */
175 #define EFUSE_LAYOUT_UID_WAFER_X (0x0E) /**< Store Wafer X information */
176 #define EFUSE_LAYOUT_UID_WAFER_Y (0x0F) /**< Store Wafer Y information */
177 
178 #define EFUSE_LAYOUT_FLASH_SE_ADDR1 (0x10) /**< start address for Flash security registers 1 */
179 #define EFUSE_LAYOUT_FLASH_SE_ADDR2 (0x14) /**< start address for Flash security registers 2 */
180 
181 #define EFUSE_LAYOUT_USER_START (0x18) /**< start address for user eFuse space */
182 #define EFUSE_LAYOUT_USER_END (0x1F) /**< end address for user eFuse space */
183 
184 /** @} */
185 
186 /** @} */
187 
188 /* Exported macro ------------------------------------------------------------*/
189 /** @defgroup EFUSE_Exported_Macros EFUSE Exported Macros
190  * @{
191  */
192 
193 /** @brief Enable the eFuse PGENB.
194  * @param __HANDLE__ Specifies the eFuse Handle.
195  * @retval None.
196  */
197 #define __HAL_EFUSE_ENABLE_PGENB(__HANDLE__) ll_efuse_enable_pgenb((__HANDLE__)->p_instance)
198 
199 /** @brief Disable the eFuse PGENB.
200  * @param __HANDLE__ Specifies the eFuse Handle.
201  * @retval None.
202  */
203 #define __HAL_EFUSE_DISABLE_PGENB(__HANDLE__) ll_efuse_disable_pgenb((__HANDLE__)->p_instance)
204 
205 /** @brief Check whether the specified eFuse flag is set or not.
206  * @param __HANDLE__ specifies the eFuse Handle.
207  * @param __FLAG__ specifies the flag to check.
208  * This parameter can be one of the following values:
209  * @arg @ref EFUSE_FLAG_INIT_CHECK_DONE eFuse initial value check done
210  * @arg @ref EFUSE_FLAG_INIT_CHECK_SUCCESS eFuse initial value check succeeded
211  * @arg @ref EFUSE_FLAG_WRITE_DONE eFuse one word write done
212  * @retval The new state of __FLAG__ (TRUE or FALSE).
213  */
214 #define __HAL_EFUSE_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->STAT, (__FLAG__)) != 0) ? SET : RESET)
215 /** @} */
216 
217 /** @} */
218 
219 /* Exported functions --------------------------------------------------------*/
220 /** @addtogroup HAL_EFUSE_DRIVER_FUNCTIONS Functions
221  * @{
222  */
223 
224 /** @defgroup EFUSE_Exported_Functions_Group1 Initialization and de-initialization functions
225  * @brief Initialization and de-initialization functions
226  *
227 @verbatim
228  ===============================================================================
229  ##### Initialization and de-initialization functions #####
230  ===============================================================================
231  [..] This subsection provides a set of functions allowing to initialize and
232  de-initialize the EFUSEx peripheral:
233 
234  (+) User must implement hal_efuse_msp_init() function in which he configures
235  all related peripherals resources (GPIO, DMA, IT and NVIC ).
236 
237  (+) Call the function hal_efuse_init() to configure the selected device with
238  the selected configuration:
239  (++) info_mode
240 
241  (+) Call the function hal_efuse_deinit() to restore the default configuration
242  of the selected EFUSEx peripheral.
243 
244 @endverbatim
245  * @{
246  */
247 
248 /**
249  ****************************************************************************************
250  * @brief Initialize the eFuse according to the specified parameters
251  * in the efuse_init_t and initialize the associated handle.
252  *
253  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
254  *
255  * @retval ::HAL_OK: Operation is OK.
256  * @retval ::HAL_ERROR: Parameter error or operation not supported.
257  * @retval ::HAL_BUSY: Driver is busy.
258  * @retval ::HAL_TIMEOUT: Timeout occurred.
259  ****************************************************************************************
260  */
262 
263 /**
264  ****************************************************************************************
265  * @brief De-initialize the eFuse peripheral.
266  *
267  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
268  *
269  * @retval ::HAL_OK: Operation is OK.
270  * @retval ::HAL_ERROR: Parameter error or operation not supported.
271  * @retval ::HAL_BUSY: Driver is busy.
272  * @retval ::HAL_TIMEOUT: Timeout occurred.
273  ****************************************************************************************
274  */
276 
277 /**
278  ****************************************************************************************
279  * @brief Initialize the eFuse MSP.
280  *
281  * @note This function should not be modified. When the callback is needed,
282  * the hal_efuse_msp_deinit can be implemented in the user file.
283  *
284  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
285  ****************************************************************************************
286  */
288 
289 /**
290  ****************************************************************************************
291  * @brief De-initialize the eFuse MSP.
292  *
293  * @note This function should not be modified. When the callback is needed,
294  * the hal_efuse_msp_deinit can be implemented in the user file.
295  *
296  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
297  ****************************************************************************************
298  */
300 
301 /** @} */
302 
303 /** @defgroup EFUSE_Exported_Functions_Group2 IO operation functions
304  * @brief eFuse Data manage functions
305  *
306  * @{
307  */
308 
309 /**
310  ****************************************************************************************
311  * @brief Write the eFuse memory data.
312  *
313  * @note Address should be eFuse memory address.
314  *
315  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
316  * @param[in] word_offset: eFuse memory offset, unit word, this parament can be a value between: 0x00 ~ 0x80.
317  * @param[in] p_data: Pointer to data buffer for storage eFuse data.
318  * @param[in] nword: Size of data to be write, unit word.
319  *
320  * @retval ::HAL_OK: Operation is OK.
321  * @retval ::HAL_ERROR: Parameter error or operation not supported.
322  * @retval ::HAL_BUSY: Driver is busy.
323  * @retval ::HAL_TIMEOUT: Timeout occurred.
324  ****************************************************************************************
325  */
326 hal_status_t hal_efuse_write(efuse_handle_t *p_efuse, uint32_t word_offset, uint32_t *p_data, uint32_t nword);
327 
328 /**
329  ****************************************************************************************
330  * @brief Read the eFuse memory data.
331  *
332  * @note Address should be eFuse memory address.
333  *
334  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
335  * @param[in] word_offset: eFuse memory offset, unit word, this parament can be a value between: 0x000 ~ 0x80.
336  * @param[in] p_data: Pointer to data buffer for storage eFuse data.
337  * @param[in] nword: Size of data to be read, unit word.
338  *
339  * @retval ::HAL_OK: Operation is OK.
340  * @retval ::HAL_ERROR: Parameter error or operation not supported.
341  * @retval ::HAL_BUSY: Driver is busy.
342  * @retval ::HAL_TIMEOUT: Timeout occurred.
343  ****************************************************************************************
344  */
345 hal_status_t hal_efuse_read(efuse_handle_t *p_efuse, uint32_t word_offset, uint32_t *p_data, uint32_t nword);
346 
347 /**
348  ****************************************************************************************
349  * @brief Check the eFuse memory with 0, if memory are all 0, return HAL_OK, then return HAL_ERROR.
350  *
351  * @param[in] p_efuse: Pointer to a eFuse handle which contains the configuration information for the specified eFuse module.
352  *
353  * @retval ::HAL_OK: Operation is OK.
354  * @retval ::HAL_ERROR: Parameter error or operation not supported.
355  * @retval ::HAL_BUSY: Driver is busy.
356  * @retval ::HAL_TIMEOUT: Timeout occurred.
357  ****************************************************************************************
358  */
360 
361 /** @} */
362 
363 /** @} */
364 
365 #ifdef __cplusplus
366 }
367 #endif
368 
369 #endif /* __GR533x_HAL_EFUSE_H__ */
370 
371 /** @} */
372 
373 /** @} */
374 
375 /** @} */
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
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr533x_hal_def.h:81
_efuse_handle
eFuse handle Structure definition
Definition: gr533x_hal_efuse.h:104
_hal_efuse_callback::efuse_msp_init
void(* efuse_msp_init)(efuse_handle_t *p_efuse)
Definition: gr533x_hal_efuse.h:131
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, uint32_t *p_data, uint32_t nword)
Write the eFuse memory data.
HAL_EFUSE_STATE_RESET
@ HAL_EFUSE_STATE_RESET
Definition: gr533x_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...
gr533x_ll_efuse.h
Header file containing functions prototypes of eFuse LL library.
_hal_efuse_callback
HAL_EFUSE Callback function definition.
Definition: gr533x_hal_efuse.h:130
_efuse_handle::p_instance
efuse_regs_t * p_instance
Definition: gr533x_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: gr533x_hal_def.h:70
HAL_EFUSE_STATE_READY
@ HAL_EFUSE_STATE_READY
Definition: gr533x_hal_efuse.h:78
_efuse_handle::state
__IO hal_efuse_state_t state
Definition: gr533x_hal_efuse.h:109
_efuse_handle::error_code
__IO uint32_t error_code
Definition: gr533x_hal_efuse.h:111
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: gr533x_hal_efuse.h:79
HAL_EFUSE_STATE_ERROR
@ HAL_EFUSE_STATE_ERROR
Definition: gr533x_hal_efuse.h:80
gr533x_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
hal_efuse_state_t
hal_efuse_state_t
HAL eFuse State Enumerations definition.
Definition: gr533x_hal_efuse.h:76
_hal_efuse_callback::efuse_msp_deinit
void(* efuse_msp_deinit)(efuse_handle_t *p_efuse)
Definition: gr533x_hal_efuse.h:132
_efuse_handle::lock
__IO hal_lock_t lock
Definition: gr533x_hal_efuse.h:107