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