gr533x_hal.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file gr533x_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 __GR533x_HAL_H__
54 #define __GR533x_HAL_H__
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 /* Includes ------------------------------------------------------------------*/
61 #include "gr533x.h"
62 #include "gr533x_hal_conf.h"
63 #include "gr533x_delay.h"
64 
65 /**
66  * @defgroup HAL_MACRO Defines
67  * @{
68  */
69 
70 /* Private macros ------------------------------------------------------------*/
71 /* Exported macros ------------------------------------------------------------*/
72 /** @defgroup HAL_Exported_Constants HAL Exported Constants
73  * @{
74  */
75 
76 /** @brief Disable interrupts globally in the system(apart from the NMI).
77  * This macro must be used in conjunction with the @ref GLOBAL_EXCEPTION_ENABLE macro
78  * since this last one will close the brace that the current macro opens. This means
79  * that both macros must be located at the same scope level.
80  */
81 #define GLOBAL_EXCEPTION_DISABLE() \
82 do { \
83  uint32_t __l_irq_rest = __get_PRIMASK(); \
84  __set_PRIMASK(1)
85 
86 
87 /** @brief Restore interrupts from the previous global disable(apart from the NMI).
88  * @sa GLOBAL_EXCEPTION_ENABLE
89  */
90 #define GLOBAL_EXCEPTION_ENABLE() \
91  if(__l_irq_rest == 0) \
92  { \
93  __set_PRIMASK(0); \
94  } \
95  else \
96  { \
97  __set_PRIMASK(1); \
98  } \
99 } while(0)
100 
101 /** @brief Disable interrupts globally in the system.
102  * This macro must be used in conjunction with the @ref GLOBAL_INT_RESTORE macro.
103  */
104 #define GLOBAL_INT_DISABLE() \
105 do { \
106  extern uint32_t global_int_disable(void); \
107  uint32_t __res_mask = global_int_disable()
108 
109 /** @brief Restore global interrupt.
110  * @sa GLOBAL_INT_RESTORE
111  */
112 #define GLOBAL_INT_RESTORE() \
113  extern void global_int_enable(uint32_t mask); \
114  global_int_enable(__res_mask); \
115 } while(0)
116 
117 /** @brief Disable external interrupts with a priority lower than IRQn_Type in the system.
118  * This macro must be used in conjunction with the @ref LOCAL_INT_RESTORE macro
119  * since this last one will close the brace that the current macro opens. This
120  * means that both macros must be located at the same scope level.
121  */
122 #define LOCAL_INT_DISABLE(IRQn_Type) \
123 do { \
124  uint32_t __l_irq_rest = __get_BASEPRI(); \
125  __set_BASEPRI(NVIC_GetPriority(IRQn_Type) + \
126  (1 << (NVIC_GetPriorityGrouping() + 1))); \
127 
128 /** @brief Restore external interrupts(apart from the BLE) from the previous disable.
129  * @sa EXP_BLE_INT_RESTORE
130  */
131 #define LOCAL_INT_RESTORE() \
132  __set_BASEPRI(__l_irq_rest); \
133 } while(0)
134 
135 
136 /** @brief Check if the program is running on the FPGA platform.
137  */
138 #define CHECK_IS_ON_FPGA() (MCU_SUB->FPGA_CTRL & MCU_SUB_FPGA_CTRL_REG_EXIST)
139 
140 #define SYSTICK_RELOAD_VALUE (SysTick->LOAD) /**< SysTick Reload value. */
141 #define SYSTICK_CURRENT_VALUE (SysTick->VAL) /**< SysTick Current value. */
142 
143 /** @} */
144 
145 /** @} */
146 
147 /* Exported types ------------------------------------------------------------*/
148 /* Exported constants --------------------------------------------------------*/
149 /* Exported functions --------------------------------------------------------*/
150 /** @addtogroup HAL_HAL_DRIVER_FUNCTIONS Functions
151  * @{
152  */
153 
154 /** @addtogroup HAL_Exported_Functions_Group1 Initialization and De-initialization Functions
155  * @brief Initialization and de-initialization functions
156  *
157 @verbatim
158  ===============================================================================
159  ##### Initialization and de-initialization functions #####
160  ===============================================================================
161  [..] This section provides functions allowing to:
162  (+) Initialize the Flash interface, the NVIC allocation and initial clock
163  configuration. It also initializes the source of time base when timeout
164  is needed.
165  (+) De-initialize common part of the HAL.
166  (+) Configure The time base source to have 1ms time base with a dedicated
167  Tick interrupt priority.
168  (++) SysTick timer is used by default as source of time base, but user can
169  eventually implement his or her proper time base source (a general purpose
170  timer for example or other time source), keeping in mind that Time base
171  duration should be kept as 1ms since PPP_TIMEOUT_VALUEs are defined and
172  handled in milliseconds basis.
173  (++) Time base configuration function (hal_init_tick()) is called automatically
174  at the beginning of the program after reset by hal_init().
175  (++) Source of time base is configured to generate interrupts at regular
176  time intervals. Care must be taken if hal_delay() is called from a
177  peripheral ISR process, the Tick interrupt line must have higher priority
178  (numerically lower) than the peripheral interrupt. Otherwise the caller
179  ISR process will be blocked.
180  (++) Functions affecting time base configurations are declared as __Weak
181  to make override possible in case of other implementations in user file.
182 
183 @endverbatim
184  * @{
185  */
186 
187 /**
188  ****************************************************************************************
189  * @brief This function configures time base source, NVIC and Low level hardware.
190  *
191  * @note This function is called at the beginning of program after reset and before
192  * the clock configuration.
193  * The SysTick configuration is based on AHB clock.
194  * When the time base configuration is done, time base tick starts incrementing.
195  * In the default implementation, SysTick is used as source of time base.
196  * The tick variable is incremented each 1ms in its ISR.
197  *
198  * @retval ::HAL_OK: Operation is OK.
199  * @retval ::HAL_ERROR: Parameter error or operation not supported.
200  * @retval ::HAL_BUSY: Driver is busy.
201  * @retval ::HAL_TIMEOUT: Timeout occurred.
202  ****************************************************************************************
203  */
205 
206 /**
207  ****************************************************************************************
208  * @brief This function de-initializes common part of the HAL and stops the source
209  * of time base.
210  *
211  * @note This function is optional.
212  *
213  * @retval ::HAL_OK: Operation is OK.
214  * @retval ::HAL_ERROR: Parameter error or operation not supported.
215  * @retval ::HAL_BUSY: Driver is busy.
216  * @retval ::HAL_TIMEOUT: Timeout occurred.
217  ****************************************************************************************
218  */
220 
221 /**
222  ****************************************************************************************
223  * @brief Initialize the MSP.
224  *
225  * @note This function should not be modified. When the callback is needed,
226  * the hal_msp_init could be implemented in the user file.
227  ****************************************************************************************
228  */
229 void hal_msp_init(void);
230 
231 /**
232  ****************************************************************************************
233  * @brief De-initialize the MSP.
234  *
235  * @note This function should not be modified. When the callback is needed,
236  * the hal_msp_deinit could be implemented in the user file.
237  ****************************************************************************************
238  */
239 void hal_msp_deinit(void);
240 
241 /** @} */
242 
243 /** @addtogroup HAL_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
244  * @brief IRQ Handler and Callbacks functions.
245  * @{
246  */
247 
248 /**
249  ****************************************************************************************
250  * @brief This function handles SYSTICK interrupt request.
251  ****************************************************************************************
252  */
254 
255 /**
256  ****************************************************************************************
257  * @brief SYSTICK callback.
258  *
259  * @note This function should not be modified. When the callback is needed,
260  * the hal_systick_callback can be implemented in the user file.
261  ****************************************************************************************
262  */
264 
265 /** @} */
266 
267 
268 /** @addtogroup HAL_Exported_Functions_Group2 HAL Control functions
269  * @brief HAL Control functions
270  *
271 @verbatim
272  ===============================================================================
273  ##### HAL Control functions #####
274  ===============================================================================
275  [..] This section provides functions allowing to:
276  (+) Provide a tick value in millisecond
277  (+) Provide a blocking delay in millisecond
278  (+) Suspend the time base source interrupt
279  (+) Resume the time base source interrupt
280  (+) Get the HAL API driver version
281 
282 @endverbatim
283  * @{
284  */
285 
286 /**
287  ****************************************************************************************
288  * @brief This function is called to increment a global variable "g_tick"
289  * used as application time base.
290  *
291  * @note In the default implementation, this variable is incremented by 1 each 1ms
292  * in Systick ISR.
293  * This function is declared as __WEAK to be overwritten in case of other
294  * implementations in user file.
295  ****************************************************************************************
296  */
298 
299 /**
300  ****************************************************************************************
301  * @brief Povides a tick value in millisecond.
302  *
303  * @note The function is declared as __WEAK to be overwritten in case of other
304  * implementations in user file.
305  *
306  * @return Tick value
307  ****************************************************************************************
308  */
309 uint32_t hal_get_tick(void);
310 
311 /**
312  ****************************************************************************************
313  * @brief This function provides accurate delay (in milliseconds) based
314  * on variable incremented.
315  *
316  * @note In the default implementation , SysTick timer is the source of time base.
317  * It is used to generate interrupts at regular time intervals where g_tick
318  * is incremented.
319  * The function is declared as __WEAK to be overwritten in case of other
320  * implementations in user file.
321  *
322  * @param[in] delay: Specify the delay time length, in milliseconds.
323  ****************************************************************************************
324  */
325 void hal_delay(__IO uint32_t delay);
326 
327 /**
328  ****************************************************************************************
329  * @brief Suspend Tick increment.
330  *
331  * @note In the default implementation , SysTick timer is the source of time base. It is
332  * used to generate interrupts at regular time intervals. Once hal_suspend_tick()
333  * is called, the SysTick interrupt will be disabled and so Tick increment
334  * is suspended.
335  * This function is declared as __WEAK to be overwritten in case of other
336  * implementations in user file.
337  ****************************************************************************************
338  */
339 void hal_suspend_tick(void);
340 
341 /**
342  ****************************************************************************************
343  * @brief Resume Tick increment.
344  *
345  * @note In the default implementation , SysTick timer is the source of time base. It is
346  * used to generate interrupts at regular time intervals. Once hal_resume_tick()
347  * is called, the SysTick interrupt will be enabled and so Tick increment
348  * is resumed.
349  * The function is declared as __WEAK to be overwritten in case of other
350  * implementations in user file.
351  ****************************************************************************************
352  */
353 void hal_resume_tick(void);
354 
355 /**
356  ****************************************************************************************
357  * @brief This function returns the HAL revision
358  *
359  * @return version: 0xXYZR (8 bits for each decimal, R for RC)
360  ****************************************************************************************
361  */
362 uint32_t hal_get_hal_version(void);
363 
364 /**
365  ****************************************************************************************
366  * @brief This function enable the DWT function
367  *
368  * @return none
369  ****************************************************************************************
370  */
371 void hal_dwt_enable(uint32_t _demcr_initial, uint32_t _dwt_ctrl_initial);
372 
373 /**
374  ****************************************************************************************
375  * @brief This function disable the DWT function
376  *
377  * @return none
378  ****************************************************************************************
379  */
380 void hal_dwt_disable(uint32_t _demcr_initial, uint32_t _dwt_ctrl_initial);
381 
382 
383 /** @} */
384 
385 /** @} */
386 
387 #ifdef __cplusplus
388 }
389 #endif
390 
391 #endif /* __GR533x_HAL_H__ */
392 
393 /** @} */
394 
395 /** @} */
396 
397 /** @} */
hal_dwt_disable
void hal_dwt_disable(uint32_t _demcr_initial, uint32_t _dwt_ctrl_initial)
This function disable the DWT function.
hal_init
hal_status_t hal_init(void)
This function configures time base source, NVIC and Low level hardware.
hal_delay
void hal_delay(__IO uint32_t delay)
This function provides accurate delay (in milliseconds) based on variable incremented.
hal_get_hal_version
uint32_t hal_get_hal_version(void)
This function returns the HAL revision.
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_dwt_enable
void hal_dwt_enable(uint32_t _demcr_initial, uint32_t _dwt_ctrl_initial)
This function enable the DWT function.
hal_resume_tick
void hal_resume_tick(void)
Resume Tick increment.
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr533x_hal_def.h:70
hal_systick_irq_handler
void hal_systick_irq_handler(void)
This function handles SYSTICK interrupt request.
hal_msp_init
void hal_msp_init(void)
Initialize the MSP.
hal_increment_tick
void hal_increment_tick(void)
This function is called to increment a global variable "g_tick" used as application time base.
hal_msp_deinit
void hal_msp_deinit(void)
De-initialize the MSP.
gr533x_hal_conf.h
HAL configuration file.
hal_systick_callback
void hal_systick_callback(void)
SYSTICK callback.
hal_get_tick
uint32_t hal_get_tick(void)
Povides a tick value in millisecond.
gr533x_delay.h
PERIPHERAL API DELAY DRIVER.