1 /**
2   ******************************************************************************
3   * @file    tae32f53xx_ll_def.h
4   * @author  MCD Application Team
5   * @brief   This file contains LL common defines, enumeration, macros and
6   *          structures definitions.
7   *
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; Copyright (c) 2020 Tai-Action.
12   * All rights reserved.</center></h2>
13   *
14   * This software is licensed by Tai-Action under BSD 3-Clause license,
15   * the "License"; You may not use this file except in compliance with the
16   * License. You may obtain a copy of the License at:
17   *                        opensource.org/licenses/BSD-3-Clause
18   *
19   ******************************************************************************
20   */
21 
22 /* Define to prevent recursive inclusion -------------------------------------*/
23 #ifndef _TAE32F53XX_LL_DEF_H_
24 #define _TAE32F53XX_LL_DEF_H_
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29 
30 /* Includes ------------------------------------------------------------------*/
31 #include <stddef.h>
32 #include "tae32f53xx.h"
33 
34 
35 /** @addtogroup TAE32F53xx_LL_Driver
36   * @{
37   */
38 
39 /** @defgroup DEFINE_LL DEFINE LL
40   * @brief    DEFINE LL
41   * @{
42   */
43 
44 
45 /* Exported constants --------------------------------------------------------*/
46 /** @defgroup DEFINE_LL_Exported_Constants DEFINE LL Exported Constants
47   * @brief    DEFINE LL Exported Constants
48   * @{
49   */
50 
51 /**
52   * @brief LL wait forever time definition
53   */
54 #define LL_WAIT_FOREVER                     0xFFFFFFFFUL
55 
56 /**
57   * @brief LL wait max delay time definition
58   */
59 #define LL_MAX_DELAY                        (LL_WAIT_FOREVER - 1U)
60 
61 /**
62   * @}
63   */
64 
65 
66 /* Exported types ------------------------------------------------------------*/
67 /** @defgroup DEFINE_LL_Exported_Types DEFINE LL Exported Types
68   * @brief    DEFINE LL Exported Types
69   * @{
70   */
71 
72 /**
73   * @brief  LL Status type definition
74   */
75 typedef enum {
76     LL_OK       = 0x00U,    /*! LL status OK                    */
77     LL_ERROR    = 0x01U,    /*! LL status ERROR                 */
78     LL_BUSY     = 0x02U,    /*! LL status BUSY                  */
79     LL_TIMEOUT  = 0x03U,    /*! LL status TIMEOUT               */
80     LL_FAILED   = 0x04U,    /*! LL status FAILED                */
81 } LL_StatusETypeDef;
82 
83 /**
84   * @brief LL Flag status type definition
85   */
86 typedef enum {
87     RESET = 0,              /*!< LL flag status RESET           */
88     SET   = !RESET,         /*!< LL flag status SET             */
89 } LL_FlagStatusETypeDef;
90 
91 /**
92   * @brief LL Functional status type definition
93   */
94 typedef enum {
95     DISABLE = 0,            /*!< LL functional status DISABLE   */
96     ENABLE  = !DISABLE,     /*!< LL functional status ENABLE    */
97 } LL_FuncStatusETypeDef;
98 
99 /**
100   * @brief LL Error status type definiton
101   */
102 typedef enum {
103     SUCCESS = 0U,           /*!< LL error status SUCCESS        */
104     ERROR   = !SUCCESS,     /*!< LL error status ERROR          */
105 } LL_ErrStatusETypeDef;
106 
107 /**
108   * @}
109   */
110 
111 
112 /* Exported macro ------------------------------------------------------------*/
113 /** @defgroup DEFINE_LL_Exported_Macros DEFINE LL Exported Macros
114   * @brief    DEFINE LL Exported Macros
115   * @{
116   */
117 
118 /* Compiler ALIAS and WEAK attribute definition */
119 #if   defined (__CC_ARM)                                        /*!< AC5 Compiler */
120 #define __ALIAS_FUNC(FUNC)                      __attribute__ ((weak, alias(#FUNC)))
121 #define __WEAK_ALIAS_FUNC(FUNC, FUNC_ALIAS)     void FUNC(void) __attribute__ ((weak, alias(#FUNC_ALIAS)));
122 #elif defined (__ICCARM__)                                      /*!< IAR Compiler */
123 #define __WEAK_ALIAS_FUNC(FUNC, FUNC_ALIAS)     void FUNC(void);_Pragma(_STRINGIFY(_WEAK_ALIAS_FUNC(FUNC, FUNC_ALIAS)))
124 #define _WEAK_ALIAS_FUNC(FUNC, FUNC_ALIAS)      weak WEAK_ALIAS_FUNC(FUNC, FUNC_ALIAS)
125 #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)  /*!< AC6 Compiler */
126 #define __ALIAS_FUNC(FUNC)                      __attribute__ ((weak, alias(#FUNC)))
127 #define __WEAK_ALIAS_FUNC(FUNC, FUNC_ALIAS)     void FUNC(void) __attribute__ ((weak, alias(#FUNC_ALIAS)));
128 #elif defined (__GNUC__)                                        /*!< GCC Compiler */
129 #define __ALIAS_FUNC(FUNC)                      __attribute__ ((weak, alias(#FUNC)))
130 #define __WEAK_ALIAS_FUNC(FUNC, FUNC_ALIAS)     void FUNC(void) __attribute__ ((weak, alias(#FUNC_ALIAS)));
131 #else
132 #error Not supported compiler type
133 #endif
134 
135 
136 /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
137 /* Compiler aligned on 4-bytes attribute definition */
138 #if defined ( __GNUC__ ) && !defined (__CC_ARM)         /* GNU Compiler */
139 #ifndef __ALIGN_END
140 #define __ALIGN_END                 __attribute__ ((aligned (4)))
141 #endif
142 
143 #ifndef __ALIGN_BEGIN
144 #define __ALIGN_BEGIN
145 #endif
146 
147 #else
148 
149 #ifndef __ALIGN_END
150 #define __ALIGN_END
151 #endif
152 
153 #ifndef __ALIGN_BEGIN
154 #if defined   (__CC_ARM)                        /* ARM Compiler */
155 #define __ALIGN_BEGIN           __align(4)
156 #elif defined (__ICCARM__)                      /* IAR Compiler */
157 #define __ALIGN_BEGIN
158 #endif
159 #endif
160 #endif
161 
162 
163 /* Compiler __NOINLINE attribute definition */
164 #if   defined (__CC_ARM) || defined (__GNUC__)          /* ARM & GNUCompiler */
165 #define __NOINLINE                      __attribute__ ( (noinline) )
166 #elif defined (__ICCARM__)                              /* ICCARM Compiler */
167 #define __NOINLINE                      _Pragma("optimize = no_inline")
168 #endif
169 
170 
171 /* Compiler misc attribute definition */
172 #if   defined (__CC_ARM)                                        /*!< AC5 Compiler */
173 #define __NO_INIT                       __attribute__((zero_init))
174 #define __AT(n)                         __attribute__((at(n)))
175 #define __SECTION(SECT)                 __attribute__((section(#SECT)))
176 #elif defined (__ICCARM__)                                      /*!< IAR Compiler */
177 #define __NO_INIT                       __no_init
178 #define __AT(n)                         @(n)
179 #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)  /*!< AC6 Compiler */
180 #define __NO_INIT
181 #define __AT(n)                         __attribute__ ((section(".ARM.__at_"#n)))
182 #define __SECTION(SECT)                 __attribute__((section(#SECT)))
183 #elif defined (__GNUC__)                                        /*!< GCC Compiler */
184 #define __NO_INIT                       __attribute__((zero_init))
185 #define __AT(n)
186 #define __SECTION(SECT)                 __attribute__((section(#SECT)))
187 #endif
188 
189 
190 /**
191   * @brief  Bit left shift definition
192   * @param  pos left shift position
193   * @return Bit left shift value
194   */
195 #define BIT(pos)                            (1U << (pos))
196 
197 /**
198   * @brief  Set bit definition
199   * @param  REG register
200   * @param  BIT Bit to set
201   * @return None
202   */
203 #define SET_BIT(REG, BIT)                   ((REG) |= (BIT))
204 
205 /**
206   * @brief  Clear bit definition
207   * @param  REG register
208   * @param  BIT Bit to clear
209   * @return None
210   */
211 #define CLEAR_BIT(REG, BIT)                 ((REG) &= ~(BIT))
212 
213 /**
214   * @brief  Read bit definition
215   * @param  REG register
216   * @param  BIT Bit to read
217   * @return None
218   */
219 #define READ_BIT(REG, BIT)                  ((REG) & (BIT))
220 
221 /**
222   * @brief  Clear register definiton
223   * @param  REG register
224   * @return None
225   */
226 #define CLEAR_REG(REG)                      ((REG) = (0x0))
227 
228 /**
229   * @brief  Write register definiton
230   * @param  REG register
231   * @param  VAL write value
232   * @return None
233   */
234 #define WRITE_REG(REG, VAL)                 ((REG) = (VAL))
235 
236 /**
237   * @brief  Read register definition
238   * @param  REG register
239   * @return None
240   */
241 #define READ_REG(REG)                       ((REG))
242 
243 /**
244   * @brief  Modify register definition
245   * @param  REG register
246   * @param  CLEARMASK clear mask
247   * @param  SETMASK set mask
248   * @return None
249   */
250 #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
251 
252 /**
253   * @brief  Position value definition
254   * @param  VAL value
255   * @return None
256   */
257 #define POSITION_VAL(VAL)                   (__CLZ(__RBIT(VAL)))
258 
259 
260 
261 /**
262   * @brief  To avoid gcc/g++ warnings
263   * @param  X avoid warning param
264   * @return None
265   */
266 #define LL_UNUSED(X)                        (void)X
267 
268 /**
269   * @brief  Macro for counting the element number of an array
270   * @param  a Array to be Counted
271   * @return size of Array
272   */
273 #define ARRAY_SIZE(a)                       (sizeof((a)) / sizeof((a)[0]))
274 
275 /**
276   * @}
277   */
278 
279 
280 /* Exported functions --------------------------------------------------------*/
281 /* Private types -------------------------------------------------------------*/
282 /* Private variables ---------------------------------------------------------*/
283 /* Private constants ---------------------------------------------------------*/
284 /* Private macros ------------------------------------------------------------*/
285 /* Private functions ---------------------------------------------------------*/
286 
287 
288 /**
289   * @}
290   */
291 
292 /**
293   * @}
294   */
295 
296 
297 #ifdef __cplusplus
298 }
299 #endif /* __cplusplus */
300 
301 
302 #endif /* _TAE32F53XX_LL_DEF_H_ */
303 
304 
305 /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/
306 
307