Flex Controller Area Network (FlexCAN)
Collaboration diagram for Flex Controller Area Network (FlexCAN):

## Modules

| FlexCAN driver

## Data Structures

struct | flexcan_frame_t
| FlexCAN message frame structure. More...
struct | flexcan_frame_t.__unnamed__
struct | flexcan_frame_t.__unnamed__.__unnamed__
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...

## 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...

## 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)
| Setting FlexCAN protocol timing characteristic. More...
void | FlEXCAN_SetRxMbGlobalMask (CAN_Type *base, uint32_t mask)
| Set the FlexCAN Receive Message Buffer Global Mask. More...
void | FlEXCAN_SetRxFifoGlobalMask (CAN_Type *base, uint32_t mask)
| Set the FlexCAN Receive FIFO Global Mask. More...
void | FlEXCAN_SetRxIndividualMask (CAN_Type *base, uint8_t maskIdx, uint32_t mask)
| Set the FlexCAN Receive Individual Mask. More...
void | FLEXCAN_SetTxMbConfig (CAN_Type *base, uint8_t mbIdx, bool enable)
| Configure a FlexCAN Transmit Message Buffer. More...
void | FLEXCAN_SetRxMbConfig (CAN_Type *base, uint8_t mbIdx, const flexcan_rx_mb_config_t *config, bool enable)
| Configure a FlexCAN Receive Message Buffer. More...
void | FlEXCAN_SetRxFifoConfig (CAN_Type *base, const flexcan_rx_fifo_config_t *config, bool enable)
| Configure the FlexCAN Rx FIFO. More...

## Status

static uint64_t uint32_t | mask
base | IFLAG2 = (uint32_t)(mask >> 32)
base | IFLAG1 = mask
static uint32_t | FLEXCAN_GetStatusFlags (CAN_Type *base)
| Get FlexCAN module interrupt flags. More...
static void | FLEXCAN_ClearStatusFlags (CAN_Type *base, uint32_t mask)
| Clear status flags with provide mask. More...
static void | FlEXCAN_GetBusErrCount (CAN_Type *base, uint8_t *txErrBuf, uint8_t *rxErrBuf)
| Get the FlexCAN Bus Error Counter value. More...
static uint64_t | FLEXCAN_GetMbStatusFlags (CAN_Type *base, uint64_t mask) static inline uint32_t FLEXCAN_GetMbStatusFlags(CAN_Type *base
| Get FlexCAN Message Buffer interrupt flags. More...
| return (base->IFLAG1 &mask)
static void | FLEXCAN_ClearMbStatusFlags (CAN_Type *base, uint64_t mask) static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base
| Clear FlexCAN Message Buffer interrupt flags. More...

## Interrupts

base | IMASK2 = (uint32_t)(mask >> 32)
base | IMASK1 = mask
static void | FLEXCAN_EnableInterrupts (CAN_Type *base, uint32_t mask)
| Enable FlexCAN interrupts according to provided mask. More...
static void | FLEXCAN_DisableInterrupts (CAN_Type *base, uint32_t mask)
| Disable FlexCAN interrupts according to provided mask. More...
static void | FLEXCAN_EnableMbInterrupts (CAN_Type *base, uint64_t mask) static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base
| Enable FlexCAN Message Buffer interrupts. More...
static void | FLEXCAN_DisableMbInterrupts (CAN_Type *base, uint64_t mask) static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base
| Disable FlexCAN Message Buffer interrupts. More...

## DMA Control

void | FLEXCAN_EnableRxFifoDMA (CAN_Type *base, bool enable)
| Enable or disable FlexCAN Rx FIFO DMA request. More...
static uint32_t | FLEXCAN_GetRxFifoHeadAddr (CAN_Type *base)
| Get the Rx FIFO Head address. More...

## Bus Operations

static void | FLEXCAN_Enable (CAN_Type *base, bool enable)
| Enables or disable the FlexCAN module operation. More...
status_t | FLEXCAN_WriteTxMb (CAN_Type *base, uint8_t mbIdx, const flexcan_frame_t *txFrame)
| Write FlexCAN Message to Transmit Message Buffer. More...
status_t | FLEXCAN_ReadRxMb (CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *rxFrame)
| Read a FlexCAN Message from Receive Message Buffer. More...
status_t | FlEXCAN_ReadRxFifo (CAN_Type *base, flexcan_frame_t *rxFrame)
| Read 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)
| Initialize the FlexCAN handle. More...
status_t | FLEXCAN_TransferSendNonBlocking (CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer)
| send message using IRQ More...
status_t | FLEXCAN_TransferReceiveNonBlocking (CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer)
| Receive message using IRQ. More...
status_t | FLEXCAN_TransferReceiveFifoNonBlocking (CAN_Type *base, flexcan_handle_t *handle, flexcan_fifo_transfer_t *xfer)
| Receive message from Rx FIFO using IRQ. More...
void | FLEXCAN_TransferAbortSend (CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx)
| Abort interrupt driven message send process. More...
void | FLEXCAN_TransferAbortReceive (CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx)
| Abort interrupt driven message receive process. More...
void | FLEXCAN_TransferAbortReceiveFifo (CAN_Type *base, flexcan_handle_t *handle)
| Abort interrupt driven message receive from Rx FIFO process. More...
void | FLEXCAN_TransferHandleIRQ (CAN_Type *base, flexcan_handle_t *handle)
| FlexCAN IRQ handle function. More...

