45#define CAN1_FIFO_ALLOCATE_RAM_SIZE 360U
48#define CAN1_NUM_OF_RX_FIFO 2U
49#define CAN1_RX_FIFO_MSG_DATA 64U
50#define CAN_RX_FIFO_WORD_0 0
51#define CAN_RX_FIFO_WORD_1 1
52#define CAN_RX_FIFO_WORD_2 2
53#define CAN_RX_FIFO_WORD_4 4
56#define CAN1_TX_MSG_SEND_REQ_BIT_POS 0x200U
57#define CAN1_TX_INC_FIFO_PTR_BIT_POS 0x100U
58#define CAN_TX_FIFO_WORD_0 0
59#define CAN_TX_FIFO_WORD_1 1
60#define CAN_TX_FIFO_WORD_2 2
61#define CAN_TX_FIFO_WORD_4 4
64#define CAN_MSG_OBJ_DLC_FIELD_SIZE 0xFU
65#define CAN_MSG_OBJ_ID_TYPE_FIELD_POS 0x10U
66#define CAN_MSG_OBJ_ID_TYPE_SHIFT_POS 0x4U
67#define CAN_MSG_OBJ_RTR_SHIFT_POS 0x5U
68#define CAN_MSG_OBJ_RTR_FIELD_POS 0x20U
69#define CAN_MSG_OBJ_FRAME_TYPE_FIELD_POS 0x20U
70#define CAN_MSG_OBJ_FRAME_TYPE_SHIFT_POS 0x5U
71#define CAN_MSG_OBJ_BRS_FIELD_POS 0x40U
72#define CAN_MSG_OBJ_BRS_SHIFT_POS 0x6U
73#define CAN_MSG_OBJ_FORMAT_TYPE_FIELD_POS 0x80U
74#define CAN_MSG_OBJ_FORMAT_TYPE_SHIFT_POS 0x7U
75#define CAN_STD_MSG_ID_MAX_SIZE 0x7FFU
76#define CAN_MSG_OBJ_SID_SHIFT_POS 0x12U
77#define CAN_EXT_MSG_ID_HIGH_MAX_SIZE 0x1FFFU
78#define CAN_EXT_MSG_ID_LOW_MAX_SIZE 0x1FU
79#define CAN_MSG_OBJ_EID_LOW_SHIFT_POS 0xBU
80#define CAN_MSG_OBJ_EID_HIGH_SHIFT_POS 0x5U
117static
void (*CAN1_InvalidMessageHandler)(
void) = NULL;
118static
void (*CAN1_BusWakeUpActivityHandler)(
void) = NULL;
119static
void (*CAN1_BusErrorHandler)(
void) = NULL;
120static
void (*CAN1_ModeChangeHandler)(
void) = NULL;
121static
void (*CAN1_SystemErrorHandler)(
void) = NULL;
122static
void (*CAN1_TxAttemptHandler)(
void) = NULL;
123static
void (*CAN1_RxBufferOverFlowHandler)(
void) = NULL;
134struct CAN1_RX_FIFO_MSG
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;
196 fifoInfo->
address = (uint16_t *) &C1FIFOUA2L;
241 for (rxFifoIndex = 0; (uint8_t)
rxFIFOMsg[rxFifoIndex].channel != fifoNum; rxFifoIndex++)
260 C1FIFOSTA1bits.RXOVIF =
false;
264 C1FIFOSTA2bits.RXOVIF =
false;
282 C1FIFOCON1Lbits.UINC = 1;
286 C1FIFOCON2Lbits.UINC = 1;
301 uint16_t fifoMsgIndex;
306 fifoMsgIndex = C1FIFOSTA1bits.FIFOCI;
310 fifoMsgIndex = C1FIFOSTA2bits.FIFOCI;
369 uint8_t dlcByteSize = 0;
403 (void)memcpy((
char *) rxMsgData, (
char *) (&rxFifoObj[
CAN_RX_FIFO_WORD_4]), dlcByteSize);
404 rxCanMsg->
data = rxMsgData;
434 uint8_t dlcByteSize = 0;
497 C1FIFOCON1H = 0xE000;
501 C1FIFOCON2H = 0xE000;
516 C1FLTCON0Lbits.F0BP = 1;
526 C1FLTCON0Lbits.FLTEN0 = 1;
529 C1FLTCON0Lbits.F1BP = 2;
539 C1FLTCON0Lbits.FLTEN1 = 1;
593 C1FIFOBAL = (uint16_t) &can1FifoMsg[0];
601 C1CONHbits.TXQEN = 1;
652 C1FLTCON0Lbits.F0BP = 0x0;
657 C1FLTCON0Lbits.FLTEN0 = 0x0;
658 C1FLTCON0Lbits.F1BP = 0x0;
663 C1FLTCON0Lbits.FLTEN1 = 0x0;
678 C1CONHbits.REQOP = requestMode;
680 while(C1CONHbits.OPMOD != requestMode)
683 if(C1INTLbits.SERRIF == 1)
700 return C1CONHbits.OPMOD;
721 if((uint16_t *)(*(fifoInfo.
address)) != NULL)
763 if((uint16_t *)(*(fifoInfo.
address)) != NULL)
821 if((uint16_t *)(*(fifoInfo.
address)) != NULL)
856 uint8_t fifoChannel = 0;
858 uint8_t numOfMsg = 0;
859 uint8_t totalMsgObj = 0;
862 uint16_t rxfifoMsgTail;
883 if(rxfifoMsgTail <
rxFIFOMsg[count].headCount)
887 else if(rxfifoMsgTail >
rxFIFOMsg[count].headCount)
889 numOfMsg = rxfifoMsgTail -
rxFIFOMsg[count].headCount;
897 totalMsgObj += numOfMsg;
906 uint8_t rxFifoStatus;
928 return C1TRECHbits.TXBO;
933 return C1TRECHbits.RXBP;
938 return C1TRECHbits.RXWARN;
943 bool errorState =
false;
944 if((0 < C1TRECLbits.RERRCNT) && (C1TRECLbits.RERRCNT < 128))
954 return C1TRECHbits.TXBP;
959 return C1TRECHbits.TXWARN;
964 bool errorState =
false;
965 if((0 < C1TRECLbits.TERRCNT) && (C1TRECLbits.TERRCNT < 128))
975 C1INTLbits.WAKIF = 0;
976 C1INTHbits.WAKIE = 1;
989 CAN1_InvalidMessageHandler = handler;
1002 CAN1_BusWakeUpActivityHandler = handler;
1015 CAN1_BusErrorHandler = handler;
1028 CAN1_ModeChangeHandler = handler;
1041 CAN1_SystemErrorHandler = handler;
1054 CAN1_TxAttemptHandler = handler;
1067 CAN1_RxBufferOverFlowHandler = handler;
1079 if(1 == C1INTLbits.WAKIF)
1081 if(CAN1_BusWakeUpActivityHandler != NULL)
1083 CAN1_BusWakeUpActivityHandler();
1086 C1INTLbits.WAKIF = 0;
1094 if(1 == C1INTLbits.IVMIF)
1096 if(CAN1_InvalidMessageHandler != NULL)
1098 CAN1_InvalidMessageHandler();
1101 C1INTLbits.IVMIF = 0;
1104 if(1 == C1INTLbits.CERRIF)
1106 if(CAN1_BusErrorHandler != NULL)
1108 CAN1_BusErrorHandler();
1111 C1INTLbits.CERRIF = 0;
1114 if(1 == C1INTLbits.MODIF)
1116 if(CAN1_ModeChangeHandler != NULL)
1118 CAN1_ModeChangeHandler();
1121 C1INTLbits.MODIF = 0;
1124 if(1 == C1INTLbits.SERRIF)
1126 if(CAN1_SystemErrorHandler != NULL)
1128 CAN1_SystemErrorHandler();
1131 C1INTLbits.SERRIF = 0;
1134 if(1 == C1INTLbits.TXATIF)
1136 if(CAN1_TxAttemptHandler != NULL)
1138 CAN1_TxAttemptHandler();
1142 if(1 == C1FIFOSTA1bits.RXOVIF)
1144 if(CAN1_RxBufferOverFlowHandler != NULL)
1146 CAN1_RxBufferOverFlowHandler();
1149 C1FIFOSTA1bits.RXOVIF = 0;
1152 if(1 == C1FIFOSTA2bits.RXOVIF)
1154 if(CAN1_RxBufferOverFlowHandler != NULL)
1156 CAN1_RxBufferOverFlowHandler();
1159 C1FIFOSTA2bits.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
#define CAN_MSG_OBJ_FORMAT_TYPE_SHIFT_POS
#define CAN1_RX_FIFO_MSG_DATA
#define CAN_MSG_OBJ_BRS_SHIFT_POS
void __attribute__((weak))
#define CAN_MSG_OBJ_RTR_FIELD_POS
#define CAN_MSG_OBJ_FORMAT_TYPE_FIELD_POS
#define CAN_TX_FIFO_WORD_1
#define CAN1_FIFO_ALLOCATE_RAM_SIZE
#define CAN_TX_FIFO_WORD_4
#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
#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
#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
#define CAN_MSG_OBJ_SID_SHIFT_POS
#define CAN_MSG_OBJ_ID_TYPE_SHIFT_POS
#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.
This data structure used to configure the CAN FD message object.
struct CAN_MSG_FIELD field