gr55xx_hal.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file gr55xx_hal.h
5  * @author BLE Driver Team
6  * @brief This file contains all the functions prototypes for the HAL
7  * module driver.
8  *
9  ****************************************************************************************
10  * @attention
11  #####Copyright (c) 2019 GOODIX
12  All rights reserved.
13 
14  Redistribution and use in source and binary forms, with or without
15  modification, are permitted provided that the following conditions are met:
16  * Redistributions of source code must retain the above copyright
17  notice, this list of conditions and the following disclaimer.
18  * Redistributions in binary form must reproduce the above copyright
19  notice, this list of conditions and the following disclaimer in the
20  documentation and/or other materials provided with the distribution.
21  * Neither the name of GOODIX nor the names of its contributors may be used
22  to endorse or promote products derived from this software without
23  specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
29  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  POSSIBILITY OF SUCH DAMAGE.
36  ****************************************************************************************
37  */
38 
39 /** @addtogroup PERIPHERAL Peripheral Driver
40  * @{
41  */
42 
43 /** @addtogroup HAL_DRIVER HAL Driver
44  * @{
45  */
46 
47 /** @defgroup HAL_HAL HAL
48  * @brief HAL module driver.
49  * @{
50  */
51 
52 /* Define to prevent recursive inclusion -------------------------------------*/
53 #ifndef __GR55xx_HAL_H__
54 #define __GR55xx_HAL_H__
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 /* Includes ------------------------------------------------------------------*/
61 #include "gr55xx.h"
62 #include "gr55xx_hal_conf.h"
63 #include "gr55xx_delay.h"
64 
65 /** @addtogroup HAL_HAL_CALLBACK_STRUCTURES Callback Structures
66  * @{
67  */
68 
69 /** @defgroup HAL_HAL_Callback Callback
70  * @{
71  */
72 
73 /**
74  * @brief HAL_HAL Callback function definition
75  */
76 
77 typedef struct _hal_callback
78 {
79  void (*msp_init)(void); /**< HAL init MSP callback */
80  void (*msp_deinit)(void); /**< HAL de-init MSP callback */
82 
83 /** @} */
84 
85 /** @} */
86 
87 /**
88  * @defgroup HAL_MACRO Defines
89  * @{
90  */
91 
92 /* Private macros ------------------------------------------------------------*/
93 /* Exported macros ------------------------------------------------------------*/
94 /** @defgroup HAL_Exported_Constants HAL Exported Constants
95  * @{
96  */
97 
98 /** @brief compare if a > b
99  * @sa CO_MAX
100  */
101 #define CO_MAX(a,b) ((a) > (b) ? (a) : (b))
102 
103 /** @brief Disable BLE_IRQn and BLESLP_IRQn.
104  * @sa BLE_INT_DISABLE
105  */
106 #define BLE_INT_DISABLE() \
107 do { \
108  volatile uint32_t __ble_l_irq_rest = __get_PRIMASK(); \
109  volatile bool __ble_int_status = NVIC_GetEnableIRQ(BLE_IRQn) || NVIC_GetEnableIRQ(BLESLP_IRQn); \
110  __set_PRIMASK(1); \
111  if (__ble_int_status) \
112  { \
113  NVIC_DisableIRQ(BLE_IRQn); \
114  NVIC_DisableIRQ(BLESLP_IRQn); \
115  } \
116  __set_PRIMASK(__ble_l_irq_rest);
117 
118 /** @brief Restore BLE_IRQn and BLESLP_IRQn.
119  * @sa BLE_INT_RESTORE
120  */
121 #define BLE_INT_RESTORE() \
122  __ble_l_irq_rest = __get_PRIMASK(); \
123  __set_PRIMASK(1); \
124  if (__ble_int_status) \
125  { \
126  NVIC_EnableIRQ(BLE_IRQn); \
127  NVIC_EnableIRQ(BLESLP_IRQn); \
128  } \
129  __set_PRIMASK(__ble_l_irq_rest); \
130 } while(0)
131 
132 /** @brief Disable interrupts globally in the system.
133  * This macro must be used in conjunction with the @ref GLOBAL_INT_RESTORE macro
134  * since this last one will close the brace that the current macro opens. This
135  * means that both macros must be located at the same scope level.
136  */
137 #define GLOBAL_INT_DISABLE() \
138 do { \
139  volatile uint32_t __nvic_iser0 = 0xFFFFFFFF; \
140  volatile uint32_t __nvic_iser1 = 0xFFFFFFFF; \
141  volatile uint32_t __ret_pri = __get_PRIMASK(); \
142  __set_PRIMASK(1); \
143  if( (NVIC->ICER[0] != 0xFFFFFFFF) || (NVIC->ICER[1] != 0xFFFFFFFF) ) \
144  { \
145  __nvic_iser0 = NVIC->ISER[0]; \
146  __nvic_iser1 = NVIC->ISER[1]; \
147  NVIC->ICER[0] = 0xFFFFFFFF; \
148  NVIC->ICER[1] = 0xFFFFFFFF; \
149  } \
150  __set_PRIMASK(__ret_pri); \
151  __DSB(); \
152  __ISB(); \
153 
154 /** @brief Restore external interrupts(Exception Type: 16~255) from the previous disable.
155  * @sa GLOBAL_INT_RESTORE
156  */
157 #define GLOBAL_INT_RESTORE() \
158  __ret_pri = __get_PRIMASK(); \
159  __set_PRIMASK(1); \
160  if( (__nvic_iser0 != 0xFFFFFFFF) || (__nvic_iser1 != 0xFFFFFFFF) ) \
161  { \
162  NVIC->ISER[0] = __nvic_iser0; \
163  NVIC->ISER[1] = __nvic_iser1; \
164  } \
165  __set_PRIMASK(__ret_pri); \
166 } while(0)
167 
168 /** @brief Disable external interrupts with a priority lower than IRQn_Type in the system.
169  * This macro must be used in conjunction with the @ref LOCAL_INT_RESTORE macro
170  * since this last one will close the brace that the current macro opens. This
171  * means that both macros must be located at the same scope level.
172  */
173 #define LOCAL_INT_DISABLE(IRQn_Type) \
174 do { \
175  uint32_t __l_irq_rest = __get_BASEPRI(); \
176  __set_BASEPRI(NVIC_GetPriority(IRQn_Type) + \
177  (1 << (NVIC_GetPriorityGrouping() + 1))); \
178 
179 /** @brief Restore external interrupts(apart from the BLE) from the previous disable.
180  * @sa EXP_BLE_INT_RESTORE
181  */
182 #define LOCAL_INT_RESTORE() \
183  __set_BASEPRI(__l_irq_rest); \
184 } while(0)
185 
186 
187 /** @brief Check if the program is running on the FPGA platform.
188  */
189 #define CHECK_IS_ON_FPGA() (AON->FPGA_CTRL & AON_REG_FPGA_CTRL_EXIST)
190 
191 #define SYSTICK_RELOAD_VALUE (SysTick->LOAD) /**< SysTick Reload value. */
192 #define SYSTICK_CURRENT_VALUE (SysTick->VAL) /**< SysTick Current value. */
193 
194 /** @} */
195 
196 /** @} */
197 
198 /* Exported types ------------------------------------------------------------*/
199 /* Exported constants --------------------------------------------------------*/
200 /* Exported functions --------------------------------------------------------*/
201 /** @addtogroup HAL_HAL_DRIVER_FUNCTIONS Functions
202  * @{
203  */
204 
205 /** @addtogroup HAL_Exported_Functions_Group1 Initialization and De-initialization Functions
206  * @brief Initialization and de-initialization functions
207  *
208 @verbatim
209  ===============================================================================
210  ##### Initialization and de-initialization functions #####
211  ===============================================================================
212  [..] This section provides functions allowing to:
213  (+) Initialize the Flash interface, the NVIC allocation and initial clock
214  configuration. It also initializes the source of time base when timeout
215  is needed.
216  (+) De-initialize common part of the HAL.
217  (+) Configure The time base source to have 1ms time base with a dedicated
218  Tick interrupt priority.
219  (++) SysTick timer is used by default as source of time base, but user can
220  eventually implement his or her proper time base source (a general purpose
221  timer for example or other time source), keeping in mind that Time base
222  duration should be kept as 1ms since PPP_TIMEOUT_VALUEs are defined and
223  handled in milliseconds basis.
224  (++) Time base configuration function (hal_init_tick()) is called automatically
225  at the beginning of the program after reset by hal_init().
226  (++) Source of time base is configured to generate interrupts at regular
227  time intervals. Care must be taken if hal_delay() is called from a
228  peripheral ISR process, the Tick interrupt line must have higher priority
229  (numerically lower) than the peripheral interrupt. Otherwise the caller
230  ISR process will be blocked.
231  (++) Functions affecting time base configurations are declared as __Weak
232  to make override possible in case of other implementations in user file.
233 
234 @endverbatim
235  * @{
236  */
237 
238 /**
239  ****************************************************************************************
240  * @brief This function configures time base source, NVIC and Low level hardware.
241  *
242  * @note This function is called at the beginning of program after reset and before
243  * the clock configuration.
244  * The SysTick configuration is based on AHB clock and the NVIC configuration
245  * is set to Priority group 4.
246  * When the time base configuration is done, time base tick starts incrementing.
247  * In the default implementation, SysTick is used as source of time base.
248  * The tick variable is incremented each 1ms in its ISR.
249  *
250  * @retval ::HAL_OK: Operation is OK.
251  * @retval ::HAL_ERROR: Parameter error or operation not supported.
252  * @retval ::HAL_BUSY: Driver is busy.
253  * @retval ::HAL_TIMEOUT: Timeout occurred.
254  ****************************************************************************************
255  */
257 
258 /**
259  ****************************************************************************************
260  * @brief This function de-initializes common part of the HAL and stops the source
261  * of time base.
262  *
263  * @note This function is optional.
264  *
265  * @retval ::HAL_OK: Operation is OK.
266  * @retval ::HAL_ERROR: Parameter error or operation not supported.
267  * @retval ::HAL_BUSY: Driver is busy.
268  * @retval ::HAL_TIMEOUT: Timeout occurred.
269  ****************************************************************************************
270  */
272 
273 /**
274  ****************************************************************************************
275  * @brief Initialize the MSP.
276  *
277  * @note This function should not be modified. When the callback is needed,
278  * the hal_msp_init could be implemented in the user file.
279  ****************************************************************************************
280  */
281 void hal_msp_init(void);
282 
283 /**
284  ****************************************************************************************
285  * @brief De-initialize the MSP.
286  *
287  * @note This function should not be modified. When the callback is needed,
288  * the hal_msp_deinit could be implemented in the user file.
289  ****************************************************************************************
290  */
291 void hal_msp_deinit(void);
292 
293 /**
294  ****************************************************************************************
295  * @brief This function configures the source of the time base.
296  *
297  * @param[in] tick_priority: Tick interrupt priority.
298  *
299  * @retval ::HAL_OK: Operation is OK.
300  * @retval ::HAL_ERROR: Parameter error or operation not supported.
301  * @retval ::HAL_BUSY: Driver is busy.
302  * @retval ::HAL_TIMEOUT: Timeout occurred.
303  ****************************************************************************************
304  */
305 hal_status_t hal_init_tick (uint32_t tick_priority);
306 
307 /** @} */
308 
309 /** @addtogroup HAL_Exported_Functions_Group2 HAL Control functions
310  * @brief HAL Control functions
311  *
312 @verbatim
313  ===============================================================================
314  ##### HAL Control functions #####
315  ===============================================================================
316  [..] This section provides functions allowing to:
317  (+) Suspend the time base source interrupt
318  (+) Resume the time base source interrupt
319  (+) Get the HAL API driver version
320 
321 @endverbatim
322  * @{
323  */
324 
325 /**
326  ****************************************************************************************
327  * @brief Suspend Tick increment.
328  *
329  * @note In the default implementation , SysTick timer is the source of time base. It is
330  * used to generate interrupts at regular time intervals. Once hal_suspend_tick()
331  * is called, the SysTick interrupt will be disabled so Tick increment
332  * is suspended.
333  * This function is declared as __WEAK to be overwritten in case of other
334  * implementations in user file.
335  ****************************************************************************************
336  */
337 void hal_suspend_tick(void);
338 
339 /**
340  ****************************************************************************************
341  * @brief Resume Tick increment.
342  *
343  * @note In the default implementation , SysTick timer is the source of time base. It is
344  * used to generate interrupts at regular time intervals. Once hal_resume_tick()
345  * is called, the SysTick interrupt will be enabled so Tick increment
346  * is resumed.
347  * The function is declared as __WEAK to be overwritten in case of other
348  * implementations in user file.
349  ****************************************************************************************
350  */
351 void hal_resume_tick(void);
352 
353 /**
354  ****************************************************************************************
355  * @brief This function returns the HAL revision
356  *
357  * @return version: 0xXYZR (8 bits for each decimal, R for RC)
358  ****************************************************************************************
359  */
360 uint32_t hal_get_hal_version(void);
361 
362 /** @} */
363 
364 /** @} */
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 
370 #endif /* __GR55xx_HAL_H__ */
371 
372 /** @} */
373 
374 /** @} */
375 
376 /** @} */
_hal_callback::msp_deinit
void(* msp_deinit)(void)
Definition: gr55xx_hal.h:80
gr55xx_delay.h
PERIPHERAL API DELAY DRIVER.
hal_init
hal_status_t hal_init(void)
This function configures time base source, NVIC and Low level hardware.
hal_get_hal_version
uint32_t hal_get_hal_version(void)
This function returns the HAL revision.
hal_callback_t
struct _hal_callback hal_callback_t
HAL_HAL Callback function definition.
hal_suspend_tick
void hal_suspend_tick(void)
Suspend Tick increment.
hal_deinit
hal_status_t hal_deinit(void)
This function de-initializes common part of the HAL and stops the source of time base.
hal_resume_tick
void hal_resume_tick(void)
Resume Tick increment.
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
_hal_callback
HAL_HAL Callback function definition.
Definition: gr55xx_hal.h:78
hal_init_tick
hal_status_t hal_init_tick(uint32_t tick_priority)
This function configures the source of the time base.
_hal_callback::msp_init
void(* msp_init)(void)
Definition: gr55xx_hal.h:79
hal_msp_init
void hal_msp_init(void)
Initialize the MSP.
hal_msp_deinit
void hal_msp_deinit(void)
De-initialize the MSP.
gr55xx_hal_conf.h
HAL configuration file.