## Usage Information

The KSDK provides a peripheral driver for the Flex Controller Area Network (FlexCAN) module of Kinetis devices.

## Data Structure Documentation

struct flexcan_frame_t

FlexCAN message frame structure.

Data Fields
struct flexcan_frame_t | __unnamed__ |
struct flexcan_frame_t | __unnamed__ |
union flexcan_frame_t | __unnamed__ |

struct flexcan_frame_t.__unnamed__

Data Fields
uint32_t | format: 1 | CAN Frame Identifier(STD or EXT format).
uint32_t | idhit: 9 | CAN Rx FIFO filter hit id(This value is only used in Rx FIFO receive mode).
uint32_t | length: 4 | CAN frame payload length in bytes(Range: 0~8).
uint32_t | reserve1: 1 | Reserved for placeholder.
uint32_t | timestamp: 16 | FlexCAN internal Free-Running Counter Time Stamp.
uint32_t | type: 1 | CAN Frame Type(DATA or REMOTE).

struct flexcan_frame_t.__unnamed__.__unnamed__

Data Fields
uint32_t | dataWord0 | CAN Frame payload word0.
uint32_t | dataWord1 | CAN Frame payload word1.

struct flexcan_config_t

FlexCAN module configuration structure.

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

struct flexcan_timing_config_t

FlexCAN protocol timing characteristic configuration structure.

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

struct flexcan_rx_mb_config_t

FlexCAN Receive Message Buffer configuration structure.

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
flexcan_frame_format_t | format | CAN Frame Identifier format(Standard of Extend).
uint32_t | id | CAN Message Buffer Frame Identifier, should be set using FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro.
flexcan_frame_type_t | type | CAN Frame Type(Data or Remote).

struct flexcan_rx_fifo_config_t

FlexCAN Rx FIFO configure structure.

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

struct flexcan_mb_transfer_t

FlexCAN Message Buffer transfer.

Collaboration diagram for flexcan_mb_transfer_t:
[legend]

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

struct flexcan_fifo_transfer_t

FlexCAN Rx FIFO transfer.

Collaboration diagram for flexcan_fifo_transfer_t:
[legend]

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

struct _flexcan_handle

FlexCAN handle structure.

FlexCAN handle structure definition.

Collaboration diagram for flexcan_handle_t:
[legend]

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

## Typedef Documentation

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.

The FlexCAN transfer callback will return value from the underlying layer. If the status equals to kStatus_FLEXCAN_ErrorStatus, the result parameter will be 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 will be 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_error_flags

FlexCAN error status 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_flags

FlexCAN status 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_interrupt_enable

FlexCAN interrupt configuration structure, default settings all disabled.

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_rx_fifo_flags

FlexCAN Rx FIFO status flags.

