gr533x_hal_def.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr533x_hal_def.h
5 * @author BLE Driver Team
6 * @brief This file contains HAL common definitions, enumeration, macros and structures definitions.
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_DEF HAL DEFINE
47 * @brief HAL common definitions.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR533x_HAL_DEF__
53 #define __GR533x_HAL_DEF__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr533x.h"
61 #include <stdio.h>
62
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_ENUMERATIONS Enumerations
65 * @{ */
66 /**
67 * @brief HAL Status structures definition
68 */
69 typedef enum
70 {
71 HAL_OK = 0x00U, /**< Operation is OK. */
72 HAL_ERROR = 0x01U, /**< Parameter error or operation is not supported. */
73 HAL_BUSY = 0x02U, /**< Driver is busy. */
74 HAL_TIMEOUT = 0x03 /**< Timeout occurred. */
75 } hal_status_t;
76
77 /**
78 * @brief HAL Lock structures definition
79 */
80 typedef enum
81 {
82 HAL_UNLOCKED = 0x00U, /**< Object is unlocked. */
83 HAL_LOCKED = 0x01 /**< Object is locked. */
84 } hal_lock_t;
85 /** @} */
86
87 /**
88 * @defgroup HAL_DEF_MACRO Defines
89 * @{
90 */
91
92 /* Exported macro ------------------------------------------------------------*/
93 /**
94 * @brief HAL never timeout definition.
95 */
96 #define HAL_NEVER_TIMEOUT (0xFFFFFFFFU)
97
98 /**
99 * @brief HAL max delay definition. Unit is millisecond.
100 * 20000ms is the max delay time in 96MHz system clock.
101 */
102 #define HAL_MAX_DELAY (20000U)
103
104 /**
105 * @brief Timeout module init. This macro must be used in
106 * conjunction with the @ref HAL_TIMEOUT_DEINIT macro
107 */
108 #define HAL_TIMEOUT_INIT() \
109 uint32_t _demcr_initial = CoreDebug->DEMCR; \
110 uint32_t _dwt_ctrl_initial = DWT->CTRL; \
111 do { \
112 hal_dwt_enable(_demcr_initial, _dwt_ctrl_initial); \
113 } while (0)
114
115 /**
116 * @brief Timeout module deinit. This macro must be used in
117 * conjunction with the @ref HAL_TIMEOUT_INIT macro
118 */
119 #define HAL_TIMEOUT_DEINIT() \
120 do { \
121 hal_dwt_disable(_demcr_initial, _dwt_ctrl_initial); \
122 } while(0)
123
124 /**
125 * @brief Timeout module get current tick.
126 * @retval Current tick
127 */
128 #define HAL_TIMEOUT_GET_TICK() (DWT->CYCCNT)
129
130 /**
131 * @brief Check whether the bits of register are set.
132 * @param REG specifies the register.
133 * @param BIT specifies the bits will be checked.
134 * @retval SET (BIT is set) or RESET (BIT is not set)
135 */
136 #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != RESET)
137 /**
138 * @brief Check whether the bits of register are clear.
139 * @param REG specifies the register.
140 * @param BIT specifies the bits will be checked.
141 * @retval SET (BIT is clear) or RESET (BIT is not clear)
142 */
143 #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == RESET)
144
145 /**
146 * @brief Link DMA handle and peripheral handle.
147 * @param __HANDLE__ specifies the peripheral handle.
148 * @param __PPP_DMA_FIELD_ specifies the DMA pointer in struction of peripheral handle.
149 * @param __DMA_HANDLE_ specifies the DMA handle.
150 * @retval None
151 */
152 #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD_, __DMA_HANDLE_) \
153 do{ \
154 (__HANDLE__)->__PPP_DMA_FIELD_ = &(__DMA_HANDLE_); \
155 (__DMA_HANDLE_).p_parent = (__HANDLE__); \
156 } while(0U)
157
158 /** @brief Reset the Handle's State field.
159 * @param __HANDLE__ specifies the Peripheral Handle.
160 * @note This macro can be used for the following purposes:
161 * - When the Handle is declared as local variable; before passing it as parameter
162 * to hal_ppp_init() for the first time, it is mandatory to use this macro
163 * to set the Handle's "State" field to 0.
164 * Otherwise, "State" field may have any random value and the first time the function
165 * hal_ppp_init() is called, the low level hardware initialization will be missed
166 * (i.e. hal_ppp_msp_init() will not be executed).
167 * - When there is a need to reconfigure the low level hardware: instead of calling
168 * hal_ppp_deinit() then hal_ppp_init(), user can make a call to this macro then hal_ppp_init().
169 * In this later function, when the Handle's "State" field is set to 0, it will execute the function
170 * hal_ppp_msp_init which will reconfigure the low level hardware.
171 * @retval None
172 */
173 #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = 0U)
174
175 #if (USE_RTOS == 1U)
176 #error " USE_RTOS should be 0 in the current HAL release "
177 #else
178 /**
179 * @brief Lock peripheral handle.
180 * @param __HANDLE__ specifies the peripheral handle.
181 * @retval HAL_BUSY If handle is locked.
182 */
183 #define __HAL_LOCK(__HANDLE__) \
184 do{ \
185 if((__HANDLE__)->lock == HAL_LOCKED) \
186 { \
187 return HAL_BUSY; \
188 } \
189 else \
190 { \
191 (__HANDLE__)->lock = HAL_LOCKED; \
192 } \
193 }while (0U)
194
195 /**
196 * @brief Unlock peripheral handle.
197 * @param __HANDLE__ specifies the peripheral handle.
198 * @retval None
199 */
200 #define __HAL_UNLOCK(__HANDLE__) \
201 do{ \
202 (__HANDLE__)->lock = HAL_UNLOCKED; \
203 }while (0U)
204 #endif /* USE_RTOS */
205
206
207 #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
208 #ifndef __weak
209 #define __weak __attribute__((weak))
210 #endif /* __weak */
211 #ifndef __packed
212 #define __packed __attribute__((__packed__))
213 #endif /* __packed */
214 #endif /* __GNUC__ */
215
216
217 /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
218 #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
219 #ifndef __ALIGN_END
220 #define __ALIGN_END __attribute__((aligned(4)))
221 #endif /* __ALIGN_END */
222 #ifndef __ALIGN_BEGIN
223 #define __ALIGN_BEGIN
224 #endif /* __ALIGN_BEGIN */
225 #else
226 #ifndef __ALIGN_END
227 #define __ALIGN_END /**< ALIGN END */
228 #endif /* __ALIGN_END */
229 #ifndef __ALIGN_BEGIN
230 #if defined(__CC_ARM) /* ARM Compiler */
231 #define __ALIGN_BEGIN __align(4)
232 #elif defined(__ICCARM__) /* IAR Compiler */
233 #define __ALIGN_BEGIN
234 #endif /* __CC_ARM */
235 #endif /* __ALIGN_BEGIN */
236 #endif /* __GNUC__ */
237
238 /**
239 * @brief __NOINLINE definition
240 */
241 #if defined(__CC_ARM) || defined(__GNUC__)
242 /* ARM & GNUCompiler
243 ----------------
244 */
245 #define __NOINLINE __attribute__((noinline))
246
247 #elif defined(__ICCARM__)
248 /* ICCARM Compiler
249 ---------------
250 */
251 #define __NOINLINE _Pragma("optimize = no_inline")
252
253 #endif
254
255 /** @} */
256
257 #ifdef __cplusplus
258 }
259 #endif
260
261 #endif /* ___GR533x_HAL_DEF__ */
262 /** @} */
263
264 /** @} */
265
266 /** @} */
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr533x_hal_def.h:81
HAL_OK
@ HAL_OK
Definition: gr533x_hal_def.h:71
HAL_ERROR
@ HAL_ERROR
Definition: gr533x_hal_def.h:72
HAL_BUSY
@ HAL_BUSY
Definition: gr533x_hal_def.h:73
HAL_UNLOCKED
@ HAL_UNLOCKED
Definition: gr533x_hal_def.h:82
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr533x_hal_def.h:70
HAL_TIMEOUT
@ HAL_TIMEOUT
Definition: gr533x_hal_def.h:74
HAL_LOCKED
@ HAL_LOCKED
Definition: gr533x_hal_def.h:83