CAN HAL API

Module: HAL (AM13E230X) API

More…

Structures

Name

struct

Mcan_Hal_RxFilterElementType
CAN RX Filter Element Configuration (FEC)

struct

Mcan_Hal_GlobalFilterConfigType
CAN Global Filter Configuration Type.

struct

Mcan_Hal_HighPriorityMsgStatusType
CAN High Priority Message Status Type.

struct

Mcan_Hal_TransferParamsType
CAN Transfer Parameters.

struct

Mcan_Hal_MessageParamsType
CAN Message Parameters.

struct

Mcan_Hal_TxConfigType
CAN TX configuration parameters.

struct

Mcan_Hal_RxConfigType
CAN RX configuration parameters.

struct

Mcan_Hal_InitParamsType
CAN HW initialization parameters.

struct

Mcan_Hal_NominalPhaseTimingType
CAN nominal bit timing parameters.

struct

Mcan_Hal_DataPhaseTimingType
CAN data phase bit timing parameters (CAN FD only)

struct

Mcan_Hal_BaudParamsType
CAN bit rate parameters.

struct

Mcan_Hal_MsgRamLayoutType
CAN Message RAM Layout Type.

struct

Mcan_Hal_ErrorCounterStatusType
CAN Error Counter Status Type.

struct

Mcan_Hal_TxEventFifoElementType
CAN Transmit Event FIFO Element Type.

struct

Mcan_Hal_InstanceType
CAN HW instance structure. Should not be modified by application directly.

Types

Name

enum

Mcan_Hal_StateType { MCAN_HAL_STATE_UNCONFIGURED = 0U, MCAN_HAL_STATE_INITIALIZED, MCAN_HAL_STATE_STOP, MCAN_HAL_STATE_START}
CAN instance states.

enum

Mcan_Hal_ProcessingModeType { MCAN_HAL_PROCESSING_MODE_POLLING = 0U, MCAN_HAL_PROCESSING_MODE_INTERRUPT = 1U}
CAN processing mode.

enum

Mcan_Hal_MsgFormatType { MCAN_HAL_MSG_FORMAT_CLASSIC = 0U, MCAN_HAL_MSG_FORMAT_FD}
CAN Message Format Type.

enum

Mcan_Hal_MsgDirectionType { MCAN_HAL_MSG_DIRECTION_RX = 0U, MCAN_HAL_MSG_DIRECTION_TX}
CAN Message Direction Type.

enum

Mcan_Hal_RxFifoType { MCAN_HAL_RX_FIFO_0 = 0U, MCAN_HAL_RX_FIFO_1 = 1U, MCAN_HAL_RX_DEDICATED_BUF = 2U, MCAN_HAL_RX_HIGH_PRIORITY = 3U}
CAN RX Source Type.

enum

Mcan_Hal_RxFifoModeType { MCAN_HAL_RX_FIFO_MODE_BLOCKING = 0U, MCAN_HAL_RX_FIFO_MODE_OVERWRITE = 1U}
CAN RX FIFO Operation Mode Type.

enum

Mcan_Hal_TxBufferType { MCAN_HAL_TX_BUFFER_FIFO = 0U, MCAN_HAL_TX_BUFFER_QUEUE, MCAN_HAL_TX_BUFFER_DEDICATED}
CAN TX Buffer Selection Type.

enum

Mcan_Hal_RxFilterActionType { MCAN_HAL_RX_FILTER_ACTION_DISABLE = 0U, MCAN_HAL_RX_FILTER_ACTION_ACCEPT_FIFO0 = 1U, MCAN_HAL_RX_FILTER_ACTION_ACCEPT_FIFO1 = 2U, MCAN_HAL_RX_FILTER_ACTION_REJECT = 3U, MCAN_HAL_RX_FILTER_ACTION_HIGH_PRIORITY = 4U, MCAN_HAL_RX_FILTER_ACTION_HIGH_PRIORITY_FIFO0 = 5U, MCAN_HAL_RX_FILTER_ACTION_HIGH_PRIORITY_FIFO1 = 6U, MCAN_HAL_RX_FILTER_ACTION_STORE_RX_BUFFER = 7U}
CAN RX Filter Action Type.

enum

Mcan_Hal_ProtocolErrorType { MCAN_HAL_PROTOCOL_ERROR_NO_ERROR = 0U, MCAN_HAL_PROTOCOL_ERROR_STUFF_ERROR, MCAN_HAL_PROTOCOL_ERROR_FORM_ERROR, MCAN_HAL_PROTOCOL_ERROR_ACK_ERROR, MCAN_HAL_PROTOCOL_ERROR_BIT1_ERROR, MCAN_HAL_PROTOCOL_ERROR_BIT0_ERROR, MCAN_HAL_PROTOCOL_ERROR_CRC_ERROR, MCAN_HAL_PROTOCOL_ERROR_NO_CHANGE}
CAN Protocol Error Code Type.

enum

Mcan_Hal_ActivityStateType { MCAN_HAL_ACTIVITY_STATE_SYNCHRONIZING = 0U, MCAN_HAL_ACTIVITY_STATE_IDLE, MCAN_HAL_ACTIVITY_STATE_RECEIVER, MCAN_HAL_ACTIVITY_STATE_TRANSMITTER}
CAN Activity State Type.

enum

Mcan_Hal_NonMatchingFrameHandlingType { MCAN_HAL_NON_MATCHING_ACCEPT_FIFO0 = 0U, MCAN_HAL_NON_MATCHING_ACCEPT_FIFO1 = 1U, MCAN_HAL_NON_MATCHING_REJECT = 2U}
CAN Non-matching Frame Handling Type.

enum

Mcan_Hal_LoopbackModeType { MCAN_HAL_LOOPBACK_NONE = 0U, MCAN_HAL_LOOPBACK_INTERNAL = 1U, MCAN_HAL_LOOPBACK_EXTERNAL = 2U}
Loopback mode selection.

enum

Mcan_Hal_RxFilterType { MCAN_HAL_RX_FILTER_TYPE_RANGE = 0U, MCAN_HAL_RX_FILTER_TYPE_DUAL = 1U, MCAN_HAL_RX_FILTER_TYPE_MASK = 2U, MCAN_HAL_RX_FILTER_TYPE_RANGE_NO_XIDAM = 3U}
CAN RX Filter Type.

typedef void(*)(struct Mcan_Hal_InstanceType_s *instancePtr, Mcan_Hal_RxFifoType rxSource, void *userArgsPtr)

Mcan_Hal_RxIndicationCallbackType
CAN RX Indication callback function pointer type.

typedef void(*)(struct Mcan_Hal_InstanceType_s *instancePtr, uint32 ndatLow, uint32 ndatHigh, void *userArgsPtr)

Mcan_Hal_RxDedicatedBufCallbackType
CAN Dedicated RX Buffer indication callback function pointer type.

typedef void(*)(struct Mcan_Hal_InstanceType_s *instancePtr, void *userArgsPtr)

Mcan_Hal_TxConfirmationCallbackType
CAN TX Confirmation callback function pointer type.

typedef void(*)(struct Mcan_Hal_InstanceType_s *instancePtr, uint32 intrStatus, void *userArgsPtr)

Mcan_Hal_ErrorCallbackType
CAN Error/Status confirmation callback function pointer type.

typedef uint32

Mcan_Hal_ProtocolStatusType
CAN Protocol Status Type.

Functions

Name

sint32

Mcan_Hal_InitParamsSetDefault(Mcan_Hal_InitParamsType * paramsPtr)
Initializes the CAN module with Default Parameters.

sint32

Mcan_Hal_Init(Mcan_Hal_InstanceType * instancePtr, const Mcan_Hal_InitParamsType * paramsPtr)
Initialize a CAN HW instance.

sint32

Mcan_Hal_DeInit(Mcan_Hal_InstanceType * instancePtr)
De-initialize a CAN HW instance.

sint32

Mcan_Hal_SetBaudrate(Mcan_Hal_InstanceType * instancePtr, const Mcan_Hal_BaudParamsType * bitparamsPtr)
Set CAN bit rate parameters.

sint32

Mcan_Hal_GetMsgRamLayout(const Mcan_Hal_InstanceType * instancePtr, Mcan_Hal_MsgRamLayoutType * layoutPtr)
Get the configured Message RAM layout.

sint32

Mcan_Hal_Start(Mcan_Hal_InstanceType * instancePtr)
Start CAN protocol operation.