The FlexCAN Rx FIFO Status enumerations is used to ditermine the status of Rx FIFO. Because Rx FIFO occupy the MB0 ~ MB7(Rx Fifo filter will also occupy more Message Buffer space), Rx FIFO status flags are maped to 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.

enum _flexcan_status

FlexCAN transfer 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_clock_source_t

FlexCAN clock source.

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

enum flexcan_frame_format_t

FlexCAN frame format.

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

enum flexcan_frame_type_t

FlexCAN frame type.

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

enum flexcan_rx_fifo_filter_type_t

FlexCAN Rx Fifo Filter type.

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

FlexCAN Rx FIFO priority.

The matching process will start from the Rx MB(or Rx FIFO) with higher priority. If no MB(or Rx FIFO filter) is satisfied, the matching process will go 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

## Function Documentation

static void FLEXCAN_ClearMbStatusFlags | ( | CAN_Type * | base,
|  | uint64_t | mask
| ) |  |

inlinestatic

Clear FlexCAN Message Buffer interrupt flags.

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

Parameters

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

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

inlinestatic

Clear status flags with provide mask.

This function clears FlexCAN status flags with provided mask. 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.

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

De-initializes a FlexCAN instance.

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

Parameters

  base | FlexCAN peripheral base address.

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

inlinestatic

Disable FlexCAN interrupts according to provided mask.

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_DisableMbInterrupts | ( | CAN_Type * | base,
|  | uint64_t | mask
| ) |  |

inlinestatic

Disable FlexCAN Message Buffer interrupts.

This function disable 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
| ) |  |

inlinestatic

Enables or disable the FlexCAN module operation.

This function enables or disables the FlexCAN module.

Parameters

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

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

inlinestatic

Enable FlexCAN interrupts according to provided mask.

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_EnableMbInterrupts | ( | CAN_Type * | base,
|  | uint64_t | mask
| ) |  |

inlinestatic

Enable FlexCAN Message Buffer interrupts.

This function enable the interrupts of given Message Buffers

Parameters

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

void FLEXCAN_EnableRxFifoDMA | ( | CAN_Type * | base,
|  | bool | enable
| ) |  |

Enable or disable FlexCAN Rx FIFO DMA request.

This function enable or disable the DMA feature of FlexCAN build-in Rx FIFO.

Parameters

  base | FlexCAN peripheral base address.
  enable | true to enable, false to disable.

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

inlinestatic

Get the FlexCAN Bus Error Counter value.

This function get the FlexCAN Bus Error Counter value for both Tx & Rx direction. These values may needed in 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.

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

Get the default configuration structure.

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.

static uint64_t FLEXCAN_GetMbStatusFlags | ( | CAN_Type * | base,
|  | uint64_t | mask
| ) |  |

inlinestatic

Get FlexCAN Message Buffer interrupt flags.

This function get 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 uint32_t FLEXCAN_GetRxFifoHeadAddr | ( | CAN_Type * | base | ) |

inlinestatic

Get the Rx FIFO Head address.

This function return the FlexCAN Rx FIFO Head address, which is mainly used by DMA/eDMA case.

Parameters

  base | FlexCAN peripheral base address.

Returns
  FlexCAN Rx FIFO Head address.

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

inlinestatic

Get FlexCAN module interrupt flags.

This function get all FlexCAN status flags, the flags are returned as the logical OR value of the enumerators _flexcan_flags. To check 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.

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

Initializes a FlexCAN instance.

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.

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

Read a FlexCAN Message from Rx FIFO.

This function Read 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_ReadRxMb | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | flexcan_frame_t * | rxFrame
| ) |  |

Read a FlexCAN Message from Receive Message Buffer.

This function read a CAN message from a specified Receive Message Buffer. The function will fill receive CAN message frame structure with just received data and activate the Message Buffer again. The function will return 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.

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

Configure the FlexCAN Rx FIFO.

This function Configure 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.

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

Set the FlexCAN Receive FIFO Global Mask.

This function Set the global mask for FlexCAN FIFO in 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
| ) |  |

Set the FlexCAN Receive Individual Mask.

