| Kinetis SDK v.2.0 API Reference Manual Rev. 0 Freescale Semiconductor, Inc.

- Main Page
- Related Pages
- API Reference

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Files | Data Structures | Macros | Typedefs | Enumerations
FlexCAN Driver
FlexCAN: Flex Controller Area Network Driver

## Overview

This section describes the programming interface of the FlexCAN driver. The FlexCAN driver configures FlexCAN module, provides a functional and transactional interfaces to build the FlexCAN application.

# Typical use case

## Message Buffer Send Operation

flexcan_config_t flexcanConfig;
flexcan_frame_t txFrame;
/* Init FlexCAN module.
FLEXCAN_GetDefaultConfig(&flexcanConfig);
FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig);
/* Enable FlexCAN module.
FLEXCAN_Enable(EXAMPLE_CAN, true);
/* Sets up the transmit message buffer.
FLEXCAN_SetTxMbConfig(EXAMPLE_CAN, TX_MESSAGE_BUFFER_INDEX, true);
/* Prepares the transmit frame for sending.
txFrame.format = KFLEXCAN_FrameFormatStandard;
txFrame.type = KFLEXCAN_FrameTypeData;
txFrame.id = FLEXCAN_ID_STD(0x123);
txFrame.length = 8;
txFrame.dataWord0 = CAN_WORD0_DATA_BYTE_0(0x11) |
CAN_WORD0_DATA_BYTE_1(0x22) |
CAN_WORD0_DATA_BYTE_2(0x33) |
CAN_WORD0_DATA_BYTE_3(0x44);
txFrame.dataWord1 = CAN_WORD1_DATA_BYTE_4(0x55) |
CAN_WORD1_DATA_BYTE_5(0x66) |
CAN_WORD1_DATA_BYTE_6(0x77) |
CAN_WORD1_DATA_BYTE_7(0x88);
/* Writes a transmit message buffer to send a CAN Message.
FLEXCAN_WriteTxMb(EXAMPLE_CAN, TX_MESSAGE_BUFFER_INDEX, &txFrame);
/* Waits until the transmit message buffer is empty.
while (!FLEXCAN_GetMbStatusFlags(EXAMPLE_CAN, 1 << TX_MESSAGE_BUFFER_INDEX));
/* Cleans the transmit message buffer empty status.
FLEXCAN_ClearMbStatusFlags(EXAMPLE_CAN, 1 << TX_MESSAGE_BUFFER_INDEX);

## Message Buffer Receive Operation

flexcan_config_t flexcanConfig;
flexcan_frame_t rxFrame;
/* Initializes the FlexCAN module.
FLEXCAN_GetDefaultConfig(&flexcanConfig);
FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig);
/* Enables the FlexCAN module.
FLEXCAN_Enable(EXAMPLE_CAN, true);
/* Sets up the receive message buffer.
mbConfig.format = KFLEXCAN_FrameFormatStandard;
mbConfig.type = KFLEXCAN_FrameTypeData;
mbConfig.id = FLEXCAN_ID_STD(0x123);
FLEXCAN_SetRxMbConfig(EXAMPLE_CAN, RX_MESSAGE_BUFFER_INDEX, &mbConfig, true);
/* Waits until the receive message buffer is full.
while (!FLEXCAN_GetMbStatusFlags(EXAMPLE_CAN, 1 << RX_MESSAGE_BUFFER_INDEX));
/* Reads the received message from the receive message buffer.
FLEXCAN_ReadRxMb(EXAMPLE_CAN, RX_MESSAGE_BUFFER_INDEX, &rxFrame);
/* Cleans the receive message buffer full status.
FLEXCAN_ClearMbStatusFlags(EXAMPLE_CAN, 1 << RX_MESSAGE_BUFFER_INDEX);

## Receive FIFO Operation

uint32_t rxFifoFilter[] = {FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(0x321, 0, 0),
FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(0x321, 1, 0),
FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(0x123, 0, 0),
FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(0x123, 1, 0)};
flexcan_config_t flexcanConfig;
flexcan_frame_t rxFrame;
/* Initializes the FlexCAN module.
FLEXCAN_GetDefaultConfig(&flexcanConfig);
FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig);
/* Enables the FlexCAN module.
FLEXCAN_Enable(EXAMPLE_CAN, true);
/* Sets up the receive FIFO.
rxFifoConfig.idFilterTable = rxFifoFilter;
rxFifoConfig.idFilterType = KFLEXCAN_RxFifoFilterTypeA;
rxFifoConfig.idFilterNum = sizeof(rxFifoFilter) / sizeof(rxFifoFilter[0]);
rxFifoConfig.priority = KFLEXCAN_RxFifoPrioHigh;
FlEXCAN_SetRxFifoConfig(EXAMPLE_CAN, &rxFifoConfig, true);
/* Waits until the receive FIFO becomes available.
while (!FLEXCAN_GetMbStatusFlags(EXAMPLE_CAN, KFLEXCAN_RxFifoFrameAvlFlag));
/* Reads the message from the receive FIFO.
FlEXCAN_ReadRxFifo(EXAMPLE_CAN, &rxFrame);
/* Cleans the receive FIFO available status.
FLEXCAN_ClearMbStatusFlags(EXAMPLE_CAN, KFLEXCAN_RxFifoFrameAvlFlag);

## Files
file | fsl_flexcan.h

## Data Structures
struct | flexcan_frame_t
| FlexCAN message frame structure. More...
struct | flexcan_config_t
| FlexCAN module configuration structure. More...
struct | flexcan_timing_config_t
| FlexCAN protocol timing characteristic configuration structure. More...
struct | flexcan_rx_mb_config_t
| FlexCAN Receive Message Buffer configuration structure. More...
struct | flexcan_rx_fifo_config_t
| FlexCAN Rx FIFO configure structure. More...
struct | flexcan_mb_transfer_t
| FlexCAN Message Buffer transfer. More...
struct | flexcan_fifo_transfer_t
| FlexCAN Rx FIFO transfer. More...
struct | flexcan_handle_t
| FlexCAN handle structure. More...

## Macros
#define | FLEXCAN_ID_STD(id) (((uint32_t)(((uint32_t)(id)) << CAN_ID_STD_SHIFT)) & CAN_ID_STD_MASK)
| FlexCAN Frame ID helper macro. More...
#define | FLEXCAN_ID_EXT(id)
| Extend Frame ID helper macro. More...
#define | FLEXCAN_RX_MB_STD_MASK(id, rtr, ide)
| FlexCAN Rx Message Buffer Mask helper macro. More...
#define | FLEXCAN_RX_MB_EXT_MASK(id, rtr, ide)
| Extend Rx Message Buffer Mask helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide)
| FlexCAN Rx FIFO Mask helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH(id, rtr, ide)
| Standard Rx FIFO Mask helper macro Type B upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW(id, rtr, ide)
| Standard Rx FIFO Mask helper macro Type B lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH(id) ((FLEXCAN_ID_STD(id) & 0x7F8) << 21)
| Standard Rx FIFO Mask helper macro Type C upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH(id) ((FLEXCAN_ID_STD(id) & 0x7F8) << 13)
| Standard Rx FIFO Mask helper macro Type C mid-upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW(id) ((FLEXCAN_ID_STD(id) & 0x7F8) << 5)
| Standard Rx FIFO Mask helper macro Type C mid-lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW(id) ((FLEXCAN_ID_STD(id) & 0x7F8) >> 3)
| Standard Rx FIFO Mask helper macro Type C lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide)
| Extend Rx FIFO Mask helper macro Type A helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH(id, rtr, ide)
| Extend Rx FIFO Mask helper macro Type B upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW(id, rtr, ide)
| Extend Rx FIFO Mask helper macro Type B lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH(id) ((FLEXCAN_ID_EXT(id) & 0x1FE00000) << 3)
| Extend Rx FIFO Mask helper macro Type C upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH(id)
| Extend Rx FIFO Mask helper macro Type C mid-upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW(id)
| Extend Rx FIFO Mask helper macro Type C mid-lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id) ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> 21)
| Extend Rx FIFO Mask helper macro Type C lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(id, rtr, ide) FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide)
| FlexCAN Rx FIFO Filter helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_HIGH(id, rtr, ide)
| Standard Rx FIFO Filter helper macro Type B upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_LOW(id, rtr, ide)
| Standard Rx FIFO Filter helper macro Type B lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_HIGH(id)
| Standard Rx FIFO Filter helper macro Type C upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_HIGH(id)
| Standard Rx FIFO Filter helper macro Type C mid-upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_LOW(id)
| Standard Rx FIFO Filter helper macro Type C mid-lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_LOW(id) FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW(id)
| Standard Rx FIFO Filter helper macro Type C lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_A(id, rtr, ide) FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide)
| Extend Rx FIFO Filter helper macro Type A helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_HIGH(id, rtr, ide)
| Extend Rx FIFO Filter helper macro Type B upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_LOW(id, rtr, ide)
| Extend Rx FIFO Filter helper macro Type B lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_HIGH(id) FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH(id)
| Extend Rx FIFO Filter helper macro Type C upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_HIGH(id)
| Extend Rx FIFO Filter helper macro Type C mid-upper part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_LOW(id)
| Extend Rx FIFO Filter helper macro Type C mid-lower part helper macro. More...
#define | FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_LOW(id) FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id)
| Extend Rx FIFO Filter helper macro Type C lower part helper macro. More...

## Typedefs
typedef void(* | flexcan_transfer_callback_t )(CAN_Type *base, flexcan_handle_t *handle, status_t status, uint32_t result, void *userData)
| FlexCAN transfer callback function. More...

## Enumerations
enum | _flexcan_status { kStatus_FLEXCAN_TxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 0), kStatus_FLEXCAN_TxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 1), kStatus_FLEXCAN_TxSwitchToRx, kStatus_FLEXCAN_RxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 3), kStatus_FLEXCAN_RxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 4), kStatus_FLEXCAN_RxOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 5), kStatus_FLEXCAN_RxFifoBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 6), kStatus_FLEXCAN_RxFifoIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 7), kStatus_FLEXCAN_RxFifoOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 8), kStatus_FLEXCAN_RxFifoWarning = MAKE_STATUS(kStatusGroup_FLEXCAN, 0), kStatus_FLEXCAN_ErrorStatus = MAKE_STATUS(kStatusGroup_FLEXCAN, 10), kStatus_FLEXCAN_UnHandled = MAKE_STATUS(kStatusGroup_FLEXCAN, 11) }
| FlexCAN transfer status. More...
enum | flexcan_frame_format_t { kFLEXCAN_FrameFormatStandard = 0x0U, kFLEXCAN_FrameFormatExtend = 0x1U }
| FlexCAN frame format. More...
enum | flexcan_frame_type_t { kFLEXCAN_FrameTypeData = 0x0U, kFLEXCAN_FrameTypeRemote = 0x1U }
| FlexCAN frame type. More...
enum | flexcan_clock_source_t { kFLEXCAN_ClkSrcOsc = 0x0U, kFLEXCAN_ClkSrcPeri = 0x1U }
| FlexCAN clock source. More...
enum | flexcan_rx_fifo_filter_type_t { kFLEXCAN_RxFifoFilterTypeA = 0x0U, kFLEXCAN_RxFifoFilterTypeB, kFLEXCAN_RxFifoFilterTypeC, kFLEXCAN_RxFifoFilterTypeD = 0x3U }
| FlexCAN Rx Fifo Filter type. More...
enum | flexcan_rx_fifo_priority_t { kFLEXCAN_RxFifoPrioLow = 0x0U, kFLEXCAN_RxFifoPrioHigh = 0x1U }
| FlexCAN Rx FIFO priority. More...
enum | _flexcan_interrupt_enable { kFLEXCAN_BusOffInterruptEnable = CAN_CTRL1_BOFFMSK_MASK, kFLEXCAN_ErrorInterruptEnable = CAN_CTRL1_ERRMSK_MASK, kFLEXCAN_RxWarningInterruptEnable = CAN_CTRL1_RWRNMSK_MASK, kFLEXCAN_TxWarningInterruptEnable = CAN_CTRL1_TWRNMSK_MASK, kFLEXCAN_WakeUpInterruptEnable = CAN_MCR_WAKMSK_MASK }
| FlexCAN interrupt configuration structure, default settings all disabled. More...
enum | _flexcan_flags { kFLEXCAN_SynchFlag = CAN_ESR1_SYNCH_MASK, kFLEXCAN_TxWarningIntFlag = CAN_ESR1_TWRNINT_MASK, kFLEXCAN_RxWarningIntFlag = CAN_ESR1_RWRNINT_MASK, kFLEXCAN_TxErrorWarningFlag = CAN_ESR1_TXWRN_MASK, kFLEXCAN_RxErrorWarningFlag = CAN_ESR1_RXWRN_MASK, kFLEXCAN_IdleFlag = CAN_ESR1_IDLE_MASK, kFLEXCAN_FaultConfinementFlag = CAN_ESR1_FLTCONF_MASK, kFLEXCAN_TransmittingFlag = CAN_ESR1_TX_MASK, kFLEXCAN_ReceivingFlag = CAN_ESR1_RX_MASK, kFLEXCAN_BusOffIntFlag = CAN_ESR1_BOFFINT_MASK, kFLEXCAN_ErrorIntFlag = CAN_ESR1_ERRINT_MASK, kFLEXCAN_WakeUpIntFlag = CAN_ESR1_WAKINT_MASK, kFLEXCAN_ErrorFlag }
| FlexCAN status flags. More...
enum | _flexcan_error_flags { kFLEXCAN_StuffingError = CAN_ESR1_STFERR_MASK, kFLEXCAN_FormError = CAN_ESR1_FRMERR_MASK, kFLEXCAN_CrcError = CAN_ESR1_CRCERR_MASK, kFLEXCAN_AckError = CAN_ESR1_ACKERR_MASK, kFLEXCAN_Bit0Error = CAN_ESR1_BIT0ERR_MASK, kFLEXCAN_Bit1Error = CAN_ESR1_BIT1ERR_MASK }
| FlexCAN error status flags. More...
enum | _flexcan_rx_fifo_flags { kFLEXCAN_RxFifoOverflowFlag = CAN_IFLAG1_BUF7I_MASK, kFLEXCAN_RxFifoWarningFlag = CAN_IFLAG1_BUF6I_MASK, kFLEXCAN_RxFifoFrameAvlFlag = CAN_IFLAG1_BUF5I_MASK }
| FlexCAN Rx FIFO status flags. More...

## Driver version
#define | FLEXCAN_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
| FlexCAN driver version 2.1.0. More...

## Initialization and deinitialization
void | FLEXCAN_Init (CAN_Type *base, const flexcan_config_t *config, uint32_t sourceClock_Hz)
| Initializes a FlexCAN instance. More...
void | FLEXCAN_Deinit (CAN_Type *base)
| De-initializes a FlexCAN instance. More...
void | FLEXCAN_GetDefaultConfig (flexcan_config_t *config)
| Get the default configuration structure. More...

## Configuration.
void | FLEXCAN_SetTimingConfig (CAN_Type *base, const flexcan_timing_config_t *config)
| Sets the FlexCAN protocol timing characteristic. More...
void | FlEXCAN_SetRxMbGlobalMask (CAN_Type *base, uint32_t mask)
| Sets the FlexCAN receive message buffer global mask. More...
void | FlEXCAN_SetRxFifoGlobalMask (CAN_Type *base, uint32_t mask)
| Sets the FlexCAN receive FIFO global mask. More...
void | FlEXCAN_SetRxIndividualMask (CAN_Type *base, uint8_t maskIdx, uint32_t mask)
| Sets the FlexCAN receive individual mask. More...
void | FLEXCAN_SetTxMbConfig (CAN_Type *base, uint8_t mbIdx, bool enable)
| Configures a FlexCAN transmit message buffer. More...
void | FLEXCAN_SetRxMbConfig (CAN_Type *base, uint8_t mbIdx, const flexcan_rx_mb_config_t *config, bool enable)
| Configures a FlexCAN Receive Message Buffer. More...
void | FlEXCAN_SetRxFifoConfig (CAN_Type *base, const flexcan_rx_fifo_config_t *config, bool enable)
| Configures the FlexCAN Rx FIFO. More...

## Status
static uint32_t | FLEXCAN_GetStatusFlags (CAN_Type *base)
| Gets the FlexCAN module interrupt flags. More...
static void | FLEXCAN_ClearStatusFlags (CAN_Type *base, uint32_t mask)
| Clears status flags with the provided mask. More...
static void | FlEXCAN_GetBusErrCount (CAN_Type *base, uint8_t *txErrBuf, uint8_t *rxErrBuf)
| Gets the FlexCAN Bus Error Counter value. More...
static uint32_t | FLEXCAN_GetMbStatusFlags (CAN_Type *base, uint32_t mask)
| Gets the FlexCAN Message Buffer interrupt flags. More...
static void | FLEXCAN_ClearMbStatusFlags (CAN_Type *base, uint32_t mask)
| Clears the FlexCAN Message Buffer interrupt flags. More...

## Interrupts
static void | FLEXCAN_EnableInterrupts (CAN_Type *base, uint32_t mask)
| Enables FlexCAN interrupts according to provided mask. More...
static void | FLEXCAN_DisableInterrupts (CAN_Type *base, uint32_t mask)
| Disables FlexCAN interrupts according to provided mask. More...
static void | FLEXCAN_EnableMbInterrupts (CAN_Type *base, uint32_t mask)
| Enables FlexCAN Message Buffer interrupts. More...
static void | FLEXCAN_DisableMbInterrupts (CAN_Type *base, uint32_t mask)
| Disables FlexCAN Message Buffer interrupts. More...

## Bus Operations
static void | FLEXCAN_Enable (CAN_Type *base, bool enable)
| Enables or disables the FlexCAN module operation. More...
status_t | FLEXCAN_WriteTxMb (CAN_Type *base, uint8_t mbIdx, const flexcan_frame_t *txFrame)
| Writes a FlexCAN Message to Transmit Message Buffer. More...
status_t | FLEXCAN_ReadRxMb (CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *rxFrame)
| Reads a FlexCAN Message from Receive Message Buffer. More...
status_t | FlEXCAN_ReadRxFifo (CAN_Type *base, flexcan_frame_t *rxFrame)
| Reads a FlexCAN Message from Rx FIFO. More...

## Transactional
status_t | FlEXCAN_TransferSendBlocking (CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *txFrame)
| Performs a polling send transaction on the CAN bus. More...
status_t | FlEXCAN_TransferReceiveBlocking (CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *rxFrame)
| Performs a polling receive transaction on the CAN bus. More...
status_t | FlEXCAN_TransferReceiveFifoBlocking (CAN_Type *base, flexcan_frame_t *rxFrame)
| Performs a polling receive transaction from Rx FIFO on the CAN bus. More...
void | FLEXCAN_TransferCreateHandle (CAN_Type *base, flexcan_handle_t *handle, flexcan_transfer_callback_t callback, void *userData)
| Initializes the FlexCAN handle. More...
status_t | FLEXCAN_TransferSendNonBlocking (CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer)
| Sends a message using IRQ. More...
status_t | FLEXCAN_TransferReceiveNonBlocking (CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer)
| Receives a message using IRQ. More...
status_t | FLEXCAN_TransferReceiveFifoNonBlocking (CAN_Type *base, flexcan_handle_t *handle, flexcan_fifo_transfer_t *xfer)
| Receives a message from Rx FIFO using IRQ. More...
void | FLEXCAN_TransferAbortSend (CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx)
| Aborts the interrupt driven message send process. More...
void | FLEXCAN_TransferAbortReceive (CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx)
| Aborts the interrupt driven message receive process. More...
void | FLEXCAN_TransferAbortReceiveFifo (CAN_Type *base, flexcan_handle_t *handle)
| Aborts the interrupt driven message receive from Rx FIFO process. More...
void | FLEXCAN_TransferHandleIRQ (CAN_Type *base, flexcan_handle_t *handle)
| FlexCAN IRQ handle function. More...

## Data Structure Documentation

struct flexcan_frame_t

#### Field Documentation

uint32_t flexcan_frame_t::timestamp

uint32_t flexcan_frame_t::length

uint32_t flexcan_frame_t::type

uint32_t flexcan_frame_t::format

uint32_t flexcan_frame_t::reserve1

uint32_t flexcan_frame_t::idhit

uint32_t flexcan_frame_t::id

uint32_t flexcan_frame_t::reserve2

uint32_t flexcan_frame_t::dataWord0

uint32_t flexcan_frame_t::dataWord1

uint8_t flexcan_frame_t::dataByte3

uint8_t flexcan_frame_t::dataByte2

uint8_t flexcan_frame_t::dataByte1

uint8_t flexcan_frame_t::dataByte0

uint8_t flexcan_frame_t::dataByte7

uint8_t flexcan_frame_t::dataByte6

uint8_t flexcan_frame_t::dataByte5

uint8_t flexcan_frame_t::dataByte4

struct flexcan_config_t

### Data Fields
uint32_t | baudRate
| FlexCAN baud rate in bps. More...
flexcan_clock_source_t | clkSrc
| Clock source for FlexCAN Protocol Engine. More...
uint8_t | maxMbNum
| The maximum number of Message Buffers used by user. More...
bool | enableLoopBack
| Enable or Disable Loop Back Self Test Mode. More...
bool | enableSelfWakeup
| Enable or Disable Self Wakeup Mode. More...
bool | enableIndividMask
| Enable or Disable Rx Individual Mask. More...

#### Field Documentation

uint32_t flexcan_config_t::baudRate

flexcan_clock_source_t flexcan_config_t::clkSrc

uint8_t flexcan_config_t::maxMbNum

bool flexcan_config_t::enableLoopBack

bool flexcan_config_t::enableSelfWakeup

bool flexcan_config_t::enableIndividMask

struct flexcan_timing_config_t

### Data Fields
uint8_t | preDivider
| Clock Pre-scaler Division Factor. More...
uint8_t | rJumpwidth
| Re-sync Jump Width. More...
uint8_t | phaseSeg1
| Phase Segment 1. More...
uint8_t | phaseSeg2
| Phase Segment 2. More...
uint8_t | propSeg
| Propagation Segment. More...

#### Field Documentation

uint8_t flexcan_timing_config_t::preDivider

uint8_t flexcan_timing_config_t::rJumpwidth

uint8_t flexcan_timing_config_t::phaseSeg1

uint8_t flexcan_timing_config_t::phaseSeg2

uint8_t flexcan_timing_config_t::propSeg

struct flexcan_rx_mb_config_t

This structure is used as the parameter of FLEXCAN_SetRxMbConfig() function. The FLEXCAN_SetRxMbConfig() function is used to configure FlexCAN Receive Message Buffer. The function abort previous receiving process, clean the Message Buffer and activate the Rx Message Buffer using given Message Buffer setting.

### Data Fields
uint32_t | id
| CAN Message Buffer Frame Identifier, should be set using FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro. More...
flexcan_frame_format_t | format
| CAN Frame Identifier format(Standard of Extend). More...
flexcan_frame_type_t | type
| CAN Frame Type(Data or Remote). More...

#### Field Documentation

uint32_t flexcan_rx_mb_config_t::id

flexcan_frame_format_t flexcan_rx_mb_config_t::format

flexcan_frame_type_t flexcan_rx_mb_config_t::type

struct flexcan_rx_fifo_config_t

### Data Fields
uint32_t * | idFilterTable
| Pointer to FlexCAN Rx FIFO identifier filter table. More...
uint8_t | idFilterNum
| The quantity of filter elements. More...
flexcan_rx_fifo_filter_type_t | idFilterType
| The FlexCAN Rx FIFO Filter type. More...
flexcan_rx_fifo_priority_t | priority
| The FlexCAN Rx FIFO receive priority. More...

#### Field Documentation

uint32_t* flexcan_rx_fifo_config_t::idFilterTable

uint8_t flexcan_rx_fifo_config_t::idFilterNum

flexcan_rx_fifo_filter_type_t flexcan_rx_fifo_config_t::idFilterType

flexcan_rx_fifo_priority_t flexcan_rx_fifo_config_t::priority

struct flexcan_mb_transfer_t

### Data Fields
flexcan_frame_t * | frame
| The buffer of CAN Message to be transfer. More...
uint8_t | mbIdx
| The index of Message buffer used to transfer Message. More...

#### Field Documentation

flexcan_frame_t* flexcan_mb_transfer_t::frame

uint8_t flexcan_mb_transfer_t::mbIdx

struct flexcan_fifo_transfer_t

### Data Fields
flexcan_frame_t * | frame
| The buffer of CAN Message to be received from Rx FIFO. More...

#### Field Documentation

flexcan_frame_t* flexcan_fifo_transfer_t::frame

struct _flexcan_handle

FlexCAN handle structure definition.

### Data Fields
flexcan_transfer_callback_t | callback
| Callback function. More...
void * | userData
| FlexCAN callback function parameter. More...
flexcan_frame_t *volatile | mbFrameBuf [CAN_WORD1_COUNT]
| The buffer for received data from Message Buffers. More...
flexcan_frame_t *volatile | rxFifoFrameBuf
| The buffer for received data from Rx FIFO. More...
volatile uint8_t | mbState [CAN_WORD1_COUNT]
| Message Buffer transfer state. More...
volatile uint8_t | rxFifoState
| Rx FIFO transfer state. More...

#### Field Documentation

flexcan_transfer_callback_t flexcan_handle_t::callback

void* flexcan_handle_t::userData

flexcan_frame_t* volatile flexcan_handle_t::mbFrameBuf[CAN_WORD1_COUNT]

flexcan_frame_t* volatile flexcan_handle_t::rxFifoFrameBuf

volatile uint8_t flexcan_handle_t::mbState[CAN_WORD1_COUNT]

volatile uint8_t flexcan_handle_t::rxFifoState

## Macro Definition Documentation

#define FLEXCAN_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))

#define FLEXCAN_ID_STD | ( |  | id | ) | (((uint32_t)(((uint32_t)(id)) << CAN_ID_STD_SHIFT)) & CAN_ID_STD_MASK)

Standard Frame ID helper macro.

#define FLEXCAN_ID_EXT | ( |  | id | ) |

Value:
(((uint32_t)(((uint32_t)(id)) << CAN_ID_EXT_SHIFT)) & \
(CAN_ID_EXT_MASK | CAN_ID_STD_MASK))

#define FLEXCAN_RX_MB_STD_MASK | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
FLEXCAN_ID_STD(id))
FLEXCAN_ID_STD
#define FLEXCAN_ID_STD(id)
FlexCAN Frame ID helper macro.
Definition: fsl_flexcan.h:53

Standard Rx Message Buffer Mask helper macro.

#define FLEXCAN_RX_MB_EXT_MASK | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
FLEXCAN_ID_EXT(id))
FLEXCAN_ID_EXT
#define FLEXCAN_ID_EXT(id)
Extend Frame ID helper macro.
Definition: fsl_flexcan.h:56

#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_A | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
(FLEXCAN_ID_STD(id) << 1))
FLEXCAN_ID_STD
#define FLEXCAN_ID_STD(id)
FlexCAN Frame ID helper macro.
Definition: fsl_flexcan.h:53

Standard Rx FIFO Mask helper macro Type A helper macro.

#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
(FLEXCAN_ID_STD(id) << 16))
FLEXCAN_ID_STD
#define FLEXCAN_ID_STD(id)
FlexCAN Frame ID helper macro.
Definition: fsl_flexcan.h:53

#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
(((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \
FLEXCAN_ID_STD(id))
FLEXCAN_ID_STD
#define FLEXCAN_ID_STD(id)
FlexCAN Frame ID helper macro.
Definition: fsl_flexcan.h:53

#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH | ( |  | id | ) | ((FLEXCAN_ID_STD(id) & 0x7F8) << 21)

#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH | ( |  | id | ) | ((FLEXCAN_ID_STD(id) & 0x7F8) << 13)

\

#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW | ( |  | id | ) | ((FLEXCAN_ID_STD(id) & 0x7F8) << 5)

#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW | ( |  | id | ) | ((FLEXCAN_ID_STD(id) & 0x7F8) >> 3)

#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
(FLEXCAN_ID_EXT(id) << 1))
FLEXCAN_ID_EXT
#define FLEXCAN_ID_EXT(id)
Extend Frame ID helper macro.
Definition: fsl_flexcan.h:56

#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
( \
((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
((FLEXCAN_ID_EXT(id) & 0x1FFF8000) \
<< 1))
FLEXCAN_ID_EXT
#define FLEXCAN_ID_EXT(id)
Extend Frame ID helper macro.
Definition: fsl_flexcan.h:56

#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
(((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \
((FLEXCAN_ID_EXT(id) & 0x1FFF8000) >> \
15))
FLEXCAN_ID_EXT
#define FLEXCAN_ID_EXT(id)
Extend Frame ID helper macro.
Definition: fsl_flexcan.h:56

#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH | ( |  | id | ) | ((FLEXCAN_ID_EXT(id) & 0x1FE00000) << 3)

#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH | ( |  | id | ) |

Value:
((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \
5)
FLEXCAN_ID_EXT
#define FLEXCAN_ID_EXT(id)
Extend Frame ID helper macro.
Definition: fsl_flexcan.h:56

#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW | ( |  | id | ) |

Value:
((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \
13)
FLEXCAN_ID_EXT
#define FLEXCAN_ID_EXT(id)
Extend Frame ID helper macro.
Definition: fsl_flexcan.h:56

#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW | ( |  | id | ) | ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> 21)

#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  | FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide)

Standard Rx FIFO Filter helper macro Type A helper macro.

#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_HIGH | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH( \
id, rtr, ide)
FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH(id, rtr, ide)
Standard Rx FIFO Mask helper macro Type B upper part helper macro.
Definition: fsl_flexcan.h:80

#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_LOW | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW( \
id, rtr, ide)
FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW(id, rtr, ide)
Standard Rx FIFO Mask helper macro Type B lower part helper macro.
Definition: fsl_flexcan.h:85

#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_HIGH | ( |  | id | ) |

Value:
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH( \
id)
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH(id)
Standard Rx FIFO Mask helper macro Type C upper part helper macro.
Definition: fsl_flexcan.h:90

#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_HIGH | ( |  | id | ) |

Value:
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH( \
id)
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH(id)
Standard Rx FIFO Mask helper macro Type C mid-upper part helper macro.
Definition: fsl_flexcan.h:93

#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_LOW | ( |  | id | ) |

Value:
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW( \
id)
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW(id)
Standard Rx FIFO Mask helper macro Type C mid-lower part helper macro.
Definition: fsl_flexcan.h:99

#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_LOW | ( |  | id | ) | FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW(id)

\

#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_A | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide)

#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_HIGH | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH( \
id, rtr, ide)
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH(id, rtr, ide)
Extend Rx FIFO Mask helper macro Type B upper part helper macro.
Definition: fsl_flexcan.h:110

#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_LOW | ( |  | id,
|  |  | rtr,
|  |  | ide
| ) |  |

Value:
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW( \
id, rtr, ide)
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW(id, rtr, ide)
Extend Rx FIFO Mask helper macro Type B lower part helper macro.
Definition: fsl_flexcan.h:119

#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_HIGH | ( |  | id | ) | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH(id)

\

#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_HIGH | ( |  | id | ) |

Value:
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH( \
id)
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH(id)
Extend Rx FIFO Mask helper macro Type C mid-upper part helper macro.
Definition: fsl_flexcan.h:129

#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_LOW | ( |  | id | ) |

Value:
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW( \
id)
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW(id)
Extend Rx FIFO Mask helper macro Type C mid-lower part helper macro.
Definition: fsl_flexcan.h:134

#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_LOW | ( |  | id | ) | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id)

## Typedef Documentation

typedef void(* flexcan_transfer_callback_t)(CAN_Type *base, flexcan_handle_t *handle, status_t status, uint32_t result, void *userData)

The FlexCAN transfer callback returns a value from the underlying layer. If the status equals to kStatus_FLEXCAN_ErrorStatus, the result parameter is the Content of FlexCAN status register which can be used to get the working status(or error status) of FlexCAN module. If the status equals to other FlexCAN Message Buffer transfer status, the result is the index of Message Buffer that generate transfer event. If the status equals to other FlexCAN Message Buffer transfer status, the result is meaningless and should be Ignored.

## Enumeration Type Documentation

enum _flexcan_status

Enumerator
kStatus_FLEXCAN_TxBusy | Tx Message Buffer is Busy.
kStatus_FLEXCAN_TxIdle | Tx Message Buffer is Idle.
kStatus_FLEXCAN_TxSwitchToRx | Remote Message is send out and Message buffer changed to Receive one.
kStatus_FLEXCAN_RxBusy | Rx Message Buffer is Busy.
kStatus_FLEXCAN_RxIdle | Rx Message Buffer is Idle.
kStatus_FLEXCAN_RxOverflow | Rx Message Buffer is Overflowed.
kStatus_FLEXCAN_RxFifoBusy | Rx Message FIFO is Busy.
kStatus_FLEXCAN_RxFifoIdle | Rx Message FIFO is Idle.
kStatus_FLEXCAN_RxFifoOverflow | Rx Message FIFO is overflowed.
kStatus_FLEXCAN_RxFifoWarning | Rx Message FIFO is almost overflowed.
kStatus_FLEXCAN_ErrorStatus | FlexCAN Module Error and Status.
kStatus_FLEXCAN_UnHandled | UnHadled Interrupt asserted.

enum flexcan_frame_format_t

Enumerator
kFLEXCAN_FrameFormatStandard | Standard frame format attribute.
kFLEXCAN_FrameFormatExtend | Extend frame format attribute.

enum flexcan_frame_type_t

Enumerator
kFLEXCAN_FrameTypeData | Data frame type attribute.
kFLEXCAN_FrameTypeRemote | Remote frame type attribute.

enum flexcan_clock_source_t

Enumerator
kFLEXCAN_ClkSrcOsc | FlexCAN Protocol Engine clock from Oscillator.
kFLEXCAN_ClkSrcPeri | FlexCAN Protocol Engine clock from Peripheral Clock.

enum flexcan_rx_fifo_filter_type_t

Enumerator
kFLEXCAN_RxFifoFilterTypeA | One full ID (standard and extended) per ID Filter element.
kFLEXCAN_RxFifoFilterTypeB | Two full standard IDs or two partial 14-bit ID slices per ID Filter Table element.
kFLEXCAN_RxFifoFilterTypeC | Four partial 8-bit Standard or extended ID slices per ID Filter Table element.
kFLEXCAN_RxFifoFilterTypeD | All frames rejected.

enum flexcan_rx_fifo_priority_t

The matching process starts from the Rx MB(or Rx FIFO) with higher priority. If no MB(or Rx FIFO filter) is satisfied, the matching process goes on with the Rx FIFO(or Rx MB) with lower priority.

Enumerator
kFLEXCAN_RxFifoPrioLow | Matching process start from Rx Message Buffer first.
kFLEXCAN_RxFifoPrioHigh | Matching process start from Rx FIFO first.

enum _flexcan_interrupt_enable

This structure contains the settings for all of the FlexCAN Module interrupt configurations. Note: FlexCAN Message Buffers and Rx FIFO have their own interrupts.

Enumerator
kFLEXCAN_BusOffInterruptEnable | Bus Off interrupt.
kFLEXCAN_ErrorInterruptEnable | Error interrupt.
kFLEXCAN_RxWarningInterruptEnable | Rx Warning interrupt.
kFLEXCAN_TxWarningInterruptEnable | Tx Warning interrupt.
kFLEXCAN_WakeUpInterruptEnable | Wake Up interrupt.

enum _flexcan_flags

This provides constants for the FlexCAN status flags for use in the FlexCAN functions. Note: The CPU read action clears FlEXCAN_ErrorFlag, therefore user need to read FlEXCAN_ErrorFlag and distinguish which error is occur using _flexcan_error_flags enumerations.

Enumerator
kFLEXCAN_SynchFlag | CAN Synchronization Status.
kFLEXCAN_TxWarningIntFlag | Tx Warning Interrupt Flag.
kFLEXCAN_RxWarningIntFlag | Rx Warning Interrupt Flag.
kFLEXCAN_TxErrorWarningFlag | Tx Error Warning Status.
kFLEXCAN_RxErrorWarningFlag | Rx Error Warning Status.
kFLEXCAN_IdleFlag | CAN IDLE Status Flag.
kFLEXCAN_FaultConfinementFlag | Fault Confinement State Flag.
kFLEXCAN_TransmittingFlag | FlexCAN In Transmission Status.
kFLEXCAN_ReceivingFlag | FlexCAN In Reception Status.
kFLEXCAN_BusOffIntFlag | Bus Off Interrupt Flag.
kFLEXCAN_ErrorIntFlag | Error Interrupt Flag.
kFLEXCAN_WakeUpIntFlag | Wake-Up Interrupt Flag.
kFLEXCAN_ErrorFlag | All FlexCAN Error Status.

enum _flexcan_error_flags

The FlexCAN Error Status enumerations is used to report current error of the FlexCAN bus. This enumerations should be used with KFLEXCAN_ErrorFlag in _flexcan_flags enumerations to ditermine which error is generated.

Enumerator
kFLEXCAN_StuffingError | Stuffing Error.
kFLEXCAN_FormError | Form Error.
kFLEXCAN_CrcError | Cyclic Redundancy Check Error.
kFLEXCAN_AckError | Received no ACK on transmission.
kFLEXCAN_Bit0Error | Unable to send dominant bit.
kFLEXCAN_Bit1Error | Unable to send recessive bit.

enum _flexcan_rx_fifo_flags

The FlexCAN Rx FIFO Status enumerations are used to determine the status of the Rx FIFO. Because Rx FIFO occupy the MB0 ~ MB7 (Rx Fifo filter also occupies more Message Buffer space), Rx FIFO status flags are mapped to the corresponding Message Buffer status flags.

Enumerator
kFLEXCAN_RxFifoOverflowFlag | Rx FIFO overflow flag.
kFLEXCAN_RxFifoWarningFlag | Rx FIFO almost full flag.
kFLEXCAN_RxFifoFrameAvlFlag | Frames available in Rx FIFO flag.

## Function Documentation

void FLEXCAN_Init | ( | CAN_Type * | base,
|  | const flexcan_config_t * | config,
|  | uint32_t | sourceClock_Hz
| ) |  |

This function initializes the FlexCAN module with user-defined settings. This example shows how to set up the flexcan_config_t parameters and how to call the FLEXCAN_Init function by passing in these parameters:

flexcan_config_t flexcanConfig;
flexcanConfig.clkSrc = KFLEXCAN_ClkSrcOsc;
flexcanConfig.baudRate = 125000U;
flexcanConfig.maxMbNum = 16;
flexcanConfig.enableLoopBack = false;
flexcanConfig.enableSelfWakeup = false;
flexcanConfig.enableIndividMask = false;
flexcanConfig.enableDoze = false;
FLEXCAN_Init(CAN0, &flexcanConfig, 8000000UL);

Parameters

  base | FlexCAN peripheral base address.
  config | Pointer to user-defined configuration structure.
  sourceClock_Hz | FlexCAN Protocol Engine clock source frequency in Hz.

void FLEXCAN_Deinit | ( | CAN_Type * | base | ) |

This function disable the FlexCAN module clock and set all register value to reset value.

Parameters

  base | FlexCAN peripheral base address.

void FLEXCAN_GetDefaultConfig | ( | flexcan_config_t * | config | ) |

This function initializes the FlexCAN configure structure to default value. The default value are: flexcanConfig->clkSrc = KFLEXCAN_ClkSrcOsc; flexcanConfig->baudRate = 125000U; flexcanConfig->maxMbNum = 16; flexcanConfig->enableLoopBack = false; flexcanConfig->enableSelfWakeup = false; flexcanConfig->enableIndividMask = false; flexcanConfig->enableDoze = false;

Parameters

  config | Pointer to FlexCAN configuration structure.

void FLEXCAN_SetTimingConfig | ( | CAN_Type * | base,
|  | const flexcan_timing_config_t * | config
| ) |  |

This function gives user settings to CAN bus timing characteristic. The function is for an experienced user. For less experienced users, call the FLEXCAN_Init() and fill the baud rate field with a desired value. This provides the default timing characteristics to the module.

Note that calling FLEXCAN_SetTimingConfig() overrides the baud rate set in FLEXCAN_Init().

Parameters

  base | FlexCAN peripheral base address.
  config | Pointer to the timing configuration structure.

void FlEXCAN_SetRxMbGlobalMask | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |

This function sets the global mask for FlexCAN message buffer in a matching process. The configuration is only effective when the Rx individual mask is disabled in the FLEXCAN_Init().

Parameters

  base | FlexCAN peripheral base address.
  mask | Rx Message Buffer Global Mask value.

void FlEXCAN_SetRxFifoGlobalMask | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |

This function sets the global mask for FlexCAN FIFO in a matching process.

Parameters

  base | FlexCAN peripheral base address.
  mask | Rx Fifo Global Mask value.

void FlEXCAN_SetRxIndividualMask | ( | CAN_Type * | base,
|  | uint8_t | maskIdx,
|  | uint32_t | mask
| ) |  |

This function sets the individual mask for FlexCAN matching process. The configuration is only effective when the Rx individual mask is enabled in FLEXCAN_Init(). If Rx FIFO is disabled, the individual mask is applied to the corresponding Message Buffer. If Rx FIFO is enabled, the individual mask for Rx FIFO occupied Message Buffer is applied to the Rx Filter with same index. What calls for special attention is that only the first 32 individual masks can be used as Rx FIFO filter mask.

Parameters

  base | FlexCAN peripheral base address.
  maskIdx | The Index of individual Mask.
  mask | Rx Individual Mask value.

void FLEXCAN_SetTxMbConfig | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | bool | enable
| ) |  |

This function aborts the previous transmission, cleans the Message Buffer, and configures it as a Transmit Message Buffer.

Parameters

  base | FlexCAN peripheral base address.
  mbIdx | The Message Buffer index.
  enable | Enable/Disable Tx Message Buffer. true: Enable Tx Message Buffer. false: Disable Tx Message Buffer.

void FLEXCAN_SetRxMbConfig | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | const flexcan_rx_mb_config_t * | config,
|  | bool | enable
| ) |  |

This function cleans a FlexCAN build-in Message Buffer and configures it as a Receive Message Buffer.

Parameters

  base | FlexCAN peripheral base address.
  mbIdx | The Message Buffer index.
  config | Pointer to FlexCAN Message Buffer configuration structure.
  enable | Enable/Disable Rx Message Buffer. true: Enable Rx Message Buffer. false: Disable Rx Message Buffer.

void FlEXCAN_SetRxFifoConfig | ( | CAN_Type * | base,
|  | const flexcan_rx_fifo_config_t * | config,
|  | bool | enable
| ) |  |

This function configures the Rx FIFO with given Rx FIFO configuration.

Parameters

  base | FlexCAN peripheral base address.
  config | Pointer to FlexCAN Rx FIFO configuration structure.
  enable | Enable/Disable Rx FIFO. true: Enable Rx FIFO. false: Disable Rx FIFO.

static uint32_t FLEXCAN_GetStatusFlags | ( | CAN_Type * | base | ) |
| inline static

This function gets all FlexCAN status flags. The flags are returned as the logical OR value of the enumerators _flexcan_flags. To check the specific status, compare the return value with enumerators in _flexcan_flags.

Parameters

  base | FlexCAN peripheral base address.

Returns
  FlexCAN status flags which are ORed by the enumerators in the _flexcan_flags.

static void FLEXCAN_ClearStatusFlags | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |
| inline static

This function clears the FlexCAN status flags with a provided mask. An automatically cleared flag can't be cleared by this function.

Parameters

  base | FlexCAN peripheral base address.
  mask | The status flags to be cleared, it is logical OR value of _flexcan_flags.

static void FlEXCAN_GetBusErrCount | ( | CAN_Type * | base,
|  | uint8_t * | txErrBuf,
|  | uint8_t * | rxErrBuf
| ) |  |
| inline static

This function gets the FlexCAN Bus Error Counter value for both Tx and Rx direction. These values may be needed in the upper layer error handling.

Parameters

  base | FlexCAN peripheral base address.
  txErrBuf | Buffer to store Tx Error Counter value.
  rxErrBuf | Buffer to store Rx Error Counter value.

static uint32_t FLEXCAN_GetMbStatusFlags | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |
| inline static

This function gets the interrupt flags of a given Message Buffers.

Parameters

  base | FlexCAN peripheral base address.
  mask | The ORed FlexCAN Message Buffer mask.

Returns
  The status of given Message Buffers.

static void FLEXCAN_ClearMbStatusFlags | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |
| inline static

This function clears the interrupt flags of a given Message Buffers.

Parameters

  base | FlexCAN peripheral base address.
  mask | The ORed FlexCAN Message Buffer mask.

static void FLEXCAN_EnableInterrupts | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |
| inline static

This function enables the FlexCAN interrupts according to provided mask. The mask is a logical OR of enumeration members, see _flexcan_interrupt_enable.

Parameters

  base | FlexCAN peripheral base address.
  mask | The interrupts to enable. Logical OR of _flexcan_interrupt_enable.

static void FLEXCAN_DisableInterrupts | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |
| inline static

This function disables the FlexCAN interrupts according to provided mask. The mask is a logical OR of enumeration members, see _flexcan_interrupt_enable.

Parameters

  base | FlexCAN peripheral base address.
  mask | The interrupts to disable. Logical OR of _flexcan_interrupt_enable.

static void FLEXCAN_EnableMbInterrupts | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |
| inline static

This function enables the interrupts of given Message Buffers

Parameters

  base | FlexCAN peripheral base address.
  mask | The ORed FlexCAN Message Buffer mask.

static void FLEXCAN_DisableMbInterrupts | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |
| inline static

This function disables the interrupts of given Message Buffers

Parameters

  base | FlexCAN peripheral base address.
  mask | The ORed FlexCAN Message Buffer mask.

static void FLEXCAN_Enable | ( | CAN_Type * | base,
|  | bool | enable
| ) |  |
| inline static

This function enables or disables the FlexCAN module.

Parameters

  base | FlexCAN base pointer.
  enable | true to enable, false to disable.

status_t FLEXCAN_WriteTxMb | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | const flexcan_frame_t * | txFrame
| ) |  |

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

  base | FlexCAN peripheral base address.
  mbIdx | The FlexCAN Message Buffer index.
  txFrame | Pointer to CAN message frame to be sent.

Return values

  kStatus_Success | - Write Tx Message Buffer Successfully.
  kStatus_Fail | - Tx Message Buffer is currently in use.

status_t FLEXCAN_ReadRxMb | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | flexcan_frame_t * | rxFrame
| ) |  |

This function reads a CAN message from a specified Receive Message Buffer. The function fills a receive CAN message frame structure with just received data and activates the Message Buffer again. The function returns immediately.

Parameters

  base | FlexCAN peripheral base address.
  mbIdx | The FlexCAN Message Buffer index.
  rxFrame | Pointer to CAN message frame structure for reception.

Return values

  kStatus_Success | - Rx Message Buffer is full and has been read successfully.
  kStatus_FLEXCAN_RxOverflow | - Rx Message Buffer is already overflowed and has been read successfully.
  kStatus_Fail | - Rx Message Buffer is empty.

status_t FlEXCAN_ReadRxFifo | ( | CAN_Type * | base,
|  | flexcan_frame_t * | rxFrame
| ) |  |

This function reads a CAN message from the FlexCAN build-in Rx FIFO.

Parameters

  base | FlexCAN peripheral base address.
  rxFrame | Pointer to CAN message frame structure for reception.

Return values

  kStatus_Success | - Read Message from Rx FIFO successfully.
  kStatus_Fail | - Rx FIFO is not enabled.

status_t FlEXCAN_TransferSendBlocking | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | flexcan_frame_t * | txFrame
| ) |  |

Note that a transfer handle does not need to be created before calling this API.

Parameters

  base | FlexCAN peripheral base pointer.
  mbIdx | The FlexCAN Message Buffer index.
  txFrame | Pointer to CAN message frame to be sent.

Return values

  kStatus_Success | - Write Tx Message Buffer Successfully.
  kStatus_Fail | - Tx Message Buffer is currently in use.

status_t FlEXCAN_TransferReceiveBlocking | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | flexcan_frame_t * | rxFrame
| ) |  |

Note that a transfer handle does not need to be created before calling this API.

Parameters

  base | FlexCAN peripheral base pointer.
  mbIdx | The FlexCAN Message Buffer index.
  rxFrame | Pointer to CAN message frame structure for reception.

Return values

  kStatus_Success | - Rx Message Buffer is full and has been read successfully.
  kStatus_FLEXCAN_RxOverflow | - Rx Message Buffer is already overflowed and has been read successfully.
  kStatus_Fail | - Rx Message Buffer is empty.

status_t FlEXCAN_TransferReceiveFifoBlocking | ( | CAN_Type * | base,
|  | flexcan_frame_t * | rxFrame
| ) |  |

Note that a transfer handle does not need to be created before calling this API.

Parameters

  base | FlexCAN peripheral base pointer.
  rxFrame | Pointer to CAN message frame structure for reception.

Return values

  kStatus_Success | - Read Message from Rx FIFO successfully.
  kStatus_Fail | - Rx FIFO is not enabled.

void FLEXCAN_TransferCreateHandle | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle,
|  | flexcan_transfer_callback_t | callback,
|  | void * | userData
| ) |  |

This function initializes the FlexCAN handle which can be used for other FlexCAN transactional APIs. Usually, for a specified FlexCAN instance, call this API once to get the initialized handle.

Parameters

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.
  callback | The callback function.
  userData | The parameter of the callback function.

status_t FLEXCAN_TransferSendNonBlocking | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle,
|  | flexcan_mb_transfer_t * | xfer
| ) |  |

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

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.
  xfer | FlexCAN Message Buffer transfer structure. See the flexcan_mb_transfer_t.

Return values

  kStatus_Success | Start Tx Message Buffer sending process successfully.
  kStatus_Fail | Write Tx Message Buffer failed.
  kStatus_FLEXCAN_TxBusy | Tx Message Buffer is in use.

status_t FLEXCAN_TransferReceiveNonBlocking | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle,
|  | flexcan_mb_transfer_t * | xfer
| ) |  |

This function receives a message using IRQ. This is non-blocking function, which returns right away. When the message has been received, the receive callback function is called.

Parameters

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.
  xfer | FlexCAN Message Buffer transfer structure. See the flexcan_mb_transfer_t.

Return values

  kStatus_Success | - Start Rx Message Buffer receiving process successfully.
  kStatus_FLEXCAN_RxBusy | - Rx Message Buffer is in use.

status_t FLEXCAN_TransferReceiveFifoNonBlocking | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle,
|  | flexcan_fifo_transfer_t * | xfer
| ) |  |

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

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.
  xfer | FlexCAN Rx FIFO transfer structure. See the flexcan_fifo_transfer_t.

Return values

  kStatus_Success | - Start Rx FIFO receiving process successfully.
  kStatus_FLEXCAN_RxFifoBusy | - Rx FIFO is currently in use.

void FLEXCAN_TransferAbortSend | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle,
|  | uint8_t | mbIdx
| ) |  |

This function aborts the interrupt driven message send process.

Parameters

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.
  mbIdx | The FlexCAN Message Buffer index.

void FLEXCAN_TransferAbortReceive | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle,
|  | uint8_t | mbIdx
| ) |  |

This function aborts the interrupt driven message receive process.

Parameters

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.
  mbIdx | The FlexCAN Message Buffer index.

void FLEXCAN_TransferAbortReceiveFifo | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle
| ) |  |

This function aborts the interrupt driven message receive from Rx FIFO process.

Parameters

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.

void FLEXCAN_TransferHandleIRQ | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle
| ) |  |

This function handles the FlexCAN Error, the Message Buffer, and the Rx FIFO IRQ request.

Parameters

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.