S32 SDK
flexcan_hal.c File Reference
#include "flexcan_hal.h"

Go to the source code of this file.

Macros

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_RTR_SHIFT   (31U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_IDE_SHIFT   (30U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_RTR_SHIFT   (15U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_IDE_SHIFT   (14U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_EXT_MASK   (0x3FFFFFFFU)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_EXT_SHIFT   (1U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_STD_MASK   (0x3FF80000U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_STD_SHIFT   (19U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_MASK   (0x3FFFU)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT1   (16U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT2   (0U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_MASK   (0x7FFU)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT1   (19U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT2   (3U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_MASK   (0xFFU)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT1   (24U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT2   (16U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT3   (8U)
 
#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT4   (0U)
 
#define FLEXCAN_ALL_INT   (0x0007U)
 
#define CAN_DLC_VALUE_12_BYTES   9U
 
#define CAN_DLC_VALUE_16_BYTES   10U
 
#define CAN_DLC_VALUE_20_BYTES   11U
 
#define CAN_DLC_VALUE_24_BYTES   12U
 
#define CAN_DLC_VALUE_32_BYTES   13U
 
#define CAN_DLC_VALUE_48_BYTES   14U
 
#define CAN_DLC_VALUE_64_BYTES   15U
 
#define RxFifoFilterTableOffset   0x18U
 
#define FlexCanRxFifoAcceptRemoteFrame   1UL
 
#define FlexCanRxFifoAcceptExtFrame   1UL
 
#define FLEXCAN_8_BYTE_PAYLOAD_MB_SIZE   16U
 
#define FLEXCAN_ARBITRATION_FIELD_SIZE   8U
 
#define FlexcanSwapBytesInWordIndex(index)   (((index) & ~3U) + (3U - ((index) & 3U)))
 
#define RxFifoFilterElementNum(x)   (((x) + 1U) * 8U)
 

Functions

static volatile uint32_t * FLEXCAN_HAL_GetMsgBuffRegion (CAN_Type *base, uint32_t msgBuffIdx)
 
static uint8_t FLEXCAN_HAL_ComputeDLCValue (uint8_t payloadSize)
 
static uint8_t FLEXCAN_HAL_ComputePayloadSize (uint8_t dlcValue)
 
static uint32_t FLEXCAN_HAL_MaxMbRAMSize (const CAN_Type *base)
 
static void FLEXCAN_HAL_ClearRAM (CAN_Type *base)
 
static uint32_t RxFifoOcuppiedLastMsgBuff (uint32_t x)
 
void FLEXCAN_HAL_Enable (CAN_Type *base)
 Enables FlexCAN controller. More...
 
void FLEXCAN_HAL_Disable (CAN_Type *base)
 Disables FlexCAN controller. More...
 
void FLEXCAN_HAL_Init (CAN_Type *base)
 Initializes the FlexCAN controller. More...
 
void FLEXCAN_HAL_SetTimeSegments (CAN_Type *base, const flexcan_time_segment_t *timeSeg)
 Sets the FlexCAN time segments for setting up bit rate. More...
 
void FLEXCAN_HAL_SetTimeSegmentsCbt (CAN_Type *base, const flexcan_time_segment_t *timeSeg)
 Sets the FlexCAN time segments for setting up bit rate for FD BRS. More...
 
void FLEXCAN_HAL_GetTimeSegments (const CAN_Type *base, flexcan_time_segment_t *timeSeg)
 Gets the FlexCAN time segments to calculate the bit rate. More...
 
status_t FLEXCAN_HAL_SetTxMsgBuff (CAN_Type *base, uint32_t msgBuffIdx, const flexcan_msgbuff_code_status_t *cs, uint32_t msgId, const uint8_t *msgData)
 Sets the FlexCAN message buffer fields for transmitting. More...
 
status_t FLEXCAN_HAL_SetRxMsgBuff (CAN_Type *base, uint32_t msgBuffIdx, const flexcan_msgbuff_code_status_t *cs, uint32_t msgId)
 Sets the FlexCAN message buffer fields for receiving. More...
 
status_t FLEXCAN_HAL_GetMsgBuff (CAN_Type *base, uint32_t msgBuffIdx, flexcan_msgbuff_t *msgBuff)
 Gets the FlexCAN message buffer fields. More...
 
status_t FLEXCAN_HAL_LockRxMsgBuff (CAN_Type *base, uint32_t msgBuffIdx)
 Locks the FlexCAN Rx message buffer. More...
 
status_t FLEXCAN_HAL_EnableRxFifo (CAN_Type *base, uint32_t numOfFilters)
 Enables the Rx FIFO. More...
 
void FLEXCAN_HAL_DisableRxFifo (CAN_Type *base)
 Disables the Rx FIFO. More...
 
void FLEXCAN_HAL_SetRxFifoFilterNum (CAN_Type *base, uint32_t number)
 Sets the number of the Rx FIFO filters. More...
 
status_t FLEXCAN_HAL_SetMaxMsgBuffNum (CAN_Type *base, uint32_t maxMsgBuffNum)
 Sets the maximum number of Message Buffers. More...
 
void FLEXCAN_HAL_SetRxFifoFilter (CAN_Type *base, flexcan_rx_fifo_id_element_format_t idFormat, const flexcan_id_table_t *idFilterTable)
 Sets the FlexCAN Rx FIFO fields. More...
 
status_t FLEXCAN_HAL_SetMsgBuffIntCmd (CAN_Type *base, uint32_t msgBuffIdx, bool enable)
 Enables/Disables the FlexCAN Message Buffer interrupt. More...
 
void FLEXCAN_HAL_SetErrIntCmd (CAN_Type *base, flexcan_int_type_t errType, bool enable)
 Enables error interrupt of the FlexCAN module. More...
 
void FLEXCAN_HAL_ExitFreezeMode (CAN_Type *base)
 Un freezes the FlexCAN module. More...
 
void FLEXCAN_HAL_EnterFreezeMode (CAN_Type *base)
 Freezes the FlexCAN module. More...
 
uint8_t FLEXCAN_HAL_GetMsgBuffIntStatusFlag (const CAN_Type *base, uint32_t msgBuffIdx)
 Gets the individual FlexCAN MB interrupt flag. More...
 
void FLEXCAN_HAL_GetErrCounter (const CAN_Type *base, flexcan_buserr_counter_t *errCount)
 Gets the transmit error counter and receives the error counter. More...
 
void FLEXCAN_HAL_ClearErrIntStatusFlag (CAN_Type *base)
 Clears all other interrupts in ERRSTAT register (Error, Busoff, Wakeup). More...
 
void FLEXCAN_HAL_ReadRxFifo (const CAN_Type *base, flexcan_msgbuff_t *rxFifo)
 Gets the FlexCAN Rx FIFO data. More...
 
void FLEXCAN_HAL_SetRxMaskType (CAN_Type *base, flexcan_rx_mask_type_t type)
 Sets the Rx masking type. More...
 
void FLEXCAN_HAL_SetRxFifoGlobalStdMask (CAN_Type *base, uint32_t stdMask)
 Sets the FlexCAN RX FIFO global standard mask. More...
 
void FLEXCAN_HAL_SetRxFifoGlobalExtMask (CAN_Type *base, uint32_t extMask)
 Sets the FlexCAN Rx FIFO global extended mask. More...
 
status_t FLEXCAN_HAL_SetRxIndividualStdMask (CAN_Type *base, uint32_t msgBuffIdx, uint32_t stdMask)
 Sets the FlexCAN Rx individual standard mask for ID filtering in the Rx MBs and the Rx FIFO. More...
 
status_t FLEXCAN_HAL_SetRxIndividualExtMask (CAN_Type *base, uint32_t msgBuffIdx, uint32_t extMask)
 Sets the FlexCAN Rx individual extended mask for ID filtering in the Rx Message Buffers and the Rx FIFO. More...
 
void FLEXCAN_HAL_SetRxMsgBuffGlobalStdMask (CAN_Type *base, uint32_t stdMask)
 Sets the FlexCAN Rx Message Buffer global standard mask. More...
 
void FLEXCAN_HAL_SetRxMsgBuff14StdMask (CAN_Type *base, uint32_t stdMask)
 Sets the FlexCAN RX Message Buffer BUF14 standard mask. More...
 
void FLEXCAN_HAL_SetRxMsgBuff15StdMask (CAN_Type *base, uint32_t stdMask)
 Sets the FlexCAN Rx Message Buffer BUF15 standard mask. More...
 
void FLEXCAN_HAL_SetRxMsgBuffGlobalExtMask (CAN_Type *base, uint32_t extMask)
 Sets the FlexCAN RX Message Buffer global extended mask. More...
 
void FLEXCAN_HAL_SetRxMsgBuff14ExtMask (CAN_Type *base, uint32_t extMask)
 Sets the FlexCAN RX Message Buffer BUF14 extended mask. More...
 
void FLEXCAN_HAL_SetRxMsgBuff15ExtMask (CAN_Type *base, uint32_t extMask)
 Sets the FlexCAN RX MB BUF15 extended mask. More...
 
void FLEXCAN_HAL_SetOperationMode (CAN_Type *base, flexcan_operation_modes_t mode)
 Set operation mode. More...
 
void FLEXCAN_HAL_ExitOperationMode (CAN_Type *base, flexcan_operation_modes_t mode)
 Exit operation mode. More...
 
void FLEXCAN_HAL_SetFDEnabled (CAN_Type *base, bool enable)
 Enables/Disables Flexible Data rate (if supported). More...
 
bool FLEXCAN_HAL_IsFDEnabled (const CAN_Type *base)
 Checks if the Flexible Data rate feature is enabled. More...
 
void FLEXCAN_HAL_SetPayloadSize (CAN_Type *base, flexcan_fd_payload_size_t payloadSize)
 Sets the payload size of the MBs. More...
 
uint8_t FLEXCAN_HAL_GetPayloadSize (const CAN_Type *base)
 Gets the payload size of the MBs. More...
 
void FLEXCAN_HAL_SetStuffBitCount (CAN_Type *base, bool enable)
 Enables/Disables the Stuff Bit Count for CAN FD frames. More...
 
void FLEXCAN_HAL_SetSelfReception (CAN_Type *base, bool enable)
 Enables/Disables the Self Reception feature. More...
 
void FLEXCAN_HAL_SetTDCOffset (CAN_Type *base, bool enable, uint8_t offset)
 Enables/Disables the Transceiver Delay Compensation feature and sets the Transceiver Delay Compensation Offset (offset value to be added to the measured transceiver's loop delay in order to define the position of the delayed comparison point when bit rate switching is active). More...
 

Macro Definition Documentation

#define CAN_DLC_VALUE_12_BYTES   9U

interrupts

Definition at line 134 of file flexcan_hal.c.

#define CAN_DLC_VALUE_16_BYTES   10U

Definition at line 135 of file flexcan_hal.c.

#define CAN_DLC_VALUE_20_BYTES   11U

Definition at line 136 of file flexcan_hal.c.

#define CAN_DLC_VALUE_24_BYTES   12U

Definition at line 137 of file flexcan_hal.c.

#define CAN_DLC_VALUE_32_BYTES   13U

Definition at line 138 of file flexcan_hal.c.

#define CAN_DLC_VALUE_48_BYTES   14U

Definition at line 139 of file flexcan_hal.c.

#define CAN_DLC_VALUE_64_BYTES   15U

Definition at line 140 of file flexcan_hal.c.

#define FLEXCAN_8_BYTE_PAYLOAD_MB_SIZE   16U

Definition at line 147 of file flexcan_hal.c.

#define FLEXCAN_ALL_INT   (0x0007U)

format C shift4. Masks for wakeup, error, bus off

Definition at line 130 of file flexcan_hal.c.

#define FLEXCAN_ARBITRATION_FIELD_SIZE   8U

Definition at line 148 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_EXT_MASK   (0x3FFFFFFFU)

format B IDE-2 mask. FlexCAN RX FIFO ID filter

Definition at line 100 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_EXT_SHIFT   (1U)

format A extended mask. FlexCAN RX FIFO ID filter

Definition at line 102 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_STD_MASK   (0x3FF80000U)

format A extended shift. FlexCAN RX FIFO ID filter

Definition at line 104 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATA_STD_SHIFT   (19U)

format A standard mask. FlexCAN RX FIFO ID filter

Definition at line 106 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_IDE_SHIFT   (30U)

format A&B RTR mask. FlexCAN RX FIFO ID filter

Definition at line 94 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATAB_RTR_SHIFT   (31U)

FlexCAN RX FIFO ID filter

Definition at line 92 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_MASK   (0x3FFFU)

format A standard shift. FlexCAN RX FIFO ID filter

Definition at line 108 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT1   (16U)

format B extended mask. FlexCAN RX FIFO ID filter

Definition at line 110 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_EXT_SHIFT2   (0U)

format B extended mask. FlexCAN RX FIFO ID filter

Definition at line 112 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_IDE_SHIFT   (14U)

format B RTR-2 mask. FlexCAN RX FIFO ID filter

Definition at line 98 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_RTR_SHIFT   (15U)

format A&B IDE mask. FlexCAN RX FIFO ID filter

Definition at line 96 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_MASK   (0x7FFU)

format B extended mask. FlexCAN RX FIFO ID filter

Definition at line 114 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT1   (19U)

format B standard mask. FlexCAN RX FIFO ID filter

Definition at line 116 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATB_STD_SHIFT2   (3U)

format B standard shift1. FlexCAN RX FIFO ID filter

Definition at line 118 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_MASK   (0xFFU)

format B standard shift2. FlexCAN RX FIFO ID filter

Definition at line 120 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT1   (24U)

format C mask. FlexCAN RX FIFO ID filter

Definition at line 122 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT2   (16U)

format C shift1. FlexCAN RX FIFO ID filter

Definition at line 124 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT3   (8U)

format C shift2. FlexCAN RX FIFO ID filter

Definition at line 126 of file flexcan_hal.c.

#define FLEXCAN_RX_FIFO_ID_FILTER_FORMATC_SHIFT4   (0U)

format C shift3. FlexCAN RX FIFO ID filter

Definition at line 128 of file flexcan_hal.c.

#define FlexCanRxFifoAcceptExtFrame   1UL

Definition at line 145 of file flexcan_hal.c.

#define FlexCanRxFifoAcceptRemoteFrame   1UL

Definition at line 144 of file flexcan_hal.c.

#define FlexcanSwapBytesInWordIndex (   index)    (((index) & ~3U) + (3U - ((index) & 3U)))

Definition at line 167 of file flexcan_hal.c.

#define RxFifoFilterElementNum (   x)    (((x) + 1U) * 8U)

Definition at line 170 of file flexcan_hal.c.

#define RxFifoFilterTableOffset   0x18U

Definition at line 142 of file flexcan_hal.c.

Function Documentation

static void FLEXCAN_HAL_ClearRAM ( CAN_Type base)
static

Definition at line 334 of file flexcan_hal.c.

static uint8_t FLEXCAN_HAL_ComputeDLCValue ( uint8_t  payloadSize)
static

Definition at line 200 of file flexcan_hal.c.

static uint8_t FLEXCAN_HAL_ComputePayloadSize ( uint8_t  dlcValue)
static

Definition at line 253 of file flexcan_hal.c.

static volatile uint32_t * FLEXCAN_HAL_GetMsgBuffRegion ( CAN_Type base,
uint32_t  msgBuffIdx 
)
static

Definition at line 180 of file flexcan_hal.c.

static uint32_t FLEXCAN_HAL_MaxMbRAMSize ( const CAN_Type base)
static

Definition at line 302 of file flexcan_hal.c.

static uint32_t RxFifoOcuppiedLastMsgBuff ( uint32_t  x)
inlinestatic

Definition at line 160 of file flexcan_hal.c.