MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
MCAN: Controller Area Network Driver

Overview

The MCUXpresso SDK provides a peripheral driver for the Controller Area Network (MCAN) module of MCUXpresso SDK devices.

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 status, uint32_t result, void *userData)
 MCAN transfer callback function. More...
 

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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
enum  mcan_frame_idformat_t {
  kMCAN_FrameIDStandard = 0x0U,
  kMCAN_FrameIDExtend = 0x1U
}
 MCAN frame format. More...
 
enum  mcan_frame_type_t {
  kMCAN_FrameTypeData = 0x0U,
  kMCAN_FrameTypeRemote = 0x1U
}
 MCAN frame type. More...
 
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. More...
 
enum  mcan_fifo_type_t {
  kMCAN_Fifo0 = 0x0U,
  kMCAN_Fifo1 = 0x1U
}
 MCAN Rx FIFO block number. More...
 
enum  mcan_fifo_opmode_config_t {
  kMCAN_FifoBlocking = 0,
  kMCAN_FifoOverwrite = 1
}
 MCAN FIFO Operation Mode. More...
 
enum  mcan_txmode_config_t {
  kMCAN_txFifo = 0,
  kMCAN_txQueue = 1
}
 MCAN Tx FIFO/Queue Mode. More...
 
enum  mcan_remote_frame_config_t {
  kMCAN_filterFrame = 0,
  kMCAN_rejectFrame = 1
}
 MCAN remote frames treatment. More...
 
enum  mcan_nonmasking_frame_config_t {
  kMCAN_acceptinFifo0 = 0,
  kMCAN_acceptinFifo1 = 1,
  kMCAN_reject0 = 2,
  kMCAN_reject1 = 3
}
 MCAN non-masking frames treatment. More...
 
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. More...
 
enum  mcan_filter_type_t {
  kMCAN_range = 0,
  kMCAN_dual = 1,
  kMCAN_classic = 2,
  kMCAN_disableORrange2 = 3
}
 MCAN Filter Type. More...
 

Driver version

#define MCAN_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 MCAN driver version 2.0.0. More...
 

Initialization and deinitialization

void MCAN_Init (CAN_Type *base, const mcan_config_t *config, uint32_t sourceClock_Hz)
 Initializes an MCAN instance. More...
 
void MCAN_Deinit (CAN_Type *base)
 Deinitializes an MCAN instance. More...
 
void MCAN_GetDefaultConfig (mcan_config_t *config)
 Gets the default configuration structure. More...
 
void MCAN_EnterNormalMode (CAN_Type *base)
 MCAN enters normal mode. More...
 

Configuration.

static void MCAN_SetMsgRAMBase (CAN_Type *base, uint32_t value)
 Sets the MCAN Message RAM base address. More...
 
static uint32_t MCAN_GetMsgRAMBase (CAN_Type *base)
 Gets the MCAN Message RAM base address. More...
 
void MCAN_SetArbitrationTimingConfig (CAN_Type *base, const mcan_timing_config_t *config)
 Sets the MCAN protocol arbitration phase timing characteristic. More...
 
void MCAN_SetRxFifo0Config (CAN_Type *base, const mcan_rx_fifo_config_t *config)
 Configures an MCAN receive fifo 0 buffer. More...
 
void MCAN_SetRxFifo1Config (CAN_Type *base, const mcan_rx_fifo_config_t *config)
 Configures an MCAN receive fifo 1 buffer. More...
 
void MCAN_SetRxBufferConfig (CAN_Type *base, const mcan_rx_buffer_config_t *config)
 Configures an MCAN receive buffer. More...
 
void MCAN_SetTxEventfifoConfig (CAN_Type *base, const mcan_tx_fifo_config_t *config)
 Configures an MCAN transmit event fifo. More...
 
void MCAN_SetTxBufferConfig (CAN_Type *base, const mcan_tx_buffer_config_t *config)
 Configures an MCAN transmit buffer. More...
 
void MCAN_SetFilterConfig (CAN_Type *base, const mcan_frame_filter_config_t *config)
 Set filter configuration. More...
 
