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