sint32

Mcan_Hal_Stop(Mcan_Hal_InstanceType * instancePtr)
Stop CAN protocol operation (immediate)

sint32

Mcan_Hal_GetStopStatus(const Mcan_Hal_InstanceType * instancePtr, boolean * isStopPtr)
Check whether the CAN controller has stopped.

sint32

Mcan_Hal_Reset(const Mcan_Hal_InstanceType * instancePtr)
Protocol-level reset of the CAN controller.

sint32

Mcan_Hal_ConfigureLoopbackMode(const Mcan_Hal_InstanceType * instancePtr, Mcan_Hal_LoopbackModeType mode)
Configure CAN loopback mode.

sint32

Mcan_Hal_GetProtocolControllerStatus(const Mcan_Hal_InstanceType * instancePtr, uint32 * protocolControllerStatusPtr)
Get CAN protocol controller status.

sint32

Mcan_Hal_GetErrorCounterStatus(Mcan_Hal_InstanceType * instancePtr, Mcan_Hal_ErrorCounterStatusType * counterPtr)
Get CAN error counter status.

sint32

Mcan_Hal_GetHighPriorityMsgStatus(const Mcan_Hal_InstanceType * instancePtr, Mcan_Hal_HighPriorityMsgStatusType * statusPtr)
Get High Priority Message status.

sint32

Mcan_Hal_MessageParamsSetDefault(Mcan_Hal_MessageParamsType * msgParamsPtr)
Initializes the CAN Message Parameters with Default Values.

sint32

Mcan_Hal_Tx(Mcan_Hal_InstanceType * instancePtr, const Mcan_Hal_MessageParamsType * msgParamsPtr, const Mcan_Hal_TransferParamsType * transferParamsPtr)
Transmit a CAN message.

sint32

Mcan_Hal_CancelTxBuffer(Mcan_Hal_InstanceType * instancePtr, uint8 bufferIndex)
Cancel a pending TX buffer transmission.

sint32

Mcan_Hal_GetTxBufTransmissionStatus(const Mcan_Hal_InstanceType * instancePtr, uint32 * txBtoMaskPtr)
Get TX buffer transmission status bitmask (MCAN_TXBTO)

sint32

Mcan_Hal_CheckTxConfirmationPoll(const Mcan_Hal_InstanceType * instancePtr, boolean * isTransferCompletePtr)
Check TX Confirmation status (polling mode)

sint32

Mcan_Hal_TxEventFifoDequeue(Mcan_Hal_InstanceType * instancePtr, Mcan_Hal_TxEventFifoElementType * txEventElemPtr)
Dequeue one TX event element.

sint32

Mcan_Hal_RxFifoPoll(Mcan_Hal_InstanceType * instancePtr)
Check RX FIFOs for pending received frames and invoke the RX indication callback.

sint32

Mcan_Hal_RxFifoDequeue(Mcan_Hal_InstanceType * instancePtr, Mcan_Hal_RxFifoType rxFifo, Mcan_Hal_MessageParamsType * msgParamsPtr, Mcan_Hal_TransferParamsType * transferParamsPtr)
Dequeue one RX frame from the specified RX FIFO.

sint32

Mcan_Hal_RxBufPoll(Mcan_Hal_InstanceType * instancePtr, uint8 * bufferIndexPtr)
Find the next dedicated RX buffer with new data.

sint32

Mcan_Hal_RxDedicatedBufDequeue(Mcan_Hal_InstanceType * instancePtr, uint8 bufferIndex, Mcan_Hal_MessageParamsType * msgParamsPtr, Mcan_Hal_TransferParamsType * transferParamsPtr)
Read a CAN message from a dedicated RX buffer and clear its NDAT flag.

sint32

Mcan_Hal_AddOrUpdateRxFilterElement(Mcan_Hal_InstanceType * instancePtr, const Mcan_Hal_RxFilterElementType * filterElementPtr)
Add or update an RX filter element.

sint32

Mcan_Hal_ClearRxFilterElement(Mcan_Hal_InstanceType * instancePtr, const Mcan_Hal_RxFilterElementType * filterElementPtr)
Clear RX filter element.

sint32

Mcan_Hal_EnableInterrupts(const Mcan_Hal_InstanceType * instancePtr)
Enable CAN interrupts.

sint32

Mcan_Hal_DisableInterrupts(const Mcan_Hal_InstanceType * instancePtr)
Disable CAN interrupts.

void

Mcan_Hal_InterruptHandler_Line0(Mcan_Hal_InstanceType * instancePtr)
CAN Interrupt Handler.

Defines

Name

MCAN_HAL_ERROR_NONE
No error.

MCAN_HAL_ERROR_INVALID_INSTANCE
Invalid instance pointer.

MCAN_HAL_ERROR_INVALID_PARAM_POINTER
Invalid parameter pointer.

MCAN_HAL_ERROR_INVALID_PARAMS
Invalid parameters.

MCAN_HAL_ERROR_UNSUPPORTED_FEATURE
Unsupported operation.

MCAN_HAL_ERROR_HW_BUSY
CAN transfer fail since underlying HW was busy.

MCAN_HAL_ERROR_INVALID_STATE
Invalid state for the requested operation.

MCAN_HAL_FIFO_EMPTY
FIFO/Event FIFO is empty — no message available to read.

MCAN_HAL_MSG_LEN_MAX_CLASSIC_BYTES
Maximum data length for Classic CAN (8 bytes)

MCAN_HAL_MSG_LEN_MAX_FD_BYTES
Maximum data length for CAN FD (64 bytes)

MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_NEW_ENTRY
TX Event FIFO New Entry.

MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_WATERMARK
TX Event FIFO Watermark Reached.

MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_FULL
TX Event FIFO Full.

MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_ELEM_LOST
TX Event FIFO Element Lost.

MCAN_HAL_INTR_SRC_TX_FIFO_EMPTY
TX FIFO Empty.

MCAN_HAL_INTR_SRC_TX_COMPLETE
Transmission Completed.

MCAN_HAL_INTR_SRC_TX_CANCEL_FINISH
Transmission Cancellation Finished.

MCAN_HAL_INTR_SRC_TX_DEFAULT
Default TX interrupt mask.

MCAN_HAL_INTR_SRC_RX_FIFO0_NEW_MSG
RX FIFO 0 New Message.

MCAN_HAL_INTR_SRC_RX_FIFO0_WATERMARK
RX FIFO 0 Watermark Reached.

MCAN_HAL_INTR_SRC_RX_FIFO0_FULL
RX FIFO 0 Full.

MCAN_HAL_INTR_SRC_RX_FIFO0_MSG_LOST
RX FIFO 0 Message Lost.

MCAN_HAL_INTR_SRC_RX_FIFO1_NEW_MSG
RX FIFO 1 New Message.

MCAN_HAL_INTR_SRC_RX_FIFO1_WATERMARK
RX FIFO 1 Watermark Reached.

MCAN_HAL_INTR_SRC_RX_FIFO1_FULL
RX FIFO 1 Full.

MCAN_HAL_INTR_SRC_RX_FIFO1_MSG_LOST
RX FIFO 1 Message Lost.

MCAN_HAL_INTR_SRC_RX_HIGH_PRIORITY_MSG
High Priority Message.

MCAN_HAL_INTR_SRC_RX_DEDICATED_BUF
Message Stored to Dedicated RX Buffer.

MCAN_HAL_INTR_SRC_RX_DEFAULT
Default RX interrupt mask.

MCAN_HAL_INTR_SRC_ERR_ERROR_PASSIVE
Error Passive state change.

MCAN_HAL_INTR_SRC_ERR_WARNING
Warning Status change.

MCAN_HAL_INTR_SRC_ERR_BUS_OFF
Bus Off state change.

MCAN_HAL_INTR_SRC_ERR_WATCHDOG
Watchdog Interrupt.

MCAN_HAL_INTR_SRC_ERR_PROTOCOL_ARB
Protocol Error in Arbitration Phase.

MCAN_HAL_INTR_SRC_ERR_PROTOCOL_DATA
Protocol Error in Data Phase.

MCAN_HAL_INTR_SRC_ERR_RESERVED_ADDR
Access to Reserved Address.

MCAN_HAL_INTR_SRC_ERR_MSG_RAM_ACCESS
Message RAM Access Failure.