void MCAN_SetSTDFilterElement (CAN_Type *base, const mcan_frame_filter_config_t *config, const mcan_std_filter_element_config_t *filter, uint8_t idx)
 Set filter configuration. More...
 
void MCAN_SetEXTFilterElement (CAN_Type *base, const mcan_frame_filter_config_t *config, const mcan_ext_filter_element_config_t *filter, uint8_t idx)
 Set filter configuration. More...
 

Status

static uint32_t MCAN_GetStatusFlag (CAN_Type *base, uint32_t mask)
 Gets the MCAN module interrupt flags. More...
 
static void MCAN_ClearStatusFlag (CAN_Type *base, uint32_t mask)
 Clears the MCAN module interrupt flags. More...
 
static bool MCAN_GetRxBufferStatusFlag (CAN_Type *base, uint8_t idx)
 Gets the new data flag of specific Rx Buffer. More...
 
static void MCAN_ClearRxBufferStatusFlag (CAN_Type *base, uint8_t idx)
 Clears the new data flag of specific Rx Buffer. More...
 

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. More...
 
static void MCAN_EnableTransmitBufferInterrupts (CAN_Type *base, uint8_t idx)
 Enables MCAN Tx Buffer interrupts according to the provided index. More...
 
static void MCAN_DisableTransmitBufferInterrupts (CAN_Type *base, uint8_t idx)
 Disables MCAN Tx Buffer interrupts according to the provided index. More...
 
static void MCAN_DisableInterrupts (CAN_Type *base, uint32_t mask)
 Disables MCAN interrupts according to the provided mask. More...
 

Bus Operations

status_t MCAN_WriteTxBuffer (CAN_Type *base, uint8_t idx, const mcan_tx_buffer_frame_t *txFrame)
 Writes an MCAN Message to the Transmit Buffer. More...
 
status_t MCAN_ReadRxFifo (CAN_Type *base, uint8_t fifoBlock, mcan_rx_buffer_frame_t *rxFrame)
 Reads an MCAN Message from Rx FIFO. More...
 

Transactional

static void MCAN_TransmitAddRequest (CAN_Type *base, uint8_t idx)
 Tx Buffer add request to send message out. More...
 
static void MCAN_TransmitCancelRequest (CAN_Type *base, uint8_t idx)
 Tx Buffer cancel sending request. More...
 
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. More...
 
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. More...
 
void MCAN_TransferCreateHandle (CAN_Type *base, mcan_handle_t *handle, mcan_transfer_callback_t callback, void *userData)
 Initializes the MCAN handle. More...
 
status_t MCAN_TransferSendNonBlocking (CAN_Type *base, mcan_handle_t *handle, mcan_buffer_transfer_t *xfer)
 Sends a message using IRQ. More...
 
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. More...
 
void MCAN_TransferAbortSend (CAN_Type *base, mcan_handle_t *handle, uint8_t bufferIdx)
 Aborts the interrupt driven message send process. More...
 
void MCAN_TransferAbortReceiveFifo (CAN_Type *base, uint8_t fifoBlock, mcan_handle_t *handle)
 Aborts the interrupt driven message receive from Rx FIFO process. More...
 
void MCAN_TransferHandleIRQ (CAN_Type *base, mcan_handle_t *handle)
 MCAN IRQ handle function. More...
 

Data Structure Documentation

struct mcan_tx_buffer_frame_t

Field Documentation

uint32_t mcan_tx_buffer_frame_t::id
uint32_t mcan_tx_buffer_frame_t::rtr
uint32_t mcan_tx_buffer_frame_t::xtd
uint32_t mcan_tx_buffer_frame_t::esi
uint32_t mcan_tx_buffer_frame_t::dlc
uint32_t mcan_tx_buffer_frame_t::brs
uint32_t mcan_tx_buffer_frame_t::fdf
uint32_t mcan_tx_buffer_frame_t::__pad1__
uint32_t mcan_tx_buffer_frame_t::efc
uint32_t mcan_tx_buffer_frame_t::mm
struct mcan_rx_buffer_frame_t

Field Documentation

