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