MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
The MCUXpresso SDK provides a driver for the common module of MCUXpresso SDK devices.
Driver Overview | |
Driver Change Log | |
The current COMMON driver version is 2.0.0. | |
Macros | |
#define | MAKE_STATUS(group, code) ((((group)*100UL) + (code))) |
Construct a status code value from a group and code number. More... | |
#define | MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix)) |
Construct the version number for drivers. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_NONE 0U |
No debug console. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_UART 1U |
Debug console based on UART. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_LPUART 2U |
Debug console based on LPUART. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_LPSCI 3U |
Debug console based on LPSCI. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_USBCDC 4U |
Debug console based on USBCDC. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_FLEXCOMM 5U |
Debug console based on FLEXCOMM. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_IUART 6U |
Debug console based on i.MX UART. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_VUSART 7U |
Debug console based on LPC_VUSART. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_MINI_USART 8U |
Debug console based on LPC_USART. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_SWO 9U |
Debug console based on SWO. More... | |
#define | DEBUG_CONSOLE_DEVICE_TYPE_QSCI 10U |
Debug console based on QSCI. More... | |
#define | ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
Computes the number of elements in an array. More... | |
#define | SDK_DSC_DEFAULT_INT_PRIO 1U |
Default DSC interrupt priority number. More... | |
#define | SetIRQBasePriority(x) __EI##x() |
Set base core IRQ priority, that core will response the interrupt request with priority >= base IRQ priority. More... | |
#define | PeriphReadReg(reg) (reg) |
Read register value. More... | |
#define | PeriphWriteReg(reg, data) (reg) = (data) |
Write data to register. More... | |
#define | PeriphSetBits(reg, bitMask) (reg) |= (bitMask) |
Set specified bits in register. More... | |
#define | PeriphClearBits(reg, bitMask) (reg) &= (~(bitMask)) |
Clear specified bits in register. More... | |
#define | PeriphInvertBits(reg, bitMask) (reg) ^= (bitMask) |
Invert specified bits in register. More... | |
#define | PeriphGetBits(reg, bitMask) ( (reg) & (bitMask) ) |
Get specified bits in register. More... | |
#define | PeriphWriteBitGroup(reg, bitMask, bitValue) (reg) = ((reg) & ~(bitMask)) | ((bitValue) & (bitMask)) |
Write group of bits to register. More... | |
#define | PeriphSafeClearFlags(reg, allFlagsMask, flagMask) (reg) = ((reg) & (~(allFlagsMask))) | ((flagMask) & (allFlagsMask)) |
Clear (acknowledge) flags which are active-high and are cleared-by-write-one. More... | |
#define | PeriphSafeClearBits(reg, allFlagsMask, bitMask) (reg) = ((reg) & (~((allFlagsMask) | (bitMask)))) |
Clear selected bits without modifying (acknowledge) bit flags which are active-high and are cleared-by-write-one. More... | |
#define | PeriphSafeSetBits(reg, allFlagsMask, bitMask) (reg) = ((reg) & (~(allFlagsMask))) | ((bitMask) & (~(allFlagsMask))) |
Set selected bits without modifying (acknowledge) bit flags which are active-high and are cleared-by-write-one. More... | |
#define | PeriphSafeWriteBitGroup(reg, allFlagsMask, bitMask, bitValue) (reg) = ((reg) & (~((allFlagsMask)|(bitMask)))) | ((bitValue) & (bitMask) & (~(allFlagsMask))) |
Write group of bits without modifying (acknowledge) bit flags which are active-high and are cleared-by-write-one. More... | |
Typedefs | |
typedef int32_t | status_t |
Type used for all status and error return values. More... | |
Functions | |
void * | SDK_Malloc (size_t size, size_t alignbytes) |
Allocate memory with given alignment and aligned size. More... | |
void | SDK_Free (void *ptr) |
Free memory. More... | |
void | SDK_DelayCoreCycles (uint32_t u32Num) |
Delay core cycles. More... | |
void | SDK_DelayAtLeastUs (uint32_t delay_us, uint32_t coreClock_Hz) |
Delay at least for some time. More... | |
Driver version | |
#define | FSL_COMMON_DRIVER_VERSION (MAKE_VERSION(1, 0, 0)) |
common driver version 2.2.2. More... | |
Min/max macros | |
#define | MIN(a, b) (((a) < (b)) ? (a) : (b)) |
#define | MAX(a, b) (((a) > (b)) ? (a) : (b)) |
UINT16_MAX/UINT32_MAX value | |
#define | UINT16_MAX ((uint16_t)-1) |
#define | UINT32_MAX ((uint32_t)-1) |
Timer utilities | |
#define | USEC_TO_COUNT(us, clockFreqInHz) (uint32_t)(((float)clockFreqInHz / 1000000U) * us) |
Macro to convert a microsecond period to raw count value. | |
#define | COUNT_TO_USEC(count, clockFreqInHz) (uint32_t)(((float)count / clockFreqInHz) * 1000000U) |
Macro to convert a raw count value to microsecond. | |
#define | MSEC_TO_COUNT(ms, clockFreqInHz) (uint32_t)(((float)clockFreqInHz / 1000U) * ms) |
Macro to convert a millisecond period to raw count value. | |
#define | COUNT_TO_MSEC(count, clockFreqInHz) (uint32_t)(((float)count / clockFreqInHz) * 1000U) |
Macro to convert a raw count value to millisecond. | |
Alignment variable definition macros | |
#define | SDK_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes))) |
Macro to define a variable with alignbytes alignment. | |
#define | SDK_SIZEALIGN(var, alignbytes) ((unsigned int)((var) + ((alignbytes)-1U)) & (unsigned int)(~(unsigned int)((alignbytes)-1U))) |
Macro to change a value to a given size aligned value. | |
#define | AT_NONCACHEABLE_SECTION(var) var |
#define | AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes))) |
#define | AT_NONCACHEABLE_SECTION_INIT(var) var |
#define | AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) var __attribute__((aligned(alignbytes))) |
Interrupt | |
DSC interrupt controller uses the same bit-filed to control interrupt enable status and priority, to provide compatible APIs, SDK uses a interrupt priority table, thus application could control the interrupt enable/disable, and interrupt priority independently. Also, the API EnableIRQWithPriority could be used to enable the interrupt and set the priority at the same time. API implementation:
The interrupt functions configure INTC module, application could call the INTC driver directly for the same purpose. | |
status_t | EnableIRQWithPriority (IRQn_Type irq, uint8_t priNum) |
Enable the IRQ, and also set the interrupt priority. More... | |
status_t | DisableIRQ (IRQn_Type irq) |
Disable specific interrupt. More... | |
status_t | EnableIRQ (IRQn_Type irq) |
Enable specific interrupt. More... | |
status_t | IRQ_SetPriority (IRQn_Type irq, uint8_t priNum) |
Set the IRQ priority. More... | |
static uint32_t | DisableGlobalIRQ (void) |
Disable the global IRQ. | |
static void | EnableGlobalIRQ (uint32_t irqSts) |
Enable the global IRQ. | |
static bool | isIRQAllowed (void) |
Check if currently core is able to response IRQ. | |
#define MAKE_STATUS | ( | group, | |
code | |||
) | ((((group)*100UL) + (code))) |
#define MAKE_VERSION | ( | major, | |
minor, | |||
bugfix | |||
) | (((major) << 16) | ((minor) << 8) | (bugfix)) |
#define FSL_COMMON_DRIVER_VERSION (MAKE_VERSION(1, 0, 0)) |
#define DEBUG_CONSOLE_DEVICE_TYPE_NONE 0U |
#define DEBUG_CONSOLE_DEVICE_TYPE_UART 1U |
#define DEBUG_CONSOLE_DEVICE_TYPE_LPUART 2U |
#define DEBUG_CONSOLE_DEVICE_TYPE_LPSCI 3U |
#define DEBUG_CONSOLE_DEVICE_TYPE_USBCDC 4U |
#define DEBUG_CONSOLE_DEVICE_TYPE_FLEXCOMM 5U |
#define DEBUG_CONSOLE_DEVICE_TYPE_IUART 6U |
#define DEBUG_CONSOLE_DEVICE_TYPE_VUSART 7U |
#define DEBUG_CONSOLE_DEVICE_TYPE_MINI_USART 8U |
#define DEBUG_CONSOLE_DEVICE_TYPE_SWO 9U |
#define DEBUG_CONSOLE_DEVICE_TYPE_QSCI 10U |
#define ARRAY_SIZE | ( | x | ) | (sizeof(x) / sizeof((x)[0])) |
#define SDK_DSC_DEFAULT_INT_PRIO 1U |
#define SetIRQBasePriority | ( | x | ) | __EI##x() |
#define PeriphReadReg | ( | reg | ) | (reg) |
Example: val = PeriphReadReg(OCCS->OSCTL2);
reg | Register name. |
#define PeriphWriteReg | ( | reg, | |
data | |||
) | (reg) = (data) |
Example: PeriphWriteReg(OCCS->OSCTL2, 0x278U);
reg | Register name. |
data | Data wrote to register. |
#define PeriphSetBits | ( | reg, | |
bitMask | |||
) | (reg) |= (bitMask) |
Example: PeriphSetBits(OCCS->OSCTL2, 0x12U);
reg | Register name. |
bitMask | Bits mask, set bits will be set in the register. |
#define PeriphClearBits | ( | reg, | |
bitMask | |||
) | (reg) &= (~(bitMask)) |
Example: PeriphClearBits(OCCS->OSCTL2, 0x12U);
reg | Register name. |
bitMask | Bits mask, set bits will be cleared in the register. |
#define PeriphInvertBits | ( | reg, | |
bitMask | |||
) | (reg) ^= (bitMask) |
Example: PeriphInvertBits(OCCS->OSCTL2, 0x12U);
reg | Register name. |
bitMask | Bits mask, set bits will be inverted in the register. |
#define PeriphGetBits | ( | reg, | |
bitMask | |||
) | ( (reg) & (bitMask) ) |
Example: val = PeriphGetBits(OCCS->OSCTL2, 0x23U);
reg | Register name. |
bitMask | Bits mask, specify the getting bits. |
#define PeriphWriteBitGroup | ( | reg, | |
bitMask, | |||
bitValue | |||
) | (reg) = ((reg) & ~(bitMask)) | ((bitValue) & (bitMask)) |
Example: PeriphWriteBitGroup(OCCS->DIVBY, OCCS_DIVBY_COD_MASK, OCCS_DIVBY_COD(23U)); PeriphWriteBitGroup(OCCS->DIVBY, OCCS_DIVBY_COD_MASK | OCCS_DIVBY_PLLDB_MASK, \ OCCS_DIVBY_COD(23U) | OCCS_DIVBY_PLLDB(49U));
reg | Register name. |
bitMask | Bits mask, mask of the group of bits. |
bitValue | This value will be written into the bit group specified by parameter bitMask. |
#define PeriphSafeClearFlags | ( | reg, | |
allFlagsMask, | |||
flagMask | |||
) | (reg) = ((reg) & (~(allFlagsMask))) | ((flagMask) & (allFlagsMask)) |
This macro is useful when a register is comprised by normal read-write bits and cleared-by-write-one bits. Example: PeriphSafeClearFlags(PWMA->FAULT[0].FSTS, PWM_FSTS_FFLAG_MASK, PWM_FSTS_FFLAG(2));
reg | Register name. |
allFlagsMask | Mask for all flags which are active-high and are cleared-by-write-one. |
flagMask | The selected flags(cleared-by-write-one) which are supposed to be cleared. |
#define PeriphSafeClearBits | ( | reg, | |
allFlagsMask, | |||
bitMask | |||
) | (reg) = ((reg) & (~((allFlagsMask) | (bitMask)))) |
This macro is useful when a register is comprised by normal read-write bits and cleared-by-write-one bits. Example: PeriphSafeClearBits(PWMA->FAULT[0].FSTS, PWM_FSTS_FFLAG_MASK, PWM_FSTS_FHALF(2));
reg | Register name. |
allFlagsMask | Mask for all flags which are active-high and are cleared-by-write-one. |
bitMask | The selected bits which are supposed to be cleared. |
#define PeriphSafeSetBits | ( | reg, | |
allFlagsMask, | |||
bitMask | |||
) | (reg) = ((reg) & (~(allFlagsMask))) | ((bitMask) & (~(allFlagsMask))) |
This macro is useful when a register is comprised by normal read-write bits and cleared-by-write-one bits. Example: PeriphSafeSetBits(PWMA->FAULT[0].FSTS, PWM_FSTS_FFLAG_MASK, PWM_FSTS_FHALF(2));
reg | Register name. |
allFlagsMask | Mask for all flags which are active-high and are cleared-by-write-one. |
bitMask | The selected bits which are supposed to be set. |
#define PeriphSafeWriteBitGroup | ( | reg, | |
allFlagsMask, | |||
bitMask, | |||
bitValue | |||
) | (reg) = ((reg) & (~((allFlagsMask)|(bitMask)))) | ((bitValue) & (bitMask) & (~(allFlagsMask))) |
This macro is useful when a register is comprised by normal read-write bits and cleared-by-write-one bits. Example: PeriphSafeWriteBitGroup(PWMA->FAULT[0].FSTS, PWM_FSTS_FFLAG_MASK, PWM_FSTS_FHALF_MASK, PWM_FSTS_FHALF(3U)); PeriphSafeWriteBitGroup(PWMA->FAULT[0].FSTS, PWM_FSTS_FFLAG_MASK, PWM_FSTS_FHALF_MASK | PWM_FSTS_FFULL_MASK, \ PWM_FSTS_FHALF(3U) | PWM_FSTS_FFULL(2U));
reg | Register name. |
allFlagsMask | Mask for all flags which are active-high and are cleared-by-write-one. |
bitMask | Bits mask, mask of the group of bits. |
bitValue | This value will be written into the bit group specified by parameter bitMask. |
typedef int32_t status_t |
enum _status_groups |
anonymous enum |
status_t EnableIRQWithPriority | ( | IRQn_Type | irq, |
uint8_t | priNum | ||
) |
priNum
is range in 1~3, and its value is NOT directly map to interrupt priority.User should check chip's RM to get its corresponding interrupt priority.
When priNum
set as 0, then SDK_DSC_DEFAULT_INT_PRIO is set instead. When priNum
set as number larger than 3, then only the 2 LSB take effect, for example, setting priNum
to 5 is the same with setting it to 1.
This function configures INTC module, application could call the INTC driver directly for the same purpose.
irq | The IRQ to enable. |
priNum | Priority number set to interrupt controller register. Larger number means higher priority. The allowed range is 1~3, and its value is NOT directly map to interrupt priority. In other words, the same priority number means different interrupt priority levels for different IRQ, please check reference manual for the relationship. When pass in 0, then SDK_DSC_DEFAULT_INT_PRIO is set to priority register. |
status_t DisableIRQ | ( | IRQn_Type | irq | ) |
This function configures INTC module, application could call the INTC driver directly for the same purpose.
irq | The IRQ to disable. |
status_t EnableIRQ | ( | IRQn_Type | irq | ) |
The recommended workflow is calling IRQ_SetPriority first, then call EnableIRQ. If IRQ_SetPriority is not called first, then the interrupt is enabled with default priority value SDK_DSC_DEFAULT_INT_PRIO.
Another recommended workflow is calling EnableIRQWithPriority directly, it is the same with calling IRQ_SetPriority + EnableIRQ.
This function configures INTC module, application could call the INTC driver directly for the same purpose.
irq | The IRQ to enable. |
status_t IRQ_SetPriority | ( | IRQn_Type | irq, |
uint8_t | priNum | ||
) |
priNum
is range in 1~3, and its value is NOT directly map to interrupt priority.User should check chip's RM to get its corresponding interrupt priority
When priNum
set as 0, then SDK_DSC_DEFAULT_INT_PRIO is set instead. When priNum
set as number larger than 3, then only the 2 LSB take effect, for example, setting priNum
to 5 is the same with setting it to 1.
This function configures INTC module, application could call the INTC driver directly for the same purpose.
irq | The IRQ to set. |
priNum | Priority number set to interrupt controller register. Larger number means higher priority, 0 means disable the interrupt. The allowed range is 0~3, and its value is NOT directly map to interrupt priority. In other words, the same priority number means different interrupt priority levels for different IRQ, please check reference manual for the relationship. |
void* SDK_Malloc | ( | size_t | size, |
size_t | alignbytes | ||
) |
This is provided to support the dynamically allocated memory used in cache-able region.
size | The length required to malloc. |
alignbytes | The alignment size. |
The | allocated memory. |
void SDK_Free | ( | void * | ptr | ) |
ptr | The memory to be release. |
void SDK_DelayCoreCycles | ( | uint32_t | u32Num | ) |
Please note that, this API uses software loop for delay, the actual delayed time depends on core clock frequency, where the function is located (ram or flash), flash clock, possible interrupt.
u32Num | Number of core clock cycle which needs to be delayed. |
void SDK_DelayAtLeastUs | ( | uint32_t | delay_us, |
uint32_t | coreClock_Hz | ||
) |
Please note that, this API uses while loop for delay, different run-time environments make the time not precise, if precise delay count was needed, please implement a new delay function with hardware timer.
delay_us | Delay time in unit of microsecond. |
coreClock_Hz | Core clock frequency with Hz. |