SDK API Reference Manual LPC5460x_v2.0.0 (2)
SDK API Reference Manual LPC5460x_v2.0.0 (2)
NXP Semiconductors
Chapter Trademarks
5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
8.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
9.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
9.4 Semihosting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
9.4.1 Guide Semihosting for IAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
9.4.2 Guide Semihosting for Keil µVision . . . . . . . . . . . . . . . . . . . . . . . . . 77
9.4.3 Guide Semihosting for KDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
9.4.4 Guide Semihosting for ATL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
9.4.5 Guide Semihosting for ARMGCC . . . . . . . . . . . . . . . . . . . . . . . . . . 80
10.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
11.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
PUBWEAK SPI0_IRQHandler
PUBWEAK SPI0_DriverIRQHandler
SPI0_IRQHandler
The first level of the weak implementation are the functions defined in the vector table. In the devices/<-
DEVICE_NAME>/<TOOLCHAIN>/startup_<DEVICE_NAME>.s/.S file, the implementation of the
first layer weak function calls the second layer of weak function. The implementation of the second layer
weak function (ex. SPI0_DriverIRQHandler) jumps to itself (B .). The KSDK drivers with transactional
APIs provide the reimplementation of the second layer function inside of the peripheral driver. If the
KSDK drivers with transactional APIs are linked into the image, the SPI0_DriverIRQHandler is replaced
with the function implemented in the KSDK SPI driver.
The reason for implementing the double weak functions is to provide a better user experience when using
the transactional APIs. For drivers with a transactional function, call the transactional APIs and the drivers
complete the interrupt-driven flow. Users are not required to redefine the vector entries out of the box.
At the same time, if users are not satisfied by the second layer weak function implemented in the KS-
DK drivers, users can redefine the first layer weak function and implement their own interrupt handler
functions to suit their implementation.
The limitation of the double weak mechanism is that it cannot be used for peripherals that share the same
vector entry. For this use case, redefine the first layer weak function to enable the desired peripheral
interrupt functionality. For example, if the MCU’s UART0 and UART1 share the same vector entry,
redefine the UART0_UART1_IRQHandler according to the use case requirements.
Feature Header Files
The peripheral drivers are designed to be reusable regardless of the peripheral functional differences from
one Kinetis MCU device to another. An overall Peripheral Feature Header File is provided for the KSD-
K-supported MCU device to define the features or configuration differences for each Kinetis sub-family
device.
Application
See the Getting Started with Kinetis SDK (KSDK) v2.0 document (KSDK20GSUG).
void main(void)
{
adc_config_t adcConfigStruct;
adc_conv_seq_config_t adcConvSeqConfigStruct;
/* Calibration. */
if (ADC_DoSelfCalibration(DEMO_ADC_BASE))
{
PRINTF("ADC_DoSelfCalibration() Done.\r\n");
}
else
{
PRINTF("ADC_DoSelfCalibration() Failed.\r\n");
}
PRINTF("Configuration Done.\r\n");
while (1)
{
/* Get the input from terminal and trigger the converter by software. */
GETCHAR();
ADC_DoSoftwareTriggerConvSeqA(DEMO_ADC_BASE);
/* Global variables. */
static adc_result_info_t gAdcResultInfoStruct;
adc_result_info_t *volatile gAdcResultInfoPtr = &gAdcResultInfoStruct;
volatile bool gAdcConvSeqAIntFlag;
void main(void)
{
adc_config_t adcConfigStruct;
adc_conv_seq_config_t adcConvSeqConfigStruct;
/* Calibration. */
if (ADC_DoSelfCalibration(DEMO_ADC_BASE))
{
PRINTF("ADC_DoSelfCalibration() Done.\r\n");
}
else
{
PRINTF("ADC_DoSelfCalibration() Failed.\r\n");
}
ADC_EnableInterrupts(DEMO_ADC_BASE,
kADC_ConvSeqAInterruptEnable); /* Enable the interrupt
the for sequence A done. */
NVIC_EnableIRQ(DEMO_ADC_IRQ_ID);
PRINTF("Configuration Done.\r\n");
while (1)
{
GETCHAR();
gAdcConvSeqAIntFlag = false;
ADC_DoSoftwareTriggerConvSeqA(DEMO_ADC_BASE);
while (!gAdcConvSeqAIntFlag)
{
}
PRINTF("gAdcResultInfoStruct.result = %d\r\n", gAdcResultInfoStruct.
result);
PRINTF("gAdcResultInfoStruct.channelNumber = %d\r\n", gAdcResultInfoStruct.
channelNumber);
PRINTF("gAdcResultInfoStruct.overrunFlag = %d\r\n", gAdcResultInfoStruct.
overrunFlag ? 1U : 0U);
PRINTF("\r\n");
}
}
/*
ISR for ADC conversion sequence A done.
*/
void DEMO_ADC_IRQ_HANDLER_FUNC(void)
{
if (kADC_ConvSeqAInterruptFlag == (
kADC_ConvSeqAInterruptFlag & ADC_GetStatusFlags(DEMO_ADC_BASE))
)
{
ADC_GetChannelConversionResult(DEMO_ADC_BASE,
DEMO_ADC_SAMPLE_CHANNEL_NUMBER, gAdcResultInfoPtr);
ADC_ClearStatusFlags(DEMO_ADC_BASE,
kADC_ConvSeqAInterruptFlag);
gAdcConvSeqAIntFlag = true;
}
}
Files
• file fsl_adc.h
Data Structures
• struct adc_config_t
Define structure for configuring the block. More...
• struct adc_conv_seq_config_t
Define structure for configuring conversion sequence. More...
• struct adc_result_info_t
Define structure of keeping conversion result information. More...
Enumerations
• enum _adc_status_flags {
kADC_ThresholdCompareFlagOnChn0 = 1U << 0U,
kADC_ThresholdCompareFlagOnChn1 = 1U << 1U,
kADC_ThresholdCompareFlagOnChn2 = 1U << 2U,
kADC_ThresholdCompareFlagOnChn3 = 1U << 3U,
kADC_ThresholdCompareFlagOnChn4 = 1U << 4U,
kADC_ThresholdCompareFlagOnChn5 = 1U << 5U,
kADC_ThresholdCompareFlagOnChn6 = 1U << 6U,
kADC_ThresholdCompareFlagOnChn7 = 1U << 7U,
kADC_ThresholdCompareFlagOnChn8 = 1U << 8U,
kADC_ThresholdCompareFlagOnChn9 = 1U << 9U,
kADC_ThresholdCompareFlagOnChn10 = 1U << 10U,
kADC_ThresholdCompareFlagOnChn11 = 1U << 11U,
kADC_OverrunFlagForChn0,
kADC_OverrunFlagForChn1,
kADC_OverrunFlagForChn2,
kADC_OverrunFlagForChn3,
kADC_OverrunFlagForChn4,
kADC_OverrunFlagForChn5,
kADC_OverrunFlagForChn6,
kADC_OverrunFlagForChn7,
kADC_OverrunFlagForChn8,
kADC_OverrunFlagForChn9,
kADC_OverrunFlagForChn10,
kADC_OverrunFlagForChn11,
kADC_GlobalOverrunFlagForSeqA = 1U << 24U,
kADC_GlobalOverrunFlagForSeqB = 1U << 25U,
kADC_ConvSeqAInterruptFlag = 1U << 28U,
kADC_ConvSeqBInterruptFlag = 1U << 29U,
kADC_ThresholdCompareInterruptFlag = 1U << 30U,
kADC_OverrunInterruptFlag = 1U << 31U }
Flags.
• enum _adc_interrupt_enable {
kADC_ConvSeqAInterruptEnable = ADC_INTEN_SEQA_INTEN_MASK,
kADC_ConvSeqBInterruptEnable = ADC_INTEN_SEQB_INTEN_MASK,
kADC_OverrunInterruptEnable = ADC_INTEN_OVR_INTEN_MASK }
Interrupts.
• enum adc_clock_mode_t {
kADC_ClockSynchronousMode,
kADC_ClockAsynchronousMode = 1U }
Define selection of clock mode.
• enum adc_resolution_t {
kADC_Resolution6bit = 0U,
kADC_Resolution8bit = 1U,
kADC_Resolution10bit = 2U,
kADC_Resolution12bit = 3U }
Define selection of resolution.
• enum adc_trigger_polarity_t {
kADC_TriggerPolarityNegativeEdge = 0U,
kADC_TriggerPolarityPositiveEdge = 1U }
Define selection of polarity of selected input trigger for conversion sequence.
• enum adc_priority_t {
kADC_PriorityLow = 0U,
kADC_PriorityHigh = 1U }
Define selection of conversion sequence’s priority.
• enum adc_seq_interrupt_mode_t {
kADC_InterruptForEachConversion = 0U,
kADC_InterruptForEachSequence = 1U }
Define selection of conversion sequence’s interrupt.
• enum adc_threshold_compare_status_t {
kADC_ThresholdCompareInRange = 0U,
kADC_ThresholdCompareBelowRange = 1U,
kADC_ThresholdCompareAboveRange = 2U }
Define status of threshold compare result.
• enum adc_threshold_crossing_status_t {
kADC_ThresholdCrossingNoDetected = 0U,
kADC_ThresholdCrossingDownward = 2U,
kADC_ThresholdCrossingUpward = 3U }
Define status of threshold crossing detection result.
• enum adc_threshold_interrupt_mode_t {
kADC_ThresholdInterruptDisabled = 0U,
kADC_ThresholdInterruptOnOutside = 1U,
kADC_ThresholdInterruptOnCrossing = 2U }
Define interrupt mode for threshold compare event.
Driver version
• #define LPC_ADC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
ADC driver version 2.0.0.
Data result.
• bool ADC_GetConvSeqAGlobalConversionResult (ADC_Type ∗base, adc_result_info_t ∗info)
Get the global ADC conversion infomation of sequence A.
• bool ADC_GetConvSeqBGlobalConversionResult (ADC_Type ∗base, adc_result_info_t ∗info)
Get the global ADC conversion infomation of sequence B.
• bool ADC_GetChannelConversionResult (ADC_Type ∗base, uint32_t channel, adc_result_info_t
∗info)
Get the channel’s ADC conversion completed under each conversion sequence.
Threshold function.
• static void ADC_SetThresholdPair0 (ADC_Type ∗base, uint32_t lowValue, uint32_t highValue)
Set the threshhold pair 0 with low and high value.
• static void ADC_SetThresholdPair1 (ADC_Type ∗base, uint32_t lowValue, uint32_t highValue)
Set the threshhold pair 1 with low and high value.
• static void ADC_SetChannelWithThresholdPair0 (ADC_Type ∗base, uint32_t channelMask)
Set given channels to apply the threshold pare 0.
• static void ADC_SetChannelWithThresholdPair1 (ADC_Type ∗base, uint32_t channelMask)
Set given channels to apply the threshold pare 1.
Interrupts.
• static void ADC_EnableInterrupts (ADC_Type ∗base, uint32_t mask)
Enable interrupts for conversion sequences.
• static void ADC_DisableInterrupts (ADC_Type ∗base, uint32_t mask)
Disable interrupts for conversion sequence.
• static void ADC_EnableShresholdCompareInterrupt (ADC_Type ∗base, uint32_t channel, adc_-
threshold_interrupt_mode_t mode)
Enable the interrupt of shreshold compare event for each channel.
Status.
• static uint32_t ADC_GetStatusFlags (ADC_Type ∗base)
Get status flags of ADC module.
• static void ADC_ClearStatusFlags (ADC_Type ∗base, uint32_t mask)
Clear status flags of ADC module.
Data Fields
• adc_clock_mode_t clockMode
Select the clock mode for ADC converter.
• uint32_t clockDividerNumber
This field is only available when using kADC_ClockSynchronousMode for "clockMode" field.
• adc_resolution_t resolution
Select the conversion bits.
• bool enableBypassCalibration
By default, a calibration cycle must be performed each time the chip is powered-up.
• uint32_t sampleTimeNumber
By default, with value as "0U", the sample period would be 2.5 ADC clocks.
The divider would be plused by 1 based on the value in this field. The available range is in 8 bits.
Re-calibration may be warranted periodically - especially if operating conditions have changed. To enable
this option would avoid the need to calibrate if offset error is not a concern in the application.
Then, to plus the "sampleTimeNumber" value here. The available value range is in 3 bits.
Data Fields
• uint32_t channelMask
Selects which one or more of the ADC channels will be sampled and converted when this sequence is
launched.
• uint32_t triggerMask
Selects which one or more of the available hardware trigger sources will cause this conversion sequence
to be initiated.
• adc_trigger_polarity_t triggerPolarity
Select the trigger to lauch conversion sequence.
• bool enableSyncBypass
To enable this feature allows the hardware trigger input to bypass synchronization flip-flop stages and
therefore shorten the time between the trigger input signal and the start of a conversion.
• bool enableSingleStep
When enabling this feature, a trigger will launch a single conversion on the next channel in the sequence
instead of the default response of launching an entire sequence of conversions.
• adc_seq_interrupt_mode_t interruptMode
Select the interrpt/DMA trigger mode.
The masked channels would be involved in current conversion sequence, beginning with the lowest-order.
The available range is in 12-bit.
Data Fields
• uint32_t result
Keey the conversion data value.
• adc_threshold_compare_status_t thresholdCompareStatus
Keep the threshold compare status.
• adc_threshold_crossing_status_t thresholdCorssingStatus
Keep the threshold crossing status.
• uint32_t channelNumber
Keep the channel number for this conversion.
• bool overrunFlag
Keep the status whether the conversion is overrun or not.
Enumerator
kADC_ThresholdCompareFlagOnChn0 Threshold comparison event on Channel 0.
kADC_ThresholdCompareFlagOnChn1 Threshold comparison event on Channel 1.
kADC_ThresholdCompareFlagOnChn2 Threshold comparison event on Channel 2.
kADC_ThresholdCompareFlagOnChn3 Threshold comparison event on Channel 3.
kADC_ThresholdCompareFlagOnChn4 Threshold comparison event on Channel 4.
Note
Not all the interrupt options are listed here
Enumerator
kADC_ConvSeqAInterruptEnable Enable interrupt upon completion of each individual conversion
in sequence A, or entire sequence.
kADC_ConvSeqBInterruptEnable Enable interrupt upon completion of each individual conversion
in sequence B, or entire sequence.
kADC_OverrunInterruptEnable Enable the detection of an overrun condition on any of the channel
data registers will cause an overrun interrupt/DMA trigger.
Enumerator
kADC_ClockSynchronousMode The ADC clock would be derived from the system clock based on
"clockDividerNumber".
kADC_ClockAsynchronousMode The ADC clock would be based on the SYSCON block’s divider.
Enumerator
kADC_Resolution6bit 6-bit resolution.
kADC_Resolution8bit 8-bit resolution.
kADC_Resolution10bit 10-bit resolution.
kADC_Resolution12bit 12-bit resolution.
Enumerator
kADC_TriggerPolarityNegativeEdge A negative edge launches the conversion sequence on the trig-
ger(s).
kADC_TriggerPolarityPositiveEdge A positive edge launches the conversion sequence on the trig-
ger(s).
Enumerator
kADC_PriorityLow This sequence would be preempted when another sequence is started.
kADC_PriorityHigh This sequence would preempt other sequence even when is is started.
Enumerator
kADC_InterruptForEachConversion The sequence interrupt/DMA trigger will be set at the end of
each individual ADC conversion inside this conversion sequence.
kADC_InterruptForEachSequence The sequence interrupt/DMA trigger will be set when the entire
set of this sequence conversions completes.
Enumerator
kADC_ThresholdCompareInRange LOW threshold <= conversion value <= HIGH threshold.
kADC_ThresholdCompareBelowRange conversion value < LOW threshold.
kADC_ThresholdCompareAboveRange conversion value > HIGH threshold.
Enumerator
kADC_ThresholdCrossingNoDetected No threshold Crossing detected.
kADC_ThresholdCrossingDownward Downward Threshold Crossing detected.
kADC_ThresholdCrossingUpward Upward Threshold Crossing Detected.
Enumerator
kADC_ThresholdInterruptDisabled Threshold comparison interrupt is disabled.
kADC_ThresholdInterruptOnOutside Threshold comparison interrupt is enabled on outside thresh-
old.
kADC_ThresholdInterruptOnCrossing Threshold comparison interrupt is enabled on crossing
threshold.
Parameters
Parameters
This function initializes the initial configuration structure with an available settings. The default values
are:
* config->clockMode = kADC_ClockSynchronousMode;
* config->clockDividerNumber = 0U;
* config->resolution = kADC_Resolution12bit;
* config->enableBypassCalibration = false;
* config->sampleTimeNumber = 0U;
*
Parameters
Parameters
Return values
When enabling the internal temperature sensor measurement, the channel 0 would be connected to internal
sensor instead of external pin.
Parameters
In order to avoid spuriously triggering the sequence, the trigger to conversion sequence should be ready
before the sequence is ready. when the sequence is disabled, the trigger would be ignored. Also, it is
suggested to disable the sequence during changing the sequence’s setting.
Parameters
Parameters
Parameters
Enable the burst mode would cause the conversion sequence to be cntinuously cycled through. Other
triggers would be ignored while this mode is enabled. Repeated conversions could be halted by disabling
this mode. And the sequence currently in process will be completed before cnversions are terminated.
Note that a new sequence could begin just before the burst mode is disabled.
Parameters
Parameters
In order to avoid spuriously triggering the sequence, the trigger to conversion sequence should be ready
before the sequence is ready. when the sequence is disabled, the trigger would be ignored. Also, it is
suggested to disable the sequence during changing the sequence’s setting.
Parameters
Parameters
Parameters
Enable the burst mode would cause the conversion sequence to be continuously cycled through. Other
triggers would be ignored while this mode is enabled. Repeated conversions could be halted by disabling
this mode. And the sequence currently in process will be completed before cnversions are terminated.
Note that a new sequence could begin just before the burst mode is disabled.
Parameters
Parameters
Parameters
Return values
Parameters
Return values
Parameters
Return values
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Returns
Mask of status flags of module, see to _adc_status_flags.
Parameters
Alternatively, the context switch handler could read original configuration and restore it when switching
back to original task/thread:
CRC_GetConfig(base, &originalConfig);
/* ... other task using CRC engine... */
CRC_Init(base, &originalConfig);
base = CRC0;
CRC_GetDefaultConfig(base, &config); /* default gives CRC-16/CCITT-FALSE */
CRC_Init(base, &config);
CRC_WriteData(base, data, sizeof(data));
checksum = CRC_Get16bitResult(base);
CRC_Deinit(base);
crc_config_t config;
uint32_t checksum;
config.polynomial = kCRC_Polynomial_CRC_32;
config.reverseIn = true;
config.complementIn = false;
config.reverseOut = true;
config.complementOut = true;
config.seed = 0xFFFFFFFFu;
CRC_Init(base, &config);
/* example: update by 1 byte at time */
while (dataSize)
{
uint8_t c = GetCharacter();
CRC_WriteData(base, &c, 1);
dataSize--;
}
checksum = CRC_Get32bitResult(base);
CRC_Deinit(base);
Per-partes data updates with context switch between. Assuming we have 3 tasks/threads, each using CRC
module to compute checksums of different protocol, with context switches.
Firstly, we prepare 3 CRC configurations for 3 different protocols: CRC-16 (ARC), CRC-16/CCITT-FAL-
SE and CRC-32. Table below lists the individual protocol specifications. See also: http://reveng.-
sourceforge.net/crc-catalogue/
uint16_t checksumCrc16;
uint32_t checksumCrc32;
uint16_t checksumCrc16Ccitt;
crc_config_t configCrc16;
crc_config_t configCrc32;
crc_config_t configCrc16Ccitt;
GetConfigCrc16(base, &configCrc16);
GetConfigCrc32(base, &configCrc32);
GetConfigCrc16Ccitt(base, &configCrc16Ccitt);
/* Task A bytes[0-3] */
CRC_Init(base, &configCrc16);
CRC_WriteData(base, &data[0], 4);
CRC_GetConfig(base, &configCrc16);
/* Task B bytes[0-3] */
CRC_Init(base, &configCrc16Ccitt);
CRC_WriteData(base, &data[0], 4);
CRC_GetConfig(base, &configCrc16Ccitt);
/* Task C 4 bytes[0-3] */
CRC_Init(base, &configCrc32);
CRC_WriteData(base, &data[0], 4);
CRC_GetConfig(base, &configCrc32);
/* Task C 3 bytes[4-6] */
CRC_Init(base, &configCrc32);
CRC_WriteData(base, &data[4], 3);
CRC_GetConfig(base, &configCrc32);
/* Task A 3 bytes[4-6] */
CRC_Init(base, &configCrc16);
CRC_WriteData(base, &data[4], 3);
CRC_GetConfig(base, &configCrc16);
CRC_Init(base, &configCrc32);
CRC_WriteData(base, &data[7], 2);
checksumCrc32 = CRC_Get32bitResult(base);
Files
• file fsl_crc.h
Data Structures
• struct crc_config_t
CRC protocol configuration. More...
Macros
• #define CRC_DRIVER_USE_CRC16_CCITT_FALSE_AS_DEFAULT 1
Default configuration structure filled by CRC_GetDefaultConfig().
Enumerations
• enum crc_polynomial_t {
kCRC_Polynomial_CRC_CCITT = 0U,
kCRC_Polynomial_CRC_16 = 1U,
kCRC_Polynomial_CRC_32 = 2U }
CRC polynomials to use.
Functions
• void CRC_Init (CRC_Type ∗base, const crc_config_t ∗config)
Enables and configures the CRC peripheral module.
• static void CRC_Deinit (CRC_Type ∗base)
Disables the CRC peripheral module.
• void CRC_Reset (CRC_Type ∗base)
resets CRC peripheral module.
• void CRC_GetDefaultConfig (crc_config_t ∗config)
Loads default values to CRC protocol configuration structure.
• void CRC_GetConfig (CRC_Type ∗base, crc_config_t ∗config)
Loads actual values configured in CRC peripheral to CRC protocol configuration structure.
• void CRC_WriteData (CRC_Type ∗base, const uint8_t ∗data, size_t dataSize)
Writes data to the CRC module.
• static uint32_t CRC_Get32bitResult (CRC_Type ∗base)
Reads 32-bit checksum from the CRC module.
• static uint16_t CRC_Get16bitResult (CRC_Type ∗base)
Reads 16-bit checksum from the CRC module.
Driver version
• #define FSL_CRC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
CRC driver version.
Data Fields
• crc_polynomial_t polynomial
CRC polynomial.
• bool reverseIn
Reverse bits on input.
• bool complementIn
Perform 1’s complement on input.
• bool reverseOut
Reverse bits on output.
• bool complementOut
Perform 1’s complement on output.
• uint32_t seed
Starting checksum value.
Version 2.0.0.
Current version: 2.0.0
Change log:
• Version 2.0.0
– initial version
Enumerator
kCRC_Polynomial_CRC_CCITT x∧ 16+x∧ 12+x∧ 5+1
kCRC_Polynomial_CRC_16 x∧ 16+x∧ 15+x∧ 2+1
kCRC_Polynomial_CRC_32 x∧ 32+x∧ 26+x∧ 23+x∧ 22+x∧ 16+x∧ 12+x∧ 11+x∧ 10+x∧ 8+x∧ 7+x∧ 5+x∧ 4+x∧ 2+x+1
This functions enables the CRC peripheral clock in the LPC SYSCON block. It also configures the CRC
engine and starts checksum computation by writing the seed.
Parameters
This functions disables the CRC peripheral clock in the LPC SYSCON block.
Parameters
Parameters
Loads default values to CRC protocol configuration structure. The default values are:
* config->polynomial = kCRC_Polynomial_CRC_CCITT;
* config->reverseIn = false;
* config->complementIn = false;
* config->reverseOut = false;
* config->complementOut = false;
* config->seed = 0xFFFFU;
*
Parameters
The values, including seed, can be used to resume CRC calculation later.
Parameters
Returns
final 32-bit checksum, after configured bit reverse and complement operations.
Returns
final 16-bit checksum, after configured bit reverse and complement operations.
The function CTIMER_Init() initializes the ctimer with specified configurations. The function CTIMER_-
GetDefaultConfig() gets the default configurations. The initialization function configures the counter/timer
mode and input selection when running in counter mode.
The function CTIMER_Deinit() stops the timer and turns off the module clock.
The function CTIMER_SetupPwm() sets up channels for PWM output. Each channel has its own duty cy-
cle, however the same PWM period is applied to all channels requesting the PWM output. The signal duty
cycle is provided as a percentage of the PWM period. Its value should be between 0 and 100 0=inactive
signal(0% duty cycle) and 100=always active signal (100% duty cycle).
The function CTIMER_UpdatePwmDutycycle() updates the PWM signal duty cycle of a particular chan-
nel.
The function CTIMER_SetupMatch() sets up channels for match operation. Each channel is configured
with a match value, if the counter should stop on match, if counter should reset on match and output pin
action. The output signal can be cleared, set or toggled on match.
The function CTIMER_SetupCapture() sets up an channel for input capture. The user can specify the
capture edge and if a interrupt should be generated when processing the input signal.
/* Init hardware*/
BOARD_InitHardware();
CTIMER_GetDefaultConfig(&config);
CTIMER_Init(CTIMER, &config);
matchConfig.enableCounterReset = true;
matchConfig.enableCounterStop = false;
matchConfig.matchValue = CLOCK_GetFreq(kCLOCK_BusClk) / 2;
matchConfig.outControl = kCTIMER_Output_Toggle;
matchConfig.outPinInitState = true;
matchConfig.enableInterrupt = false;
matchConfig.cb_func = NULL;
CTIMER_SetupMatch(CTIMER, CTIMER_MAT_OUT, &matchConfig);
CTIMER_StartTimer(CTIMER);
while (1)
{
}
}
/* Init hardware*/
BOARD_InitHardware();
/* CTimer0 counter uses the AHB clock, some CTimer1 modules use the Aysnc clock */
srcClock_Hz = CLOCK_GetFreq(kCLOCK_BusClk);
CTIMER_GetDefaultConfig(&config);
CTIMER_Init(CTIMER, &config);
CTIMER_SetupPwm(CTIMER, CTIMER_MAT_OUT, 20, 20000, srcClock_Hz, NULL);
CTIMER_StartTimer(CTIMER);
while (1)
{
}
}
Files
• file fsl_ctimer.h
Data Structures
• struct ctimer_match_config_t
Match configuration. More...
• struct ctimer_config_t
Timer configuration structure. More...
Enumerations
• enum ctimer_capture_channel_t {
kCTIMER_Capture_0 = 0U,
kCTIMER_Capture_1,
kCTIMER_Capture_2,
kCTIMER_Capture_3 }
List of Timer capture channels.
• enum ctimer_capture_edge_t {
kCTIMER_Capture_RiseEdge = 1U,
kCTIMER_Capture_FallEdge = 2U,
kCTIMER_Capture_BothEdge = 3U }
List of capture edge options.
• enum ctimer_match_t {
kCTIMER_Match_0 = 0U,
kCTIMER_Match_1,
kCTIMER_Match_2,
kCTIMER_Match_3 }
List of Timer match registers.
• enum ctimer_match_output_control_t {
kCTIMER_Output_NoAction = 0U,
kCTIMER_Output_Clear,
kCTIMER_Output_Set,
kCTIMER_Output_Toggle }
List of output control options.
• enum ctimer_timer_mode_t
List of Timer modes.
• enum ctimer_interrupt_enable_t {
kCTIMER_Match0InterruptEnable = CTIMER_MCR_MR0I_MASK,
kCTIMER_Match1InterruptEnable = CTIMER_MCR_MR1I_MASK,
kCTIMER_Match2InterruptEnable = CTIMER_MCR_MR2I_MASK,
kCTIMER_Match3InterruptEnable = CTIMER_MCR_MR3I_MASK,
kCTIMER_Capture0InterruptEnable = CTIMER_CCR_CAP0I_MASK,
kCTIMER_Capture1InterruptEnable = CTIMER_CCR_CAP1I_MASK,
kCTIMER_Capture2InterruptEnable = CTIMER_CCR_CAP2I_MASK,
kCTIMER_Capture3InterruptEnable = CTIMER_CCR_CAP3I_MASK }
List of Timer interrupts.
• enum ctimer_status_flags_t {
kCTIMER_Match0Flag = CTIMER_IR_MR0INT_MASK,
kCTIMER_Match1Flag = CTIMER_IR_MR1INT_MASK,
kCTIMER_Match2Flag = CTIMER_IR_MR2INT_MASK,
kCTIMER_Match3Flag = CTIMER_IR_MR3INT_MASK,
kCTIMER_Capture0Flag = CTIMER_IR_CR0INT_MASK,
kCTIMER_Capture1Flag = CTIMER_IR_CR1INT_MASK,
kCTIMER_Capture2Flag = CTIMER_IR_CR2INT_MASK,
kCTIMER_Capture3Flag = CTIMER_IR_CR3INT_MASK }
List of Timer flags.
• enum ctimer_callback_type_t {
kCTIMER_SingleCallback,
kCTIMER_MultipleCallback }
Callback type when registering for a callback.
Functions
• void CTIMER_SetupMatch (CTIMER_Type ∗base, ctimer_match_t matchChannel, const ctimer_-
match_config_t ∗config)
Setup the match register.
• void CTIMER_SetupCapture (CTIMER_Type ∗base, ctimer_capture_channel_t capture, ctimer_-
capture_edge_t edge, bool enableInt)
Setup the capture.
• void CTIMER_RegisterCallBack (CTIMER_Type ∗base, ctimer_callback_t ∗cb_func, ctimer_-
callback_type_t cb_type)
Register callback.
• static void CTIMER_Reset (CTIMER_Type ∗base)
Reset the counter.
Driver version
• #define FSL_CTIMER_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Version 2.0.0.
Interrupt Interface
• static void CTIMER_EnableInterrupts (CTIMER_Type ∗base, uint32_t mask)
Enables the selected Timer interrupts.
• static void CTIMER_DisableInterrupts (CTIMER_Type ∗base, uint32_t mask)
Disables the selected Timer interrupts.
• static uint32_t CTIMER_GetEnabledInterrupts (CTIMER_Type ∗base)
Gets the enabled Timer interrupts.
Status Interface
• static uint32_t CTIMER_GetStatusFlags (CTIMER_Type ∗base)
Gets the Timer status flags.
• static void CTIMER_ClearStatusFlags (CTIMER_Type ∗base, uint32_t mask)
Clears the Timer status flags.
This structure holds the configuration settings for each match register.
Data Fields
• uint32_t matchValue
This is stored in the match register.
• bool enableCounterReset
true: Match will reset the counter false: Match will not reser the counter
• bool enableCounterStop
true: Match will stop the counter false: Match will not stop the counter
• ctimer_match_output_control_t outControl
Action to be taken on a match on the EM bit/output.
• bool outPinInitState
Initial value of the EM bit/output.
• bool enableInterrupt
true: Generate interrupt upon match false: Do not generate interrupt on match
This structure holds the configuration settings for the Timer peripheral. To initialize this structure to
reasonable defaults, call the CTIMER_GetDefaultConfig() function and pass a pointer to the configuration
structure instance.
The configuration structure can be made constant so as to reside in flash.
Data Fields
• ctimer_timer_mode_t mode
Timer mode.
• ctimer_capture_channel_t input
Input channel to increment the timer, used only in timer modes that rely on this input signal to increment
TC.
• uint32_t prescale
Prescale value.
Enumerator
kCTIMER_Capture_0 Timer capture channel 0.
kCTIMER_Capture_1 Timer capture channel 1.
kCTIMER_Capture_2 Timer capture channel 2.
kCTIMER_Capture_3 Timer capture channel 3.
Enumerator
kCTIMER_Capture_RiseEdge Capture on rising edge.
kCTIMER_Capture_FallEdge Capture on falling edge.
kCTIMER_Capture_BothEdge Capture on rising and falling edge.
Enumerator
kCTIMER_Match_0 Timer match register 0.
kCTIMER_Match_1 Timer match register 1.
kCTIMER_Match_2 Timer match register 2.
Enumerator
kCTIMER_Output_NoAction No action is taken.
kCTIMER_Output_Clear Clear the EM bit/output to 0.
kCTIMER_Output_Set Set the EM bit/output to 1.
kCTIMER_Output_Toggle Toggle the EM bit/output.
Enumerator
kCTIMER_Match0InterruptEnable Match 0 interrupt.
kCTIMER_Match1InterruptEnable Match 1 interrupt.
kCTIMER_Match2InterruptEnable Match 2 interrupt.
kCTIMER_Match3InterruptEnable Match 3 interrupt.
kCTIMER_Capture0InterruptEnable Capture 0 interrupt.
kCTIMER_Capture1InterruptEnable Capture 1 interrupt.
kCTIMER_Capture2InterruptEnable Capture 2 interrupt.
kCTIMER_Capture3InterruptEnable Capture 3 interrupt.
Enumerator
kCTIMER_Match0Flag Match 0 interrupt flag.
kCTIMER_Match1Flag Match 1 interrupt flag.
kCTIMER_Match2Flag Match 2 interrupt flag.
kCTIMER_Match3Flag Match 3 interrupt flag.
kCTIMER_Capture0Flag Capture 0 interrupt flag.
kCTIMER_Capture1Flag Capture 1 interrupt flag.
kCTIMER_Capture2Flag Capture 2 interrupt flag.
kCTIMER_Capture3Flag Capture 3 interrupt flag.
When registering a callback an array of function pointers is passed the size could be 1 or 8, the callback
type will tell that.
Enumerator
kCTIMER_SingleCallback Single Callback type where there is only one callback for the timer.
based on the status flags different channels needs to be handled differently
kCTIMER_MultipleCallback Multiple Callback type where there can be 8 valid callbacks, one per
channel. for both match/capture
Note
This API should be called at the beginning of the application before using the driver.
Parameters
Parameters
* config->mode = kCTIMER_TimerMode;
* config->input = kCTIMER_Capture_0;
* config->prescale = 0;
*
Parameters
Enables PWM mode on the match channel passed in and will then setup the match value and other match
parameters to generate a PWM signal. This function will assign match channel 3 to set the PWM cycle.
Note
When setting PWM output from multiple output pins, all should use the same PWM frequency
Parameters
Returns
kStatus_Success on success kStatus_Fail If matchChannel passed in is 3; this channel is reserved to
set the PWM cycle
Parameters
User configuration is used to setup the match value and action to be taken when a match occurs.
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Returns
The enabled interrupts. This is the logical OR of members of the enumeration ctimer_interrupt_-
enable_t
Parameters
Returns
The status flags. This is the logical OR of members of the enumeration ctimer_status_flags_t
Parameters
Parameters
Parameters
The timer counter and prescale counter are reset on the next positive edge of the APB clock.
Parameters
Macros
• #define MAKE_STATUS(group, code) ((((group)∗100) + (code)))
Construct a status code value from a group and code number.
• #define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
Construct the version number for drivers.
• #define DEBUG_CONSOLE_DEVICE_TYPE_NONE 0U
No debug console.
• #define DEBUG_CONSOLE_DEVICE_TYPE_UART 1U
Debug console base on UART.
• #define DEBUG_CONSOLE_DEVICE_TYPE_LPUART 2U
Debug console base on LPUART.
• #define DEBUG_CONSOLE_DEVICE_TYPE_LPSCI 3U
Debug console base on LPSCI.
• #define DEBUG_CONSOLE_DEVICE_TYPE_USBCDC 4U
Debug console base on USBCDC.
• #define DEBUG_CONSOLE_DEVICE_TYPE_FLEXCOMM 5U
Debug console base on USBCDC.
• #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
Computes the number of elements in an array.
• #define ADC_RSTS
Typedefs
• typedef int32_t status_t
Type used for all status and error return values.
Enumerations
• enum _status_groups {
kStatusGroup_Generic = 0,
kStatusGroup_FLASH = 1,
kStatusGroup_LPSPI = 4,
kStatusGroup_FLEXIO_SPI = 5,
kStatusGroup_DSPI = 6,
kStatusGroup_FLEXIO_UART = 7,
kStatusGroup_FLEXIO_I2C = 8,
kStatusGroup_LPI2C = 9,
kStatusGroup_UART = 10,
kStatusGroup_I2C = 11,
kStatusGroup_LPSCI = 12,
kStatusGroup_LPUART = 13,
kStatusGroup_SPI = 14,
kStatusGroup_XRDC = 15,
kStatusGroup_SEMA42 = 16,
kStatusGroup_SDHC = 17,
kStatusGroup_SDMMC = 18,
kStatusGroup_SAI = 19,
kStatusGroup_MCG = 20,
kStatusGroup_SCG = 21,
kStatusGroup_SDSPI = 22,
kStatusGroup_FLEXIO_I2S = 23,
kStatusGroup_FLASHIAP = 25,
kStatusGroup_FLEXCOMM_I2C = 26,
kStatusGroup_I2S = 27,
kStatusGroup_SDRAMC = 35,
kStatusGroup_POWER = 39,
kStatusGroup_ENET = 40,
kStatusGroup_PHY = 41,
kStatusGroup_TRGMUX = 42,
kStatusGroup_SMARTCARD = 43,
kStatusGroup_LMEM = 44,
kStatusGroup_QSPI = 45,
kStatusGroup_DMA = 50,
kStatusGroup_EDMA = 51,
kStatusGroup_DMAMGR = 52,
kStatusGroup_FLEXCAN = 53,
kStatusGroup_LTC = 54,
kStatusGroup_FLEXIO_CAMERA = 55,
kStatusGroup_LPC_SPI = 56,
kStatusGroup_LPC_USART = 57,
kStatusGroup_DMIC = 58,
kStatusGroup_SDIF = 59,
kStatusGroup_SPIFI = 60,
kStatusGroup_OTP = 61, SDK API Reference Manual v2.0.0
58 kStatusGroup_MCAN = 62, NXP Semiconductors
kStatusGroup_NOTIFIER = 98,
Overview
kStatusGroup_ApplicationRangeStart = 100 }
Status group numbers.
• enum _generic_status
Generic status return codes.
• enum SYSCON_RSTn_t {
kFLASH_RST_SHIFT_RSTn = 0 | 7U,
kFMC_RST_SHIFT_RSTn = 0 | 8U,
kEEPROM_RST_SHIFT_RSTn = 0 | 9U,
kSPIFI_RST_SHIFT_RSTn = 0 | 10U,
kMUX_RST_SHIFT_RSTn = 0 | 11U,
kIOCON_RST_SHIFT_RSTn = 0 | 13U,
kGPIO0_RST_SHIFT_RSTn = 0 | 14U,
kGPIO1_RST_SHIFT_RSTn = 0 | 15U,
kGPIO2_RST_SHIFT_RSTn = 0 | 16U,
kGPIO3_RST_SHIFT_RSTn = 0 | 17U,
kPINT_RST_SHIFT_RSTn = 0 | 18U,
kGINT_RST_SHIFT_RSTn = 0 | 19U,
kDMA_RST_SHIFT_RSTn = 0 | 20U,
kCRC_RST_SHIFT_RSTn = 0 | 21U,
kWWDT_RST_SHIFT_RSTn = 0 | 22U,
kADC0_RST_SHIFT_RSTn = 0 | 27U,
kMRT_RST_SHIFT_RSTn = 65536 | 0U,
kSCT0_RST_SHIFT_RSTn = 65536 | 2U,
kMCAN0_RST_SHIFT_RSTn = 65536 | 7U,
kMCAN1_RST_SHIFT_RSTn = 65536 | 8U,
kUTICK_RST_SHIFT_RSTn = 65536 | 10U,
kFC0_RST_SHIFT_RSTn = 65536 | 11U,
kFC1_RST_SHIFT_RSTn = 65536 | 12U,
kFC2_RST_SHIFT_RSTn = 65536 | 13U,
kFC3_RST_SHIFT_RSTn = 65536 | 14U,
kFC4_RST_SHIFT_RSTn = 65536 | 15U,
kFC5_RST_SHIFT_RSTn = 65536 | 16U,
kFC6_RST_SHIFT_RSTn = 65536 | 17U,
kFC7_RST_SHIFT_RSTn = 65536 | 18U,
kDMIC_RST_SHIFT_RSTn = 65536 | 19U,
kCT32B2_RST_SHIFT_RSTn = 65536 | 22U,
kUSB0D_RST_SHIFT_RSTn = 65536 | 25U,
kCT32B0_RST_SHIFT_RSTn = 65536 | 26U,
kCT32B1_RST_SHIFT_RSTn = 65536 | 27U,
kLCD_RST_SHIFT_RSTn = 131072 | 2U,
kSDIO_RST_SHIFT_RSTn = 131072 | 3U,
kUSB1H_RST_SHIFT_RSTn = 131072 | 4U,
kUSB1D_RST_SHIFT_RSTn = 131072 | 5U,
kUSB1RAM_RST_SHIFT_RSTn = 131072 | 6U,
kEMC_RST_SHIFT_RSTn = 131072 | 7U,
kETH_RST_SHIFT_RSTn = 131072 | 8U,
kGPIO4_RST_SHIFT_RSTn = 131072 | 9U,
kGPIO5_RST_SHIFT_RSTn = 131072 | 10U,
kAES_RST_SHIFT_RSTn = 131072 | 11U,
kOTP_RST_SHIFT_RSTn = 131072 | 12U,
kRNG_RST_SHIFT_RSTn = 131072 | 13U,
kFC8_RST_SHIFT_RSTn =SDK
131072API| Reference
14U, Manual v2.0.0
60 kFC9_RST_SHIFT_RSTn = 131072 | 15U, NXP Semiconductors
kUSB0HMR_RST_SHIFT_RSTn = 131072 | 16U,
Overview
Functions
• static void EnableIRQ (IRQn_Type interrupt)
Enable specific interrupt.
• static void DisableIRQ (IRQn_Type interrupt)
Disable specific interrupt.
• static uint32_t DisableGlobalIRQ (void)
Disable the global IRQ.
• static void EnableGlobalIRQ (uint32_t primask)
Enaable the global IRQ.
• uint32_t InstallIRQHandler (IRQn_Type irq, uint32_t irqHandler)
install IRQ handler
• void EnableDeepSleepIRQ (IRQn_Type interrupt)
Enable specific interrupt for wake-up from deep-sleep mode.
• void DisableDeepSleepIRQ (IRQn_Type interrupt)
Disable specific interrupt for wake-up from deep-sleep mode.
• void RESET_SetPeripheralReset (reset_ip_name_t peripheral)
Assert reset to peripheral.
• void RESET_ClearPeripheralReset (reset_ip_name_t peripheral)
Clear reset to peripheral.
• void RESET_PeripheralReset (reset_ip_name_t peripheral)
Reset peripheral module.
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) (uint64_t)((uint64_t)us ∗ clockFreqInHz /
1000000U)
Macro to convert a microsecond period to raw count value.
• #define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)count ∗ 1000000U /
clockFreqInHz)
Macro to convert a raw count value to microsecond.
• #define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)ms ∗ clockFreqInHz / 1000-
U)
Macro to convert a millisecond period to raw count value.
• #define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)count ∗ 1000U / clock-
FreqInHz)
Macro to convert a raw count value to millisecond.
8.2.2 #define MAKE_VERSION( major, minor, bugfix ) (((major) << 16) | ((minor)
<< 8) | (bugfix))
Value:
{ \
kADC0_RST_SHIFT_RSTn \
} /* Reset bits for ADC peripheral */
Enumerator
kStatusGroup_Generic Group number for generic status codes.
kStatusGroup_FLASH Group number for FLASH status codes.
Defines the enumeration for peripheral reset control bits in PRESETCTRL/ASYNCPRESETCTRL regis-
ters
Enumerator
kFLASH_RST_SHIFT_RSTn Flash controller reset control
kFMC_RST_SHIFT_RSTn Flash accelerator reset control
kEEPROM_RST_SHIFT_RSTn EEPROM reset control
kSPIFI_RST_SHIFT_RSTn SPIFI reset control
kMUX_RST_SHIFT_RSTn Input mux reset control
kIOCON_RST_SHIFT_RSTn IOCON reset control
kGPIO0_RST_SHIFT_RSTn GPIO0 reset control
kGPIO1_RST_SHIFT_RSTn GPIO1 reset control
kGPIO2_RST_SHIFT_RSTn GPIO2 reset control
kGPIO3_RST_SHIFT_RSTn GPIO3 reset control
kPINT_RST_SHIFT_RSTn Pin interrupt (PINT) reset control
kGINT_RST_SHIFT_RSTn Grouped interrupt (PINT) reset control.
kDMA_RST_SHIFT_RSTn DMA reset control
kCRC_RST_SHIFT_RSTn CRC reset control
kWWDT_RST_SHIFT_RSTn Watchdog timer reset control
kADC0_RST_SHIFT_RSTn ADC0 reset control
kMRT_RST_SHIFT_RSTn Multi-rate timer (MRT) reset control
kSCT0_RST_SHIFT_RSTn SCTimer/PWM 0 (SCT0) reset control
kMCAN0_RST_SHIFT_RSTn MCAN0 reset control
kMCAN1_RST_SHIFT_RSTn MCAN1 reset control
kUTICK_RST_SHIFT_RSTn Micro-tick timer reset control
kFC0_RST_SHIFT_RSTn Flexcomm Interface 0 reset control
kFC1_RST_SHIFT_RSTn Flexcomm Interface 1 reset control
kFC2_RST_SHIFT_RSTn Flexcomm Interface 2 reset control
kFC3_RST_SHIFT_RSTn Flexcomm Interface 3 reset control
kFC4_RST_SHIFT_RSTn Flexcomm Interface 4 reset control
kFC5_RST_SHIFT_RSTn Flexcomm Interface 5 reset control
kFC6_RST_SHIFT_RSTn Flexcomm Interface 6 reset control
kFC7_RST_SHIFT_RSTn Flexcomm Interface 7 reset control
kDMIC_RST_SHIFT_RSTn Digital microphone interface reset control
kCT32B2_RST_SHIFT_RSTn CT32B2 reset control
Parameters
Disable the global interrupt and return the current primask register. User is required to provided the
primask register for the EnableGlobalIRQ().
Returns
Current primask value.
Set the primask register with the provided primask value but not just enable the primask. The idea is for
the convinience of integration of RTOS. some RTOS get its own management mechanism of primask.
User is required to use the EnableGlobalIRQ() and DisableGlobalIRQ() in pair.
Parameters
primask value of primask register to be restored. The primask value is supposed to be provided
by the DisableGlobalIRQ().
Parameters
Returns
The old IRQ handler address
Enable the interrupt for wake-up from deep sleep mode. Some interrupts are typically used in sleep mode
only and will not occur during deep-sleep mode because relevant clocks are stopped. However, it is
possible to enable those clocks (significantly increasing power consumption in the reduced power mode),
making these wake-ups possible.
Note
This function also enables the interrupt in the NVIC (EnableIRQ() is called internally).
Parameters
Disable the interrupt for wake-up from deep sleep mode. Some interrupts are typically used in sleep
mode only and will not occur during deep-sleep mode because relevant clocks are stopped. However, it is
possible to enable those clocks (significantly increasing power consumption in the reduced power mode),
making these wake-ups possible.
Note
This function also disables the interrupt in the NVIC (DisableIRQ() is called internally).
Parameters
peripheral Assert reset to this peripheral. The enum argument contains encoding of reset register
and reset bit position in the reset register.
Parameters
peripheral Clear reset to this peripheral. The enum argument contains encoding of reset register
and reset bit position in the reset register.
peripheral Peripheral to reset. The enum argument contains encoding of reset register and reset
bit position in the reset register.
To initialize the debug console, call the DbgConsole_Init() function with these parameters. This function
automatically enables the module and the clock.
/*
* @brief Initializes the the peripheral used to debug messages.
*
* @param baseAddr Indicates which address of the peripheral is used to send debug messages.
* @param baudRate The desired baud rate in bits per second.
* @param device Low level device type for the debug console, can be one of:
* @arg DEBUG_CONSOLE_DEVICE_TYPE_UART,
* @arg DEBUG_CONSOLE_DEVICE_TYPE_LPUART,
* @arg DEBUG_CONSOLE_DEVICE_TYPE_LPSCI,
* @arg DEBUG_CONSOLE_DEVICE_TYPE_USBCDC.
* @param clkSrcFreq Frequency of peripheral source clock.
*
* @return Whether initialization was successful or not.
*/
status_t DbgConsole_Init(uint32_t baseAddr, uint32_t baudRate, uint8_t device, uint32_t clkSrcFreq)
DEBUG_CONSOLE_DEVICE_TYPE_NONE
DEBUG_CONSOLE_DEVICE_TYPE_LPSCI
DEBUG_CONSOLE_DEVICE_TYPE_UART
DEBUG_CONSOLE_DEVICE_TYPE_LPUART
DEBUG_CONSOLE_DEVICE_TYPE_USBCDC
After the initialization is successful, stdout and stdin are connected to the selected peripheral. The debug
console state is stored in the debug_console_state_t structure, such as shown here.
This example shows how to call the DbgConsole_Init() given the user configuration structure.
DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, BOARD_DEBUG_UART_BAUDRATE,
DEBUG_CONSOLE_DEVICE_TYPE_UART, uartClkSrcFreq);
The debug console provides input and output functions to scan and print formatted data.
• Support a format specifier for PRINTF following this prototype " %[flags][width][.precision][length]specifier",
which is explained below
flags Description
- Left-justified within the given field width. Right-
justified is the default.
+ Forces to precede the result with a plus or minus
sign (+ or -) even for positive numbers. By default,
only negative numbers are preceded with a - sign.
(space) If no sign is written, a blank space is inserted be-
fore the value.
# Used with o, x, or X specifiers the value is pre-
ceded with 0, 0x, or 0X respectively for values
other than zero. Used with e, E and f, it forces
the written output to contain a decimal point even
if no digits would follow. By default, if no digits
follow, no decimal point is written. Used with g or
G the result is the same as with e or E but trailing
zeros are not removed.
0 Left-pads the number with zeroes (0) instead of
spaces, where padding is specified (see width sub-
specifier).
Width Description
(number) A minimum number of characters to be printed. If
the value to be printed is shorter than this number,
the result is padded with blank spaces. The value
is not truncated even if the result is larger.
∗ The width is not specified in the format string, but
as an additional integer value argument preceding
the argument that has to be formatted.
.precision Description
.number For integer specifiers (d, i, o, u, x, X) precision
specifies the minimum number of digits to be writ-
ten. If the value to be written is shorter than this
number, the result is padded with leading zeros.
The value is not truncated even if the result is
longer. A precision of 0 means that no character
is written for the value 0. For e, E, and f speci-
fiers this is the number of digits to be printed after
the decimal point. For g and G specifiers This
is the maximum number of significant digits to be
printed. For s this is the maximum number of
characters to be printed. By default, all characters
are printed until the ending null character is en-
countered. For c type it has no effect. When no
precision is specified, the default is 1. If the period
is specified without an explicit value for precision,
0 is assumed.
.∗ The precision is not specified in the format string,
but as an additional integer value argument pre-
ceding the argument that has to be formatted.
length Description
Do not support
specifier Description
d or i Signed decimal integer
f Decimal floating point
F Decimal floating point capital letters
x Unsigned hexadecimal integer
X Unsigned hexadecimal integer capital letters
o Signed octal
b Binary value
p Pointer address
u Unsigned decimal integer
c Character
s String of characters
n Nothing printed
• Support a format specifier for SCANF following this prototype " %[∗][width][length]specifier",
which is explained below
∗ Description
An optional starting asterisk indicates that the data is to be read from the stream but ignored. In other
words, it is not stored in the corresponding argument.
width Description
This specifies the maximum number of characters to be read in the current reading operation.
length Description
hh The argument is interpreted as a signed charac-
ter or unsigned character (only applies to integer
specifiers: i, d, o, u, x, and X).
h The argument is interpreted as a short integer
or unsigned short integer (only applies to integer
specifiers: i, d, o, u, x, and X).
l The argument is interpreted as a long integer or
unsigned long integer for integer specifiers (i, d,
o, u, x, and X) and as a wide character or wide
character string for specifiers c and s.
ll The argument is interpreted as a long long integer
or unsigned long long integer for integer specifiers
(i, d, o, u, x, and X) and as a wide character or
wide character string for specifiers c and s.
L The argument is interpreted as a long double (only
applies to floating point specifiers: e, E, f, g, and
G).
j or z or t Not supported
The debug console has its own printf/scanf/putchar/getchar functions which are defined in the header file.
ch = GETCHAR();
PUTCHAR(ch);
PRINTF("Execution timer: %s\n\rTime: %u ticks %2.5f milliseconds\n\rDONE\n\r", "1 day", 86400, 86.4);
void __assert_func(const char *file, int line, const char *func, const char *failedExpr)
{
PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" function name \"%s\" \n", failedExpr, file ,
line, func);
for (;;)
{}
}
Note:
To use ’printf’ and ’scanf’ for GNUC Base, add file ’fsl_sbrk.c’ in path: ..\{package}\devices\{subset}\utilities\fsl-
_sbrk.c to your project.
Modules
• Semihosting
9.4 Semihosting
Semihosting is a mechanism for ARM targets to communicate input/output requests from application code
to a host computer running a debugger. This mechanism can be used, for example, to enable functions in
the C library, such as printf() and scanf(), to use the screen and keyboard of the host rather than having a
screen and keyboard on the target system.
NOTE: After the setting both "printf" and "scanf" are available for debugging.
Remove function fputc and fgetc is used to support KEIL in "fsl_debug_console.c" and add the following
code to project.
#pragma import(__use_no_semihosting_swi)
struct __FILE
{
int handle;
};
FILE __stdout;
FILE __stdin;
defsym=__heap_size__=0x2000")
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}
--defsym=__heap_size__=0x2000")
G} --specs=rdimon.specs ")
Remove
target_link_libraries(semihosting_ARMGCC.elf debug nosys)
2. Run "build_debug.bat" to build project
(b) After the setting, press "enter". The PuTTY window now shows the printf() output.
dma_transfer_config_t transferConfig;
uint32_t transferDone = false;
DMA_Init(DMA0);
DMA_EnableChannel(DMA0, channel);
DMA_SetChannelPriority(DMA0, channel,
kDMA_ChannelPriority0);
DMA_CreateHandle(&g_DMA_Handle, DMA0, channel);
DMA_SetCallback(&g_DMA_Handle, DMA_Callback, &transferDone);
DMA_PrepareTransfer(&transferConfig, srcAddr, destAddr, transferByteWidth, transferBytes
,
kDMA_MemoryToMemory, NULL);
DMA_SubmitTransfer(&g_DMA_Handle, &transferConfig);
DMA_StartTransfer(&g_DMA_Handle);
/* Wait for DMA transfer finish */
while (transferDone != true);
Files
• file fsl_dma.h
Data Structures
• struct dma_descriptor_t
DMA descriptor structure. More...
• struct dma_xfercfg_t
DMA transfer configuration. More...
• struct dma_channel_trigger_t
DMA channel trigger. More...
• struct dma_transfer_config_t
DMA transfer configuration. More...
• struct dma_handle_t
DMA transfer handle structure. More...
Typedefs
• typedef void(∗ dma_callback )(struct _dma_handle ∗handle, void ∗userData, bool transferDone,
uint32_t intmode)
Define Callback function for DMA.
Enumerations
• enum dma_priority_t {
kDMA_ChannelPriority0 = 0,
kDMA_ChannelPriority1,
kDMA_ChannelPriority2,
kDMA_ChannelPriority3,
kDMA_ChannelPriority4,
kDMA_ChannelPriority5,
kDMA_ChannelPriority6,
kDMA_ChannelPriority7 }
DMA channel priority.
• enum dma_irq_t {
kDMA_IntA,
kDMA_IntB }
DMA interrupt flags.
• enum dma_trigger_type_t {
kDMA_NoTrigger = 0,
kDMA_LowLevelTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1) | DMA_CHANNEL_CFG-
_TRIGTYPE(1),
kDMA_HighLevelTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1) | DMA_CHANNEL_CFG-
_TRIGTYPE(1) | DMA_CHANNEL_CFG_TRIGPOL(1),
kDMA_FallingEdgeTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1),
kDMA_RisingEdgeTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1) | DMA_CHANNEL_CF-
G_TRIGPOL(1) }
DMA trigger type.
• enum dma_trigger_burst_t {
kDMA_SingleTransfer = 0,
kDMA_LevelBurstTransfer = DMA_CHANNEL_CFG_TRIGBURST(1),
kDMA_EdgeBurstTransfer1 = DMA_CHANNEL_CFG_TRIGBURST(1),
kDMA_EdgeBurstTransfer2 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_C-
FG_BURSTPOWER(1),
kDMA_EdgeBurstTransfer4 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_C-
FG_BURSTPOWER(2),
kDMA_EdgeBurstTransfer8 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_C-
FG_BURSTPOWER(3),
kDMA_EdgeBurstTransfer16 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_-
CFG_BURSTPOWER(4),
kDMA_EdgeBurstTransfer32 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_-
CFG_BURSTPOWER(5),
kDMA_EdgeBurstTransfer64 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_-
CFG_BURSTPOWER(6),
kDMA_EdgeBurstTransfer128 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL-
_CFG_BURSTPOWER(7),
kDMA_EdgeBurstTransfer256 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL-
_CFG_BURSTPOWER(8),
kDMA_EdgeBurstTransfer512 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL-
_CFG_BURSTPOWER(9),
kDMA_EdgeBurstTransfer1024 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNE-
L_CFG_BURSTPOWER(10) }
DMA trigger burst.
• enum dma_burst_wrap_t {
kDMA_NoWrap = 0,
kDMA_SrcWrap = DMA_CHANNEL_CFG_SRCBURSTWRAP(1),
kDMA_DstWrap = DMA_CHANNEL_CFG_DSTBURSTWRAP(1),
kDMA_SrcAndDstWrap = DMA_CHANNEL_CFG_SRCBURSTWRAP(1) | DMA_CHANNEL-
_CFG_DSTBURSTWRAP(1) }
DMA burst wrapping.
• enum dma_transfer_type_t {
kDMA_MemoryToMemory = 0x0U,
kDMA_PeripheralToMemory,
kDMA_MemoryToPeripheral,
kDMA_StaticToStatic }
DMA transfer type.
• enum _dma_transfer_status { kStatus_DMA_Busy = MAKE_STATUS(kStatusGroup_DMA, 0) }
DMA transfer status.
Driver version
• #define FSL_DMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
DMA driver version.
Data Fields
• uint32_t xfercfg
Transfer configuration.
• void ∗ srcEndAddr
Last source address of DMA transfer.
• void ∗ dstEndAddr
Last destination address of DMA transfer.
• void ∗ linkToNextDesc
Address of next DMA descriptor in chain.
Data Fields
• bool valid
Descriptor is ready to transfer.
• bool reload
Reload channel configuration register after current descriptor is exhausted.
• bool swtrig
Perform software trigger.
• bool clrtrig
Clear trigger.
• bool intA
Raises IRQ when transfer is done and set IRQA status register flag.
• bool intB
Raises IRQ when transfer is done and set IRQB status register flag.
• uint8_t byteWidth
Byte width of data to transfer.
• uint8_t srcInc
Increment source address by ’srcInc’ x ’byteWidth’.
• uint8_t dstInc
Increment destination address by ’dstInc’ x ’byteWidth’.
• uint16_t transferCount
Number of transfers.
Data Fields
• uint8_t ∗ srcAddr
Source data address.
• uint8_t ∗ dstAddr
Destination data address.
• uint8_t ∗ nextDesc
Chain custom descriptor.
• dma_xfercfg_t xfercfg
Transfer options.
• bool isPeriph
DMA transfer is driven by peripheral.
Data Fields
• dma_callback callback
Callback function.
• void ∗ userData
Callback function parameter.
• DMA_Type ∗ base
DMA peripheral base address.
• uint8_t channel
DMA channel number.
Version 2.0.0.
Enumerator
kDMA_ChannelPriority0 Highest channel priority - priority 0.
kDMA_ChannelPriority1 Channel priority 1.
kDMA_ChannelPriority2 Channel priority 2.
kDMA_ChannelPriority3 Channel priority 3.
kDMA_ChannelPriority4 Channel priority 4.
kDMA_ChannelPriority5 Channel priority 5.
kDMA_ChannelPriority6 Channel priority 6.
kDMA_ChannelPriority7 Lowest channel priority - priority 7.
Enumerator
kDMA_IntA DMA interrupt flag A.
kDMA_IntB DMA interrupt flag B.
Enumerator
kDMA_NoTrigger Trigger is disabled.
kDMA_LowLevelTrigger Low level active trigger.
kDMA_HighLevelTrigger High level active trigger.
kDMA_FallingEdgeTrigger Falling edge active trigger.
kDMA_RisingEdgeTrigger Rising edge active trigger.
Enumerator
kDMA_SingleTransfer Single transfer.
kDMA_LevelBurstTransfer Burst transfer driven by level trigger.
kDMA_EdgeBurstTransfer1 Perform 1 transfer by edge trigger.
kDMA_EdgeBurstTransfer2 Perform 2 transfers by edge trigger.
kDMA_EdgeBurstTransfer4 Perform 4 transfers by edge trigger.
kDMA_EdgeBurstTransfer8 Perform 8 transfers by edge trigger.
kDMA_EdgeBurstTransfer16 Perform 16 transfers by edge trigger.
kDMA_EdgeBurstTransfer32 Perform 32 transfers by edge trigger.
kDMA_EdgeBurstTransfer64 Perform 64 transfers by edge trigger.
kDMA_EdgeBurstTransfer128 Perform 128 transfers by edge trigger.
kDMA_EdgeBurstTransfer256 Perform 256 transfers by edge trigger.
kDMA_EdgeBurstTransfer512 Perform 512 transfers by edge trigger.
kDMA_EdgeBurstTransfer1024 Perform 1024 transfers by edge trigger.
Enumerator
kDMA_NoWrap Wrapping is disabled.
kDMA_SrcWrap Wrapping is enabled for source.
kDMA_DstWrap Wrapping is enabled for destination.
kDMA_SrcAndDstWrap Wrapping is enabled for source and destination.
Enumerator
kDMA_MemoryToMemory Transfer from memory to memory (increment source and destination)
kDMA_PeripheralToMemory Transfer from peripheral to memory (increment only destination)
kDMA_MemoryToPeripheral Transfer from memory to peripheral (increment only source)
kDMA_StaticToStatic Peripheral to static memory (do not increment source or destination)
Enumerator
kStatus_DMA_Busy Channel is busy and can’t handle the transfer request.
This function enable the DMA clock, set descriptor table and enable DMA peripheral.
Parameters
Parameters
Returns
True for active state, false otherwise.
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Returns
True for enabled PeriphRq, false for disabled.
Parameters
Parameters
Returns
The number of bytes which have not been transferred yet.
Parameters
Parameters
Returns
Channel priority value.
Parameters
This function is called if using transaction API for DMA. This function initializes the internal state of
DMA handle.
Parameters
handle DMA handle pointer. The DMA handle stores callback function and parameters.
base DMA peripheral base address.
channel DMA channel number.
This callback is called in DMA IRQ handler. Use the callback to do something after the current major
loop transfer completes.
Parameters
This function prepares the transfer configuration structure according to the user input.
Parameters
Note
The data address and the data width must be consistent. For example, if the SRC is 4 bytes, so the
source address must be 4 bytes aligned, or it shall result in source address error(SAE).
This function submits the DMA transfer request according to the transfer configuration structure. If the
user submits the transfer request repeatedly, this function packs an unprocessed request as a TCD and
enables scatter/gather feature to process it in the next time.
Parameters
Return values
This function enables the channel request. User can call this function after submitting the transfer request
or before submitting the transfer request.
Parameters
This function clears the channel major interrupt flag and call the callback function if it is not NULL.
This function group implements DMIC initialization and deinitialization API. DMIC_Init() function En-
ables the clock to the DMIC register interface. DMIC_Dinit() function Disables the clock to the DMIC
register interface.
11.2.2 Configuration
This function group implements DMIC configration API. DMIC_ConfigIO()function configures the use
of PDM(Pulse Density moulation) pins. DMIC_SetOperationMode()function configures the mode of op-
eration either in DMA or in interrupt. DMIC_ConfigChannel() function configures the various property
of a DMIC channel. DMIC_Use2fs()function configures the Clock scaling used for PCM data output.
DMIC_EnableChannnel() function enables a particualr DMIC channel. DMIC_FifoChannel() function
configures FIFO settings for a DMIC channel.
This function group implements the API to get data and status of DMIC FIFO. DMIC_FifoGetStatus()
function gives the status of a DMIC FIFO. DMIC_ClearStatus() function clears the status of a DMIC
FIFO. DMIC_FifoGetData() function gets data from a DMIC FIFO.
DMIC_EnablebleIntCallback() enables the interrupt for the selected DMIC peripheral. DMIC_Disable-
IntCallback() disables the interrupt for the selected DMIC peripheral.
This function group implements the API for HWVAD DMIC_SetGainNoiseEstHwvad() Sets the gain
value for the noise estimator. DMIC_SetGainSignalEstHwvad() Sets the gain value for the signal estima-
tor. DMIC_SetFilterCtrlHwvad() Sets the hwvad filter cutoff frequency parameter. DMIC_SetInputGain-
Hwvad() Sets the input gain of hwvad. DMIC_CtrlClrIntrHwvad() Clears hwvad internal interrupt flag.
DMIC_FilterResetHwvad() Resets hwvad filters. DMIC_GetNoiseEnvlpEst() Gets the value from output
of the filter z7.
DMIC_HwvadEnableIntCallback() enables the hwvad interrupt for the selected DMIC peripheral. DMI-
C_HwvadDisableIntCallback() disables the hwvad interrupt for the selected DMIC peripheral.
dmic_channel_config_t dmic_channel_cfg;
dma_transfer_config_t transferConfig;
BOARD_InitHardware();
APPInit();
dmic_channel_cfg.divhfclk = kDMIC_Pdm_Div1;
dmic_channel_cfg.osr = 25U;
dmic_channel_cfg.gainshft = 1U;
dmic_channel_cfg.preac2coef = kDMIC_Comp0_0;
dmic_channel_cfg.preac4coef = kDMIC_Comp0_0;
dmic_channel_cfg.dc_cut_level = kDMIC_Dc_Cut155;
dmic_channel_cfg.post_dc_gain_reduce = 0U;
dmic_channel_cfg.saturate16bit = 1U;
dmic_channel_cfg.sample_rate = kDMIC_Phy_Full_Speed;
DMIC_Init(DMIC0);
DMIC_CfgIO(DMIC0, kPDM_Dual);
DMIC_Use2fs(DMIC0, true);
DMIC_SetOpMode(DMIC0, kDMIC_Op_Dma);
DMIC_CfgChannel(DMIC0, kDMIC_Ch0, kDMIC_Left, &dmic_channel_cfg);
DMIC_EnableChannnel(DMIC0, DMIC_CHANEN_EN_CH0(1));
PRINTF("Configure DMA\r\n");
DMA_Init(DMA0);
DMA_EnableChannel(DMA0, DMAREQ_DMIC0);
DMA_SubmitTransfer(&g_DMA_Handle, &transferConfig);
transferConfig.xfercfg.intA = false;
transferConfig.xfercfg.intB = true;
DMA_CreateDescriptor(&g_pingpong_desc[1], &transferConfig.
xfercfg, (void *)&DMIC0->CHANNEL[kDMIC_Ch0].FIFO_DATA,
&g_data_buffer[BUFFER_LENGTH / 2], &g_pingpong_desc[0]);
transferConfig.xfercfg.intA = true;
transferConfig.xfercfg.intB = false;
DMA_CreateDescriptor(&g_pingpong_desc[0], &transferConfig.
xfercfg, (void *)&DMIC0->CHANNEL[kDMIC_Ch0].FIFO_DATA,
&g_data_buffer[0], &g_pingpong_desc[1]);
DMA_StartTransfer(&g_DMA_Handle);
Modules
• DMIC DMA Driver
• DMIC Driver
Files
• file fsl_dmic.h
Data Structures
• struct dmic_channel_config_t
DMIC Channel configuration structure. More...
Typedefs
Enumerations
• enum operation_mode_t {
kDMIC_OperationModePoll = 0U,
kDMIC_OperationModeInterrupt = 1U,
kDMIC_OperationModeDma = 2U }
DMIC different operation modes.
• enum stereo_side_t {
kDMIC_Left = 0U,
kDMIC_Right = 1U }
DMIC left/right values.
• enum pdm_div_t {
kDMIC_PdmDiv1 = 0U,
kDMIC_PdmDiv2 = 1U,
kDMIC_PdmDiv3 = 2U,
kDMIC_PdmDiv4 = 3U,
kDMIC_PdmDiv6 = 4U,
kDMIC_PdmDiv8 = 5U,
kDMIC_PdmDiv12 = 6U,
kDMIC_PdmDiv16 = 7U,
kDMIC_PdmDiv24 = 8U,
kDMIC_PdmDiv32 = 9U,
kDMIC_PdmDiv48 = 10U,
kDMIC_PdmDiv64 = 11U,
kDMIC_PdmDiv96 = 12U,
kDMIC_PdmDiv128 = 13U }
DMIC Clock pre-divider values.
• enum compensation_t {
kDMIC_CompValueZero = 0U,
kDMIC_CompValueNegativePoint16 = 1U,
kDMIC_CompValueNegativePoint15 = 2U,
kDMIC_CompValueNegativePoint13 = 3U }
Pre-emphasis Filter coefficient value for 2FS and 4FS modes.
• enum dc_removal_t {
kDMIC_DcNoRemove = 0U,
kDMIC_DcCut155 = 1U,
kDMIC_DcCut78 = 2U,
kDMIC_DcCut39 = 3U }
DMIC DC filter control values.
• enum dmic_io_t {
kDMIC_PdmDual = 0U,
kDMIC_PdmStereo = 4U,
kDMIC_PdmBypass = 3U,
kDMIC_PdmBypassClk0 = 1U,
kDMIC_PdmBypassClk1 = 2U }
DMIC IO configiration.
• enum dmic_channel_t {
kDMIC_Channel0 = 0U,
kDMIC_Channel1 = 1U }
DMIC Channel number.
• enum dmic_phy_sample_rate_t {
kDMIC_PhyFullSpeed = 0U,
kDMIC_PhyHalfSpeed = 1U }
DMIC and decimator sample rates.
• enum _dmic_status {
kStatus_DMIC_Busy = MAKE_STATUS(kStatusGroup_DMIC, 0),
kStatus_DMIC_Idle = MAKE_STATUS(kStatusGroup_DMIC, 1),
kStatus_DMIC_OverRunError = MAKE_STATUS(kStatusGroup_DMIC, 2),
kStatus_DMIC_UnderRunError = MAKE_STATUS(kStatusGroup_DMIC, 3) }
DMIC transfer status.
Functions
DMIC version
Data Fields
• pdm_div_t divhfclk
DMIC Clock pre-divider values.
• uint32_t osr
oversampling rate(CIC decimation rate) for PCM
• int32_t gainshft
4FS PCM data gain control
• compensation_t preac2coef
Pre-emphasis Filter coefficient value for 2FS.
• compensation_t preac4coef
Pre-emphasis Filter coefficient value for 4FS.
• dc_removal_t dc_cut_level
DMIC DC filter control values.
• uint32_t post_dc_gain_reduce
Fine gain adjustment in the form of a number of bits to downshift.
• dmic_phy_sample_rate_t sample_rate
DMIC and decimator sample rates.
• bool saturate16bit
Selects 16-bit saturation.
0 means results roll over if out range and do not saturate. 1 means if the result overflows, it saturates at
0xFFFF for positive overflow and 0x8000 for negative overflow.
Enumerator
kDMIC_OperationModePoll Polling mode.
kDMIC_OperationModeInterrupt Interrupt mode.
kDMIC_OperationModeDma DMA mode.
Enumerator
kDMIC_Left Left Stereo channel.
kDMIC_Right Right Stereo channel.
Enumerator
kDMIC_PdmDiv1 DMIC pre-divider set in divide by 1.
kDMIC_PdmDiv2 DMIC pre-divider set in divide by 2.
kDMIC_PdmDiv3 DMIC pre-divider set in divide by 3.
kDMIC_PdmDiv4 DMIC pre-divider set in divide by 4.
kDMIC_PdmDiv6 DMIC pre-divider set in divide by 6.
kDMIC_PdmDiv8 DMIC pre-divider set in divide by 8.
kDMIC_PdmDiv12 DMIC pre-divider set in divide by 12.
kDMIC_PdmDiv16 DMIC pre-divider set in divide by 16.
kDMIC_PdmDiv24 DMIC pre-divider set in divide by 24.
kDMIC_PdmDiv32 DMIC pre-divider set in divide by 32.
kDMIC_PdmDiv48 DMIC pre-divider set in divide by 48.
kDMIC_PdmDiv64 DMIC pre-divider set in divide by 64.
Enumerator
kDMIC_CompValueZero Compensation 0.
kDMIC_CompValueNegativePoint16 Compensation -0.16.
kDMIC_CompValueNegativePoint15 Compensation -0.15.
kDMIC_CompValueNegativePoint13 Compensation -0.13.
Enumerator
kDMIC_DcNoRemove Flat response no filter.
kDMIC_DcCut155 Cut off Frequency is 155 Hz.
kDMIC_DcCut78 Cut off Frequency is 78 Hz.
kDMIC_DcCut39 Cut off Frequency is 39 Hz.
Enumerator
kDMIC_PdmDual Two separate pairs of PDM wires.
kDMIC_PdmStereo Stereo Mic.
kDMIC_PdmBypass Clk Bypass clocks both channels.
kDMIC_PdmBypassClk0 Clk Bypass clocks only channel0.
kDMIC_PdmBypassClk1 Clk Bypas clocks only channel1.
Enumerator
kDMIC_Channel0 DMIC channel 0.
kDMIC_Channel1 DMIC channel 1.
Enumerator
kDMIC_PhyFullSpeed Decimator gets one sample per each chosen clock edge of PDM interface.
kDMIC_PhyHalfSpeed PDM clock to Microphone is halved, decimator receives each sample twice.
Enumerator
kStatus_DMIC_Busy DMIC is busy.
kStatus_DMIC_Idle DMIC is idle.
kStatus_DMIC_OverRunError DMIC over run Error.
kStatus_DMIC_UnderRunError DMIC under run Error.
Parameters
Returns
DMIC instance.
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Parameters
Returns
FIFO status
Parameters
Returns
FIFO status
Parameters
Returns
FIFO data
This function enables the interrupt for the selected DMIC peripheral. The callback function is not enabled
until this function is called.
Parameters
Return values
None.
This function disables the interrupt for the selected DMIC peripheral.
Parameters
Return values
None.
Files
• file fsl_dmic_dma.h
Data Structures
• struct dmic_transfer_t
DMIC transfer structure. More...
• struct dmic_dma_handle_t
DMIC DMA handle. More...
Typedefs
DMA transactional
Data Fields
• uint16_t ∗ data
The buffer of data to be transfer.
• size_t dataSize
Data Fields
• DMIC_Type ∗ base
DMIC peripheral base address.
• dma_handle_t ∗ rxDmaHandle
The DMA RX channel used.
• dmic_dma_transfer_callback_t callback
Callback function.
• void ∗ userData
DMIC callback function parameter.
• size_t transferSize
Size of the data to receive.
• volatile uint8_t state
Internal state of DMIC DMA transfer.
Parameters
This function receives data using DMA. This is a non-blocking function, which returns right away. When
all data is received, the receive callback function is called.
Parameters
Return values
kStatus_Success
This function gets the number of bytes that have been received.
Parameters
Return values
Data Structures
• struct eeprom_config_t
EEPROM region configuration structure. More...
Enumerations
• enum eeprom_auto_program_t {
kEEPROM_AutoProgramDisable = 0x0,
kEEPROM_AutoProgramWriteWord = 0x1,
kEEPROM_AutoProgramLastWord = 0x2 }
EEPROM automatic program option.
• enum eeprom_interrupt_enable_t { kEEPROM_ProgramFinishInterruptEnable = EEPROM_INTE-
NSET_PROG_SET_EN_MASK }
EEPROM interrupt source.
Driver version
• #define FSL_EEPROM_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
EEPROM driver version 2.0.0.
Data Fields
• eeprom_auto_program_t autoProgram
Automatic program feature.
• uint8_t readWaitPhase1
EEPROM read waiting phase 1.
• uint8_t readWaitPhase2
EEPROM read waiting phase 2.
• uint8_t writeWaitPhase1
EEPROM write waiting phase 1.
• uint8_t writeWaitPhase2
EEPROM write waiting phase 2.
• uint8_t writeWaitPhase3
EEPROM write waiting phase 3.
• bool lockTimingParam
If lock the read and write wait phase settings.
Enumerator
kEEPROM_AutoProgramDisable Disable auto program.
kEEPROM_AutoProgramWriteWord Auto program triggered after 1 word is written.
kEEPROM_AutoProgramLastWord Auto program triggered after last word of a page written.
Enumerator
kEEPROM_ProgramFinishInterruptEnable Interrupt while program finished.
This function configures the EEPROM module with the user-defined configuration. This function also sets
the internal clock frequency to about 155kHz according to the source clock frequency.
Parameters
Parameters
Parameters
EEPROM write always needs a program and erase cycle to write the data into EEPROM. This program
and erase cycle can be finished automaticlly or manually. If users want to use or disable auto program
feature, users can call this API.
Parameters
This function make EEPROM eneter or out of power mode. Notice that, users shall not put EEPROM
into power down mode while there is still any pending EEPROM operation. While EEPROM is wakes up
from power down mode, any EEPROM operation has to be suspended for 100 us.
Parameters
Parameters
Parameters
Parameters
Returns
EEPROM interrupt flag status
Parameters
Returns
EEPROM enabled interrupt flag status
This API trigger a interrupt manually, users can no need to wait for hardware trigger interrupt. Call this
API will set the corresponding bit in INSTAT register.
Parameters
This API clears interrupt flags manually. Call this API will clear the corresponding bit in INSTAT register.
Parameters
Users can write a page or at least a word data into EEPROM address.
Parameters
Users can write a page or at least a word data into EEPROM address.
Parameters
// Basic configuration
emc_basic_config_t basiConfig =
{
kEMC_LittleEndian,
kEMC_IntloopbackEmcclk,
1, // EMC CLOCK DIV is 2
7, // cmd delay is 7
7, // feeback clock delay is 7
};
For the APP_DelayCal(): The system configure provided the command and feedback clock delay calibra-
tion for EMC EMCDYCTRL and EMCCAL. Application may require the change for these two system
configure register. please use the recommded work flow to choose the best delay.
// function calibration
uint32_t calibration(uint16_t times)
{
uint32_t i;
uint32_t value;
uint32_t count = 0;
if (!times)
{
return 0;
}
/* 16 bit write */
for (i = 0; i < SDRAM_SIZE/0x40000; i++)
{
for (j = 0; j < 0x10000; j++)
{
*short_wr_ptr++ = (i + j);
*short_wr_ptr++ = (i + j) + 1;
}
}
/* Verifying */
wr_ptr = (uint32_t *)SDRAM_BASE;
for (i = 0; i < SDRAM_SIZE/0x40000; i++)
{
for (j = 0; j < 0x10000; j++)
{
data = *wr_ptr;
if (data != (((((i + j) + 1) & 0xFFFF) << 16) | ((i + j) & 0xFFFF)))
{
return 0x0;
}
wr_ptr++;
}
}
return 0x1;
}
cmddly = 0x0;
cmddlystart = cmddlyend = 0xFF;
if (sdram_rwtest() == 0x1)
{
/* Test passed */
if (cmddlystart == 0xFF)
{
cmddlystart = cmddly;
}
ppass = 0x1;
}
else
{
/* Test failed */
if (ppass == 1)
{
cmddlyend = cmddly;
pass = 0x1;
ppass = 0x0;
}
}
/* If the test passed, the we can use the average of the min and max values to get an optimal DQSIN delay
*/
if (pass == 0x1)
{
cmddly = (cmddlystart + cmddlyend) / 2;
}
else if (ppass == 0x1)
{
cmddly = (cmddlystart + 0x1F) / 2;
}
else
{
/* A working value couldn’t be found, just pick something safe so the system doesn’t become unstable */
cmddly = 0x10;
}
fbclkdly = 0x0;
fbclkdlystart = fbclkdlyend = 0xFF;
if (sdram_rwtest() == 0x1)
{
/* Test passed */
if (fbclkdlystart == 0xFF)
{
fbclkdlystart = fbclkdly;
}
ppass = 0x1;
}
else
{
/* Test failed */
if (ppass == 1)
{
fbclkdlyend = fbclkdly;
pass = 0x1;
ppass = 0x0;
}
}
fbclkdly++;
}
/* If the test passed, the we can use the average of the min and max values to get an optimal DQSIN delay
*/
if (pass == 0x1)
{
fbclkdly = (fbclkdlystart + fbclkdlyend) / 2;
}
else if (ppass == 0x1)
{
fbclkdly = (fbclkdlystart + 0x1F) / 2;
}
else
{
/* A working value couldn’t be found, just pick something safe so the system doesn’t become unstable */
fbclkdly = 0x10;
}
// adjust the found the delay to the system configuration delay control register
void adjust_timing( void )
{
uint32_t dwtemp, cmddly, fbclkdly;
/* Current value */
ringosccount[1] = calibration();
dwtemp = SYSCON->EMCDLYCTRL;
cmddly = ((dwtemp & 0x1F) * ringosccount[0] / ringosccount[1]) & 0x1F;
APP_DelayCal()
{
ringosccount[0] = calibration();
if (find_cmddly() == 0x0)
{
while (1); /* fatal error */
}
if (find_fbclkdly() == 0x0)
{
while (1); /* fatal error */
}
adjust_timing();
}
Data Structures
• struct emc_dynamic_timing_config_t
EMC dynamic timing/delay configure structure. More...
• struct emc_dynamic_chip_config_t
EMC dynamic memory controller independent chip configuration structure. More...
• struct emc_static_chip_config_t
Macros
• #define EMC_STATIC_MEMDEV_NUM (4U)
Define the chip numbers for dynamic and static memory devices.
Enumerations
• enum emc_static_memwidth_t {
kEMC_8BitWidth = 0x0U,
kEMC_16BitWidth,
kEMC_32BitWidth }
Define EMC memory width for static memory device.
• enum emc_static_special_config_t {
kEMC_AsynchronosPageEnable = 0x0008U,
kEMC_ActiveHighChipSelect = 0x0040U,
kEMC_ByteLaneStateAllLow = 0x0080U,
kEMC_ExtWaitEnable = 0x0100U,
kEMC_BufferEnable = 0x80000U }
Define EMC static configuration.
• enum emc_dynamic_device_t {
kEMC_Sdram = 0x0U,
kEMC_Lpsdram }
EMC dynamic memory device.
• enum emc_dynamic_read_t {
kEMC_NoDelay = 0x0U,
kEMC_Cmddelay,
kEMC_CmdDelayPulseOneclk,
kEMC_CmddelayPulsetwoclk }
EMC dynamic read strategy.
• enum emc_endian_mode_t {
kEMC_LittleEndian = 0x0U,
kEMC_BigEndian }
EMC endian mode.
• enum emc_fbclk_src_t {
kEMC_IntloopbackEmcclk = 0U,
kEMC_EMCFbclkInput }
EMC Feedback clock input source select.
Driver version
• #define FSL_EMC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
EMC driver version 2.0.0.
Data Fields
• uint32_t refreshPeriod_Nanosec
The refresh period in unit of nanosecond.
• uint32_t tRp_Ns
Precharge command period in unit of nanosecond.
• uint32_t tRas_Ns
Active to precharge command period in unit of nanosecond.
• uint32_t tSrex_Ns
Self-refresh exit time in unit of nanosecond.
• uint32_t tApr_Ns
Last data out to active command time in unit of nanosecond.
• uint32_t tDal_Ns
Data-in to active command in unit of nanosecond.
• uint32_t tWr_Ns
Write recovery time in unit of nanosecond.
• uint32_t tRc_Ns
Active to active command period in unit of nanosecond.
• uint32_t tRfc_Ns
Auto-refresh period and auto-refresh to active command period in unit of nanosecond.
• uint32_t tXsr_Ns
Exit self-refresh to active command time in unit of nanosecond.
• uint32_t tRrd_Ns
Active bank A to active bank B latency in unit of nanosecond.
• uint8_t tMrd_Nclk
Load mode register to active command time in unit of EMCCLK cycles.
Please take refer to the address mapping table in the RM in EMC chapter when you set the "devAddrMap".
Choose the right Bit 14 Bit12 ∼ Bit 7 group in the table according to the bus width/banks/row/colum length
for you device. Set devAddrMap with the value make up with the seven bits (bit14 bit12 ∼ bit 7) and inset
the bit 13 with 0. for example, if the bit 14 and bit12 ∼ bit7 is 1000001 is choosen according to the 32bit
high-performance bus width with 2 banks, 11 row lwngth, 8 column length. Set devAddrMap with 0x81.
Data Fields
• uint8_t chipIndex
Chip Index, range from 0 ∼ EMC_DYNAMIC_MEMDEV_NUM - 1.
• emc_dynamic_device_t dynamicDevice
All chips shall use the same device setting.
• uint8_t rAS_Nclk
Active to read/write delay tRCD.
• uint16_t sdramModeReg
Sdram mode register setting.
• uint16_t sdramExtModeReg
Used for low-power sdram device.
• uint8_t devAddrMap
dynamic device address mapping, choose the address mapping for your specific device.
Data Fields
• emc_static_memwidth_t memWidth
Memory width.
• uint32_t specailConfig
Static configuration,a logical OR of "emc_static_special_config_t".
• uint32_t tWaitWriteEn_Ns
The delay form chip select to write enable in unit of nanosecond.
• uint32_t tWaitOutEn_Ns
The delay from chip selcet to output enable in unit of nanosecond.
• uint32_t tWaitReadNoPage_Ns
In No-page mode, the delay from chip select to read access in unit of nanosecond.
• uint32_t tWaitReadPage_Ns
In page mode, the read after the first read wait states in unit of nanosecond.
• uint32_t tWaitWrite_Ns
The delay from chip select to write access in unit of nanosecond.
• uint32_t tWaitTurn_Ns
The Bus turn-around time in unit of nanosecond.
Defines the static memory controller configure structure and uses the EMC_Init() function to make neces-
sary initializations.
Data Fields
• emc_endian_mode_t endian
Endian mode .
• emc_fbclk_src_t fbClkSrc
The feedback clock source.
• uint8_t emcClkDiv
EMC_CLK = AHB_CLK / (emc_clkDiv + 1).
Enumerator
kEMC_8BitWidth 8 bit memory width.
kEMC_16BitWidth 16 bit memory width.
kEMC_32BitWidth 32 bit memory width.
Enumerator
kEMC_AsynchronosPageEnable Enable the asynchronous page mode. page length four.
kEMC_ActiveHighChipSelect Chip select active high.
kEMC_ByteLaneStateAllLow Reads/writes the respective valuie bits in BLS3:0 are low.
kEMC_ExtWaitEnable Extended wait enable.
kEMC_BufferEnable Buffer enable.
Enumerator
kEMC_Sdram Dynamic memory device: SDRAM.
kEMC_Lpsdram Dynamic memory device: Low-power SDRAM.
Enumerator
kEMC_NoDelay No delay.
kEMC_Cmddelay Command delayed strategy, using EMCCLKDELAY.
kEMC_CmdDelayPulseOneclk Command delayed strategy pluse one clock cycle using EMCCLK-
DELAY.
kEMC_CmddelayPulsetwoclk Command delayed strategy pulse two clock cycle using EMCCLK-
DELAY.
Enumerator
kEMC_LittleEndian Little endian mode.
kEMC_BigEndian Big endian mode.
Enumerator
kEMC_IntloopbackEmcclk Use the internal loop back from EMC_CLK output.
kEMC_EMCFbclkInput Use the external EMC_FBCLK input.
This function ungates the EMC clock, initializes the emc system configure and enable the EMC module.
This function must be called in the first step to initialize the external memory.
Parameters
This function initializes the dynamic memory controller in external memory controller. This function must
be called after EMC_Init and before accessing the external dynamic memory.
Parameters
configure The EMC dynamic memory controller chip independent configuration pointer. This
configuration pointer is actually pointer to a configration array. the array number
depends on the "totalChips".
totalChips The total dynamic memory chip numbers been used or the length of the "emc_-
dynamic_chip_config_t" type memory.
This function initializes the static memory controller in external memory controller. This function must
be called after EMC_Init and before accessing the external static memory.
Parameters
This function gates the EMC controller clock. As a result, the EMC module doesn’t work after calling this
function.
Parameters
Parameters
Parameters
Enable the address mirror the EMC_CS1is mirrored to both EMC_CS0 and EMC_DYCS0 memory areas.
Disable the address mirror enables EMC_cS0 and EMC_DYCS0 memory to be accessed.
Parameters
This function can be used to get the operating mode of the EMC.
Parameters
Returns
The EMC in self-refresh mode if true, else in normal mode.
Parameters
All PTP 1588 fatures are enabled by define "ENET_PTP1588FEATURE_REQUIRED" This function
group configures the PTP IEEE 1588 feature, starts/stops/gets/sets/corrects the PTP IEEE 1588 timer, gets
the receive/transmit frame timestamp
The ENET_GetRxFrameTime() and ENET_GetTxFrameTime() functions are called by the PTP stack to
get the timestamp captured by the ENET driver.
enet_config_t config;
uint8_t index;
void *buff;
uint32_t refClock = 50000000;
phy_speed_t speed;
phy_duplex_t duplex;
uint32_t length = 0;
uint8_t *buffer;
uint32_t timedelay;
status_t status;
enet_buffer_config_t buffConfig = {
ENET_RXBD_NUM,
ENET_TXBD_NUM,
&g_txBuffDescrip[0],
&g_txBuffDescrip[0],
&g_rxBuffDescrip[0],
&g_rxBuffDescrip[ENET_RXBD_NUM],
&rxbuffer[0],
ENET_BuffSizeAlign(ENET_RXBUFF_SIZE),
};
PHY_Init(EXAMPLE_ENET_BASE, EXAMPLE_PHY_ADDR);
ENET_GetDefaultConfig(&config);
config.miiSpeed = (enet_mii_speed_t)speed;
config.miiDuplex = (enet_mii_duplex_t)duplex;
config.interrupt = kENET_DmaTx;
ENET_Init(EXAMPLE_ENET_BASE, &config, &g_macAddr[0], refClock);
ENET_CreateHandler(EXAMPLE_ENET_BASE, &g_handle, &config, &buffConfig, ENET_IntCallback,
NULL);
ENET_DescriptorInit(EXAMPLE_ENET_BASE, &config, &buffConfig);
ENET_StartRxTx(EXAMPLE_ENET_BASE, 1, 1);
ENET_BuildBroadCastFrame();
while (1)
{
status = ENET_GetRxFrameSize(EXAMPLE_ENET_BASE, &g_handle, &length, 0);
if ((status == kStatus_Success) && (length != 0))
{
uint8_t *data = (uint8_t *)malloc(length);
if (data)
{
status = ENET_ReadFrame(EXAMPLE_ENET_BASE, &g_handle, data, length, 0);
if (status == kStatus_Success)
{
PRINTF(" One frame received. the length %d \r\n", length);
PRINTF(" Dest Address %02x:%02x:%02x:%02x:%02x:%02x Src Address
%02x:%02x:%02x:%02x:%02x:%02x \r\n",
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8],
data[9],
data[10], data[11]);
}
free(data);
}
}
else if (status == kStatus_ENET_RxFrameError)
{
ENET_ReadFrame(EXAMPLE_ENET_BASE, &g_handle, NULL, 0, 0);
}
if (g_testIdx < ENET_EXAMPLE_SEND_COUNT)
{
if (PHY_GetLinkStatus(EXAMPLE_ENET_BASE, EXAMPLE_PHY_ADDR))
{
buffer = (uint8_t *)malloc(ENET_EXAMPLE_FRAME_SIZE);
if (buffer)
{
memcpy(buffer, &g_frame[g_txIdx], ENET_EXAMPLE_FRAME_SIZE);
g_txIdx = (g_txIdx + 1) % ENET_EXAMPLE_PACKAGETYPE;
g_txbuff[g_txbuffIdx] = buffer;
g_txbuffIdx = (g_txbuffIdx + 1) % ENET_TXBD_NUM;
if (kStatus_Success ==
ENET_SendFrame(EXAMPLE_ENET_BASE, &g_handle, buffer,
ENET_EXAMPLE_FRAME_SIZE))
{
g_testIdx++;
}
}
}
}
}
enet_config_t config;
uint8_t index;
void *buff;
uint32_t refClock = 50000000;
phy_speed_t speed;
phy_duplex_t duplex;
uint32_t length = 0;
uint8_t *buffer;
uint32_t data1, data2;
uint32_t timedelay;
enet_buffer_config_t buffConfig = {
ENET_RXBD_NUM,
ENET_TXBD_NUM,
&g_txBuffDescrip[0],
&g_txBuffDescrip[0],
&g_rxBuffDescrip[0],
&g_rxBuffDescrip[ENET_RXBD_NUM],
&rxbuffer[0],
ENET_BuffSizeAlign(ENET_RXBUFF_SIZE),
};
PHY_Init(EXAMPLE_ENET_BASE, EXAMPLE_PHY_ADDR);
ENET_GetDefaultConfig(&config);
ENET_EnableInterrupts(ENET, kENET_DmaTx);
EnableIRQ(ENET_EXAMPLE_IRQ);
ENET_StartRxTx(EXAMPLE_ENET_BASE, 1, 1);
ENET_BuildBroadCastFrame();
while (1)
{
ENET_GetRxDescriptor(&g_rxBuffDescrip[g_rxGenIdx], &data1, &data2, &length);
if (length > 0)
{
g_rxGenIdx = (g_rxGenIdx + 1) % ENET_RXBD_NUM;
void *buffer1;
buffer1 = malloc(ENET_RXBUFF_SIZE);
if (buffer1)
{
ENET_UpdateRxDescriptor(&g_rxBuffDescrip[g_rxCosumIdx], buffer1,
NULL, false, false);
g_rxCosumIdx = (g_rxCosumIdx + 1) % ENET_RXBD_NUM;
}
free((void *)data1);
}
g_txbuff[g_txbuffIdx] = buffer;
g_txbuffIdx = (g_txbuffIdx + 1) % ENET_TXBD_NUM;
while (ENET_TXQueue(buffer, ENET_EXAMPLE_FRAME_SIZE) != kStatus_Success)
;
g_testIdx++;
}
}
}
}
if (ENET_IsTxDescriptorDmaOwn(&g_txBuffDescrip[g_txGenIdx]))
{
return kStatus_Fail;
}
ENET_SetupTxDescriptor(&g_txBuffDescrip[g_txGenIdx], data, length, NULL, 0,
length, true, false, kENET_FirstLastFlag, 0);
txdescTailAddr = (uint32_t)&g_txBuffDescrip[g_txGenIdx];
if (!g_txGenIdx)
{
txdescTailAddr = (uint32_t)&g_txBuffDescrip[ENET_TXBD_NUM];
}
ENET_UpdateTxDescriptorTail(EXAMPLE_ENET_BASE, 0, txdescTailAddr);
return kStatus_Success;
}
Data Structures
• struct enet_rx_bd_struct_t
Defines the receive descriptor structure has the read-format and write-back format structure. More...
• struct enet_tx_bd_struct_t
Defines the transmit descriptor structure has the read-format and write-back format structure. More...
• struct enet_buffer_config_t
Defines the buffer descriptor configure structure. More...
• struct enet_multiqueue_config_t
Defines the configuration when multi-queue is used. More...
• struct enet_config_t
Defines the basic configuration structure for the ENET device. More...
• struct enet_tx_bd_ring_t
Defines the ENET transmit buffer descriptor ring/queue structure. More...
• struct enet_rx_bd_ring_t
Defines the ENET receive buffer descriptor ring/queue structure. More...
• struct enet_handle_t
Defines the ENET handler structure. More...
Typedefs
• typedef void(∗ enet_callback_t )(ENET_Type ∗base, enet_handle_t ∗handle, enet_event_t event,
uint8_t channel, void ∗userData)
ENET callback function.
Enumerations
• enum _enet_status {
kStatus_ENET_RxFrameError = MAKE_STATUS(kStatusGroup_ENET, 0U),
kStatus_ENET_RxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 1U),
kStatus_ENET_RxFrameEmpty = MAKE_STATUS(kStatusGroup_ENET, 2U),
kStatus_ENET_TxFrameBusy = MAKE_STATUS(kStatusGroup_ENET, 3U),
kStatus_ENET_TxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 4U),
kStatus_ENET_TxFrameOverLen = MAKE_STATUS(kStatusGroup_ENET, 5U) }
Defines the status return codes for transaction.
• enum enet_mii_mode_t {
kENET_MiiMode = 0U,
kENET_RmiiMode = 1U }
Defines the MII/RMII mode for data interface between the MAC and the PHY.
• enum enet_mii_speed_t {
kENET_MiiSpeed10M = 0U,
kENET_MiiSpeed100M = 1U }
Defines the 10/100 Mbps speed for the MII data interface.
• enum enet_mii_duplex_t {
kENET_MiiHalfDuplex = 0U,
kENET_MiiFullDuplex }
Defines the half or full duplex for the MII data interface.
• enum enet_mii_normal_opcode {
kENET_MiiWriteFrame = 1U,
kENET_MiiReadFrame = 3U }
Define the MII opcode for normal MDIO_CLAUSES_22 Frame.
• enum enet_dma_burstlen {
kENET_BurstLen1 = 0x00001U,
kENET_BurstLen2 = 0x00002U,
kENET_BurstLen4 = 0x00004U,
kENET_BurstLen8 = 0x00008U,
kENET_BurstLen16 = 0x00010U,
kENET_BurstLen32 = 0x00020U,
kENET_BurstLen64 = 0x10008U,
kENET_BurstLen128 = 0x10010U,
kENET_BurstLen256 = 0x10020U }
Define the DMA maximum transmit burst length.
• enum enet_desc_flag {
kENET_MiddleFlag = 0,
kENET_FirstFlagOnly,
kENET_LastFlagOnly,
kENET_FirstLastFlag }
Define the flag for the descriptor.
• enum enet_systime_op {
kENET_SystimeAdd = 0U,
kENET_SystimeSubtract = 1U }
Define the system time adjust operation control.
• enum enet_ts_rollover_type {
kENET_BinaryRollover = 0,
kENET_DigitalRollover = 1 }
Define the system time rollover control.
• enum enet_special_config_t {
kENET_DescDoubleBuffer = 0x0001U,
kENET_StoreAndForward = 0x0002U,
kENET_PromiscuousEnable = 0x0004U,
kENET_FlowControlEnable = 0x0008U,
kENET_BroadCastRxDisable = 0x0010U,
kENET_MulticastAllEnable = 0x0020U,
kENET_8023AS2KPacket = 0x0040U }
Defines some special configuration for ENET.
• enum enet_dma_interrupt_enable_t {
kENET_DmaTx = ENET_DMA_CH_DMA_CHX_INT_EN_TIE_MASK,
kENET_DmaTxStop = ENET_DMA_CH_DMA_CHX_INT_EN_TSE_MASK,
kENET_DmaTxBuffUnavail = ENET_DMA_CH_DMA_CHX_INT_EN_TBUE_MASK,
kENET_DmaRx = ENET_DMA_CH_DMA_CHX_INT_EN_RIE_MASK,
kENET_DmaRxBuffUnavail = ENET_DMA_CH_DMA_CHX_INT_EN_RBUE_MASK,
kENET_DmaRxStop = ENET_DMA_CH_DMA_CHX_INT_EN_RSE_MASK,
kENET_DmaRxWatchdogTimeout = ENET_DMA_CH_DMA_CHX_INT_EN_RWTE_MASK,
kENET_DmaEarlyTx = ENET_DMA_CH_DMA_CHX_INT_EN_ETIE_MASK,
kENET_DmaEarlyRx = ENET_DMA_CH_DMA_CHX_INT_EN_ERIE_MASK,
kENET_DmaBusErr = ENET_DMA_CH_DMA_CHX_INT_EN_FBEE_MASK }
List of DMA interrupts supported by the ENET interrupt.
• enum enet_mac_interrupt_enable_t
List of mac interrupts supported by the ENET interrupt.
• enum enet_event_t {
kENET_RxIntEvent,
kENET_TxIntEvent,
kENET_WakeUpIntEvent,
kENET_TimeStampIntEvent }
Defines the common interrupt event for callback use.
• enum enet_dma_tx_sche {
kENET_FixPri = 0,
kENET_WeightStrPri,
kENET_WeightRoundRobin }
Define the DMA transmit arbitration for multi-queue.
• enum enet_mtl_multiqueue_txsche {
kENET_txWeightRR = 0U,
kENET_txStrPrio = 3U }
Define the MTL tx scheduling algorithm for multiple queues/rings.
• enum enet_mtl_multiqueue_rxsche {
kENET_rxStrPrio = 0U,
kENET_rxWeightStrPrio }
Define the MTL rx scheduling algorithm for multiple queues/rings.
• enum enet_mtl_rxqueuemap {
kENET_StaticDirctMap = 0x100U,
kENET_DynamicMap }
Define the MTL rx queue and DMA channel mapping.
• enum enet_ptp_event_type_t {
kENET_PtpEventMsgType = 3U,
kENET_PtpSrcPortIdLen = 10U,
kENET_PtpEventPort = 319U,
kENET_PtpGnrlPort = 320U }
Defines the ENET PTP message related constant.
Driver version
• #define FSL_ENET_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Defines the driver version.
Control and status region bit masks of the receive buffer descriptor.
• #define ENET_RXDESCRIP_RD_BUFF1VALID_MASK (1U << 24)
Defines for read format.
• #define ENET_RXDESCRIP_RD_BUFF2VALID_MASK (1U << 25)
Buffer2 address valid.
• #define ENET_RXDESCRIP_RD_IOC_MASK (1U << 30)
Interrupt enable on complete.
• #define ENET_RXDESCRIP_RD_OWN_MASK (1U << 31)
Own bit.
• #define ENET_RXDESCRIP_WR_ERR_MASK ((1U << 3) | (1U << 7))
Defines for write back format.
• #define ENET_RXDESCRIP_WR_PYLOAD_MASK (0x7U)
• #define ENET_RXDESCRIP_WR_PTPMSGTYPE_MASK (0xF00U)
• #define ENET_RXDESCRIP_WR_PTPTYPE_MASK (1U << 12)
• #define ENET_RXDESCRIP_WR_PTPVERSION_MASK (1U << 13)
• #define ENET_RXDESCRIP_WR_PTPTSA_MASK (1U << 14)
• #define ENET_RXDESCRIP_WR_PACKETLEN_MASK (0x7FFFU)
• #define ENET_RXDESCRIP_WR_ERRSUM_MASK (1U << 15)
• #define ENET_RXDESCRIP_WR_TYPE_MASK (0x30000U)
• #define ENET_RXDESCRIP_WR_DE_MASK (1U << 19)
• #define ENET_RXDESCRIP_WR_RE_MASK (1U << 20)
• #define ENET_RXDESCRIP_WR_OE_MASK (1U << 21)
• #define ENET_RXDESCRIP_WR_RS0V_MASK (1U << 25)
• #define ENET_RXDESCRIP_WR_RS1V_MASK (1U << 26)
• #define ENET_RXDESCRIP_WR_RS2V_MASK (1U << 27)
• #define ENET_RXDESCRIP_WR_LD_MASK (1U << 28)
• #define ENET_RXDESCRIP_WR_FD_MASK (1U << 29)
• #define ENET_RXDESCRIP_WR_CTXT_MASK (1U << 30)
• #define ENET_RXDESCRIP_WR_OWN_MASK (1U << 31)
Interrupts.
• void ENET_EnableInterrupts (ENET_Type ∗base, uint32_t mask)
Enables the ENET DMA and MAC interrupts.
• void ENET_DisableInterrupts (ENET_Type ∗base, uint32_t mask)
Disables the ENET DMA and MAC interrupts.
• static uint32_t ENET_GetDmaInterruptStatus (ENET_Type ∗base, uint8_t channel)
Gets the ENET DMA interrupt status flag.
• static void ENET_ClearDmaInterruptStatus (ENET_Type ∗base, uint8_t channel, uint32_t mask)
Clear the ENET DMA interrupt status flag.
• static uint32_t ENET_GetMacInterruptStatus (ENET_Type ∗base)
Gets the ENET MAC interrupt status flag.
• void ENET_ClearMacInterruptStatus (ENET_Type ∗base, uint32_t mask)
Clears the ENET mac interrupt events status flag.
Functional operation.
• static bool ENET_IsTxDescriptorDmaOwn (enet_tx_bd_struct_t ∗txDesc)
Get the tx descriptor DMA Own flag.
• void ENET_SetupTxDescriptor (enet_tx_bd_struct_t ∗txDesc, void ∗buffer1, uint32_t bytes1, void
∗buffer2, uint32_t bytes2, uint32_t framelen, bool intEnable, bool tsEnable, enet_desc_flag flag,
uint8_t slotNum)
Transactional operation
• void ENET_CreateHandler (ENET_Type ∗base, enet_handle_t ∗handle, enet_config_t ∗config,
enet_buffer_config_t ∗bufferConfig, enet_callback_t callback, void ∗userData)
Create ENET Handler.
• status_t ENET_GetRxFrameSize (ENET_Type ∗base, enet_handle_t ∗handle, uint32_t ∗length,
uint8_t channel)
Gets the size of the read frame.
• status_t ENET_ReadFrame (ENET_Type ∗base, enet_handle_t ∗handle, uint8_t ∗data, uint32_t
length, uint8_t channel)
Reads a frame from the ENET device.
• status_t ENET_SendFrame (ENET_Type ∗base, enet_handle_t ∗handle, uint8_t ∗data, uint32_t
length)
Transmits an ENET frame.
• void ENET_ReclaimTxDescriptor (ENET_Type ∗base, enet_handle_t ∗handle, uint8_t channel)
Reclaim tx descriptors.
• void ENET_PMTIRQHandler (ENET_Type ∗base, enet_handle_t ∗handle)
The ENET PMT IRQ handler.
• void ENET_IRQHandler (ENET_Type ∗base, enet_handle_t ∗handle)
The ENET IRQ handler.
They both has the same size with different region definition. so we define the read-format region as the
recive descriptor structure Use the read-format region mask bits in the descriptor initialization Use the
write-back format region mask bits in the receive data process.
Data Fields
They both has the same size with different region definition. so we define the read-format region as the
transmit descriptor structure Use the read-format region mask bits in the descriptor initialization Use the
write-back format region mask bits in the transmit data process.
Data Fields
Notes:
1. The receive and transmit descriptor start address pointer and tail pointer must be word-aligned.
2. The recommended minimum tx/rx ring length is 4.
3. The tx/rx descriptor tail address shall be the address pointer to the address just after the end of the
last last descriptor. because only the descriptors between the start address and the tail address will
be used by DMA.
4. The decriptor address is the start address of all used contiguous memory. for example, the rxDesc-
StartAddrAlign is the start address of rxRingLen contiguous descriptor memorise for rx descriptor
ring 0.
5. The "∗rxBufferstartAddr" is the first element of rxRingLen (2∗rxRingLen for double buffers) rx
buffers. It means the ∗rxBufferStartAddr is the rx buffer for the first descriptor the ∗rxBufferStart-
Addr + 1 is the rx buffer for the second descriptor or the rx buffer for the second buffer in the first
descriptor. so please make sure the rxBufferStartAddr is the address of a rxRingLen or 2∗rxRingLen
array.
Data Fields
• uint8_t rxRingLen
Data Fields
• enet_dma_tx_sche dmaTxSche
Transmit arbitation.
• enet_dma_burstlen burstLen
Burset len for the queue 1.
• uint8_t txdmaChnWeight [ENET_RING_NUM_MAX]
Transmit channel weight.
• enet_mtl_multiqueue_txsche mtltxSche
Transmit schedule for multi-queue.
• enet_mtl_multiqueue_rxsche mtlrxSche
Receive schedule for multi-queue.
• uint8_t rxqueweight [ENET_RING_NUM_MAX]
Refer to the MTL RxQ Control register.
Note:
1. Default the signal queue is used so the "∗multiqueueCfg" is set default with NULL. Set the pointer
with a valid configration pointer if the multiple queues are required. If multiple queue is enabled,
please make sure the buffer configuration for all are prepared also.
Data Fields
• uint16_t specialControl
The logicl or of enet_special_config_t.
• enet_multiqueue_config_t ∗ multiqueueCfg
Use both tx/rx queue(dma channel) 0 and 1.
• enet_mii_mode_t miiMode
MII mode.
• enet_mii_speed_t miiSpeed
MII Speed.
• enet_mii_duplex_t miiDuplex
MII duplex.
• uint16_t pauseDuration
Used in the tx flow control frame, only valid when kENET_FlowControlEnable is set.
Data Fields
• enet_tx_bd_struct_t ∗ txBdBase
Buffer descriptor base address pointer.
• uint16_t txGenIdx
tx generate index.
• uint16_t txConsumIdx
tx consum index.
• volatile uint16_t txDescUsed
tx descriptor used number.
• uint16_t txRingLen
tx ring length.
Data Fields
• enet_rx_bd_struct_t ∗ rxBdBase
Data Fields
• bool multiQueEnable
Enable multi-queue.
• bool doubleBuffEnable
The double buffer is used in the descriptor.
• bool rxintEnable
Rx interrup enabled.
• enet_rx_bd_ring_t rxBdRing [ENET_RING_NUM_MAX]
Receive buffer descriptor.
• enet_tx_bd_ring_t txBdRing [ENET_RING_NUM_MAX]
Transmit buffer descriptor.
• enet_callback_t callback
Callback function.
• void ∗ userData
Callback function parameter.
Version 2.0.0.
Enumerator
kStatus_ENET_RxFrameError A frame received but data error happen.
kStatus_ENET_RxFrameFail Failed to receive a frame.
kStatus_ENET_RxFrameEmpty No frame arrive.
kStatus_ENET_TxFrameBusy Transmit descriptors are under process.
Enumerator
kENET_MiiMode MII mode for data interface.
kENET_RmiiMode RMII mode for data interface.
Enumerator
kENET_MiiSpeed10M Speed 10 Mbps.
kENET_MiiSpeed100M Speed 100 Mbps.
Enumerator
kENET_MiiHalfDuplex Half duplex mode.
kENET_MiiFullDuplex Full duplex mode.
Enumerator
kENET_MiiWriteFrame Write frame operation for a valid MII management frame.
kENET_MiiReadFrame Read frame operation for a valid MII management frame.
Enumerator
kENET_BurstLen1 DMA burst length 1.
kENET_BurstLen2 DMA burst length 2.
kENET_BurstLen4 DMA burst length 4.
kENET_BurstLen8 DMA burst length 8.
Enumerator
kENET_MiddleFlag It’s a middle descriptor of the frame.
kENET_FirstFlagOnly It’s the first descriptor of the frame.
kENET_LastFlagOnly It’s the last descriptor of the frame.
kENET_FirstLastFlag It’s the first and last descriptor of the frame.
Enumerator
kENET_SystimeAdd System time add to.
kENET_SystimeSubtract System time subtract.
Enumerator
kENET_BinaryRollover System time binary rollover.
kENET_DigitalRollover System time digital rollover.
These control flags are provided for special user requirements. Normally, these is no need to set this control
flags for ENET initialization. But if you have some special requirements, set the flags to specialControl in
the enet_config_t.
Note
"kENET_StoreAndForward" is recommended to be set when the ENET_PTP1588FEATURE_RE-
QUIRED is defined or else the timestamp will be mess-up when the overflow happens.
Enumerator
kENET_DescDoubleBuffer The double buffer is used in the tx/rx descriptor.
kENET_StoreAndForward The rx/tx store and forward enable.
kENET_PromiscuousEnable The promiscuous enabled.
kENET_FlowControlEnable The flow control enabled.
kENET_BroadCastRxDisable The broadcast disabled.
kENET_MulticastAllEnable All multicast are passed.
kENET_8023AS2KPacket 8023as support for 2K packets.
Enumerator
kENET_RxIntEvent Receive interrupt event.
kENET_TxIntEvent Transmit interrupt event.
kENET_WakeUpIntEvent Wake up interrupt event.
kENET_TimeStampIntEvent Time stamp interrupt event.
Enumerator
kENET_FixPri Fixed priority. channel 0 has lower priority than channel 1.
kENET_WeightStrPri Weighted(burst length) strict priority.
kENET_WeightRoundRobin Weighted (weight factor) round robin.
Enumerator
kENET_txWeightRR Tx weight round-robin.
kENET_txStrPrio Tx strict priority.
Enumerator
kENET_rxStrPrio Tx weight round-robin, rx strict priority.
kENET_rxWeightStrPrio Tx strict priority, rx weight strict priority.
Enumerator
kENET_StaticDirctMap The received fame in rx Qn(n = 0,1) direclty map to dma channel n.
kENET_DynamicMap The received frame in rx Qn(n = 0,1) map to the dma channel m(m = 0,1)
related with the same Mac.
Enumerator
kENET_PtpEventMsgType PTP event message type.
kENET_PtpSrcPortIdLen PTP message sequence id length.
kENET_PtpEventPort PTP event port number.
kENET_PtpGnrlPort PTP general port number.
The purpose of this API is to get the default ENET configure structure for ENET_Init(). User may use
the initialized structure unchanged in ENET_Init(), or modify some fields of the structure before calling
ENET_Init(). Example:
enet_config_t config;
ENET_GetDefaultConfig(&config);
Parameters
This function ungates the module clock and initializes it with the ENET basic configuration.
Parameters
This function gates the module clock and disables the ENET module.
Parameters
Note
This function is do all tx/rx descriptors initialization. Because this API read all interrupt registers first
and then set the interrupt flag for all descriptos, if the interrupt register is set. so the descriptor initial-
ization should be called after ENET_Init(), ENET_EnableInterrupts() and ENET_CreateHandle()(if
transactional APIs are used).
Parameters
This function enable the tx/rx and starts the rx/tx DMA. This shall be set after ENET initialization and
before starting to receive the data.
Parameters
Note
This must be called after all the ENET initilization. And should be called when the ENET re-
ceive/transmit is required.
This API is provided to dynamically change the speed and dulpex for MAC.
Parameters
Parameters
Parameters
Returns
The status of MII Busy status.
Parameters
Returns
The data read from PHY
Parameters
Parameters
Parameters
macAddr The six-byte Mac address pointer. The pointer is allocated by application and input
into the API.
the remote power wake up frame and magic frame can wake up the ENET from the power down mode.
Parameters
Eixt from the power down mode and recover to noraml work mode.
Parameters
This function enables the ENET interrupt according to the provided mask. The mask is a logical OR of
enet_dma_interrupt_enable_t and enet_mac_interrupt_enable_t. For example, to enable the dma and mac
interrupt, do the following.
* ENET_EnableInterrupts(ENET, kENET_DmaRx |
kENET_DmaTx | kENET_MacPmt);
*
Parameters
This function disables the ENET interrupt according to the provided mask. The mask is a logical OR of
enet_dma_interrupt_enable_t and enet_mac_interrupt_enable_t. For example, to disable the dma and mac
interrupt, do the following.
* ENET_DisableInterrupts(ENET, kENET_DmaRx |
kENET_DmaTx | kENET_MacPmt);
*
Parameters
Parameters
Returns
The event status of the interrupt source. This is the logical OR of members of the enumeration ::
enet_dma_interrupt_enable_t.
Parameters
Returns
The event status of the interrupt source. This is the logical OR of members of the enumeration ::
enet_dma_interrupt_enable_t.
Parameters
Returns
The event status of the interrupt source. Use the enum in enet_mac_interrupt_enable_t and right shift
ENET_MACINT_ENUM_OFFSET to mask the returned value to get the exact interrupt status.
This function clears enabled ENET interrupts according to the provided mask. The mask is a logical O-
R of enumeration members. See the enet_mac_interrupt_enable_t. For example, to clear the TX frame
interrupt and RX frame interrupt, do the following.
* ENET_ClearMacInterruptStatus(ENET, kENET_MacPmt);
*
Parameters
Parameters
Return values
This function is a low level functional API to setup or prepare a given tx descriptor.
Parameters
Note
This must be called after all the ENET initilization. And should be called when the ENET re-
ceive/transmit is required. Transmit buffers are ’zero-copy’ buffers, so the buffer must remain in
memory until the packet has been fully transmitted. The buffers should be free or requeued in the
transmit interrupt irq handler.
This function is a low level functional API to update the the tx descriptor tail. This is called after you
setup a new tx descriptor to update the tail pointer to make the new descritor accessable by DMA.
Parameters
This function is a low level functional API to update the the rx descriptor tail. This is called after you
setup a new rx descriptor to update the tail pointer to make the new descritor accessable by DMA and to
anouse the rx poll command for DMA.
Parameters
This function is a low level functional API to get the the status flag from a given rx descriptor.
Parameters
Return values
Note
This must be called after all the ENET initilization. And should be called when the ENET re-
ceive/transmit is required.
This function is a low level functional API to Updates the buffers and the own status for a given rx
descriptor.
Parameters
Note
This must be called after all the ENET initilization. And should be called when the ENET re-
ceive/transmit is required.
This is a transactional API and it’s provided to store all datas which are needed during the whole trans-
actional process. This API should not be used when you use functional APIs to do data tx/rx. This is
funtion will store many data/flag for transactional use, so all configure API such as ENET_Init(), ENET-
_DescriptorInit(), ENET_EnableInterrupts() etc.
Note
as our transactional transmit API use the zero-copy transmit buffer. so there are two thing we em-
phasize here:
1. tx buffer free/requeue for application should be done in the tx interrupt handler. Please set
callback: kENET_TxIntEvent with tx buffer free/requeue process APIs.
2. the tx interrupt is forced to open.
Parameters
This function gets a received frame size from the ENET buffer descriptors.
Note
The FCS of the frame is automatically removed by MAC and the size is the length without the FCS.
After calling ENET_GetRxFrameSize, ENET_ReadFrame() should be called to update the receive
buffers If the result is not "kStatus_ENET_RxFrameEmpty".
Parameters
handle The ENET handler structure. This is the same handler pointer used in the ENET_Init.
length The length of the valid frame received.
channel The DMAC channel for the rx.
Return values
This function reads a frame from the ENET DMA descriptors. The ENET_GetRxFrameSize should be
used to get the size of the prepared data buffer. For example use rx dma channel 0:
* uint32_t length;
* enet_handle_t g_handle;
Parameters
Returns
The execute status, successful or failure.
Note
The CRC is automatically appended to the data. Input the data to send without the CRC.
Parameters
Return values
This function is used to update the tx descriptor status and store the tx timestamp when the 1588 feature
is enabled. This is called by the transmit interupt IRQ handler after the complete of a frame transmission.
Parameters
Parameters
Parameters
/* Erase sector 1 */
FLASHIAP_EraseSector(1, 1, SystemCoreClock);
/* Write sector 1 */
FLASHIAP_CopyRamToFlash(SECTOR_1_ADRESS, DATA_BUFFER_ADDRESS, NUM_OF_BYTES_TO_WRITE,
SystemCoreClock);
Files
• file fsl_flashiap.h
Typedefs
• typedef void(∗ IAP_ENTRY_T )(uint32_t cmd[5], uint32_t stat[4])
IAP_ENTRY API function type.
Enumerations
• enum _flashiap_status {
kStatus_FLASHIAP_Success = kStatus_Success,
kStatus_FLASHIAP_InvalidCommand = MAKE_STATUS(kStatusGroup_FLASHIAP, 1U),
kStatus_FLASHIAP_SrcAddrError,
kStatus_FLASHIAP_DstAddrError,
kStatus_FLASHIAP_SrcAddrNotMapped,
kStatus_FLASHIAP_DstAddrNotMapped,
kStatus_FLASHIAP_CountError,
kStatus_FLASHIAP_InvalidSector,
kStatus_FLASHIAP_SectorNotblank = MAKE_STATUS(kStatusGroup_FLASHIAP, 8U),
kStatus_FLASHIAP_NotPrepared,
kStatus_FLASHIAP_CompareError,
kStatus_FLASHIAP_Busy,
kStatus_FLASHIAP_ParamError,
kStatus_FLASHIAP_AddrError = MAKE_STATUS(kStatusGroup_FLASHIAP, 13U),
kStatus_FLASHIAP_AddrNotMapped,
kStatus_FLASHIAP_NoPower = MAKE_STATUS(kStatusGroup_FLASHIAP, 24U),
kStatus_FLASHIAP_NoClock }
Flashiap status codes.
• enum _flashiap_commands {
kIapCmd_FLASHIAP_PrepareSectorforWrite = 50U,
kIapCmd_FLASHIAP_CopyRamToFlash = 51U,
kIapCmd_FLASHIAP_EraseSector = 52U,
kIapCmd_FLASHIAP_BlankCheckSector = 53U,
kIapCmd_FLASHIAP_ReadPartId = 54U,
kIapCmd_FLASHIAP_Read_BootromVersion = 55U,
kIapCmd_FLASHIAP_Compare = 56U,
kIapCmd_FLASHIAP_ReinvokeISP = 57U,
kIapCmd_FLASHIAP_ReadUid = 58U,
kIapCmd_FLASHIAP_ErasePage = 59U,
kIapCmd_FLASHIAP_ReadMisr = 70U,
kIapCmd_FLASHIAP_ReinvokeI2cSpiISP = 71U }
Flashiap command codes.
Functions
• static void iap_entry (uint32_t ∗cmd_param, uint32_t ∗status_result)
IAP_ENTRY API function type.
• status_t FLASHIAP_PrepareSectorForWrite (uint32_t startSector, uint32_t endSector)
Prepare sector for write operation.
• status_t FLASHIAP_CopyRamToFlash (uint32_t dstAddr, uint32_t ∗srcAddr, uint32_t numOf-
Bytes, uint32_t systemCoreClock)
Copy RAM to flash.
• status_t FLASHIAP_EraseSector (uint32_t startSector, uint32_t endSector, uint32_t systemCore-
Clock)
Erase sector.
• status_t FLASHIAP_ErasePage (uint32_t startPage, uint32_t endPage, uint32_t systemCoreClock)
This function erases page(s).
• status_t FLASHIAP_BlankCheckSector (uint32_t startSector, uint32_t endSector)
Blank check sector(s)
• status_t FLASHIAP_Compare (uint32_t dstAddr, uint32_t ∗srcAddr, uint32_t numOfBytes)
Compare memory contents of flash with ram.
Driver version
• #define FSL_FLASHIAP_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Version 2.0.0.
Enumerator
kStatus_FLASHIAP_Success Api is executed successfully.
kStatus_FLASHIAP_InvalidCommand Invalid command.
kStatus_FLASHIAP_SrcAddrError Source address is not on word boundary.
kStatus_FLASHIAP_DstAddrError Destination address is not on a correct boundary.
kStatus_FLASHIAP_SrcAddrNotMapped Source address is not mapped in the memory map.
kStatus_FLASHIAP_DstAddrNotMapped Destination address is not mapped in the memory map.
kStatus_FLASHIAP_CountError Byte count is not multiple of 4 or is not a permitted value.
kStatus_FLASHIAP_InvalidSector Sector number is invalid or end sector number is greater than
start sector number.
kStatus_FLASHIAP_SectorNotblank One or more sectors are not blank.
kStatus_FLASHIAP_NotPrepared Command to prepare sector for write operation was not exe-
cuted.
kStatus_FLASHIAP_CompareError Destination and source memory contents do not match.
kStatus_FLASHIAP_Busy Flash programming hardware interface is busy.
kStatus_FLASHIAP_ParamError Insufficient number of parameters or invalid parameter.
kStatus_FLASHIAP_AddrError Address is not on word boundary.
kStatus_FLASHIAP_AddrNotMapped Address is not mapped in the memory map.
kStatus_FLASHIAP_NoPower Flash memory block is powered down.
kStatus_FLASHIAP_NoClock Flash memory block or controller is not clocked.
Enumerator
kIapCmd_FLASHIAP_PrepareSectorforWrite Prepare Sector for write.
kIapCmd_FLASHIAP_CopyRamToFlash Copy RAM to flash.
kIapCmd_FLASHIAP_EraseSector Erase Sector.
kIapCmd_FLASHIAP_BlankCheckSector Blank check sector.
kIapCmd_FLASHIAP_ReadPartId Read part id.
kIapCmd_FLASHIAP_Read_BootromVersion Read bootrom version.
kIapCmd_FLASHIAP_Compare Compare.
kIapCmd_FLASHIAP_ReinvokeISP Reinvoke ISP.
kIapCmd_FLASHIAP_ReadUid Read Uid isp.
kIapCmd_FLASHIAP_ErasePage Erase Page.
kIapCmd_FLASHIAP_ReadMisr Read Misr.
kIapCmd_FLASHIAP_ReinvokeI2cSpiISP Reinvoke I2C/SPI isp.
Return values
This function prepares sector(s) for write/erase operation. This function must be called before calling the
FLASHIAP_CopyRamToFlash() or FLASHIAP_EraseSector() or FLASHIAP_ErasePage() function. The
end sector must be greater than or equal to start sector number.
Parameters
Return values
This function programs the flash memory. Corresponding sectors must be prepared via FLASHIAP_-
PrepareSectorForWrite before calling calling this function. The addresses should be a 256 byte boundary
and the number of bytes should be 256 | 512 | 1024 | 4096.
Parameters
Return values
This function erases sector(s). The end sector must be greater than or equal to start sector number. FLAS-
HIAP_PrepareSectorForWrite must be called before calling this function.
Parameters
Return values
The end page must be greater than or equal to start page number. Corresponding sectors must be prepared
via FLASHIAP_PrepareSectorForWrite before calling calling this function.
Parameters
Return values
kStatus_FLASHIAP_Not- Command to prepare sector for write operation was not executed.
Prepared
kStatus_FLASHIAP_Busy Flash programming hardware interface is busy.
Blank check single or multiples sectors of flash memory. The end sector must be greater than or equal to
start sector number. It can be used to verify the sector eraseure after FLASHIAP_EraseSector call.
Parameters
startSector : Start sector number. Must be greater than or equal to start sector number
endSector : End sector number
Return values
This function compares the contents of flash and ram. It can be used to verify the flash memory contents
after FLASHIAP_CopyRamToFlash call.
Parameters
Return values
i2c_master_config_t masterConfig;
uint8_t status;
status_t result = kStatus_Success;
uint8_t txBuff[BUFFER_SIZE];
if(result)
{
/* If error occours, send STOP. */
I2C_MasterStop(EXAMPLE_I2C_MASTER_BASEADDR, kI2CStop);
return result;
}
i2c_master_handle_t g_m_handle;
volatile bool g_MasterCompletionFlag = false;
i2c_master_config_t masterConfig;
uint8_t status;
status_t result = kStatus_Success;
uint8_t txBuff[BUFFER_SIZE];
i2c_master_transfer_t masterXfer;
masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = NULL;
masterXfer.subaddressSize = 0;
masterXfer.data = txBuff;
masterXfer.dataSize = BUFFER_SIZE;
masterXfer.flags = kI2C_TransferDefaultFlag;
I2C_MasterTransferCreateHandle(EXAMPLE_I2C_MASTER_BASEADDR, &g_m_handle,
i2c_master_callback, NULL);
I2C_MasterTransferNonBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &g_m_handle, &
masterXfer);
i2c_master_dma_handle_t g_m_dma_handle;
dma_handle_t dmaHandle;
volatile bool g_MasterCompletionFlag = false;
i2c_master_config_t masterConfig;
uint8_t txBuff[BUFFER_SIZE];
i2c_master_transfer_t masterXfer;
masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = NULL;
masterXfer.subaddressSize = 0;
masterXfer.data = txBuff;
masterXfer.dataSize = BUFFER_SIZE;
masterXfer.flags = kI2C_TransferDefaultFlag;
DMA_EnableChannel(EXAMPLE_DMA, EXAMPLE_I2C_MASTER_CHANNEL);
DMA_CreateHandle(&dmaHandle, EXAMPLE_DMA, EXAMPLE_I2C_MASTER_CHANNEL);
I2C_MasterTransferCreateHandleDMA(EXAMPLE_I2C_MASTER_BASEADDR, &
g_m_dma_handle, i2c_master_callback, NULL, &dmaHandle);
I2C_MasterTransferDMA(EXAMPLE_I2C_MASTER_BASEADDR, &g_m_dma_handle, &masterXfer);
i2c_slave_config_t slaveConfig;
uint8_t status;
status_t result = kStatus_Success;
return result;
i2c_slave_config_t slaveConfig;
i2c_slave_handle_t g_s_handle;
volatile bool g_SlaveCompletionFlag = false;
/* Receive request */
case kI2C_SlaveReceiveEvent:
/* Update information for received process */
xfer->data = g_slave_buff;
xfer->dataSize = I2C_DATA_LENGTH;
break;
/* Transfer done */
case kI2C_SlaveCompletionEvent:
g_SlaveCompletionFlag = true;
break;
default:
g_SlaveCompletionFlag = true;
break;
}
}
I2C_SlaveInit(EXAMPLE_I2C_SLAVE_BASEADDR, &slaveConfig);
I2C_SlaveTransferCreateHandle(EXAMPLE_I2C_SLAVE_BASEADDR, &g_s_handle,
i2c_slave_callback, NULL);
I2C_SlaveTransferNonBlocking(EXAMPLE_I2C_SLAVE_BASEADDR, &g_s_handle,
kI2C_SlaveCompletionEvent);
g_SlaveCompletionFlag = false;
Modules
• I2C DMA Driver
• I2C Driver
• I2C FreeRTOS Driver
• I2C Master Driver
• I2C Slave Driver
Files
• file fsl_i2c.h
Macros
Enumerations
• enum _i2c_status {
kStatus_I2C_Busy = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 0),
kStatus_I2C_Idle = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 1),
kStatus_I2C_Nak,
kStatus_I2C_InvalidParameter,
kStatus_I2C_BitError = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 4),
kStatus_I2C_ArbitrationLost = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 5),
kStatus_I2C_NoTransferInProgress,
kStatus_I2C_DmaRequestFail = MAKE_STATUS(kStatusGroup_FLEXCOMM_I2C, 7) }
I2C status return codes.
Driver version
Enumerator
kStatus_I2C_Busy The master is already performing a transfer.
kStatus_I2C_Idle The slave driver is idle.
kStatus_I2C_Nak The slave device sent a NAK in response to a byte.
kStatus_I2C_InvalidParameter Unable to proceed due to invalid parameter.
kStatus_I2C_BitError Transferred bit was not seen on the bus.
kStatus_I2C_ArbitrationLost Arbitration lost error.
kStatus_I2C_NoTransferInProgress Attempt to abort a transfer when one is not in progress.
kStatus_I2C_DmaRequestFail DMA request failed.
Data Structures
• struct i2c_master_config_t
Structure with settings to initialize the I2C master module. More...
• struct i2c_master_transfer_t
Non-blocking transfer descriptor structure. More...
• struct i2c_master_handle_t
Driver handle for master non-blocking APIs. More...
Typedefs
Enumerations
• enum _i2c_master_flags {
kI2C_MasterPendingFlag = I2C_STAT_MSTPENDING_MASK,
kI2C_MasterArbitrationLostFlag = I2C_STAT_MSTARBLOSS_MASK,
kI2C_MasterStartStopErrorFlag = I2C_STAT_MSTSTSTPERR_MASK }
I2C master peripheral flags.
• enum i2c_direction_t {
kI2C_Write = 0U,
kI2C_Read = 1U }
Direction of master and slave transfers.
• enum _i2c_master_transfer_flags {
kI2C_TransferDefaultFlag = 0x00U,
kI2C_TransferNoStartFlag = 0x01U,
kI2C_TransferRepeatedStartFlag = 0x02U,
kI2C_TransferNoStopFlag = 0x04U }
Transfer option flags.
• enum _i2c_transfer_states
States for the state machine used by transactional APIs.
Status
Interrupts
Bus operations
Non-blocking
IRQ handler
This structure holds configuration settings for the I2C peripheral. To initialize this structure to reason-
able defaults, call the I2C_MasterGetDefaultConfig() function and pass a pointer to your configuration
structure instance.
The configuration structure can be made constant so it resides in flash.
Data Fields
• bool enableMaster
Whether to enable master mode.
• uint32_t baudRate_Bps
Desired baud rate in bits per second.
• bool enableTimeout
Enable internal timeout function.
Data Fields
• uint32_t flags
Bit mask of options for the transfer.
• uint16_t slaveAddress
The 7-bit slave address.
• i2c_direction_t direction
Either kI2C_Read or kI2C_Write.
• uint32_t subaddress
Sub address.
• size_t subaddressSize
Length of sub address to send in bytes.
• void ∗ data
Pointer to data to transfer.
• size_t dataSize
Number of bytes to transfer.
Note
The contents of this structure are private and subject to change.
Data Fields
• uint8_t state
Transfer state machine current state.
• uint32_t transferCount
Indicates progress of the transfer.
• uint32_t remainingBytes
Remaining byte count in current state.
• uint8_t ∗ buf
Buffer pointer for current state.
• i2c_master_transfer_t transfer
Copy of the current transfer info.
• i2c_master_transfer_callback_t completionCallback
Callback function pointer.
• void ∗ userData
Application data passed to callback.
This callback is used only for the non-blocking master transfer API. Specify the callback you wish to use
in the call to I2C_MasterTransferCreateHandle().
Parameters
Note
These enums are meant to be OR’d together to form a bit mask.
Enumerator
kI2C_MasterPendingFlag The I2C module is waiting for software interaction.
kI2C_MasterArbitrationLostFlag The arbitration of the bus was lost. There was collision on the
bus
kI2C_MasterStartStopErrorFlag There was an error during start or stop phase of the transaction.
Enumerator
kI2C_Write Master transmit.
kI2C_Read Master receive.
Note
These enumerations are intended to be OR’d together to form a bit mask of options for the _i2c_-
master_transfer::flags field.
Enumerator
kI2C_TransferDefaultFlag Transfer starts with a start signal, stops with a stop signal.
kI2C_TransferNoStartFlag Don’t send a start condition, address, and sub address.
kI2C_TransferRepeatedStartFlag Send a repeated start condition.
kI2C_TransferNoStopFlag Don’t send a stop condition.
This function provides the following default configuration for the I2C master peripheral:
* masterConfig->enableMaster = true;
* masterConfig->baudRate_Bps = 100000U;
* masterConfig->enableTimeout = false;
*
After calling this function, you can override any settings in order to customize the configuration, prior to
initializing the master driver with I2C_MasterInit().
Parameters
out masterConfig User provided configuration structure for default values. Refer to i2c_-
master_config_t.
This function enables the peripheral clock and initializes the I2C master peripheral as described by the
user provided configuration. A software reset is performed prior to configuration.
Parameters
This function disables the I2C master peripheral and gates the clock. It also performs a software reset to
restore the peripheral to reset conditions.
Parameters
Parameters
A bit mask with the state of all I2C status flags is returned. For each flag, the corresponding bit in the
return value is set if the flag is asserted.
Parameters
Returns
State of the status flags:
• 1: related status flag is set.
• 0: related status flag is not set.
See Also
_i2c_master_flags
See Also
_i2c_master_flags.
Parameters
Parameters
Parameters
Returns
A bitmask composed of _i2c_master_flags enumerators OR’d together to indicate the set of enabled
interrupts.
The I2C master is automatically disabled and re-enabled as necessary to configure the baud rate. Do not
call this function during a transfer, or the transfer is aborted.
Parameters
Return values
This function is used to initiate a new master mode transfer by sending the START signal. The slave
address is sent following the I2C START signal.
Parameters
Return values
Return values
Parameters
Return values
Sends up to txSize number of bytes to the previously addressed slave device. The slave may reply with a
NAK to any byte in order to terminate the transfer early. If this happens, this function returns kStatus_I2-
C_Nak.
Parameters
Return values
Parameters
Return values
Note
The API does not return until the transfer succeeds or fails due to arbitration lost or receiving a NAK.
Parameters
Return values
The creation of a handle is for use with the non-blocking APIs. Once a handle is created, there is not a
corresponding destroy handle. If the user wants to terminate a transfer, the I2C_MasterTransferAbort()
API shall be called.
Parameters
Parameters
Return values
Parameters
Return values
kStatus_Success
kStatus_I2C_Busy
Note
It is not safe to call this function from an IRQ handler that has a higher priority than the I2C periph-
eral’s IRQ priority.
Parameters
Return values
Note
This function does not need to be called unless you are reimplementing the nonblocking API’s inter-
rupt handler routines to add special functionality.
Parameters
Data Structures
• struct i2c_slave_address_t
Data structure with 7-bit Slave address and Slave address disable. More...
• struct i2c_slave_config_t
Structure with settings to initialize the I2C slave module. More...
• struct i2c_slave_transfer_t
I2C slave transfer structure. More...
• struct i2c_slave_handle_t
I2C slave handle structure. More...
Typedefs
Enumerations
• enum _i2c_slave_flags {
kI2C_SlavePendingFlag = I2C_STAT_SLVPENDING_MASK,
kI2C_SlaveNotStretching = I2C_STAT_SLVNOTSTR_MASK,
kI2C_SlaveSelected = I2C_STAT_SLVSEL_MASK,
kI2C_SaveDeselected = I2C_STAT_SLVDESEL_MASK }
I2C slave peripheral flags.
• enum i2c_slave_address_register_t {
kI2C_SlaveAddressRegister0 = 0U,
kI2C_SlaveAddressRegister1 = 1U,
kI2C_SlaveAddressRegister2 = 2U,
kI2C_SlaveAddressRegister3 = 3U }
I2C slave address register.
• enum i2c_slave_address_qual_mode_t {
kI2C_QualModeMask = 0U,
kI2C_QualModeExtend }
I2C slave address match options.
• enum i2c_slave_bus_speed_t
I2C slave bus speed options.
• enum i2c_slave_transfer_event_t {
kI2C_SlaveAddressMatchEvent = 0x01U,
kI2C_SlaveTransmitEvent = 0x02U,
kI2C_SlaveReceiveEvent = 0x04U,
kI2C_SlaveCompletionEvent = 0x20U,
kI2C_SlaveDeselectedEvent,
kI2C_SlaveAllEvents }
Set of events sent to the callback for non blocking slave transfers.
• enum i2c_slave_fsm_t
I2C slave software finite state machine states.
Slave status
Slave non-blocking
Data Fields
• uint8_t address
7-bit Slave address SLVADR.
• bool addressDisable
Slave address disable SADISABLE.
This structure holds configuration settings for the I2C slave peripheral. To initialize this structure to rea-
sonable defaults, call the I2C_SlaveGetDefaultConfig() function and pass a pointer to your configuration
structure instance.
The configuration structure can be made constant so it resides in flash.
Data Fields
• i2c_slave_address_t address0
Slave’s 7-bit address and disable.
• i2c_slave_address_t address1
Alternate slave 7-bit address and disable.
• i2c_slave_address_t address2
Alternate slave 7-bit address and disable.
• i2c_slave_address_t address3
Alternate slave 7-bit address and disable.
• i2c_slave_address_qual_mode_t qualMode
Qualify mode for slave address 0.
• uint8_t qualAddress
Slave address qualifier for address 0.
• i2c_slave_bus_speed_t busSpeed
Slave bus speed mode.
• bool enableSlave
Enable slave mode.
If the slave function stretches SCL to allow for software response, it must provide sufficient data setup
time to the master before releasing the stretched clock. This is accomplished by inserting one clock time
of CLKDIV at that point. The busSpeed value is used to configure CLKDIV such that one clock time is
greater than the tSU;DAT value noted in the I2C bus specification for the I2C mode that is being used. If
the busSpeed mode is unknown at compile time, use the longest data setup time kI2C_SlaveStandardMode
(250 ns)
Data Fields
• i2c_slave_handle_t ∗ handle
Pointer to handle that contains this transfer.
• i2c_slave_transfer_event_t event
Note
The contents of this structure are private and subject to change.
Data Fields
• volatile i2c_slave_transfer_t transfer
I2C slave transfer.
• volatile bool isBusy
This callback is used only for the slave non-blocking transfer API. To install a callback, use the I2C_-
SlaveSetCallback() function after you have created a handle.
Parameters
base Base address for the I2C instance on which the event occurred.
transfer Pointer to transfer descriptor containing values passed to and/or from the callback.
userData Arbitrary pointer-sized value passed from the application.
Note
These enums are meant to be OR’d together to form a bit mask.
Enumerator
kI2C_SlavePendingFlag The I2C module is waiting for software interaction.
kI2C_SlaveNotStretching Indicates whether the slave is currently stretching clock (0 = yes, 1 = no).
Enumerator
kI2C_SlaveAddressRegister0 Slave Address 0 register.
kI2C_SlaveAddressRegister1 Slave Address 1 register.
kI2C_SlaveAddressRegister2 Slave Address 2 register.
kI2C_SlaveAddressRegister3 Slave Address 3 register.
Enumerator
kI2C_QualModeMask The SLVQUAL0 field (qualAddress) is used as a logical mask for matching
address0.
kI2C_QualModeExtend The SLVQUAL0 (qualAddress) field is used to extend address 0 matching
in a range of addresses.
These event enumerations are used for two related purposes. First, a bit mask created by OR’ing together
events is passed to I2C_SlaveTransferNonBlocking() in order to specify which events to enable. Then,
when the slave callback is invoked, it is passed the current event through its transfer parameter.
Note
These enumerations are meant to be OR’d together to form a bit mask of events.
Enumerator
kI2C_SlaveAddressMatchEvent Received the slave address after a start or repeated start.
kI2C_SlaveTransmitEvent Callback is requested to provide data to transmit (slave-transmitter role).
This function provides the following default configuration for the I2C slave peripheral:
* slaveConfig->enableSlave = true;
* slaveConfig->address0.disable = false;
* slaveConfig->address0.address = 0u;
* slaveConfig->address1.disable = true;
* slaveConfig->address2.disable = true;
* slaveConfig->address3.disable = true;
* slaveConfig->busSpeed = kI2C_SlaveStandardMode;
*
After calling this function, override any settings to customize the configuration, prior to initializing the
master driver with I2C_SlaveInit(). Be sure to override at least the address0.address member of the con-
figuration structure with the desired slave address.
Parameters
out slaveConfig User provided configuration structure that is set to default values. Refer
to i2c_slave_config_t.
This function enables the peripheral clock and initializes the I2C slave peripheral as described by the user
provided configuration.
Parameters
Parameters
This function disables the I2C slave peripheral and gates the clock. It also performs a software reset to
restore the peripheral to reset conditions.
Parameters
Parameters
See Also
_i2c_slave_flags.
The function executes blocking address phase and blocking data phase.
Parameters
Returns
kStatus_Success Data has been sent.
kStatus_Fail Unexpected slave state (master data write while master read from slave is expected).
The function executes blocking address phase and blocking data phase.
Parameters
Returns
kStatus_Success Data has been received.
kStatus_Fail Unexpected slave state (master data read while master write to slave is expected).
The creation of a handle is for use with the non-blocking APIs. Once a handle is created, there is not a
corresponding destroy handle. If the user wants to terminate a transfer, the I2C_SlaveTransferAbort() API
shall be called.
Parameters
Call this API after calling I2C_SlaveInit() and I2C_SlaveTransferCreateHandle() to start processing trans-
actions driven by an I2C master. The slave monitors the I2C bus and pass events to the callback that
was passed into the call to I2C_SlaveTransferCreateHandle(). The callback is always invoked from the
interrupt context.
If no slave Tx transfer is busy, a master read from slave request invokes kI2C_SlaveTransmitEvent call-
back. If no slave Rx transfer is busy, a master write to slave request invokes kI2C_SlaveReceiveEvent
callback.
The set of events received by the callback is customizable. To do so, set the eventMask parameter to the
OR’d combination of i2c_slave_transfer_event_t enumerators for the events you wish to receive. The k-
I2C_SlaveTransmitEvent and kI2C_SlaveReceiveEvent events are always enabled and do not need to be
included in the mask. Alternatively, you can pass 0 to get a default set of only the transmit and receive
events that are always enabled. In addition, the kI2C_SlaveAllEvents constant is provided as a convenient
way to enable all events.
Parameters
Return values
The function can be called in response to kI2C_SlaveTransmitEvent callback to start a new slave Tx
transfer from within the transfer callback.
The set of events received by the callback is customizable. To do so, set the eventMask parameter to the
OR’d combination of i2c_slave_transfer_event_t enumerators for the events you wish to receive. The k-
I2C_SlaveTransmitEvent and kI2C_SlaveReceiveEvent events are always enabled and do not need to be
included in the mask. Alternatively, you can pass 0 to get a default set of only the transmit and receive
events that are always enabled. In addition, the kI2C_SlaveAllEvents constant is provided as a convenient
way to enable all events.
Parameters
Return values
The function can be called in response to kI2C_SlaveReceiveEvent callback to start a new slave Rx transfer
from within the transfer callback.
The set of events received by the callback is customizable. To do so, set the eventMask parameter to the
OR’d combination of i2c_slave_transfer_event_t enumerators for the events you wish to receive. The k-
I2C_SlaveTransmitEvent and kI2C_SlaveReceiveEvent events are always enabled and do not need to be
included in the mask. Alternatively, you can pass 0 to get a default set of only the transmit and receive
events that are always enabled. In addition, the kI2C_SlaveAllEvents constant is provided as a convenient
way to enable all events.
Parameters
Return values
This function should only be called from the address match event callback kI2C_SlaveAddressMatch-
Event.
Parameters
Returns
The 8-bit address matched by the I2C slave. Bit 0 contains the R/w direction bit, and the 7-bit slave
address is in the upper 7 bits.
Note
This API could be called at any time to stop slave for handling the bus events.
Parameters
Return values
kStatus_Success
kStatus_I2C_Idle
Parameters
Return values
Note
This function does not need to be called unless you are reimplementing the non blocking API’s
interrupt handler routines to add special functionality.
Parameters
Data Structures
• struct i2c_master_dma_handle_t
I2C master dma transfer structure. More...
Macros
Typedefs
Data Fields
• uint8_t state
Parameters
Parameters
Return values
Parameters
Parameters
Data Structures
• struct i2c_rtos_handle_t
I2C FreeRTOS handle. More...
Data Fields
• I2C_Type ∗ base
I2C base address.
• i2c_master_handle_t drv_handle
A handle of the underlying driver, treated as opaque by the RTOS layer.
• status_t async_status
Transactional state of the underlying driver.
• SemaphoreHandle_t mutex
A mutex to lock the handle during a transfer.
• SemaphoreHandle_t semaphore
A semaphore to notify and unblock task when the transfer ends.
This function initializes the I2C module and the related RTOS context.
Parameters
handle The RTOS I2C handle, the pointer to an allocated space for RTOS context.
base The pointer base address of the I2C instance to initialize.
masterConfig Configuration structure to set-up I2C in master mode.
srcClock_Hz Frequency of input clock of the I2C module.
Returns
status of the operation.
This function deinitializes the I2C module and the related RTOS context.
Parameters
This function performs an I2C transfer according to data given in the transfer structure.
Parameters
Returns
status of the operation.
Length of buffer for transmit or receive has to be multiply of 4 bytes. Buffer address has to be aligned
to 4-bytes. Data are put into or taken from FIFO unaltered in DMA mode so buffer has to be prepared
according to following information.
If i2s_config_t.dataLength (channel bit width) is between 4 and 16, every word in buffer should contain
data for left and right channels.
MSB LSB
R15 R14R13R12R11R10R09R08R07R06R05R04R03R02R01R00L15L14L13L12L11L10L09L08L07L06L05L04L03L02L01L00
MSB LSB
L23L22L21L20L19L18L17L16L15L14L13L12L11L10L09L08L07L06L05L04L03L02L01L00
MSB LSB
R23R22R21R20R19R18R17R16R15R14R13R12R11R10R09R08R07R06R05R04R03R02R01R00
MSB LSB
R07 R06R05R04R03R02R01R00L23L22L21L20L19L18L17L16L15L14L13L12L11L10L09L08L07L06L05L04L03L02L01L00
MSB LSB
R23R22R21R20R19R18R17R16R15R14R13R12R11R10R09R08
MSB LSB
L31 L30L29L28L27L26L25L24L23L22L21L20L19L18L17L16L15L14L13L12L11L10L09L08L07L06L05L04L03L02L01L00
MSB LSB
R31 R30R29R28R27R26R25R24R23R22R21R20R19R18R17R16R15R14R13R12R11R10R09R08R07R06R05R04R03R02R01R00
MSB LSB
R03 R02 R01 R00 L03 L02 L01 L00
MSB LSB
R07 R06 R05 R04 R03 R02 R01 R00 L07 L06 L05 L04 L03 L02 L01 L00
MSB LSB
R15 R14R13R12R11R10R09R08R07R06R05R04R03R02R01R00L15L14L13L12L11L10L09L08L07L06L05L04L03L02L01L00
MSB
R23 R22
R21
R20
R19
R18
R17
R16
R15
R14
R13
R12
R11
R10
R09
R08
R07
R06
R05
R04
R03
R02
R01
R00
L23
L22
L21
L20
L19
L18
L17
L16
L15
L14
L13
L12
L11
L10
L09
L08
L07
L0
MSB
R23 R22
R21
R20
R19
R18
R17
R16
R15
R14
R13
R12
R11
R10
R09
R08
R07
R06
R05
R04
R03
R02
R01
R00
L23
L22
L21
L20
L19
L18
L17
L16
L15
L14
L13
L12
L11
L10
L09
L08
L07
L0
MSB LSB
L31 L30L29L28L27L26L25L24L23L22L21L20L19L18L17L16L15L14L13L12L11L10L09L08L07L06L05L04L03L02L01L00
MSB LSB
R31 R30R29R28R27R26R25R24R23R22R21R20R19R18R17R16R15R14R13R12R11R10R09R08R07R06R05R04R03R02R01R00
MSB LSB
L31 L30L29L28L27L26L25L24L23L22L21L20L19L18L17L16L15L14L13L12L11L10L09L08L07L06L05L04L03L02L01L00
Transmit example
void StartTransfer(void)
{
i2s_config_t config;
i2s_transfer_t transfer;
i2s_handle_t handle;
I2S_TxGetDefaultConfig(&config);
config.masterSlave = kI2S_MasterSlaveNormalMaster;
config.divider = 32; /* clock frequency/audio sample frequency/channels/channel bit depth */
I2S_TxInit(I2S0, &config);
transfer.data = buffer;
transfer.dataSize = sizeof(buffer);
I2S_TxTransferNonBlocking(I2S0, &handle, transfer);
/* Enqueue next buffer right away so there is no drop in audio data stream when the first buffer
finishes */
I2S_TxTransferNonBlocking(I2S0, &handle, someTransfer);
}
if (completionStatus == kStatus_I2S_BufferComplete)
{
/* Enqueue next buffer */
transfer.data = buffer;
transfer.dataSize = sizeof(buffer);
I2S_TxTransferNonBlocking(base, handle, transfer);
}
}
Receive example
void StartTransfer(void)
{
i2s_config_t config;
i2s_transfer_t transfer;
i2s_handle_t handle;
I2S_RxGetDefaultConfig(&config);
config.masterSlave = kI2S_MasterSlaveNormalMaster;
config.divider = 32; /* clock frequency/audio sample frequency/channels/channel bit depth */
I2S_RxInit(I2S0, &config);
transfer.data = buffer;
transfer.dataSize = sizeof(buffer);
I2S_RxTransferNonBlocking(I2S0, &handle, transfer);
/* Enqueue next buffer right away so there is no drop in audio data stream when the first buffer
finishes */
I2S_RxTransferNonBlocking(I2S0, &handle, someTransfer);
}
if (completionStatus == kStatus_I2S_BufferComplete)
{
/* Enqueue next buffer */
transfer.data = buffer;
transfer.dataSize = sizeof(buffer);
I2S_RxTransferNonBlocking(base, handle, transfer);
}
}
Transmit example
void StartTransfer(void)
{
i2s_config_t config;
i2s_transfer_t transfer;
i2s_dma_handle_t handle;
I2S_TxGetDefaultConfig(&config);
config.masterSlave = kI2S_MasterSlaveNormalMaster;
config.divider = 32; /* clock frequency/audio sample frequency/channels/channel bit depth */
I2S_TxInit(I2S0, &config);
transfer.data = buffer;
transfer.dataSize = sizeof(buffer);
/* Enqueue next buffer right away so there is no drop in audio data stream when the first buffer
finishes */
I2S_TxTransferNonBlockingDMA(I2S0, &handle, someTransfer);
}
if (completionStatus == kStatus_I2S_BufferComplete)
{
/* Enqueue next buffer */
transfer.data = buffer;
transfer.dataSize = sizeof(buffer);
I2S_TxTransferNonBlockingDMA(base, handle, transfer);
}
}
Receive example
void StartTransfer(void)
{
i2s_config_t config;
i2s_transfer_t transfer;
i2s_dma_handle_t handle;
I2S_RxGetDefaultConfig(&config);
config.masterSlave = kI2S_MasterSlaveNormalMaster;
config.divider = 32; /* clock frequency/audio sample frequency/channels/channel bit depth */
I2S_RxInit(I2S0, &config);
transfer.data = buffer;
transfer.dataSize = sizeof(buffer);
I2S_RxTransferNonBlockingDMA(I2S0, &handle, transfer);
/* Enqueue next buffer right away so there is no drop in audio data stream when the first buffer
finishes */
I2S_RxTransferNonBlockingDMA(I2S0, &handle, someTransfer);
}
if (completionStatus == kStatus_I2S_BufferComplete)
{
/* Enqueue next buffer */
transfer.data = buffer;
transfer.dataSize = sizeof(buffer);
I2S_RxTransferNonBlockingDMA(base, handle, transfer);
}
}
Modules
• I2S DMA Driver
• I2S Driver
Files
• file fsl_i2s.h
Data Structures
• struct i2s_config_t
I2S configuration structure. More...
• struct i2s_transfer_t
Buffer to transfer from or receive audio data into. More...
• struct i2s_handle_t
Members not to be accessed / modified outside of the driver. More...
Macros
Typedefs
Enumerations
• enum _i2s_status {
kStatus_I2S_BufferComplete,
kStatus_I2S_Done = MAKE_STATUS(kStatusGroup_I2S, 1),
kStatus_I2S_Busy }
I2S status codes.
• enum i2s_flags_t {
kI2S_TxErrorFlag = I2S_FIFOINTENSET_TXERR_MASK,
kI2S_TxLevelFlag = I2S_FIFOINTENSET_TXLVL_MASK,
kI2S_RxErrorFlag = I2S_FIFOINTENSET_RXERR_MASK,
kI2S_RxLevelFlag = I2S_FIFOINTENSET_RXLVL_MASK }
I2S flags.
• enum i2s_master_slave_t {
kI2S_MasterSlaveNormalSlave = 0x0,
kI2S_MasterSlaveWsSyncMaster = 0x1,
kI2S_MasterSlaveExtSckMaster = 0x2,
kI2S_MasterSlaveNormalMaster = 0x3 }
Master / slave mode.
• enum i2s_mode_t {
kI2S_ModeI2sClassic = 0x0,
kI2S_ModeDspWs50 = 0x1,
kI2S_ModeDspWsShort = 0x2,
kI2S_ModeDspWsLong = 0x3 }
I2S mode.
Driver version
Non-blocking API
Enable / disable
Interrupts
Data Fields
• i2s_master_slave_t masterSlave
Master / slave configuration.
• i2s_mode_t mode
I2S mode.
• bool rightLow
Right channel data in low portion of FIFO.
• bool leftJust
Left justify data in FIFO.
• bool pdmData
Data source is the D-Mic subsystem.
• bool sckPol
SCK polarity.
• bool wsPol
WS polarity.
• uint16_t divider
Flexcomm function clock divider (1 - 4096)
• bool oneChannel
true mono, false stereo
• uint8_t dataLength
Data length (4 - 32)
• uint16_t frameLength
Frame width (4 - 512)
• uint16_t position
Data position in the frame.
• uint8_t watermark
FIFO trigger level.
• bool txEmptyZero
Transmit zero when buffer becomes empty or last item.
• bool pack48
Packing format for 48-bit data (false - 24 bit values, true - alternating 32-bit and 16-bit values)
Data Fields
• volatile uint8_t ∗ data
Pointer to data buffer.
• volatile size_t dataSize
Buffer size in bytes.
Data Fields
• uint32_t state
State of transfer.
• i2s_transfer_callback_t completionCallback
Callback function pointer.
• void ∗ userData
Application data passed to callback.
• bool oneChannel
Parameters
Enumerator
kStatus_I2S_BufferComplete Transfer from/into a single buffer has completed.
kStatus_I2S_Done All buffers transfers have completed.
kStatus_I2S_Busy Already performing a transfer and cannot queue another buffer.
Note
These enums are meant to be OR’d together to form a bit mask.
Enumerator
kI2S_TxErrorFlag TX error interrupt.
kI2S_TxLevelFlag TX level interrupt.
kI2S_RxErrorFlag RX error interrupt.
kI2S_RxLevelFlag RX level interrupt.
Enumerator
kI2S_MasterSlaveNormalSlave Normal slave.
kI2S_MasterSlaveWsSyncMaster WS synchronized master.
kI2S_MasterSlaveExtSckMaster Master using existing SCK.
kI2S_MasterSlaveNormalMaster Normal master.
Enumerator
kI2S_ModeI2sClassic I2S classic mode.
Ungates the FLEXCOMM clock and configures the module for I2S transmission using a configuration
structure. The configuration structure can be custom filled or set with default values by I2S_TxGet-
DefaultConfig().
Note
This API should be called at the beginning of the application to use the I2S driver.
Parameters
Ungates the FLEXCOMM clock and configures the module for I2S receive using a configuration structure.
The configuration structure can be custom filled or set with default values by I2S_RxGetDefaultConfig().
Note
This API should be called at the beginning of the application to use the I2S driver.
Parameters
This API initializes the configuration structure for use in I2S_TxInit(). The initialized structure can remain
unchanged in I2S_TxInit(), or it can be modified before calling I2S_TxInit(). Example:
i2s_config_t config;
I2S_TxGetDefaultConfig(&config);
Default values:
* config->masterSlave = kI2S_MasterSlaveNormalMaster;
* config->mode = kI2S_ModeI2sClassic;
* config->rightLow = false;
* config->leftJust = false;
* config->pdmData = false;
* config->sckPol = false;
* config->wsPol = false;
* config->divider = 1;
* config->oneChannel = false;
* config->dataLength = 16;
* config->frameLength = 32;
* config->position = 0;
* config->watermark = 4;
* config->txEmptyZero = true;
* config->pack48 = false;
*
Parameters
This API initializes the configuration structure for use in I2S_RxInit(). The initialized structure can remain
unchanged in I2S_RxInit(), or it can be modified before calling I2S_RxInit(). Example:
i2s_config_t config;
I2S_RxGetDefaultConfig(&config);
Default values:
* config->masterSlave = kI2S_MasterSlaveNormalSlave;
* config->mode = kI2S_ModeI2sClassic;
* config->rightLow = false;
* config->leftJust = false;
* config->pdmData = false;
* config->sckPol = false;
* config->wsPol = false;
* config->divider = 1;
* config->oneChannel = false;
* config->dataLength = 16;
* config->frameLength = 32;
* config->position = 0;
* config->watermark = 4;
* config->txEmptyZero = false;
* config->pack48 = false;
*
Parameters
This API gates the FLEXCOMM clock. The I2S module can’t operate unless I2S_TxInit or I2S_RxInit is
called to enable the clock.
Parameters
Parameters
Parameters
Return values
kStatus_Success
kStatus_I2S_Busy if all queue slots are occupied with unsent buffers.
Parameters
Parameters
Parameters
Return values
kStatus_Success
kStatus_I2S_Busy if all queue slots are occupied with buffers which are not full.
Parameters
Parameters
Return values
kStatus_Success
kStatus_NoTransferIn- there is no non-blocking transaction currently in progress.
Progress
Parameters
Return values
kStatus_Success
kStatus_NoTransferIn- there is no non-blocking transaction currently in progress.
Progress
Parameters
Parameters
Parameters
Parameters
interruptMask bit mask of interrupts to enable. See i2s_flags_t for the set of constants that should be
OR’d together to form the bit mask.
Parameters
Returns
A bitmask composed of i2s_flags_t enumerators OR’d together to indicate the set of enabled inter-
rupts.
Parameters
Parameters
Files
• file fsl_i2s_dma.h
Data Structures
• struct i2s_dma_handle_t
Members not to be accessed / modified outside of the driver. More...
Typedefs
Driver version
DMA API
Data Fields
• uint32_t state
Internal state of I2S DMA transfer.
• i2s_dma_transfer_callback_t completionCallback
Callback function pointer.
• void ∗ userData
Application data passed to callback.
• dma_handle_t ∗ dmaHandle
DMA handle.
• volatile i2s_transfer_t i2sQueue [I2S_NUM_BUFFERS]
Transfer queue storing transfer buffers.
• volatile uint8_t queueUser
Queue index where user’s next transfer will be stored.
• volatile uint8_t queueDriver
Queue index of buffer actually used by the driver.
Parameters
Parameters
Parameters
Return values
kStatus_Success
kStatus_I2S_Busy if all queue slots are occupied with unsent buffers.
Parameters
Parameters
Parameters
Return values
kStatus_Success
kStatus_I2S_Busy if all queue slots are occupied with buffers which are not full.
Parameters
void main(void)
{
//...
SPI_MasterGetDefaultConfig(&masterConfig);
// Prepare to send.
xfer.txData = sendData;
xfer.rxData = receiveBuff;
xfer.dataSize = sizeof(sendData);
// Send out.
SPI_MasterTransferNonBlocking(SPI0, &spiHandle, &xfer);
// ...
}
void main(void)
{
//...
// Prepares to send.
xfer.txData = sendData;
xfer.rxData = receiveBuff;
xfer.dataSize = sizeof(sendData);
// Sends out.
SPI_MasterTransferDMA(SPI0, &spiHandle, &xfer);
// ...
}
Modules
• SPI DMA Driver
• SPI Driver
• SPI FreeRTOS driver
This section describes the programming interface of the SPI DMA driver.
Files
• file fsl_spi.h
Data Structures
• struct spi_master_config_t
SPI master user configure structure. More...
• struct spi_slave_config_t
SPI slave user configure structure. More...
• struct spi_transfer_t
SPI transfer structure. More...
• struct spi_config_t
Internal configuration structure used in ’spi’ and ’spi_dma’ driver. More...
• struct spi_master_handle_t
SPI transfer handle structure. More...
Typedefs
Enumerations
• enum spi_xfer_option_t {
kSPI_FrameDelay = (SPI_FIFOWR_EOF_MASK),
kSPI_FrameAssert = (SPI_FIFOWR_EOT_MASK) }
SPI transfer option.
• enum spi_shift_direction_t {
kSPI_MsbFirst = 0U,
kSPI_LsbFirst = 1U }
SPI data shifter direction options.
• enum spi_clock_polarity_t {
kSPI_ClockPolarityActiveHigh = 0x0U,
kSPI_ClockPolarityActiveLow }
SPI clock polarity configuration.
• enum spi_clock_phase_t {
kSPI_ClockPhaseFirstEdge = 0x0U,
kSPI_ClockPhaseSecondEdge }
SPI clock phase configuration.
• enum spi_txfifo_watermark_t {
kSPI_TxFifo0 = 0,
kSPI_TxFifo1 = 1,
kSPI_TxFifo2 = 2,
kSPI_TxFifo3 = 3,
kSPI_TxFifo4 = 4,
kSPI_TxFifo5 = 5,
kSPI_TxFifo6 = 6,
kSPI_TxFifo7 = 7 }
txFIFO watermark values
• enum spi_rxfifo_watermark_t {
kSPI_RxFifo1 = 0,
kSPI_RxFifo2 = 1,
kSPI_RxFifo3 = 2,
kSPI_RxFifo4 = 3,
kSPI_RxFifo5 = 4,
kSPI_RxFifo6 = 5,
kSPI_RxFifo7 = 6,
kSPI_RxFifo8 = 7 }
rxFIFO watermark values
• enum spi_data_width_t {
kSPI_Data4Bits = 3,
kSPI_Data5Bits = 4,
kSPI_Data6Bits = 5,
kSPI_Data7Bits = 6,
kSPI_Data8Bits = 7,
kSPI_Data9Bits = 8,
kSPI_Data10Bits = 9,
kSPI_Data11Bits = 10,
kSPI_Data12Bits = 11,
kSPI_Data13Bits = 12,
kSPI_Data14Bits = 13,
kSPI_Data15Bits = 14,
kSPI_Data16Bits = 15 }
Transfer data width.
• enum spi_ssel_t {
kSPI_Ssel0 = 0,
kSPI_Ssel1 = 1,
kSPI_Ssel2 = 2,
kSPI_Ssel3 = 3 }
Slave select.
• enum _spi_status {
kStatus_SPI_Busy = MAKE_STATUS(kStatusGroup_LPC_SPI, 0),
kStatus_SPI_Idle = MAKE_STATUS(kStatusGroup_LPC_SPI, 1),
kStatus_SPI_Error = MAKE_STATUS(kStatusGroup_LPC_SPI, 2),
kStatus_SPI_BaudrateNotSupport }
SPI transfer status.
• enum _spi_interrupt_enable {
kSPI_RxLvlIrq = SPI_FIFOINTENSET_RXLVL_MASK,
kSPI_TxLvlIrq = SPI_FIFOINTENSET_TXLVL_MASK }
SPI interrupt sources.
• enum _spi_statusflags {
kSPI_TxEmptyFlag = SPI_FIFOSTAT_TXEMPTY_MASK,
kSPI_TxNotFullFlag = SPI_FIFOSTAT_TXNOTFULL_MASK,
kSPI_RxNotEmptyFlag = SPI_FIFOSTAT_RXNOTEMPTY_MASK,
kSPI_RxFullFlag = SPI_FIFOSTAT_RXFULL_MASK }
SPI status flags.
Functions
Driver version
Status
Interrupts
DMA Control
Bus Operations
Transactional
Data Fields
• bool enableLoopback
Enable loopback for test purpose.
• bool enableMaster
Enable SPI at initialization time.
• spi_clock_polarity_t polarity
Clock polarity.
• spi_clock_phase_t phase
Clock phase.
• spi_shift_direction_t direction
MSB or LSB.
• uint32_t baudRate_Bps
Baud Rate for SPI in Hz.
• spi_data_width_t dataWidth
Width of the data.
• spi_ssel_t sselNum
Slave select number.
• spi_txfifo_watermark_t txWatermark
txFIFO watermark
• spi_rxfifo_watermark_t rxWatermark
rxFIFO watermark
Data Fields
• bool enableSlave
Enable SPI at initialization time.
• spi_clock_polarity_t polarity
Clock polarity.
• spi_clock_phase_t phase
Clock phase.
• spi_shift_direction_t direction
MSB or LSB.
• spi_data_width_t dataWidth
Width of the data.
• spi_txfifo_watermark_t txWatermark
txFIFO watermark
• spi_rxfifo_watermark_t rxWatermark
rxFIFO watermark
Data Fields
• uint8_t ∗ txData
Send buffer.
• uint8_t ∗ rxData
Receive buffer.
• uint32_t configFlags
Additional option to control transfer.
• size_t dataSize
Transfer bytes.
Data Fields
• uint8_t ∗volatile txData
Transfer buffer.
• uint8_t ∗volatile rxData
Receive buffer.
• volatile size_t txRemainingBytes
Number of data to be transmitted [in bytes].
• volatile size_t rxRemainingBytes
Number of data to be received [in bytes].
Enumerator
kSPI_FrameDelay Delay chip select.
kSPI_FrameAssert When transfer ends, assert chip select.
Enumerator
kSPI_MsbFirst Data transfers start with most significant bit.
kSPI_LsbFirst Data transfers start with least significant bit.
Enumerator
kSPI_ClockPolarityActiveHigh Active-high SPI clock (idles low).
Enumerator
kSPI_ClockPhaseFirstEdge First edge on SCK occurs at the middle of the first cycle of a data
transfer.
kSPI_ClockPhaseSecondEdge First edge on SCK occurs at the start of the first cycle of a data
transfer.
Enumerator
kSPI_TxFifo0 SPI tx watermark is empty.
kSPI_TxFifo1 SPI tx watermark at 1 item.
kSPI_TxFifo2 SPI tx watermark at 2 items.
kSPI_TxFifo3 SPI tx watermark at 3 items.
kSPI_TxFifo4 SPI tx watermark at 4 items.
kSPI_TxFifo5 SPI tx watermark at 5 items.
kSPI_TxFifo6 SPI tx watermark at 6 items.
kSPI_TxFifo7 SPI tx watermark at 7 items.
Enumerator
kSPI_RxFifo1 SPI rx watermark at 1 item.
kSPI_RxFifo2 SPI rx watermark at 2 items.
kSPI_RxFifo3 SPI rx watermark at 3 items.
kSPI_RxFifo4 SPI rx watermark at 4 items.
kSPI_RxFifo5 SPI rx watermark at 5 items.
kSPI_RxFifo6 SPI rx watermark at 6 items.
kSPI_RxFifo7 SPI rx watermark at 7 items.
kSPI_RxFifo8 SPI rx watermark at 8 items.
Enumerator
kSPI_Data4Bits 4 bits data width
Enumerator
kSPI_Ssel0 Slave select 0.
kSPI_Ssel1 Slave select 1.
kSPI_Ssel2 Slave select 2.
kSPI_Ssel3 Slave select 3.
Enumerator
kStatus_SPI_Busy SPI bus is busy.
kStatus_SPI_Idle SPI is idle.
kStatus_SPI_Error SPI error.
kStatus_SPI_BaudrateNotSupport Baudrate is not support in current clock source.
Enumerator
kSPI_RxLvlIrq Rx level interrupt.
kSPI_TxLvlIrq Tx level interrupt.
Enumerator
kSPI_TxEmptyFlag txFifo is empty
The purpose of this API is to get the configuration structure initialized for use in SPI_MasterInit(). User
may use the initialized structure unchanged in SPI_MasterInit(), or modify some fields of the structure
before calling SPI_MasterInit(). After calling this API, the master is ready to transfer. Example:
spi_master_config_t config;
SPI_MasterGetDefaultConfig(&config);
Parameters
The configuration structure can be filled by user from scratch, or be set with default values by SPI_Master-
GetDefaultConfig(). After calling this API, the slave is ready to transfer. Example
spi_master_config_t config = {
.baudRate_Bps = 400000,
...
};
SPI_MasterInit(SPI0, &config);
Parameters
The purpose of this API is to get the configuration structure initialized for use in SPI_SlaveInit(). Modify
some fields of the structure before calling SPI_SlaveInit(). Example:
spi_slave_config_t config;
SPI_SlaveGetDefaultConfig(&config);
Parameters
The configuration structure can be filled by user from scratch or be set with default values by SPI_Slave-
GetDefaultConfig(). After calling this API, the slave is ready to transfer. Example
spi_slave_config_t config = {
.polarity = flexSPIClockPolarity_ActiveHigh;
.phase = flexSPIClockPhase_FirstEdge;
.direction = flexSPIMsbFirst;
...
};
SPI_SlaveInit(SPI0, &config);
Parameters
Calling this API resets the SPI module, gates the SPI clock. The SPI module can’t work unless calling the
SPI_MasterInit/SPI_SlaveInit to initialize module.
Parameters
18.3.5.7 static void SPI_Enable ( SPI_Type ∗ base, bool enable ) [inline], [static]
Parameters
Parameters
Returns
SPI Status, use status flag to AND _spi_statusflags could get the related status.
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Returns
Data in the register.
This function initializes the SPI master handle which can be used for other SPI master transactional APIs.
Usually, for a specified SPI instance, call this API once to get the initialized handle.
Parameters
Parameters
Return values
Parameters
Return values
Returns
status of status_t.
Parameters
Parameters
This function initializes the SPI slave handle which can be used for other SPI slave transactional APIs.
Usually, for a specified SPI instance, call this API once to get the initialized handle.
Parameters
Parameters
Return values
Returns
status of status_t.
Parameters
This section describes the programming interface of the SPI DMA driver.
Files
• file fsl_spi_dma.h
Data Structures
• struct spi_dma_handle_t
SPI DMA transfer handle, users should not touch the content of the handle. More...
Typedefs
DMA Transactional
Data Fields
• volatile bool txInProgress
Send transfer finished.
• volatile bool rxInProgress
Receive transfer finished.
• dma_handle_t ∗ txHandle
DMA handler for SPI send.
• dma_handle_t ∗ rxHandle
DMA handler for SPI receive.
• uint8_t bytesPerFrame
Bytes in a frame for SPI tranfer.
• spi_dma_callback_t callback
Callback for SPI DMA transfer.
• void ∗ userData
User Data for SPI DMA callback.
• uint32_t state
Internal state of SPI DMA transfer.
• size_t transferSize
Bytes need to be transfer.
This function initializes the SPI master DMA handle which can be used for other SPI master transactional
APIs. Usually, for a specified SPI instance, user need only call this API once to get the initialized handle.
Parameters
Parameters
Return values
This function initializes the SPI slave DMA handle which can be used for other SPI master transactional
APIs. Usually, for a specified SPI instance, user need only call this API once to get the initialized handle.
Parameters
Note
This interface returned immediately after transfer initiates, users should call SPI_GetTransferStatus
to poll the transfer status to check whether SPI transfer finished.
Parameters
Return values
Parameters
Returns
status of status_t.
Parameters
Returns
status of status_t.
This section describes the programming interface of the SPI FreeRTOS driver.
Files
• file fsl_spi_freertos.h
Data Structures
• struct spi_rtos_handle_t
SPI FreeRTOS handle. More...
Data Fields
• SPI_Type ∗ base
SPI base address.
• spi_master_handle_t drv_handle
Handle of the underlying driver, treated as opaque by the RTOS layer.
• SemaphoreHandle_t mutex
Mutex to lock the handle during a trasfer.
• SemaphoreHandle_t event
Semaphore to notify and unblock task when transfer ends.
This function initializes the SPI module and related RTOS context.
Parameters
handle The RTOS SPI handle, the pointer to an allocated space for RTOS context.
base The pointer base address of the SPI instance to initialize.
masterConfig Configuration structure to set-up SPI in master mode.
srcClock_Hz Frequency of input clock of the SPI module.
Returns
status of the operation.
This function deinitializes the SPI module and related RTOS context.
Parameters
This function performs an SPI transfer according to data given in the transfer structure.
Parameters
Returns
status of the operation.
In this example, the buffer size is 32, but only 31 bytes are used for saving data.
uint8_t ch;
USART_GetDefaultConfig(&user_config);
user_config.baudRate_Bps = 115200U;
user_config.enableTx = true;
user_config.enableRx = true;
USART_Init(USART1,&user_config,120000000U);
while(1)
{
USART_ReadBlocking(USART1, &ch, 1);
USART_WriteBlocking(USART1, &ch, 1);
}
usart_handle_t g_usartHandle;
usart_config_t user_config;
usart_transfer_t sendXfer;
usart_transfer_t receiveXfer;
volatile bool txFinished;
volatile bool rxFinished;
uint8_t sendData[] = [’H’, ’e’, ’l’, ’l’, ’o’];
uint8_t receiveData[32];
if (kStatus_USART_TxIdle == status)
{
txFinished = true;
}
if (kStatus_USART_RxIdle == status)
{
rxFinished = true;
}
}
void main(void)
{
//...
USART_GetDefaultConfig(&user_config);
user_config.baudRate_Bps = 115200U;
user_config.enableTx = true;
user_config.enableRx = true;
// Prepare to send.
sendXfer.data = sendData
sendXfer.dataSize = sizeof(sendData);
txFinished = false;
// Send out.
USART_TransferSendNonBlocking(USART1, &g_usartHandle, &sendXfer);
// Prepare to receive.
receiveXfer.data = receiveData;
receiveXfer.dataSize = sizeof(receiveData);
rxFinished = false;
// Receive.
USART_TransferReceiveNonBlocking(USART1, &g_usartHandle, &receiveXfer,
NULL);
// ...
}
#define RING_BUFFER_SIZE 64
#define RX_DATA_SIZE 32
usart_handle_t g_usartHandle;
usart_config_t user_config;
usart_transfer_t sendXfer;
usart_transfer_t receiveXfer;
volatile bool txFinished;
volatile bool rxFinished;
uint8_t receiveData[RX_DATA_SIZE];
uint8_t ringBuffer[RING_BUFFER_SIZE];
if (kStatus_USART_RxIdle == status)
{
rxFinished = true;
}
}
void main(void)
{
size_t bytesRead;
//...
USART_GetDefaultConfig(&user_config);
user_config.baudRate_Bps = 115200U;
user_config.enableTx = true;
user_config.enableRx = true;
// Prepare to receive.
receiveXfer.data = receiveData;
receiveXfer.dataSize = sizeof(receiveData);
rxFinished = false;
// Receive.
USART_TransferReceiveNonBlocking(USART1, &g_usartHandle, &receiveXfer);
// ...
}
usart_handle_t g_usartHandle;
dma_handle_t g_usartTxDmaHandle;
dma_handle_t g_usartRxDmaHandle;
usart_config_t user_config;
usart_transfer_t sendXfer;
usart_transfer_t receiveXfer;
volatile bool txFinished;
volatile bool rxFinished;
uint8_t sendData[] = [’H’, ’e’, ’l’, ’l’, ’o’];
uint8_t receiveData[32];
if (kStatus_USART_TxIdle == status)
{
txFinished = true;
}
if (kStatus_USART_RxIdle == status)
{
rxFinished = true;
}
}
void main(void)
{
//...
USART_GetDefaultConfig(&user_config);
user_config.baudRate_Bps = 115200U;
user_config.enableTx = true;
user_config.enableRx = true;
DMA_Init(DMA0);
DMA_EnableChannel(DMA0, USART_TX_DMA_CHANNEL);
DMA_EnableChannel(DMA0, USART_RX_DMA_CHANNEL);
// Prepare to send.
sendXfer.data = sendData
sendXfer.dataSize = sizeof(sendData);
txFinished = false;
// Send out.
USART_TransferSendDMA(USART1, &g_usartHandle, &sendXfer);
// Prepare to receive.
receiveXfer.data = receiveData;
receiveXfer.dataSize = sizeof(receiveData);
rxFinished = false;
// Receive.
USART_TransferReceiveDMA(USART1, &g_usartHandle, &receiveXfer);
// ...
}
Modules
• USART DMA Driver
• USART Driver
• USART FreeRTOS Driver
Data Structures
• struct usart_config_t
USART configuration structure. More...
• struct usart_transfer_t
USART transfer structure. More...
• struct usart_handle_t
USART handle structure. More...
Typedefs
Enumerations
• enum _usart_status {
kStatus_USART_TxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 0),
kStatus_USART_RxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 1),
kStatus_USART_TxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 2),
kStatus_USART_RxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 3),
kStatus_USART_TxError = MAKE_STATUS(kStatusGroup_LPC_USART, 7),
kStatus_USART_RxError = MAKE_STATUS(kStatusGroup_LPC_USART, 9),
kStatus_USART_RxRingBufferOverrun = MAKE_STATUS(kStatusGroup_LPC_USART, 8),
kStatus_USART_NoiseError = MAKE_STATUS(kStatusGroup_LPC_USART, 10),
kStatus_USART_FramingError = MAKE_STATUS(kStatusGroup_LPC_USART, 11),
kStatus_USART_ParityError = MAKE_STATUS(kStatusGroup_LPC_USART, 12),
kStatus_USART_BaudrateNotSupport }
Error codes for the USART driver.
• enum usart_parity_mode_t {
kUSART_ParityDisabled = 0x0U,
kUSART_ParityEven = 0x2U,
kUSART_ParityOdd = 0x3U }
USART parity mode.
• enum usart_stop_bit_count_t {
kUSART_OneStopBit = 0U,
kUSART_TwoStopBit = 1U }
USART stop bit count.
• enum usart_data_len_t {
kUSART_7BitsPerChar = 0U,
kUSART_8BitsPerChar = 1U }
USART data size.
• enum usart_txfifo_watermark_t {
kUSART_TxFifo0 = 0,
kUSART_TxFifo1 = 1,
kUSART_TxFifo2 = 2,
kUSART_TxFifo3 = 3,
kUSART_TxFifo4 = 4,
kUSART_TxFifo5 = 5,
kUSART_TxFifo6 = 6,
kUSART_TxFifo7 = 7 }
txFIFO watermark values
• enum usart_rxfifo_watermark_t {
kUSART_RxFifo1 = 0,
kUSART_RxFifo2 = 1,
kUSART_RxFifo3 = 2,
kUSART_RxFifo4 = 3,
kUSART_RxFifo5 = 4,
kUSART_RxFifo6 = 5,
kUSART_RxFifo7 = 6,
kUSART_RxFifo8 = 7 }
rxFIFO watermark values
• enum _usart_interrupt_enable
USART interrupt configuration structure, default settings all disabled.
• enum _usart_flags {
kUSART_TxError = (USART_FIFOSTAT_TXERR_MASK),
kUSART_RxError = (USART_FIFOSTAT_RXERR_MASK),
kUSART_TxFifoEmptyFlag = (USART_FIFOSTAT_TXEMPTY_MASK),
kUSART_TxFifoNotFullFlag = (USART_FIFOSTAT_TXNOTFULL_MASK),
kUSART_RxFifoNotEmptyFlag = (USART_FIFOSTAT_RXNOTEMPTY_MASK),
kUSART_RxFifoFullFlag = (USART_FIFOSTAT_RXFULL_MASK) }
USART status flags.
Functions
Driver version
Status
Interrupts
Bus Operations
Transactional
Data Fields
• uint32_t baudRate_Bps
USART baud rate.
• usart_parity_mode_t parityMode
Parity mode, disabled (default), even, odd.
• usart_stop_bit_count_t stopBitCount
Number of stop bits, 1 stop bit (default) or 2 stop bits.
• usart_data_len_t bitCountPerChar
Data length - 7 bit, 8 bit.
• bool loopback
Enable peripheral loopback.
• bool enableRx
Enable RX.
• bool enableTx
Enable TX.
• usart_txfifo_watermark_t txWatermark
txFIFO watermark
• usart_rxfifo_watermark_t rxWatermark
rxFIFO watermark
Data Fields
• uint8_t ∗ data
The buffer of data to be transfer.
• size_t dataSize
The byte count to be transfer.
Data Fields
• uint8_t ∗volatile txData
Address of remaining data to send.
• volatile size_t txDataSize
Size of the remaining data to send.
• size_t txDataSizeAll
Size of the data to send out.
• uint8_t ∗volatile rxData
Address of remaining data to receive.
• volatile size_t rxDataSize
Size of the remaining data to receive.
• size_t rxDataSizeAll
Size of the data to receive.
• uint8_t ∗ rxRingBuffer
Start address of the receiver ring buffer.
• size_t rxRingBufferSize
Size of the ring buffer.
• volatile uint16_t rxRingBufferHead
Index for the driver to store received data into ring buffer.
• volatile uint16_t rxRingBufferTail
Index for the user to get data from the ring buffer.
• usart_transfer_callback_t callback
Callback function.
• void ∗ userData
USART callback function parameter.
• volatile uint8_t txState
TX transfer state.
• volatile uint8_t rxState
RX transfer state.
• usart_txfifo_watermark_t txWatermark
txFIFO watermark
• usart_rxfifo_watermark_t rxWatermark
rxFIFO watermark
Enumerator
kStatus_USART_TxBusy Transmitter is busy.
kStatus_USART_RxBusy Receiver is busy.
kStatus_USART_TxIdle USART transmitter is idle.
kStatus_USART_RxIdle USART receiver is idle.
kStatus_USART_TxError Error happens on txFIFO.
Enumerator
kUSART_ParityDisabled Parity disabled.
kUSART_ParityEven Parity enabled, type even, bit setting: PE|PT = 10.
kUSART_ParityOdd Parity enabled, type odd, bit setting: PE|PT = 11.
Enumerator
kUSART_OneStopBit One stop bit.
kUSART_TwoStopBit Two stop bits.
Enumerator
kUSART_7BitsPerChar Seven bit mode.
kUSART_8BitsPerChar Eight bit mode.
Enumerator
kUSART_TxFifo0 USART tx watermark is empty.
kUSART_TxFifo1 USART tx watermark at 1 item.
kUSART_TxFifo2 USART tx watermark at 2 items.
kUSART_TxFifo3 USART tx watermark at 3 items.
kUSART_TxFifo4 USART tx watermark at 4 items.
kUSART_TxFifo5 USART tx watermark at 5 items.
kUSART_TxFifo6 USART tx watermark at 6 items.
kUSART_TxFifo7 USART tx watermark at 7 items.
Enumerator
kUSART_RxFifo1 USART rx watermark at 1 item.
kUSART_RxFifo2 USART rx watermark at 2 items.
kUSART_RxFifo3 USART rx watermark at 3 items.
kUSART_RxFifo4 USART rx watermark at 4 items.
kUSART_RxFifo5 USART rx watermark at 5 items.
kUSART_RxFifo6 USART rx watermark at 6 items.
kUSART_RxFifo7 USART rx watermark at 7 items.
kUSART_RxFifo8 USART rx watermark at 8 items.
This provides constants for the USART status flags for use in the USART functions.
Enumerator
kUSART_TxError TEERR bit, sets if TX buffer is error.
kUSART_RxError RXERR bit, sets if RX buffer is error.
kUSART_TxFifoEmptyFlag TXEMPTY bit, sets if TX buffer is empty.
kUSART_TxFifoNotFullFlag TXNOTFULL bit, sets if TX buffer is not full.
kUSART_RxFifoNotEmptyFlag RXNOEMPTY bit, sets if RX buffer is not empty.
kUSART_RxFifoFullFlag RXFULL bit, sets if RX buffer is full.
This function configures the USART module with the user-defined settings. The user can configure the
configuration structure and also get the default configuration by using the USART_GetDefaultConfig()
function. Example below shows how to use this API to configure USART.
* usart_config_t usartConfig;
* usartConfig.baudRate_Bps = 115200U;
* usartConfig.parityMode = kUSART_ParityDisabled;
* usartConfig.stopBitCount = kUSART_OneStopBit;
* USART_Init(USART1, &usartConfig, 20000000U);
*
Parameters
Return values
This function waits for TX complete, disables TX and RX, and disables the USART clock.
Parameters
This function initializes the USART configuration structure to a default value. The default values are:
usartConfig->baudRate_Bps = 115200U; usartConfig->parityMode = kUSART_ParityDisabled; usart-
Config->stopBitCount = kUSART_OneStopBit; usartConfig->bitCountPerChar = kUSART_8BitsPer-
Char; usartConfig->loopback = false; usartConfig->enableTx = false; usartConfig->enableRx = false;
Parameters
This function configures the USART module baud rate. This function is used to update the USART
module baud rate after the USART module is initialized by the USART_Init.
Parameters
Return values
This function get all USART status flags, the flags are returned as the logical OR value of the enumerators
_usart_flags. To check a specific status, compare the return value with enumerators in _usart_flags. For
example, to check whether the TX is empty:
* if (kUSART_TxFifoNotFullFlag &
USART_GetStatusFlags(USART1))
* {
* ...
* }
*
Parameters
Returns
USART status flags which are ORed by the enumerators in the _usart_flags.
This function clear supported USART status flags Flags that can be cleared or set are: kUSART_TxError
kUSART_RxError For example:
* USART_ClearStatusFlags(USART1, kUSART_TxError |
kUSART_RxError)
*
Parameters
This function enables the USART interrupts according to the provided mask. The mask is a logical OR of
enumeration members. See _usart_interrupt_enable. For example, to enable TX empty interrupt and RX
full interrupt:
* USART_EnableInterrupts(USART1, kUSART_TxLevelInterruptEnable |
kUSART_RxLevelInterruptEnable);
*
Parameters
This function disables the USART interrupts according to a provided mask. The mask is a logical OR of
enumeration members. See _usart_interrupt_enable. This example shows how to disable the TX empty
interrupt and RX full interrupt:
* USART_DisableInterrupts(USART1, kUSART_TxLevelInterruptEnable |
kUSART_RxLevelInterruptEnable);
*
Parameters
This function writes data to the txFIFO directly. The upper layer must ensure that txFIFO has space for
data to write before calling this function.
Parameters
This function reads data from the rxFIFO directly. The upper layer must ensure that the rxFIFO is not
empty before calling this function.
Parameters
Returns
The byte read from USART data register.
This function polls the TX register, waits for the TX register to be empty or for the TX FIFO to have room
and writes data to the TX buffer.
Parameters
This function polls the RX register, waits for the RX register to be full or for RX FIFO to have data and
read data from the TX register.
Parameters
Return values
This function initializes the USART handle which can be used for other USART transactional APIs.
Usually, for a specified USART instance, call this API once to get the initialized handle.
Parameters
This function sends data using an interrupt method. This is a non-blocking function, which returns directly
without waiting for all data to be written to the TX register. When all data is written to the TX register in
the IRQ handler, the USART driver calls the callback function and passes the kStatus_USART_TxIdle as
status parameter.
Note
The kStatus_USART_TxIdle is passed to the upper layer when all data is written to the TX register.
However it does not ensure that all data are sent out. Before disabling the TX, check the kUSART-
_TransmissionCompleteFlag to ensure that the TX is finished.
Parameters
Return values
Note
When using the RX ring buffer, one byte is reserved for internal use. In other words, if ring-
BufferSize is 32, then only 31 bytes are used for saving data.
Parameters
ringBuffer Start address of the ring buffer for background receiving. Pass NULL to disable the
ring buffer.
ringBufferSize size of the ring buffer.
This function aborts the background transfer and uninstalls the ring buffer.
Parameters
This function aborts the interrupt driven data sending. The user can get the remainBtyes to find out how
many bytes are still not sent out.
Parameters
This function gets the number of bytes that have been written to USART TX register by interrupt method.
Parameters
Return values
This function receives data using an interrupt method. This is a non-blocking function, which returns
without waiting for all data to be received. If the RX ring buffer is used and not empty, the data in the
ring buffer is copied and the parameter receivedBytes shows how many bytes are copied from the
ring buffer. After copying, if the data in the ring buffer is not enough to read, the receive request is saved
by the USART driver. When the new data arrives, the receive request is serviced first. When all data
is received, the USART driver notifies the upper layer through a callback function and passes the status
parameter kStatus_USART_RxIdle. For example, the upper layer needs 10 bytes but there are only 5 bytes
in the ring buffer. The 5 bytes are copied to the xfer->data and this function returns with the parameter
receivedBytes set to 5. For the left 5 bytes, newly arrived data is saved from the xfer->data[5]. When
5 bytes are received, the USART driver notifies the upper layer. If the RX ring buffer is not enabled, this
function enables the RX and RX interrupt to receive data to the xfer->data. When all data is received, the
upper layer is notified.
Parameters
Return values
This function aborts the interrupt-driven data receiving. The user can get the remainBytes to find out how
many bytes not received yet.
Parameters
This function gets the number of bytes that have been received.
Parameters
Return values
This function handles the USART transmit and receive IRQ request.
Parameters
Files
• file fsl_usart_dma.h
Data Structures
• struct usart_dma_handle_t
UART DMA handle. More...
Typedefs
DMA transactional
Data Fields
• USART_Type ∗ base
UART peripheral base address.
• usart_dma_transfer_callback_t callback
Callback function.
• void ∗ userData
UART callback function parameter.
• size_t rxDataSizeAll
Size of the data to receive.
• size_t txDataSizeAll
Size of the data to send out.
• dma_handle_t ∗ txDmaHandle
The DMA TX channel used.
• dma_handle_t ∗ rxDmaHandle
The DMA RX channel used.
• volatile uint8_t txState
TX transfer state.
• volatile uint8_t rxState
RX transfer state.
Parameters
This function sends data using DMA. This is a non-blocking function, which returns right away. When all
data is sent, the send callback function is called.
Parameters
Return values
This function receives data using DMA. This is a non-blocking function, which returns right away. When
all data is received, the receive callback function is called.
Parameters
Return values
This function gets the number of bytes that have been received.
Parameters
Return values
Files
• file fsl_usart_freertos.h
Data Structures
• struct rtos_usart_config
FLEX USART configuration structure. More...
• struct usart_rtos_handle_t
FLEX USART FreeRTOS handle. More...
Data Fields
• USART_Type ∗ base
USART base address.
• uint32_t srcclk
USART source clock in Hz.
• uint32_t baudrate
Desired communication speed.
• usart_parity_mode_t parity
Parity setting.
• usart_stop_bit_count_t stopbits
Number of stop bits to use.
• uint8_t ∗ buffer
Buffer for background reception.
• uint32_t buffer_size
Size of buffer for background reception.
Data Fields
• USART_Type ∗ base
USART base address.
• usart_transfer_t txTransfer
TX transfer structure.
• usart_transfer_t rxTransfer
RX transfer structure.
• SemaphoreHandle_t rxSemaphore
RX semaphore for resource sharing.
• SemaphoreHandle_t txSemaphore
TX semaphore for resource sharing.
• EventGroupHandle_t rxEvent
RX completion event.
• EventGroupHandle_t txEvent
TX completion event.
• void ∗ t_state
Transactional state of the underlying driver.
Parameters
handle The RTOS USART handle, the pointer to allocated space for RTOS context.
t_handle The pointer to allocated space where to store transactional layer internal state.
cfg The pointer to the parameters required to configure the USART after initialization.
Returns
0 succeed, others fail.
This function deinitializes the USART module, sets all register values to reset value, and releases the
resources.
Parameters
This function sends data. It is a synchronous API. If the hardware buffer is full, the task is in the blocked
state.
Parameters
This function receives data from USART. It is a synchronous API. If data is immediately available, it is
returned immediately and the number of bytes received.
Parameters
{
fmc_config_t config;
fmc_flash_signature_t hardSignature;
FMC_GetDefaultConfig(&config);
FMC_Init(FMC, &config);
/* print data. */
Modules
• Fmc_driver
Functions
• void FMC_Init (FMC_Type ∗base, fmc_config_t ∗config)
Initialize FMC module.
• void FMC_Deinit (FMC_Type ∗base)
Deinit FMC module.
• void FMC_GetDefaultConfig (fmc_config_t ∗config)
Provides default configuration for fmc module.
• void FMC_GenerateFlashSignature (FMC_Type ∗base, uint32_t startAddress, uint32_t length, fmc-
_flash_signature_t ∗flashSignature)
Generate hardware flash signature.
Driver version
• #define FSL_FMC_DRIVER_VERSION (MAKE_VERSION(2U, 0U, 0U))
Driver version 2.0.0.
This function provides default configuration for fmc module, the default wait states value is 5.
Parameters
This function generates hardware flash signature for specified address range.
Note
This function needs to be excuted out of flash memory.
Parameters
Files
• file fsl_fmeas.h
Driver version
• #define FSL_FMEAS_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Defines LPC Frequency Measure driver version 2.0.0.
Change log:
• Version 2.0.0
– initial version
Parameters
Parameters
Returns
true if a measurement cycle is active, otherwise false.
Parameters
Returns
Frequency in Hz.
/* Initialize GINT */
GINT_Init(GINT0);
Files
• file fsl_gint.h
Typedefs
• typedef void(∗ gint_cb_t )(void)
GINT Callback function.
Enumerations
• enum gint_comb_t {
kGINT_CombineOr = 0U,
kGINT_CombineAnd = 1U }
GINT combine inputs type.
• enum gint_trig_t {
kGINT_TrigEdge = 0U,
kGINT_TrigLevel = 1U }
GINT trigger type.
Functions
• void GINT_Init (GINT_Type ∗base)
Initialize GINT peripheral.
• void GINT_SetCtrl (GINT_Type ∗base, gint_comb_t comb, gint_trig_t trig, gint_cb_t callback)
Setup GINT peripheral control parameters.
• void GINT_GetCtrl (GINT_Type ∗base, gint_comb_t ∗comb, gint_trig_t ∗trig, gint_cb_t ∗callback)
Get GINT peripheral control parameters.
• void GINT_ConfigPins (GINT_Type ∗base, gint_port_t port, uint32_t polarityMask, uint32_-
t enableMask)
Configure GINT peripheral pins.
• void GINT_GetConfigPins (GINT_Type ∗base, gint_port_t port, uint32_t ∗polarityMask, uint32_t
∗enableMask)
Get GINT peripheral pin configuration.
• void GINT_EnableCallback (GINT_Type ∗base)
Enable callback.
• void GINT_DisableCallback (GINT_Type ∗base)
Disable callback.
• static void GINT_ClrStatus (GINT_Type ∗base)
Clear GINT status.
• static uint32_t GINT_GetStatus (GINT_Type ∗base)
Get GINT status.
• void GINT_Deinit (GINT_Type ∗base)
Deinitialize GINT peripheral.
Driver version
• #define FSL_GINT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Version 2.0.0.
Enumerator
kGINT_CombineOr A grouped interrupt is generated when any one of the enabled inputs is active.
kGINT_CombineAnd A grouped interrupt is generated when all enabled inputs are active.
Enumerator
kGINT_TrigEdge Edge triggered based on polarity.
kGINT_TrigLevel Level triggered based on polarity.
This function initializes the GINT peripheral and enables the clock.
Parameters
Return values
None.
Return values
None.
Return values
None.
This function enables and controls the polarity of enabled pin(s) of a given port.
Parameters
Return values
None.
Return values
None.
This function enables the interrupt for the selected GINT peripheral. Although the pin(s) are monitored as
soon as they are enabled, the callback function is not enabled until this function is called.
Parameters
Return values
None.
This function disables the interrupt for the selected GINT peripheral. Although the pins are still being
monitored but the callback function is not called.
Parameters
Return values
None.
Return values
None.
Return values
Parameters
Return values
None.
The function GPIO_WritePinOutput() set output state of selected GPIO pin. The function GPIO_Read-
PinInput() read input value of selected GPIO pin.
The function GPIO_SetPinsOutput() sets the output level of selected GPIO pins to the logic 1. The func-
tion GPIO_ClearPinsOutput() sets the output level of selected GPIO pins to the logic 1. The function
GPIO_TogglePinsOutput() reverse the output level of selected GPIO pins. The function GPIO_ReadPins-
Input() read input value of selected port.
The function GPIO_SetPortMask() set port mask, only pins masked by 0 will be enabled in following
functions. The function GPIO_WriteMPort() sets the state of selected GPIO port, only pins masked by 0
will be affected. The function GPIO_ReadMPort() reads the state of selected GPIO port, only pins masked
by 0 are enabled for read, pins masked by 1 are read as 0.
int main(void)
{
uint32_t port_state = 0;
gpio_pin_config_t led_config = {
kGPIO_DigitalOutput, 0,
};
/* Port masking */
GPIO_SetPortMask(GPIO, BOARD_LED_GPIO_PORT, 0x0000ffff);
GPIO_WriteMPort(GPIO, BOARD_LED_GPIO_PORT, 0xffffffff);
port_state = GPIO_ReadPinsInput(GPIO, 0);
port_state = GPIO_ReadMPort(GPIO, 0);
while (1)
{
port_state = GPIO_ReadPinsInput(GPIO, 0);
if (!(port_state & (1 << BOARD_SW1_GPIO_PIN)))
{
GPIO_TogglePinsOutput(GPIO, BOARD_LED_GPIO_PORT, 1u << BOARD_LED_GPIO_PIN)
;
}
Files
• file fsl_gpio.h
Data Structures
• struct gpio_pin_config_t
The GPIO pin configuration structure. More...
Enumerations
• enum gpio_pin_direction_t {
kGPIO_DigitalInput = 0U,
kGPIO_DigitalOutput = 1U }
LPC GPIO direction definition.
Functions
• static void GPIO_SetPinsOutput (GPIO_Type ∗base, uint32_t port, uint32_t mask)
Sets the output level of the multiple GPIO pins to the logic 1.
• static void GPIO_ClearPinsOutput (GPIO_Type ∗base, uint32_t port, uint32_t mask)
Sets the output level of the multiple GPIO pins to the logic 0.
• static void GPIO_TogglePinsOutput (GPIO_Type ∗base, uint32_t port, uint32_t mask)
Reverses current output logic of the multiple GPIO pins.
Driver version
• #define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
LPC GPIO driver version 2.0.0.
GPIO Configuration
• void GPIO_PinInit (GPIO_Type ∗base, uint32_t port, uint32_t pin, const gpio_pin_config_t
∗config)
Initializes a GPIO pin used by the board.
Every pin can only be configured as either output pin or input pin at a time. If configured as a input pin,
then leave the outputConfig unused.
Data Fields
• gpio_pin_direction_t pinDirection
GPIO direction, input or output.
• uint8_t outputLogic
Set default output logic, no use in input.
Enumerator
kGPIO_DigitalInput Set current pin as digital input.
kGPIO_DigitalOutput Set current pin as digital output.
To initialize the GPIO, define a pin configuration, either input or output, in the user file. Then, call the
GPIO_PinInit() function.
This is an example to define an input pin or output pin configuration:
Parameters
Parameters
Parameters
Return values
Parameters
Parameters
Parameters
Files
• file fsl_inputmux.h
• file fsl_inputmux_connections.h
Functions
• void INPUTMUX_Init (INPUTMUX_Type ∗base)
Initialize INPUTMUX peripheral.
• void INPUTMUX_AttachSignal (INPUTMUX_Type ∗base, uint32_t index, inputmux_connection-
_t connection)
Attaches a signal.
• void INPUTMUX_Deinit (INPUTMUX_Type ∗base)
Deinitialize INPUTMUX peripheral.
Driver version
• #define FSL_INPUTMUX_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Group interrupt driver version for SDK.
Version 2.0.0.
Enumerator
kINPUTMUX_SctGpi0ToSct0 SCT INMUX.
kINPUTMUX_I2sS7clkToSct0 Frequency measure.
kINPUTMUX_FreqmeGpioClk_b Pin Interrupt.
kINPUTMUX_GpioPort1Pin31ToPintsel DMA ITRIG.
kINPUTMUX_Otrig3ToDma DMA OTRIG.
Return values
None.
Parameters
Return values
None.
Return values
None.
The function IOCONPinMuxSet() set pinmux for single pin according to selected configuration.
The function IOCON_SetPinMuxing() set pinmux for group of pins according to selected configuration.
Files
• file fsl_iocon.h
Data Structures
• struct iocon_group_t
Array of IOCON pin definitions passed to IOCON_SetPinMuxing() must be in this format. More...
Macros
• #define IOCON_FUNC0 0x0
IOCON function and mode selection definitions.
• #define IOCON_FUNC1 0x1
Selects pin function 1.
• #define IOCON_FUNC2 0x2
Selects pin function 2.
• #define IOCON_FUNC3 0x3
Selects pin function 3.
• #define IOCON_FUNC4 0x4
Selects pin function 4.
• #define IOCON_FUNC5 0x5
Selects pin function 5.
• #define IOCON_FUNC6 0x6
Selects pin function 6.
• #define IOCON_FUNC7 0x7
Selects pin function 7.
• #define IOCON_MODE_INACT (0x0 << 3)
No addition pin function.
• #define IOCON_MODE_PULLDOWN (0x1 << 3)
Selects pull-down function.
• #define IOCON_MODE_PULLUP (0x2 << 3)
Selects pull-up function.
• #define IOCON_MODE_REPEATER (0x3 << 3)
Selects pin repeater function.
• #define IOCON_HYS_EN (0x1 << 5)
Enables hysteresis.
• #define IOCON_GPIO_MODE (0x1 << 5)
GPIO Mode.
• #define IOCON_I2C_SLEW (0x1 << 5)
I2C Slew Rate Control.
• #define IOCON_INV_EN (0x1 << 6)
Enables invert function on input.
• #define IOCON_ANALOG_EN (0x0 << 7)
Enables analog function by setting 0 to bit 7.
• #define IOCON_DIGITAL_EN (0x1 << 7)
Enables digital function by setting 1 to bit 7(default)
• #define IOCON_STDI2C_EN (0x1 << 8)
I2C standard mode/fast-mode.
• #define IOCON_FASTI2C_EN (0x3 << 8)
I2C Fast-mode Plus and high-speed slave.
• #define IOCON_INPFILT_OFF (0x1 << 8)
Input filter Off for GPIO pins.
• #define IOCON_INPFILT_ON (0x0 << 8)
Input filter On for GPIO pins.
• #define IOCON_OPENDRAIN_EN (0x1 << 10)
Enables open-drain function.
• #define IOCON_S_MODE_0CLK (0x0 << 11)
Bypass input filter.
• #define IOCON_S_MODE_1CLK (0x1 << 11)
Input pulses shorter than 1 filter clock are rejected.
Functions
• __STATIC_INLINE void IOCON_PinMuxSet (IOCON_Type ∗base, uint8_t port, uint8_t pin,
uint32_t modefunc)
Sets I/O Control pin mux.
• __STATIC_INLINE void IOCON_SetPinMuxing (IOCON_Type ∗base, const iocon_group_t ∗pin-
Array, uint32_t arrayLength)
Set all I/O Control pin muxing.
Driver version
• #define LPC_IOCON_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
IOCON driver version 2.0.0.
Note
See the User Manual for specific modes and functions supported by the various pins.Selects pin
function 0
Parameters
Returns
Nothing
Parameters
Returns
Nothing
The function LCDC_SetPanelAddr is used to set the new framebuffer address. After this function, the
new framebuffer address is not loaded to current register until the vertical synchroization. When the
address is loaded, the interrupt kLCDC_BaseAddrUpdateInterrupt occurs then upper layer could set the
new framebuffer. In this example, there are two buffers. When the active buffer is displayed, upper layer
could modify the inactive buffer.
void LCD_IRQHandler(void)
{
uint32_t intStatus = LCDC_GetEnabledInterruptsPendingStatus(LCD);
LCDC_ClearInterruptsStatus(LCD, intStatus);
int main(void)
{
lcdc_config_t lcdConfig;
s_frameAddrUpdated = false;
LCDC_GetDefaultConfig(&lcdConfig);
lcdConfig.panelClock_Hz = LCD_PANEL_CLK;
lcdConfig.ppl = LCD_PPL;
lcdConfig.hsw = LCD_HSW;
lcdConfig.hfp = LCD_HFP;
lcdConfig.hbp = LCD_HBP;
lcdConfig.lpp = LCD_LPP;
lcdConfig.vsw = LCD_VSW;
lcdConfig.vfp = LCD_VFP;
lcdConfig.vbp = LCD_VBP;
lcdConfig.polarityFlags = LCD_POL_FLAGS;
lcdConfig.upperPanelAddr = (uint32_t)s_frameBufs[0];
lcdConfig.bpp = kLCDC_16BPP565;
lcdConfig.display = kLCDC_DisplayTFT;
lcdConfig.swapRedBlue = false;
LCDC_EnableInterrupts(LCD,
kLCDC_BaseAddrUpdateInterrupt);
NVIC_EnableIRQ(LCD_IRQn);
LCDC_Start(LCD);
LCDC_PowerUp(LCD);
while (1)
{
/*
* Fill the inactive buffer.
*/
APP_FillBuffer((void *)s_frameBufs[s_inactiveBufsIdx]);
while (!s_frameAddrUpdated)
{
}
/*
* The buffer address has been loaded to the LCD controller, now
* set the inactive buffer to active buffer.
*/
LCDC_SetPanelAddr(LCD, kLCDC_UpperPanel, (uint32_t)(s_frameBufs[
s_inactiveBufsIdx]));
s_frameAddrUpdated = false;
s_inactiveBufsIdx ^= 1U;
}
}
This example shows how to show a 32x32 pixel cursor and change its position.
lcdc_cursor_config_t cursorConfig;
int32_t cursorPosX = 0;
int32_t cursorPosY = 0;
cursorConfig.size = kLCDC_CursorSize32;
cursorConfig.syncMode = kLCDC_CursorSync;
cursorConfig.image[0] = (uint32_t *)cursor32Img0;
LCDC_SetCursorConfig(LCD, &cursorConfig);
LCDC_ChooseCursor(LCD, 0);
LCDC_SetCursorPosition(LCD, 0, 0);
LCDC_EnableCursor(LCD, true);
while (1)
{
// Do something else here
Data Structures
• struct lcdc_config_t
LCD configuration structure. More...
• struct lcdc_cursor_palette_t
LCD hardware cursor palette. More...
• struct lcdc_cursor_config_t
LCD hardware cursor configuration structure. More...
Macros
• #define LCDC_CURSOR_COUNT 4
How many hardware cursors supports.
• #define LCDC_CURSOR_IMG_BPP 2
LCD cursor image bits per pixel.
• #define LCDC_CURSOR_IMG_32X32_WORDS (32 ∗ 32 ∗ LCDC_CURSOR_IMG_BPP / (8 ∗
sizeof(uint32_t)))
LCD 32x32 cursor image size in word(32-bit).
• #define LCDC_CURSOR_IMG_64X64_WORDS (64 ∗ 64 ∗ LCDC_CURSOR_IMG_BPP / (8 ∗
sizeof(uint32_t)))
LCD 64x64 cursor image size in word(32-bit).
• #define LCDC_PALETTE_SIZE_WORDS (ARRAY_SIZE(((LCD_Type ∗)0)->PAL))
LCD palette size in words(32-bit).
Enumerations
• enum _lcdc_polarity_flags {
kLCDC_InvertVsyncPolarity = LCD_POL_IVS_MASK,
kLCDC_InvertHsyncPolarity = LCD_POL_IHS_MASK,
kLCDC_InvertClkPolarity = LCD_POL_IPC_MASK,
kLCDC_InvertDePolarity = LCD_POL_IOE_MASK }
LCD sigal polarity flags.
• enum lcdc_bpp_t {
kLCDC_1BPP = 0U,
kLCDC_2BPP = 1U,
kLCDC_4BPP = 2U,
kLCDC_8BPP = 3U,
kLCDC_16BPP = 4U,
kLCDC_24BPP = 5U,
kLCDC_16BPP565 = 6U,
kLCDC_12BPP = 7U }
LCD bits per pixel.
• enum lcdc_display_t {
kLCDC_DisplayTFT = LCD_CTRL_LCDTFT_MASK,
kLCDC_DisplaySingleMonoSTN4Bit = LCD_CTRL_LCDBW_MASK,
kLCDC_DisplaySingleMonoSTN8Bit,
kLCDC_DisplayDualMonoSTN4Bit,
kLCDC_DisplayDualMonoSTN8Bit,
kLCDC_DisplaySingleColorSTN8Bit = 0U,
kLCDC_DisplayDualColorSTN8Bit = LCD_CTRL_LCDDUAL_MASK }
The types of display panel.
• enum lcdc_data_format_t {
kLCDC_LittleEndian = 0U,
kLCDC_BigEndian = LCD_CTRL_BEPO_MASK | LCD_CTRL_BEBO_MASK,
kLCDC_WinCeMode = LCD_CTRL_BEPO_MASK }
LCD panel buffer data format.
• enum lcdc_vertical_compare_interrupt_mode_t {
kLCDC_StartOfVsync,
kLCDC_StartOfBackPorch,
kLCDC_StartOfActiveVideo,
kLCDC_StartOfFrontPorch }
LCD vertical compare interrupt mode.
• enum _lcdc_interrupts {
kLCDC_CursorInterrupt = LCD_CRSR_INTMSK_CRSRIM_MASK,
kLCDC_FifoUnderflowInterrupt = LCD_INTMSK_FUFIM_MASK,
kLCDC_BaseAddrUpdateInterrupt = LCD_INTMSK_LNBUIM_MASK,
kLCDC_VerticalCompareInterrupt = LCD_INTMSK_VCOMPIM_MASK,
kLCDC_AhbErrorInterrupt = LCD_INTMSK_BERIM_MASK }
LCD interrupts.
• enum lcdc_panel_t {
kLCDC_UpperPanel,
kLCDC_LowerPanel }
LCD panel frame.
• enum lcdc_cursor_size_t {
kLCDC_CursorSize32,
kLCDC_CursorSize64 }
LCD hardware cursor size.
• enum lcdc_cursor_sync_mode_t {
kLCDC_CursorAsync,
kLCDC_CursorSync }
LCD hardware cursor frame synchronization mode.
Variables
• uint32_t lcdc_config_t::panelClock_Hz
Panel clock in Hz.
• uint16_t lcdc_config_t::ppl
Pixels per line, it must could be divided by 16.
• uint8_t lcdc_config_t::hsw
HSYNC pulse width.
• uint8_t lcdc_config_t::hfp
Horizontal front porch.
• uint8_t lcdc_config_t::hbp
Horizontal back porch.
• uint16_t lcdc_config_t::lpp
Lines per panal.
• uint8_t lcdc_config_t::vsw
VSYNC pulse width.
• uint8_t lcdc_config_t::vfp
Vrtical front porch.
• uint8_t lcdc_config_t::vbp
Vertical back porch.
• uint8_t lcdc_config_t::acBiasFreq
The number of line clocks between AC bias pin toggling.
• uint16_t lcdc_config_t::polarityFlags
OR’ed value of _lcdc_polarity_flags, used to contol the signal polarity.
• bool lcdc_config_t::enableLineEnd
Enable line end or not, the line end is a positive pulse with 4 panel clock.
• uint8_t lcdc_config_t::lineEndDelay
The panel clocks between the last pixel of line and the start of line end.
• uint32_t lcdc_config_t::upperPanelAddr
LCD upper panel base address, must be double-word(64-bit) align.
• uint32_t lcdc_config_t::lowerPanelAddr
LCD lower panel base address, must be double-word(64-bit) align.
• lcdc_bpp_t lcdc_config_t::bpp
LCD bits per pixel.
• lcdc_data_format_t lcdc_config_t::dataFormat
Data format.
• bool lcdc_config_t::swapRedBlue
Set true to use BGR format, set false to choose RGB format.
• lcdc_display_t lcdc_config_t::display
The display type.
• uint8_t lcdc_cursor_palette_t::red
Red color component.
• uint8_t lcdc_cursor_palette_t::green
Red color component.
• uint8_t lcdc_cursor_palette_t::blue
Red color component.
• lcdc_cursor_size_t lcdc_cursor_config_t::size
Cursor size.
• lcdc_cursor_sync_mode_t lcdc_cursor_config_t::syncMode
Cursor synchronization mode.
• lcdc_cursor_palette_t lcdc_cursor_config_t::palette0
Cursor palette 0.
• lcdc_cursor_palette_t lcdc_cursor_config_t::palette1
Cursor palette 1.
• uint32_t ∗ lcdc_cursor_config_t::image [LCDC_CURSOR_COUNT]
Pointer to cursor image data.
Driver version
• #define LPC_LCDC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
LCDC driver version 2.0.0.
LCD control
• void LCDC_SetPanelAddr (LCD_Type ∗base, lcdc_panel_t panel, uint32_t addr)
Sets panel frame base address.
• void LCDC_SetPalette (LCD_Type ∗base, const uint32_t ∗palette, uint8_t count_words)
Sets palette.
Interrupts
• static void LCDC_SetVerticalInterruptMode (LCD_Type ∗base, lcdc_vertical_compare_interrupt_-
mode_t mode)
Sets the vertical compare interrupt mode.
• void LCDC_EnableInterrupts (LCD_Type ∗base, uint32_t mask)
Enable LCD interrupts.
• void LCDC_DisableInterrupts (LCD_Type ∗base, uint32_t mask)
Disable LCD interrupts.
• uint32_t LCDC_GetInterruptsPendingStatus (LCD_Type ∗base)
Get LCD interrupt pending status.
• uint32_t LCDC_GetEnabledInterruptsPendingStatus (LCD_Type ∗base)
Get LCD enabled interrupt pending status.
• void LCDC_ClearInterruptsStatus (LCD_Type ∗base, uint32_t mask)
Clear LCD interrupts pending status.
Hardware cursor
• void LCDC_SetCursorConfig (LCD_Type ∗base, const lcdc_cursor_config_t ∗config)
Set the hardware cursor configuration.
• void LCDC_CursorGetDefaultConfig (lcdc_cursor_config_t ∗config)
Get the hardware cursor default configuration.
• static void LCDC_EnableCursor (LCD_Type ∗base, bool enable)
Enable or disable the cursor.
• static void LCDC_ChooseCursor (LCD_Type ∗base, uint8_t index)
Choose which cursor to display.
• void LCDC_SetCursorPosition (LCD_Type ∗base, int32_t positionX, int32_t positionY)
Set the position of cursor.
• void LCDC_SetCursorImage (LCD_Type ∗base, lcdc_cursor_size_t size, uint8_t index, const
uint32_t ∗image)
Set the cursor image.
Data Fields
• uint32_t panelClock_Hz
Panel clock in Hz.
• uint16_t ppl
Pixels per line, it must could be divided by 16.
• uint8_t hsw
HSYNC pulse width.
• uint8_t hfp
Horizontal front porch.
• uint8_t hbp
Horizontal back porch.
• uint16_t lpp
Lines per panal.
• uint8_t vsw
VSYNC pulse width.
• uint8_t vfp
Vrtical front porch.
• uint8_t vbp
Vertical back porch.
• uint8_t acBiasFreq
The number of line clocks between AC bias pin toggling.
• uint16_t polarityFlags
OR’ed value of _lcdc_polarity_flags, used to contol the signal polarity.
• bool enableLineEnd
Enable line end or not, the line end is a positive pulse with 4 panel clock.
• uint8_t lineEndDelay
The panel clocks between the last pixel of line and the start of line end.
• uint32_t upperPanelAddr
LCD upper panel base address, must be double-word(64-bit) align.
• uint32_t lowerPanelAddr
LCD lower panel base address, must be double-word(64-bit) align.
• lcdc_bpp_t bpp
LCD bits per pixel.
• lcdc_data_format_t dataFormat
Data format.
• bool swapRedBlue
Set true to use BGR format, set false to choose RGB format.
• lcdc_display_t display
The display type.
Data Fields
• uint8_t red
Red color component.
• uint8_t green
Red color component.
• uint8_t blue
Red color component.
Data Fields
• lcdc_cursor_size_t size
Cursor size.
• lcdc_cursor_sync_mode_t syncMode
Cursor synchronization mode.
• lcdc_cursor_palette_t palette0
Cursor palette 0.
• lcdc_cursor_palette_t palette1
Cursor palette 1.
• uint32_t ∗ image [LCDC_CURSOR_COUNT]
Pointer to cursor image data.
Enumerator
kLCDC_InvertVsyncPolarity Invert the VSYNC polarity, set to active low.
kLCDC_InvertHsyncPolarity Invert the HSYNC polarity, set to active low.
kLCDC_InvertClkPolarity Invert the panel clock polarity, set to drive data on falling edge.
kLCDC_InvertDePolarity Invert the data enable (DE) polarity, set to active low.
Enumerator
kLCDC_1BPP 1 bpp.
kLCDC_2BPP 2 bpp.
kLCDC_4BPP 4 bpp.
kLCDC_8BPP 8 bpp.
kLCDC_16BPP 16 bpp.
Enumerator
kLCDC_DisplayTFT Active matrix TFT panels with up to 24-bit bus interface.
kLCDC_DisplaySingleMonoSTN4Bit Single-panel monochrome STN (4-bit bus interface).
kLCDC_DisplaySingleMonoSTN8Bit Single-panel monochrome STN (8-bit bus interface).
kLCDC_DisplayDualMonoSTN4Bit Dual-panel monochrome STN (4-bit bus interface).
kLCDC_DisplayDualMonoSTN8Bit Dual-panel monochrome STN (8-bit bus interface).
kLCDC_DisplaySingleColorSTN8Bit Single-panel color STN (8-bit bus interface).
kLCDC_DisplayDualColorSTN8Bit Dual-panel coor STN (8-bit bus interface).
Enumerator
kLCDC_LittleEndian Little endian byte, little endian pixel.
kLCDC_BigEndian Big endian byte, big endian pixel.
kLCDC_WinCeMode little-endian byte, big-endian pixel for Windows CE mode.
Enumerator
kLCDC_StartOfVsync Generate vertical compare interrupt at start of VSYNC.
kLCDC_StartOfBackPorch Generate vertical compare interrupt at start of back porch.
kLCDC_StartOfActiveVideo Generate vertical compare interrupt at start of active video.
kLCDC_StartOfFrontPorch Generate vertical compare interrupt at start of front porch.
Enumerator
kLCDC_CursorInterrupt Cursor image read finished interrupt.
kLCDC_FifoUnderflowInterrupt FIFO underflow interrupt.
kLCDC_BaseAddrUpdateInterrupt Panel frame base address update interrupt.
kLCDC_VerticalCompareInterrupt Vertical compare interrupt.
kLCDC_AhbErrorInterrupt AHB master error interrupt.
Enumerator
kLCDC_UpperPanel Upper panel frame.
kLCDC_LowerPanel Lower panel frame.
Enumerator
kLCDC_CursorSize32 32x32 pixel cursor.
kLCDC_CursorSize64 64x64 pixel cursor.
Enumerator
kLCDC_CursorAsync Cursor change will be displayed immediately.
kLCDC_CursorSync Cursor change will be displayed in next frame.
Parameters
Return values
Parameters
This function initializes the configuration structure. The default values are:
config->panelClock_Hz = 0U;
config->ppl = 0U;
config->hsw = 0U;
config->hfp = 0U;
config->hbp = 0U;
config->lpp = 0U;
config->vsw = 0U;
config->vfp = 0U;
config->vbp = 0U;
config->acBiasFreq = 1U;
config->polarityFlags = 0U;
config->enableLineEnd = false;
config->lineEndDelay = 0U;
config->upperPanelAddr = 0U;
config->lowerPanelAddr = 0U;
config->bpp = kLCDC_1BPP;
config->dataFormat = kLCDC_LittleEndian;
config->swapRedBlue = false;
config->display = kLCDC_DisplayTFT;
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Example to enable LCD base address update interrupt and vertical compare interrupt:
LCDC_EnableInterrupts(LCD, kLCDC_BaseAddrUpdateInterrupt
| kLCDC_VerticalCompareInterrupt);
Parameters
Example to disable LCD base address update interrupt and vertical compare interrupt:
LCDC_DisableInterrupts(LCD, kLCDC_BaseAddrUpdateInterrupt
| kLCDC_VerticalCompareInterrupt);
Parameters
Example:
uint32_t status;
status = LCDC_GetInterruptsPendingStatus(LCD);
Parameters
Returns
Interrupts pending status, it is OR’ed value of _lcdc_interrupts.
This function is similar with LCDC_GetInterruptsPendingStatus, the only difference is, this function only
returns the pending status of the interrupts that have been enabled using LCDC_EnableInterrupts.
Parameters
Returns
Interrupts pending status, it is OR’ed value of _lcdc_interrupts.
Example to clear LCD base address update interrupt and vertical compare interrupt pending status:
LCDC_ClearInterruptsStatus(LCD,
kLCDC_BaseAddrUpdateInterrupt |
kLCDC_VerticalCompareInterrupt);
Parameters
This function should be called before enabling the hardware cursor. It supports initializing multiple cursor
images at a time when using 32x32 pixels cursor.
For example:
lcdc_cursor_config_t cursorConfig;
LCDC_CursorGetDefaultConfig(&cursorConfig);
cursorConfig.image[0] = cursor0Img;
cursorConfig.image[2] = cursor2Img;
LCDC_SetCursorConfig(LCD, &cursorConfig);
LCDC_ChooseCursor(LCD, 0);
LCDC_SetCursorPosition(LCD, 0, 0);
LCDC_EnableCursor(LCD);
In this example, cursor 0 and cursor 2 image data are initialized, but cursor 1 and cursor 3 image data
are not initialized because image[1] and image[2] are all NULL. With this, application could initializes
all cursor images it will use at the beginning and call LCDC_SetCursorImage directly to display the one
which it needs.
Parameters
config->size = kLCDC_CursorSize32;
config->syncMode = kLCDC_CursorAsync;
config->palette0.red = 0U;
config->palette0.green = 0U;
config->palette0.blue = 0U;
config->palette1.red = 255U;
config->palette1.green = 255U;
config->palette1.blue = 255U;
config->image[0] = (uint32_t *)0;
config->image[1] = (uint32_t *)0;
config->image[2] = (uint32_t *)0;
config->image[3] = (uint32_t *)0;
Parameters
Parameters
When using 32x32 cursor, the number of cursors supports is LCDC_CURSOR_COUNT. When using
64x64 cursor, the LCD only supports one cursor. This function selects which cursor to display when using
32x32 cursor. When synchronization mode is kLCDC_CursorSync, the change effects in the next frame.
When synchronization mode is ∗ kLCDC_CursorAsync, change effects immediately.
Parameters
Note
The function LCDC_SetCursorPosition must be called after this function to show the new cursor.
When synchronization mode is kLCDC_CursorSync, position change effects in the next frame. When
synchronization mode is kLCDC_CursorAsync, position change effects immediately.
Parameters
The interrupt kLCDC_CursorInterrupt indicates that last cursor pixel is displayed. When the hardware
cursor is enabled,
Parameters
Data Structures
• struct mcan_tx_buffer_frame_t
MCAN Tx Buffer structure. More...
• struct mcan_rx_buffer_frame_t
MCAN Rx FIFO/Buffer structure. More...
• struct mcan_rx_fifo_config_t
MCAN Rx FIFO configuration. More...
• struct mcan_rx_buffer_config_t
MCAN Rx Buffer configuration. More...
• struct mcan_tx_fifo_config_t
MCAN Tx Event FIFO configuration. More...
• struct mcan_tx_buffer_config_t
MCAN Tx Buffer configuration. More...
• struct mcan_std_filter_element_config_t
MCAN Standard Message ID Filter Element. More...
• struct mcan_ext_filter_element_config_t
MCAN Extended Message ID Filter Element. More...
• struct mcan_frame_filter_config_t
MCAN Rx filter configuration. More...
• struct mcan_config_t
MCAN module configuration structure. More...
• struct mcan_timing_config_t
MCAN protocol timing characteristic configuration structure. More...
• struct mcan_buffer_transfer_t
MCAN Buffer transfer. More...
• struct mcan_fifo_transfer_t
MCAN Rx FIFO transfer. More...
• struct mcan_handle_t
MCAN handle structure. More...
Typedefs
• typedef void(∗ mcan_transfer_callback_t )(CAN_Type ∗base, mcan_handle_t ∗handle, status_t sta-
tus, uint32_t result, void ∗userData)
MCAN transfer callback function.
Enumerations
• enum _mcan_status {
kStatus_MCAN_TxBusy = MAKE_STATUS(kStatusGroup_MCAN, 0),
kStatus_MCAN_TxIdle = MAKE_STATUS(kStatusGroup_MCAN, 1),
kStatus_MCAN_RxBusy = MAKE_STATUS(kStatusGroup_MCAN, 2),
kStatus_MCAN_RxIdle = MAKE_STATUS(kStatusGroup_MCAN, 3),
kStatus_MCAN_RxFifo0New = MAKE_STATUS(kStatusGroup_MCAN, 4),
kStatus_MCAN_RxFifo0Idle = MAKE_STATUS(kStatusGroup_MCAN, 5),
kStatus_MCAN_RxFifo0Watermark = MAKE_STATUS(kStatusGroup_MCAN, 6),
kStatus_MCAN_RxFifo0Full = MAKE_STATUS(kStatusGroup_MCAN, 7),
kStatus_MCAN_RxFifo0Lost = MAKE_STATUS(kStatusGroup_MCAN, 8),
kStatus_MCAN_RxFifo1New = MAKE_STATUS(kStatusGroup_MCAN, 9),
kStatus_MCAN_RxFifo1Idle = MAKE_STATUS(kStatusGroup_MCAN, 10),
kStatus_MCAN_RxFifo1Watermark = MAKE_STATUS(kStatusGroup_MCAN, 11),
kStatus_MCAN_RxFifo1Full = MAKE_STATUS(kStatusGroup_MCAN, 12),
kStatus_MCAN_RxFifo1Lost = MAKE_STATUS(kStatusGroup_MCAN, 13),
kStatus_MCAN_RxFifo0Busy = MAKE_STATUS(kStatusGroup_MCAN, 14),
kStatus_MCAN_RxFifo1Busy = MAKE_STATUS(kStatusGroup_MCAN, 15),
kStatus_MCAN_ErrorStatus = MAKE_STATUS(kStatusGroup_MCAN, 16),
kStatus_MCAN_UnHandled = MAKE_STATUS(kStatusGroup_MCAN, 17) }
MCAN transfer status.
• enum _mcan_flags {
kMCAN_AccesstoRsvdFlag = CAN_IR_ARA_MASK,
kMCAN_ProtocolErrDIntFlag = CAN_IR_PED_MASK,
kMCAN_ProtocolErrAIntFlag = CAN_IR_PEA_MASK,
kMCAN_BusOffIntFlag = CAN_IR_BO_MASK,
kMCAN_ErrorWarningIntFlag = CAN_IR_EW_MASK,
kMCAN_ErrorPassiveIntFlag = CAN_IR_EP_MASK }
MCAN status flags.
• enum _mcan_rx_fifo_flags {
kMCAN_RxFifo0NewFlag = CAN_IR_RF0N_MASK,
kMCAN_RxFifo0WatermarkFlag = CAN_IR_RF0W_MASK,
kMCAN_RxFifo0FullFlag = CAN_IR_RF0F_MASK,
kMCAN_RxFifo0LostFlag = CAN_IR_RF0L_MASK,
kMCAN_RxFifo1NewFlag = CAN_IR_RF1N_MASK,
kMCAN_RxFifo1WatermarkFlag = CAN_IR_RF1W_MASK,
kMCAN_RxFifo1FullFlag = CAN_IR_RF1F_MASK,
kMCAN_RxFifo1LostFlag = CAN_IR_RF1L_MASK }
MCAN Rx FIFO status flags.
• enum _mcan_tx_flags {
kMCAN_TxTransmitCompleteFlag = CAN_IR_TC_MASK,
kMCAN_TxTransmitCancelFinishFlag = CAN_IR_TCF_MASK,
kMCAN_TxEventFifoLostFlag = CAN_IR_TEFL_MASK,
kMCAN_TxEventFifoFullFlag = CAN_IR_TEFF_MASK,
kMCAN_TxEventFifoWatermarkFlag = CAN_IR_TEFW_MASK,
kMCAN_TxEventFifoNewFlag = CAN_IR_TEFN_MASK,
kMCAN_TxEventFifoEmptyFlag = CAN_IR_TFE_MASK }
MCAN Tx status flags.
• enum _mcan_interrupt_enable {
kMCAN_BusOffInterruptEnable = CAN_IE_BOE_MASK,
kMCAN_ErrorInterruptEnable = CAN_IE_EPE_MASK,
kMCAN_WarningInterruptEnable = CAN_IE_EWE_MASK }
MCAN interrupt configuration structure, default settings all disabled.
• enum mcan_frame_idformat_t {
kMCAN_FrameIDStandard = 0x0U,
kMCAN_FrameIDExtend = 0x1U }
MCAN frame format.
• enum mcan_frame_type_t {
kMCAN_FrameTypeData = 0x0U,
kMCAN_FrameTypeRemote = 0x1U }
MCAN frame type.
• enum mcan_bytes_in_datafield_t {
kMCAN_8ByteDatafield = 0x0U,
kMCAN_12ByteDatafield = 0x1U,
kMCAN_16ByteDatafield = 0x2U,
kMCAN_20ByteDatafield = 0x3U,
kMCAN_24ByteDatafield = 0x4U,
kMCAN_32ByteDatafield = 0x5U,
kMCAN_48ByteDatafield = 0x6U,
kMCAN_64ByteDatafield = 0x7U }
MCAN frame datafield size.
• enum mcan_fifo_type_t {
kMCAN_Fifo0 = 0x0U,
kMCAN_Fifo1 = 0x1U }
MCAN Rx FIFO block number.
• enum mcan_fifo_opmode_config_t {
kMCAN_FifoBlocking = 0,
kMCAN_FifoOverwrite = 1 }
MCAN FIFO Operation Mode.
• enum mcan_txmode_config_t {
kMCAN_txFifo = 0,
kMCAN_txQueue = 1 }
MCAN Tx FIFO/Queue Mode.
• enum mcan_remote_frame_config_t {
kMCAN_filterFrame = 0,
kMCAN_rejectFrame = 1 }
MCAN remote frames treatment.
• enum mcan_nonmasking_frame_config_t {
kMCAN_acceptinFifo0 = 0,
kMCAN_acceptinFifo1 = 1,
kMCAN_reject0 = 2,
kMCAN_reject1 = 3 }
MCAN non-masking frames treatment.
• enum mcan_fec_config_t {
kMCAN_disable = 0,
kMCAN_storeinFifo0 = 1,
kMCAN_storeinFifo1 = 2,
kMCAN_reject = 3,
kMCAN_setprio = 4,
kMCAN_setpriofifo0 = 5,
kMCAN_setpriofifo1 = 6,
kMCAN_storeinbuffer = 7 }
MCAN Filter Element Configuration.
• enum mcan_filter_type_t {
kMCAN_range = 0,
kMCAN_dual = 1,
kMCAN_classic = 2,
kMCAN_disableORrange2 = 3 }
MCAN Filter Type.
Driver version
• #define MCAN_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
MCAN driver version 2.0.0.
Configuration.
• static void MCAN_SetMsgRAMBase (CAN_Type ∗base, uint32_t value)
Sets the MCAN Message RAM base address.
• static uint32_t MCAN_GetMsgRAMBase (CAN_Type ∗base)
Gets the MCAN Message RAM base address.
• void MCAN_SetArbitrationTimingConfig (CAN_Type ∗base, const mcan_timing_config_-
t ∗config)
Sets the MCAN protocol arbitration phase timing characteristic.
• void MCAN_SetDataTimingConfig (CAN_Type ∗base, const mcan_timing_config_t ∗config)
Sets the MCAN protocol data phase timing characteristic.
Status
• static uint32_t MCAN_GetStatusFlag (CAN_Type ∗base, uint32_t mask)
Gets the MCAN module interrupt flags.
• static void MCAN_ClearStatusFlag (CAN_Type ∗base, uint32_t mask)
Clears the MCAN module interrupt flags.
• static bool MCAN_GetRxBufferStatusFlag (CAN_Type ∗base, uint8_t idx)
Gets the new data flag of specific Rx Buffer.
• static void MCAN_ClearRxBufferStatusFlag (CAN_Type ∗base, uint8_t idx)
Clears the new data flag of specific Rx Buffer.
Interrupts
• static void MCAN_EnableInterrupts (CAN_Type ∗base, uint32_t line, uint32_t mask)
Enables MCAN interrupts according to the provided interrupt line and mask.
• static void MCAN_EnableTransmitBufferInterrupts (CAN_Type ∗base, uint8_t idx)
Enables MCAN Tx Buffer interrupts according to the provided index.
• static void MCAN_DisableTransmitBufferInterrupts (CAN_Type ∗base, uint8_t idx)
Disables MCAN Tx Buffer interrupts according to the provided index.
• static void MCAN_DisableInterrupts (CAN_Type ∗base, uint32_t mask)
Disables MCAN interrupts according to the provided mask.
Bus Operations
• status_t MCAN_WriteTxBuffer (CAN_Type ∗base, uint8_t idx, const mcan_tx_buffer_frame_t ∗tx-
Frame)
Writes a MCAN Message to the Transmit Buffer.
• status_t MCAN_ReadRxFifo (CAN_Type ∗base, uint8_t fifoBlock, mcan_rx_buffer_frame_t ∗rx-
Frame)
Reads a MCAN Message from Rx FIFO.
Transactional
• static void MCAN_TransmitAddRequest (CAN_Type ∗base, uint8_t idx)
Tx Buffer add request to send message out.
• static void MCAN_TransmitCancelRequest (CAN_Type ∗base, uint8_t idx)
Tx Buffer cancel sending request.
• status_t MCAN_TransferSendBlocking (CAN_Type ∗base, uint8_t idx, mcan_tx_buffer_frame_t
∗txFrame)
Performs a polling send transaction on the CAN bus.
• status_t MCAN_TransferReceiveFifoBlocking (CAN_Type ∗base, uint8_t fifoBlock, mcan_rx_-
buffer_frame_t ∗rxFrame)
Performs a polling receive transaction from Rx FIFO on the CAN bus.
• void MCAN_TransferCreateHandle (CAN_Type ∗base, mcan_handle_t ∗handle, mcan_transfer_-
callback_t callback, void ∗userData)
Initializes the MCAN handle.
• status_t MCAN_TransferSendNonBlocking (CAN_Type ∗base, mcan_handle_t ∗handle, mcan_-
buffer_transfer_t ∗xfer)
Sends a message using IRQ.
• status_t MCAN_TransferReceiveFifoNonBlocking (CAN_Type ∗base, uint8_t fifoBlock, mcan_-
handle_t ∗handle, mcan_fifo_transfer_t ∗xfer)
Receives a message from Rx FIFO using IRQ.
• void MCAN_TransferAbortSend (CAN_Type ∗base, mcan_handle_t ∗handle, uint8_t bufferIdx)
Aborts the interrupt driven message send process.
• void MCAN_TransferAbortReceiveFifo (CAN_Type ∗base, uint8_t fifoBlock, mcan_handle_t
∗handle)
Aborts the interrupt driven message receive from Rx FIFO process.
• void MCAN_TransferHandleIRQ (CAN_Type ∗base, mcan_handle_t ∗handle)
MCAN IRQ handle function.
Data Fields
• uint32_t address
Rx Buffer start address.
• mcan_bytes_in_datafield_t datafieldSize
Data field size per frame, size>8 is for CANFD.
Data Fields
• uint32_t address
Event fifo start address.
• uint32_t elementSize
FIFOn element number.
• uint32_t watermark
FIFOn watermark level.
Data Fields
• uint32_t address
Tx Buffers Start Address.
• uint32_t dedicatedSize
Number of Dedicated Transmit Buffers.
• uint32_t fqSize
Transmit FIFO/Queue Size.
• mcan_txmode_config_t mode
Tx FIFO/Queue Mode.
• mcan_bytes_in_datafield_t datafieldSize
Data field size per frame, size>8 is for CANFD.
Data Fields
• uint32_t sfid2: 11
Standard Filter ID 2.
• uint32_t __pad0__: 5
Reserved.
• uint32_t sfid1: 11
Standard Filter ID 1.
• mcan_fec_config_t sfec: 3
Standard Filter Element Configuration.
• mcan_filter_type_t sft: 2
Standard Filter Type/.
Data Fields
• uint32_t efid1: 29
Extended Filter ID 1.
• mcan_fec_config_t efec: 3
Extended Filter Element Configuration.
• uint32_t efid2: 29
Extended Filter ID 2.
• uint32_t __pad0__: 1
Reserved.
• mcan_filter_type_t eft: 2
Extended Filter Type.
Data Fields
• uint32_t address
Filter start address.
• uint32_t listSize
Filter list size.
• mcan_frame_idformat_t idFormat
Frame format.
• mcan_remote_frame_config_t remFrame
Remote frame treatment.
• mcan_nonmasking_frame_config_t nmFrame
Non-masking frame treatment.
Data Fields
• uint32_t baudRateA
Baud rate of Arbitration phase in bps.
• uint32_t baudRateD
Baud rate of Data phase in bps.
• bool enableCanfdNormal
Enable or Disable CANFD normal.
• bool enableCanfdSwitch
Enable or Disable CANFD with baudrate switch.
• bool enableLoopBackInt
Enable or Disable Internal Back.
• bool enableLoopBackExt
Enable or Disable External Loop Back.
• bool enableBusMon
Enable or Disable Bus Monitoring Mode.
Data Fields
• uint16_t preDivider
Clock Pre-scaler Division Factor.
• uint8_t rJumpwidth
Re-sync Jump Width.
• uint8_t seg1
Data Time Segment 1.
• uint8_t seg2
Data Time Segment 2.
Data Fields
• mcan_tx_buffer_frame_t ∗ frame
The buffer of CAN Message to be transfer.
• uint8_t bufferIdx
The index of Message buffer used to transfer Message.
Data Fields
• mcan_rx_buffer_frame_t ∗ frame
The buffer of CAN Message to be received from Rx FIFO.
Data Fields
• mcan_transfer_callback_t callback
Callback function.
• void ∗ userData
MCAN callback function parameter.
• mcan_tx_buffer_frame_t ∗volatile bufferFrameBuf [64]
The buffer for received data from Buffers.
• mcan_rx_buffer_frame_t ∗volatile rxFifoFrameBuf
The buffer for received data from Rx FIFO.
• volatile uint8_t txbufferIdx
Message Buffer transfer state.
• volatile uint8_t bufferState [64]
Message Buffer transfer state.
• volatile uint8_t rxFifoState
Rx FIFO transfer state.
The MCAN transfer callback returns a value from the underlying layer. If the status equals to kStatus_M-
CAN_ErrorStatus, the result parameter is the Content of MCAN status register which can be used to get
the working status(or error status) of MCAN module. If the status equals to other MCAN Message Buffer
transfer status, the result is the index of Message Buffer that generate transfer event. If the status equals to
other MCAN Message Buffer transfer status, the result is meaningless and should be Ignored.
Enumerator
kStatus_MCAN_TxBusy Tx Buffer is Busy.
kStatus_MCAN_TxIdle Tx Buffer is Idle.
kStatus_MCAN_RxBusy Rx Buffer is Busy.
kStatus_MCAN_RxIdle Rx Buffer is Idle.
kStatus_MCAN_RxFifo0New New message written to Rx FIFO 0.
kStatus_MCAN_RxFifo0Idle Rx FIFO 0 is Idle.
kStatus_MCAN_RxFifo0Watermark Rx FIFO 0 fill level reached watermark.
kStatus_MCAN_RxFifo0Full Rx FIFO 0 full.
kStatus_MCAN_RxFifo0Lost Rx FIFO 0 message lost.
kStatus_MCAN_RxFifo1New New message written to Rx FIFO 1.
kStatus_MCAN_RxFifo1Idle Rx FIFO 1 is Idle.
This provides constants for the MCAN status flags for use in the MCAN functions. Note: The CPU read
action clears MCAN_ErrorFlag, therefore user need to read MCAN_ErrorFlag and distinguish which error
is occur using _mcan_error_flags enumerations.
Enumerator
kMCAN_AccesstoRsvdFlag CAN Synchronization Status.
kMCAN_ProtocolErrDIntFlag Tx Warning Interrupt Flag.
kMCAN_ProtocolErrAIntFlag Rx Warning Interrupt Flag.
kMCAN_BusOffIntFlag Tx Error Warning Status.
kMCAN_ErrorWarningIntFlag Rx Error Warning Status.
kMCAN_ErrorPassiveIntFlag Rx Error Warning Status.
The MCAN Rx FIFO Status enumerations are used to determine the status of the Rx FIFO.
Enumerator
kMCAN_RxFifo0NewFlag Rx FIFO 0 new message flag.
kMCAN_RxFifo0WatermarkFlag Rx FIFO 0 watermark reached flag.
kMCAN_RxFifo0FullFlag Rx FIFO 0 full flag.
kMCAN_RxFifo0LostFlag Rx FIFO 0 message lost flag.
kMCAN_RxFifo1NewFlag Rx FIFO 0 new message flag.
kMCAN_RxFifo1WatermarkFlag Rx FIFO 0 watermark reached flag.
kMCAN_RxFifo1FullFlag Rx FIFO 0 full flag.
kMCAN_RxFifo1LostFlag Rx FIFO 0 message lost flag.
The MCAN Tx Status enumerations are used to determine the status of the Tx Buffer/Event FIFO.
Enumerator
kMCAN_TxTransmitCompleteFlag Transmission completed flag.
kMCAN_TxTransmitCancelFinishFlag Transmission cancellation finished flag.
kMCAN_TxEventFifoLostFlag Tx Event FIFO element lost.
kMCAN_TxEventFifoFullFlag Tx Event FIFO full.
kMCAN_TxEventFifoWatermarkFlag Tx Event FIFO fill level reached watermark.
kMCAN_TxEventFifoNewFlag Tx Handler wrote Tx Event FIFO element flag.
kMCAN_TxEventFifoEmptyFlag Tx FIFO empty flag.
This structure contains the settings for all of the MCAN Module interrupt configurations.
Enumerator
kMCAN_BusOffInterruptEnable Bus Off interrupt.
kMCAN_ErrorInterruptEnable Error interrupt.
kMCAN_WarningInterruptEnable Rx Warning interrupt.
Enumerator
kMCAN_FrameIDStandard Standard frame format attribute.
kMCAN_FrameIDExtend Extend frame format attribute.
Enumerator
kMCAN_FrameTypeData Data frame type attribute.
kMCAN_FrameTypeRemote Remote frame type attribute.
Enumerator
kMCAN_8ByteDatafield 8 byte data field.
kMCAN_12ByteDatafield 12 byte data field.
kMCAN_16ByteDatafield 16 byte data field.
Enumerator
kMCAN_Fifo0 CAN Rx FIFO 0.
kMCAN_Fifo1 CAN Rx FIFO 1.
Enumerator
kMCAN_FifoBlocking FIFO blocking mode.
kMCAN_FifoOverwrite FIFO overwrite mode.
Enumerator
kMCAN_txFifo Tx FIFO operation.
kMCAN_txQueue Tx Queue operation.
Enumerator
kMCAN_filterFrame Filter remote frames.
kMCAN_rejectFrame Reject all remote frames.
Enumerator
kMCAN_acceptinFifo0 Accept non-masking frames in Rx FIFO 0.
Enumerator
kMCAN_disable Disable filter element.
kMCAN_storeinFifo0 Store in Rx FIFO 0 if filter matches.
kMCAN_storeinFifo1 Store in Rx FIFO 1 if filter matches.
kMCAN_reject Reject ID if filter matches.
kMCAN_setprio Set priority if filter matches.
kMCAN_setpriofifo0 Set priority and store in FIFO 0 if filter matches.
kMCAN_setpriofifo1 Set priority and store in FIFO 1 if filter matches.
kMCAN_storeinbuffer Store into Rx Buffer or as debug message.
Enumerator
kMCAN_range Range filter from SFID1 to SFID2.
kMCAN_dual Dual ID filter for SFID1 or SFID2.
kMCAN_classic Classic filter: SFID1 = filter, SFID2 = mask.
kMCAN_disableORrange2 Filter element disabled for standard filter or Range filter, XIDAM mask
not applied for extended filter.
This function initializes the MCAN module with user-defined settings. This example shows how to set up
the mcan_config_t parameters and how to call the MCAN_Init function by passing in these parameters.
* mcan_config_t config;
* config->baudRateA = 500000U;
* config->baudRateD = 500000U;
* config->enableCanfdNormal = false;
* config->enableCanfdSwitch = false;
* config->enableLoopBackInt = false;
* config->enableLoopBackExt = false;
* config->enableBusMon = false;
* MCAN_Init(CANFD0, &config, 8000000UL);
*
Parameters
This function initializes the MCAN configuration structure to default values. The default values are as
follows. config->baudRateA = 500000U; config->baudRateD = 500000U; config->enableCanfdNormal
= false; config->enableCanfdSwitch = false; config->enableLoopBackInt = false; config->enableLoop-
BackExt = false; config->enableBusMon = false;
Parameters
After initialization, INIT bit in CCCR register must be cleared to enter normal mode thus synchronizes to
the CAN bus and ready for communication.
Parameters
Returns
Message RAM base address.
This function gives user settings to CAN bus timing characteristic. The function is for an experienced
user. For less experienced users, call the MCAN_Init() and fill the baud rate field with a desired value.
This provides the default arbitration phase timing characteristics.
Note that calling MCAN_SetArbitrationTimingConfig() overrides the baud rate set in MCAN_Init().
Parameters
This function gives user settings to CAN bus timing characteristic. The function is for an experienced
user. For less experienced users, call the MCAN_Init() and fill the baud rate field with a desired value.
This provides the default data phase timing characteristics.
Note that calling MCAN_SetArbitrationTimingConfig() overrides the baud rate set in MCAN_Init().
Parameters
This function sets start address, element size, watermark, operation mode and datafield size of the recieve
fifo 0.
Parameters
This function sets start address, element size, watermark, operation mode and datafield size of the recieve
fifo 1.
Parameters
This function sets start address and datafield size of the recieve buffer.
Parameters
This function sets start address, element size, watermark of the transmit event fifo.
Parameters
This function sets start address, element size, fifo/queue mode and datafield size of the transmit buffer.
Parameters
This function sets remote and non masking frames in global filter configuration, also the start address, list
size in standard/extended ID filter configuration.
Parameters
This function sets remote and non masking frames in global filter configuration, also the start address, list
size in standard/extended ID filter configuration.
Parameters
This function sets remote and non masking frames in global filter configuration, also the start address, list
size in standard/extended ID filter configuration.
Parameters
Returns
MCAN status flags which are ORed.
Parameters
Returns
Rx Buffer new data status flag.
This function enables the MCAN interrupts according to the provided interrupt line and mask. The mask
is a logical OR of enumeration members.
Parameters
This function disables the MCAN interrupts according to the provided mask. The mask is a logical OR of
enumeration members.
Parameters
This function writes a CAN Message to the specified Transmit Message Buffer and changes the Message
Buffer state to start CAN Message transmit. After that the function returns immediately.
Parameters
This function reads a CAN message from the Rx FIFO in the Message RAM.
Parameters
Return values
Parameters
Note that a transfer handle does not need to be created before calling this API.
Parameters
Return values
Note that a transfer handle does not need to be created before calling this API.
Parameters
Return values
This function initializes the MCAN handle, which can be used for other MCAN transactional APIs. Usu-
ally, for a specified MCAN instance, call this API once to get the initialized handle.
Parameters
This function sends a message using IRQ. This is a non-blocking function, which returns right away.
When messages have been sent out, the send callback function is called.
Parameters
Return values
This function receives a message using IRQ. This is a non-blocking function, which returns right away.
When all messages have been received, the receive callback function is called.
Parameters
Return values
This function aborts the interrupt driven message receive from Rx FIFO process.
Parameters
This function handles the MCAN Error, the Buffer, and the Rx FIFO IRQ request.
Parameters
The function MRT_Init() initializes the MRT with specified configurations. The function MRT_Get-
DefaultConfig() gets the default configurations. The initialization function configures the MRT operating
mode.
The function MRT_Deinit() stops the MRT timers and disables the module clock.
The function MRT_UpdateTimerPeriod() is used to update the timer period in units of count. The new
value will be immediately loaded or will be loaded at the end of the current time interval.
The function MRT_GetCurrentTimerCount() reads the current timer counting value. This function returns
the real-time timer counting value, in a range from 0 to a timer period.
The timer period operation functions takes the count value in ticks. User can call the utility macros
provided in fsl_common.h to convert to microseconds or milliseconds
The function MRT_StartTimer() starts the timer counting. After calling this function, the timer loads the
period value, counts down to 0 and depending on the timer mode it will either load the respective start
value again or stop. When the timer reaches 0, it generates a trigger pulse and sets the timeout interrupt
flag.
The function MRT_StopTimer() stops the timer counting.
These functions can be used to reserve and release a channel. The function MRT_GetIdleChannel() finds
the available channel. This function returns the lowest available channel number. The function MRT_-
ReleaseChannel() release the channel when the timer is using the multi-task mode. In multi-task mode,
the INUSE flags allow more control over when MRT channels are released for further use.
28.2.5 Status
28.2.6 Interrupt
Provides functions to enable/disable PIT interrupts and get current enabled interrupts.
int main(void)
{
uint32_t mrt_clock;
mrt_clock = CLOCK_GetFreq(kCLOCK_BusClk);
/* mrtConfig.enableMultiTask = false; */
MRT_GetDefaultConfig(&mrtConfig);
/* Start channel 0 */
while (true)
{
/* Check whether occur interupt and toggle LED */
if (true == mrtIsrFlag)
{
PRINTF("\r\n Channel No.0 interrupt is occured !");
LED_RED_TOGGLE();
mrtIsrFlag = false;
}
}
}
Files
• file fsl_mrt.h
Data Structures
• struct mrt_config_t
MRT configuration structure. More...
Enumerations
• enum mrt_chnl_t {
kMRT_Channel_0 = 0U,
kMRT_Channel_1,
kMRT_Channel_2,
kMRT_Channel_3 }
List of MRT channels.
• enum mrt_timer_mode_t {
kMRT_RepeatMode = (0 << MRT_CHANNEL_CTRL_MODE_SHIFT),
kMRT_OneShotMode = (1 << MRT_CHANNEL_CTRL_MODE_SHIFT),
kMRT_OneShotStallMode = (2 << MRT_CHANNEL_CTRL_MODE_SHIFT) }
List of MRT timer modes.
• enum mrt_interrupt_enable_t { kMRT_TimerInterruptEnable = MRT_CHANNEL_CTRL_INTE-
N_MASK }
List of MRT interrupts.
• enum mrt_status_flags_t {
kMRT_TimerInterruptFlag = MRT_CHANNEL_STAT_INTFLAG_MASK,
kMRT_TimerRunFlag = MRT_CHANNEL_STAT_RUN_MASK }
List of MRT status flags.
Driver version
• #define FSL_MRT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Version 2.0.0.
Interrupt Interface
• static void MRT_EnableInterrupts (MRT_Type ∗base, mrt_chnl_t channel, uint32_t mask)
Enables the MRT interrupt.
• static void MRT_DisableInterrupts (MRT_Type ∗base, mrt_chnl_t channel, uint32_t mask)
Disables the selected MRT interrupt.
• static uint32_t MRT_GetEnabledInterrupts (MRT_Type ∗base, mrt_chnl_t channel)
Gets the enabled MRT interrupts.
Status Interface
• static uint32_t MRT_GetStatusFlags (MRT_Type ∗base, mrt_chnl_t channel)
Gets the MRT status flags.
• static void MRT_ClearStatusFlags (MRT_Type ∗base, mrt_chnl_t channel, uint32_t mask)
Clears the MRT status flags.
This structure holds the configuration settings for the MRT peripheral. To initialize this structure to rea-
sonable defaults, call the MRT_GetDefaultConfig() function and pass a pointer to your config structure
instance.
The config struct can be made const so it resides in flash
Data Fields
• bool enableMultiTask
true: Timers run in multi-task mode; false: Timers run in hardware status mode
Enumerator
kMRT_Channel_0 MRT channel number 0.
kMRT_Channel_1 MRT channel number 1.
kMRT_Channel_2 MRT channel number 2.
kMRT_Channel_3 MRT channel number 3.
Enumerator
kMRT_RepeatMode Repeat Interrupt mode.
kMRT_OneShotMode One-shot Interrupt mode.
kMRT_OneShotStallMode One-shot stall mode.
Enumerator
kMRT_TimerInterruptEnable Timer interrupt enable.
Enumerator
kMRT_TimerInterruptFlag Timer interrupt flag.
kMRT_TimerRunFlag Indicates state of the timer.
Note
This API should be called at the beginning of the application using the MRT driver.
Parameters
Parameters
* config->enableMultiTask = false;
*
Parameters
Parameters
Parameters
Parameters
Parameters
Returns
The enabled interrupts. This is the logical OR of members of the enumeration mrt_interrupt_enable-
_t
Parameters
Returns
The status flags. This is the logical OR of members of the enumeration mrt_status_flags_t
Parameters
The new value will be immediately loaded or will be loaded at the end of the current time interval. For
one-shot interrupt mode the new value will be immediately loaded.
Note
User can call the utility macros provided in fsl_common.h to convert to ticks
Parameters
This function returns the real-time timer counting value, in a range from 0 to a timer period.
Note
User can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
Parameters
Returns
Current timer counting value in ticks
After calling this function, timers load period value, counts down to 0 and depending on the timer mode it
will either load the respective start value again or stop.
Note
User can call the utility macros provided in fsl_common.h to convert to ticks
Parameters
In multi-task mode, the INUSE flags allow more control over when MRT channels are released for further
use. The user can hold on to a channel acquired by calling MRT_GetIdleChannel() for as long as it is
needed and release it by calling this function. This removes the need to ask for an available channel for
every use.
Parameters
{
status_t status;
CLOCK_EnableClock(kCLOCK_Otp);
status = OTP_EnableBankWriteMask(kOTP_Bank3);
if (status != kStatus_Success)
{
return;
}
/* Unreversible operation */
status = OTP_ProgramRegister(3U, 1U, 0xA5A5U);
if (status != kStatus_Success)
{
return;
}
}
Enumerations
• enum otp_bank_t {
kOTP_Bank0 = 0x1U,
kOTP_Bank1 = 0x2U,
kOTP_Bank2 = 0x4U,
kOTP_Bank3 = 0x8U }
Bank bit flags.
• enum otp_word_t {
kOTP_Word0 = 0x1U,
kOTP_Word1 = 0x2U,
kOTP_Word2 = 0x4U,
kOTP_Word3 = 0x8U }
Bank word bit flags.
• enum otp_lock_t {
kOTP_LockDontLock = 0U,
kOTP_LockLock = 1U }
Functions
• static status_t OTP_Init (void)
Initializes OTP controller.
• static status_t OTP_EnableBankWriteMask (otp_bank_t bankMask)
Unlock one or more OTP banks for write access.
• static status_t OTP_DisableBankWriteMask (otp_bank_t bankMask)
Lock one or more OTP banks for write access.
• static status_t OTP_EnableBankWriteLock (uint32_t bankIndex, otp_word_t regEnableMask, otp-
_word_t regDisableMask, otp_lock_t lockWrite)
Locks or unlocks write access to a register of an OTP bank and possibly lock un/locking of it.
• static status_t OTP_EnableBankReadLock (uint32_t bankIndex, otp_word_t regEnableMask, otp_-
word_t regDisableMask, otp_lock_t lockWrite)
Locks or unlocks read access to a register of an OTP bank and possibly lock un/locking of it.
• static status_t OTP_ProgramRegister (uint32_t bankIndex, uint32_t regIndex, uint32_t value)
Program a single register in an OTP bank.
• static uint32_t OTP_GetDriverVersion (void)
Returns the version of the OTP driver in ROM.
Driver version
• #define FSL_OTP_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
OTP driver version 2.0.0.
• Version 2.0.0
– Initial version.
Enumerator
kOTP_Bank0 Bank 0.
kOTP_Bank1 Bank 1.
kOTP_Bank2 Bank 2.
kOTP_Bank3 Bank 3.
Enumerator
kOTP_Word0 Word 0.
kOTP_Word1 Word 1.
kOTP_Word2 Word 2.
kOTP_Word3 Word 3.
Enumerator
kOTP_LockDontLock Do not lock.
kOTP_LockLock Lock till reset.
Enumerator
kStatus_OTP_WrEnableInvalid Write enable invalid.
kStatus_OTP_SomeBitsAlreadyProgrammed Some bits already programmed.
kStatus_OTP_AllDataOrMaskZero All data or mask zero.
kStatus_OTP_WriteAccessLocked Write access locked.
kStatus_OTP_ReadDataMismatch Read data mismatch.
kStatus_OTP_UsbIdEnabled USB ID enabled.
kStatus_OTP_EthMacEnabled Ethernet MAC enabled.
kStatus_OTP_AesKeysEnabled AES keys enabled.
Returns
kStatus_Success upon successful execution, error status otherwise.
Parameters
Returns
kStatus_Success upon successful execution, error status otherwise.
Parameters
Returns
kStatus_Success upon successful execution, error status otherwise.
Parameters
Returns
kStatus_Success upon successful execution, error status otherwise.
Parameters
Returns
kStatus_Success upon successful execution, error status otherwise.
Parameters
Returns
kStatus_Success upon successful execution, error status otherwise.
Returns
version.
/* Initialize PINT */
PINT_Init(PINT);
pint_pmatch_cfg_t pmcfg;
/* Initialize PINT */
PINT_Init(PINT);
/* Enable PatternMatch */
PINT_PatternMatchEnable(PINT);
Files
• file fsl_pint.h
Typedefs
• typedef void(∗ pint_cb_t )(pint_pin_int_t pintr, uint32_t pmatch_status)
PINT Callback function.
Enumerations
• enum pint_pin_enable_t {
kPINT_PinIntEnableNone = 0U,
kPINT_PinIntEnableRiseEdge = PINT_PIN_RISE_EDGE,
kPINT_PinIntEnableFallEdge = PINT_PIN_FALL_EDGE,
kPINT_PinIntEnableBothEdges = PINT_PIN_BOTH_EDGE,
kPINT_PinIntEnableLowLevel = PINT_PIN_LOW_LEVEL,
kPINT_PinIntEnableHighLevel = PINT_PIN_HIGH_LEVEL }
PINT Pin Interrupt enable type.
• enum pint_pin_int_t { kPINT_PinInt0 = 0U }
PINT Pin Interrupt type.
• enum pint_pmatch_input_src_t {
kPINT_PatternMatchInp0Src = 0U,
kPINT_PatternMatchInp1Src = 1U,
kPINT_PatternMatchInp2Src = 2U,
kPINT_PatternMatchInp3Src = 3U,
kPINT_PatternMatchInp4Src = 4U,
kPINT_PatternMatchInp5Src = 5U,
kPINT_PatternMatchInp6Src = 6U,
kPINT_PatternMatchInp7Src = 7U }
PINT Pattern Match bit slice input source type.
• enum pint_pmatch_bslice_t { kPINT_PatternMatchBSlice0 = 0U }
PINT Pattern Match bit slice type.
• enum pint_pmatch_bslice_cfg_t {
kPINT_PatternMatchAlways = 0U,
kPINT_PatternMatchStickyRise = 1U,
kPINT_PatternMatchStickyFall = 2U,
kPINT_PatternMatchStickyBothEdges = 3U,
kPINT_PatternMatchHigh = 4U,
kPINT_PatternMatchLow = 5U,
kPINT_PatternMatchNever = 6U,
kPINT_PatternMatchBothEdges = 7U }
PINT Pattern Match configuration type.
Functions
• void PINT_Init (PINT_Type ∗base)
Initialize PINT peripheral.
• void PINT_PinInterruptConfig (PINT_Type ∗base, pint_pin_int_t intr, pint_pin_enable_t enable,
pint_cb_t callback)
Configure PINT peripheral pin interrupt.
• void PINT_PinInterruptGetConfig (PINT_Type ∗base, pint_pin_int_t pintr, pint_pin_enable_t
∗enable, pint_cb_t ∗callback)
Get PINT peripheral pin interrupt configuration.
• static void PINT_PinInterruptClrStatus (PINT_Type ∗base, pint_pin_int_t pintr)
Clear Selected pin interrupt status.
• static uint32_t PINT_PinInterruptGetStatus (PINT_Type ∗base, pint_pin_int_t pintr)
Get Selected pin interrupt status.
• static void PINT_PinInterruptClrStatusAll (PINT_Type ∗base)
Clear all pin interrupts status.
• static uint32_t PINT_PinInterruptGetStatusAll (PINT_Type ∗base)
Get all pin interrupts status.
• static void PINT_PinInterruptClrFallFlag (PINT_Type ∗base, pint_pin_int_t pintr)
Clear Selected pin interrupt fall flag.
• static uint32_t PINT_PinInterruptGetFallFlag (PINT_Type ∗base, pint_pin_int_t pintr)
Get selected pin interrupt fall flag.
• static void PINT_PinInterruptClrFallFlagAll (PINT_Type ∗base)
Clear all pin interrupt fall flags.
• static uint32_t PINT_PinInterruptGetFallFlagAll (PINT_Type ∗base)
Get all pin interrupt fall flags.
• static void PINT_PinInterruptClrRiseFlag (PINT_Type ∗base, pint_pin_int_t pintr)
Clear Selected pin interrupt rise flag.
• static uint32_t PINT_PinInterruptGetRiseFlag (PINT_Type ∗base, pint_pin_int_t pintr)
Get selected pin interrupt rise flag.
• static void PINT_PinInterruptClrRiseFlagAll (PINT_Type ∗base)
Clear all pin interrupt rise flags.
• static uint32_t PINT_PinInterruptGetRiseFlagAll (PINT_Type ∗base)
Get all pin interrupt rise flags.
• void PINT_PatternMatchConfig (PINT_Type ∗base, pint_pmatch_bslice_t bslice, pint_pmatch_cfg-
_t ∗cfg)
Configure PINT pattern match.
• void PINT_PatternMatchGetConfig (PINT_Type ∗base, pint_pmatch_bslice_t bslice, pint_pmatch-
_cfg_t ∗cfg)
Driver version
• #define FSL_PINT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Version 2.0.0.
Enumerator
kPINT_PinIntEnableNone Do not generate Pin Interrupt.
kPINT_PinIntEnableRiseEdge Generate Pin Interrupt on rising edge.
kPINT_PinIntEnableFallEdge Generate Pin Interrupt on falling edge.
kPINT_PinIntEnableBothEdges Generate Pin Interrupt on both edges.
kPINT_PinIntEnableLowLevel Generate Pin Interrupt on low level.
kPINT_PinIntEnableHighLevel Generate Pin Interrupt on high level.
Enumerator
kPINT_PinInt0 Pin Interrupt 0.
Enumerator
kPINT_PatternMatchInp0Src Input source 0.
kPINT_PatternMatchInp1Src Input source 1.
kPINT_PatternMatchInp2Src Input source 2.
kPINT_PatternMatchInp3Src Input source 3.
kPINT_PatternMatchInp4Src Input source 4.
kPINT_PatternMatchInp5Src Input source 5.
kPINT_PatternMatchInp6Src Input source 6.
kPINT_PatternMatchInp7Src Input source 7.
Enumerator
kPINT_PatternMatchBSlice0 Bit slice 0.
Enumerator
kPINT_PatternMatchAlways Always Contributes to product term match.
kPINT_PatternMatchStickyRise Sticky Rising edge.
kPINT_PatternMatchStickyFall Sticky Falling edge.
kPINT_PatternMatchStickyBothEdges Sticky Rising or Falling edge.
kPINT_PatternMatchHigh High level.
kPINT_PatternMatchLow Low level.
kPINT_PatternMatchNever Never contributes to product term match.
kPINT_PatternMatchBothEdges Either rising or falling edge.
This function initializes the PINT peripheral and enables the clock.
Parameters
Return values
None.
Return values
None.
callback Callback.
Return values
None.
Return values
None.
Return values
Parameters
Return values
None.
Return values
status Each bit position indicates the status of corresponding pin interrupt. = 0
No pin interrupt request. = 1 Pin interrupt request active.
Return values
None.
Parameters
Return values
flag = 0 Falling edge has not been detected. = 1 Falling edge has been detected.
This function clears the fall flag for all pin interrupts.
Parameters
Return values
None.
Return values
flags Each bit position indicates the falling edge detection of the corresponding
pin interrupt. 0 Falling edge has not been detected. = 1 Falling edge has
been detected.
Parameters
Return values
None.
Return values
flag = 0 Rising edge has not been detected. = 1 Rising edge has been detected.
This function clears the rise flag for all pin interrupts.
Parameters
Return values
None.
Parameters
Return values
flags Each bit position indicates the rising edge detection of the corresponding
pin interrupt. 0 Rising edge has not been detected. = 1 Rising edge has
been detected.
Return values
None.
This function returns the configuration of a given pattern match bit slice.
Parameters
Return values
None.
Return values
status = 0 Match has not been detected. = 1 Match has been detected.
Return values
status Each bit position indicates the match status of corresponding bit slice. = 0
Match has not been detected. = 1 Match has been detected.
This function resets the pattern match detection logic if any of the product term is matching.
Parameters
Return values
pmstatus Each bit position indicates the match status of corresponding bit slice. = 0
Match was detected. = 1 Match was not detected.
Return values
None.
Return values
None.
Parameters
Return values
None.
Return values
None.
This function enables the interrupt for the selected PINT peripheral. Although the pin(s) are monitored as
soon as they are enabled, the callback function is not enabled until this function is called.
Parameters
Return values
None.
This function disables the interrupt for the selected PINT peripheral. Although the pins are still being
monitored but the callback function is not called.
Parameters
Return values
None.
Return values
None.
The function RIT_Init() initializes the RIT with specified configurations. The function RIT_GetDefault-
Config() gets the default configurations. The initialization function configures the RIT operation normally
in debug mode.
The function RIT_Deinit() disables the RIT timers and disables the module clock.
The function RIT_SetTimerCompare() sets the timer period in units of count. Timers counts from 0 to the
count value set here. The function RIT_SetMaskBit() sets some bit which will be ignored in comparison
between the compare and counter register.
The function RIT_GetCurrentTimerCount() reads the current timer counting value. This function returns
the real-time timer counting value, in a range from 0 to a timer period.
The timer period operation functions takes the count value in ticks. User can call the utility macros
provided in fsl_common.h to convert to microseconds or milliseconds
The function RIT_StartTimer() starts the timer counting. After calling this function, the timer counts up to
the counter value set earlier by using the RIT_SetTimerCompare() function. Each time the timer reaches
the count value, it generates a trigger pulse and sets the interrupt flag and set the counter to zero/continue
counting when RIT_ClearCounter() set the Timer clear enable/disable.
The function RIT_StopTimer() stops the timer counting./∗ resets the timer’s counter register.
Data Structures
• struct rit_config_t
RIT config structure. More...
Enumerations
• enum rit_status_flags_t { kRIT_TimerFlag = RIT_CTRL_RITINT_MASK }
List of RIT status flags.
Driver version
• #define FSL_RIT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Version 2.0.0.
Status Interface
• static uint32_t RIT_GetStatusFlags (RIT_Type ∗base)
Gets the RIT status flags.
• static void RIT_ClearStatusFlags (RIT_Type ∗base, uint32_t mask)
Clears the RIT status flags.
This structure holds the configuration settings for the RIT peripheral. To initialize this structure to rea-
sonable defaults, call the RIT_GetDefaultConfig() function and pass a pointer to your config structure
instance.
The config struct can be made const so it resides in flash
Data Fields
• bool enableRunInDebug
true: The timer is halted when the processor is halted for debugging.
Enumerator
kRIT_TimerFlag Timer flag.
Note
This API should be called at the beginning of the application using the RIT driver.
Parameters
Parameters
Parameters
Parameters
Returns
The status flags. This is the logical OR of members of the enumeration rit_status_flags_t
Parameters
Timers begin counting from the value set by this function until it XXXXXXX, then it counting the value
again. Software must stop the counter before reloading it with a new value..
Note
Users can call the utility macros provided in fsl_common.h to convert to ticks
Parameters
Timers begin counting from the value set by this function until it XXXXXXX, then it counting the value
again. Software must stop the counter before reloading it with a new value..
Note
Users can call the utility macros provided in fsl_common.h to convert to ticks
Parameters
This function returns the real-time timer counting value, in a range from 0 to a timer period.
Note
Users can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
Parameters
Returns
Current timer counting value in ticks
This function returns the real-time timer counting value, in a range from 0 to a timer period.
Note
Users can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
Parameters
Returns
Current timer counting value in ticks
This function returns the real-time timer counting value, in a range from 0 to a timer period.
Note
Users can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
Parameters
Returns
Current timer counting value in ticks
After calling this function, timers load initial value(0U), count up to desired value or over-flow then the
counter will count up again. Each time a timer reaches desired value, it generates a XXXXXXX and sets
XXXXXXX.
Parameters
This function stop timer counting. Timer reload their new value after the next time they call the RIT_-
StartTimer.
Parameters
{
uint32_t number;
uint32_t skip;
uint32_t data[4];
/* Print data */
PRINTF("0x");
for (number = 0; number < 4; number++)
{
PRINTF("%08X", data[number]);
}
PRINTF("\r\n");
}
Functions
• static uint32_t RNG_GetRandomData (void)
Gets random data.
Driver version
• #define FSL_RNG_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
RNG driver version 2.0.0.
Returns
random data
The function RTC_Init() initializes the RTC with specified configurations. The function RTC_GetDefault-
Config() gets the default configurations.
The function RTC_Deinit() disables the RTC timer and disables the module clock.
The function RTC_SetDatetime() sets the timer period in seconds. User passes in the details in date &
time format by using the below data structure.
The function RTC_GetDatetime() reads the current timer value in seconds, converts it to date & time
format and stores it into a datetime structure passed in by the user.
The function RTC_SetAlarm() sets the alarm time period in seconds. User passes in the details in date &
time format by using the datetime data structure.
The function RTC_GetAlarm() reads the alarm time in seconds, converts it to date & time format and
stores it into a datetime structure passed in by the user.
33.2.5 Status
33.2.6 Interrupt
Provides functions to enable/disable RTC interrupts and get current enabled interrupts.
Provides functions to enable high resolution timer and set and get the wake time.
int main(void)
{
uint32_t sec;
uint32_t currSeconds;
rtc_datetime_t date;
/* Init RTC */
RTC_Init(RTC);
/* RTC time counter has to be stopped before setting the date & time in the TSR register */
RTC_StopTimer(RTC);
Files
• file fsl_rtc.h
Data Structures
• struct rtc_datetime_t
Structure is used to hold the date and time. More...
Enumerations
• enum rtc_interrupt_enable_t {
kRTC_AlarmInterruptEnable = RTC_CTRL_ALARMDPD_EN_MASK,
kRTC_WakeupInterruptEnable = RTC_CTRL_WAKEDPD_EN_MASK }
List of RTC interrupts.
• enum rtc_status_flags_t {
kRTC_AlarmFlag = RTC_CTRL_ALARM1HZ_MASK,
kRTC_WakeupFlag = RTC_CTRL_WAKE1KHZ_MASK }
List of RTC flags.
Functions
• static void RTC_SetWakeupCount (RTC_Type ∗base, uint16_t wakeupValue)
Enable the RTC high resolution timer and set the wake-up time.
• static uint16_t RTC_GetWakeupCount (RTC_Type ∗base)
Read actual RTC counter value.
• static void RTC_Reset (RTC_Type ∗base)
Performs a software reset on the RTC module.
Driver version
• #define FSL_RTC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Version 2.0.0.
Interrupt Interface
• static void RTC_EnableInterrupts (RTC_Type ∗base, uint32_t mask)
Enables the selected RTC interrupts.
• static void RTC_DisableInterrupts (RTC_Type ∗base, uint32_t mask)
Disables the selected RTC interrupts.
• static uint32_t RTC_GetEnabledInterrupts (RTC_Type ∗base)
Gets the enabled RTC interrupts.
Status Interface
• static uint32_t RTC_GetStatusFlags (RTC_Type ∗base)
Gets the RTC status flags.
• static void RTC_ClearStatusFlags (RTC_Type ∗base, uint32_t mask)
Clears the RTC status flags.
Data Fields
• uint16_t year
Range from 1970 to 2099.
• uint8_t month
Range from 1 to 12.
• uint8_t day
Range from 1 to 31 (depending on month).
• uint8_t hour
Range from 0 to 23.
• uint8_t minute
Range from 0 to 59.
• uint8_t second
Range from 0 to 59.
Enumerator
kRTC_AlarmInterruptEnable Alarm interrupt.
kRTC_WakeupInterruptEnable Wake-up interrupt.
Enumerator
kRTC_AlarmFlag Alarm flag.
kRTC_WakeupFlag 1kHz wake-up timer flag
Note
This API should be called at the beginning of the application using the RTC driver.
Parameters
Parameters
The RTC counter must be stopped prior to calling this function as writes to the RTC seconds register will
fail if the RTC counter is running.
Parameters
Returns
kStatus_Success: Success in setting the time and starting the RTC kStatus_InvalidArgument: Error
because the datetime format is incorrect
Parameters
The function checks whether the specified alarm time is greater than the present time. If not, the function
does not set the alarm and returns an error.
Parameters
Returns
kStatus_Success: success in setting the RTC alarm kStatus_InvalidArgument: Error because the
alarm datetime format is incorrect kStatus_Fail: Error because the alarm time has already passed
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Returns
The enabled interrupts. This is the logical OR of members of the enumeration rtc_interrupt_enable_t
Parameters
Returns
The status flags. This is the logical OR of members of the enumeration rtc_status_flags_t
Parameters
After calling this function, the timer counter increments once a second provided SR[TOF] or SR[TIF] are
not set.
Parameters
RTC’s seconds register can be written to only when the timer is stopped.
Parameters
This resets all RTC registers to their reset value. The bit is cleared by software explicitly clearing it.
Parameters
The function SCTIMER_Init() initializes the SCTimer with specified configurations. The function SCTI-
MER_GetDefaultConfig() gets the default configurations.
The function SCTIMER_Deinit() halts the SCTimer counter and turns off the module clock.
The function SCTIMER_SetupPwm() sets up SCTimer channels for PWM output. The function can set
up the PWM signal properties duty cycle and level-mode (active low or high) to use. However, the same
PWM period and PWM mode (edge or center-aligned) is applied to all channels requesting the PWM
output. The signal duty cycle is provided as a percentage of the PWM period. Its value should be between
1 and 100.
The function SCTIMER_UpdatePwmDutycycle() updates the PWM signal duty cycle of a particular SC-
Timer channel.
34.2.3 Status
34.2.4 Interrupt
Provides functions to enable/disable SCTimer interrupts and get current enabled interrupts.
The user can create an event and enable it in the current state using the functions SCTIMER_Create-
AndScheduleEvent() and SCTIMER_ScheduleEvent(). SCTIMER_CreateAndScheduleEvent() creates a
new event based on the users preference and enables it in the current state. SCTIMER_ScheduleEvent()
enables an event created earlier in the current state.
The user can get the current state number by calling SCTIMER_GetCurrentState(), he can use this state
number to set state transitions when a particular event is triggered.
Once the user has created and enabled events for the current state he can go to the next state by calling
the function SCTIMER_IncreaseState(). The user can then start creating events to be enabled in this new
state.
There are a set of functions that decide what action should be taken when an event is triggered. SCTIMER-
_SetupCaptureAction() sets up which counter to capture and which capture register to read on event trigger.
SCTIMER_SetupNextStateAction() sets up which state the SCTimer state machine should transition to
on event trigger. SCTIMER_SetupOutputSetAction() sets up which pin to set on event trigger. SCTI-
MER_SetupOutputClearAction() sets up which pin to clear on event trigger. SCTIMER_SetupOutput-
ToggleAction() sets up which pin to toggle on event trigger. SCTIMER_SetupCounterLimitAction() sets
up which counter will be limited on event trigger. SCTIMER_SetupCounterStopAction() sets up which
counter will be stopped on event trigger. SCTIMER_SetupCounterStartAction() sets up which counter will
be started on event trigger. SCTIMER_SetupCounterHaltAction() sets up which counter will be halted on
event trigger. SCTIMER_SetupDmaTriggerAction() sets up which DMA request will be activated on
event trigger.
sctimerClock = CLOCK_GetFreq(kCLOCK_BusClk);
SCTIMER_GetDefaultConfig(&sctimerInfo);
/* Configure second PWM with different duty cycle but same frequency as before */
pwmParam.output = kSCTIMER_Out_2;
pwmParam.level = kSCTIMER_LowTrue;
pwmParam.dutyCyclePercent = 20;
if (SCTIMER_SetupPwm(SCT0, &pwmParam,
kSCTIMER_CenterAlignedPwm, 24000U, sctimerClock, &event) == kStatus_Fail)
{
return -1;
}
while (1)
{
}
}
Files
• file fsl_sctimer.h
Data Structures
• struct sctimer_pwm_signal_param_t
Options to configure a SCTimer PWM signal. More...
• struct sctimer_config_t
SCTimer configuration structure. More...
Typedefs
• typedef void(∗ sctimer_event_callback_t )(void)
SCTimer callback typedef.
Enumerations
• enum sctimer_pwm_mode_t {
kSCTIMER_EdgeAlignedPwm = 0U,
kSCTIMER_CenterAlignedPwm }
SCTimer PWM operation modes.
• enum sctimer_counter_t {
kSCTIMER_Counter_L = 0U,
kSCTIMER_Counter_H }
SCTimer counters when working as two independent 16-bit counters.
• enum sctimer_input_t {
kSCTIMER_Input_0 = 0U,
kSCTIMER_Input_1,
kSCTIMER_Input_2,
kSCTIMER_Input_3,
kSCTIMER_Input_4,
kSCTIMER_Input_5,
kSCTIMER_Input_6,
kSCTIMER_Input_7 }
List of SCTimer input pins.
• enum sctimer_out_t {
kSCTIMER_Out_0 = 0U,
kSCTIMER_Out_1,
kSCTIMER_Out_2,
kSCTIMER_Out_3,
kSCTIMER_Out_4,
kSCTIMER_Out_5,
kSCTIMER_Out_6,
kSCTIMER_Out_7 }
List of SCTimer output pins.
• enum sctimer_pwm_level_select_t {
kSCTIMER_LowTrue = 0U,
kSCTIMER_HighTrue }
SCTimer PWM output pulse mode: high-true, low-true or no output.
• enum sctimer_clock_mode_t {
kSCTIMER_System_ClockMode = 0U,
kSCTIMER_Sampled_ClockMode,
kSCTIMER_Input_ClockMode,
kSCTIMER_Asynchronous_ClockMode }
SCTimer clock mode options.
• enum sctimer_clock_select_t {
kSCTIMER_Clock_On_Rise_Input_0 = 0U,
kSCTIMER_Clock_On_Fall_Input_0,
kSCTIMER_Clock_On_Rise_Input_1,
kSCTIMER_Clock_On_Fall_Input_1,
kSCTIMER_Clock_On_Rise_Input_2,
kSCTIMER_Clock_On_Fall_Input_2,
kSCTIMER_Clock_On_Rise_Input_3,
kSCTIMER_Clock_On_Fall_Input_3,
kSCTIMER_Clock_On_Rise_Input_4,
kSCTIMER_Clock_On_Fall_Input_4,
kSCTIMER_Clock_On_Rise_Input_5,
kSCTIMER_Clock_On_Fall_Input_5,
kSCTIMER_Clock_On_Rise_Input_6,
kSCTIMER_Clock_On_Fall_Input_6,
kSCTIMER_Clock_On_Rise_Input_7,
kSCTIMER_Clock_On_Fall_Input_7 }
SCTimer clock select options.
• enum sctimer_conflict_resolution_t {
kSCTIMER_ResolveNone = 0U,
kSCTIMER_ResolveSet,
kSCTIMER_ResolveClear,
kSCTIMER_ResolveToggle }
SCTimer output conflict resolution options.
• enum sctimer_event_t
List of SCTimer event types.
• enum sctimer_interrupt_enable_t {
kSCTIMER_Event0InterruptEnable = (1U << 0),
kSCTIMER_Event1InterruptEnable = (1U << 1),
kSCTIMER_Event2InterruptEnable = (1U << 2),
kSCTIMER_Event3InterruptEnable = (1U << 3),
kSCTIMER_Event4InterruptEnable = (1U << 4),
kSCTIMER_Event5InterruptEnable = (1U << 5),
kSCTIMER_Event6InterruptEnable = (1U << 6),
kSCTIMER_Event7InterruptEnable = (1U << 7),
kSCTIMER_Event8InterruptEnable = (1U << 8),
kSCTIMER_Event9InterruptEnable = (1U << 9),
kSCTIMER_Event10InterruptEnable = (1U << 10),
kSCTIMER_Event11InterruptEnable = (1U << 11),
kSCTIMER_Event12InterruptEnable = (1U << 12) }
List of SCTimer interrupts.
• enum sctimer_status_flags_t {
kSCTIMER_Event0Flag = (1U << 0),
kSCTIMER_Event1Flag = (1U << 1),
kSCTIMER_Event2Flag = (1U << 2),
kSCTIMER_Event3Flag = (1U << 3),
kSCTIMER_Event4Flag = (1U << 4),
kSCTIMER_Event5Flag = (1U << 5),
kSCTIMER_Event6Flag = (1U << 6),
kSCTIMER_Event7Flag = (1U << 7),
kSCTIMER_Event8Flag = (1U << 8),
kSCTIMER_Event9Flag = (1U << 9),
kSCTIMER_Event10Flag = (1U << 10),
kSCTIMER_Event11Flag = (1U << 11),
kSCTIMER_Event12Flag = (1U << 12),
kSCTIMER_BusErrorLFlag,
kSCTIMER_BusErrorHFlag }
List of SCTimer flags.
Driver version
• #define FSL_SCTIMER_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Version 2.0.0.
Interrupt Interface
• static void SCTIMER_EnableInterrupts (SCT_Type ∗base, uint32_t mask)
Enables the selected SCTimer interrupts.
• static void SCTIMER_DisableInterrupts (SCT_Type ∗base, uint32_t mask)
Disables the selected SCTimer interrupts.
Status Interface
• static uint32_t SCTIMER_GetStatusFlags (SCT_Type ∗base)
Gets the SCTimer status flags.
• static void SCTIMER_ClearStatusFlags (SCT_Type ∗base, uint32_t mask)
Clears the SCTimer status flags.
Data Fields
• sctimer_out_t output
The output pin to use to generate the PWM signal.
• sctimer_pwm_level_select_t level
PWM output active level select.
• uint8_t dutyCyclePercent
PWM pulse width, value should be between 1 to 100 100 = always active signal (100% duty cycle).
This structure holds the configuration settings for the SCTimer peripheral. To initialize this structure to
reasonable defaults, call the SCTMR_GetDefaultConfig() function and pass a pointer to the configuration
structure instance.
The configuration structure can be made constant so as to reside in flash.
Data Fields
• bool enableCounterUnify
true: SCT operates as a unified 32-bit counter; false: SCT operates as two 16-bit counters
• sctimer_clock_mode_t clockMode
SCT clock mode value.
• sctimer_clock_select_t clockSelect
SCT clock select value.
• bool enableBidirection_l
true: Up-down count mode for the L or unified counter false: Up count mode only for the L or unified
counter
• bool enableBidirection_h
true: Up-down count mode for the H or unified counter false: Up count mode only for the H or unified
counter.
• uint8_t prescale_l
Prescale value to produce the L or unified counter clock.
• uint8_t prescale_h
Prescale value to produce the H counter clock.
• uint8_t outInitState
Defines the initial output value.
Enumerator
kSCTIMER_EdgeAlignedPwm Edge-aligned PWM.
kSCTIMER_CenterAlignedPwm Center-aligned PWM.
Enumerator
kSCTIMER_Counter_L Counter L.
kSCTIMER_Counter_H Counter H.
Enumerator
kSCTIMER_Input_0 SCTIMER input 0.
kSCTIMER_Input_1 SCTIMER input 1.
kSCTIMER_Input_2 SCTIMER input 2.
kSCTIMER_Input_3 SCTIMER input 3.
kSCTIMER_Input_4 SCTIMER input 4.
kSCTIMER_Input_5 SCTIMER input 5.
kSCTIMER_Input_6 SCTIMER input 6.
kSCTIMER_Input_7 SCTIMER input 7.
Enumerator
kSCTIMER_Out_0 SCTIMER output 0.
kSCTIMER_Out_1 SCTIMER output 1.
kSCTIMER_Out_2 SCTIMER output 2.
kSCTIMER_Out_3 SCTIMER output 3.
kSCTIMER_Out_4 SCTIMER output 4.
kSCTIMER_Out_5 SCTIMER output 5.
kSCTIMER_Out_6 SCTIMER output 6.
kSCTIMER_Out_7 SCTIMER output 7.
Enumerator
kSCTIMER_LowTrue Low true pulses.
kSCTIMER_HighTrue High true pulses.
Enumerator
kSCTIMER_System_ClockMode System Clock Mode.
kSCTIMER_Sampled_ClockMode Sampled System Clock Mode.
kSCTIMER_Input_ClockMode SCT Input Clock Mode.
kSCTIMER_Asynchronous_ClockMode Asynchronous Mode.
Enumerator
kSCTIMER_Clock_On_Rise_Input_0 Rising edges on input 0.
kSCTIMER_Clock_On_Fall_Input_0 Falling edges on input 0.
kSCTIMER_Clock_On_Rise_Input_1 Rising edges on input 1.
kSCTIMER_Clock_On_Fall_Input_1 Falling edges on input 1.
kSCTIMER_Clock_On_Rise_Input_2 Rising edges on input 2.
kSCTIMER_Clock_On_Fall_Input_2 Falling edges on input 2.
kSCTIMER_Clock_On_Rise_Input_3 Rising edges on input 3.
kSCTIMER_Clock_On_Fall_Input_3 Falling edges on input 3.
kSCTIMER_Clock_On_Rise_Input_4 Rising edges on input 4.
kSCTIMER_Clock_On_Fall_Input_4 Falling edges on input 4.
kSCTIMER_Clock_On_Rise_Input_5 Rising edges on input 5.
kSCTIMER_Clock_On_Fall_Input_5 Falling edges on input 5.
kSCTIMER_Clock_On_Rise_Input_6 Rising edges on input 6.
kSCTIMER_Clock_On_Fall_Input_6 Falling edges on input 6.
kSCTIMER_Clock_On_Rise_Input_7 Rising edges on input 7.
kSCTIMER_Clock_On_Fall_Input_7 Falling edges on input 7.
Specifies what action should be taken if multiple events dictate that a given output should be both set and
cleared at the same time
Enumerator
kSCTIMER_ResolveNone No change.
kSCTIMER_ResolveSet Set output.
kSCTIMER_ResolveClear Clear output.
kSCTIMER_ResolveToggle Toggle output.
Enumerator
kSCTIMER_Event0InterruptEnable Event 0 interrupt.
kSCTIMER_Event1InterruptEnable Event 1 interrupt.
kSCTIMER_Event2InterruptEnable Event 2 interrupt.
kSCTIMER_Event3InterruptEnable Event 3 interrupt.
kSCTIMER_Event4InterruptEnable Event 4 interrupt.
kSCTIMER_Event5InterruptEnable Event 5 interrupt.
Enumerator
kSCTIMER_Event0Flag Event 0 Flag.
kSCTIMER_Event1Flag Event 1 Flag.
kSCTIMER_Event2Flag Event 2 Flag.
kSCTIMER_Event3Flag Event 3 Flag.
kSCTIMER_Event4Flag Event 4 Flag.
kSCTIMER_Event5Flag Event 5 Flag.
kSCTIMER_Event6Flag Event 6 Flag.
kSCTIMER_Event7Flag Event 7 Flag.
kSCTIMER_Event8Flag Event 8 Flag.
kSCTIMER_Event9Flag Event 9 Flag.
kSCTIMER_Event10Flag Event 10 Flag.
kSCTIMER_Event11Flag Event 11 Flag.
kSCTIMER_Event12Flag Event 12 Flag.
kSCTIMER_BusErrorLFlag Bus error due to write when L counter was not halted.
kSCTIMER_BusErrorHFlag Bus error due to write when H counter was not halted.
Note
This API should be called at the beginning of the application using the SCTimer driver.
Parameters
Returns
kStatus_Success indicates success; Else indicates failure.
Parameters
* config->enableCounterUnify = true;
* config->clockMode = kSCTIMER_System_ClockMode;
* config->clockSelect = kSCTIMER_Clock_On_Rise_Input_0;
* config->enableBidirection_l = false;
* config->enableBidirection_h = false;
* config->prescale_l = 0;
* config->prescale_h = 0;
* config->outInitState = 0;
*
Parameters
Call this function to configure the PWM signal period, mode, duty cycle, and edge. This function will
create 2 events; one of the events will trigger on match with the pulse value and the other will trigger
when the counter matches the PWM period. The PWM period event is also used as a limit event to reset
the counter or change direction. Both events are enabled for the same state. The state number can be
retrieved by calling the function SCTIMER_GetCurrentStateNumber(). The counter is set to operate as
one 32-bit counter (unify bit is set to 1). The counter operates in bi-directional mode when generating a
center-aligned PWM.
Note
When setting PWM output from multiple output pins, they all should use the same PWM mode i.e
all PWM’s should be either edge-aligned or center-aligned.
Parameters
Returns
kStatus_Success on success kStatus_Fail If we have hit the limit in terms of number of events created
or if an incorrect PWM dutycylce is passed in.
Parameters
Parameters
Parameters
Parameters
Returns
The enabled interrupts. This is the logical OR of members of the enumeration sctimer_interrupt_-
enable_t
Parameters
Returns
The status flags. This is the logical OR of members of the enumeration sctimer_status_flags_t
Parameters
Parameters
Parameters
This function will configure an event using the options provided by the user. If the event type uses the
counter match, then the function will set the user provided match value into a match register and put this
match register number into the event control register. The event is enabled for the current state and the
event number is increased by one at the end. The function returns the event number; this event number
can be used to configure actions to be done when this event is triggered.
Parameters
Returns
kStatus_Success on success kStatus_Error if we have hit the limit in terms of number of events
created or if we have reached the limit in terms of number of match registers
This function will allow the event passed in to trigger in the current state. The event must be created earlier
by either calling the function SCTIMER_SetupPwm() or function SCTIMER_CreateAndScheduleEvent()
.
Parameters
All future events created by calling the function SCTIMER_ScheduleEvent() will be enabled in this new
state.
Parameters
Returns
kStatus_Success on success kStatus_Error if we have hit the limit in terms of states used
User can use this to set the next state by calling the function SCTIMER_SetupNextStateAction().
Parameters
Returns
The current state
Parameters
Returns
kStatus_Success on success kStatus_Error if we have hit the limit in terms of number of
match/capture registers available
If the interrupt for the event is enabled by the user, then a callback can be registered which will be invoked
when the event is triggered
Parameters
This transition will be triggered by the event number that is passed in by the user.
Parameters
This output will be set when the event number that is passed in by the user is triggered.
Parameters
This output will be cleared when the event number that is passed in by the user is triggered.
Parameters
This change in the output level is triggered by the event number that is passed in by the user.
Parameters
The counter is limited when the event number that is passed in by the user is triggered.
Parameters
The counter is stopped when the event number that is passed in by the user is triggered.
Parameters
The counter will re-start when the event number that is passed in by the user is triggered.
Parameters
The counter is disabled (halted) when the event number that is passed in by the user is triggered. When
the counter is halted, all further events are disabled. The HALT condition can only be removed by calling
the SCTIMER_StartTimer() function.
Parameters
DMA request will be triggered by the event number that is passed in by the user.
Parameters
Parameters
sdif_handle_t handle;
SDIF_TransferCreateHandle(base, &handle, &callback, &userData);
Data Structures
• struct sdif_dma_descriptor_t
define the internal DMA descriptor More...
• struct sdif_dma_config_t
Defines the internal DMA config structure. More...
• struct sdif_data_t
Card data descriptor. More...
• struct sdif_command_t
Card command descriptor. More...
• struct sdif_transfer_t
Transfer state. More...
• struct sdif_config_t
Data structure to initialize the sdif. More...
• struct sdif_capability_t
SDIF capability information. More...
• struct sdif_transfer_callback_t
sdif callback functions. More...
• struct sdif_handle_t
sdif handle More...
• struct sdif_host_t
sdif host descriptor More...
Macros
• #define SDIF_DriverIRQHandler SDIO_DriverIRQHandler
convert the name here, due to RM use SDIO
• #define SDIF_SUPPORT_SD_VERSION (0x20)
define the controller support sd/sdio card version 2.0
• #define SDIF_SUPPORT_MMC_VERSION (0x44)
define the controller support mmc card version 4.4
• #define SDIF_TIMEOUT_VALUE (65535U)
define the timeout counter
• #define SDIF_POLL_DEMAND_VALUE (0xFFU)
this value can be any value
• #define SDIF_DMA_DESCRIPTOR_BUFFER1_SIZE(x) (x & 0x1FFFU)
DMA descriptor buffer1 size.
• #define SDIF_DMA_DESCRIPTOR_BUFFER2_SIZE(x) ((x & 0x1FFFU) << 13U)
DMA descriptor buffer2 size.
• #define SDIF_RX_WATERMARK (15U)
RX water mark value.
• #define SDIF_TX_WATERMARK (16U)
TX water mark value.
• #define SDIF_INDENTIFICATION_MODE_SAMPLE_DELAY (0X17U)
SDIOCLKCTRL setting below clock delay setting should meet you board layout user can change it when
you meet timing mismatch issue such as: response error/CRC error and so on.
Typedefs
• typedef status_t(∗ sdif_transfer_function_t )(SDIF_Type ∗base, sdif_transfer_t ∗content)
sdif transfer function.
Enumerations
• enum _sdif_status {
kStatus_SDIF_DescriptorBufferLenError = MAKE_STATUS(kStatusGroup_SDIF, 0U),
kStatue_SDIF_InvalidArgument = MAKE_STATUS(kStatusGroup_SDIF, 1U),
kStatus_SDIF_SyncCmdTimeout = MAKE_STATUS(kStatusGroup_SDIF, 2U) }
SDIF status.
• enum _sdif_capability_flag {
kSDIF_SupportHighSpeedFlag = 0x1U,
kSDIF_SupportDmaFlag = 0x2U,
kSDIF_SupportSuspendResumeFlag = 0x4U,
kSDIF_SupportV330Flag = 0x8U,
kSDIF_Support4BitFlag = 0x10U,
kSDIF_Support8BitFlag = 0x20U }
Host controller capabilities flag mask.
• enum _sdif_reset_type {
kSDIF_ResetController,
kSDIF_ResetFIFO = SDIF_CTRL_FIFO_RESET_MASK,
kSDIF_ResetDMAInterface = SDIF_CTRL_DMA_RESET_MASK,
kSDIF_ResetAll }
define the reset type
• enum sdif_bus_width_t {
kSDIF_Bus1BitWidth = 0U,
kSDIF_Bus4BitWidth = SDIF_CTYPE_CARD_WIDTH0_MASK,
kSDIF_Bus8BitWidth = SDIF_CTYPE_CARD_WIDTH1_MASK }
define the card bus width type
• enum _sdif_command_flags {
kSDIF_CmdResponseExpect = SDIF_CMD_RESPONSE_EXPECT_MASK,
kSDIF_CmdResponseLengthLong = SDIF_CMD_RESPONSE_LENGTH_MASK,
kSDIF_CmdCheckResponseCRC = SDIF_CMD_CHECK_RESPONSE_CRC_MASK,
kSDIF_DataExpect = SDIF_CMD_DATA_EXPECTED_MASK,
kSDIF_DataWriteToCard = SDIF_CMD_READ_WRITE_MASK,
kSDIF_DataStreamTransfer = SDIF_CMD_TRANSFER_MODE_MASK,
kSDIF_DataTransferAutoStop = SDIF_CMD_SEND_AUTO_STOP_MASK,
kSDIF_WaitPreTransferComplete,
kSDIF_TransferStopAbort,
kSDIF_SendInitialization,
kSDIF_CmdUpdateClockRegisterOnly,
kSDIF_CmdtoReadCEATADevice = SDIF_CMD_READ_CEATA_DEVICE_MASK,
kSDIF_CmdExpectCCS = SDIF_CMD_CCS_EXPECTED_MASK,
kSDIF_BootModeEnable = SDIF_CMD_ENABLE_BOOT_MASK,
kSDIF_BootModeExpectAck = SDIF_CMD_EXPECT_BOOT_ACK_MASK,
kSDIF_BootModeDisable = SDIF_CMD_DISABLE_BOOT_MASK,
kSDIF_BootModeAlternate = SDIF_CMD_BOOT_MODE_MASK,
kSDIF_CmdVoltageSwitch = SDIF_CMD_VOLT_SWITCH_MASK,
kSDIF_CmdDataUseHoldReg = SDIF_CMD_USE_HOLD_REG_MASK }
define the command flags
• enum _sdif_command_type {
kCARD_CommandTypeNormal = 0U,
kCARD_CommandTypeSuspend = 1U,
kCARD_CommandTypeResume = 2U,
kCARD_CommandTypeAbort = 3U }
The command type.
• enum _sdif_response_type {
kCARD_ResponseTypeNone = 0U,
kCARD_ResponseTypeR1 = 1U,
kCARD_ResponseTypeR1b = 2U,
kCARD_ResponseTypeR2 = 3U,
kCARD_ResponseTypeR3 = 4U,
kCARD_ResponseTypeR4 = 5U,
kCARD_ResponseTypeR5 = 6U,
kCARD_ResponseTypeR5b = 7U,
kCARD_ResponseTypeR6 = 8U,
kCARD_ResponseTypeR7 = 9U }
The command response type.
• enum _sdif_interrupt_mask {
kSDIF_CardDetect = SDIF_INTMASK_CDET_MASK,
kSDIF_ResponseError = SDIF_INTMASK_RE_MASK,
kSDIF_CommandDone = SDIF_INTMASK_CDONE_MASK,
kSDIF_DataTransferOver = SDIF_INTMASK_DTO_MASK,
kSDIF_WriteFIFORequest = SDIF_INTMASK_TXDR_MASK,
kSDIF_ReadFIFORequest = SDIF_INTMASK_RXDR_MASK,
kSDIF_ResponseCRCError = SDIF_INTMASK_RCRC_MASK,
kSDIF_DataCRCError = SDIF_INTMASK_DCRC_MASK,
kSDIF_ResponseTimeout = SDIF_INTMASK_RTO_MASK,
kSDIF_DataReadTimeout = SDIF_INTMASK_DRTO_MASK,
kSDIF_DataStarvationByHostTimeout = SDIF_INTMASK_HTO_MASK,
kSDIF_FIFOError = SDIF_INTMASK_FRUN_MASK,
kSDIF_HardwareLockError = SDIF_INTMASK_HLE_MASK,
kSDIF_DataStartBitError = SDIF_INTMASK_SBE_MASK,
kSDIF_AutoCmdDone = SDIF_INTMASK_ACD_MASK,
kSDIF_DataEndBitError = SDIF_INTMASK_EBE_MASK,
kSDIF_SDIOInterrupt = SDIF_INTMASK_SDIO_INT_MASK_MASK,
kSDIF_CommandTransferStatus,
kSDIF_DataTransferStatus ,
kSDIF_AllInterruptStatus = 0x1FFFFU }
define the interrupt mask flags
• enum _sdif_dma_status {
kSDIF_DMATransFinishOneDescriptor = SDIF_IDSTS_TI_MASK,
kSDIF_DMARecvFinishOneDescriptor = SDIF_IDSTS_RI_MASK,
kSDIF_DMAFatalBusError = SDIF_IDSTS_FBE_MASK,
kSDIF_DMADescriptorUnavailable = SDIF_IDSTS_DU_MASK,
kSDIF_DMACardErrorSummary = SDIF_IDSTS_CES_MASK,
kSDIF_NormalInterruptSummary = SDIF_IDSTS_NIS_MASK,
kSDIF_AbnormalInterruptSummary = SDIF_IDSTS_AIS_MASK }
define the internal DMA status flags
• enum _sdif_dma_descriptor_flag {
kSDIF_DisableCompleteInterrupt = 0x2U,
kSDIF_DMADescriptorDataBufferEnd = 0x4U,
kSDIF_DMADescriptorDataBufferStart = 0x8U,
kSDIF_DMASecondAddrChained = 0x10U,
kSDIF_DMADescriptorEnd = 0x20U,
kSDIF_DMADescriptorOwnByDMA = 0x80000000U }
define the internal DMA descriptor flag
• enum sdif_dma_mode_t
define the internal DMA mode
• enum _sdif_card_freq {
kSDIF_Freq50MHZ = 50000000U,
kSDIF_Freq400KHZ = 400000U }
define the card work freq mode
• enum _sdif_clock_pharse_shift {
kSDIF_ClcokPharseShift0,
kSDIF_ClcokPharseShift90,
kSDIF_ClcokPharseShift180,
kSDIF_ClcokPharseShift270 }
define the clock pharse shift
Functions
• void SDIF_Init (SDIF_Type ∗base, sdif_config_t ∗config)
SDIF module initialization function.
• void SDIF_Deinit (SDIF_Type ∗base)
SDIF module deinit function.
• bool SDIF_SendCardActive (SDIF_Type ∗base, uint32_t timeout)
SDIF send initialize 80 clocks for SD card after initilize.
• static uint32_t SDIF_DetectCardInsert (SDIF_Type ∗base, bool data3)
SDIF module detect card insert status function.
• static void SDIF_EnableCardClock (SDIF_Type ∗base, bool enable)
SDIF module enable/disable card clock.
• static void SDIF_EnableLowPowerMode (SDIF_Type ∗base, bool enable)
SDIF module enable/disable module disable the card clock to enter low power mode when card is idle,for
SDIF cards, if interrupts must be detected, clock should not be stopped.
• uint32_t SDIF_SetCardClock (SDIF_Type ∗base, uint32_t srcClock_Hz, uint32_t target_HZ)
Sets the card bus clock frequency.
• bool SDIF_Reset (SDIF_Type ∗base, uint32_t mask, uint32_t timeout)
reset the different block of the interface.
• static void SDIF_EnableCardPower (SDIF_Type ∗base, bool enable)
enable/disable the card power.
• static uint32_t SDIF_GetCardWriteProtect (SDIF_Type ∗base)
get the card write protect status
• static void SDIF_SetCardBusWidth (SDIF_Type ∗base, sdif_bus_width_t type)
set card data bus width
• static void SDIF_AssertHardwareReset (SDIF_Type ∗base)
toggle state on hardware reset PIN This is used which card has a reset PIN typically.
• status_t SDIF_SendCommand (SDIF_Type ∗base, sdif_command_t ∗cmd, uint32_t timeout)
send command to the card
• static void SDIF_EnableGlobalInterrupt (SDIF_Type ∗base, bool enable)
SDIF enable/disable global interrupt.
• static void SDIF_EnableInterrupt (SDIF_Type ∗base, uint32_t mask)
SDIF enable interrupt.
• static void SDIF_DisableInterrupt (SDIF_Type ∗base, uint32_t mask)
SDIF disable interrupt.
• static uint32_t SDIF_GetInterruptStatus (SDIF_Type ∗base)
SDIF get interrupt status.
• static void SDIF_ClearInterruptStatus (SDIF_Type ∗base, uint32_t mask)
SDIF clear interrupt status.
• void SDIF_TransferCreateHandle (SDIF_Type ∗base, sdif_handle_t ∗handle, sdif_transfer_-
callback_t ∗callback, void ∗userData)
Creates the SDIF handle.
• static void SDIF_EnableDmaInterrupt (SDIF_Type ∗base, uint32_t mask)
SDIF enable DMA interrupt.
• static void SDIF_DisableDmaInterrupt (SDIF_Type ∗base, uint32_t mask)
Driver version
• #define FSL_SDIF_DRIVER_VERSION (MAKE_VERSION(2U, 0U, 0U))
Driver version 2.0.0.
Data Fields
• uint32_t dmaDesAttribute
Data Fields
• bool enableFixBurstLen
fix burst len enable/disable flag,When set, the AHB will
use only SINGLE, INCR4, INCR8 or INCR16 during start of normal burst transfers.
• sdif_dma_mode_t mode
define the DMA mode
• uint8_t dmaDesSkipLen
define the descriptor skip length ,the length between two descriptor this field is special for dual DMA mode
• uint32_t ∗ dmaDesBufferStartAddr
internal DMA descriptor start address
• uint32_t dmaDesBufferLen
internal DMA buffer descriptor buffer len ,user need to pay attention to the dma descriptor buffer length
if it is bigger enough for your transfer
When reset, the AHB will use SINGLE and INCR burst transfer operations
Data Fields
• bool streamTransfer
indicate this is a stream data transfer command
• bool enableAutoCommand12
indicate if auto stop will send when data transfer over
• bool enableIgnoreError
indicate if enable ignore error when transfer data
• size_t blockSize
Block size, take care when config this parameter.
• uint32_t blockCount
Block count.
• uint32_t ∗ rxData
data buffer to recieve
Data Fields
• uint32_t index
Command index.
• uint32_t argument
Command argument.
• uint32_t response [4U]
Response for this command.
• uint32_t type
define the command type
• uint32_t responseType
Command response type.
• uint32_t flags
Cmd flags.
• uint32_t responseErrorFlags
response error flags, need to check the flags when recieve the cmd response
Data Fields
• sdif_data_t ∗ data
Data to transfer.
• sdif_command_t ∗ command
Command to send.
Data Fields
• uint8_t responseTimeout
command reponse timeout value
• uint32_t cardDetDebounce_Clock
define the debounce clock count which will used in card detect logic,typical value is 5-25ms
• uint32_t endianMode
define endian mode ,this field is not used in this
module actually, keep for compatible with middleware
• uint32_t dataTimeout
data timeout value
Data Fields
• uint32_t sdVersion
support SD card/sdio version
• uint32_t mmcVersion
support emmc card version
• uint32_t maxBlockLength
Maximum block length united as byte.
• uint32_t maxBlockCount
Maximum byte count can be transfered.
• uint32_t flags
Capability flags to indicate the support information.
Data Fields
Defines the structure to save the sdif state information and callback function. The detail interrupt status
when send command or transfer data can be obtained from interruptFlags field by using mask defined in
sdif_interrupt_flag_t;
Note
All the fields except interruptFlags and transferredWords must be allocated by the user.
Data Fields
Data Fields
• SDIF_Type ∗ base
sdif peripheral base address
• uint32_t sourceClock_Hz
sdif source clock frequency united in Hz
• sdif_config_t config
sdif configuration
• sdif_transfer_function_t transfer
sdif transfer function
• sdif_capability_t capability
sdif capability information
Enumerator
kStatus_SDIF_DescriptorBufferLenError Set DMA descriptor failed.
Enumerator
kSDIF_SupportHighSpeedFlag Support high-speed.
kSDIF_SupportDmaFlag Support DMA.
kSDIF_SupportSuspendResumeFlag Support suspend/resume.
kSDIF_SupportV330Flag Support voltage 3.3V.
kSDIF_Support4BitFlag Support 4 bit mode.
kSDIF_Support8BitFlag Support 8 bit mode.
Enumerator
kSDIF_ResetController reset controller,will reset: BIU/CIU interface CIU and state machine,AB-
ORT_READ_DATA,SEND_IRQ_RESPONSE and READ_WAIT bits of control register,STA-
RT_CMD bit of the command register
kSDIF_ResetFIFO reset data FIFO
kSDIF_ResetDMAInterface reset DMA interface
kSDIF_ResetAll reset all
Enumerator
kSDIF_Bus1BitWidth 1bit bus width, 1bit mode and 4bit mode share one register bit
kSDIF_Bus4BitWidth 4bit mode mask
kSDIF_Bus8BitWidth support 8 bit mode
Enumerator
kSDIF_CmdResponseExpect command request response
kSDIF_CmdResponseLengthLong command response length long
kSDIF_CmdCheckResponseCRC request check command response CRC
Enumerator
kCARD_CommandTypeNormal Normal command.
kCARD_CommandTypeSuspend Suspend command.
kCARD_CommandTypeResume Resume command.
kCARD_CommandTypeAbort Abort command.
Enumerator
kCARD_ResponseTypeNone Response type: none.
kCARD_ResponseTypeR1 Response type: R1.
kCARD_ResponseTypeR1b Response type: R1b.
kCARD_ResponseTypeR2 Response type: R2.
kCARD_ResponseTypeR3 Response type: R3.
kCARD_ResponseTypeR4 Response type: R4.
kCARD_ResponseTypeR5 Response type: R5.
kCARD_ResponseTypeR5b Response type: R5b.
Enumerator
kSDIF_CardDetect mask for card detect
kSDIF_ResponseError command response error
kSDIF_CommandDone command transfer over
kSDIF_DataTransferOver data transfer over flag
kSDIF_WriteFIFORequest write FIFO request
kSDIF_ReadFIFORequest read FIFO request
kSDIF_ResponseCRCError reponse CRC error
kSDIF_DataCRCError data CRC error
kSDIF_ResponseTimeout response timeout
kSDIF_DataReadTimeout read data timeout
kSDIF_DataStarvationByHostTimeout data starvation by host time out
kSDIF_FIFOError indicate the FIFO underrun or overrun error
kSDIF_HardwareLockError hardware lock write error
kSDIF_DataStartBitError start bit error
kSDIF_AutoCmdDone indicate the auto command done
kSDIF_DataEndBitError end bit error
kSDIF_SDIOInterrupt interrupt from the SDIO card
kSDIF_CommandTransferStatus command transfer status collection
kSDIF_DataTransferStatus data transfer status collection
kSDIF_AllInterruptStatus all interrupt mask
Enumerator
kSDIF_DMATransFinishOneDescriptor DMA transfer finished for one DMA descriptor.
kSDIF_DMARecvFinishOneDescriptor DMA revieve finished for one DMA descriptor.
kSDIF_DMAFatalBusError DMA fatal bus error.
kSDIF_DMADescriptorUnavailable DMA descriptor unavailable.
kSDIF_DMACardErrorSummary card error summary
kSDIF_NormalInterruptSummary normal interrupt summary
kSDIF_AbnormalInterruptSummary abnormal interrupt summary
Enumerator
kSDIF_DisableCompleteInterrupt disable the complete interrupt flag for the ends in the buffer
pointed to by this descriptor
kSDIF_DMADescriptorDataBufferEnd indicate this descriptor contain the last data buffer of data
kSDIF_DMADescriptorDataBufferStart indicate this descriptor contain the first data buffer of
data,if first buffer size is 0,next descriptor contain the begaining of the data
kSDIF_DMASecondAddrChained indicate that the second addr in the descriptor is the next descrip-
tor addr not the data buffer
kSDIF_DMADescriptorEnd indicate that the descriptor list reached its final descriptor
kSDIF_DMADescriptorOwnByDMA indicate the descriptor is own by SD/MMC DMA
Enumerator
kSDIF_Freq50MHZ 50MHZ mode
kSDIF_Freq400KHZ identificatioin mode
Enumerator
kSDIF_ClcokPharseShift0 clock pharse shift 0
kSDIF_ClcokPharseShift90 clock pharse shift 90
kSDIF_ClcokPharseShift180 clock pharse shift 180
kSDIF_ClcokPharseShift270 clock pharse shift 270
Parameters
Parameters
Parameters
Parameters
Parameters
Returns
The nearest frequency of busClock_Hz configured to SD bus.
Parameters
Returns
reset result.
once turn power on, software should wait for regulator/switch ramp-up time before trying to initialize card.
Parameters
Parameters
Parameters
Parameters
Parameters
Returns
command excute status
Parameters
Parameters
Parameters
Parameters
Parameters
register call back function for interrupt and enable the interrupt
Parameters
Parameters
Parameters
Parameters
Returns
the internal DMA status register
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Parameters
Data Structures
• struct spifi_command_t
SPIFI command structure. More...
• struct spifi_config_t
SPIFI region configuration structure. More...
• struct spifi_transfer_t
Transfer structure for SPIFI. More...
• struct spifi_dma_handle_t
SPIFI DMA transfer handle, users should not touch the content of the handle. More...
Typedefs
• typedef void(∗ spifi_dma_callback_t )(SPIFI_Type ∗base, spifi_dma_handle_t ∗handle, status_t sta-
tus, void ∗userData)
SPIFI DMA transfer callback function for finish and error.
Enumerations
• enum _status_t {
kStatus_SPIFI_Idle = MAKE_STATUS(kStatusGroup_SPIFI, 0),
kStatus_SPIFI_Busy = MAKE_STATUS(kStatusGroup_SPIFI, 1),
kStatus_SPIFI_Error = MAKE_STATUS(kStatusGroup_SPIFI, 2) }
Status structure of SPIFI.
• enum spifi_interrupt_enable_t { kSPIFI_CommandFinishInterruptEnable = SPIFI_CTRL_INTEN-
_MASK }
SPIFI interrupt source.
• enum spifi_spi_mode_t {
kSPIFI_SPISckLow = 0x0U,
kSPIFI_SPISckHigh = 0x1U }
SPIFI SPI mode select.
• enum spifi_dual_mode_t {
kSPIFI_QuadMode = 0x0U,
kSPIFI_DualMode = 0x1U }
SPIFI dual mode select.
• enum spifi_data_direction_t {
kSPIFI_DataInput = 0x0U,
kSPIFI_DataOutput = 0x1U }
SPIFI data direction.
• enum spifi_command_format_t {
kSPIFI_CommandAllSerial = 0x0,
kSPIFI_CommandDataQuad = 0x1U,
kSPIFI_CommandOpcodeSerial = 0x2U,
kSPIFI_CommandAllQuad = 0x3U }
SPIFI command opcode format.
• enum spifi_command_type_t {
kSPIFI_CommandOpcodeOnly = 0x1U,
kSPIFI_CommandOpcodeAddrOneByte = 0x2U,
kSPIFI_CommandOpcodeAddrTwoBytes = 0x3U,
kSPIFI_CommandOpcodeAddrThreeBytes = 0x4U,
kSPIFI_CommandOpcodeAddrFourBytes = 0x5U,
kSPIFI_CommandNoOpcodeAddrThreeBytes = 0x6U,
kSPIFI_CommandNoOpcodeAddrFourBytes = 0x7U }
SPIFI command type.
• enum _spifi_status_flags {
kSPIFI_MemoryCommandWriteFinished = SPIFI_STAT_MCINIT_MASK,
kSPIFI_CommandWriteFinished = SPIFI_STAT_CMD_MASK,
kSPIFI_InterruptRequest = SPIFI_STAT_INTRQ_MASK }
SPIFI status flags.
Functions
• static void SPIFI_EnableDMA (SPIFI_Type ∗base, bool enable)
Enable or disable DMA request for SPIFI.
• static uint32_t SPIFI_GetDataRegisterAddress (SPIFI_Type ∗base)
Gets the SPIFI data register address.
• static void SPIFI_WriteData (SPIFI_Type ∗base, uint32_t data)
Write a word data in address of SPIFI.
• static uint32_t SPIFI_ReadData (SPIFI_Type ∗base)
Read data from serial flash.
Driver version
• #define FSL_SPIFI_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
SPIFI driver version 2.0.0.
Status
• static uint32_t SPIFI_GetStatusFlag (SPIFI_Type ∗base)
Get the status of all interrupt flags for SPIFI.
DMA Transactional
• void SPIFI_TransferTxCreateHandleDMA (SPIFI_Type ∗base, spifi_dma_handle_t ∗handle, spifi-
_dma_callback_t callback, void ∗userData, dma_handle_t ∗dmaHandle)
Initializes the SPIFI handle for send which is used in transactional functions and set the callback.
• void SPIFI_TransferRxCreateHandleDMA (SPIFI_Type ∗base, spifi_dma_handle_t ∗handle, spifi-
_dma_callback_t callback, void ∗userData, dma_handle_t ∗dmaHandle)
Initializes the SPIFI handle for receive which is used in transactional functions and set the callback.
• status_t SPIFI_TransferSendDMA (SPIFI_Type ∗base, spifi_dma_handle_t ∗handle, spifi_transfer-
_t ∗xfer)
Transfers SPIFI data using an DMA non-blocking method.
• status_t SPIFI_TransferReceiveDMA (SPIFI_Type ∗base, spifi_dma_handle_t ∗handle, spifi_-
transfer_t ∗xfer)
Receives data using an DMA non-blocking method.
• void SPIFI_TransferAbortSendDMA (SPIFI_Type ∗base, spifi_dma_handle_t ∗handle)
Aborts the sent data using DMA.
• void SPIFI_TransferAbortReceiveDMA (SPIFI_Type ∗base, spifi_dma_handle_t ∗handle)
Aborts the receive data using DMA.
• status_t SPIFI_TransferGetSendCountDMA (SPIFI_Type ∗base, spifi_dma_handle_t ∗handle, size-
_t ∗count)
Gets the transferred counts of send.
• status_t SPIFI_TransferGetReceiveCountDMA (SPIFI_Type ∗base, spifi_dma_handle_t ∗handle,
size_t ∗count)
Gets the status of the receive transfer.
Data Fields
• uint16_t dataLen
How many data bytes are needed in this command.
• bool isPollMode
For command need to read data from serial flash.
• spifi_data_direction_t direction
Data direction of this command.
• uint8_t intermediateBytes
How many intermediate bytes needed.
• spifi_command_format_t format
Command format.
• spifi_command_type_t type
Command type.
• uint8_t opcode
Command opcode value.
Data Fields
• uint16_t timeout
SPI transfer timeout, the unit is SCK cycles.
• uint8_t csHighTime
CS high time cycles.
• bool disablePrefetch
True means SPIFI will not attempt a speculative prefetch.
• bool disableCachePrefech
Disable prefetch of cache line.
• bool isFeedbackClock
Is data sample uses feedback clock.
• spifi_spi_mode_t spiMode
SPIFI spi mode select.
• bool isReadFullClockCycle
If enable read full clock cycle.
• spifi_dual_mode_t dualMode
SPIFI dual mode, dual or quad.
Data Fields
• uint8_t ∗ data
Pointer to data to transmit.
• size_t dataSize
Bytes to be transmit.
Data Fields
• dma_handle_t ∗ dmaHandle
DMA handler for SPIFI send.
• size_t transferSize
Bytes need to transfer.
• uint32_t state
Internal state for SPIFI DMA transfer.
• spifi_dma_callback_t callback
Callback for users while transfer finish or error occurred.
• void ∗ userData
User callback parameter.
Enumerator
kStatus_SPIFI_Idle SPIFI is in idle state.
kStatus_SPIFI_Busy SPIFI is busy.
kStatus_SPIFI_Error Error occurred during SPIFI transfer.
Enumerator
kSPIFI_CommandFinishInterruptEnable Interrupt while command finished.
Enumerator
kSPIFI_SPISckLow SCK low after last bit of command, keeps low while CS high.
kSPIFI_SPISckHigh SCK high after last bit of command and while CS high.
Enumerator
kSPIFI_QuadMode SPIFI uses IO3:0.
kSPIFI_DualMode SPIFI uses IO1:0.
Enumerator
kSPIFI_DataInput Data input from serial flash.
kSPIFI_DataOutput Data output to serial flash.
Enumerator
kSPIFI_CommandAllSerial All fields of command are serial.
kSPIFI_CommandDataQuad Only data field is dual/quad, others are serial.
kSPIFI_CommandOpcodeSerial Only opcode field is serial, others are quad/dual.
kSPIFI_CommandAllQuad All fields of command are dual/quad mode.
Enumerator
kSPIFI_CommandOpcodeOnly Command only have opcode, no address field.
kSPIFI_CommandOpcodeAddrOneByte Command have opcode and also one byte address field.
kSPIFI_CommandOpcodeAddrTwoBytes Command have opcode and also two bytes address field.
Enumerator
kSPIFI_MemoryCommandWriteFinished Memory command write finished.
kSPIFI_CommandWriteFinished Command write finished.
kSPIFI_InterruptRequest CMD flag from 1 to 0, means command execute finished.
This function configures the SPIFI module with the user-defined configuration.
Parameters
Parameters
Parameters
Parameters
Parameters
Before writing a command wihch needs specific intermediate value, users shall call this function to write
it. The main use of this function for current serial flash is to select no-opcode mode and cancelling this
mode. As dummy cycle do not care about the value, no need to call this function.
Parameters
SPIFI includes caching of prevously-accessed data to improve performance. Software can write an address
to this function, to prevent such caching at and above the address.
Parameters
Call this function means SPIFI enters to memory mode, while users need to use command, a SPIFI_Reset-
Command shall be called.
Parameters
The interrupt is triggered only in command mode, and it means the command now is finished.
Parameters
The interrupt is triggered only in command mode, and it means the command now is finished.
Parameters
Parameters
Returns
SPIFI flag status
Parameters
This API is used to provide a transfer address for the SPIFI DMA transfer configuration.
Parameters
Returns
data register address
Users can write a page or at least a word data into SPIFI address.
Parameters
Users should notice before call this function, the data length field in command register shall larger than 4,
otherwise a hardfault will happen.
Parameters
Returns
Data input from flash.
Parameters
Parameters
This function writes data to the SPIFI transmit FIFO. This function is non-blocking.
Parameters
This function receive data from the SPIFI receive buffer/FIFO. This function is non-blocking.
Parameters
Parameters
Return values
Parameters
Return values
/* Write enable */
SPIFI_SetCommand(EXAMPLE_SPIFI, &command[WRITE_ENABLE]);
/* Set address */
SPIFI_SetCommandAddress(EXAMPLE_SPIFI, FSL_FEATURE_SPIFI_START_ADDRESS);
/* Erase sector */
SPIFI_SetCommand(EXAMPLE_SPIFI, &command[ERASE_SECTOR]);
/* Check if finished */
check_if_finish();
/* Program page */
/* Write enable */
SPIFI_SetCommand(EXAMPLE_SPIFI, &command[WRITE_ENABLE]);
/* Set address */
SPIFI_SetCommandAddress(EXAMPLE_SPIFI, FSL_FEATURE_SPIFI_START_ADDRESS);
/* Erase sector */
SPIFI_SetCommand(EXAMPLE_SPIFI, &command[ERASE_SECTOR]);
/* Check if finished */
check_if_finish();
/* Program page */
while (page < (SECTOR_SIZE/PAGE_SIZE))
{
SPIFI_SetCommand(EXAMPLE_SPIFI, &command[WRITE_ENABLE]);
SPIFI_SetCommandAddress(EXAMPLE_SPIFI, FSL_FEATURE_SPIFI_START_ADDRESS + page *
PAGE_SIZE);
SPIFI_SetCommand(EXAMPLE_SPIFI, &command[PROGRAM_PAGE]);
xfer.data = g_buffer;
xfer.dataSize = PAGE_SIZE;
SPIFI_TransferSendDMA(EXAMPLE_SPIFI, &handle, &xfer);
while (!finished)
{}
finished = false;
page ++;
check_if_finish();
}
Modules
• Clock driver
The SDK provides a peripheral clock driver for the SYSCON module of LPC devices.
SYSCON clock module provides clocks, such as MCLKCLK, ADCCLK, DMICCLK, MCGFLLCLK,
FXCOMCLK,WDTOSC, RTCOSC, USBCLK and SYSPLL. The functions CLOCK_EnableClock() and
CLOCK_DisableClock() enables and disables the various clocks. CLOCK_SetupFROClocking() initial-
izes the FRO to 12MHz, 48 MHz or 96 MHz frequency. CLOCK_SetupPLLData(), CLOCK_Setup-
SystemPLLPrec(), and CLOCK_SetPLLFreq() functions are used to setup the PLL. The SYSCON clock
driver provides functions to get the frequency of these clocks, such as CLOCK_GetFreq(), CLOCK_Get-
Fro12MFreq(), CLOCK_GetExtClkFreq(), CLOCK_GetWdtOscFreq(), CLOCK_GetFroHfFreq(), CLO-
CK_GetPllOutFreq(), CLOCK_GetOsc32KFreq() , CLOCK_GetCoreSysClkFreq(), CLOCK_GetI2SM-
ClkFreq(),CLOCK_GetFlexCommClkFreq and CLOCK_GetAsyncApbClkFreq.
The SYSCON clock driver provides the function to configure the clock selected. The function CLOCK_-
AttachClk() is implemented for this. The function selects the clock source for a particular peripheral like
MAINCLK, DMIC, FLEXCOMM, USB, ADC and PLL.
The SYSCON clock module provides the function to setup the peripheral clock dividers. The function
CLOCK_SetClkDiv() configures the CLKDIV registers for various periperals like USB, DMIC, I2S, SY-
STICK, AHB, ADC and also for CLKOUT and TRACE functions.
The SYSCON clock driver provides the function CLOCK_SetFLASHAccessCyclesForFreq() that config-
ures FLASHCFG register with a selected FLASHTIM value.
Files
• file fsl_clock.h
Data Structures
• struct pll_config_t
PLL configuration structure. More...
• struct pll_setup_t
PLL setup structure This structure can be used to pre-build a PLL setup configuration at run-time and
quickly set the PLL to the configuration. More...
• struct usb_pll_setup_t
PLL setup structure This structure can be used to pre-build a USB PLL setup configuration at run-time
and quickly set the usb PLL to the configuration. More...
Macros
• #define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0
Configure whether driver controls clock.
• #define ADC_CLOCKS
Clock ip name array for ROM.
• #define ROM_CLOCKS
Clock ip name array for ROM.
• #define SRAM_CLOCKS
Clock ip name array for SRAM.
• #define FLASH_CLOCKS
Clock ip name array for FLASH.
• #define FMC_CLOCKS
Clock ip name array for FMC.
• #define EEPROM_CLOCKS
Clock ip name array for EEPROM.
• #define SPIFI_CLOCKS
Clock ip name array for SPIFI.
• #define INPUTMUX_CLOCKS
Clock ip name array for INPUTMUX.
• #define IOCON_CLOCKS
• #define AES_CLOCKS
Clock ip name array for AES.
• #define OTP_CLOCKS
Clock ip name array for OTP.
• #define RNG_CLOCKS
Clock ip name array for RNG.
• #define USBHMR0_CLOCKS
Clock ip name array for USBHMR0.
• #define USBHSL0_CLOCKS
Clock ip name array for USBHSL0.
• #define SHA0_CLOCKS
Clock ip name array for SHA0.
• #define SMARTCARD_CLOCKS
Clock ip name array for SMARTCARD.
• #define USBD_CLOCKS
Clock ip name array for USBD.
• #define USBH_CLOCKS
Clock ip name array for USBH.
• #define CLK_GATE_REG_OFFSET_SHIFT 8U
Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock.
• #define MUX_A(m, choice) (((m) << 0) | ((choice + 1) << 8))
Clock Mux Switches The encoding is as follows each connection identified is 64bits wide starting from LSB
upwards.
• #define PLL_CONFIGFLAG_USEINRATE (1 << 0)
PLL configuration structure flags for ’flags’ field These flags control how the PLL configuration function
sets up the PLL setup structure.
• #define PLL_CONFIGFLAG_FORCENOFRACT
Force non-fractional output mode, PLL output will not use the fractional, automatic bandwidth, or SS \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ hardware.
• #define PLL_SETUPFLAG_POWERUP (1 << 0)
PLL setup structure flags for ’flags’ field These flags control how the PLL setup function sets up the PLL.
• #define PLL_SETUPFLAG_WAITLOCK (1 << 1)
Setup will wait for PLL lock, implies the PLL will be pwoered on.
• #define PLL_SETUPFLAG_ADGVOLT (1 << 2)
Optimize system voltage for the new PLL rate.
Enumerations
• enum clock_ip_name_t
Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock.
• enum clock_name_t {
kCLOCK_CoreSysClk,
kCLOCK_BusClk,
kCLOCK_ClockOut,
kCLOCK_FroHf,
kCLOCK_SpiFi,
kCLOCK_Adc,
kCLOCK_Usb0,
kCLOCK_Usb1,
kCLOCK_UsbPll,
kCLOCK_Mclk,
kCLOCK_Sct,
kCLOCK_SDio,
kCLOCK_EMC,
kCLOCK_LCD,
kCLOCK_MCAN0,
kCLOCK_MCAN1,
kCLOCK_Fro12M,
kCLOCK_ExtClk,
kCLOCK_PllOut,
kCLOCK_UsbClk,
kClock_WdtOsc,
kCLOCK_Frg,
kCLOCK_Dmic,
kCLOCK_AsyncApbClk,
kCLOCK_FlexI2S,
kCLOCK_Flexcomm0,
kCLOCK_Flexcomm1,
kCLOCK_Flexcomm2,
kCLOCK_Flexcomm3,
kCLOCK_Flexcomm4,
kCLOCK_Flexcomm5,
kCLOCK_Flexcomm6,
kCLOCK_Flexcomm7,
kCLOCK_Flexcomm8,
kCLOCK_Flexcomm9 }
Clock name used to get clock frequency.
• enum async_clock_src_t {
kCLOCK_AsyncMainClk = 0,
kCLOCK_AsyncFro12Mhz }
• enum clock_flashtim_t {
kCLOCK_Flash1Cycle = 0,
kCLOCK_Flash2Cycle,
kCLOCK_Flash3Cycle,
kCLOCK_Flash4Cycle,
kCLOCK_Flash5Cycle,
kCLOCK_Flash6Cycle,
kCLOCK_Flash7Cycle,
kCLOCK_Flash8Cycle }
FLASH Access time definitions.
• enum ss_progmodfm_t {
kSS_MF_512 = (0 << 20),
kSS_MF_384 = (1 << 20),
kSS_MF_256 = (2 << 20),
kSS_MF_128 = (3 << 20),
kSS_MF_64 = (4 << 20),
kSS_MF_32 = (5 << 20),
kSS_MF_24 = (6 << 20),
kSS_MF_16 = (7 << 20) }
PLL Spread Spectrum (SS) Programmable modulation frequency See (MF) field in the SYSPLLSSCTRL1
register in the UM.
• enum ss_progmoddp_t {
kSS_MR_K0 = (0 << 23),
kSS_MR_K1 = (1 << 23),
kSS_MR_K1_5 = (2 << 23),
kSS_MR_K2 = (3 << 23),
kSS_MR_K3 = (4 << 23),
kSS_MR_K4 = (5 << 23),
kSS_MR_K6 = (6 << 23),
kSS_MR_K8 = (7 << 23) }
PLL Spread Spectrum (SS) Programmable frequency modulation depth See (MR) field in the SYSPLLSSC-
TRL1 register in the UM.
• enum ss_modwvctrl_t {
kSS_MC_NOC = (0 << 26),
kSS_MC_RECC = (2 << 26),
kSS_MC_MAXC = (3 << 26) }
PLL Spread Spectrum (SS) Modulation waveform control See (MC) field in the SYSPLLSSCTRL1 register
in the UM.
• enum pll_error_t {
kStatus_PLL_Success = MAKE_STATUS(kStatusGroup_Generic, 0),
kStatus_PLL_OutputTooLow = MAKE_STATUS(kStatusGroup_Generic, 1),
kStatus_PLL_OutputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 2),
kStatus_PLL_InputTooLow = MAKE_STATUS(kStatusGroup_Generic, 3),
kStatus_PLL_InputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 4),
kStatus_PLL_OutsideIntLimit = MAKE_STATUS(kStatusGroup_Generic, 5),
kStatus_PLL_CCOTooLow = MAKE_STATUS(kStatusGroup_Generic, 6),
kStatus_PLL_CCOTooHigh = MAKE_STATUS(kStatusGroup_Generic, 7) }
Functions
This structure can be used to configure the settings for a PLL setup structure. Fill in the desired configu-
ration for the PLL and call the PLL setup function to fill in a PLL setup structure.
Data Fields
• uint32_t desiredRate
Desired PLL rate in Hz.
• uint32_t inputRate
PLL input clock in Hz, only used if PLL_CONFIGFLAG_USEINRATE flag is set.
• uint32_t flags
PLL configuration flags, Or’ed value of PLL_CONFIGFLAG_∗ definitions.
• ss_progmodfm_t ss_mf
SS Programmable modulation frequency, only applicable when not using PLL_CONFIGFLAG_FORCE-
NOFRACT flag.
• ss_progmoddp_t ss_mr
SS Programmable frequency modulation depth, only applicable when not using PLL_CONFIGFLAG_F-
ORCENOFRACT flag.
• ss_modwvctrl_t ss_mc
SS Modulation waveform control, only applicable when not using PLL_CONFIGFLAG_FORCENOFRA-
CT flag.
• bool mfDither
false for fixed modulation frequency or true for dithering, only applicable when not using PLL_CONFIG-
FLAG_FORCENOFRACT flag
It can be populated with the PLL setup function. If powering up or waiting for PLL lock, the PLL input
clock source should be configured prior to PLL setup.
Data Fields
• uint32_t syspllctrl
PLL control register SYSPLLCTRL.
• uint32_t syspllndec
PLL NDEC register SYSPLLNDEC.
• uint32_t syspllpdec
PLL PDEC register SYSPLLPDEC.
• uint32_t syspllmdec
PLL MDEC registers SYSPLLPDEC.
• uint32_t pllRate
Acutal PLL rate.
• uint32_t flags
PLL setup flags, Or’ed value of PLL_SETUPFLAG_∗ definitions.
It can be populated with the USB PLL setup function. If powering up or waiting for USB PLL lock, the
PLL input clock source should be configured prior to USB PLL setup.
Data Fields
• uint8_t msel
USB PLL control register msel:1U-256U.
• uint8_t psel
USB PLL control register psel:only support inter 1U 2U 4U 8U.
• uint8_t nsel
USB PLL control register nsel:only suppoet inter 1U 2U 3U 4U.
• bool direct
USB PLL CCO output control.
• bool bypass
USB PLL inout clock bypass control.
• bool fbsel
USB PLL ineter mode and non-integer mode control.
• uint32_t inputRate
When set to 0, peripheral drivers will enable clock in initialize function and disable clock in de-initialize
function. When set to 1, peripheral driver will not control the clock, application could contol the clock out
of the driver.
Note
All drivers share this feature switcher. If it is set to 1, application should handle clock enable and
disable for all drivers.
Value:
{ \
kCLOCK_Adc0 \
}
Value:
{ \
kCLOCK_Rom \
}
Value:
{ \
kCLOCK_Sram1, kCLOCK_Sram2, kCLOCK_Sram3 \
}
Value:
{ \
kCLOCK_Flash \
}
Value:
{ \
kCLOCK_Fmc \
}
Value:
{ \
kCLOCK_Eeprom \
}
Value:
{ \
kCLOCK_Spifi \
}
Value:
{ \
kCLOCK_InputMux \
}
Value:
{ \
kCLOCK_Iocon \
}
Value:
{ \
kCLOCK_Gpio0,kLOCK_Gpio1, kCLOCK_Gpio2, kCLOCK_Gpio3, kCLOCK_Gpio4, kCLOCK_Gpio5 \
}
Value:
{ \
kCLOCK_Pint \
}
Value:
{ \
kCLOCK_Gint, kCLOCK_Gint \
}
Value:
{ \
kCLOCK_Dma \
}
Value:
{ \
kCLOCK_Crc \
}
Value:
{ \
kCLOCK_Wwdt \
}
Value:
{ \
kCLOCK_Rtc \
}
Value:
{ \
kCLOCK_Adc0 \
}
Value:
{ \
kCLOCK_Mrt \
}
Value:
{ \
kCLOCK_Rit \
}
Value:
{ \
kCLOCK_Sct0 \
}
Value:
{ \
kCLOCK_Mcan0, kCLOCK_Mcan1 \
}
Value:
{ \
kCLOCK_Utick \
}
Value:
{ \
kCLOCK_FlexComm0, kCLOCK_FlexComm1, kCLOCK_FlexComm2, kCLOCK_FlexComm3, \
kCLOCK_FlexComm4, kCLOCK_FlexComm5, kCLOCK_FlexComm6, kCLOCK_FlexComm7, \
kCLOCK_FlexComm8, kCLOCK_FlexComm9 \
}
Value:
{ \
kCLOCK_MinUart0, kCLOCK_MinUart1, kCLOCK_MinUart2, kCLOCK_MinUart3, kCLOCK_MinUart4,
kCLOCK_MinUart5, \
kCLOCK_MinUart6, kCLOCK_MinUart7, kCLOCK_MinUart8,kCLOCK_MinUart9 \
}
Value:
{
\
kCLOCK_BI2c0, kCLOCK_BI2c1, kCLOCK_BI2c2, kCLOCK_BI2c3, kCLOCK_BI2c4, kCLOCK_BI2c5, kCLOCK_BI2c6,
kCLOCK_BI2c7, \
kCLOCK_BI2c8, kCLOCK_BI2c9 \
}
Value:
{
\
kCLOCK_LSpi0, kCLOCK_LSpi1, kCLOCK_LSpi2, kCLOCK_LSpi3, kCLOCK_LSpi4, kCLOCK_LSpi5, kCLOCK_LSpi6,
kCLOCK_LSpi7, \
kCLOCK_LSpi8, kCLOCK_LSpi9 \
}
Value:
{ \
kCLOCK_FlexI2s0, kCLOCK_FlexI2s1, kCLOCK_FlexI2s2, kCLOCK_FlexI2s3, kCLOCK_FlexI2s4,
kCLOCK_FlexI2s5, \
kCLOCK_FlexI2s6, kCLOCK_FlexI2s7, kCLOCK_FlexI2s8, kCLOCK_FlexI2s9
\
}
Value:
{ \
kCLOCK_DMic \
}
Value:
{ \
kCLOCK_Ct32b0, kCLOCK_Ct32b1, kCLOCK_Ct32b2, kCLOCK_Ct32b3, kCLOCK_Ct32b4 \
}
Value:
{ \
kCLOCK_Lcd \
}
Value:
{ \
kCLOCK_Sdio \
}
Value:
{ \
kCLOCK_UsbRam1 \
}
Value:
{ \
kCLOCK_Emc \
}
Value:
{ \
kCLOCK_Eth \
}
Value:
{ \
kCLOCK_Aes \
}
Value:
{ \
kCLOCK_Otp \
}
Value:
{ \
kCLOCK_Rng \
}
Value:
{ \
kCLOCK_Usbhmr0 \
}
Value:
{ \
kCLOCK_Usbhsl0 \
}
Value:
{ \
kCLOCK_Sha0 \
}
Value:
{ \
kCLOCK_SmartCard0, kCLOCK_SmartCard1 \
}
Value:
{ \
kCLOCK_Usbd0, kCLOCK_Usbh1, kCLOCK_Usbd1 \
}
Value:
{ \
kCLOCK_Usbh1 \
}
[4 bits for choice, where 1 is A, 2 is B, 3 is C and 4 is D, 0 means end of descriptor] [8 bits mux ID]∗
When the PLL_CONFIGFLAG_USEINRATE flag is selected, the ’InputRate’ field in the configuration
structure must be assigned with the expected PLL frequency. If the PLL_CONFIGFLAG_USEINRATE
is not used, ’InputRate’ is ignored in the configuration function and the driver will determine the PLL rate
from the currently selected PLL source. This flag might be used to configure the PLL input clock more
accurately when using the WDT oscillator or a more dyanmic CLKIN source.
When the PLL_CONFIGFLAG_FORCENOFRACT flag is selected, the PLL hardware for the automatic
bandwidth selection, Spread Spectrum (SS) support, and fractional M-divider are not used.
Flag to use InputRate in PLL configuration structure for setup
Enumerator
kCLOCK_CoreSysClk Core/system clock (aka MAIN_CLK)
kCLOCK_BusClk Bus clock (AHB clock)
kCLOCK_ClockOut CLOCKOUT.
kCLOCK_FroHf FRO48/96.
kCLOCK_SpiFi SPIFI.
kCLOCK_Adc ADC.
kCLOCK_Usb0 USB0.
kCLOCK_Usb1 USB1.
kCLOCK_UsbPll USB1 PLL.
kCLOCK_Mclk MCLK.
kCLOCK_Sct SCT.
kCLOCK_SDio SDIO.
kCLOCK_EMC EMC.
kCLOCK_LCD LCD.
kCLOCK_MCAN0 MCAN0.
kCLOCK_MCAN1 MCAN1.
kCLOCK_Fro12M FRO12M.
kCLOCK_ExtClk External Clock.
kCLOCK_PllOut PLL Output.
kCLOCK_UsbClk USB input.
kClock_WdtOsc Watchdog Oscillator.
kCLOCK_Frg Frg Clock.
kCLOCK_Dmic Digital Mic clock.
kCLOCK_AsyncApbClk Async APB clock.
kCLOCK_FlexI2S FlexI2S clock.
kCLOCK_Flexcomm0 Flexcomm0Clock.
kCLOCK_Flexcomm1 Flexcomm1Clock.
kCLOCK_Flexcomm2 Flexcomm2Clock.
kCLOCK_Flexcomm3 Flexcomm3Clock.
kCLOCK_Flexcomm4 Flexcomm4Clock.
kCLOCK_Flexcomm5 Flexcomm5Clock.
kCLOCK_Flexcomm6 Flexcomm6Clock.
kCLOCK_Flexcomm7 Flexcomm7Clock.
kCLOCK_Flexcomm8 Flexcomm8Clock.
kCLOCK_Flexcomm9 Flexcomm9Clock.
Enumerator
kCLOCK_AsyncMainClk Main System clock.
kCLOCK_AsyncFro12Mhz 12MHz FRO
Enumerator
kCLOCK_Flash1Cycle Flash accesses use 1 CPU clocks.
kCLOCK_Flash2Cycle Flash accesses use 2 CPU clocks.
kCLOCK_Flash3Cycle Flash accesses use 3 CPU clocks.
kCLOCK_Flash4Cycle Flash accesses use 4 CPU clocks.
kCLOCK_Flash5Cycle Flash accesses use 5 CPU clocks.
kCLOCK_Flash6Cycle Flash accesses use 6 CPU clocks.
kCLOCK_Flash7Cycle Flash accesses use 7 CPU clocks.
kCLOCK_Flash8Cycle Flash accesses use 8 CPU clocks.
Enumerator
kSS_MF_512 Nss = 512 (fm ? 3.9 - 7.8 kHz)
kSS_MF_384 Nss ?= 384 (fm ? 5.2 - 10.4 kHz)
kSS_MF_256 Nss = 256 (fm ? 7.8 - 15.6 kHz)
kSS_MF_128 Nss = 128 (fm ? 15.6 - 31.3 kHz)
kSS_MF_64 Nss = 64 (fm ? 32.3 - 64.5 kHz)
kSS_MF_32 Nss = 32 (fm ? 62.5- 125 kHz)
kSS_MF_24 Nss ?= 24 (fm ? 83.3- 166.6 kHz)
kSS_MF_16 Nss = 16 (fm ? 125- 250 kHz)
Enumerator
kSS_MR_K0 k = 0 (no spread spectrum)
kSS_MR_K1 k = 1
kSS_MR_K1_5 k = 1.5
kSS_MR_K2 k = 2
kSS_MR_K3 k = 3
kSS_MR_K4 k = 4
kSS_MR_K6 k = 6
kSS_MR_K8 k = 8
Compensation for low pass filtering of the PLL to get a triangular modulation at the output of the PLL,
giving a flat frequency spectrum.
Enumerator
kSS_MC_NOC no compensation
kSS_MC_RECC recommended setting
kSS_MC_MAXC max. compensation
Enumerator
kStatus_PLL_Success PLL operation was successful.
kStatus_PLL_OutputTooLow PLL output rate request was too low.
kStatus_PLL_OutputTooHigh PLL output rate request was too high.
Enumerator
kCLOCK_UsbSrcFro Use FRO 96 or 48 MHz.
kCLOCK_UsbSrcSystemPll Use System PLL output.
kCLOCK_UsbSrcMainClock Use Main clock.
kCLOCK_UsbSrcUsbPll Use USB PLL clock.
kCLOCK_UsbSrcNone Use None, this may be selected in order to reduce power when no output is
needed.
Parameters
Returns
Nothing
Parameters
Returns
returns success or fail status.
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Returns
Frequency of selected clock
Returns
Frequency of FRO 12MHz
Returns
Frequency of ClockOut
Returns
Frequency of Spifi.
Returns
Frequency of Adc Clock.
Returns
Frequency of Usb0 Clock.
Returns
Frequency of Usb1 Clock.
Returns
Frequency of MClk Clock.
Returns
Frequency of SCTimer Clock.
Returns
Frequency of SDIO Clock.
Returns
Frequency of LCD Clock.
Returns
Frequency of LCD CLKIN Clock.
Returns
Frequency of External Clock. If no external clock is used returns 0.
Returns
Frequency of Watchdog Oscillator
Returns
Frequency of High-Freq output of FRO
Returns
Frequency of PLL
Returns
Frequency of PLL
Returns
Frequency of PLL
Returns
Frequency of 32kHz osc
Returns
Frequency of Core System
Returns
Frequency of I2S MCLK Clock
Returns
Frequency of Flexcomm functional Clock
Returns
Asynchronous APB CLock source
Returns
Frequency of Asynchronous APB Clock Clock
Returns
Audio PLL input clock rate
Returns
System PLL input clock rate
Parameters
Returns
System PLL output clock rate
Note
The PLL rate is cached in the driver in a variable as the rate computation function can take some
time to perform. It is recommended to use ’false’ with the ’recompute’ parameter.
Parameters
Returns
System AUDIO PLL output clock rate
Note
The AUDIO PLL rate is cached in the driver in a variable as the rate computation function can take
some time to perform. It is recommended to use ’false’ with the ’recompute’ parameter.
Parameters
Returns
System USB PLL output clock rate
Note
The USB PLL rate is cached in the driver in a variable as the rate computation function can take
some time to perform. It is recommended to use ’false’ with the ’recompute’ parameter.
bypass : true to bypass PLL (PLL output = PLL input, false to disable bypass
Returns
System PLL output clock rate
Returns
true if the PLL is locked, false if not locked
Returns
true if the USB PLL is locked, false if not locked
Returns
true if the AUDIO PLL is locked, false if not locked
Parameters
Returns
Nothing
Parameters
Returns
Nothing
Parameters
Returns
System PLL output clock rate the setup structure will generate
Parameters
Returns
System PLL output clock rate the setup structure will generate
Parameters
Returns
System PLL output clock rate the setup structure will generate
Parameters
Returns
PLL_ERROR_SUCCESS on success, or PLL setup error code
Note
Actual frequency for setup may vary from the desired frequency based on the accuracy of input
clocks, rounding, non-fractional PLL mode, etc.
Parameters
Returns
PLL_ERROR_SUCCESS on success, or PLL setup error code
Note
Actual frequency for setup may vary from the desired frequency based on the accuracy of input
clocks, rounding, non-fractional PLL mode, etc.
Parameters
Returns
PLL_ERROR_SUCCESS on success, or PLL setup error code
Note
This function will power off the PLL, setup the PLL with the new setup data, and then optionally
powerup the PLL, wait for PLL lock, and adjust system voltages to the new PLL rate. The function
will not alter any source clocks (ie, main systen clock) that may use the PLL, so these should be
setup prior to and after exiting the function.
Parameters
Returns
PLL_ERROR_SUCCESS on success, or PLL setup error code
Note
This function will power off the PLL, setup the PLL with the new setup data, and then optionally
powerup the AUDIO PLL, wait for PLL lock, and adjust system voltages to the new AUDIOPLL
rate. The function will not alter any source clocks (ie, main systen clock) that may use the AUDIO
PLL, so these should be setup prior to and after exiting the function.
Parameters
Returns
kStatus_PLL_Success on success, or PLL setup error code
Note
This function will power off the PLL, setup the PLL with the new setup data, and then optionally
powerup the PLL, wait for PLL lock, and adjust system voltages to the new PLL rate. The function
will not alter any source clocks (ie, main systen clock) that may use the PLL, so these should be
setup prior to and after exiting the function.
Parameters
Returns
kStatus_PLL_Success on success, or USB PLL setup error code
Note
This function will power off the USB PLL, setup the PLL with the new setup data, and then option-
ally powerup the USB PLL, wait for USB PLL lock, and adjust system voltages to the new USB PLL
rate. The function will not alter any source clocks (ie, usb pll clock) that may use the USB PLL, so
these should be setup prior to and after exiting the function.
Parameters
multiply_by : multiplier
input_freq : Clock input frequency of the PLL
Returns
Nothing
Note
Unlike the Chip_Clock_SetupSystemPLLPrec() function, this function does not disable or enable
PLL power, wait for PLL lock, or adjust system voltages. These must be done in the application.
The function will not alter any source clocks (ie, main systen clock) that may use the PLL, so these
should be setup prior to and after exiting the function.
Parameters
Parameters
Parameters
Parameters
/* Intiialize UTICK */
UTICK_Init(UTICK0);
/* Set the UTICK timer to wake up the device from reduced power mode */
UTICK_SetTick(UTICK0, kUTICK_Repeat, UTICK_TIME, NULL);
while (1)
{
}
Files
• file fsl_utick.h
Typedefs
• typedef void(∗ utick_callback_t )(void)
UTICK callback function.
Enumerations
• enum utick_mode_t {
kUTICK_Onetime = 0x0U,
kUTICK_Repeat = 0x1U }
UTICK timer operational mode.
Driver version
• #define FSL_UTICK_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
UTICK driver version 2.0.0.
Enumerator
kUTICK_Onetime Trigger once.
kUTICK_Repeat Trigger repeatedly.
Returns
status register value
Returns
none
Returns
none
This function handles the interrupt and refers to the callback array in the driver to callback user (as per
request in UTICK_SetTick()). if no user callback is scheduled, the interrupt will simply be cleared.
Parameters
Returns
none
The function WWDT_Init() initializes the watchdog timer with specified configurations. The configura-
tions include timeout value and whether to enable watchdog after iniy. The function WWDT_GetDefault-
Config() gets the default configurations.
The function WWDT_Deinit() disables the watchdog and the module clock.
39.2.2 Status
39.2.3 Interrupt
Provides functions to enable/disable WWDT interrupts and get current enabled interrupts.
/* Init hardware*/
BOARD_InitHardware();
POWER_DisablePD(kPDRUNCFG_PD_WDT_OSC);
NVIC_EnableIRQ(WDT_BOD_IRQn);
WWDT_GetDefaultConfig(&config);
/*
* Set watchdog feed time constant to approximately 2s
* Set watchdog warning time to 512 ticks after feed time constant
* Set watchdog window time to 1s
*/
config.timeoutValue = wdtFreq * 2;
config.warningValue = 512;
config.windowValue = wdtFreq * 1;
/* Configure WWDT to reset on timeout */
config.enableWatchdogReset = true;
while (1)
{
}
}
Files
• file fsl_wwdt.h
Data Structures
• struct wwdt_config_t
Describes WWDT configuration structure. More...
Enumerations
• enum _wwdt_status_flags_t {
kWWDT_TimeoutFlag = WWDT_MOD_WDTOF_MASK,
kWWDT_WarningFlag = WWDT_MOD_WDINT_MASK }
WWDT status flags.
Driver version
• #define FSL_WWDT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Defines WWDT driver version 2.0.0.
Refresh sequence
• #define WWDT_FIRST_WORD_OF_REFRESH (0xAAU)
First word of refresh sequence.
• #define WWDT_SECOND_WORD_OF_REFRESH (0x55U)
Second word of refresh sequence.
Data Fields
• bool enableWwdt
Enables or disables WWDT.
• bool enableWatchdogReset
true: Watchdog timeout will cause a chip reset false: Watchdog timeout will not cause a chip reset
• bool enableWatchdogProtect
true: Enable watchdog protect i.e timeout value can only be changed after counter is below warning &
window values false: Disable watchdog protect; timeout value can be changed at any time
• bool enableLockOscillator
true: Disabling or powering down the watchdog oscillator is prevented Once set, this bit can only be
cleared by a reset false: Do not lock oscillator
• uint32_t windowValue
Window value, set this to 0xFFFFFF if windowing is not in effect.
• uint32_t timeoutValue
Timeout value.
• uint32_t warningValue
Watchdog time counter value that will generate a warning interrupt.
This structure contains the WWDT status flags for use in the WWDT functions.
Enumerator
kWWDT_TimeoutFlag Time-out flag, set when the timer times out.
kWWDT_WarningFlag Warning interrupt flag, set when timer is below the value WDWARNINT.
This function initializes the WWDT configure structure to default value. The default value are:
* config->enableWwdt = true;
* config->enableWatchdogReset = false;
* config->enableWatchdogProtect = false;
* config->enableLockOscillator = false;
* config->windowValue = 0xFFFFFFU;
* config->timeoutValue = 0xFFFFFFU;
* config->warningValue = 0;
*
Parameters
See Also
wwdt_config_t
This function initializes the WWDT. When called, the WWDT runs according to the configuration.
Example:
* wwdt_config_t config;
* WWDT_GetDefaultConfig(&config);
* config.timeoutValue = 0x7ffU;
* WWDT_Init(wwdt_base,&config);
*
Parameters
This function write value into WWDT_MOD register to enable the WWDT, it is a write-once bit; once
this bit is set to one and a watchdog feed is performed, the watchdog timer will run permanently.
Parameters
This function write value into WWDT_MOD register to disable the WWDT.
Parameters
* uint32_t status;
* status = WWDT_GetStatusFlags(wwdt_base) &
kWWDT_TimeoutFlag;
*
Parameters
Returns
The status flags. This is the logical OR of members of the enumeration _wwdt_status_flags_t
* WWDT_ClearStatusFlags(wwdt_base, kWWDT_WarningFlag);
*
Parameters
The WDWARNINT register determines the watchdog timer counter value that will generate a watchdog
interrupt. When the watchdog timer counter is no longer greater than the value defined by WARNINT, an
interrupt will be generated after the subsequent WDCLK.
Parameters
This function sets the timeout value. Every time a feed sequence occurs the value in the TC register is
loaded into the Watchdog timer. Writing a value below 0xFF will cause 0xFF to be loaded into the TC
register. Thus the minimum time-out interval is TWDCLK∗256∗4. If enableWatchdogProtect flag is true
in wwdt_config_t config structure, any attempt to change the timeout value before the watchdog counter
is below the warning and window values will cause a watchdog reset and set the WDTOF flag.
Parameters
The WINDOW register determines the highest TV value allowed when a watchdog feed is performed. If a
feed sequence occurs when timer value is greater than the value in WINDOW, a watchdog event will occur.
To disable windowing, set windowValue to 0xFFFFFF (maximum possible timer value) so windowing is
not in effect.
Parameters
This function feeds the WWDT. This function should be called before WWDT timer is in timeout. Other-
wise, a reset is asserted.
Parameters
39.8 Fmc_driver
39.8.1 Overview
Data Structures
• struct fmc_flash_signature_t
Defines the generated 128-bit signature. More...
• struct fmc_config_t
fmc config structure. More...
Enumerations
Enumerator
kFMC_SignatureGenerationDoneFlag Flash signature generation done.