MCAN_HAL_INTR_SRC_ERR_TIMEOUT
Timeout Occurred.

MCAN_HAL_INTR_SRC_ERR_TIMESTAMP_WRAP
Timestamp Wraparound.

MCAN_HAL_INTR_SRC_ERR_LOGGING_OVERFLOW
Error Logging Overflow.

MCAN_HAL_INTR_SRC_ERR_BIT_ERR_UNCORRECTED
Bit Error Uncorrected.

MCAN_HAL_INTR_SRC_ERR_DEFAULT
Default error interrupt mask.

MCAN_HAL_RX_STD_FILTER_ELEMENT_MAX
Maximum number of standard ID RX filter elements supported by MCAN FD.

MCAN_HAL_RX_EXT_FILTER_ELEMENT_MAX
Maximum number of extended ID RX filter elements supported by MCAN FD.

MCAN_HAL_RX_FILTER_ELEMENT_MAX
Maximum number of RX filter elements supported by MCAN FD.

MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_SYNCHRONIZING
ACT == 0b00: Controller is synchronizing (bus integration)

MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_IDLE
ACT == 0b01: Controller is idle on the CAN bus.

MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_RECEIVER
ACT == 0b10: Controller is currently receiving a frame.

MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_TRANSMITTER
ACT == 0b11: Controller is currently transmitting a frame.

MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_MASK
Mask to extract the ACT field from the status value.

MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ERROR_PASSIVE
Error Passive flag (MCAN_PSR.EP == 1). The node’s error counter has exceeded the error-passive threshold (128).

MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_WARNING
Warning Status flag (MCAN_PSR.EW == 1). At least one error counter has reached the warning level (96).

MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_BUS_OFF
Bus Off flag (MCAN_PSR.BO == 1). The transmit error counter exceeded 255; CAN protocol operation is stopped.

MCAN_HAL_RX_BUFFER_MAX
Maximum number of dedicated RX buffers (MCAN_RXBC, up to 64)

MCAN_HAL_TX_BUFFER_MAX
Maximum number of TX buffers (dedicated + FIFO/Queue combined, MCAN_TXBC, up to 32)

Detailed Description

Note: All transfer APIs are non-blocking unless specified otherwise, i.e they dont wait for the RX/TX operation to complete.

CAN (Controller Area Network) HAL driver provides APIs for CAN communication using the Bosch MCAN FD IP core

Types Documentation

enum Mcan_Hal_StateType

Enumerator

Value

Description

MCAN_HAL_STATE_UNCONFIGURED

0U

Instance is not configured.

MCAN_HAL_STATE_INITIALIZED

Instance is initialized but not yet started on the bus.

MCAN_HAL_STATE_STOP

Instance is stopped (SW_INIT mode, not on bus)

MCAN_HAL_STATE_START

Instance is started and actively communicating on the bus.

CAN instance states.

enum Mcan_Hal_ProcessingModeType

Enumerator

Value

Description

MCAN_HAL_PROCESSING_MODE_POLLING

0U

Polling mode — application calls the Poll API to check for events.

MCAN_HAL_PROCESSING_MODE_INTERRUPT

1U

Interrupt mode — hardware interrupt triggers the registered callback.

CAN processing mode.

Selects whether a CAN event (TX confirmation, RX indication) is handled by polling or by interrupt-driven callback. This is a controller-level, init-time setting and it must not be changed after Mcan_Hal_Init() returns.

enum Mcan_Hal_MsgFormatType

Enumerator

Value

Description

MCAN_HAL_MSG_FORMAT_CLASSIC

0U

Classic CAN message format (up to 8 bytes)

MCAN_HAL_MSG_FORMAT_FD

CAN FD message format (up to 64 bytes)

CAN Message Format Type.

enum Mcan_Hal_MsgDirectionType

Enumerator

Value

Description

MCAN_HAL_MSG_DIRECTION_RX

0U

Receive direction.

MCAN_HAL_MSG_DIRECTION_TX

Transmit direction.

CAN Message Direction Type.

enum Mcan_Hal_RxFifoType

Enumerator

Value

Description

MCAN_HAL_RX_FIFO_0

0U

RX FIFO 0.

MCAN_HAL_RX_FIFO_1

1U

RX FIFO 1.

MCAN_HAL_RX_DEDICATED_BUF

2U

Dedicated RX buffer — new message stored (MCAN_IR.DRX). Call Mcan_Hal_RxBufPoll() to find which buffer index has new data.

MCAN_HAL_RX_HIGH_PRIORITY

3U

High Priority Message (MCAN_IR.HPM) — a frame matching a high-priority filter has been received. Call Mcan_Hal_GetHighPriorityMsgStatus() to find the storage location. The normal FIFO or buffer callback also fires.

CAN RX Source Type.

Identifies the RX hardware source passed to the Mcan_Hal_RxIndicationCallbackType callback and used in Mcan_Hal_RxFifoDequeue().

When used in Mcan_Hal_RxFifoDequeue(), only MCAN_HAL_RX_FIFO_0 and MCAN_HAL_RX_FIFO_1 are valid.

When passed to the RX indication callback:

enum Mcan_Hal_RxFifoModeType

Enumerator

Value

Description

MCAN_HAL_RX_FIFO_MODE_BLOCKING

0U

Blocking mode (default): new messages are rejected when FIFO is full.

MCAN_HAL_RX_FIFO_MODE_OVERWRITE

1U

Overwrite mode: oldest message is overwritten when FIFO is full.

CAN RX FIFO Operation Mode Type.

Selects whether an RX FIFO operates in blocking or overwrite mode. Maps to MCAN_RXFnC.FnOM bit.

enum Mcan_Hal_TxBufferType

Enumerator

Value

Description

MCAN_HAL_TX_BUFFER_FIFO

0U

TX FIFO — messages transmitted in FIFO order (MCAN_TXBC.TFQM=0)

MCAN_HAL_TX_BUFFER_QUEUE

TX Queue — messages transmitted in priority order, lowest ID first (MCAN_TXBC.TFQM=1)

MCAN_HAL_TX_BUFFER_DEDICATED

TX Dedicated Buffer — message placed in a specific numbered buffer.

CAN TX Buffer Selection Type.

enum Mcan_Hal_RxFilterActionType

Enumerator

Value

Description

MCAN_HAL_RX_FILTER_ACTION_DISABLE

0U

Disable filter element — no action (SFEC/EFEC = 0x0)

MCAN_HAL_RX_FILTER_ACTION_ACCEPT_FIFO0

1U

Accept the message into RX FIFO 0 on filter match (SFEC/EFEC = 0x1)

MCAN_HAL_RX_FILTER_ACTION_ACCEPT_FIFO1

2U

Accept the message into RX FIFO 1 on filter match (SFEC/EFEC = 0x2)

MCAN_HAL_RX_FILTER_ACTION_REJECT

3U

Reject the message on filter match (SFEC/EFEC = 0x3)

MCAN_HAL_RX_FILTER_ACTION_HIGH_PRIORITY

4U

Set High Priority Message interrupt (MCAN_IR.HPM) on filter match (SFEC/EFEC = 0x4)

MCAN_HAL_RX_FILTER_ACTION_HIGH_PRIORITY_FIFO0

5U

Set HPM interrupt and store in RX FIFO 0 on filter match (SFEC/EFEC = 0x5)

MCAN_HAL_RX_FILTER_ACTION_HIGH_PRIORITY_FIFO1

6U

Set HPM interrupt and store in RX FIFO 1 on filter match (SFEC/EFEC = 0x6)

MCAN_HAL_RX_FILTER_ACTION_STORE_RX_BUFFER

7U

Store into dedicated Rx Buffer (SFEC/EFEC = 0x7, SFT/EFT ignored)

CAN RX Filter Action Type.

Specifies the action taken when a filter element matches a received frame. Maps to the SFEC/EFEC field in the Standard/Extended Message ID Filter Element.

enum Mcan_Hal_ProtocolErrorType

Enumerator

Value

Description

MCAN_HAL_PROTOCOL_ERROR_NO_ERROR

0U

No error - LEC has been reset by successful reception/transmission.

MCAN_HAL_PROTOCOL_ERROR_STUFF_ERROR

Bit stuffing error - more than 5 equal bits in a sequence.

MCAN_HAL_PROTOCOL_ERROR_FORM_ERROR

Form error - fixed format part has wrong format.

MCAN_HAL_PROTOCOL_ERROR_ACK_ERROR

