fsl_flexcan.h
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _FSL_FLEXCAN_H_
#define _FSL_FLEXCAN_H_
#include "fsl_common.h"
/******************************************************************************
* Definitions
*****************************************************************************/
#define FLEXCAN_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
#define FLEXCAN_ID_STD(id) \
(((uint32_t)(((uint32_t)(id)) << CAN_ID_STD_SHIFT)) & CAN_ID_STD_MASK)
#define FLEXCAN_ID_EXT(id) \
(((uint32_t)(((uint32_t)(id)) << CAN_ID_EXT_SHIFT)) & \
(CAN_ID_EXT_MASK | CAN_ID_STD_MASK))
#define FLEXCAN_RX_MB_STD_MASK(id, rtr, ide) \
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
FLEXCAN_ID_STD(id))
#define FLEXCAN_RX_MB_EXT_MASK(id, rtr, ide) \
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
FLEXCAN_ID_EXT(id))
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide) \
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
(FLEXCAN_ID_STD(id) << 1))
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH(id, rtr, ide) \
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
(FLEXCAN_ID_STD(id) << 16))
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW(id, rtr, ide) \
(((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \
FLEXCAN_ID_STD(id))
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH(id) \
((FLEXCAN_ID_STD(id) & 0x7F8) << 21)
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH(id) \
((FLEXCAN_ID_STD(id) & 0x7F8) << 13)
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW(id) \
((FLEXCAN_ID_STD(id) & 0x7F8) << 5)
#define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW(id) \
((FLEXCAN_ID_STD(id) & 0x7F8) >> 3)
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide) \
(((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
(FLEXCAN_ID_EXT(id) << 1))
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH(id, rtr, ide) \
( \
((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \
((FLEXCAN_ID_EXT(id) & 0x1FFF8000) \
<< 1))
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW(id, rtr, ide) \
(((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \
((FLEXCAN_ID_EXT(id) & 0x1FFF8000) >> \
15))
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH(id) \
((FLEXCAN_ID_EXT(id) & 0x1FE00000) << 3)
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH(id) \
((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \
5)
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW(id) \
((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \
13)
#define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id) \
((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> 21)
#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(id, rtr, ide) \
FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide)
#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_HIGH(id, rtr, ide) \
FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH( \
id, rtr, ide)
#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_LOW(id, rtr, ide) \
FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW( \
id, rtr, ide)
#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_HIGH(id) \
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH( \
id)
#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_HIGH(id) \
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH( \
id)
#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_LOW(id) \
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW( \
id)
#define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_LOW(id) \
FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW(id)
#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_A(id, rtr, ide) \
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide)
#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_HIGH(id, rtr, ide) \
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH( \
id, rtr, ide)
#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_LOW(id, rtr, ide) \
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW( \
id, rtr, ide)
#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_HIGH(id) \
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH(id)
#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_HIGH(id) \
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH( \
id)
#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_LOW(id) \
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW( \
id)
#define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_LOW(id) \
FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id)
enum _flexcan_status
{
kStatus_FLEXCAN_TxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 0),
kStatus_FLEXCAN_TxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 1),
kStatus_FLEXCAN_TxSwitchToRx = MAKE_STATUS(
kStatusGroup_FLEXCAN, 2),
kStatus_FLEXCAN_RxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 3),
kStatus_FLEXCAN_RxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 4),
kStatus_FLEXCAN_RxOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 5),
kStatus_FLEXCAN_RxFifoBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 6),
kStatus_FLEXCAN_RxFifoIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 7),
kStatus_FLEXCAN_RxFifoOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 8),
kStatus_FLEXCAN_RxFifoWarning = MAKE_STATUS(kStatusGroup_FLEXCAN, 0),
kStatus_FLEXCAN_ErrorStatus = MAKE_STATUS(kStatusGroup_FLEXCAN, 10),
kStatus_FLEXCAN_UnHandled = MAKE_STATUS(kStatusGroup_FLEXCAN, 11),
};
typedef enum _flexcan_frame_format
{
kFLEXCAN_FrameFormatStandard = 0x0U,
kFLEXCAN_FrameFormatExtend = 0x1U,
} flexcan_frame_format_t;
typedef enum _flexcan_frame_type
{
kFLEXCAN_FrameTypeData = 0x0U,
kFLEXCAN_FrameTypeRemote = 0x1U,
} flexcan_frame_type_t;
typedef enum _flexcan_clock_source
{
kFLEXCAN_ClkSrcOsc = 0x0U,
kFLEXCAN_ClkSrcPeri = 0x1U,
} flexcan_clock_source_t;
typedef enum _flexcan_rx_fifo_filter_type
{
kFLEXCAN_RxFifoFilterTypeA = 0x0U,
kFLEXCAN_RxFifoFilterTypeB =
0x1U,
kFLEXCAN_RxFifoFilterTypeC =
0x2U,
kFLEXCAN_RxFifoFilterTypeD = 0x3U,
} flexcan_rx_fifo_filter_type_t;
typedef enum _flexcan_rx_fifo_priority
{
kFLEXCAN_RxFifoPrioLow = 0x0U,
kFLEXCAN_RxFifoPrioHigh = 0x1U,
} flexcan_rx_fifo_priority_t;
enum _flexcan_interrupt_enable
{
kFLEXCAN_BusOffInterruptEnable = CAN_CTRL1_BOFFMSK_MASK,
kFLEXCAN_ErrorInterruptEnable = CAN_CTRL1_ERRMSK_MASK,
kFLEXCAN_RxWarningInterruptEnable = CAN_CTRL1_RWRNMSK_MASK,
kFLEXCAN_TxWarningInterruptEnable = CAN_CTRL1_TWRNMSK_MASK,
kFLEXCAN_WakeUpInterruptEnable = CAN_MCR_WAKMSK_MASK,
};
enum _flexcan_flags
{
kFLEXCAN_SynchFlag = CAN_ESR1_SYNCH_MASK,
kFLEXCAN_TxWarningIntFlag = CAN_ESR1_TWRNINT_MASK,
kFLEXCAN_RxWarningIntFlag = CAN_ESR1_RWRNINT_MASK,
kFLEXCAN_TxErrorWarningFlag = CAN_ESR1_TXWRN_MASK,
kFLEXCAN_RxErrorWarningFlag = CAN_ESR1_RXWRN_MASK,
kFLEXCAN_IdleFlag = CAN_ESR1_IDLE_MASK,
kFLEXCAN_FaultConfinementFlag = CAN_ESR1_FLTCONF_MASK,
kFLEXCAN_TransmittingFlag = CAN_ESR1_TX_MASK,
kFLEXCAN_ReceivingFlag = CAN_ESR1_RX_MASK,
kFLEXCAN_BusOffIntFlag = CAN_ESR1_BOFFINT_MASK,
kFLEXCAN_ErrorIntFlag = CAN_ESR1_ERRINT_MASK,
kFLEXCAN_WakeUpIntFlag = CAN_ESR1_WAKINT_MASK,
kFLEXCAN_ErrorFlag = CAN_ESR1_BIT1ERR_MASK |
CAN_ESR1_BIT0ERR_MASK |
CAN_ESR1_ACKERR_MASK | CAN_ESR1_CRCERR_MASK | CAN_ESR1_FRMERR_MASK | CAN_ESR1_STFERR_MASK,
};
enum _flexcan_error_flags
{
kFLEXCAN_StuffingError = CAN_ESR1_STFERR_MASK,
kFLEXCAN_FormError = CAN_ESR1_FRMERR_MASK,
kFLEXCAN_CrcError = CAN_ESR1_CRCERR_MASK,
kFLEXCAN_AckError = CAN_ESR1_ACKERR_MASK,
kFLEXCAN_Bit0Error = CAN_ESR1_BIT0ERR_MASK,
kFLEXCAN_Bit1Error = CAN_ESR1_BIT1ERR_MASK,
};
enum _flexcan_rx_fifo_flags
{
kFLEXCAN_RxFifoOverflowFlag = CAN_IFLAG1_BUF7I_MASK,
kFLEXCAN_RxFifoWarningFlag = CAN_IFLAG1_BUF6I_MASK,
kFLEXCAN_RxFifoFrameAvlFlag = CAN_IFLAG1_BUF5I_MASK,
};
#if defined(__CC_ARM)
#pragma anon_unions
#endif
typedef struct _flexcan_frame
{
struct
{
uint32_t timestamp : 16;
uint32_t length : 4;
uint32_t type : 1;
uint32_t format : 1;
uint32_t reserve1 : 1;
uint32_t idhit : 9;
};
struct
{
uint32_t id : 29;
uint32_t reserve2 : 3;
};
union
{
struct
{
uint32_t dataWord0;
uint32_t dataWord1;
};
struct
{
uint8_t dataByte3;
uint8_t dataByte2;
uint8_t dataByte1;
uint8_t dataByte0;
uint8_t dataByte7;
uint8_t dataByte6;
uint8_t dataByte5;
uint8_t dataByte4;
};
};
} flexcan_frame_t;
typedef struct _flexcan_config
{
uint32_t baudRate;
flexcan_clock_source_t clkSrc;
uint8_t maxMbNum;
bool enableLoopBack;
bool enableSelfWakeup;
bool enableIndividMask;
#if (defined(FSL_FEATURE_FLEXCAN_HAS_DOZE_MODE_SUPPORT) && FSL_FEATURE_FLEXCAN_HAS_DOZE_MODE_SUPPORT)
bool enableDoze;
#endif
} flexcan_config_t;
typedef struct _flexcan_timing_config
{
uint8_t preDivider;
uint8_t rJumpwidth;
uint8_t phaseSeg1;
uint8_t phaseSeg2;
uint8_t propSeg;
} flexcan_timing_config_t;
typedef struct _flexcan_rx_mb_config
{
uint32_t id;
flexcan_frame_format_t format;
flexcan_frame_type_t type;
} flexcan_rx_mb_config_t;
typedef struct _flexcan_rx_fifo_config
{
uint32_t *idFilterTable;
uint8_t idFilterNum;
flexcan_rx_fifo_filter_type_t idFilterType;
flexcan_rx_fifo_priority_t priority;
} flexcan_rx_fifo_config_t;
typedef struct _flexcan_mb_transfer
{
flexcan_frame_t *frame;
uint8_t mbIdx;
} flexcan_mb_transfer_t;
typedef struct _flexcan_fifo_transfer
{
flexcan_frame_t *frame;
} flexcan_fifo_transfer_t;
typedef struct _flexcan_handle flexcan_handle_t;
typedef void (*flexcan_transfer_callback_t)(
CAN_Type *base, flexcan_handle_t *handle, status_t status, uint32_t result, void *userData);
struct _flexcan_handle
{
flexcan_transfer_callback_t callback;
void *userData;
flexcan_frame_t *volatile mbFrameBuf[CAN_WORD1_COUNT];
flexcan_frame_t *volatile rxFifoFrameBuf;
volatile uint8_t mbState[CAN_WORD1_COUNT];
volatile uint8_t rxFifoState;
};
/******************************************************************************
* API
*****************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
void FLEXCAN_Init(CAN_Type *base, const flexcan_config_t *config, uint32_t sourceClock_Hz);
void FLEXCAN_Deinit(CAN_Type *base);
void FLEXCAN_GetDefaultConfig(flexcan_config_t *config);
/* @} */
void FLEXCAN_SetTimingConfig(CAN_Type *base, const flexcan_timing_config_t *config);
void FlEXCAN_SetRxMbGlobalMask(CAN_Type *base, uint32_t mask);
void FlEXCAN_SetRxFifoGlobalMask(CAN_Type *base, uint32_t mask);
void FlEXCAN_SetRxIndividualMask(CAN_Type *base, uint8_t maskIdx, uint32_t mask);
void FLEXCAN_SetTxMbConfig(CAN_Type *base, uint8_t mbIdx, bool enable);
void FLEXCAN_SetRxMbConfig(CAN_Type *base, uint8_t mbIdx, const flexcan_rx_mb_config_t *config, bool enable);
void FlEXCAN_SetRxFifoConfig(CAN_Type *base, const flexcan_rx_fifo_config_t *config, bool enable);
/* @} */
static inline uint32_t FLEXCAN_GetStatusFlags(CAN_Type *base)
{
return base->ESR1;
}
static inline void FLEXCAN_ClearStatusFlags(CAN_Type *base, uint32_t mask)
{
/* Write 1 to clear status flag. */
base->ESR1 = mask;
}
static inline void FlEXCAN_GetBusErrCount(CAN_Type *base, uint8_t *txErrBuf, uint8_t *rxErrBuf)
{
if (txErrBuf)
{
*txErrBuf = (uint8_t)((base->ECR & CAN_ECR_TXERRCNT_MASK) >> CAN_ECR_TXERRCNT_SHIFT);
}
if (rxErrBuf)
{
*rxErrBuf = (uint8_t)((base->ECR & CAN_ECR_RXERRCNT_MASK) >> CAN_ECR_RXERRCNT_SHIFT);
}
}
#if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
static inline uint64_t FLEXCAN_GetMbStatusFlags(CAN_Type *base, uint64_t mask)
#else
static inline uint32_t FLEXCAN_GetMbStatusFlags(CAN_Type *base, uint32_t mask)
#endif
{
#if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
return ((((uint64_t)base->IFLAG1) & mask) | ((((uint64_t)base->IFLAG2) << 32) & mask));
#else
return (base->IFLAG1 & mask);
#endif
}
#if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base, uint64_t mask)
#else
static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base, uint32_t mask)
#endif
{
#if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
base->IFLAG1 = (uint32_t)(mask & 0xFFFFFFFF);
base->IFLAG2 = (uint32_t)(mask >> 32);
#else
base->IFLAG1 = mask;
#endif
}
/* @} */
static inline void FLEXCAN_EnableInterrupts(CAN_Type *base, uint32_t mask)
{
/* Solve Wake Up Interrupt. */
if (mask & kFLEXCAN_WakeUpInterruptEnable)
{
base->MCR |= CAN_MCR_WAKMSK_MASK;
}
/* Solve others. */
base->CTRL1 |= (mask & (~((uint32_t)kFLEXCAN_WakeUpInterruptEnable)));
}
static inline void FLEXCAN_DisableInterrupts(CAN_Type *base, uint32_t mask)
{
/* Solve Wake Up Interrupt. */
if (mask & kFLEXCAN_WakeUpInterruptEnable)
{
base->MCR &= ~CAN_MCR_WAKMSK_MASK;
}
/* Solve others. */
base->CTRL1 &= ~(mask & (~((uint32_t)kFLEXCAN_WakeUpInterruptEnable)));
}
#if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base, uint64_t mask)
#else
static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base, uint32_t mask)
#endif
{
#if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
base->IMASK1 |= (uint32_t)(mask & 0xFFFFFFFF);
base->IMASK2 |= (uint32_t)(mask >> 32);
#else
base->IMASK1 |= mask;
#endif
}
#if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base, uint64_t mask)
#else
static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base, uint32_t mask)
#endif
{
#if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0)
base->IMASK1 &= ~((uint32_t)(mask & 0xFFFFFFFF));
base->IMASK2 &= ~((uint32_t)(mask >> 32));
#else
base->IMASK1 &= ~mask;
#endif
}
/* @} */
#if (defined(FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA) && FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA)
void FLEXCAN_EnableRxFifoDMA(CAN_Type *base, bool enable);
static inline uint32_t FLEXCAN_GetRxFifoHeadAddr(CAN_Type *base)
{
return (uint32_t) & (base->MB[0].CS);
}
/* @} */
#endif /* FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA */
static inline void FLEXCAN_Enable(CAN_Type *base, bool enable)
{
if (enable)
{
base->MCR &= ~CAN_MCR_MDIS_MASK;
/* Wait FlexCAN exit from low-power mode. */
while (base->MCR & CAN_MCR_LPMACK_MASK)
{
}
}
else
{
base->MCR |= CAN_MCR_MDIS_MASK;
/* Wait FlexCAN enter low-power mode. */
while (!(base->MCR & CAN_MCR_LPMACK_MASK))
{
}
}
}
status_t FLEXCAN_WriteTxMb(CAN_Type *base, uint8_t mbIdx, const flexcan_frame_t *txFrame);
status_t FLEXCAN_ReadRxMb(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *rxFrame);
status_t FlEXCAN_ReadRxFifo(CAN_Type *base, flexcan_frame_t *rxFrame);
/* @} */
status_t FlEXCAN_TransferSendBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *txFrame);
status_t FlEXCAN_TransferReceiveBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *rxFrame);
status_t FlEXCAN_TransferReceiveFifoBlocking(CAN_Type *base, flexcan_frame_t *rxFrame);
void FLEXCAN_TransferCreateHandle(CAN_Type *base,
flexcan_handle_t *handle,
flexcan_transfer_callback_t callback,
void *userData);
status_t FLEXCAN_TransferSendNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer);
status_t FLEXCAN_TransferReceiveNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer);
status_t FLEXCAN_TransferReceiveFifoNonBlocking(CAN_Type *base,
flexcan_handle_t *handle,
flexcan_fifo_transfer_t *xfer);
void FLEXCAN_TransferAbortSend(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
void FLEXCAN_TransferAbortReceive(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx);
void FLEXCAN_TransferAbortReceiveFifo(CAN_Type *base, flexcan_handle_t *handle);
void FLEXCAN_TransferHandleIRQ(CAN_Type *base, flexcan_handle_t *handle);
/* @} */
#if defined(__cplusplus)
}
#endif
#endif /* _FSL_FLEXCAN_H_ */
flexcan_rx_fifo_filter_type_t
flexcan_rx_fifo_filter_type_t
FlexCAN Rx Fifo Filter type.
Definition: fsl_flexcan.h:186
flexcan_fifo_transfer_t
FlexCAN Rx FIFO transfer.
Definition: fsl_flexcan.h:382
FLEXCAN_TransferAbortReceiveFifo
void FLEXCAN_TransferAbortReceiveFifo(CAN_Type *base, flexcan_handle_t *handle)
Abort interrupt driven message receive from Rx FIFO process.
Definition: fsl_flexcan.c:1115
kFLEXCAN_TxErrorWarningFlag
Definition: fsl_flexcan.h:237
flexcan_rx_fifo_priority_t
flexcan_rx_fifo_priority_t
FlexCAN Rx FIFO priority.
Definition: fsl_flexcan.h:203
kFLEXCAN_ReceivingFlag
Definition: fsl_flexcan.h:242
_flexcan_handle::rxFifoFrameBuf
flexcan_frame_t *volatile rxFifoFrameBuf
Definition: fsl_flexcan.h:410
kStatus_FLEXCAN_UnHandled
Definition: fsl_flexcan.h:161
kStatus_FLEXCAN_TxIdle
Definition: fsl_flexcan.h:150
FLEXCAN_DisableMbInterrupts
static void FLEXCAN_DisableMbInterrupts(CAN_Type *base, uint64_t mask) static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base
Disable FlexCAN Message Buffer interrupts.
kStatus_FLEXCAN_RxFifoBusy
Definition: fsl_flexcan.h:156
flexcan_rx_mb_config_t::format
flexcan_frame_format_t format
Definition: fsl_flexcan.h:361
flexcan_config_t::baudRate
uint32_t baudRate
Definition: fsl_flexcan.h:327
kStatus_FLEXCAN_ErrorStatus
Definition: fsl_flexcan.h:160
flexcan_config_t::enableSelfWakeup
bool enableSelfWakeup
Definition: fsl_flexcan.h:331
_flexcan_interrupt_enable
_flexcan_interrupt_enable
FlexCAN interrupt configuration structure, default settings all disabled.
Definition: fsl_flexcan.h:215
kFLEXCAN_TxWarningInterruptEnable
Definition: fsl_flexcan.h:220
flexcan_transfer_callback_t
void(* flexcan_transfer_callback_t)(CAN_Type *base, flexcan_handle_t *handle, status_t status, uint32_t result, void *userData)
FlexCAN transfer callback function.
Definition: fsl_flexcan.h:400
kFLEXCAN_RxFifoFilterTypeA
Definition: fsl_flexcan.h:188
flexcan_mb_transfer_t
FlexCAN Message Buffer transfer.
Definition: fsl_flexcan.h:375
kFLEXCAN_ErrorIntFlag
Definition: fsl_flexcan.h:244
kFLEXCAN_FaultConfinementFlag
Definition: fsl_flexcan.h:240
flexcan_rx_mb_config_t::id
uint32_t id
Definition: fsl_flexcan.h:359
flexcan_timing_config_t::phaseSeg1
uint8_t phaseSeg1
Definition: fsl_flexcan.h:343
_flexcan_handle
FlexCAN handle structure.
Definition: fsl_flexcan.h:404
kStatus_FLEXCAN_RxBusy
Definition: fsl_flexcan.h:153
FLEXCAN_TransferReceiveFifoNonBlocking
status_t FLEXCAN_TransferReceiveFifoNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_fifo_transfer_t *xfer)
Receive message from Rx FIFO using IRQ.
Definition: fsl_flexcan.c:1047
kFLEXCAN_BusOffIntFlag
Definition: fsl_flexcan.h:243
FLEXCAN_TransferAbortSend
void FLEXCAN_TransferAbortSend(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx)
Abort interrupt driven message send process.
Definition: fsl_flexcan.c:1073
kFLEXCAN_FrameTypeRemote
Definition: fsl_flexcan.h:175
_flexcan_handle::callback
flexcan_transfer_callback_t callback
Definition: fsl_flexcan.h:406
kFLEXCAN_FormError
Definition: fsl_flexcan.h:261
flexcan_timing_config_t::propSeg
uint8_t propSeg
Definition: fsl_flexcan.h:345
kFLEXCAN_Bit0Error
Definition: fsl_flexcan.h:264
kStatus_FLEXCAN_RxFifoIdle
Definition: fsl_flexcan.h:157
_flexcan_error_flags
_flexcan_error_flags
FlexCAN error status flags.
Definition: fsl_flexcan.h:258
kStatus_FLEXCAN_RxIdle
Definition: fsl_flexcan.h:154
kFLEXCAN_IdleFlag
Definition: fsl_flexcan.h:239
kFLEXCAN_RxFifoFilterTypeC
Definition: fsl_flexcan.h:191
flexcan_rx_fifo_config_t::idFilterNum
uint8_t idFilterNum
Definition: fsl_flexcan.h:369
kFLEXCAN_CrcError
Definition: fsl_flexcan.h:262
kFLEXCAN_StuffingError
Definition: fsl_flexcan.h:260
FlEXCAN_ReadRxFifo
status_t FlEXCAN_ReadRxFifo(CAN_Type *base, flexcan_frame_t *rxFrame)
Read a FlexCAN Message from Rx FIFO.
Definition: fsl_flexcan.c:824
flexcan_timing_config_t::preDivider
uint8_t preDivider
Definition: fsl_flexcan.h:341
FLEXCAN_TransferCreateHandle
void FLEXCAN_TransferCreateHandle(CAN_Type *base, flexcan_handle_t *handle, flexcan_transfer_callback_t callback, void *userData)
Initialize the FlexCAN handle.
Definition: fsl_flexcan.c:921
flexcan_mb_transfer_t::mbIdx
uint8_t mbIdx
Definition: fsl_flexcan.h:378
_flexcan_handle::rxFifoState
volatile uint8_t rxFifoState
Definition: fsl_flexcan.h:412
FLEXCAN_ClearMbStatusFlags
static void FLEXCAN_ClearMbStatusFlags(CAN_Type *base, uint64_t mask) static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base
Clear FlexCAN Message Buffer interrupt flags.
FlEXCAN_TransferReceiveBlocking
status_t FlEXCAN_TransferReceiveBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *rxFrame)
Performs a polling receive transaction on the CAN bus.
Definition: fsl_flexcan.c:889
FLEXCAN_GetMbStatusFlags
static uint64_t FLEXCAN_GetMbStatusFlags(CAN_Type *base, uint64_t mask) static inline uint32_t FLEXCAN_GetMbStatusFlags(CAN_Type *base
Get FlexCAN Message Buffer interrupt flags.
FlEXCAN_SetRxMbGlobalMask
void FlEXCAN_SetRxMbGlobalMask(CAN_Type *base, uint32_t mask)
Set the FlexCAN Receive Message Buffer Global Mask.
Definition: fsl_flexcan.c:469
kFLEXCAN_ErrorInterruptEnable
Definition: fsl_flexcan.h:218
flexcan_rx_fifo_config_t::idFilterTable
uint32_t * idFilterTable
Definition: fsl_flexcan.h:368
FLEXCAN_WriteTxMb
status_t FLEXCAN_WriteTxMb(CAN_Type *base, uint8_t mbIdx, const flexcan_frame_t *txFrame)
Write FlexCAN Message to Transmit Message Buffer.
Definition: fsl_flexcan.c:712
kFLEXCAN_RxWarningInterruptEnable
Definition: fsl_flexcan.h:219
kFLEXCAN_WakeUpInterruptEnable
Definition: fsl_flexcan.h:221
kStatusGroup_FLEXCAN
Definition: fsl_common.h:100
FLEXCAN_TransferHandleIRQ
void FLEXCAN_TransferHandleIRQ(CAN_Type *base, flexcan_handle_t *handle)
FlexCAN IRQ handle function.
Definition: fsl_flexcan.c:1134
kStatus_FLEXCAN_TxSwitchToRx
Definition: fsl_flexcan.h:151
_flexcan_flags
_flexcan_flags
FlexCAN status flags.
Definition: fsl_flexcan.h:232
FLEXCAN_EnableMbInterrupts
static void FLEXCAN_EnableMbInterrupts(CAN_Type *base, uint64_t mask) static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base
Enable FlexCAN Message Buffer interrupts.
FlEXCAN_SetRxIndividualMask
void FlEXCAN_SetRxIndividualMask(CAN_Type *base, uint8_t maskIdx, uint32_t mask)
Set the FlexCAN Receive Individual Mask.
Definition: fsl_flexcan.c:495
kFLEXCAN_TransmittingFlag
Definition: fsl_flexcan.h:241
kFLEXCAN_RxWarningIntFlag
Definition: fsl_flexcan.h:236
kFLEXCAN_FrameFormatStandard
Definition: fsl_flexcan.h:167
kFLEXCAN_FrameFormatExtend
Definition: fsl_flexcan.h:168
FLEXCAN_SetRxMbConfig
void FLEXCAN_SetRxMbConfig(CAN_Type *base, uint8_t mbIdx, const flexcan_rx_mb_config_t *config, bool enable)
Configure a FlexCAN Receive Message Buffer.
Definition: fsl_flexcan.c:535
kFLEXCAN_ClkSrcOsc
Definition: fsl_flexcan.h:181
kFLEXCAN_BusOffInterruptEnable
Definition: fsl_flexcan.h:217
flexcan_timing_config_t
FlexCAN protocol timing characteristic configuration structure.
Definition: fsl_flexcan.h:339
flexcan_rx_fifo_config_t::priority
flexcan_rx_fifo_priority_t priority
Definition: fsl_flexcan.h:371
flexcan_clock_source_t
flexcan_clock_source_t
FlexCAN clock source.
Definition: fsl_flexcan.h:179
FLEXCAN_ClearStatusFlags
static void FLEXCAN_ClearStatusFlags(CAN_Type *base, uint32_t mask)
Clear status flags with provide mask.
Definition: fsl_flexcan.h:613
kFLEXCAN_TxWarningIntFlag
Definition: fsl_flexcan.h:235
FLEXCAN_EnableInterrupts
static void FLEXCAN_EnableInterrupts(CAN_Type *base, uint32_t mask)
Enable FlexCAN interrupts according to provided mask.
Definition: fsl_flexcan.h:702
FLEXCAN_GetStatusFlags
static uint32_t FLEXCAN_GetStatusFlags(CAN_Type *base)
Get FlexCAN module interrupt flags.
Definition: fsl_flexcan.h:599
FLEXCAN_DisableInterrupts
static void FLEXCAN_DisableInterrupts(CAN_Type *base, uint32_t mask)
Disable FlexCAN interrupts according to provided mask.
Definition: fsl_flexcan.h:723
FLEXCAN_GetRxFifoHeadAddr
static uint32_t FLEXCAN_GetRxFifoHeadAddr(CAN_Type *base)
Get the Rx FIFO Head address.
Definition: fsl_flexcan.h:805
FLEXCAN_SetTimingConfig
void FLEXCAN_SetTimingConfig(CAN_Type *base, const flexcan_timing_config_t *config)
Setting FlexCAN protocol timing characteristic.
Definition: fsl_flexcan.c:448
FlEXCAN_SetRxFifoConfig
void FlEXCAN_SetRxFifoConfig(CAN_Type *base, const flexcan_rx_fifo_config_t *config, bool enable)
Configure the FlexCAN Rx FIFO.
Definition: fsl_flexcan.c:579
flexcan_mb_transfer_t::frame
flexcan_frame_t * frame
Definition: fsl_flexcan.h:377
FLEXCAN_TransferAbortReceive
void FLEXCAN_TransferAbortReceive(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx)
Abort interrupt driven message receive process.
Definition: fsl_flexcan.c:1096
kFLEXCAN_WakeUpIntFlag
Definition: fsl_flexcan.h:245
kFLEXCAN_SynchFlag
Definition: fsl_flexcan.h:234
FlEXCAN_GetBusErrCount
static void FlEXCAN_GetBusErrCount(CAN_Type *base, uint8_t *txErrBuf, uint8_t *rxErrBuf)
Get the FlexCAN Bus Error Counter value.
Definition: fsl_flexcan.h:629
kFLEXCAN_RxFifoOverflowFlag
Definition: fsl_flexcan.h:278
flexcan_config_t::enableIndividMask
bool enableIndividMask
Definition: fsl_flexcan.h:332
FlEXCAN_TransferSendBlocking
status_t FlEXCAN_TransferSendBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *txFrame)
Performs a polling send transaction on the CAN bus.
Definition: fsl_flexcan.c:868
flexcan_frame_t
FlexCAN message frame structure.
Definition: fsl_flexcan.h:287
kStatus_FLEXCAN_TxBusy
Definition: fsl_flexcan.h:149
flexcan_rx_mb_config_t
FlexCAN Receive Message Buffer configuration structure.
Definition: fsl_flexcan.h:357
kFLEXCAN_RxFifoWarningFlag
Definition: fsl_flexcan.h:279
kFLEXCAN_Bit1Error
Definition: fsl_flexcan.h:265
FlEXCAN_TransferReceiveFifoBlocking
status_t FlEXCAN_TransferReceiveFifoBlocking(CAN_Type *base, flexcan_frame_t *rxFrame)
Performs a polling receive transaction from Rx FIFO on the CAN bus.
Definition: fsl_flexcan.c:903
FLEXCAN_SetTxMbConfig
void FLEXCAN_SetTxMbConfig(CAN_Type *base, uint8_t mbIdx, bool enable)
Configure a FlexCAN Transmit Message Buffer.
Definition: fsl_flexcan.c:509
kStatus_FLEXCAN_RxOverflow
Definition: fsl_flexcan.h:155
kFLEXCAN_RxFifoFilterTypeB
Definition: fsl_flexcan.h:189
flexcan_config_t
FlexCAN module configuration structure.
Definition: fsl_flexcan.h:325
FLEXCAN_EnableRxFifoDMA
void FLEXCAN_EnableRxFifoDMA(CAN_Type *base, bool enable)
Enable or disable FlexCAN Rx FIFO DMA request.
Definition: fsl_flexcan.c:685
kFLEXCAN_FrameTypeData
Definition: fsl_flexcan.h:174
flexcan_rx_fifo_config_t::idFilterType
flexcan_rx_fifo_filter_type_t idFilterType
Definition: fsl_flexcan.h:370
kStatus_FLEXCAN_RxFifoWarning
Definition: fsl_flexcan.h:159
kFLEXCAN_RxFifoPrioLow
Definition: fsl_flexcan.h:205
kFLEXCAN_RxFifoFilterTypeD
Definition: fsl_flexcan.h:193
_flexcan_handle::userData
void * userData
Definition: fsl_flexcan.h:407
flexcan_timing_config_t::phaseSeg2
uint8_t phaseSeg2
Definition: fsl_flexcan.h:344
kFLEXCAN_RxErrorWarningFlag
Definition: fsl_flexcan.h:238
kFLEXCAN_AckError
Definition: fsl_flexcan.h:263
kFLEXCAN_ClkSrcPeri
Definition: fsl_flexcan.h:182
FLEXCAN_Deinit
void FLEXCAN_Deinit(CAN_Type *base)
De-initializes a FlexCAN instance.
Definition: fsl_flexcan.c:419
FLEXCAN_Enable
static void FLEXCAN_Enable(CAN_Type *base, bool enable)
Enables or disable the FlexCAN module operation.
Definition: fsl_flexcan.h:826
FlEXCAN_SetRxFifoGlobalMask
void FlEXCAN_SetRxFifoGlobalMask(CAN_Type *base, uint32_t mask)
Set the FlexCAN Receive FIFO Global Mask.
Definition: fsl_flexcan.c:483
flexcan_rx_mb_config_t::type
flexcan_frame_type_t type
Definition: fsl_flexcan.h:362
_flexcan_rx_fifo_flags
_flexcan_rx_fifo_flags
FlexCAN Rx FIFO status flags.
Definition: fsl_flexcan.h:276
flexcan_frame_type_t
flexcan_frame_type_t
FlexCAN frame type.
Definition: fsl_flexcan.h:172
flexcan_frame_format_t
flexcan_frame_format_t
FlexCAN frame format.
Definition: fsl_flexcan.h:165
flexcan_config_t::enableDoze
bool enableDoze
Definition: fsl_flexcan.h:334
FLEXCAN_ReadRxMb
status_t FLEXCAN_ReadRxMb(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *rxFrame)
Read a FlexCAN Message from Receive Message Buffer.
Definition: fsl_flexcan.c:765
flexcan_timing_config_t::rJumpwidth
uint8_t rJumpwidth
Definition: fsl_flexcan.h:342
kFLEXCAN_RxFifoFrameAvlFlag
Definition: fsl_flexcan.h:280
FLEXCAN_TransferReceiveNonBlocking
status_t FLEXCAN_TransferReceiveNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer)
Receive message using IRQ.
Definition: fsl_flexcan.c:1016
FLEXCAN_GetDefaultConfig
void FLEXCAN_GetDefaultConfig(flexcan_config_t *config)
Get the default configuration structure.
Definition: fsl_flexcan.c:431
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
flexcan_config_t::enableLoopBack
bool enableLoopBack
Definition: fsl_flexcan.h:330
FLEXCAN_Init
void FLEXCAN_Init(CAN_Type *base, const flexcan_config_t *config, uint32_t sourceClock_Hz)
Initializes a FlexCAN instance.
Definition: fsl_flexcan.c:366
kFLEXCAN_RxFifoPrioHigh
Definition: fsl_flexcan.h:206
flexcan_rx_fifo_config_t
FlexCAN Rx FIFO configure structure.
Definition: fsl_flexcan.h:366
flexcan_config_t::clkSrc
flexcan_clock_source_t clkSrc
Definition: fsl_flexcan.h:328
flexcan_config_t::maxMbNum
uint8_t maxMbNum
Definition: fsl_flexcan.h:329
kFLEXCAN_ErrorFlag
Definition: fsl_flexcan.h:246
kStatus_FLEXCAN_RxFifoOverflow
Definition: fsl_flexcan.h:158
FLEXCAN_TransferSendNonBlocking
status_t FLEXCAN_TransferSendNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer)
send message using IRQ
Definition: fsl_flexcan.c:969