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