]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/NXP_Code/drivers/fsl_common.h
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso / NXP_Code / drivers / fsl_common.h
1 /*\r
2  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.\r
3  * Copyright 2016-2019 NXP\r
4  * All rights reserved.\r
5  *\r
6  * SPDX-License-Identifier: BSD-3-Clause\r
7  */\r
8 \r
9 #ifndef _FSL_COMMON_H_\r
10 #define _FSL_COMMON_H_\r
11 \r
12 #include <assert.h>\r
13 #include <stdbool.h>\r
14 #include <stdint.h>\r
15 #include <string.h>\r
16 #include <stdlib.h>\r
17 \r
18 #if defined(__ICCARM__)\r
19 #include <stddef.h>\r
20 #endif\r
21 \r
22 /*\r
23  * For CMSIS pack RTE.\r
24  * CMSIS pack RTE generates "RTC_Components.h" which contains the statements\r
25  * of the related <RTE_Components_h> element for all selected software components.\r
26  */\r
27 #ifdef _RTE_\r
28 #include "RTE_Components.h"\r
29 #endif\r
30 \r
31 #include "fsl_device_registers.h"\r
32 \r
33 /*!\r
34  * @addtogroup ksdk_common\r
35  * @{\r
36  */\r
37 \r
38 /*******************************************************************************\r
39  * Definitions\r
40  ******************************************************************************/\r
41 \r
42 /*! @brief Construct a status code value from a group and code number. */\r
43 #define MAKE_STATUS(group, code) ((((group)*100) + (code)))\r
44 \r
45 /*! @brief Construct the version number for drivers. */\r
46 #define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))\r
47 \r
48 /*! @name Driver version */\r
49 /*@{*/\r
50 /*! @brief common driver version 2.2.2. */\r
51 #define FSL_COMMON_DRIVER_VERSION (MAKE_VERSION(2, 2, 2))\r
52 /*@}*/\r
53 \r
54 /* Debug console type definition. */\r
55 #define DEBUG_CONSOLE_DEVICE_TYPE_NONE          0U      /*!< No debug console.             */\r
56 #define DEBUG_CONSOLE_DEVICE_TYPE_UART          1U      /*!< Debug console based on UART.   */\r
57 #define DEBUG_CONSOLE_DEVICE_TYPE_LPUART        2U      /*!< Debug console based on LPUART. */\r
58 #define DEBUG_CONSOLE_DEVICE_TYPE_LPSCI         3U      /*!< Debug console based on LPSCI.  */\r
59 #define DEBUG_CONSOLE_DEVICE_TYPE_USBCDC        4U      /*!< Debug console based on USBCDC. */\r
60 #define DEBUG_CONSOLE_DEVICE_TYPE_FLEXCOMM      5U      /*!< Debug console based on FLEXCOMM. */\r
61 #define DEBUG_CONSOLE_DEVICE_TYPE_IUART         6U      /*!< Debug console based on i.MX UART. */\r
62 #define DEBUG_CONSOLE_DEVICE_TYPE_VUSART        7U      /*!< Debug console based on LPC_VUSART. */\r
63 #define DEBUG_CONSOLE_DEVICE_TYPE_MINI_USART    8U      /*!< Debug console based on LPC_USART. */\r
64 #define DEBUG_CONSOLE_DEVICE_TYPE_SWO           9U      /*!< Debug console based on SWO. */\r
65 \r
66 /*! @brief Status group numbers. */\r
67 enum _status_groups\r
68 {\r
69     kStatusGroup_Generic = 0,                 /*!< Group number for generic status codes. */\r
70     kStatusGroup_FLASH = 1,                   /*!< Group number for FLASH status codes. */\r
71     kStatusGroup_LPSPI = 4,                   /*!< Group number for LPSPI status codes. */\r
72     kStatusGroup_FLEXIO_SPI = 5,              /*!< Group number for FLEXIO SPI status codes. */\r
73     kStatusGroup_DSPI = 6,                    /*!< Group number for DSPI status codes. */\r
74     kStatusGroup_FLEXIO_UART = 7,             /*!< Group number for FLEXIO UART status codes. */\r
75     kStatusGroup_FLEXIO_I2C = 8,              /*!< Group number for FLEXIO I2C status codes. */\r
76     kStatusGroup_LPI2C = 9,                   /*!< Group number for LPI2C status codes. */\r
77     kStatusGroup_UART = 10,                   /*!< Group number for UART status codes. */\r
78     kStatusGroup_I2C = 11,                    /*!< Group number for UART status codes. */\r
79     kStatusGroup_LPSCI = 12,                  /*!< Group number for LPSCI status codes. */\r
80     kStatusGroup_LPUART = 13,                 /*!< Group number for LPUART status codes. */\r
81     kStatusGroup_SPI = 14,                    /*!< Group number for SPI status code.*/\r
82     kStatusGroup_XRDC = 15,                   /*!< Group number for XRDC status code.*/\r
83     kStatusGroup_SEMA42 = 16,                 /*!< Group number for SEMA42 status code.*/\r
84     kStatusGroup_SDHC = 17,                   /*!< Group number for SDHC status code */\r
85     kStatusGroup_SDMMC = 18,                  /*!< Group number for SDMMC status code */\r
86     kStatusGroup_SAI = 19,                    /*!< Group number for SAI status code */\r
87     kStatusGroup_MCG = 20,                    /*!< Group number for MCG status codes. */\r
88     kStatusGroup_SCG = 21,                    /*!< Group number for SCG status codes. */\r
89     kStatusGroup_SDSPI = 22,                  /*!< Group number for SDSPI status codes. */\r
90     kStatusGroup_FLEXIO_I2S = 23,             /*!< Group number for FLEXIO I2S status codes */\r
91     kStatusGroup_FLEXIO_MCULCD = 24,          /*!< Group number for FLEXIO LCD status codes */\r
92     kStatusGroup_FLASHIAP = 25,               /*!< Group number for FLASHIAP status codes */\r
93     kStatusGroup_FLEXCOMM_I2C = 26,           /*!< Group number for FLEXCOMM I2C status codes */\r
94     kStatusGroup_I2S = 27,                    /*!< Group number for I2S status codes */\r
95     kStatusGroup_IUART = 28,                  /*!< Group number for IUART status codes */\r
96     kStatusGroup_CSI = 29,                    /*!< Group number for CSI status codes */\r
97     kStatusGroup_MIPI_DSI = 30,               /*!< Group number for MIPI DSI status codes */\r
98     kStatusGroup_SDRAMC = 35,                 /*!< Group number for SDRAMC status codes. */\r
99     kStatusGroup_POWER = 39,                  /*!< Group number for POWER status codes. */\r
100     kStatusGroup_ENET = 40,                   /*!< Group number for ENET status codes. */\r
101     kStatusGroup_PHY = 41,                    /*!< Group number for PHY status codes. */\r
102     kStatusGroup_TRGMUX = 42,                 /*!< Group number for TRGMUX status codes. */\r
103     kStatusGroup_SMARTCARD = 43,              /*!< Group number for SMARTCARD status codes. */\r
104     kStatusGroup_LMEM = 44,                   /*!< Group number for LMEM status codes. */\r
105     kStatusGroup_QSPI = 45,                   /*!< Group number for QSPI status codes. */\r
106     kStatusGroup_DMA = 50,                    /*!< Group number for DMA status codes. */\r
107     kStatusGroup_EDMA = 51,                   /*!< Group number for EDMA status codes. */\r
108     kStatusGroup_DMAMGR = 52,                 /*!< Group number for DMAMGR status codes. */\r
109     kStatusGroup_FLEXCAN = 53,                /*!< Group number for FlexCAN status codes. */\r
110     kStatusGroup_LTC = 54,                    /*!< Group number for LTC status codes. */\r
111     kStatusGroup_FLEXIO_CAMERA = 55,          /*!< Group number for FLEXIO CAMERA status codes. */\r
112     kStatusGroup_LPC_SPI = 56,                /*!< Group number for LPC_SPI status codes. */\r
113     kStatusGroup_LPC_USART = 57,              /*!< Group number for LPC_USART status codes. */\r
114     kStatusGroup_DMIC = 58,                   /*!< Group number for DMIC status codes. */\r
115     kStatusGroup_SDIF = 59,                   /*!< Group number for SDIF status codes.*/\r
116     kStatusGroup_SPIFI = 60,                  /*!< Group number for SPIFI status codes. */\r
117     kStatusGroup_OTP = 61,                    /*!< Group number for OTP status codes. */\r
118     kStatusGroup_MCAN = 62,                   /*!< Group number for MCAN status codes. */\r
119     kStatusGroup_CAAM = 63,                   /*!< Group number for CAAM status codes. */\r
120     kStatusGroup_ECSPI = 64,                  /*!< Group number for ECSPI status codes. */\r
121     kStatusGroup_USDHC = 65,                  /*!< Group number for USDHC status codes.*/\r
122     kStatusGroup_LPC_I2C = 66,                /*!< Group number for LPC_I2C status codes.*/\r
123     kStatusGroup_DCP = 67,                    /*!< Group number for DCP status codes.*/\r
124     kStatusGroup_MSCAN = 68,                  /*!< Group number for MSCAN status codes.*/\r
125     kStatusGroup_ESAI = 69,                   /*!< Group number for ESAI status codes. */\r
126     kStatusGroup_FLEXSPI = 70,                /*!< Group number for FLEXSPI status codes. */\r
127     kStatusGroup_MMDC = 71,                   /*!< Group number for MMDC status codes. */\r
128     kStatusGroup_PDM = 72,                    /*!< Group number for MIC status codes. */\r
129     kStatusGroup_SDMA = 73,                   /*!< Group number for SDMA status codes. */\r
130     kStatusGroup_ICS = 74,                    /*!< Group number for ICS status codes. */\r
131     kStatusGroup_SPDIF = 75,                  /*!< Group number for SPDIF status codes. */\r
132     kStatusGroup_LPC_MINISPI = 76,            /*!< Group number for LPC_MINISPI status codes. */\r
133     kStatusGroup_HASHCRYPT = 77,              /*!< Group number for Hashcrypt status codes */\r
134     kStatusGroup_LPC_SPI_SSP = 78,            /*!< Group number for LPC_SPI_SSP status codes. */\r
135     kStatusGroup_I3C = 79,                    /*!< Group number for I3C status codes */\r
136     kStatusGroup_LPC_I2C_1 = 97,              /*!< Group number for LPC_I2C_1 status codes. */\r
137     kStatusGroup_NOTIFIER = 98,               /*!< Group number for NOTIFIER status codes. */\r
138     kStatusGroup_DebugConsole = 99,           /*!< Group number for debug console status codes. */\r
139     kStatusGroup_SEMC = 100,                  /*!< Group number for SEMC status codes. */\r
140     kStatusGroup_ApplicationRangeStart = 101, /*!< Starting number for application groups. */\r
141     kStatusGroup_IAP = 102,                   /*!< Group number for IAP status codes */\r
142 \r
143     kStatusGroup_HAL_GPIO = 121,              /*!< Group number for HAL GPIO status codes. */\r
144     kStatusGroup_HAL_UART = 122,              /*!< Group number for HAL UART status codes. */\r
145     kStatusGroup_HAL_TIMER = 123,             /*!< Group number for HAL TIMER status codes. */\r
146     kStatusGroup_HAL_SPI = 124,               /*!< Group number for HAL SPI status codes. */\r
147     kStatusGroup_HAL_I2C = 125,               /*!< Group number for HAL I2C status codes. */\r
148     kStatusGroup_HAL_FLASH = 126,             /*!< Group number for HAL FLASH status codes. */\r
149     kStatusGroup_HAL_PWM = 127,               /*!< Group number for HAL PWM status codes. */\r
150     kStatusGroup_HAL_RNG = 128,               /*!< Group number for HAL RNG status codes. */\r
151     kStatusGroup_TIMERMANAGER = 135,          /*!< Group number for TiMER MANAGER status codes. */\r
152     kStatusGroup_SERIALMANAGER = 136,         /*!< Group number for SERIAL MANAGER status codes. */\r
153     kStatusGroup_LED = 137,                   /*!< Group number for LED status codes. */\r
154     kStatusGroup_BUTTON = 138,                /*!< Group number for BUTTON status codes. */\r
155     kStatusGroup_EXTERN_EEPROM = 139,         /*!< Group number for EXTERN EEPROM status codes. */\r
156     kStatusGroup_SHELL = 140,                 /*!< Group number for SHELL status codes. */\r
157     kStatusGroup_MEM_MANAGER = 141,           /*!< Group number for MEM MANAGER status codes. */\r
158     kStatusGroup_LIST = 142,                  /*!< Group number for List status codes. */\r
159     kStatusGroup_OSA = 143,                   /*!< Group number for OSA status codes. */\r
160     kStatusGroup_COMMON_TASK = 144,           /*!< Group number for Common task status codes. */\r
161     kStatusGroup_MSG = 145,                   /*!< Group number for messaging status codes. */\r
162     kStatusGroup_SDK_OCOTP = 146,             /*!< Group number for OCOTP status codes. */\r
163     kStatusGroup_SDK_FLEXSPINOR = 147,        /*!< Group number for FLEXSPINOR status codes.*/\r
164     kStatusGroup_CODEC = 148,                 /*!< Group number for codec status codes. */\r
165     kStatusGroup_ASRC = 149,                 /*!< Group number for codec status ASRC. */\r
166     kStatusGroup_OTFAD = 150,                 /*!< Group number for codec status codes. */\r
167 };\r
168 \r
169 /*! @brief Generic status return codes. */\r
170 enum\r
171 {\r
172     kStatus_Success = MAKE_STATUS(kStatusGroup_Generic, 0),\r
173     kStatus_Fail = MAKE_STATUS(kStatusGroup_Generic, 1),\r
174     kStatus_ReadOnly = MAKE_STATUS(kStatusGroup_Generic, 2),\r
175     kStatus_OutOfRange = MAKE_STATUS(kStatusGroup_Generic, 3),\r
176     kStatus_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4),\r
177     kStatus_Timeout = MAKE_STATUS(kStatusGroup_Generic, 5),\r
178     kStatus_NoTransferInProgress = MAKE_STATUS(kStatusGroup_Generic, 6),\r
179 };\r
180 \r
181 /*! @brief Type used for all status and error return values. */\r
182 typedef int32_t status_t;\r
183 \r
184 /*\r
185  * Macro guard for whether to use default weak IRQ implementation in drivers\r
186  */\r
187 #ifndef FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ\r
188 #define FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ 1\r
189 #endif\r
190 \r
191 /*! @name Min/max macros */\r
192 /* @{ */\r
193 #if !defined(MIN)\r
194 #define MIN(a, b) (((a) < (b)) ? (a) : (b))\r
195 #endif\r
196 \r
197 #if !defined(MAX)\r
198 #define MAX(a, b) (((a) > (b)) ? (a) : (b))\r
199 #endif\r
200 /* @} */\r
201 \r
202 /*! @brief Computes the number of elements in an array. */\r
203 #if !defined(ARRAY_SIZE)\r
204 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))\r
205 #endif\r
206 \r
207 /*! @name UINT16_MAX/UINT32_MAX value */\r
208 /* @{ */\r
209 #if !defined(UINT16_MAX)\r
210 #define UINT16_MAX ((uint16_t)-1)\r
211 #endif\r
212 \r
213 #if !defined(UINT32_MAX)\r
214 #define UINT32_MAX ((uint32_t)-1)\r
215 #endif\r
216 /* @} */\r
217 \r
218 /*! @name Timer utilities */\r
219 /* @{ */\r
220 /*! Macro to convert a microsecond period to raw count value */\r
221 #define USEC_TO_COUNT(us, clockFreqInHz) (uint64_t)(((uint64_t)(us) * (clockFreqInHz)) / 1000000U)\r
222 /*! Macro to convert a raw count value to microsecond */\r
223 #define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000000U / clockFreqInHz)\r
224 \r
225 /*! Macro to convert a millisecond period to raw count value */\r
226 #define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)ms * clockFreqInHz / 1000U)\r
227 /*! Macro to convert a raw count value to millisecond */\r
228 #define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000U / clockFreqInHz)\r
229 /* @} */\r
230 \r
231 /*! @name Alignment variable definition macros */\r
232 /* @{ */\r
233 #if (defined(__ICCARM__))\r
234 /**\r
235  * Workaround to disable MISRA C message suppress warnings for IAR compiler.\r
236  * http:/ /supp.iar.com/Support/?note=24725\r
237  */\r
238 _Pragma("diag_suppress=Pm120")\r
239 #define SDK_PRAGMA(x) _Pragma(#x)\r
240     _Pragma("diag_error=Pm120")\r
241 /*! Macro to define a variable with alignbytes alignment */\r
242 #define SDK_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var\r
243 /*! Macro to define a variable with L1 d-cache line size alignment */\r
244 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)\r
245 #define SDK_L1DCACHE_ALIGN(var) SDK_PRAGMA(data_alignment = FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) var\r
246 #endif\r
247 /*! Macro to define a variable with L2 cache line size alignment */\r
248 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)\r
249 #define SDK_L2CACHE_ALIGN(var) SDK_PRAGMA(data_alignment = FSL_FEATURE_L2CACHE_LINESIZE_BYTE) var\r
250 #endif\r
251 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)\r
252 /*! Macro to define a variable with alignbytes alignment */\r
253 #define SDK_ALIGN(var, alignbytes) __attribute__((aligned(alignbytes))) var\r
254 /*! Macro to define a variable with L1 d-cache line size alignment */\r
255 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)\r
256 #define SDK_L1DCACHE_ALIGN(var) __attribute__((aligned(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE))) var\r
257 #endif\r
258 /*! Macro to define a variable with L2 cache line size alignment */\r
259 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)\r
260 #define SDK_L2CACHE_ALIGN(var) __attribute__((aligned(FSL_FEATURE_L2CACHE_LINESIZE_BYTE))) var\r
261 #endif\r
262 #elif defined(__GNUC__)\r
263 /*! Macro to define a variable with alignbytes alignment */\r
264 #define SDK_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))\r
265 /*! Macro to define a variable with L1 d-cache line size alignment */\r
266 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)\r
267 #define SDK_L1DCACHE_ALIGN(var) var __attribute__((aligned(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)))\r
268 #endif\r
269 /*! Macro to define a variable with L2 cache line size alignment */\r
270 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)\r
271 #define SDK_L2CACHE_ALIGN(var) var __attribute__((aligned(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)))\r
272 #endif\r
273 #else\r
274 #error Toolchain not supported\r
275 #define SDK_ALIGN(var, alignbytes) var\r
276 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)\r
277 #define SDK_L1DCACHE_ALIGN(var) var\r
278 #endif\r
279 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)\r
280 #define SDK_L2CACHE_ALIGN(var) var\r
281 #endif\r
282 #endif\r
283 \r
284 /*! Macro to change a value to a given size aligned value */\r
285 #define SDK_SIZEALIGN(var, alignbytes) \\r
286     ((unsigned int)((var) + ((alignbytes)-1U)) & (unsigned int)(~(unsigned int)((alignbytes)-1U)))\r
287 /* @} */\r
288 \r
289 /*! @name Non-cacheable region definition macros */\r
290 /* For initialized non-zero non-cacheable variables, please using "AT_NONCACHEABLE_SECTION_INIT(var) ={xx};" or\r
291  * "AT_NONCACHEABLE_SECTION_ALIGN_INIT(var) ={xx};" in your projects to define them, for zero-inited non-cacheable variables,\r
292  * please using "AT_NONCACHEABLE_SECTION(var);" or "AT_NONCACHEABLE_SECTION_ALIGN(var);" to define them, these zero-inited variables\r
293  * will be initialized to zero in system startup.\r
294  */\r
295 /* @{ */\r
296 #if (defined(__ICCARM__))\r
297 #if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))\r
298 #define AT_NONCACHEABLE_SECTION(var) var @"NonCacheable"\r
299 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable"\r
300 #define AT_NONCACHEABLE_SECTION_INIT(var) var @"NonCacheable.init"\r
301 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable.init"\r
302 #else\r
303 #define AT_NONCACHEABLE_SECTION(var) var\r
304 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var\r
305 #define AT_NONCACHEABLE_SECTION_INIT(var) var\r
306 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var\r
307 #endif\r
308 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))\r
309 #if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))\r
310 #define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var\r
311 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \\r
312     __attribute__((section("NonCacheable.init"))) __attribute__((aligned(alignbytes))) var\r
313 #if(defined(__CC_ARM))\r
314 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable"), zero_init)) var\r
315 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \\r
316     __attribute__((section("NonCacheable"), zero_init)) __attribute__((aligned(alignbytes))) var\r
317 #else\r
318 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section(".bss.NonCacheable"))) var\r
319 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \\r
320     __attribute__((section(".bss.NonCacheable"))) __attribute__((aligned(alignbytes))) var\r
321 #endif\r
322 #else\r
323 #define AT_NONCACHEABLE_SECTION(var) var\r
324 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) __attribute__((aligned(alignbytes))) var\r
325 #define AT_NONCACHEABLE_SECTION_INIT(var) var\r
326 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) __attribute__((aligned(alignbytes))) var\r
327 #endif\r
328 #elif(defined(__XCC__))\r
329 #define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var\r
330 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \\r
331     __attribute__((section("NonCacheable.init"))) var __attribute__((aligned(alignbytes)))\r
332 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable"))) var\r
333 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \\r
334     __attribute__((section("NonCacheable"))) var __attribute__((aligned(alignbytes)))\r
335 #elif(defined(__GNUC__))\r
336 /* For GCC, when the non-cacheable section is required, please define "__STARTUP_INITIALIZE_NONCACHEDATA"\r
337  * in your projects to make sure the non-cacheable section variables will be initialized in system startup.\r
338  */\r
339 #if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))\r
340 #define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var\r
341 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \\r
342     __attribute__((section("NonCacheable.init"))) var __attribute__((aligned(alignbytes)))\r
343 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable,\"aw\",%nobits @"))) var\r
344 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \\r
345     __attribute__((section("NonCacheable,\"aw\",%nobits @"))) var __attribute__((aligned(alignbytes)))\r
346 #else\r
347 #define AT_NONCACHEABLE_SECTION(var) var\r
348 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))\r
349 #define AT_NONCACHEABLE_SECTION_INIT(var) var\r
350 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) var __attribute__((aligned(alignbytes)))\r
351 #endif\r
352 #else\r
353 #error Toolchain not supported.\r
354 #define AT_NONCACHEABLE_SECTION(var) var\r
355 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) var\r
356 #define AT_NONCACHEABLE_SECTION_INIT(var) var\r
357 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) var\r
358 #endif\r
359 /* @} */\r
360 \r
361 /*! @name Time sensitive region */\r
362 /* @{ */\r
363 #if defined(FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE) && FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE\r
364 #if (defined(__ICCARM__))\r
365 #define AT_QUICKACCESS_SECTION_CODE(func) func @"CodeQuickAccess"\r
366 #define AT_QUICKACCESS_SECTION_DATA(func) func @"DataQuickAccess"\r
367 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))\r
368 #define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func\r
369 #define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func\r
370 #elif(defined(__GNUC__))\r
371 #define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func\r
372 #define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func\r
373 #else\r
374 #error Toolchain not supported.\r
375 #endif /* defined(__ICCARM__) */\r
376 #else\r
377 #if (defined(__ICCARM__))\r
378 #define AT_QUICKACCESS_SECTION_CODE(func) func\r
379 #define AT_QUICKACCESS_SECTION_DATA(func) func\r
380 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))\r
381 #define AT_QUICKACCESS_SECTION_CODE(func) func\r
382 #define AT_QUICKACCESS_SECTION_DATA(func) func\r
383 #elif(defined(__GNUC__))\r
384 #define AT_QUICKACCESS_SECTION_CODE(func) func\r
385 #define AT_QUICKACCESS_SECTION_DATA(func) func\r
386 #else\r
387 #error Toolchain not supported.\r
388 #endif\r
389 #endif /* __FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE */\r
390 /* @} */\r
391 \r
392 /*! @name Ram Function */\r
393 #if (defined(__ICCARM__))\r
394 #define RAMFUNCTION_SECTION_CODE(func) func @"RamFunction"\r
395 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))\r
396 #define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func\r
397 #elif(defined(__GNUC__))\r
398 #define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func\r
399 #else\r
400 #error Toolchain not supported.\r
401 #endif /* defined(__ICCARM__) */\r
402 /* @} */\r
403 \r
404 /*! @name Suppress fallthrough warning macro */\r
405 /* For switch case code block, if case section ends without "break;" statement, there wil be\r
406  fallthrough warning with compiler flag -Wextra or -Wimplicit-fallthrough=n when using armgcc.\r
407  To suppress this warning, "SUPPRESS_FALL_THROUGH_WARNING();" need to be added at the end of each\r
408  case section which misses "break;"statement.\r
409  */\r
410 /* @{ */\r
411 #if defined(__GNUC__) && !defined(__ARMCC_VERSION)\r
412 #define SUPPRESS_FALL_THROUGH_WARNING() __attribute__ ((fallthrough))\r
413 #else\r
414 #define SUPPRESS_FALL_THROUGH_WARNING()\r
415 #endif\r
416 /* @} */\r
417 \r
418 #if defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )\r
419 void DefaultISR(void);\r
420 #endif\r
421 /*\r
422  * The fsl_clock.h is included here because it needs MAKE_VERSION/MAKE_STATUS/status_t\r
423  * defined in previous of this file.\r
424  */\r
425 #include "fsl_clock.h"\r
426 \r
427 /*\r
428  * Chip level peripheral reset API, for MCUs that implement peripheral reset control external to a peripheral\r
429  */\r
430 #if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \\r
431      (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0)))\r
432 #include "fsl_reset.h"\r
433 #endif\r
434 \r
435 /*******************************************************************************\r
436  * API\r
437  ******************************************************************************/\r
438 \r
439 #if defined(__cplusplus)\r
440         extern "C"\r
441 {\r
442 #endif\r
443 \r
444     /*!\r
445      * @brief Enable specific interrupt.\r
446      *\r
447      * Enable LEVEL1 interrupt. For some devices, there might be multiple interrupt\r
448      * levels. For example, there are NVIC and intmux. Here the interrupts connected\r
449      * to NVIC are the LEVEL1 interrupts, because they are routed to the core directly.\r
450      * The interrupts connected to intmux are the LEVEL2 interrupts, they are routed\r
451      * to NVIC first then routed to core.\r
452      *\r
453      * This function only enables the LEVEL1 interrupts. The number of LEVEL1 interrupts\r
454      * is indicated by the feature macro FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS.\r
455      *\r
456      * @param interrupt The IRQ number.\r
457      * @retval kStatus_Success Interrupt enabled successfully\r
458      * @retval kStatus_Fail Failed to enable the interrupt\r
459      */\r
460     static inline status_t EnableIRQ(IRQn_Type interrupt)\r
461     {\r
462         if (NotAvail_IRQn == interrupt)\r
463         {\r
464             return kStatus_Fail;\r
465         }\r
466 \r
467 #if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)\r
468         if (interrupt >= FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)\r
469         {\r
470             return kStatus_Fail;\r
471         }\r
472 #endif\r
473 \r
474 #if defined(__GIC_PRIO_BITS)\r
475         GIC_EnableIRQ(interrupt);\r
476 #else\r
477         NVIC_EnableIRQ(interrupt);\r
478 #endif\r
479         return kStatus_Success;\r
480     }\r
481 \r
482     /*!\r
483      * @brief Disable specific interrupt.\r
484      *\r
485      * Disable LEVEL1 interrupt. For some devices, there might be multiple interrupt\r
486      * levels. For example, there are NVIC and intmux. Here the interrupts connected\r
487      * to NVIC are the LEVEL1 interrupts, because they are routed to the core directly.\r
488      * The interrupts connected to intmux are the LEVEL2 interrupts, they are routed\r
489      * to NVIC first then routed to core.\r
490      *\r
491      * This function only disables the LEVEL1 interrupts. The number of LEVEL1 interrupts\r
492      * is indicated by the feature macro FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS.\r
493      *\r
494      * @param interrupt The IRQ number.\r
495      * @retval kStatus_Success Interrupt disabled successfully\r
496      * @retval kStatus_Fail Failed to disable the interrupt\r
497      */\r
498     static inline status_t DisableIRQ(IRQn_Type interrupt)\r
499     {\r
500         if (NotAvail_IRQn == interrupt)\r
501         {\r
502             return kStatus_Fail;\r
503         }\r
504 \r
505 #if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)\r
506         if (interrupt >= FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)\r
507         {\r
508             return kStatus_Fail;\r
509         }\r
510 #endif\r
511 \r
512 #if defined(__GIC_PRIO_BITS)\r
513         GIC_DisableIRQ(interrupt);\r
514 #else\r
515     NVIC_DisableIRQ(interrupt);\r
516 #endif\r
517         return kStatus_Success;\r
518     }\r
519 \r
520     /*!\r
521      * @brief Disable the global IRQ\r
522      *\r
523      * Disable the global interrupt and return the current primask register. User is required to provided the primask\r
524      * register for the EnableGlobalIRQ().\r
525      *\r
526      * @return Current primask value.\r
527      */\r
528     static inline uint32_t DisableGlobalIRQ(void)\r
529     {\r
530 #if defined (__XCC__)\r
531         return 0;\r
532 #else\r
533 #if defined(CPSR_I_Msk)\r
534         uint32_t cpsr = __get_CPSR() & CPSR_I_Msk;\r
535 \r
536         __disable_irq();\r
537 \r
538         return cpsr;\r
539 #else\r
540     uint32_t regPrimask = __get_PRIMASK();\r
541 \r
542     __disable_irq();\r
543 \r
544     return regPrimask;\r
545 #endif\r
546 #endif\r
547     }\r
548 \r
549     /*!\r
550      * @brief Enable the global IRQ\r
551      *\r
552      * Set the primask register with the provided primask value but not just enable the primask. The idea is for the\r
553      * convenience of integration of RTOS. some RTOS get its own management mechanism of primask. User is required to\r
554      * use the EnableGlobalIRQ() and DisableGlobalIRQ() in pair.\r
555      *\r
556      * @param primask value of primask register to be restored. The primask value is supposed to be provided by the\r
557      * DisableGlobalIRQ().\r
558      */\r
559     static inline void EnableGlobalIRQ(uint32_t primask)\r
560     {\r
561 #if defined (__XCC__)\r
562 #else\r
563 #if defined(CPSR_I_Msk)\r
564         __set_CPSR((__get_CPSR() & ~CPSR_I_Msk) | primask);\r
565 #else\r
566     __set_PRIMASK(primask);\r
567 #endif\r
568 #endif\r
569     }\r
570 \r
571 #if defined(ENABLE_RAM_VECTOR_TABLE)\r
572     /*!\r
573      * @brief install IRQ handler\r
574      *\r
575      * @param irq IRQ number\r
576      * @param irqHandler IRQ handler address\r
577      * @return The old IRQ handler address\r
578      */\r
579     uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler);\r
580 #endif /* ENABLE_RAM_VECTOR_TABLE. */\r
581 \r
582 #if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))\r
583     /*!\r
584      * @brief Enable specific interrupt for wake-up from deep-sleep mode.\r
585      *\r
586      * Enable the interrupt for wake-up from deep sleep mode.\r
587      * Some interrupts are typically used in sleep mode only and will not occur during\r
588      * deep-sleep mode because relevant clocks are stopped. However, it is possible to enable\r
589      * those clocks (significantly increasing power consumption in the reduced power mode),\r
590      * making these wake-ups possible.\r
591      *\r
592      * @note This function also enables the interrupt in the NVIC (EnableIRQ() is called internaly).\r
593      *\r
594      * @param interrupt The IRQ number.\r
595      */\r
596     void EnableDeepSleepIRQ(IRQn_Type interrupt);\r
597 \r
598     /*!\r
599      * @brief Disable specific interrupt for wake-up from deep-sleep mode.\r
600      *\r
601      * Disable the interrupt for wake-up from deep sleep mode.\r
602      * Some interrupts are typically used in sleep mode only and will not occur during\r
603      * deep-sleep mode because relevant clocks are stopped. However, it is possible to enable\r
604      * those clocks (significantly increasing power consumption in the reduced power mode),\r
605      * making these wake-ups possible.\r
606      *\r
607      * @note This function also disables the interrupt in the NVIC (DisableIRQ() is called internaly).\r
608      *\r
609      * @param interrupt The IRQ number.\r
610      */\r
611     void DisableDeepSleepIRQ(IRQn_Type interrupt);\r
612 #endif /* FSL_FEATURE_SOC_SYSCON_COUNT */\r
613 \r
614     /*!\r
615      * @brief Allocate memory with given alignment and aligned size.\r
616      *\r
617      * This is provided to support the dynamically allocated memory\r
618      * used in cache-able region.\r
619      * @param size The length required to malloc.\r
620      * @param alignbytes The alignment size.\r
621      * @retval The allocated memory.\r
622      */\r
623     void *SDK_Malloc(size_t size, size_t alignbytes);\r
624 \r
625     /*!\r
626      * @brief Free memory.\r
627      *\r
628      * @param ptr The memory to be release.\r
629      */\r
630     void SDK_Free(void *ptr);\r
631 \r
632     /*!\r
633     * @brief Delay at least for some time.\r
634     *  Please note that, this API uses while loop for delay, different run-time environments make the time not precise,\r
635     *  if precise delay count was needed, please implement a new delay function with hardware timer.\r
636     *\r
637     * @param delay_us  Delay time in unit of microsecond.\r
638     * @param coreClock_Hz  Core clock frequency with Hz.\r
639     */\r
640     void SDK_DelayAtLeastUs(uint32_t delay_us, uint32_t coreClock_Hz);\r
641 \r
642 #if defined(__cplusplus)\r
643 }\r
644 #endif\r
645 \r
646 /*! @} */\r
647 \r
648 #endif /* _FSL_COMMON_H_ */\r