ACK error - message was not acknowledged by another node.

MCAN_HAL_PROTOCOL_ERROR_BIT1_ERROR

Bit 1 error - recessive bit was transmitted but dominant was monitored.

MCAN_HAL_PROTOCOL_ERROR_BIT0_ERROR

Bit 0 error - dominant bit was transmitted but recessive was monitored.

MCAN_HAL_PROTOCOL_ERROR_CRC_ERROR

CRC error - received CRC does not match calculated CRC.

MCAN_HAL_PROTOCOL_ERROR_NO_CHANGE

No change - no CAN bus event detected since last read.

CAN Protocol Error Code Type.

Enumerates the different protocol error codes that can occur during CAN communication.

enum Mcan_Hal_ActivityStateType

Enumerator

Value

Description

MCAN_HAL_ACTIVITY_STATE_SYNCHRONIZING

0U

Synchronizing - controller is synchronizing on CAN communication.

MCAN_HAL_ACTIVITY_STATE_IDLE

Idle - controller is neither transmitting nor receiving.

MCAN_HAL_ACTIVITY_STATE_RECEIVER

Receiver - controller is operating as receiver.

MCAN_HAL_ACTIVITY_STATE_TRANSMITTER

Transmitter - controller is operating as transmitter.

CAN Activity State Type.

Enumerates the different activity states of the CAN controller during communication.

enum Mcan_Hal_NonMatchingFrameHandlingType

Enumerator

Value

Description

MCAN_HAL_NON_MATCHING_ACCEPT_FIFO0

0U

Accept non-matching frames into RX FIFO 0.

MCAN_HAL_NON_MATCHING_ACCEPT_FIFO1

1U

Accept non-matching frames into RX FIFO 1.

MCAN_HAL_NON_MATCHING_REJECT

2U

Reject non-matching frames.

CAN Non-matching Frame Handling Type.

Defines how received frames that do not match any filter element are handled. Maps to MCAN_GFC.ANFS (standard) and MCAN_GFC.ANFE (extended) fields.

enum Mcan_Hal_LoopbackModeType

Enumerator

Value

Description

MCAN_HAL_LOOPBACK_NONE

0U

No loopback — normal bus operation.

MCAN_HAL_LOOPBACK_INTERNAL

1U

Internal loopback — TX connected to RX internally.

MCAN_HAL_LOOPBACK_EXTERNAL

2U

External loopback — TX connected to RX via bus; frames visible on bus.

Loopback mode selection.

Controls which loopback mode is activated

enum Mcan_Hal_RxFilterType

Enumerator

Value

Description

MCAN_HAL_RX_FILTER_TYPE_RANGE

0U

Range filter: sfid2 >= ID >= sfid1 for standard, efid2 >= ID >= efid1 for extended.

MCAN_HAL_RX_FILTER_TYPE_DUAL

1U

Dual filter: ID matches sfid1 OR sfid2.

MCAN_HAL_RX_FILTER_TYPE_MASK

2U

Mask filter: (ID & mask) == (filter_id & mask)

MCAN_HAL_RX_FILTER_TYPE_RANGE_NO_XIDAM

3U

Range filter without XIDAM mask (extended only, EFT = 11)

CAN RX Filter Type.

Specifies the filter matching type for RX filtering. Maps to SFT[1:0] (standard) and EFT[1:0] (extended) fields.

typedef Mcan_Hal_RxIndicationCallbackType

typedef void(* Mcan_Hal_RxIndicationCallbackType) (struct Mcan_Hal_InstanceType_s *instancePtr, Mcan_Hal_RxFifoType rxSource, void *userArgsPtr);

CAN RX Indication callback function pointer type.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • rxSource RX source identifying where the message was stored

  • userArgsPtr Pointer to user arguments

Called from Mcan_Hal_InterruptHandler_Line0() (interrupt mode) or Mcan_Hal_RxFifoPoll() (non-interrupt mode) when a CAN message is received. The rxSource parameter identifies where the frame was stored:

typedef Mcan_Hal_RxDedicatedBufCallbackType

typedef void(* Mcan_Hal_RxDedicatedBufCallbackType) (struct Mcan_Hal_InstanceType_s *instancePtr, uint32 ndatLow, uint32 ndatHigh, void *userArgsPtr);

CAN Dedicated RX Buffer indication callback function pointer type.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • ndatLow MCAN_NDAT1 value — new-data flags for buffers 0-31

  • ndatHigh MCAN_NDAT2 value — new-data flags for buffers 32-63

  • userArgsPtr Pointer to user arguments

Called from Mcan_Hal_InterruptHandler_Line0() when MCAN_IR.DRX fires (one or more dedicated RX buffers have new data). The ndatLow and ndatHigh parameters carry the full MCAN_NDAT1 and MCAN_NDAT2 register values captured at interrupt time, so the application can determine which buffer indices have new data without an extra register read.

Bit N of ndatLow corresponds to dedicated RX buffer N (0-31). Bit N of ndatHigh corresponds to dedicated RX buffer N+32 (32-63).

For each set bit, call Mcan_Hal_RxDedicatedBufDequeue() with the corresponding buffer index to read the frame and clear the NDAT flag.

typedef Mcan_Hal_TxConfirmationCallbackType

typedef void(* Mcan_Hal_TxConfirmationCallbackType) (struct Mcan_Hal_InstanceType_s *instancePtr, void *userArgsPtr);

CAN TX Confirmation callback function pointer type.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • userArgsPtr Pointer to user arguments

Called when a CAN message is successfully transmitted.

typedef Mcan_Hal_ErrorCallbackType

typedef void(* Mcan_Hal_ErrorCallbackType) (struct Mcan_Hal_InstanceType_s *instancePtr, uint32 intrStatus, void *userArgsPtr);

CAN Error/Status confirmation callback function pointer type.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • intrStatus MCAN_IR register value captured before clearing, indicating which interrupt sources fired

  • userArgsPtr Pointer to user arguments

Called from Mcan_Hal_InterruptHandler_Line0() when one or more error or status interrupt sources (MCAN_IR register) are pending and enabled. The MCAN_IR value has already been cleared before this callback is invoked.

typedef Mcan_Hal_ProtocolStatusType

typedef uint32 Mcan_Hal_ProtocolStatusType;

CAN Protocol Status Type.

Raw MCAN_PSR register value. The caller can inspect individual fields using the MCAN_PSR_* bit-field masks defined in hw_mcan.h. This avoids the overhead of unpacking every field when only a subset is needed.

Key fields in MCAN_PSR:

  • LEC [2:0] : Last Error Code (see Mcan_Hal_ProtocolErrorType)

  • ACT [4:3] : Activity state (see Mcan_Hal_ActivityStateType)

  • EP [5] : Error Passive flag

  • EW [6] : Warning Status flag

  • BO [7] : Bus Off flag

  • DLEC [10:8] : Data phase Last Error Code

  • RESI [11] : ESI flag of last received FD message

  • RBRS [12] : BRS flag of last received FD message

  • RFDF [13] : Received an FD message flag

  • PXE [14] : Protocol Exception Event flag

  • TDCV [22:16]: Transmitter Delay Compensation Value (0-127 mtq)

Functions Documentation

function Mcan_Hal_InitParamsSetDefault

sint32 Mcan_Hal_InitParamsSetDefault(
    Mcan_Hal_InitParamsType * paramsPtr
)

Initializes the CAN module with Default Parameters.

Parameters:

  • paramsPtr Pointer to CAN HW initialization parameters

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]

function Mcan_Hal_Init

sint32 Mcan_Hal_Init(
    Mcan_Hal_InstanceType * instancePtr,
    const Mcan_Hal_InitParamsType * paramsPtr
)

Initialize a CAN HW instance.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • paramsPtr Pointer to CAN HW initialization parameters

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if paramsPtr is NULL MCAN_HAL_ERROR_INVALID_STATE if instancePtr is not in UNCONFIGURED state

Initializes the CAN hardware instance with the provided configuration parameters. Sets up the basic instance structure, registers, and state.

function Mcan_Hal_DeInit

sint32 Mcan_Hal_DeInit(
    Mcan_Hal_InstanceType * instancePtr
)

De-initialize a CAN HW instance.

Parameters:

  • instancePtr Pointer to CAN HW instance

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL

Disable the HW and any enabled interrupts at the CAN HW. Resets the instance state to UNCONFIGURED.