uint32_t mcan_rx_buffer_frame_t::id
uint32_t mcan_rx_buffer_frame_t::rtr
uint32_t mcan_rx_buffer_frame_t::xtd
uint32_t mcan_rx_buffer_frame_t::esi
uint32_t mcan_rx_buffer_frame_t::rxts
uint32_t mcan_rx_buffer_frame_t::dlc
uint32_t mcan_rx_buffer_frame_t::brs
uint32_t mcan_rx_buffer_frame_t::fdf
uint32_t mcan_rx_buffer_frame_t::__pad0__
uint32_t mcan_rx_buffer_frame_t::fidx
uint32_t mcan_rx_buffer_frame_t::anmf
struct mcan_rx_fifo_config_t

Data Fields

uint32_t address
 FIFOn start address. More...
 
uint32_t elementSize
 FIFOn element number. More...
 
uint32_t watermark
 FIFOn watermark level. More...
 
mcan_fifo_opmode_config_t opmode
 FIFOn blocking/overwrite mode. More...
 
mcan_bytes_in_datafield_t datafieldSize
 Data field size per frame, size>8 is for CANFD. More...
 

Field Documentation

uint32_t mcan_rx_fifo_config_t::address
uint32_t mcan_rx_fifo_config_t::elementSize
uint32_t mcan_rx_fifo_config_t::watermark
mcan_fifo_opmode_config_t mcan_rx_fifo_config_t::opmode
mcan_bytes_in_datafield_t mcan_rx_fifo_config_t::datafieldSize
struct mcan_rx_buffer_config_t

Data Fields

uint32_t address
 Rx Buffer start address. More...
 
mcan_bytes_in_datafield_t datafieldSize
 Data field size per frame, size>8 is for CANFD. More...
 

Field Documentation

uint32_t mcan_rx_buffer_config_t::address
mcan_bytes_in_datafield_t mcan_rx_buffer_config_t::datafieldSize
struct mcan_tx_fifo_config_t

Data Fields

uint32_t address
 Event fifo start address. More...
 
uint32_t elementSize
 FIFOn element number. More...
 
uint32_t watermark
 FIFOn watermark level. More...
 

Field Documentation

uint32_t mcan_tx_fifo_config_t::address
uint32_t mcan_tx_fifo_config_t::elementSize
uint32_t mcan_tx_fifo_config_t::watermark
struct mcan_tx_buffer_config_t

Data Fields

uint32_t address
 Tx Buffers Start Address. More...
 
uint32_t dedicatedSize
 Number of Dedicated Transmit Buffers. More...
 
uint32_t fqSize
 Transmit FIFO/Queue Size. More...
 
mcan_txmode_config_t mode
 Tx FIFO/Queue Mode. More...
 
mcan_bytes_in_datafield_t datafieldSize
 Data field size per frame, size>8 is for CANFD. More...
 

Field Documentation

uint32_t mcan_tx_buffer_config_t::address
uint32_t mcan_tx_buffer_config_t::dedicatedSize
uint32_t mcan_tx_buffer_config_t::fqSize
mcan_txmode_config_t mcan_tx_buffer_config_t::mode
mcan_bytes_in_datafield_t mcan_tx_buffer_config_t::datafieldSize
struct mcan_std_filter_element_config_t

Data Fields

uint32_t sfid2: 11
 Standard Filter ID 2. More...
 
uint32_t __pad0__: 5
 Reserved. More...
 
uint32_t sfid1: 11
 Standard Filter ID 1. More...
 
mcan_fec_config_t sfec: 3
 Standard Filter Element Configuration. More...
 
mcan_filter_type_t sft: 2
 Standard Filter Type/.
 

Field Documentation

uint32_t mcan_std_filter_element_config_t::sfid2
uint32_t mcan_std_filter_element_config_t::__pad0__
uint32_t mcan_std_filter_element_config_t::sfid1
mcan_fec_config_t mcan_std_filter_element_config_t::sfec
struct mcan_ext_filter_element_config_t

Data Fields

uint32_t efid1: 29
 Extended Filter ID 1. More...
 
mcan_fec_config_t efec: 3
 Extended Filter Element Configuration. More...
 