This function Set the Individual mask for FlexCAN matching process. The configuration is only effective when Rx Individual Mask is enabled in FLEXCAN_Init(). If Rx FIFO is disabled, the Individual Mask is applied to corresponding Message Buffer. If Rx FIFO is enabled, the Individual Mask for Rx FIFO occupied Message Buffer will be applied to Rx Filter with same index. What calls for special attention is that only the first 32 Individual Mask 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_SetRxMbConfig | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | const flexcan_rx_mb_config_t * | config,
|  | bool | enable
| ) |  |

Configure a FlexCAN Receive Message Buffer.

This function clean a FlexCAN build-in Message Buffer and configure 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_SetRxMbGlobalMask | ( | CAN_Type * | base,
|  | uint32_t | mask
| ) |  |

Set the FlexCAN Receive Message Buffer Global Mask.

This function Set the global mask for FlexCAN Message Buffer in matching process. The configuration is only effective when Rx Individual Mask is disabled in FLEXCAN_Init().

Parameters

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

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

Setting FlexCAN protocol timing characteristic.

This function give user fine settings to CAN bus timing characteristic. The function is for user who is really versed in CAN protocol, for these users who just what to establish CAN communication among MCUs, just call FLEXCAN_Init() and fill the baud rate field with desired one. Doing this, default timing characteristic will provide to the module.

Note: Calling FLEXCAN_SetTimingConfig() will override the baud rate setted in FLEXCAN_Init().

Parameters

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

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

Configure a FlexCAN Transmit Message Buffer.

This function abort privious transmission, clean the Message Buffer and configure 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_TransferAbortReceive | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle,
|  | uint8_t | mbIdx
| ) |  |

Abort interrupt driven message receive process.

This function abort 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
| ) |  |

Abort interrupt driven message receive from Rx FIFO process.

This function abort interrupt driven message receive from Rx FIFO process.

Parameters

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

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

Abort interrupt driven message send process.

This function aborts interrupt driven message send process.

Parameters

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

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

Initialize the FlexCAN handle.

This function initializes the FlexCAN handle which can be used for other FlexCAN transactional APIs. Usually, for a specified FlexCAN instance, user only need to 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.

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

FlexCAN IRQ handle function.

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

Parameters

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

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

Performs a polling receive transaction on the CAN bus.

Note: There is no need to create transfer handle 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
| ) |  |

Performs a polling receive transaction from Rx FIFO on the CAN bus.

Note: There is no need to create transfer handle 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.

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

Receive message from Rx FIFO using IRQ.

This function receive message using IRQ, this is non-blocking function, will return right away, when all messages have been received, the receive callback function will be called.

Parameters

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.
  xfer | FlexCAN Rx FIFO transfer structure, refer to flexcan_fifo_transfer_t.

Return values

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

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

Receive message using IRQ.

This function receive message using IRQ, this is non-blocking function, will return right away, when message have been received, the receive callback function will be called.

Parameters

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.
  xfer | FlexCAN Message Buffer transfer structure, refer to 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_TransferSendBlocking | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | flexcan_frame_t * | txFrame
| ) |  |

Performs a polling send transaction on the CAN bus.

Note: There is no need to create transfer handle 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_TransferSendNonBlocking | ( | CAN_Type * | base,
|  | flexcan_handle_t * | handle,
|  | flexcan_mb_transfer_t * | xfer
| ) |  |

send message using IRQ

This function send message using IRQ, this is non-blocking function, will return right away, when message have been sent out, the send callback function will be called.

Parameters

  base | FlexCAN peripheral base address.
  handle | FlexCAN handle pointer.
  xfer | FlexCAN Message Buffer transfer structure, refer to 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_WriteTxMb | ( | CAN_Type * | base,
|  | uint8_t | mbIdx,
|  | const flexcan_frame_t * | txFrame
| ) |  |

Write FlexCAN Message to Transmit Message Buffer.

This function write a CAN Message to the specified Transmit Message Buffer and change the Message Buffer state to start CAN Message transmit, after that the function will return 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.

## Variable Documentation

static void uint32_t mask

Initial value:
{
#if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
return ((((uint64_t)base->IFLAG1) & mask) | ((((uint64_t)base->IFLAG2) << 32) & mask))