1 /**
2   ******************************************************************************
3   * @file    stm32n6xx_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) 2023 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 __STM32N6xx_HAL_DEF
22 #define __STM32N6xx_HAL_DEF
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #if defined (__ARM_FEATURE_CMSE) &&  (__ARM_FEATURE_CMSE == 3U)
30 #include <arm_cmse.h>
31 #endif /* defined (__ARM_FEATURE_CMSE) &&  (__ARM_FEATURE_CMSE == 3U) */
32 
33 #include "stm32n6xx.h"
34 #include "Legacy/stm32_hal_legacy.h"  /* Aliases file for old names compatibility */
35 #include <stddef.h>
36 #include <math.h>
37 
38 /* Exported types ------------------------------------------------------------*/
39 
40 /**
41   * @brief  HAL Status structures definition
42   */
43 typedef enum
44 {
45   HAL_OK       = 0x00,
46   HAL_ERROR    = 0x01,
47   HAL_BUSY     = 0x02,
48   HAL_TIMEOUT  = 0x03
49 } HAL_StatusTypeDef;
50 
51 /**
52   * @brief  HAL Lock structures definition
53   */
54 typedef enum
55 {
56   HAL_UNLOCKED = 0x00,
57   HAL_LOCKED   = 0x01
58 } HAL_LockTypeDef;
59 
60 /* Exported macros -----------------------------------------------------------*/
61 
62 #if !defined(UNUSED)
63 #define UNUSED(X) (void)X      /* To avoid gcc/g++ warnings */
64 #endif /* UNUSED */
65 
66 #define HAL_MAX_DELAY      0xFFFFFFFFU
67 
68 #define HAL_IS_BIT_SET(REG, BIT)         (((REG) & (BIT)) == (BIT))
69 #define HAL_IS_BIT_CLR(REG, BIT)         (((REG) & (BIT)) == 0U)
70 
71 #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__)       \
72   do{                                                                      \
73     (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__);                   \
74     (__DMA_HANDLE__).Parent = (__HANDLE__);                                \
75   } while(0)
76 
77 /** @brief Reset the Handle's State field.
78   * @param __HANDLE__ specifies the Peripheral Handle.
79   * @note  This macro can be used for the following purpose:
80   *          - When the Handle is declared as local variable; before passing it as parameter
81   *            to HAL_PPP_Init() for the first time, it is mandatory to use this macro
82   *            to set to 0 the Handle's "State" field.
83   *            Otherwise, "State" field may have any random value and the first time the function
84   *            HAL_PPP_Init() is called, the low level hardware initialization will be missed
85   *            (i.e. HAL_PPP_MspInit() will not be executed).
86   *          - When there is a need to reconfigure the low level hardware: instead of calling
87   *            HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
88   *            In this later function, when the Handle's "State" field is set to 0, it will execute the function
89   *            HAL_PPP_MspInit() which will reconfigure the low level hardware.
90   * @retval None
91   */
92 #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0)
93 
94 #if (USE_RTOS == 1)
95 /* Reserved for future use */
96 #error " USE_RTOS should be 0 in the current HAL release "
97 #else
98 #define __HAL_LOCK(__HANDLE__)               \
99   do{                                        \
100     if((__HANDLE__)->Lock == HAL_LOCKED)     \
101     {                                        \
102       return HAL_BUSY;                       \
103     }                                        \
104     else                                     \
105     {                                        \
106       (__HANDLE__)->Lock = HAL_LOCKED;       \
107     }                                        \
108   }while (0)
109 
110 #define __HAL_UNLOCK(__HANDLE__)             \
111   do{                                        \
112     (__HANDLE__)->Lock = HAL_UNLOCKED;       \
113   }while (0)
114 #endif /* USE_RTOS */
115 
116 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */
117 #ifndef __weak
118 #define __weak __attribute__((weak))
119 #endif /* __weak */
120 #ifndef __packed
121 #define __packed __attribute__((packed))
122 #endif /* __packed */
123 #elif defined (__GNUC__) /* GNU Compiler */
124 #ifndef __weak
125 #define __weak __attribute__((weak))
126 #endif /* __weak */
127 #ifndef __packed
128 #define __packed __attribute__((__packed__))
129 #endif /* __packed */
130 #endif /* __ARMCC_VERSION */
131 
132 /* Macro to get buffer 32-bytes aligned (aligned to cache line width) */
133 #define ALIGN_32BYTES(buf)  buf __attribute__((aligned(32)))
134 
135 /* Legacy macros to get variable 4-bytes aligned */
136 #ifndef __ALIGN_BEGIN
137 #define __ALIGN_BEGIN
138 #endif /* __ALIGN_BEGIN */
139 #ifndef __ALIGN_END
140 #define __ALIGN_END  __attribute__((aligned(4)))
141 #endif /* __ALIGN_END */
142 
143 /**
144   * @brief  __RAM_FUNC definition
145   */
146 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
147 /* ARM Compiler V6
148    ---------------
149    RAM functions are defined using the toolchain options.
150    Functions that are executed in RAM should reside in a separate source module.
151    Using the 'Options for File' dialog you can simply change the 'Code / Const'
152    area of a module to a memory space in physical RAM.
153    Available memory areas are declared in the 'Target' tab of the 'Options for Target'
154    dialog.
155 */
156 #define __RAM_FUNC
157 
158 #elif defined (__ICCARM__)
159 /* ICCARM Compiler
160    ---------------
161    RAM functions are defined using a specific toolchain keyword "__ramfunc".
162 */
163 #define __RAM_FUNC  __ramfunc
164 
165 #elif defined (__GNUC__)
166 /* GNU Compiler
167    ------------
168   RAM functions are defined using a specific toolchain attribute
169    "__attribute__((section(".RamFunc")))".
170 */
171 #define __RAM_FUNC  __attribute__((section(".RamFunc")))
172 
173 #endif /* __ARMCC_VERSION */
174 
175 /**
176   * @brief  __NOINLINE definition
177   */
178 #if (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined (__GNUC__)
179 /* ARM Compiler V6 & GNU Compiler */
180 #define __NOINLINE __attribute__((noinline))
181 
182 #elif defined ( __ICCARM__ )
183 /* ICCARM Compiler */
184 #define __NOINLINE _Pragma("optimize = no_inline")
185 
186 #endif /* __ARMCC_VERSION || __GNUC__ */
187 
188 /* Non cacheable section and attribute
189   ------------------------------------
190   Create a non-cacheable section for DMA buffers and other hardware shared data.
191   The user can then use the __NON_CACHEABLE_SECTION_BEGIN and NON_CACHEABLE_SECTION_END to configure a non cacheable region
192   containing the data that was defined using the __NON_CACHEABLE attribute. */
193 #if defined(__ICCARM__)
194 #pragma section=".noncacheable"
195 #define __NON_CACHEABLE_SECTION_BEGIN ((uint32_t) __sfb(".noncacheable"))
196 #define __NON_CACHEABLE_SECTION_END   ((uint32_t) __sfe(".noncacheable"))
197 #elif defined(__ARMCC_VERSION)
198 extern uint32_t Image$$RW_NONCACHEABLEBUFFER$$Base;
199 extern uint32_t Image$$RW_NONCACHEABLEBUFFER$$Length;
200 #define __NON_CACHEABLE_SECTION_BEGIN Image$$RW_NONCACHEABLEBUFFER$$Base
201 #define __NON_CACHEABLE_SECTION_END   (__NON_CACHEABLE_SECTION_BEGIN + Image$$RW_NONCACHEABLEBUFFER$$Length)
202 #elif defined(__GNUC__)
203 extern uint32_t __snoncacheable;
204 extern uint32_t __enoncacheable;
205 #define __NON_CACHEABLE_SECTION_BEGIN ((uint32_t) &__snoncacheable)
206 #define __NON_CACHEABLE_SECTION_END   ((uint32_t) &__enoncacheable)
207 #endif /* defined(__ICCARM__) */
208 #define __NON_CACHEABLE __attribute__((section(".noncacheable")))
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #endif /* ___STM32N6xx_HAL_DEF */
215