• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /* Includes ------------------------------------------------------------------*/
57 #include "gr55xx.h"
58 #include "gr55xx_hal_conf.h"
59 #include "gr55xx_hal_def.h"
60 #include "gr55xx_delay.h"
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 /** @addtogroup HAL_HAL_CALLBACK_STRUCTURES Callback Structures
67   * @{
68   */
69 
70 /** @defgroup HAL_HAL_Callback Callback
71   * @{
72   */
73 
74 /**
75   * @brief HAL_HAL Callback function definition
76   */
77 
78 typedef struct _hal_callback {
79     void (*msp_init)(void);         /**< HAL init MSP callback                  */
80     void (*msp_deinit)(void);       /**< HAL de-init MSP callback               */
81 } hal_callback_t;
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         NVIC_DisableIRQ(BLE_IRQn); \
113         NVIC_DisableIRQ(BLESLP_IRQn); \
114     }                                 \
115     __set_PRIMASK(__ble_l_irq_rest)
116 /** @brief Restore BLE_IRQn and BLESLP_IRQn.
117  *  @sa BLE_INT_RESTORE
118  */
119 #define BLE_INT_RESTORE()                                                                            \
120     __ble_l_irq_rest = __get_PRIMASK();                                                              \
121     __set_PRIMASK(1);                                                                                \
122     if (__ble_int_status)                                                                            \
123     {                                                                                                \
124         NVIC_EnableIRQ(BLE_IRQn);                                                                    \
125         NVIC_EnableIRQ(BLESLP_IRQn);                                                                 \
126     }                                                                                                \
127     __set_PRIMASK(__ble_l_irq_rest);                                                                 \
128 } while (0)
129 
130 #ifdef GR5515_E
131 /** @brief Disable interrupts globally in the system.
132  * This macro must be used in conjunction with the @ref GLOBAL_INT_RESTORE macro.
133  */
134 #define GLOBAL_INT_DISABLE()                               \
135 do {                                                       \
136     extern uint32_t global_int_disable(void);              \
137     uint32_t __res_mask = global_int_disable()
138 
139 /** @brief Restore global interrupt.
140  *  @sa GLOBAL_INT_RESTORE
141  */
142 #define GLOBAL_INT_RESTORE()                               \
143     extern void global_int_enable(uint32_t mask);          \
144     global_int_enable(__res_mask);                         \
145 } while (0)
146 #else
147 /** @brief Disable interrupts globally in the system.
148  * This macro must be used in conjunction with the @ref GLOBAL_INT_RESTORE macro
149  * since this last one will close the brace that the current macro opens. This
150  * means that both macros must be located at the same scope level.
151  */
152 #define GLOBAL_INT_DISABLE()                                                 \
153 do {                                                                         \
154     volatile uint32_t __nvic_iser0 = 0xFFFFFFFF;                             \
155     volatile uint32_t __nvic_iser1 = 0xFFFFFFFF;                             \
156     volatile uint32_t __ret_pri = __get_PRIMASK();                             \
157     __set_PRIMASK(1);                             \
158     if ((NVIC->ICER[0] != 0xFFFFFFFF) ||  (NVIC->ICER[1] != 0xFFFFFFFF)) { \
159         __nvic_iser0 = NVIC->ISER[0];                                        \
160         __nvic_iser1 = NVIC->ISER[1];                                        \
161         NVIC->ICER[0] = 0xFFFFFFFF;                                          \
162         NVIC->ICER[1] = 0xFFFFFFFF;                                          \
163     }                                                                        \
164     __set_PRIMASK(__ret_pri);                                                \
165     __DSB();                                                                 \
166     __ISB()
167 /** @brief Restore external interrupts(Exception Type: 16~255) from the previous disable.
168  *  @sa GLOBAL_INT_RESTORE
169  */
170 #define GLOBAL_INT_RESTORE()                                                 \
171     __ret_pri = __get_PRIMASK();                                             \
172     __set_PRIMASK(1);                                                        \
173     if ( (__nvic_iser0 != 0xFFFFFFFF) || (__nvic_iser1 != 0xFFFFFFFF) )      \
174     {                                                                        \
175         NVIC->ISER[0] = __nvic_iser0;                                        \
176         NVIC->ISER[1] = __nvic_iser1;                                        \
177     }                                                                        \
178     __set_PRIMASK(__ret_pri);                                                \
179 } while (0)
180 #endif
181 
182 /** @brief Disable external interrupts with a priority lower than IRQn_Type in the system.
183  * This macro must be used in conjunction with the @ref LOCAL_INT_RESTORE macro
184  * since this last one will close the brace that the current macro opens. This
185  * means that both macros must be located at the same scope level.
186  */
187 #define LOCAL_INT_DISABLE(IRQn_Type)                         \
188 do {                                                         \
189     uint32_t __l_irq_rest = __get_BASEPRI();                 \
190     __set_BASEPRI(NVIC_GetPriority(IRQn_Type) +              \
191                  (1 << (NVIC_GetPriorityGrouping() + 1)))
192 
193 /** @brief Restore external interrupts(apart from the BLE) from the previous disable.
194  *  @sa EXP_BLE_INT_RESTORE
195  */
196 #define LOCAL_INT_RESTORE()                                  \
197     __set_BASEPRI(__l_irq_rest);                             \
198 } while (0)
199 
200 
201 /** @brief Check if the program is running on the FPGA platform.
202  */
203 #define CHECK_IS_ON_FPGA()                (AON->FPGA_CTRL & AON_REG_FPGA_CTRL_EXIST)
204 
205 #define SYSTICK_RELOAD_VALUE              (SysTick->LOAD)  /**< SysTick Reload value. */
206 #define SYSTICK_CURRENT_VALUE             (SysTick->VAL)   /**< SysTick Current value. */
207 
208 /** @} */
209 
210 /** @} */
211 
212 /* Exported types ------------------------------------------------------------*/
213 /* Exported constants --------------------------------------------------------*/
214 /* Exported functions --------------------------------------------------------*/
215 /** @addtogroup HAL_HAL_DRIVER_FUNCTIONS Functions
216   * @{
217   */
218 
219 /** @addtogroup HAL_Exported_Functions_Group1 Initialization and De-initialization Functions
220  *  @brief    Initialization and de-initialization functions
221  *
222 @verbatim
223  ===============================================================================
224               ##### Initialization and de-initialization functions #####
225  ===============================================================================
226     [..]  This section provides functions allowing to:
227       (+) Initialize the Flash interface, the NVIC allocation and initial clock
228           configuration. It also initializes the source of time base when timeout
229           is needed.
230       (+) De-initialize common part of the HAL.
231       (+) Configure The time base source to have 1ms time base with a dedicated
232           Tick interrupt priority.
233         (++) SysTick timer is used by default as source of time base, but user can
234              eventually implement his or her proper time base source (a general purpose
235              timer for example or other time source), keeping in mind that Time base
236              duration should be kept as 1ms since PPP_TIMEOUT_VALUEs are defined and
237              handled in milliseconds basis.
238         (++) Time base configuration function (hal_init_tick()) is called automatically
239              at the beginning of the program after reset by hal_init().
240         (++) Source of time base is configured  to generate interrupts at regular
241              time intervals. Care must be taken if hal_delay() is called from a
242              peripheral ISR process, the Tick interrupt line must have higher priority
243             (numerically lower) than the peripheral interrupt. Otherwise the caller
244             ISR process will be blocked.
245        (++) Functions affecting time base configurations are declared as __Weak
246             to make  override possible  in case of other  implementations in user file.
247 
248 @endverbatim
249  * @{
250  */
251 
252 /**
253  ****************************************************************************************
254  * @brief  This function configures time base source, NVIC and Low level hardware.
255  *
256  * @note   This function is called at the beginning of program after reset and before
257  *         the clock configuration.
258  *         The SysTick configuration is based on AHB clock and the NVIC configuration
259  *         is set to Priority group 4.
260  *         When the time base configuration is done, time base tick starts incrementing.
261  *         In the default implementation, SysTick is used as source of time base.
262  *         The tick variable is incremented each 1ms in its ISR.
263  *
264  * @retval ::HAL_OK: Operation is OK.
265  * @retval ::HAL_ERROR: Parameter error or operation not supported.
266  * @retval ::HAL_BUSY: Driver is busy.
267  * @retval ::HAL_TIMEOUT: Timeout occurred.
268  ****************************************************************************************
269  */
270 hal_status_t hal_init(void);
271 
272 /**
273  ****************************************************************************************
274  * @brief  This function de-initializes common part of the HAL and stops the source
275  *         of time base.
276  *
277  * @note   This function is optional.
278  *
279  * @retval ::HAL_OK: Operation is OK.
280  * @retval ::HAL_ERROR: Parameter error or operation not supported.
281  * @retval ::HAL_BUSY: Driver is busy.
282  * @retval ::HAL_TIMEOUT: Timeout occurred.
283  ****************************************************************************************
284  */
285 hal_status_t hal_deinit(void);
286 
287 /**
288  ****************************************************************************************
289  * @brief  Initialize the MSP.
290  *
291  * @note   This function should not be modified. When the callback is needed,
292  *         the hal_msp_init could be implemented in the user file.
293  ****************************************************************************************
294  */
295 void hal_msp_init(void);
296 
297 /**
298  ****************************************************************************************
299  * @brief  De-initialize the MSP.
300  *
301  * @note   This function should not be modified. When the callback is needed,
302  *          the hal_msp_deinit could be implemented in the user file.
303  ****************************************************************************************
304  */
305 void hal_msp_deinit(void);
306 
307 /**
308  ****************************************************************************************
309  * @brief  This function configures the source of the time base.
310  *
311  * @param[in]  tick_priority: Tick interrupt priority.
312  *
313  * @retval ::HAL_OK: Operation is OK.
314  * @retval ::HAL_ERROR: Parameter error or operation not supported.
315  * @retval ::HAL_BUSY: Driver is busy.
316  * @retval ::HAL_TIMEOUT: Timeout occurred.
317  ****************************************************************************************
318  */
319 hal_status_t hal_init_tick (uint32_t tick_priority);
320 
321 /** @} */
322 
323 /** @addtogroup HAL_Exported_Functions_Group2 HAL Control functions
324  *  @brief    HAL Control functions
325  *
326 @verbatim
327  ===============================================================================
328                       ##### HAL Control functions #####
329  ===============================================================================
330     [..]  This section provides functions allowing to:
331       (+) Suspend the time base source interrupt
332       (+) Resume the time base source interrupt
333       (+) Get the HAL API driver version
334 
335 @endverbatim
336  * @{
337  */
338 
339 /**
340  ****************************************************************************************
341  * @brief  Suspend 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_suspend_tick()
345  *         is called, the SysTick interrupt will be disabled so Tick increment
346  *         is suspended.
347  *         This function is declared as __WEAK to be overwritten in case of other
348  *         implementations  in user file.
349  ****************************************************************************************
350  */
351 void hal_suspend_tick(void);
352 
353 /**
354  ****************************************************************************************
355  * @brief  Resume Tick increment.
356  *
357  * @note   In the default implementation , SysTick timer is the source of time base. It is
358  *         used to generate interrupts at regular time intervals. Once hal_resume_tick()
359  *         is called, the SysTick interrupt will be enabled so Tick increment
360  *         is resumed.
361  *         The function is declared as __WEAK to be overwritten in case of other
362  *         implementations  in user file.
363  ****************************************************************************************
364  */
365 void hal_resume_tick(void);
366 
367 /**
368  ****************************************************************************************
369  * @brief  This function returns the HAL revision
370  *
371  * @return version: 0xXYZR (8 bits for each decimal, R for RC)
372  ****************************************************************************************
373  */
374 uint32_t hal_get_hal_version(void);
375 
376 /** @} */
377 
378 /** @} */
379 
380 #ifdef __cplusplus
381 }
382 #endif
383 
384 #endif /* __GR55xx_HAL_H__ */
385 
386 /** @} */
387 
388 /** @} */
389 
390 /** @} */
391