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