]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M0+_LPC51U68_GCC_IAR_KEIL/drivers/fsl_common.h
Increase test coverage for queue sets.
[freertos] / FreeRTOS / Demo / CORTEX_M0+_LPC51U68_GCC_IAR_KEIL / 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, 1, 0))\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_I3C = 79,                    /*!< Group number for I3C status codes */\r
127     kStatusGroup_LPC_I2C_1 = 97,              /*!< Group number for LPC_I2C_1 status codes. */\r
128     kStatusGroup_NOTIFIER = 98,               /*!< Group number for NOTIFIER status codes. */\r
129     kStatusGroup_DebugConsole = 99,           /*!< Group number for debug console status codes. */\r
130     kStatusGroup_SEMC = 100,                  /*!< Group number for SEMC status codes. */\r
131     kStatusGroup_ApplicationRangeStart = 101, /*!< Starting number for application groups. */\r
132     kStatusGroup_IAP = 102,                   /*!< Group number for IAP status codes */\r
133 \r
134     kStatusGroup_HAL_GPIO = 121,              /*!< Group number for HAL GPIO status codes. */\r
135     kStatusGroup_HAL_UART = 122,              /*!< Group number for HAL UART status codes. */\r
136     kStatusGroup_HAL_TIMER = 123,             /*!< Group number for HAL TIMER status codes. */\r
137     kStatusGroup_HAL_SPI = 124,               /*!< Group number for HAL SPI status codes. */\r
138     kStatusGroup_HAL_I2C = 125,               /*!< Group number for HAL I2C status codes. */\r
139     kStatusGroup_HAL_FLASH = 126,             /*!< Group number for HAL FLASH status codes. */\r
140     kStatusGroup_HAL_PWM = 127,               /*!< Group number for HAL PWM status codes. */\r
141     kStatusGroup_HAL_RNG = 128,               /*!< Group number for HAL RNG status codes. */\r
142     kStatusGroup_TIMERMANAGER = 135,          /*!< Group number for TiMER MANAGER status codes. */\r
143     kStatusGroup_SERIALMANAGER = 136,         /*!< Group number for SERIAL MANAGER status codes. */\r
144     kStatusGroup_LED = 137,                   /*!< Group number for LED status codes. */\r
145     kStatusGroup_BUTTON = 138,                /*!< Group number for BUTTON status codes. */\r
146     kStatusGroup_EXTERN_EEPROM = 139,         /*!< Group number for EXTERN EEPROM status codes. */\r
147     kStatusGroup_SHELL = 140,                 /*!< Group number for SHELL status codes. */\r
148     kStatusGroup_MEM_MANAGER = 141,           /*!< Group number for MEM MANAGER status codes. */\r
149     kStatusGroup_LIST = 142,                  /*!< Group number for List status codes. */\r
150     kStatusGroup_OSA = 143,                   /*!< Group number for OSA status codes. */\r
151     kStatusGroup_COMMON_TASK = 144,           /*!< Group number for Common task status codes. */\r
152     kStatusGroup_MSG = 145,                   /*!< Group number for messaging status codes. */\r
153     kStatusGroup_SDK_OCOTP = 146,             /*!< Group number for OCOTP status codes. */\r
154     kStatusGroup_SDK_FLEXSPINOR = 147,        /*!< Group number for FLEXSPINOR status codes.*/\r
155     kStatusGroup_CODEC = 148,                 /*!< Group number for codec status codes. */\r
156 };\r
157 \r
158 /*! @brief Generic status return codes. */\r
159 enum _generic_status\r
160 {\r
161     kStatus_Success = MAKE_STATUS(kStatusGroup_Generic, 0),\r
162     kStatus_Fail = MAKE_STATUS(kStatusGroup_Generic, 1),\r
163     kStatus_ReadOnly = MAKE_STATUS(kStatusGroup_Generic, 2),\r
164     kStatus_OutOfRange = MAKE_STATUS(kStatusGroup_Generic, 3),\r
165     kStatus_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4),\r
166     kStatus_Timeout = MAKE_STATUS(kStatusGroup_Generic, 5),\r
167     kStatus_NoTransferInProgress = MAKE_STATUS(kStatusGroup_Generic, 6),\r
168 };\r
169 \r
170 /*! @brief Type used for all status and error return values. */\r
171 typedef int32_t status_t;\r
172 \r
173 /*\r
174  * Macro guard for whether to use default weak IRQ implementation in drivers\r
175  */\r
176 #ifndef FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ\r
177 #define FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ 1\r
178 #endif\r
179 \r
180 /*! @name Min/max macros */\r
181 /* @{ */\r
182 #if !defined(MIN)\r
183 #define MIN(a, b) (((a) < (b)) ? (a) : (b))\r
184 #endif\r
185 \r
186 #if !defined(MAX)\r
187 #define MAX(a, b) (((a) > (b)) ? (a) : (b))\r
188 #endif\r
189 /* @} */\r
190 \r
191 /*! @brief Computes the number of elements in an array. */\r
192 #if !defined(ARRAY_SIZE)\r
193 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))\r
194 #endif\r
195 \r
196 /*! @name UINT16_MAX/UINT32_MAX value */\r
197 /* @{ */\r
198 #if !defined(UINT16_MAX)\r
199 #define UINT16_MAX ((uint16_t)-1)\r
200 #endif\r
201 \r
202 #if !defined(UINT32_MAX)\r
203 #define UINT32_MAX ((uint32_t)-1)\r
204 #endif\r
205 /* @} */\r
206 \r
207 /*! @name Timer utilities */\r
208 /* @{ */\r
209 /*! Macro to convert a microsecond period to raw count value */\r
210 #define USEC_TO_COUNT(us, clockFreqInHz) (uint64_t)((uint64_t)us * clockFreqInHz / 1000000U)\r
211 /*! Macro to convert a raw count value to microsecond */\r
212 #define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000000U / clockFreqInHz)\r
213 \r
214 /*! Macro to convert a millisecond period to raw count value */\r
215 #define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)ms * clockFreqInHz / 1000U)\r
216 /*! Macro to convert a raw count value to millisecond */\r
217 #define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000U / clockFreqInHz)\r
218 /* @} */\r
219 \r
220 /*! @name Alignment variable definition macros */\r
221 /* @{ */\r
222 #if (defined(__ICCARM__))\r
223 /**\r
224  * Workaround to disable MISRA C message suppress warnings for IAR compiler.\r
225  * http://supp.iar.com/Support/?note=24725\r
226  */\r
227 _Pragma("diag_suppress=Pm120")\r
228 #define SDK_PRAGMA(x) _Pragma(#x)\r
229     _Pragma("diag_error=Pm120")\r
230 /*! Macro to define a variable with alignbytes alignment */\r
231 #define SDK_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var\r
232 /*! Macro to define a variable with L1 d-cache line size alignment */\r
233 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)\r
234 #define SDK_L1DCACHE_ALIGN(var) SDK_PRAGMA(data_alignment = FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) var\r
235 #endif\r
236 /*! Macro to define a variable with L2 cache line size alignment */\r
237 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)\r
238 #define SDK_L2CACHE_ALIGN(var) SDK_PRAGMA(data_alignment = FSL_FEATURE_L2CACHE_LINESIZE_BYTE) var\r
239 #endif\r
240 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)\r
241 /*! Macro to define a variable with alignbytes alignment */\r
242 #define SDK_ALIGN(var, alignbytes) __attribute__((aligned(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) __attribute__((aligned(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) __attribute__((aligned(FSL_FEATURE_L2CACHE_LINESIZE_BYTE))) var\r
250 #endif\r
251 #elif defined(__GNUC__)\r
252 /*! Macro to define a variable with alignbytes alignment */\r
253 #define SDK_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))\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) var __attribute__((aligned(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)))\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) var __attribute__((aligned(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)))\r
261 #endif\r
262 #else\r
263 #error Toolchain not supported\r
264 #define SDK_ALIGN(var, alignbytes) var\r
265 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)\r
266 #define SDK_L1DCACHE_ALIGN(var) var\r
267 #endif\r
268 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)\r
269 #define SDK_L2CACHE_ALIGN(var) var\r
270 #endif\r
271 #endif\r
272 \r
273 /*! Macro to change a value to a given size aligned value */\r
274 #define SDK_SIZEALIGN(var, alignbytes) \\r
275     ((unsigned int)((var) + ((alignbytes)-1)) & (unsigned int)(~(unsigned int)((alignbytes)-1)))\r
276 /* @} */\r
277 \r
278 /*! @name Non-cacheable region definition macros */\r
279 /* For initialized non-zero non-cacheable variables, please using "AT_NONCACHEABLE_SECTION_INIT(var) ={xx};" or\r
280  * "AT_NONCACHEABLE_SECTION_ALIGN_INIT(var) ={xx};" in your projects to define them, for zero-inited non-cacheable variables,\r
281  * please using "AT_NONCACHEABLE_SECTION(var);" or "AT_NONCACHEABLE_SECTION_ALIGN(var);" to define them, these zero-inited variables\r
282  * will be initialized to zero in system startup.\r
283  */\r
284 /* @{ */\r
285 #if (defined(__ICCARM__))\r
286 #if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))\r
287 #define AT_NONCACHEABLE_SECTION(var) var @"NonCacheable"\r
288 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable"\r
289 #define AT_NONCACHEABLE_SECTION_INIT(var) var @"NonCacheable.init"\r
290 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable.init"\r
291 #else\r
292 #define AT_NONCACHEABLE_SECTION(var) var\r
293 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var\r
294 #define AT_NONCACHEABLE_SECTION_INIT(var) var\r
295 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var\r
296 #endif\r
297 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))\r
298 #if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))\r
299 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable"), zero_init)) var\r
300 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \\r
301     __attribute__((section("NonCacheable"), zero_init)) __attribute__((aligned(alignbytes))) var\r
302 #define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var\r
303 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \\r
304     __attribute__((section("NonCacheable.init"))) __attribute__((aligned(alignbytes))) var\r
305 #else\r
306 #define AT_NONCACHEABLE_SECTION(var) var\r
307 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) __attribute__((aligned(alignbytes))) var\r
308 #define AT_NONCACHEABLE_SECTION_INIT(var) var\r
309 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) __attribute__((aligned(alignbytes))) var\r
310 #endif\r
311 #elif(defined(__GNUC__))\r
312 /* For GCC, when the non-cacheable section is required, please define "__STARTUP_INITIALIZE_NONCACHEDATA"\r
313  * in your projects to make sure the non-cacheable section variables will be initialized in system startup.\r
314  */\r
315 #if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))\r
316 #define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var\r
317 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \\r
318     __attribute__((section("NonCacheable.init"))) var __attribute__((aligned(alignbytes)))\r
319 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable,\"aw\",%nobits @"))) var\r
320 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \\r
321     __attribute__((section("NonCacheable,\"aw\",%nobits @"))) var __attribute__((aligned(alignbytes)))\r
322 #else\r
323 #define AT_NONCACHEABLE_SECTION(var) var\r
324 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))\r
325 #define AT_NONCACHEABLE_SECTION_INIT(var) var\r
326 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) var __attribute__((aligned(alignbytes)))\r
327 #endif\r
328 #else\r
329 #error Toolchain not supported.\r
330 #define AT_NONCACHEABLE_SECTION(var) var\r
331 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) var\r
332 #define AT_NONCACHEABLE_SECTION_INIT(var) var\r
333 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) var\r
334 #endif\r
335 /* @} */\r
336 \r
337 /*! @name Time sensitive region */\r
338 /* @{ */\r
339 #if defined(FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE) && FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE\r
340 #if (defined(__ICCARM__))\r
341 #define AT_QUICKACCESS_SECTION_CODE(func) func @"CodeQuickAccess"\r
342 #define AT_QUICKACCESS_SECTION_DATA(func) func @"DataQuickAccess"\r
343 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))\r
344 #define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"))) func\r
345 #define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func\r
346 #elif(defined(__GNUC__))\r
347 #define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"))) func\r
348 #define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func\r
349 #else\r
350 #error Toolchain not supported.\r
351 #endif /* defined(__ICCARM__) */\r
352 #else\r
353 #if (defined(__ICCARM__))\r
354 #define AT_QUICKACCESS_SECTION_CODE(func) func\r
355 #define AT_QUICKACCESS_SECTION_DATA(func) func\r
356 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))\r
357 #define AT_QUICKACCESS_SECTION_CODE(func) func\r
358 #define AT_QUICKACCESS_SECTION_DATA(func) func\r
359 #elif(defined(__GNUC__))\r
360 #define AT_QUICKACCESS_SECTION_CODE(func) func\r
361 #define AT_QUICKACCESS_SECTION_DATA(func) func\r
362 #else\r
363 #error Toolchain not supported.\r
364 #endif\r
365 #endif /* __FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE */\r
366 /* @} */\r
367 \r
368 /*! @name Ram Function */\r
369 #if (defined(__ICCARM__))\r
370 #define RAMFUNCTION_SECTION_CODE(func) func @"RamFunction"\r
371 #elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))\r
372 #define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func\r
373 #elif(defined(__GNUC__))\r
374 #define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func\r
375 #else\r
376 #error Toolchain not supported.\r
377 #endif /* defined(__ICCARM__) */\r
378 /* @} */\r
379 \r
380 /*\r
381  * The fsl_clock.h is included here because it needs MAKE_VERSION/MAKE_STATUS/status_t\r
382  * defined in previous of this file.\r
383  */\r
384 #include "fsl_clock.h"\r
385 \r
386 /*\r
387  * Chip level peripheral reset API, for MCUs that implement peripheral reset control external to a peripheral\r
388  */\r
389 #if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \\r
390      (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0)))\r
391 #include "fsl_reset.h"\r
392 #endif\r
393 \r
394 /*******************************************************************************\r
395  * API\r
396  ******************************************************************************/\r
397 \r
398 #if defined(__cplusplus)\r
399         extern "C"\r
400 {\r
401 #endif\r
402 \r
403     /*!\r
404      * @brief Enable specific interrupt.\r
405      *\r
406      * Enable LEVEL1 interrupt. For some devices, there might be multiple interrupt\r
407      * levels. For example, there are NVIC and intmux. Here the interrupts connected\r
408      * to NVIC are the LEVEL1 interrupts, because they are routed to the core directly.\r
409      * The interrupts connected to intmux are the LEVEL2 interrupts, they are routed\r
410      * to NVIC first then routed to core.\r
411      *\r
412      * This function only enables the LEVEL1 interrupts. The number of LEVEL1 interrupts\r
413      * is indicated by the feature macro FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS.\r
414      *\r
415      * @param interrupt The IRQ number.\r
416      * @retval kStatus_Success Interrupt enabled successfully\r
417      * @retval kStatus_Fail Failed to enable the interrupt\r
418      */\r
419     static inline status_t EnableIRQ(IRQn_Type interrupt)\r
420     {\r
421         if (NotAvail_IRQn == interrupt)\r
422         {\r
423             return kStatus_Fail;\r
424         }\r
425 \r
426 #if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)\r
427         if (interrupt >= FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)\r
428         {\r
429             return kStatus_Fail;\r
430         }\r
431 #endif\r
432 \r
433 #if defined(__GIC_PRIO_BITS)\r
434         GIC_EnableIRQ(interrupt);\r
435 #else\r
436         NVIC_EnableIRQ(interrupt);\r
437 #endif\r
438         return kStatus_Success;\r
439     }\r
440 \r
441     /*!\r
442      * @brief Disable specific interrupt.\r
443      *\r
444      * Disable LEVEL1 interrupt. For some devices, there might be multiple interrupt\r
445      * levels. For example, there are NVIC and intmux. Here the interrupts connected\r
446      * to NVIC are the LEVEL1 interrupts, because they are routed to the core directly.\r
447      * The interrupts connected to intmux are the LEVEL2 interrupts, they are routed\r
448      * to NVIC first then routed to core.\r
449      *\r
450      * This function only disables the LEVEL1 interrupts. The number of LEVEL1 interrupts\r
451      * is indicated by the feature macro FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS.\r
452      *\r
453      * @param interrupt The IRQ number.\r
454      * @retval kStatus_Success Interrupt disabled successfully\r
455      * @retval kStatus_Fail Failed to disable the interrupt\r
456      */\r
457     static inline status_t DisableIRQ(IRQn_Type interrupt)\r
458     {\r
459         if (NotAvail_IRQn == interrupt)\r
460         {\r
461             return kStatus_Fail;\r
462         }\r
463 \r
464 #if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)\r
465         if (interrupt >= FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)\r
466         {\r
467             return kStatus_Fail;\r
468         }\r
469 #endif\r
470 \r
471 #if defined(__GIC_PRIO_BITS)\r
472         GIC_DisableIRQ(interrupt);\r
473 #else\r
474     NVIC_DisableIRQ(interrupt);\r
475 #endif\r
476         return kStatus_Success;\r
477     }\r
478 \r
479     /*!\r
480      * @brief Disable the global IRQ\r
481      *\r
482      * Disable the global interrupt and return the current primask register. User is required to provided the primask\r
483      * register for the EnableGlobalIRQ().\r
484      *\r
485      * @return Current primask value.\r
486      */\r
487     static inline uint32_t DisableGlobalIRQ(void)\r
488     {\r
489 #if defined (__XCC__)\r
490         return 0;\r
491 #else\r
492 #if defined(CPSR_I_Msk)\r
493         uint32_t cpsr = __get_CPSR() & CPSR_I_Msk;\r
494 \r
495         __disable_irq();\r
496 \r
497         return cpsr;\r
498 #else\r
499     uint32_t regPrimask = __get_PRIMASK();\r
500 \r
501     __disable_irq();\r
502 \r
503     return regPrimask;\r
504 #endif\r
505 #endif\r
506     }\r
507 \r
508     /*!\r
509      * @brief Enable the global IRQ\r
510      *\r
511      * Set the primask register with the provided primask value but not just enable the primask. The idea is for the\r
512      * convenience of integration of RTOS. some RTOS get its own management mechanism of primask. User is required to\r
513      * use the EnableGlobalIRQ() and DisableGlobalIRQ() in pair.\r
514      *\r
515      * @param primask value of primask register to be restored. The primask value is supposed to be provided by the\r
516      * DisableGlobalIRQ().\r
517      */\r
518     static inline void EnableGlobalIRQ(uint32_t primask)\r
519     {\r
520 #if defined (__XCC__)\r
521 #else\r
522 #if defined(CPSR_I_Msk)\r
523         __set_CPSR((__get_CPSR() & ~CPSR_I_Msk) | primask);\r
524 #else\r
525     __set_PRIMASK(primask);\r
526 #endif\r
527 #endif\r
528     }\r
529 \r
530 #if defined(ENABLE_RAM_VECTOR_TABLE)\r
531     /*!\r
532      * @brief install IRQ handler\r
533      *\r
534      * @param irq IRQ number\r
535      * @param irqHandler IRQ handler address\r
536      * @return The old IRQ handler address\r
537      */\r
538     uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler);\r
539 #endif /* ENABLE_RAM_VECTOR_TABLE. */\r
540 \r
541 #if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))\r
542     /*!\r
543      * @brief Enable specific interrupt for wake-up from deep-sleep mode.\r
544      *\r
545      * Enable the interrupt for wake-up from deep sleep mode.\r
546      * Some interrupts are typically used in sleep mode only and will not occur during\r
547      * deep-sleep mode because relevant clocks are stopped. However, it is possible to enable\r
548      * those clocks (significantly increasing power consumption in the reduced power mode),\r
549      * making these wake-ups possible.\r
550      *\r
551      * @note This function also enables the interrupt in the NVIC (EnableIRQ() is called internaly).\r
552      *\r
553      * @param interrupt The IRQ number.\r
554      */\r
555     void EnableDeepSleepIRQ(IRQn_Type interrupt);\r
556 \r
557     /*!\r
558      * @brief Disable specific interrupt for wake-up from deep-sleep mode.\r
559      *\r
560      * Disable the interrupt for wake-up from deep sleep mode.\r
561      * Some interrupts are typically used in sleep mode only and will not occur during\r
562      * deep-sleep mode because relevant clocks are stopped. However, it is possible to enable\r
563      * those clocks (significantly increasing power consumption in the reduced power mode),\r
564      * making these wake-ups possible.\r
565      *\r
566      * @note This function also disables the interrupt in the NVIC (DisableIRQ() is called internaly).\r
567      *\r
568      * @param interrupt The IRQ number.\r
569      */\r
570     void DisableDeepSleepIRQ(IRQn_Type interrupt);\r
571 #endif /* FSL_FEATURE_SOC_SYSCON_COUNT */\r
572 \r
573     /*!\r
574      * @brief Allocate memory with given alignment and aligned size.\r
575      *\r
576      * This is provided to support the dynamically allocated memory\r
577      * used in cache-able region.\r
578      * @param size The length required to malloc.\r
579      * @param alignbytes The alignment size.\r
580      * @retval The allocated memory.\r
581      */\r
582     void *SDK_Malloc(size_t size, size_t alignbytes);\r
583 \r
584     /*!\r
585      * @brief Free memory.\r
586      *\r
587      * @param ptr The memory to be release.\r
588      */\r
589     void SDK_Free(void *ptr);\r
590 \r
591 #if defined(__cplusplus)\r
592 }\r
593 #endif\r
594 \r
595 /*! @} */\r
596 \r
597 #endif /* _FSL_COMMON_H_ */\r