1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_def.h
4   * @author  MCD Application Team
5   * @brief   This file contains HAL common defines, enumeration, macros and
6   *          structures definitions.
7   ******************************************************************************
8   * @attention
9   *
10   * Copyright (c) 2016 STMicroelectronics.
11   * All rights reserved.
12   *
13   * This software is licensed under terms that can be found in the LICENSE file
14   * in the root directory of this software component.
15   * If no LICENSE file comes with this software, it is provided AS-IS.
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef __STM32L0xx_HAL_DEF
22 #define __STM32L0xx_HAL_DEF
23 
24 #ifdef __cplusplus
25  extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32l0xx.h"
30 #include "Legacy/stm32_hal_legacy.h"
31 #include <stddef.h>
32 
33 /* Exported types ------------------------------------------------------------*/
34 
35 /**
36   * @brief  HAL Status structures definition
37   */
38 typedef enum
39 {
40   HAL_OK       = 0x00U,
41   HAL_ERROR    = 0x01U,
42   HAL_BUSY     = 0x02U,
43   HAL_TIMEOUT  = 0x03U
44 } HAL_StatusTypeDef;
45 
46 /**
47   * @brief  HAL Lock structures definition
48   */
49 typedef enum
50 {
51   HAL_UNLOCKED = 0x00U,
52   HAL_LOCKED   = 0x01U
53 } HAL_LockTypeDef;
54 
55 /* Exported macro ------------------------------------------------------------*/
56 
57 #if !defined(UNUSED)
58 #define UNUSED(X) (void)X      /* To avoid gcc/g++ warnings */
59 #endif /* UNUSED */
60 
61 #define HAL_MAX_DELAY      0xFFFFFFFFU
62 
63 #define HAL_IS_BIT_SET(REG, BIT)         (((REG) & (BIT)) == (BIT))
64 #define HAL_IS_BIT_CLR(REG, BIT)         (((REG) & (BIT)) == 0U)
65 
66 #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__)             \
67                         do{                                                    \
68                             (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
69                             (__DMA_HANDLE__).Parent = (__HANDLE__);             \
70                           } while(0)
71 
72 /** @brief Reset the Handle's State field.
73   * @param __HANDLE__: specifies the Peripheral Handle.
74   * @note  This macro can be used for the following purpose:
75   *          - When the Handle is declared as local variable; before passing it as parameter
76   *            to HAL_PPP_Init() for the first time, it is mandatory to use this macro
77   *            to set to 0 the Handle's "State" field.
78   *            Otherwise, "State" field may have any random value and the first time the function
79   *            HAL_PPP_Init() is called, the low level hardware initialization will be missed
80   *            (i.e. HAL_PPP_MspInit() will not be executed).
81   *          - When there is a need to reconfigure the low level hardware: instead of calling
82   *            HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
83   *            In this later function, when the Handle's "State" field is set to 0, it will execute the function
84   *            HAL_PPP_MspInit() which will reconfigure the low level hardware.
85   * @retval None
86   */
87 #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U)
88 
89 #if (USE_RTOS == 1)
90 
91   /* Reserved for future use */
92   #error "USE_RTOS should be 0 in the current HAL release"
93 
94 #else
95   #define __HAL_LOCK(__HANDLE__)                                               \
96                                 do{                                            \
97                                     if((__HANDLE__)->Lock == HAL_LOCKED)       \
98                                     {                                          \
99                                        return HAL_BUSY;                        \
100                                     }                                          \
101                                     else                                       \
102                                     {                                          \
103                                        (__HANDLE__)->Lock = HAL_LOCKED;        \
104                                     }                                          \
105                                   }while (0)
106 
107   #define __HAL_UNLOCK(__HANDLE__)                                             \
108                                   do{                                          \
109                                       (__HANDLE__)->Lock = HAL_UNLOCKED;       \
110                                     }while (0)
111 #endif /* USE_RTOS */
112 
113 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */
114   #ifndef __weak
115     #define __weak  __attribute__((weak))
116   #endif
117   #ifndef __packed
118     #define __packed  __attribute__((packed))
119   #endif
120 #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
121   #ifndef __weak
122     #define __weak   __attribute__((weak))
123   #endif /* __weak */
124   #ifndef __packed
125     #define __packed __attribute__((__packed__))
126   #endif /* __packed */
127 
128   #define __NOINLINE __attribute__ ( (noinline) )
129 
130 #endif /* __GNUC__ */
131 
132 
133 /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
134 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */
135   #ifndef __ALIGN_BEGIN
136     #define __ALIGN_BEGIN
137   #endif
138   #ifndef __ALIGN_END
139     #define __ALIGN_END      __attribute__ ((aligned (4)))
140   #endif
141 #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
142   #ifndef __ALIGN_END
143     #define __ALIGN_END    __attribute__ ((aligned (4)))
144   #endif /* __ALIGN_END */
145   #ifndef __ALIGN_BEGIN
146     #define __ALIGN_BEGIN
147   #endif /* __ALIGN_BEGIN */
148 #else
149   #ifndef __ALIGN_END
150     #define __ALIGN_END
151   #endif /* __ALIGN_END */
152   #ifndef __ALIGN_BEGIN
153     #if defined   (__CC_ARM)      /* ARM Compiler V5*/
154       #define __ALIGN_BEGIN    __align(4)
155     #elif defined (__ICCARM__)    /* IAR Compiler */
156       #define __ALIGN_BEGIN
157     #endif /* __CC_ARM */
158   #endif /* __ALIGN_BEGIN */
159 #endif /* __GNUC__ */
160 
161 /**
162   * @brief  __RAM_FUNC definition
163   */
164 #if defined ( __CC_ARM   ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
165 /* ARM Compiler V4/V5 and V6
166    --------------------------
167    RAM functions are defined using the toolchain options.
168    Functions that are executed in RAM should reside in a separate source module.
169    Using the 'Options for File' dialog you can simply change the 'Code / Const'
170    area of a module to a memory space in physical RAM.
171    Available memory areas are declared in the 'Target' tab of the 'Options for Target'
172    dialog.
173 */
174 #define __RAM_FUNC
175 
176 #define __NOINLINE __attribute__ ( (noinline) )
177 
178 
179 #elif defined ( __ICCARM__ )
180 /* ICCARM Compiler
181    ---------------
182    RAM functions are defined using a specific toolchain keyword "__ramfunc".
183 */
184 #define __RAM_FUNC __ramfunc
185 
186 #define __NOINLINE _Pragma("optimize = no_inline")
187 
188 #elif defined   (  __GNUC__  )
189 /* GNU Compiler
190    ------------
191   RAM functions are defined using a specific toolchain attribute
192    "__attribute__((section(".RamFunc")))".
193 */
194 #define __RAM_FUNC  __attribute__((section(".RamFunc")))
195 
196 #endif
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif /* ___STM32L0xx_HAL_DEF */
203 
204 
205