function Mcan_Hal_SetBaudrate

sint32 Mcan_Hal_SetBaudrate(
    Mcan_Hal_InstanceType * instancePtr,
    const Mcan_Hal_BaudParamsType * bitparamsPtr
)

Set CAN bit rate parameters.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • bitparamsPtr Pointer to CAN bit rate parameters

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if bitparamsPtr is NULL

Precondition: CAN communication must be stopped (controller in SW_INIT mode, MCAN_CCCR.INIT=1 and CCE=1)

Configures the CAN bit rate using the provided parameters. Must be called while controller is in SW_INIT mode (after Mcan_Hal_Init(), before Mcan_Hal_Start()).

function Mcan_Hal_GetMsgRamLayout

sint32 Mcan_Hal_GetMsgRamLayout(
    const Mcan_Hal_InstanceType * instancePtr,
    Mcan_Hal_MsgRamLayoutType * layoutPtr
)

Get the configured Message RAM layout.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • layoutPtr Pointer to structure to receive all section start addresses

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if layoutPtr is NULL

Precondition: Mcan_Hal_Init() must have been called successfully.

Reads the hardware address registers for all Message RAM sections (Standard/Extended filter lists, TX buffers, TX Event FIFO, RX FIFO 0/1, RX buffers) and returns them in a single Mcan_Hal_MsgRamLayoutType structure. A field is 0 when the corresponding section was not configured.

function Mcan_Hal_Start

sint32 Mcan_Hal_Start(
    Mcan_Hal_InstanceType * instancePtr
)

Start CAN protocol operation.

Parameters:

  • instancePtr Pointer to CAN HW instance

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_STATE if controller is not in STOP state

Precondition: Controller must be in STOP state (after Mcan_Hal_SetBaudrate())

Transitions the CAN controller from SW_INIT mode to Normal operational mode by clearing MCAN_CCCR.INIT. After this call, the controller is actively monitoring the CAN bus and can transmit/receive messages. Instance state transitions to START.

function Mcan_Hal_Stop

sint32 Mcan_Hal_Stop(
    Mcan_Hal_InstanceType * instancePtr
)

Stop CAN protocol operation (immediate)

Parameters:

  • instancePtr Pointer to CAN HW instance

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_STATE if controller is in UNCONFIGURED state

Note: This is an immediate stop For a graceful stop (finish current frame before stopping), use the clock-stop request mechanism:

  1. Set MCAN_CCCR.CSR=1 (via DL_MCAN directly using DL_MCAN_addClockStopRequest())

  2. Poll Mcan_Hal_GetStopStatus() until it returns TRUE (hardware sets MCAN_CCCR.INIT=1 and MCAN_CCCR.CSA=1 when done)

  3. Call Mcan_Hal_Stop() to update the HAL state to STOP

Sets MCAN_CCCR.INIT=1 directly to enter SW_INIT mode. Any frame currently being transmitted is aborted immediately. Instance state transitions to STOP.

function Mcan_Hal_GetStopStatus

sint32 Mcan_Hal_GetStopStatus(
    const Mcan_Hal_InstanceType * instancePtr,
    boolean * isStopPtr
)

Check whether the CAN controller has stopped.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • isStopPtr Pointer to boolean; set to TRUE when MCAN_CCCR.INIT=1 (stopped), FALSE when MCAN_CCCR.INIT=0 (running)

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if isStopPtr is NULL MCAN_HAL_ERROR_INVALID_STATE if controller is in UNCONFIGURED state

Reads MCAN_CCCR.INIT to determine if the controller is in SW_INIT mode (stopped). Returns TRUE when MCAN_CCCR.INIT=1, FALSE when MCAN_CCCR.INIT=0 (normal operation).

Use this after requesting a graceful stop (MCAN_CCCR.CSR=1) to poll until the hardware has finished pending transmissions and entered SW_INIT mode. After this returns TRUE, call Mcan_Hal_Stop() to update the HAL state.

function Mcan_Hal_Reset

sint32 Mcan_Hal_Reset(
    const Mcan_Hal_InstanceType * instancePtr
)

Protocol-level reset of the CAN controller.

Parameters:

  • instancePtr Pointer to CAN HW instance

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_STATE if controller is not in INITIALIZED or STOP state

Note: This is a protocol-only reset. It does NOT clear filter lists, message RAM configuration, TX/RX FIFO/buffer layouts, or interrupt settings. To perform a full peripheral reset (clearing all configuration), call Mcan_Hal_DeInit() followed by Mcan_Hal_Init().

Performs a CAN protocol reset by toggling MCAN_CCCR.INIT (SW_INIT → Normal). This resets the CAN protocol state machine and error counters, and causes the controller to re-synchronize to the bus after detecting 11 consecutive recessive bits.

function Mcan_Hal_ConfigureLoopbackMode

sint32 Mcan_Hal_ConfigureLoopbackMode(
    const Mcan_Hal_InstanceType * instancePtr,
    Mcan_Hal_LoopbackModeType mode
)

Configure CAN loopback mode.

Parameters:

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_STATE if controller is in MCAN_HAL_STATE_START

Precondition: CAN controller must not be in MCAN_HAL_STATE_START (must be stopped or initialized)

Configures the MCAN controller loopback mode. When MCAN_HAL_LOOPBACK_INTERNAL is selected, MCAN_CCCR.TEST=1, MCAN_TEST.LBCK=1, and MCAN_CCCR.MON=1 are set — every transmitted frame is received by this node without appearing on the external CAN bus. When MCAN_HAL_LOOPBACK_EXTERNAL is selected, MCAN_CCCR.TEST=1 and MCAN_TEST.LBCK=1 are set — transmitted frames appear on the bus and are also received by this node. When MCAN_HAL_LOOPBACK_NONE is selected, all loopback and test bits are cleared.

function Mcan_Hal_GetProtocolControllerStatus

sint32 Mcan_Hal_GetProtocolControllerStatus(
    const Mcan_Hal_InstanceType * instancePtr,
    uint32 * protocolControllerStatusPtr
)

Get CAN protocol controller status.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • protocolControllerStatusPtr Pointer to store the bitmask of active MCAN_HAL_PROTOCOL_CONTROLLER_STATUS flags

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if protocolControllerStatusPtr is NULL

Reads the MCAN_PSR register and returns a bitmask of active [MCAN_HAL_PROTOCOL_CONTROLLER_STATUS] flags. Multiple flags may be set simultaneously; test individual bits with the MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_* macros.

function Mcan_Hal_GetErrorCounterStatus

sint32 Mcan_Hal_GetErrorCounterStatus(
    Mcan_Hal_InstanceType * instancePtr,
    Mcan_Hal_ErrorCounterStatusType * counterPtr
)

Get CAN error counter status.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • counterPtr Pointer to store error counter status information

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if counterPtr is NULL

Retrieves the transmit and receive error counters along with error passive status from MCAN_ECR register.

function Mcan_Hal_GetHighPriorityMsgStatus

sint32 Mcan_Hal_GetHighPriorityMsgStatus(
    const Mcan_Hal_InstanceType * instancePtr,
    Mcan_Hal_HighPriorityMsgStatusType * statusPtr
)

Get High Priority Message status.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • statusPtr Pointer to store high priority message status

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if statusPtr is NULL

Reads the MCAN_HPMS register which is updated whenever a filter element configured with SFEC/EFEC = 100, 101, or 110 (High Priority Message actions) matches a received frame.

function Mcan_Hal_MessageParamsSetDefault

sint32 Mcan_Hal_MessageParamsSetDefault(
    Mcan_Hal_MessageParamsType * msgParamsPtr
)

Initializes the CAN Message Parameters with Default Values.

Parameters:

  • msgParamsPtr Pointer to CAN message parameters

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_PARAM_POINTER if msgParamsPtr is NULL

Sets all fields of the Mcan_Hal_MessageParamsType structure to their default values. This function should be called before configuring specific message parameters.

function Mcan_Hal_Tx

sint32 Mcan_Hal_Tx(
    Mcan_Hal_InstanceType * instancePtr,
    const Mcan_Hal_MessageParamsType * msgParamsPtr,
    const Mcan_Hal_TransferParamsType * transferParamsPtr
)

Transmit a CAN message.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • msgParamsPtr Pointer to message parameters (ID, format, flags)

  • transferParamsPtr Pointer to transfer parameters (data buffer and length)

Return:

