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