uint32_t efid2: 29
 Extended Filter ID 2. More...
 
uint32_t __pad0__: 1
 Reserved. More...
 
mcan_filter_type_t eft: 2
 Extended Filter Type. More...
 

Field Documentation

uint32_t mcan_ext_filter_element_config_t::efid1
mcan_fec_config_t mcan_ext_filter_element_config_t::efec
uint32_t mcan_ext_filter_element_config_t::efid2
uint32_t mcan_ext_filter_element_config_t::__pad0__
mcan_filter_type_t mcan_ext_filter_element_config_t::eft
struct mcan_frame_filter_config_t

Data Fields

uint32_t address
 Filter start address. More...
 
uint32_t listSize
 Filter list size. More...
 
mcan_frame_idformat_t idFormat
 Frame format. More...
 
mcan_remote_frame_config_t remFrame
 Remote frame treatment. More...
 
mcan_nonmasking_frame_config_t nmFrame
 Non-masking frame treatment. More...
 

Field Documentation

uint32_t mcan_frame_filter_config_t::address
uint32_t mcan_frame_filter_config_t::listSize
mcan_frame_idformat_t mcan_frame_filter_config_t::idFormat
mcan_remote_frame_config_t mcan_frame_filter_config_t::remFrame
mcan_nonmasking_frame_config_t mcan_frame_filter_config_t::nmFrame
struct mcan_config_t

Data Fields

uint32_t baudRateA
 Baud rate of Arbitration phase in bps. More...
 
uint32_t baudRateD
 Baud rate of Data phase in bps. More...
 
bool enableCanfdNormal
 Enable or Disable CANFD normal. More...
 
bool enableCanfdSwitch
 Enable or Disable CANFD with baudrate switch. More...
 
bool enableLoopBackInt
 Enable or Disable Internal Back. More...
 
bool enableLoopBackExt
 Enable or Disable External Loop Back. More...
 
bool enableBusMon
 Enable or Disable Bus Monitoring Mode. More...
 

Field Documentation

uint32_t mcan_config_t::baudRateA
uint32_t mcan_config_t::baudRateD
bool mcan_config_t::enableCanfdNormal
bool mcan_config_t::enableCanfdSwitch
bool mcan_config_t::enableLoopBackInt
bool mcan_config_t::enableLoopBackExt
bool mcan_config_t::enableBusMon
struct mcan_timing_config_t

Data Fields

uint16_t preDivider
 Clock Pre-scaler Division Factor. More...
 
uint8_t rJumpwidth
 Re-sync Jump Width. More...
 
uint8_t seg1
 Data Time Segment 1. More...
 
uint8_t seg2
 Data Time Segment 2. More...
 

Field Documentation

uint16_t mcan_timing_config_t::preDivider
uint8_t mcan_timing_config_t::rJumpwidth
uint8_t mcan_timing_config_t::seg1
uint8_t mcan_timing_config_t::seg2
struct mcan_buffer_transfer_t

Data Fields

mcan_tx_buffer_frame_tframe
 The buffer of CAN Message to be transfer. More...
 
uint8_t bufferIdx
 The index of Message buffer used to transfer Message. More...
 

Field Documentation

mcan_tx_buffer_frame_t* mcan_buffer_transfer_t::frame
uint8_t mcan_buffer_transfer_t::bufferIdx
struct mcan_fifo_transfer_t

Data Fields

mcan_rx_buffer_frame_tframe
 The buffer of CAN Message to be received from Rx FIFO. More...
 

Field Documentation

mcan_rx_buffer_frame_t* mcan_fifo_transfer_t::frame
struct _mcan_handle

MCAN handle structure definition.

Data Fields

mcan_transfer_callback_t callback
 Callback function. More...
 
void * userData
 MCAN callback function parameter. More...
 
mcan_tx_buffer_frame_t *volatile bufferFrameBuf [64]
 The buffer for received data from Buffers. More...
 
mcan_rx_buffer_frame_t *volatile rxFifoFrameBuf
 The buffer for received data from Rx FIFO. More...
 
volatile uint8_t txbufferIdx
 Message Buffer transfer state. More...
 