Precondition:

  • Controller must be in START state (after Mcan_Hal_Start())

  • For Classic CAN: DataLenBytes must be 0-8; for CAN FD: 0-64

  • For standard ID: StandardMessageID must be 0-0x7FF; for extended: 0-0x1FFFFFFF

  • DataBufferPtr must point to a buffer of at least DataLenBytes bytes

Queues a CAN message for transmission via the specified TX buffer type (FIFO, Queue, or Dedicated buffer).

function Mcan_Hal_CancelTxBuffer

sint32 Mcan_Hal_CancelTxBuffer(
    Mcan_Hal_InstanceType * instancePtr,
    uint8 bufferIndex
)

Cancel a pending TX buffer transmission.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • bufferIndex TX buffer index to cancel (0 to TxBufNum, must not be a TX FIFO slot

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAMS if bufferIndex >= MCAN_HAL_TX_BUFFER_MAX or bufferIndex refers to a TX FIFO slot (not a dedicated buffer or queue buffer)

Requests cancellation of a pending transmission from a dedicated TX buffer or TX Queue buffer by setting the corresponding bit in MCAN_TXBCR. Cancellation is not intended for TX FIFO. Successful cancellation is signaled by MCAN_TXBCF and interrupt MCAN_IR.TCF.

function Mcan_Hal_GetTxBufTransmissionStatus

sint32 Mcan_Hal_GetTxBufTransmissionStatus(
    const Mcan_Hal_InstanceType * instancePtr,
    uint32 * txBtoMaskPtr
)

Get TX buffer transmission status bitmask (MCAN_TXBTO)

Parameters:

  • instancePtr Pointer to CAN HW instance

  • txBtoMaskPtr Pointer to receive the MCAN_TXBTO bitmask (bits 0-31, one bit per TX buffer). Must not be NULL.

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if txBtoMaskPtr is NULL

Note: For TX FIFO operation, use Mcan_Hal_TxEventFifoDequeue() with MessageMarker instead, since FIFO buffers are reused and the buffer index is not meaningful.

Reads the MCAN_TXBTO (Tx Buffer Transmission Occurred) register and returns the bitmask in txBtoMaskPtr. Each bit N corresponds to TX buffer N (0-31):

  • Bit N = 1: buffer N has successfully transmitted a frame

  • Bit N = 0: buffer N has not transmitted since the last CCE cycle

function Mcan_Hal_CheckTxConfirmationPoll

sint32 Mcan_Hal_CheckTxConfirmationPoll(
    const Mcan_Hal_InstanceType * instancePtr,
    boolean * isTransferCompletePtr
)

Check TX Confirmation status (polling mode)

Parameters:

  • instancePtr Pointer to CAN HW instance

  • isTransferCompletePtr Pointer to store transfer completion status (TRUE if transfer completed, FALSE otherwise)

Return:

Note: For dedicated TX buffer status without the TX Event FIFO, use Mcan_Hal_GetTxBufTransmissionStatus() to read MCAN_TXBTO directly.

Checks the TX Event FIFO new entry flag (MCAN_IR.TEFN) to determine whether the controller has successfully transmitted a frame. Returns MCAN_HAL_FIFO_EMPTY when no transmission has completed yet. Use Mcan_Hal_TxEventFifoDequeue() to retrieve the TX event details after this returns MCAN_HAL_ERROR_NONE.

function Mcan_Hal_TxEventFifoDequeue

sint32 Mcan_Hal_TxEventFifoDequeue(
    Mcan_Hal_InstanceType * instancePtr,
    Mcan_Hal_TxEventFifoElementType * txEventElemPtr
)

Dequeue one TX event element.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • txEventElemPtr Pointer to structure to receive the TX event element fields

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if txEventElemPtr is NULL MCAN_HAL_FIFO_EMPTY if TX Event FIFO is empty

Reads the next element from the TX Event FIFO, advances the get index (MCAN_TXEFA)

function Mcan_Hal_RxFifoPoll

sint32 Mcan_Hal_RxFifoPoll(
    Mcan_Hal_InstanceType * instancePtr
)

Check RX FIFOs for pending received frames and invoke the RX indication callback.

Parameters:

  • instancePtr Pointer to CAN HW instance

Return:

Reads MCAN_IR.RF0N and MCAN_IR.RF1N. For each active FIFO (FIFO 0 checked before FIFO 1), clears the interrupt flag and invokes the registered RxIndicationCb with the corresponding MCAN_HAL_RX_FIFO_0 or MCAN_HAL_RX_FIFO_1 source. The callback must call Mcan_Hal_RxFifoDequeue() to read the frame. Returns MCAN_HAL_FIFO_EMPTY immediately if neither FIFO has data.

function Mcan_Hal_RxFifoDequeue

sint32 Mcan_Hal_RxFifoDequeue(
    Mcan_Hal_InstanceType * instancePtr,
    Mcan_Hal_RxFifoType rxFifo,
    Mcan_Hal_MessageParamsType * msgParamsPtr,
    Mcan_Hal_TransferParamsType * transferParamsPtr
)

Dequeue one RX frame from the specified RX FIFO.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • rxFifo RX FIFO to dequeue from (MCAN_HAL_RX_FIFO_0 or MCAN_HAL_RX_FIFO_1)

  • msgParamsPtr Pointer to message parameters; populated with received frame header fields on return

  • transferParamsPtr Pointer to transfer parameters; DataBufferPtr must point to a buffer large enough to hold the received payload (up to MCAN_HAL_MSG_LEN_MAX_FD_BYTES)

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if msgParamsPtr or transferParamsPtr is NULL MCAN_HAL_FIFO_EMPTY if the specified RX FIFO is empty

Note: Only MCAN_HAL_RX_FIFO_0 and MCAN_HAL_RX_FIFO_1 are valid for rxFifo. For dedicated RX buffers, use Mcan_Hal_RxDedicatedBufDequeue() instead.

Reads one frame from the specified RX FIFO into msgParamsPtr and transferParamsPtr, and advances the FIFO get index (MCAN_RXFnA).

function Mcan_Hal_RxBufPoll

sint32 Mcan_Hal_RxBufPoll(
    Mcan_Hal_InstanceType * instancePtr,
    uint8 * bufferIndexPtr
)

Find the next dedicated RX buffer with new data.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • bufferIndexPtr Pointer to receive the buffer index (0 to MCAN_HAL_RX_BUFFER_MAX-1) of the next buffer with new data. Must not be NULL.

Return:

Note: The buffer index returned corresponds to the RxBufferIndex configured in the filter element (Mcan_Hal_RxFilterElementType::RxBufferIndex) during Mcan_Hal_AddOrUpdateRxFilterElement().

Scans MCAN_NDAT1 (buffers 0-31) then MCAN_NDAT2 (buffers 32-63) and returns the lowest-indexed buffer with its new-data flag set. Call this from within the Mcan_Hal_RxDedicatedBufCallbackType to find which buffer indices have new data, then call Mcan_Hal_RxDedicatedBufDequeue() for each set bit. Call in a loop until MCAN_HAL_FIFO_EMPTY when using polling mode.

function Mcan_Hal_RxDedicatedBufDequeue

sint32 Mcan_Hal_RxDedicatedBufDequeue(
    Mcan_Hal_InstanceType * instancePtr,
    uint8 bufferIndex,
    Mcan_Hal_MessageParamsType * msgParamsPtr,
    Mcan_Hal_TransferParamsType * transferParamsPtr
)

Read a CAN message from a dedicated RX buffer and clear its NDAT flag.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • bufferIndex Dedicated RX buffer index (0 to MCAN_HAL_RX_BUFFER_MAX-1)

  • msgParamsPtr Pointer to message parameters (filled with received message info)

  • transferParamsPtr Pointer to transfer parameters; DataBufferPtr must point to a buffer large enough to hold the received payload

Return:

Note: The NDAT flag must be set before calling this function. If the NDAT flag is not set, the buffer may contain stale data and this function returns MCAN_HAL_FIFO_EMPTY without reading.

Reads the received message from the specified dedicated RX buffer in the Message RAM, populates msgParamsPtr and transferParamsPtr, and clears the corresponding MCAN_NDAT1/2 new-data flag.

In polling mode, call after Mcan_Hal_RxBufPoll() returns a buffer index. In interrupt mode, call for each set bit in the ndatLow/ndatHigh bitmasks passed to Mcan_Hal_RxDedicatedBufCallbackType.

function Mcan_Hal_AddOrUpdateRxFilterElement

sint32 Mcan_Hal_AddOrUpdateRxFilterElement(
    Mcan_Hal_InstanceType * instancePtr,
    const Mcan_Hal_RxFilterElementType * filterElementPtr
)

Add or update an RX filter element.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • filterElementPtr Pointer to filter element configuration; FilterIndex selects the slot to write (0 to StdFilterCount-1 for standard, 0 to ExtFilterCount-1 for extended)

Return:

Writes an RX filter element at the index specified by filterElementPtr->FilterIndex. This function both adds new filter elements and overwrites existing ones. For standard ID filters: FilterIndex must be 0 to (StdFilterCount - 1). For extended ID filters (UseExtendedID=TRUE): FilterIndex must be 0 to (ExtFilterCount - 1).

Filter Type Configuration:

  • RANGE (0): For standard ID: sfid2 >= ID >= sfid1; For extended: efid2 >= ID >= efid1

  • DUAL (1): ID matches sfid1 OR sfid2 (default, commonly used)

  • MASK (2): Classic mask filtering: (ID & mask) == (filter_id & mask)

  • RANGE_NO_XIDAM (3): Range filter without XIDAM mask (extended only)

function Mcan_Hal_ClearRxFilterElement

sint32 Mcan_Hal_ClearRxFilterElement(
    Mcan_Hal_InstanceType * instancePtr,
    const Mcan_Hal_RxFilterElementType * filterElementPtr
)

Clear RX filter element.

Parameters:

  • instancePtr Pointer to CAN HW instance

  • filterElementPtr Pointer to filter element; only FilterIndex and UseExtendedID are used to identify which filter slot to clear

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_PARAM_POINTER if filterElementPtr is NULL MCAN_HAL_ERROR_INVALID_PARAMS if FilterIndex is out of range for the filter list

Clears/removes an RX filter element

Filter elements can be cleared anytime while the IP is in operation.

function Mcan_Hal_EnableInterrupts

sint32 Mcan_Hal_EnableInterrupts(
    const Mcan_Hal_InstanceType * instancePtr
)

Enable CAN interrupts.

Parameters:

  • instancePtr Pointer to CAN HW instance

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_STATE if controller is in UNCONFIGURED state

Note: The HAL uses a single MCAN interrupt line at a time; Line 0 and Line 1 cannot be used simultaneously. By default, the HAL is configured to use Line 0, so all interrupt sources (TX, RX, error) are routed to Line 0.

Enables MCAN interrupt sources and interrupt lines based on the processing modes configured during Mcan_Hal_Init(). Called automatically by Mcan_Hal_Init().

All interrupt sources are routed to interrupt Line 0

function Mcan_Hal_DisableInterrupts

sint32 Mcan_Hal_DisableInterrupts(
    const Mcan_Hal_InstanceType * instancePtr
)

Disable CAN interrupts.

Parameters:

  • instancePtr Pointer to CAN HW instance

Return: MCAN_HAL_ERROR_NONE on success, otherwise error code [Mcan_Hal_ErrorType]MCAN_HAL_ERROR_INVALID_INSTANCE if instancePtr is NULL MCAN_HAL_ERROR_INVALID_STATE if controller is in UNCONFIGURED state

Disables MCAN interrupt sources and interrupt lines that were enabled by Mcan_Hal_EnableInterrupts(). Mirrors the enable logic exactly.

function Mcan_Hal_InterruptHandler_Line0

void Mcan_Hal_InterruptHandler_Line0(
    Mcan_Hal_InstanceType * instancePtr
)

CAN Interrupt Handler.

Parameters:

  • instancePtr Pointer to CAN HW instance

Note: If callbacks are NULL, the corresponding events are silently discarded.

Precondition:

Processes all pending MCAN interrupt sources routed to Line 0 and invokes the registered callbacks: TX confirmation, RX indication, and error/status events.

The HAL uses Line 0 by default, and Line 0 and Line 1 cannot be used at the same time. All interrupt sources (TX, RX, error) are therefore routed to Line 0 by Mcan_Hal_EnableInterrupts()

Macros Documentation

define MCAN_HAL_ERROR_NONE

#define MCAN_HAL_ERROR_NONE (0)

No error.

define MCAN_HAL_ERROR_INVALID_INSTANCE

#define MCAN_HAL_ERROR_INVALID_INSTANCE (1)

Invalid instance pointer.

define MCAN_HAL_ERROR_INVALID_PARAM_POINTER

#define MCAN_HAL_ERROR_INVALID_PARAM_POINTER (2)

Invalid parameter pointer.

define MCAN_HAL_ERROR_INVALID_PARAMS

#define MCAN_HAL_ERROR_INVALID_PARAMS (3)

Invalid parameters.

define MCAN_HAL_ERROR_UNSUPPORTED_FEATURE

#define MCAN_HAL_ERROR_UNSUPPORTED_FEATURE (4)

Unsupported operation.

define MCAN_HAL_ERROR_HW_BUSY

#define MCAN_HAL_ERROR_HW_BUSY (5)

CAN transfer fail since underlying HW was busy.

define MCAN_HAL_ERROR_INVALID_STATE

#define MCAN_HAL_ERROR_INVALID_STATE (6)

Invalid state for the requested operation.

define MCAN_HAL_FIFO_EMPTY

#define MCAN_HAL_FIFO_EMPTY (7)

FIFO/Event FIFO is empty — no message available to read.

define MCAN_HAL_MSG_LEN_MAX_CLASSIC_BYTES

#define MCAN_HAL_MSG_LEN_MAX_CLASSIC_BYTES (8U)

Maximum data length for Classic CAN (8 bytes)

define MCAN_HAL_MSG_LEN_MAX_FD_BYTES

#define MCAN_HAL_MSG_LEN_MAX_FD_BYTES (64U)

Maximum data length for CAN FD (64 bytes)

define MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_NEW_ENTRY

#define MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_NEW_ENTRY (MCAN_IR_TEFN_MASK)

TX Event FIFO New Entry.

define MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_WATERMARK

#define MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_WATERMARK (MCAN_IR_TEFW_MASK)

TX Event FIFO Watermark Reached.

define MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_FULL

#define MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_FULL (MCAN_IR_TEFF_MASK)

TX Event FIFO Full.

define MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_ELEM_LOST

#define MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_ELEM_LOST (MCAN_IR_TEFL_MASK)

TX Event FIFO Element Lost.

define MCAN_HAL_INTR_SRC_TX_FIFO_EMPTY

#define MCAN_HAL_INTR_SRC_TX_FIFO_EMPTY (MCAN_IR_TFE_MASK)

TX FIFO Empty.

define MCAN_HAL_INTR_SRC_TX_COMPLETE

#define MCAN_HAL_INTR_SRC_TX_COMPLETE (MCAN_IR_TC_MASK)

Transmission Completed.

define MCAN_HAL_INTR_SRC_TX_CANCEL_FINISH

#define MCAN_HAL_INTR_SRC_TX_CANCEL_FINISH (MCAN_IR_TCF_MASK)

Transmission Cancellation Finished.

define MCAN_HAL_INTR_SRC_TX_DEFAULT

#define MCAN_HAL_INTR_SRC_TX_DEFAULT     ((uint32)(MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_NEW_ENTRY | MCAN_HAL_INTR_SRC_TX_CANCEL_FINISH))

Default TX interrupt mask.

define MCAN_HAL_INTR_SRC_RX_FIFO0_NEW_MSG

#define MCAN_HAL_INTR_SRC_RX_FIFO0_NEW_MSG (MCAN_IR_RF0N_MASK)

RX FIFO 0 New Message.

define MCAN_HAL_INTR_SRC_RX_FIFO0_WATERMARK

#define MCAN_HAL_INTR_SRC_RX_FIFO0_WATERMARK (MCAN_IR_RF0W_MASK)

RX FIFO 0 Watermark Reached.

define MCAN_HAL_INTR_SRC_RX_FIFO0_FULL

#define MCAN_HAL_INTR_SRC_RX_FIFO0_FULL (MCAN_IR_RF0F_MASK)

RX FIFO 0 Full.

define MCAN_HAL_INTR_SRC_RX_FIFO0_MSG_LOST

#define MCAN_HAL_INTR_SRC_RX_FIFO0_MSG_LOST (MCAN_IR_RF0L_MASK)

RX FIFO 0 Message Lost.

define MCAN_HAL_INTR_SRC_RX_FIFO1_NEW_MSG

#define MCAN_HAL_INTR_SRC_RX_FIFO1_NEW_MSG (MCAN_IR_RF1N_MASK)

RX FIFO 1 New Message.

define MCAN_HAL_INTR_SRC_RX_FIFO1_WATERMARK

#define MCAN_HAL_INTR_SRC_RX_FIFO1_WATERMARK (MCAN_IR_RF1W_MASK)

RX FIFO 1 Watermark Reached.

define MCAN_HAL_INTR_SRC_RX_FIFO1_FULL

#define MCAN_HAL_INTR_SRC_RX_FIFO1_FULL (MCAN_IR_RF1F_MASK)

RX FIFO 1 Full.

define MCAN_HAL_INTR_SRC_RX_FIFO1_MSG_LOST

#define MCAN_HAL_INTR_SRC_RX_FIFO1_MSG_LOST (MCAN_IR_RF1L_MASK)

RX FIFO 1 Message Lost.

define MCAN_HAL_INTR_SRC_RX_HIGH_PRIORITY_MSG

#define MCAN_HAL_INTR_SRC_RX_HIGH_PRIORITY_MSG (MCAN_IR_HPM_MASK)

High Priority Message.

define MCAN_HAL_INTR_SRC_RX_DEDICATED_BUF

#define MCAN_HAL_INTR_SRC_RX_DEDICATED_BUF (MCAN_IR_DRX_MASK)

Message Stored to Dedicated RX Buffer.

define MCAN_HAL_INTR_SRC_RX_DEFAULT

#define MCAN_HAL_INTR_SRC_RX_DEFAULT     ((uint32)(MCAN_HAL_INTR_SRC_RX_FIFO0_NEW_MSG | MCAN_HAL_INTR_SRC_RX_FIFO1_NEW_MSG | \
              MCAN_HAL_INTR_SRC_RX_HIGH_PRIORITY_MSG | MCAN_HAL_INTR_SRC_RX_DEDICATED_BUF))

