43#include "../../sources_common/Totempole_Application_Setup.h"
46#define CAN1_FIFO_ALLOCATE_RAM_SIZE 144U
49#define CAN1_NUM_OF_RX_FIFO 1U
50#define CAN1_RX_FIFO_MSG_DATA 64U
51#define CAN_RX_FIFO_WORD_0 0
52#define CAN_RX_FIFO_WORD_1 1
53#define CAN_RX_FIFO_WORD_2 2
54#define CAN_RX_FIFO_WORD_4 4
57#define CAN1_TX_MSG_SEND_REQ_BIT_POS 0x200U
58#define CAN1_TX_INC_FIFO_PTR_BIT_POS 0x100U
59#define CAN_TX_FIFO_WORD_0 0
60#define CAN_TX_FIFO_WORD_1 1
61#define CAN_TX_FIFO_WORD_2 2
62#define CAN_TX_FIFO_WORD_4 4
65#define CAN_MSG_OBJ_DLC_FIELD_SIZE 0xFU
66#define CAN_MSG_OBJ_ID_TYPE_FIELD_POS 0x10U
67#define CAN_MSG_OBJ_ID_TYPE_SHIFT_POS 0x4U
68#define CAN_MSG_OBJ_RTR_SHIFT_POS 0x5U
69#define CAN_MSG_OBJ_RTR_FIELD_POS 0x20U
70#define CAN_MSG_OBJ_FRAME_TYPE_FIELD_POS 0x20U
71#define CAN_MSG_OBJ_FRAME_TYPE_SHIFT_POS 0x5U
72#define CAN_MSG_OBJ_BRS_FIELD_POS 0x40U
73#define CAN_MSG_OBJ_BRS_SHIFT_POS 0x6U
74#define CAN_MSG_OBJ_FORMAT_TYPE_FIELD_POS 0x80U
75#define CAN_MSG_OBJ_FORMAT_TYPE_SHIFT_POS 0x7U
76#define CAN_STD_MSG_ID_MAX_SIZE 0x7FFU
77#define CAN_MSG_OBJ_SID_SHIFT_POS 0x12U
78#define CAN_EXT_MSG_ID_HIGH_MAX_SIZE 0x1FFFU
79#define CAN_EXT_MSG_ID_LOW_MAX_SIZE 0x1FU
80#define CAN_MSG_OBJ_EID_LOW_SHIFT_POS 0xBU
81#define CAN_MSG_OBJ_EID_HIGH_SHIFT_POS 0x5U
168 static const uint8_t dlcByteSize[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U};
169 return dlcByteSize[dlc];
184 fifoInfo->
address = (uint16_t *) &C1TXQUAL;
190 fifoInfo->
address = (uint16_t *) &C1FIFOUA1L;
235 for (rxFifoIndex = 0; (uint8_t)
rxFIFOMsg[rxFifoIndex].channel != fifoNum; rxFifoIndex++)
254 C1FIFOSTA1bits.RXOVIF =
false;
272 C1FIFOCON1Lbits.UINC = 1;
287 uint16_t fifoMsgIndex;
292 fifoMsgIndex = C1FIFOSTA1bits.FIFOCI;
351 uint8_t dlcByteSize = 0;
416 uint8_t dlcByteSize = 0;
479 C1FIFOCON1H = 0xE000;
494 C1FLTCON0Lbits.F0BP = 1;
497 C1FLTOBJ0L = CANReceiveID;
505 C1FLTCON0Lbits.FLTEN0 = 1;
567 C1CONHbits.TXQEN = 1;
616 C1FLTCON0Lbits.F0BP = 0x0;
621 C1FLTCON0Lbits.FLTEN0 = 0x0;
636 C1CONHbits.REQOP = requestMode;
638 while(C1CONHbits.OPMOD != requestMode)
641 if(C1INTLbits.SERRIF == 1)
658 return C1CONHbits.OPMOD;
679 if((uint16_t *)(*(fifoInfo.
address)) != NULL)
721 if((uint16_t *)(*(fifoInfo.
address)) != NULL)
779 if((uint16_t *)(*(fifoInfo.
address)) != NULL)
814 uint8_t fifoChannel = 0;
816 uint8_t numOfMsg = 0;
817 uint8_t totalMsgObj = 0;
820 uint16_t rxfifoMsgTail;
841 if(rxfifoMsgTail <
rxFIFOMsg[count].headCount)
845 else if(rxfifoMsgTail >
rxFIFOMsg[count].headCount)
855 totalMsgObj += numOfMsg;
864 uint8_t rxFifoStatus;
882 return C1TRECHbits.TXBO;
887 return C1TRECHbits.RXBP;
892 return C1TRECHbits.RXWARN;
897 bool errorState =
false;
898 if((0 < C1TRECLbits.RERRCNT) && (C1TRECLbits.RERRCNT < 128))
908 return C1TRECHbits.TXBP;
913 return C1TRECHbits.TXWARN;
918 bool errorState =
false;
919 if((0 < C1TRECLbits.TERRCNT) && (C1TRECLbits.TERRCNT < 128))
929 C1INTLbits.WAKIF = 0;
930 C1INTHbits.WAKIE = 1;
1033 if(1 == C1INTLbits.WAKIF)
1040 C1INTLbits.WAKIF = 0;
1048 if(1 == C1INTLbits.IVMIF)
1055 C1INTLbits.IVMIF = 0;
1058 if(1 == C1INTLbits.CERRIF)
1065 C1INTLbits.CERRIF = 0;
1068 if(1 == C1INTLbits.MODIF)
1075 C1INTLbits.MODIF = 0;
1078 if(1 == C1INTLbits.SERRIF)
1085 C1INTLbits.SERRIF = 0;
1088 if(1 == C1INTLbits.TXATIF)
1096 if(1 == C1FIFOSTA1bits.RXOVIF)
1103 C1FIFOSTA1bits.RXOVIF = 0;
This is the generated driver header file for the CAN1 driver using CCL.
This is the generated driver types header file for the CAN driver using CCL.
@ CAN_RX_MSG_NOT_AVAILABLE
@ CAN_OP_MODE_SYS_ERROR_OCCURED
@ CAN_OP_MODE_REQUEST_FAIL
@ CAN_OP_MODE_REQUEST_SUCCESS
@ CAN_TX_MSG_REQUEST_BRS_ERROR
@ CAN_TX_MSG_REQUEST_SUCCESS
@ CAN_TX_MSG_REQUEST_DLC_EXCEED_ERROR
@ CAN_TX_MSG_REQUEST_FIFO_FULL
#define CAN_RX_FIFO_WORD_1
#define CAN_MSG_OBJ_EID_LOW_SHIFT_POS
static void(* CAN1_RxBufferOverFlowHandler)(void)
#define CAN_MSG_OBJ_FORMAT_TYPE_SHIFT_POS
#define CAN1_RX_FIFO_MSG_DATA
#define CAN_MSG_OBJ_BRS_SHIFT_POS
#define CAN_MSG_OBJ_RTR_FIELD_POS
#define CAN_MSG_OBJ_FORMAT_TYPE_FIELD_POS
#define CAN_TX_FIFO_WORD_1
static uint8_t can1FifoMsg[CAN1_FIFO_ALLOCATE_RAM_SIZE]
#define CAN1_FIFO_ALLOCATE_RAM_SIZE
static void(* CAN1_SystemErrorHandler)(void)
#define CAN_TX_FIFO_WORD_4
static void(* CAN1_ModeChangeHandler)(void)
#define CAN_MSG_OBJ_ID_TYPE_FIELD_POS
#define CAN_STD_MSG_ID_MAX_SIZE
#define CAN_RX_FIFO_WORD_2
#define CAN_MSG_OBJ_FRAME_TYPE_SHIFT_POS
static volatile struct CAN1_RX_FIFO_MSG rxFIFOMsg[CAN1_NUM_OF_RX_FIFO]
#define CAN_TX_FIFO_WORD_0
#define CAN1_TX_MSG_SEND_REQ_BIT_POS
static void(* CAN1_InvalidMessageHandler)(void)
#define CAN_EXT_MSG_ID_LOW_MAX_SIZE
#define CAN_MSG_OBJ_DLC_FIELD_SIZE
#define CAN_MSG_OBJ_BRS_FIELD_POS
#define CAN1_TX_INC_FIFO_PTR_BIT_POS
static uint8_t rxMsgData[CAN1_RX_FIFO_MSG_DATA]
#define CAN_MSG_OBJ_FRAME_TYPE_FIELD_POS
#define CAN_MSG_OBJ_EID_HIGH_SHIFT_POS
#define CAN1_NUM_OF_RX_FIFO
#define CAN_RX_FIFO_WORD_0
#define CAN_EXT_MSG_ID_HIGH_MAX_SIZE
#define CAN_RX_FIFO_WORD_4
#define CAN_MSG_OBJ_RTR_SHIFT_POS
static void(* CAN1_BusWakeUpActivityHandler)(void)
#define CAN_MSG_OBJ_SID_SHIFT_POS
static void(* CAN1_TxAttemptHandler)(void)
#define CAN_MSG_OBJ_ID_TYPE_SHIFT_POS
static void(* CAN1_BusErrorHandler)(void)
#define CAN_TX_FIFO_WORD_2
static void CAN1_MessageWriteToFifo(uint16_t *txFifoObj, struct CAN_MSG_OBJ *txCanMsg)
This function Read the message object from user input and update to the CAN1 TX FIFO.
static void CAN1_RX_FIFO_IncrementMsgPtr(const uint8_t fifoNum)
This function Update the receive FIFO message increment tail position.
void CAN1_ModeChangeCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CAN1_ModeCha...
void CAN1_RxBufferOverFlowCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CAN1_RxBuffe...
enum CAN_TX_FIFO_STATUS CAN1_TransmitFIFOStatusGet(const enum CAN1_TX_FIFO_CHANNELS fifoChannel)
Returns the CAN1 transmitter FIFO status.
static void CAN1_RX_FIFO_OverflowStatusFlagClear(const enum CAN1_RX_FIFO_CHANNELS fifoNum)
This function is used to clear the CAN1 receive FIFO overflow status bit.
static void CAN1_RX_FIFO_ResetInfo(void)
This function reset the CAN1 receive message head count.
CAN_DLC
Defines the CAN message payload size that are available for the mode to use.
bool CAN1_ReceiveMessageGet(const enum CAN1_RX_FIFO_CHANNELS fifoChannel, struct CAN_MSG_OBJ *rxCanMsg)
Reads the received single message object from the CAN1 receive FIFO.
bool CAN1_IsTxErrorActive(void)
Returns the transmit error active state.
bool CAN1_IsRxErrorWarning(void)
Returns the receive error warning state. If Receiver error counter is above 95 to below 128,...
void CAN1_TxAttemptCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
const struct CAN_INTERFACE CAN_FD1
Structure object of type CAN_INTERFACE with the custom name given by the user in the Melody Driver Us...
void CAN1_Sleep(void)
Sets the CAN node in sleep mode.
uint8_t CAN1_RX_FIFO_StatusGet(const enum CAN1_RX_FIFO_CHANNELS fifoNum)
This returns the CAN1 receive FIFO status.
bool CAN1_Receive(struct CAN_MSG_OBJ *rxCanMsg)
Reads the received single message object.
static uint16_t CAN1_RX_FIFO_MessageIndexGet(const enum CAN1_RX_FIFO_CHANNELS fifoNum)
This function get the Receiver FIFO message index value.
void CAN1_BusErrorCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CAN1_BusErro...
static void CAN1_FIFO_InfoGet(const uint8_t fifoNum, volatile struct CAN1_FIFO_INFO *fifoInfo)
This function get the FIFO user address, message depth and payload size information.
void CAN1_SystemErrorCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CAN1_SystemE...
CAN_TX_FIFO_STATUS
Defines the CAN transmit status get Api return status.
static uint8_t CAN1_DlcToDataBytesGet(const enum CAN_DLC dlc)
This function get the DLC enum based decimal value.
void CAN1_BusWakeUpActivityCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
bool CAN1_IsRxErrorActive(void)
Returns the receive error active state.
static void CAN1_TX_FIFO_Configuration(void)
This function configure the CAN1 transmit FIFO settings.
static void CAN1_RX_FIFO_Configuration(void)
This function configure the CAN1 receive FIFO settings.
static void CAN1_RX_FIFO_FilterMaskConfiguration(void)
This function configure the CAN1 filter and mask settings.
CAN_OP_MODE_STATUS
Defines the CAN operation set Api return status.
void CAN1_Tasks(void)
This routine is used to implement the tasks for polled implementations.
void CAN1_SystemErrorCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
bool CAN1_IsRxErrorPassive(void)
Returns the receive error passive state.
void CAN1_ModeChangeCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
void CAN1_InvalidMessageCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
static uint8_t CAN1_RxFifoSearch(uint8_t fifoNum)
This function Search the CAN1 receive FIFO channel index.
bool CAN1_IsTxErrorWarning(void)
Returns the transmit error warning state. If Transmitter error counter is above 95 to below 128,...
static void CAN1_ErrorNotificationEnable(void)
This function enables the CAN1 error notification interrupt.
static void CAN1_MessageReadFromFifo(uint16_t *rxFifoObj, struct CAN_MSG_OBJ *rxCanMsg)
This function read the message object from receive FIFO and update to the user message object point...
bool CAN1_IsTxErrorPassive(void)
Returns the transmit error passive state.
CAN1_TX_FIFO_CHANNELS
This enumeration defines the can Transmit FIFO Configured in MCC Melody CAN user interface.
static void CAN1_BitRateConfiguration(void)
This function configure the CAN1 bit rate settings.
uint8_t CAN1_ReceivedMessageCountGet(void)
Returns the number of CAN messages received in all the FIFO.
CAN_TX_MSG_REQUEST_STATUS
Defines the CAN transmit Api return status.
bool CAN1_IsBusOff(void)
Returns the bus off status.
void CAN1_BusErrorCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
void CAN1_RxBufferOverFlowCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
enum CAN_TX_MSG_REQUEST_STATUS CAN1_Transmit(const enum CAN1_TX_FIFO_CHANNELS fifoChannel, struct CAN_MSG_OBJ *txCanMsg)
Writes the CAN message object to specified transmit FIFO channel.
void CAN1_Initialize(void)
Initializes CAN1 module.
void CAN1_InvalidMessageCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CAN1_Invalid...
CAN_OP_MODES
Defines the CAN operation modes are available for the module to use.
void CAN1_BusWakeUpActivityCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CAN1_BusWake...
CAN1_RX_FIFO_CHANNELS
This enumeration defines the can receive FIFO.
void CAN1_Deinitialize(void)
Deinitializes CAN1 to POR values.
static void CAN1_TX_FIFO_MessageSendRequest(const enum CAN1_TX_FIFO_CHANNELS fifoChannel)
This function enables The FIFO transmit message send request bit.
enum CAN_OP_MODES CAN1_OperationModeGet(void)
Get the CAN1 operation mode.
void CAN1_TxAttemptCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for CAN1_TxAttem...
enum CAN_OP_MODE_STATUS CAN1_OperationModeSet(const enum CAN_OP_MODES requestMode)
Sets the CAN1 operation mode.
Structure containing the function pointers of CAN driver.
void(* Initialize)(void)
Pointer to CANx_Initialize e.g. CAN1_Initialize.
This data structure used to configure the CAN FD message object.
struct CAN_MSG_FIELD field
enum CAN1_RX_FIFO_CHANNELS channel