volatile uint8_t bufferState [64]
 Message Buffer transfer state. More...
 
volatile uint8_t rxFifoState
 Rx FIFO transfer state. More...
 

Field Documentation

mcan_transfer_callback_t mcan_handle_t::callback
void* mcan_handle_t::userData
mcan_tx_buffer_frame_t* volatile mcan_handle_t::bufferFrameBuf[64]
mcan_rx_buffer_frame_t* volatile mcan_handle_t::rxFifoFrameBuf
volatile uint8_t mcan_handle_t::txbufferIdx
volatile uint8_t mcan_handle_t::bufferState[64]
volatile uint8_t mcan_handle_t::rxFifoState

Macro Definition Documentation

#define MCAN_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))

Typedef Documentation

typedef void(* mcan_transfer_callback_t)(CAN_Type *base, mcan_handle_t *handle, status_t status, uint32_t result, void *userData)

The MCAN transfer callback returns a value from the underlying layer. If the status equals to kStatus_MCAN_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.

Enumeration Type Documentation

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.

kStatus_MCAN_RxFifo1Watermark 

Rx FIFO 1 fill level reached watermark.

kStatus_MCAN_RxFifo1Full 

Rx FIFO 1 full.

kStatus_MCAN_RxFifo1Lost 

Rx FIFO 1 message lost.

kStatus_MCAN_RxFifo0Busy 

Rx FIFO 0 is busy.

kStatus_MCAN_RxFifo1Busy 

Rx FIFO 1 is busy.

kStatus_MCAN_ErrorStatus 

MCAN Module Error and Status.

kStatus_MCAN_UnHandled 

UnHadled Interrupt asserted.

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.

kMCAN_20ByteDatafield 

20 byte data field.

kMCAN_24ByteDatafield 

24 byte data field.

kMCAN_32ByteDatafield 

32 byte data field.

kMCAN_48ByteDatafield 

48 byte data field.

kMCAN_64ByteDatafield 

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

kMCAN_acceptinFifo1 

Accept non-masking frames in Rx FIFO 1.

kMCAN_reject0 

Reject non-masking frames.

kMCAN_reject1 

Reject non-masking frames.

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.

Function Documentation

void MCAN_Init ( CAN_Type *  base,
const mcan_config_t config,
uint32_t  sourceClock_Hz 
)

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
baseMCAN peripheral base address.
configPointer to the user-defined configuration structure.
sourceClock_HzMCAN Protocol Engine clock source frequency in Hz.
void MCAN_Deinit ( CAN_Type *  base)

This function deinitializes the MCAN module.

Parameters
baseMCAN peripheral base address.
void MCAN_GetDefaultConfig ( mcan_config_t config)

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->enableLoopBackExt = false; config->enableBusMon = false;

Parameters
configPointer to the MCAN configuration structure.
void MCAN_EnterNormalMode ( CAN_Type *  base)

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
baseMCAN peripheral base address.
static void MCAN_SetMsgRAMBase ( CAN_Type *  base,
uint32_t  value 
)
inlinestatic

This function sets the Message RAM base address.

Parameters
baseMCAN peripheral base address.
valueDesired Message RAM base.
static uint32_t MCAN_GetMsgRAMBase ( CAN_Type *  base)
inlinestatic

This function gets the Message RAM base address.