Default RX interrupt mask.

define MCAN_HAL_INTR_SRC_ERR_ERROR_PASSIVE

#define MCAN_HAL_INTR_SRC_ERR_ERROR_PASSIVE (MCAN_IR_EP_MASK)

Error Passive state change.

define MCAN_HAL_INTR_SRC_ERR_WARNING

#define MCAN_HAL_INTR_SRC_ERR_WARNING (MCAN_IR_EW_MASK)

Warning Status change.

define MCAN_HAL_INTR_SRC_ERR_BUS_OFF

#define MCAN_HAL_INTR_SRC_ERR_BUS_OFF (MCAN_IR_BO_MASK)

Bus Off state change.

define MCAN_HAL_INTR_SRC_ERR_WATCHDOG

#define MCAN_HAL_INTR_SRC_ERR_WATCHDOG (MCAN_IR_WDI_MASK)

Watchdog Interrupt.

define MCAN_HAL_INTR_SRC_ERR_PROTOCOL_ARB

#define MCAN_HAL_INTR_SRC_ERR_PROTOCOL_ARB (MCAN_IR_PEA_MASK)

Protocol Error in Arbitration Phase.

define MCAN_HAL_INTR_SRC_ERR_PROTOCOL_DATA

#define MCAN_HAL_INTR_SRC_ERR_PROTOCOL_DATA (MCAN_IR_PED_MASK)

Protocol Error in Data Phase.

define MCAN_HAL_INTR_SRC_ERR_RESERVED_ADDR

#define MCAN_HAL_INTR_SRC_ERR_RESERVED_ADDR (MCAN_IR_ARA_MASK)

Access to Reserved Address.

define MCAN_HAL_INTR_SRC_ERR_MSG_RAM_ACCESS

#define MCAN_HAL_INTR_SRC_ERR_MSG_RAM_ACCESS (MCAN_IR_MRAF_MASK)

Message RAM Access Failure.

define MCAN_HAL_INTR_SRC_ERR_TIMEOUT

#define MCAN_HAL_INTR_SRC_ERR_TIMEOUT (MCAN_IR_TOO_MASK)

Timeout Occurred.

define MCAN_HAL_INTR_SRC_ERR_TIMESTAMP_WRAP

#define MCAN_HAL_INTR_SRC_ERR_TIMESTAMP_WRAP (MCAN_IR_TSW_MASK)

Timestamp Wraparound.

define MCAN_HAL_INTR_SRC_ERR_LOGGING_OVERFLOW

#define MCAN_HAL_INTR_SRC_ERR_LOGGING_OVERFLOW (MCAN_IR_ELO_MASK)

Error Logging Overflow.

define MCAN_HAL_INTR_SRC_ERR_BIT_ERR_UNCORRECTED

#define MCAN_HAL_INTR_SRC_ERR_BIT_ERR_UNCORRECTED (MCAN_IR_BEU_MASK)

Bit Error Uncorrected.

define MCAN_HAL_INTR_SRC_ERR_DEFAULT

#define MCAN_HAL_INTR_SRC_ERR_DEFAULT     ((uint32)(MCAN_HAL_INTR_SRC_ERR_BUS_OFF | MCAN_HAL_INTR_SRC_ERR_ERROR_PASSIVE | MCAN_HAL_INTR_SRC_ERR_WARNING | \
              MCAN_HAL_INTR_SRC_ERR_MSG_RAM_ACCESS | MCAN_HAL_INTR_SRC_RX_FIFO0_MSG_LOST |                          \
              MCAN_HAL_INTR_SRC_RX_FIFO1_MSG_LOST | MCAN_HAL_INTR_SRC_TX_EVENT_FIFO_ELEM_LOST))

Default error interrupt mask.

define MCAN_HAL_RX_STD_FILTER_ELEMENT_MAX

#define MCAN_HAL_RX_STD_FILTER_ELEMENT_MAX (128U)

Maximum number of standard ID RX filter elements supported by MCAN FD.

define MCAN_HAL_RX_EXT_FILTER_ELEMENT_MAX

#define MCAN_HAL_RX_EXT_FILTER_ELEMENT_MAX (64U)

Maximum number of extended ID RX filter elements supported by MCAN FD.

define MCAN_HAL_RX_FILTER_ELEMENT_MAX

#define MCAN_HAL_RX_FILTER_ELEMENT_MAX (128U)

Maximum number of RX filter elements supported by MCAN FD.

define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_SYNCHRONIZING

#define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_SYNCHRONIZING (0x00U)

ACT == 0b00: Controller is synchronizing (bus integration)

define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_IDLE

#define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_IDLE (1U << MCAN_PSR_ACT_OFS)

ACT == 0b01: Controller is idle on the CAN bus.

define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_RECEIVER

#define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_RECEIVER (2U << MCAN_PSR_ACT_OFS)

ACT == 0b10: Controller is currently receiving a frame.

define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_TRANSMITTER

#define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_TRANSMITTER (3U << MCAN_PSR_ACT_OFS)

ACT == 0b11: Controller is currently transmitting a frame.

define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_MASK

#define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ACT_MASK (MCAN_PSR_ACT_MASK)

Mask to extract the ACT field from the status value.

define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ERROR_PASSIVE

#define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_ERROR_PASSIVE (MCAN_PSR_EP_MASK)

Error Passive flag (MCAN_PSR.EP == 1). The node’s error counter has exceeded the error-passive threshold (128).

define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_WARNING

#define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_WARNING (MCAN_PSR_EW_MASK)

Warning Status flag (MCAN_PSR.EW == 1). At least one error counter has reached the warning level (96).

define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_BUS_OFF

#define MCAN_HAL_PROTOCOL_CONTROLLER_STATUS_BUS_OFF (MCAN_PSR_BO_MASK)

Bus Off flag (MCAN_PSR.BO == 1). The transmit error counter exceeded 255; CAN protocol operation is stopped.

define MCAN_HAL_RX_BUFFER_MAX

#define MCAN_HAL_RX_BUFFER_MAX (64U)

Maximum number of dedicated RX buffers (MCAN_RXBC, up to 64)

define MCAN_HAL_TX_BUFFER_MAX

#define MCAN_HAL_TX_BUFFER_MAX (32U)

Maximum number of TX buffers (dedicated + FIFO/Queue combined, MCAN_TXBC, up to 32)