Parameters
baseMCAN peripheral base address.
Returns
Message RAM base address.
void MCAN_SetArbitrationTimingConfig ( CAN_Type *  base,
const mcan_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 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
baseMCAN peripheral base address.
configPointer to the timing configuration structure.
void MCAN_SetRxFifo0Config ( CAN_Type *  base,
const mcan_rx_fifo_config_t config 
)

This function sets start address, element size, watermark, operation mode and datafield size of the recieve fifo 0.

Parameters
baseMCAN peripheral base address.
configThe receive fifo 0 configuration structure.
void MCAN_SetRxFifo1Config ( CAN_Type *  base,
const mcan_rx_fifo_config_t config 
)

This function sets start address, element size, watermark, operation mode and datafield size of the recieve fifo 1.

Parameters
baseMCAN peripheral base address.
configThe receive fifo 1 configuration structure.
void MCAN_SetRxBufferConfig ( CAN_Type *  base,
const mcan_rx_buffer_config_t config 
)

This function sets start address and datafield size of the recieve buffer.

Parameters
baseMCAN peripheral base address.
configThe receive buffer configuration structure.
void MCAN_SetTxEventfifoConfig ( CAN_Type *  base,
const mcan_tx_fifo_config_t config 
)

This function sets start address, element size, watermark of the transmit event fifo.

Parameters
baseMCAN peripheral base address.
configThe transmit event fifo configuration structure.
void MCAN_SetTxBufferConfig ( CAN_Type *  base,
const mcan_tx_buffer_config_t config 
)

This function sets start address, element size, fifo/queue mode and datafield size of the transmit buffer.

Parameters
baseMCAN peripheral base address.
configThe transmit buffer configuration structure.
void MCAN_SetFilterConfig ( CAN_Type *  base,
const mcan_frame_filter_config_t config 
)

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
baseMCAN peripheral base address.
configThe MCAN filter configuration.
void MCAN_SetSTDFilterElement ( CAN_Type *  base,
const mcan_frame_filter_config_t config,
const mcan_std_filter_element_config_t filter,
uint8_t  idx 
)

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
baseMCAN peripheral base address.
configThe MCAN filter configuration.
void MCAN_SetEXTFilterElement ( CAN_Type *  base,
const mcan_frame_filter_config_t config,
const mcan_ext_filter_element_config_t filter,
uint8_t  idx 
)

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
baseMCAN peripheral base address.
configThe MCAN filter configuration.
static uint32_t MCAN_GetStatusFlag ( CAN_Type *  base,
uint32_t  mask 
)
inlinestatic

This function gets all MCAN interrupt status flags.

Parameters
baseMCAN peripheral base address.
maskThe ORed MCAN interrupt mask.
Returns
MCAN status flags which are ORed.
static void MCAN_ClearStatusFlag ( CAN_Type *  base,
uint32_t  mask 
)
inlinestatic

This function clears MCAN interrupt status flags.

Parameters
baseMCAN peripheral base address.
maskThe ORed MCAN interrupt mask.
static bool MCAN_GetRxBufferStatusFlag ( CAN_Type *  base,
uint8_t  idx 
)
inlinestatic

This function gets new data flag of specific Rx Buffer.

Parameters
baseMCAN peripheral base address.
idxRx Buffer index.
Returns
Rx Buffer new data status flag.
static void MCAN_ClearRxBufferStatusFlag ( CAN_Type *  base,
uint8_t  idx 
)
inlinestatic

This function clears new data flag of specific Rx Buffer.

Parameters
baseMCAN peripheral base address.
idxRx Buffer index.
static void MCAN_EnableInterrupts ( CAN_Type *  base,
uint32_t  line,
uint32_t  mask 
)
inlinestatic

This function enables the MCAN interrupts according to the provided interrupt line and mask. The mask is a logical OR of enumeration members.

Parameters
baseMCAN peripheral base address.
lineInterrupt line number, 0 or 1.
maskThe interrupts to enable.
static void MCAN_EnableTransmitBufferInterrupts ( CAN_Type *  base,
uint8_t  idx 
)
inlinestatic

This function enables the MCAN Tx Buffer interrupts.

Parameters
baseMCAN peripheral base address.
idxTx Buffer index.
static void MCAN_DisableTransmitBufferInterrupts ( CAN_Type *  base,
uint8_t  idx 
)
inlinestatic

This function disables the MCAN Tx Buffer interrupts.

Parameters
baseMCAN peripheral base address.
idxTx Buffer index.
static void MCAN_DisableInterrupts ( CAN_Type *  base,
uint32_t  mask 
)
inlinestatic

This function disables the MCAN interrupts according to the provided mask. The mask is a logical OR of enumeration members.

Parameters
baseMCAN peripheral base address.
maskThe interrupts to disable.
status_t MCAN_WriteTxBuffer ( CAN_Type *  base,
uint8_t  idx,
const mcan_tx_buffer_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
baseMCAN peripheral base address.
idxThe MCAN Tx Buffer index.
txFramePointer to CAN message frame to be sent.
status_t MCAN_ReadRxFifo ( CAN_Type *  base,
uint8_t  fifoBlock,
mcan_rx_buffer_frame_t rxFrame 
)

This function reads a CAN message from the Rx FIFO in the Message RAM.

Parameters
baseMCAN peripheral base address.
fifoBlockRx FIFO block 0 or 1.
rxFramePointer to CAN message frame structure for reception.
Return values
kStatus_Success- Read Message from Rx FIFO successfully.
static void MCAN_TransmitAddRequest ( CAN_Type *  base,
uint8_t  idx 
)
inlinestatic

This function add sending request to corresponding Tx Buffer.

Parameters
baseMCAN peripheral base address.
idxTx Buffer index.
static void MCAN_TransmitCancelRequest ( CAN_Type *  base,
uint8_t  idx 
)
inlinestatic

This function clears Tx buffer request pending bit.

Parameters
baseMCAN peripheral base address.
idxTx Buffer index.
status_t MCAN_TransferSendBlocking ( CAN_Type *  base,
uint8_t  idx,
mcan_tx_buffer_frame_t txFrame 
)

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

Parameters
baseMCAN peripheral base pointer.
idxThe MCAN buffer index.
txFramePointer 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 MCAN_TransferReceiveFifoBlocking ( CAN_Type *  base,
uint8_t  fifoBlock,
mcan_rx_buffer_frame_t rxFrame 
)

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

Parameters
baseMCAN peripheral base pointer.
fifoBlockRx FIFO block, 0 or 1.
rxFramePointer to CAN message frame structure for reception.
Return values
kStatus_Success- Read Message from Rx FIFO successfully.
kStatus_Fail- No new message in Rx FIFO.
void MCAN_TransferCreateHandle ( CAN_Type *  base,
mcan_handle_t *  handle,
mcan_transfer_callback_t  callback,
void *  userData 
)

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

Parameters
baseMCAN peripheral base address.
handleMCAN handle pointer.
callbackThe callback function.
userDataThe parameter of the callback function.
status_t MCAN_TransferSendNonBlocking ( CAN_Type *  base,
mcan_handle_t *  handle,
mcan_buffer_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
baseMCAN peripheral base address.
handleMCAN handle pointer.
xferMCAN Buffer transfer structure. See the mcan_buffer_transfer_t.
Return values
kStatus_SuccessStart Tx Buffer sending process successfully.
kStatus_FailWrite Tx Buffer failed.
kStatus_MCAN_TxBusyTx Buffer is in use.
status_t MCAN_TransferReceiveFifoNonBlocking ( CAN_Type *  base,
uint8_t  fifoBlock,
mcan_handle_t *  handle,
mcan_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
baseMCAN peripheral base address.
handleMCAN handle pointer.
fifoBlockRx FIFO block, 0 or 1.
xferMCAN Rx FIFO transfer structure. See the mcan_fifo_transfer_t.
Return values
kStatus_Success- Start Rx FIFO receiving process successfully.
kStatus_MCAN_RxFifo0Busy- Rx FIFO 0 is currently in use.
kStatus_MCAN_RxFifo1Busy- Rx FIFO 1 is currently in use.
void MCAN_TransferAbortSend ( CAN_Type *  base,
mcan_handle_t *  handle,
uint8_t  bufferIdx 
)

This function aborts the interrupt driven message send process.

Parameters
baseMCAN peripheral base address.
handleMCAN handle pointer.
bufferIdxThe MCAN Buffer index.
void MCAN_TransferAbortReceiveFifo ( CAN_Type *  base,
uint8_t  fifoBlock,
mcan_handle_t *  handle 
)

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

Parameters
baseMCAN peripheral base address.
fifoBlockMCAN Fifo block, 0 or 1.
handleMCAN handle pointer.
void MCAN_TransferHandleIRQ ( CAN_Type *  base,
mcan_handle_t *  handle 
)

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

Parameters
baseMCAN peripheral base address.
handleMCAN handle pointer.