diff --git a/Core/Include/ivec_mcal_mcan.h b/Core/Include/ivec_mcal_mcan.h index 61dd9bb..fe582f1 100644 --- a/Core/Include/ivec_mcal_mcan.h +++ b/Core/Include/ivec_mcal_mcan.h @@ -1,27 +1,23 @@ - #ifndef CORE_INCLUDE_IVEC_MCAL_MCAN_H_ #define CORE_INCLUDE_IVEC_MCAL_MCAN_H_ -#include "ti_msp_dl_config.h" #include "..\utils\utils.h" -typedef enum -{ - STD_ID = 0x00, - EXT_ID = 0x01, - ERROR = 0x02 -} xCanIdType_t; +#include "ti_msp_dl_config.h" +typedef enum { + STD_ID = 0x00, EXT_ID = 0x01, ERROR = 0x02 +} xCanIdType_t; IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* const mcan, xCAN_baud_t BAUD); IVEC_McalStatus_e xMCAL_MCANDeInit(MCAN_Regs* const mcan); -IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, DL_MCAN_TxBufElement *TxMsg ,uint16_t *TxData, uint32_t BufNum, int Bytes); -IVEC_McalStatus_e xMCAL_MCANRx(MCAN_Regs *MCAN, DL_MCAN_RxBufElement *RxMsg ,uint32_t FifoNum,uint8_t *RxData,int DLC); +//IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, uint32_t u32ID ,uint16_t *TxData, uint32_t BufNum, uint32_t Bytes); +IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, uint32_t u32ID ,uint16_t *TxData, uint32_t BufNum, uint32_t Bytes); +IVEC_McalStatus_e xMCAL_MCANTxBlocking(MCAN_Regs *MCAN, uint32_t u32ID ,uint16_t *TxData, uint32_t BufNum, int Bytes); +IVEC_McalStatus_e xMCAL_MCANRx(MCAN_Regs *MCAN,uint32_t *ID ,uint8_t *RxData, int DLC); IVEC_McalStatus_e xMCAL_getMCAN_ErrorStatus(char *ErrorStatus); IVEC_McalStatus_e xMCAL_getMCAN_InterruptLine1Status(uint32_t *Interrupt_Status); - -void mcu_FDCAN_RxFifo_Callback(uint32_t Identifier, uint8_t *data, uint16_t DataLength); - +IVEC_McalStatus_e xMCAL_resetMCAN(MCAN_Regs* const mcan, xCAN_baud_t BAUD); #endif /* CORE_INCLUDE_IVEC_MCAL_MCAN_H_ */ diff --git a/Core/Source/ivec_mcal_mcan.c b/Core/Source/ivec_mcal_mcan.c index a1e33c3..1143d5f 100644 --- a/Core/Source/ivec_mcal_mcan.c +++ b/Core/Source/ivec_mcal_mcan.c @@ -1,245 +1,238 @@ - /** - ****************************************************************************** - * @file ivec_mcal_mcan.c - * @brief This file provides APIs for MCAN peripheral. - * @date 15-feb-2024 - * @Author Vecmocon Technology - ****************************************************************************** - */ +/** + ****************************************************************************** + * @file ivec_mcal_mcan.c + * @brief This file provides APIs for MCAN peripheral. + * @date 15-feb-2024 + * @Author Vecmocon Technology + ****************************************************************************** + */ -#include <..\Core\Include\ivec_mcal_mcan.h> +#include <../Core/Include/ivec_mcal_mcan.h> #include "string.h" -static volatile bool b_MCAN_InitFlag = 0; /*!< CAN initialization flag */ -static volatile bool b_ServiceInt=true; -static volatile uint32_t u32InterruptLine1Status; -static char u8ErrorInterruptStatus[50]; -static volatile DL_MCAN_RxFIFOStatus rxFS; -static DL_MCAN_RxBufElement TempRxMsg; -static uint32_t id; -extern uint16_t idx; -uint32_t IntrStatus; -static volatile uint8_t u8_MCAN_StatusFlag = IVEC_MCAL_STATUS_ERROR; -uint8_t g_CanData[8]; -volatile DL_MCAN_ProtocolStatus HeaderStat; -#define MCAN_FILTER_SIZE 4u - -extern uint16_t g_u16CanSpeed; - - +volatile bool b_MCAN_InitFlag = 0; /*!< CAN initialization flag */ +volatile uint8_t u8_MCAN_StatusFlag = IVEC_MCAL_STATUS_ERROR; +volatile bool b_ServiceInt=true; +volatile uint32_t u32InterruptLine1Status; +volatile char u8ErrorInterruptStatus[50]; +volatile DL_MCAN_RxFIFOStatus rxFS; +volatile DL_MCAN_RxBufElement TempRxMsg; +volatile uint8_t TempRxBuffer[8]; +volatile uint32_t TempRxID; +volatile uint32_t id; +DL_MCAN_ProtocolStatus HeaderStat; +volatile uint32_t l_canTransmitTimeout; +volatile uint8_t u8CallBack_buff[8]={0}; +volatile IVEC_McalStatus_e l_statusFlag = IVEC_MCAL_STATUS_SUCCESS; +extern volatile uint8_t u8CANDataAct; /*REQUIRED MCAN CONFIGS*/ + +__attribute__((weak)) void mcu_FDCAN_RxFifo_Callback(uint32_t Identifier, uint8_t *data, uint16_t DataLength) +{ + +} + /*=======================================================================================PRIVATE_MEMBERS======================================================================================*/ static const DL_MCAN_ClockConfig gMCAN0ClockConf = { - .clockSel = DL_MCAN_FCLK_HFCLK,////DL_MCAN_FCLK_SYSPLLCLK1,DL_MCAN_FCLK_HFCLK, - .divider = DL_MCAN_FCLK_DIV_1, + .clockSel = DL_MCAN_FCLK_HFCLK,////DL_MCAN_FCLK_SYSPLLCLK1,DL_MCAN_FCLK_HFCLK, + .divider = DL_MCAN_FCLK_DIV_1, }; -static const DL_MCAN_InitParams gMCAN0InitParams= { +static DL_MCAN_InitParams gMCAN0InitParams= { -/* Initialize MCAN Init parameters. */ - .fdMode = false, - .brsEnable = false, - .txpEnable = false, - .efbi = false, - .pxhddisable = false, - .darEnable = false, - .wkupReqEnable = false, - .autoWkupEnable = false, - .emulationEnable = true, - .tdcEnable = true, - .wdcPreload = 255, + /* Initialize MCAN Init parameters. */ + .fdMode = false, + .brsEnable = false, + .txpEnable = false, + .efbi = false, + .pxhddisable = false, + .darEnable = false, + .wkupReqEnable = false, + .autoWkupEnable = false, + .emulationEnable = true, + .tdcEnable = true, + .wdcPreload = 255, -/* Transmitter Delay Compensation parameters. */ - .tdcConfig.tdcf = 10, - .tdcConfig.tdco = 6, + /* Transmitter Delay Compensation parameters. */ + .tdcConfig.tdcf = 10, + .tdcConfig.tdco = 6, }; static DL_MCAN_ConfigParams gMCAN0ConfigParams={ - /* Initialize MCAN Config parameters. */ - .monEnable = false, - .asmEnable = false, - .tsPrescalar = 15, - .tsSelect = 0, - .timeoutSelect = DL_MCAN_TIMEOUT_SELECT_CONT, - .timeoutPreload = 65535, - .timeoutCntEnable = false, - .filterConfig.rrfs = false, - .filterConfig.rrfe = false, - .filterConfig.anfe = 0, - .filterConfig.anfs = 0, -// .filterConfig.rrfs = true, -// .filterConfig.rrfe = true, -// .filterConfig.anfe = 1, -// .filterConfig.anfs = 1, + /* Initialize MCAN Config parameters. */ + .monEnable = false, + .asmEnable = false, + .tsPrescalar = 15, + .tsSelect = 0, + .timeoutSelect = DL_MCAN_TIMEOUT_SELECT_CONT, + .timeoutPreload = 65535, + .timeoutCntEnable = false, + .filterConfig.rrfs = false, + .filterConfig.rrfe = false, + .filterConfig.anfe = 0, + .filterConfig.anfs = 0, }; - - static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParams ={ - /* Standard ID Filter List Start Address. */ - .flssa = 5 , - /* List Size: Standard ID. */ - .lss = MCAN_FILTER_SIZE, - /* Extended ID Filter List Start Address. */ - .flesa = 48 , - /* List Size: Extended ID. */ - .lse = 1 , - /* Tx Buffers Start Address. */ - .txStartAddr = 10 , - /* Number of Dedicated Transmit Buffers. */ - .txBufNum = 10 , - .txFIFOSize = 10, - /* Tx Buffer Element Size. */ - .txBufMode = 0, - .txBufElemSize = DL_MCAN_ELEM_SIZE_8BYTES, - /* Tx Event FIFO Start Address. */ - .txEventFIFOStartAddr = 640 , - /* Event FIFO Size. */ - .txEventFIFOSize = 10 , - /* Level for Tx Event FIFO watermark interrupt. */ - .txEventFIFOWaterMark = 0, - /* Rx FIFO0 Start Address. */ - .rxFIFO0startAddr = 170 , - /* Number of Rx FIFO elements. */ - .rxFIFO0size = 10 , - /* Rx FIFO0 Watermark. */ - .rxFIFO0waterMark = 0, - .rxFIFO0OpMode = 0, - /* Rx FIFO1 Start Address. */ - .rxFIFO1startAddr = 190 , - /* Number of Rx FIFO elements. */ - .rxFIFO1size = 10 , - /* Level for Rx FIFO 1 watermark interrupt. */ - .rxFIFO1waterMark = 10, - /* FIFO blocking mode. */ - .rxFIFO1OpMode = 0, - /* Rx Buffer Start Address. */ - .rxBufStartAddr = 208 , - /* Rx Buffer Element Size. */ - .rxBufElemSize = DL_MCAN_ELEM_SIZE_8BYTES, - /* Rx FIFO0 Element Size. */ - .rxFIFO0ElemSize = DL_MCAN_ELEM_SIZE_8BYTES, - /* Rx FIFO1 Element Size. */ - .rxFIFO1ElemSize = DL_MCAN_ELEM_SIZE_8BYTES, + /* Standard ID Filter List Start Address. */ + .flssa = 0 , + /* List Size: Standard ID. */ + .lss = 0 , + /* Extended ID Filter List Start Address. */ + .flesa = 0 , + /* List Size: Extended ID. */ + .lse = 0 , + /* Tx Buffers Start Address. */ + .txStartAddr = 10 , + /* Number of Dedicated Transmit Buffers. */ + .txBufNum = 10 , + .txFIFOSize = 10, + /* Tx Buffer Element Size. */ + .txBufMode = 0, + .txBufElemSize = DL_MCAN_ELEM_SIZE_8BYTES, + /* Tx Event FIFO Start Address. */ + .txEventFIFOStartAddr = 640 , + /* Event FIFO Size. */ + .txEventFIFOSize = 10 , + /* Level for Tx Event FIFO watermark interrupt. */ + .txEventFIFOWaterMark = 0, + /* Rx FIFO0 Start Address. */ + .rxFIFO0startAddr = 170 , + /* Number of Rx FIFO elements. */ + .rxFIFO0size = 10 , + /* Rx FIFO0 Watermark. */ + .rxFIFO0waterMark = 0, + .rxFIFO0OpMode = 0, + /* Rx FIFO1 Start Address. */ + .rxFIFO1startAddr = 190 , + /* Number of Rx FIFO elements. */ + .rxFIFO1size = 10 , + /* Level for Rx FIFO 1 watermark interrupt. */ + .rxFIFO1waterMark = 10, + /* FIFO blocking mode. */ + .rxFIFO1OpMode = 0, + /* Rx Buffer Start Address. */ + .rxBufStartAddr = 208 , + /* Rx Buffer Element Size. */ + .rxBufElemSize = DL_MCAN_ELEM_SIZE_8BYTES, + /* Rx FIFO0 Element Size. */ + .rxFIFO0ElemSize = DL_MCAN_ELEM_SIZE_8BYTES, + /* Rx FIFO1 Element Size. */ + .rxFIFO1ElemSize = DL_MCAN_ELEM_SIZE_8BYTES, }; -//static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem = { -// .sfec = 0x1, // Store in Rx FIFO 0 if filter matches -// .sft = 0x11, // Disable filter, receive all IDs -// .sfid1 = 0, // These values won't be used because filtering is disabled -// .sfid2 = 0, // These values won't be used because filtering is disabled -//}; -// -//// Static filter element definition to disable filtering -//static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFilterElem = { -// .efid1 = 0, // These values won't be used because filtering is disabled -// .efec = 0x0, // Disable filter element (0b000) -// .efid2 = 0xffffffff, // These values won't be used because filtering is disabled -// .eft = 0x3, // Set to 0b11 for disabling filtering (no specific filter applied) -//}; - - - - static DL_MCAN_BitTimingParams gMCAN0BitTimes_500 = { - /* Arbitration Baud Rate Pre-scaler. */ - .nomRatePrescalar = 0, - /* Arbitration Time segment before sample point. */ - .nomTimeSeg1 = 41, - /* Arbitration Time segment after sample point. */ - .nomTimeSeg2 = 4, - /* Arbitration (Re)Synchronization Jump Width Range. */ - .nomSynchJumpWidth = 4, - /* Data Baud Rate Pre-scaler. */ - .dataRatePrescalar = 0, - /* Data Time segment before sample point. */ - .dataTimeSeg1 = 0, - /* Data Time segment after sample point. */ - .dataTimeSeg2 = 0, - /* Data (Re)Synchronization Jump Width. */ - .dataSynchJumpWidth = 0, + /* Arbitration Baud Rate Pre-scaler. */ + .nomRatePrescalar = 0, + /* Arbitration Time segment before sample point. */ + .nomTimeSeg1 = 41, + /* Arbitration Time segment after sample point. */ + .nomTimeSeg2 = 4, + /* Arbitration (Re)Synchronization Jump Width Range. */ + .nomSynchJumpWidth = 4, + /* Data Baud Rate Pre-scaler. */ + .dataRatePrescalar = 0, + /* Data Time segment before sample point. */ + .dataTimeSeg1 = 0, + /* Data Time segment after sample point. */ + .dataTimeSeg2 = 0, + /* Data (Re)Synchronization Jump Width. */ + .dataSynchJumpWidth = 0, }; -static const DL_MCAN_BitTimingParams gMCAN0BitTimes_250 = { - /* Arbitration Baud Rate Pre-scaler. */ - .nomRatePrescalar = 0, - /* Arbitration Time segment before sample point. */ - .nomTimeSeg1 = 82, - /* Arbitration Time segment after sample point. */ - .nomTimeSeg2 = 11, - /* Arbitration (Re)Synchronization Jump Width Range. */ - .nomSynchJumpWidth = 11, - /* Data Baud Rate Pre-scaler. */ - .dataRatePrescalar = 0, - /* Data Time segment before sample point. */ - .dataTimeSeg1 = 0, - /* Data Time segment after sample point. */ - .dataTimeSeg2 = 0, - /* Data (Re)Synchronization Jump Width. */ - .dataSynchJumpWidth = 0, -}; - -//static const DL_MCAN_BitTimingParams gMCAN0BitTimes_125 = { -// /* Arbitration Baud Rate Pre-scaler. */ -// .nomRatePrescalar = 0, -// /* Arbitration Time segment before sample point. */ -// .nomTimeSeg1 = 138, -// /* Arbitration Time segment after sample point. */ -// .nomTimeSeg2 = 19, -// /* Arbitration (Re)Synchronization Jump Width Range. */ -// .nomSynchJumpWidth = 19, -// /* Data Baud Rate Pre-scaler. */ -// .dataRatePrescalar = 0, -// /* Data Time segment before sample point. */ -// .dataTimeSeg1 = 0, -// /* Data Time segment after sample point. */ -// .dataTimeSeg2 = 0, -// /* Data (Re)Synchronization Jump Width. */ -// .dataSynchJumpWidth = 0, -//}; - -static const DL_MCAN_BitTimingParams gMCAN0BitTimes_150 = { - /* Arbitration Baud Rate Pre-scaler. */ - .nomRatePrescalar = 0, - /* Arbitration Time segment before sample point. */ - .nomTimeSeg1 = 138, - /* Arbitration Time segment after sample point. */ - .nomTimeSeg2 = 19, - /* Arbitration (Re)Synchronization Jump Width Range. */ - .nomSynchJumpWidth = 19, - /* Data Baud Rate Pre-scaler. */ - .dataRatePrescalar = 0, - /* Data Time segment before sample point. */ - .dataTimeSeg1 = 19, - /* Data Time segment after sample point. */ - .dataTimeSeg2 = 2, - /* Data (Re)Synchronization Jump Width. */ - .dataSynchJumpWidth = 2, +static DL_MCAN_BitTimingParams gMCAN0BitTimes_250 = { + /* Arbitration Baud Rate Pre-scaler. */ + .nomRatePrescalar = 0, + /* Arbitration Time segment before sample point. */ + .nomTimeSeg1 = 138, + /* Arbitration Time segment after sample point. */ + .nomTimeSeg2 = 19, + /* Arbitration (Re)Synchronization Jump Width Range. */ + .nomSynchJumpWidth = 19, + /* Data Baud Rate Pre-scaler. */ + .dataRatePrescalar = 0, + /* Data Time segment before sample point. */ + .dataTimeSeg1 = 0, + /* Data Time segment after sample point. */ + .dataTimeSeg2 = 0, + /* Data (Re)Synchronization Jump Width. */ + .dataSynchJumpWidth = 0, }; -static const DL_MCAN_BitTimingParams gMCAN0BitTimes_1000 = { - /* Arbitration Baud Rate Pre-scaler. */ - .nomRatePrescalar = 0, - /* Arbitration Time segment before sample point. */ - .nomTimeSeg1 = 19, - /* Arbitration Time segment after sample point. */ - .nomTimeSeg2 = 2, - /* Arbitration (Re)Synchronization Jump Width Range. */ - .nomSynchJumpWidth = 2, - /* Data Baud Rate Pre-scaler. */ - .dataRatePrescalar = 0, - /* Data Time segment before sample point. */ - .dataTimeSeg1 = 19, - /* Data Time segment after sample point. */ - .dataTimeSeg2 = 2, - /* Data (Re)Synchronization Jump Width. */ - .dataSynchJumpWidth = 2, +static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem1 = { + .sfec = 0x1, + .sft = 0x01, + .sfid1 = 0x1AE, + .sfid2 = 0x520, }; +static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem2 = { + .sfec = 0x1, + .sft = 0x00, + .sfid1 = 0xBB, + .sfid2 = 0xBB, +}; + +static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem3 = { + .sfec = 0x1, + .sft = 0x00, + .sfid1 = 0x1A4, + .sfid2 = 0x1A4, +}; + +static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem4 = { + .sfec = 0x1, + .sft = 0x00, + .sfid1 = 0x521, + .sfid2 = 0x521, +}; + +static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem5 = { + .sfec = 0x1, + .sft = 0x00, + .sfid1 = 0x16, + .sfid2 = 0x16, +}; + +static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFiltelem1 = { + .efec = 0x1, + .eft = 0x0, + .efid1 = 0x18904001, + .efid2 = 0x18904001, +}; + +static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFiltelem2 = { + .efec = 0x1, + .eft = 0x0, + .efid1 = 0x1CECFF23, + .efid2 = 0x1CECFF23, +}; + +static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFiltelem3 = { + .efec = 0x1, + .eft = 0x0, + .efid1 = 0x1CEBFF23, + .efid2 = 0x1CEBFF23, +}; + +volatile DL_MCAN_TxBufElement txMsg = { + .id = ((uint32_t)(0x00)) << 18U, + .rtr = 0U, + .xtd = 0U, + .esi = 0U, + .dlc = 8U, + .brs = 1U, + .fdf = 1U, + .efc = 1U, + .mm = 0xAAU, + .data = 0U, +}; + + /*____________________________________________________________________________________________________________________________________________________________________________________________*/ @@ -248,128 +241,29 @@ static const DL_MCAN_BitTimingParams gMCAN0BitTimes_1000 = { ==============================================================================================================================================================================================*/ /** - * @brief Static Function to store RX data in a static buffer - * @retval void - */ -//static void _prv_vGetRxMsg(DL_MCAN_RxBufElement *rxMsg,uint8_t *RxData,int DLC) -//{ -// for (int i =0 ; i < DLC ; i++) -// { -// RxData[i] = rxMsg->data[i]; -// } -// -//} -static void _prv_vGetRxMsg(DL_MCAN_RxBufElement *rxMsg,uint8_t *RxData,int DLC) + * @brief Static Function to store RX data in a static buffer + * @retval void + */ +static void _prv_vGetRxMsg(DL_MCAN_RxBufElement *rxMsg,uint32_t *ID,uint8_t *RxData,int DLC) { - id = ((rxMsg->id & (uint32_t) 0x1FFC0000) >> (uint32_t) 18); + for (int i =0 ; i < DLC ; i++) - switch (id) { - case 0x5: - - *RxData = rxMsg->data[0]; - idx = (rxMsg->data[0] + 1) % 256; - - break; - default: - /* Don't do anything */ - break; - } - -} - -/** - * @brief Private Function working as an Error Handler in IRQ - * @retval void - */ -static void ErrorHandler() -{ - switch(DL_MCAN_getIntrStatus(CANFD0)) { - case MCAN_IR_PED_MASK: - strcpy(u8ErrorInterruptStatus, "Protocol Error in Data Phase!"); - __asm("nop"); - break; - case MCAN_IR_PEA_MASK: - strcpy(u8ErrorInterruptStatus, "Protocol Error in Arbitration Phase!"); - __asm("nop"); - break; - case MCAN_IR_BO_MASK: - strcpy(u8ErrorInterruptStatus, "CAN BUS OFF!"); - DL_MCAN_reset(CANFD0); - __asm("nop"); - break; - case MCAN_IR_EW_MASK: - strcpy(u8ErrorInterruptStatus, "Warning Status Interrupt generated!"); - __asm("nop"); - break; - case MCAN_IR_EP_MASK: - strcpy(u8ErrorInterruptStatus, "Error Passive Interrupt generated!"); - __asm("nop"); - break; - case MCAN_IR_ELO_MASK: - strcpy(u8ErrorInterruptStatus, "Error Logging Overflow!"); - __asm("nop"); - break; - case MCAN_IR_BEU_MASK: - strcpy(u8ErrorInterruptStatus, "Bit Error Uncorrected!"); - __asm("nop"); - break; - case MCAN_IR_TOO_MASK: - strcpy(u8ErrorInterruptStatus, "Timeout Occured!"); - __asm("nop"); - break; - default: - break; - + RxData[i] = (rxMsg->data[i] & 0xFF); } } + /** * @brief Default Interrupt Handler for MCAN * */ -//void CANFD0_IRQHandler(void) -//{ -// ErrorHandler(); -// -// switch (DL_MCAN_getPendingInterrupt(CANFD0)) { -// case DL_MCAN_IIDX_LINE1: -// /* Check MCAN interrupts fired during TX/RX of CAN package */ -// u32InterruptLine1Status |= DL_MCAN_getIntrStatus(CANFD0); -// DL_MCAN_clearIntrStatus(CANFD0, u32InterruptLine1Status,DL_MCAN_INTR_SRC_MCAN_LINE_1); -// b_ServiceInt = true; -// break; -// default: -// break; -// } -//} - void CANFD0_IRQHandler(void) { - IntrStatus = DL_MCAN_getIntrStatus(CANFD0); + uint32_t IntrStatus = DL_MCAN_getIntrStatus(CANFD0); DL_MCAN_getProtocolStatus(CANFD0, &HeaderStat); - if(HeaderStat.busOffStatus==1) - { - DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL); - - } - if (HeaderStat.lastErrCode) { - - if (HeaderStat.lastErrCode != 3){ - int status = -1; - //printf("Attempting recovery...\n"); - status = xECU_CanReInit(CANFD0 , g_u16CanSpeed); - if(status == 0) - { - //printf("done\n"); - } - } -// else - //printf("tx ack err...\n"); - } - if (IntrStatus & DL_MCAN_INTERRUPT_TC){ __asm("nop"); DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1); @@ -378,78 +272,85 @@ void CANFD0_IRQHandler(void) u8_MCAN_StatusFlag = IVEC_MCAL_STATUS_SUCCESS; __asm("nop"); } - if(IntrStatus & DL_MCAN_INTERRUPT_RF0N) - { + else if(IntrStatus & DL_MCAN_INTERRUPT_RF0N){ + + while (false == b_ServiceInt); + b_ServiceInt = false; rxFS.fillLvl = 0; rxFS.num = DL_MCAN_RX_FIFO_NUM_0; - - int status = -1; - while ((rxFS.fillLvl) == 0) { DL_MCAN_getRxFIFOStatus(CANFD0, &rxFS); } - if (rxFS.fillLvl > 0) { - // There are messages to process - while (rxFS.fillLvl > 0) { - // Read and process messages... - // (Assuming you have logic to read from the FIFO) - DL_MCAN_readMsgRam(CANFD0, DL_MCAN_MEM_TYPE_FIFO, 0, rxFS.num, &TempRxMsg); - // Acknowledge the message - DL_MCAN_writeRxFIFOAck(CANFD0, rxFS.num, rxFS.getIdx); - - // Update the FIFO status again after reading - DL_MCAN_getRxFIFOStatus(CANFD0, &rxFS); - } - } + DL_MCAN_readMsgRam(CANFD0, DL_MCAN_MEM_TYPE_FIFO, 0, rxFS.num, &TempRxMsg); + DL_MCAN_writeRxFIFOAck(CANFD0, rxFS.num, rxFS.getIdx); xCanIdType_t idType = ERROR; - uint64_t idx = 0; - idx = TempRxMsg.id; - if(TempRxMsg.xtd == 0) + if (TempRxMsg.id >= 0 && TempRxMsg.id <= 0x7FF) { - idx = ((TempRxMsg.id & (uint32_t) 0x1FFC0000) >> (uint32_t) 18); + idType = STD_ID; + } else if (TempRxMsg.id <= 0x1FFFFFFF) + { + idType = EXT_ID; } - if(idx) + for(int i=0;i<8;i++) { - for(uint8_t inx = 0; inx <= 7; inx++) - { - g_CanData[inx] = TempRxMsg.data[inx]; - } - mcu_FDCAN_RxFifo_Callback(idx, &g_CanData[0], TempRxMsg.dlc); + u8CallBack_buff[i]=(TempRxMsg.data[i] & 0xFF); } + __asm("nop"); + + TempRxID=TempRxMsg.id; + _prv_vGetRxMsg(&TempRxMsg,&TempRxID ,TempRxBuffer,TempRxMsg.dlc); + DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1); b_ServiceInt = true; - DL_MCAN_getIntrStatus(CANFD0); + if(HeaderStat.busOffStatus==1) + { + DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL); + } + + uint32_t u32RxCANID = 0; + uint8_t u8RxData[8] = {0}; + + xMCAL_MCANRx(CANFD0,&u32RxCANID,u8RxData,8); + +// vSOC_MeterCallback(u32RxCANID, &u8RxData[0]); + mcu_FDCAN_RxFifo_Callback(u32RxCANID, &u8RxData[0], TempRxMsg.dlc); + } + else if(IntrStatus & MCAN_IR_PEA_MASK) + { + __asm("nop"); + DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1); + + } + else if(IntrStatus & MCAN_IR_BO_MASK) + + { DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1); } - //ErrorHandler(); + else{ + DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1); + + } } - - - - /*============================================================================================================================================================================================= API ==============================================================================================================================================================================================*/ /** - * @brief Function to initialize MCAN Peripheral - * @note Interrupts are enabled in this function itself - * @param MCAN Pointer to the register overlay for the peripheral - * @param BAUD Param to set Baud rate of MCAN - * @retval IVEC_McalStatus_e - */ + * @brief Function to initialize MCAN Peripheral + * @note Interrupts are enabled in this function itself + * @param MCAN Pointer to the register overlay for the peripheral + * @param BAUD Param to set Baud rate of MCAN + * @retval IVEC_McalStatus_e + */ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD) { -// DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM59, IOMUX_PINCM59_PF_CANFD0_CANTX); //ok -// DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM60, IOMUX_PINCM60_PF_CANFD0_CANRX); - assert(MCAN == CANFD0); assert(BAUD == BAUD_500 || BAUD == BAUD_250); assert(b_MCAN_InitFlag == 0); @@ -482,40 +383,37 @@ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD) /* Configure Bit timings. */ if(BAUD==BAUD_500) { + DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_500); } else if(BAUD==BAUD_250) { DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_250); } - else if(BAUD==BAUD_1000) - { - DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_1000); - } - else if(BAUD==BAUD_150) - { - DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_150); - } -// else if(BAUD==BAUD_125) -// { -// DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_125); -// } - else - { - DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_500); - } /* Configure Message RAM Sections */ DL_MCAN_msgRAMConfig(MCAN, (DL_MCAN_MsgRAMConfigParams*) &gMCAN0MsgRAMConfigParams); -// /* Configure Standard ID filter element */ -// DL_MCAN_addStdMsgIDFilter(MCAN, 0U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem); + /* Configure Standard ID filter element */ +// DL_MCAN_addStdMsgIDFilter(MCAN, 0U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem1); // -// DL_MCAN_addExtMsgIDFilter(MCAN, 0U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0ExtFilterElem); +// DL_MCAN_addStdMsgIDFilter(MCAN, 1U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem2); +// +// DL_MCAN_addStdMsgIDFilter(MCAN, 2U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem3); +// +// DL_MCAN_addStdMsgIDFilter(MCAN, 3U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem4); +// +// DL_MCAN_addStdMsgIDFilter(MCAN, 4U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem5); +// +// DL_MCAN_addExtMsgIDFilter(MCAN, 0U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem1); +// +// DL_MCAN_addExtMsgIDFilter(MCAN, 1U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem2); +// +// DL_MCAN_addExtMsgIDFilter(MCAN, 2U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem3); /* Set Extended ID Mask. */ - DL_MCAN_setExtIDAndMask(MCAN, (0x1FFFFFFFU) ); + DL_MCAN_setExtIDAndMask(MCAN, (0x1FFFFFFFU)); /* Take MCAN out of the SW initialization mode */ DL_MCAN_setOpMode(MCAN, DL_MCAN_OPERATION_MODE_NORMAL); @@ -534,12 +432,22 @@ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD) DL_MCAN_INTERRUPT_TC | \ DL_MCAN_INTERRUPT_TOO), 1U); - DL_MCAN_selectIntrLine(MCAN, DL_MCAN_INTR_MASK_ALL, DL_MCAN_INTR_LINE_NUM_1); + DL_MCAN_selectIntrLine(MCAN, (DL_MCAN_INTERRUPT_BEU | \ + DL_MCAN_INTERRUPT_BO | \ + DL_MCAN_INTERRUPT_ELO | \ + DL_MCAN_INTERRUPT_EP | \ + DL_MCAN_INTERRUPT_EW | \ + DL_MCAN_INTERRUPT_PEA | \ + DL_MCAN_INTERRUPT_PED | \ + DL_MCAN_INTERRUPT_RF0N | \ + DL_MCAN_INTERRUPT_TC | \ + DL_MCAN_INTERRUPT_TOO), DL_MCAN_INTR_LINE_NUM_1); DL_MCAN_enableIntrLine(MCAN, DL_MCAN_INTR_LINE_NUM_1, 1U); /* Enable MSPM0 MCAN interrupt */ DL_MCAN_clearInterruptStatus(MCAN,(DL_MCAN_MSP_INTERRUPT_LINE1)); DL_MCAN_enableInterrupt(MCAN,(DL_MCAN_MSP_INTERRUPT_LINE1)); + NVIC_SetPriority(CANFD0_INT_IRQn, 1); NVIC_EnableIRQ(CANFD0_INT_IRQn); b_MCAN_InitFlag = 1; @@ -549,121 +457,132 @@ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD) /** - * @brief Function to De-Initialize MCAN peripheral - * @param MCAN Pointer to the register overlay for the peripheral - * @retval IVEC MCAL status - */ - + * @brief Function to De-Initialize MCAN peripheral + * @param MCAN Pointer to the register overlay for the peripheral + * @retval IVEC MCAL status + */ IVEC_McalStatus_e xMCAL_MCANDeInit(MCAN_Regs* MCAN) { assert(MCAN == CANFD0); - assert(b_MCAN_InitFlag != 0); // Ensure the module was initialized before deinitializing. + assert(b_MCAN_InitFlag != 0); - /* Disable MSPM0 MCAN interrupt */ NVIC_DisableIRQ(CANFD0_INT_IRQn); - DL_MCAN_disableInterrupt(MCAN, DL_MCAN_MSP_INTERRUPT_LINE1); - - /* Put MCAN in SW initialization mode to stop it */ - DL_MCAN_setOpMode(MCAN, DL_MCAN_OPERATION_MODE_SW_INIT); - - /* Wait till MCAN is in SW initialization mode */ - while (DL_MCAN_OPERATION_MODE_SW_INIT != DL_MCAN_getOpMode(MCAN)); - - /* Disable the MCAN clock */ - DL_MCAN_disableModuleClock(MCAN); - - /* Clear initialization flag */ + DL_MCAN_disablePower(MCAN); b_MCAN_InitFlag = 0; return IVEC_MCAL_STATUS_SUCCESS; + } - /** - * @brief Function to Transmit CAN message - * @param MCAN Pointer to the register overlay for the peripheral - * @param TxMsg Message Object. - * @param TxData Array of Data to be transmitted - * @param BufNum Tx Buffer Number - * @param Bytes Number of bytes to be transmitted - * @retval IVEC_McalStatus_e - */ -IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, DL_MCAN_TxBufElement *TxMsg ,uint16_t *TxData, uint32_t BufNum, int Bytes) + * @brief Function to Transmit CAN message + * @param MCAN Pointer to the register overlay for the peripheral + * @param ID Message ID for TxMsg Object. + * @param TxData Array of Data to be transmitted + * @param BufNum Tx Buffer Number + * @param Bytes Number of bytes to be transmitted + * @retval IVEC_McalStatus_e + */ +IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, uint32_t u32ID ,uint16_t *TxData, uint32_t BufNum, uint32_t Bytes) { + // xMCAL_MCANTx(CANFD0,0x14FFFC23, timerTxData , 0, 8); + assert(MCAN == CANFD0); assert(b_MCAN_InitFlag != 0); + assert(Bytes<=8); + + if (u32ID>0x7FF){ + txMsg.xtd = 1; + txMsg.id = u32ID; + } + else{ + txMsg.xtd = 0; + txMsg.id = ((uint32_t)(u32ID)) << 18U; + } for(int i=0;idata[i] = TxData[i]; + txMsg.data[i]=TxData[i]; } - uint32_t txPendingStatus; - //Check if the Tx Buffer is available (no pending request) - txPendingStatus = DL_MCAN_getTxBufReqPend(MCAN); + // memcpy(txMsg.data,TxData,Bytes); + __asm("nop"); - //Check if the specified buffer (BufNum) is available - if ((txPendingStatus & (1 << BufNum)) == 0) + DL_MCAN_writeMsgRam(MCAN, DL_MCAN_MEM_TYPE_BUF, BufNum , &txMsg); + + DL_MCAN_TXBufTransIntrEnable(MCAN, BufNum, 1U); + + DL_MCAN_TXBufAddReq(MCAN, BufNum); + + l_canTransmitTimeout = i32MCAL_getTicks(); + u8_MCAN_StatusFlag = IVEC_MCAL_STATUS_BUSY; + + while(1){ + + if (u8_MCAN_StatusFlag == IVEC_MCAL_STATUS_SUCCESS || u8_MCAN_StatusFlag == IVEC_MCAL_STATUS_ERROR){ + __asm("nop"); + return u8_MCAN_StatusFlag; + } + else if((i32MCAL_getTicks() - l_canTransmitTimeout) > 2){ + __asm("nop"); + return IVEC_MCAL_STATUS_TIMEOUT; + } + } + if(HeaderStat.busOffStatus==1) { - DL_MCAN_writeMsgRam(MCAN, DL_MCAN_MEM_TYPE_BUF, BufNum , TxMsg); - DL_MCAN_TXBufAddReq(MCAN, BufNum); - - - } - else - { - //printf("tx pending\n"); - //return IVEC_MCAL_STATUS_BUSY; - + DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL); } + + b_ServiceInt = true; return IVEC_MCAL_STATUS_SUCCESS; } /** - * @brief Function to Receive CAN message - * @param MCAN Pointer to the register overlay for the peripheral - * @param RxMsg Message Object. - * @param FifoNum Fifo Number to be used - * @param RxData Array where received data is to be stored - * @param DLC length of received data - * @retval IVEC_McalStatus_e - */ -IVEC_McalStatus_e xMCAL_MCANRx(MCAN_Regs *MCAN, DL_MCAN_RxBufElement *RxMsg ,uint32_t FifoNum,uint8_t *RxData,int DLC) + * @brief Function to Receive CAN message + * @param MCAN Pointer to the register overlay for the peripheral + * @param RxMsg Message Object. + * @param FifoNum Fifo Number to be used + * @param RxData Array where received data is to be stored + * @param DLC length of received data + * @retval IVEC_McalStatus_e + */ +IVEC_McalStatus_e xMCAL_MCANRx(MCAN_Regs *MCAN,uint32_t *ID ,uint8_t *RxData, int DLC) { assert(MCAN == CANFD0); assert(b_MCAN_InitFlag != 0); - while (false == b_ServiceInt) + if(HeaderStat.busOffStatus==1) { - __WFE();//__asm("nop"); + DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL); } - b_ServiceInt = false; - rxFS.fillLvl = 0; - - if ((u32InterruptLine1Status & MCAN_IR_RF0N_MASK) == MCAN_IR_RF0N_MASK) - { - rxFS.num = DL_MCAN_RX_FIFO_NUM_0; - while ((rxFS.fillLvl) == 0) - { - DL_MCAN_getRxFIFOStatus(MCAN, &rxFS); - } - DL_MCAN_readMsgRam(MCAN, DL_MCAN_MEM_TYPE_FIFO, FifoNum, rxFS.num, RxMsg); - DL_MCAN_writeRxFIFOAck(MCAN, rxFS.num, rxFS.getIdx); - _prv_vGetRxMsg(RxMsg,RxData,DLC); - u32InterruptLine1Status &= ~(MCAN_IR_RF0N_MASK); - } + if((((TempRxID&0xFFF)>>1)==0x16)) + { + xMCAL_SoftReset(); + } + if((((TempRxID&0xFFF)>>1)==0x1AE)||(((TempRxID&0xFFF)>>1)==0x520)||(((TempRxID&0xFFF)>>1)==0xBB)||(((TempRxID&0xFFF)>>1)==0x1A4)||(((TempRxID&0xFFF)>>1)==0x521))//TODO: CHANGE ID CHECKS AFTER UPDATED CAN MATRIX + { + *ID=((TempRxID&0xFFF)>>1); + } + else + { + *ID=TempRxID; + } + for(int i=0;iid); -// printf("ID received dequeue %d\n",xBuff.id); l_xFuncStatus = commonECU_SUCCESS; } diff --git a/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c b/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c index 94428c9..db0d850 100644 --- a/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c +++ b/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c @@ -6,24 +6,14 @@ #define LOG_STRING "ivec-ecu-UART" #define CAN_UART_BUFFER_MAX_SIZE 2048 - - -volatile uint8_t g_TxCplt; -static uint8_t g_prv_u8CANUartDataBuffer[CAN_UART_BUFFER_MAX_SIZE]; - +#define DATA_PACKET_TIMEOUT 100 CmplxFifoQueueHandle_s __gprv_MyEcuUARTResponseQueue = { 0 }; -static uint32_t g_prv_u32CanUartDataAvailable = 0; -uint8_t QueueBuffer[100]; +static uint8_t __gprv_u8CANUartDataBuffer[CAN_UART_BUFFER_MAX_SIZE]; +static uint32_t __gprv_u32CanUartDataAvailable = 0; -#define DATA_PACKET_TIMEOUT 300 -//McalUartHandle_s prvUartHandle; -//#define SIZE 12U -//uint8_t u8txdata[SIZE]="Hello World"; -//uint32_t u32data_size=sizeof(u8txdata); -uint8_t u8rxdata; // Get the UART instance based on the enum static UART_Regs* GetUartInstance(McalUartPortNumber_e eUartPortNumber) @@ -43,15 +33,10 @@ static UART_Regs* GetUartInstance(McalUartPortNumber_e eUartPortNumber) static void __prv_vEcu_CANOverUartMsgCallback(IVEC_McalUartEvents_e eIndType, char* pucBuffer, uint32_t u32Size) { - if(eIndType == IVEC_MCAL_UART_EVENT_RX_ARRIVED){ if( u8CMPLX_FifoEnqueue(&__gprv_MyEcuUARTResponseQueue, pucBuffer, u32Size) ) - g_prv_u32CanUartDataAvailable += u32Size; + __gprv_u32CanUartDataAvailable += u32Size; } - - // IVEC_EcuCANHandle_s* l_xTempHandle = __prvECU_CANGetHandle(IVEC_ECU_CAN_EXTERNAL); - // if (l_xTempHandle != NULL) - } static void prvChecksumCalculate(uint8_t* pkt, int len, uint8_t *ck) { @@ -76,8 +61,8 @@ IVEC_EcuCommonErr_e xECU_UARTInit(McalUartHandle_s* prvUartHandle, uint32_t spee IVEC_ECU_LOG(LOG_STRING, "UART Initilising Queue"); __gprv_MyEcuUARTResponseQueue.i32ElementSize = sizeof(uint8_t); - __gprv_MyEcuUARTResponseQueue.i32TotalElements = 100; - __gprv_MyEcuUARTResponseQueue.pu8Buffer = (uint8_t*)QueueBuffer; + __gprv_MyEcuUARTResponseQueue.i32TotalElements = CAN_UART_BUFFER_MAX_SIZE; + __gprv_MyEcuUARTResponseQueue.pu8Buffer = (uint8_t*)__gprv_u8CANUartDataBuffer; __gprv_MyEcuUARTResponseQueue.i32QueueType = FIXED_ELEMENT_SIZE_QUEUE; l_i32Ret = u8CMPLX_FifoQueueInit(&__gprv_MyEcuUARTResponseQueue); if (l_i32Ret == 0) @@ -186,8 +171,6 @@ IVEC_EcuCommonErr_e xECU_UARTGetData(McalUartHandle_s *prvUartHandle, uint8_t* p } } - //xMCAL_TimerstopCounter(); // Stop the timer - if (ijk != len) { l_xFuncStatus = commonECU_READ_FAIL; diff --git a/ivec_RTE/src/ivec_rte.c b/ivec_RTE/src/ivec_rte.c index 905cb53..d5c5e2e 100644 --- a/ivec_RTE/src/ivec_rte.c +++ b/ivec_RTE/src/ivec_rte.c @@ -69,11 +69,6 @@ uint8_t mcu_tempDataReadPin(void){ } -/** - * #define TOUCH_BUTTON_PORT (GPIOB) - #define TOUCH_BUTTON_PIN_17_PIN (DL_GPIO_PIN_17) - #define TOUCH_BUTTON_PIN_17_IOMUX (IOMUX_PINCM43) - */ void vRTE_MatlabInit(void) { u8MCAL_gpioInit(); @@ -102,18 +97,18 @@ void vRTE_MatlabRun(void) tm1650_displaySwitch(TM_1650_Screen_ON); tm1650_showDot(TM_1650_DIG_1,false); tm1650_showDot(TM_1650_DIG_2,false); -// tm1650_showDot(TM_1650_DIG_3,false); + tm1650_showDot(TM_1650_DIG_3,false); tm1650_showNum(TM_1650_DIG_3, socTouchDisplay_Y.op_u8OnesPlace); tm1650_showNum(TM_1650_DIG_2, socTouchDisplay_Y.op_u8TensPlace); -// tm1650_showNum(TM_1650_DIG_1, socTouchDisplay_Y.op_u8HundredsPlace); + tm1650_showNum(TM_1650_DIG_1, socTouchDisplay_Y.op_u8HundredsPlace); } if( socTouchDisplay_Y.op_bErrorStatus ) { tm1650_displaySwitch(TM_1650_Screen_ON); tm1650_showDot(TM_1650_DIG_1,false); tm1650_showDot(TM_1650_DIG_2,false); -// tm1650_showDot(TM_1650_DIG_3,false); + tm1650_showDot(TM_1650_DIG_3,false); char l_cData = 'R'; l_cData = 'C'; @@ -145,26 +140,30 @@ void vRTE_UARTDataProcess(void) retCode= xECU_ReadCANDataOverUART(&g_xUartHandle,pucBuf,&ulId); if(retCode > -1) { - if(ulId == 0x00) + if(retCode > 0 && ulId == 0x00) { - //vECU_InitiateUartToCanTransmit(&g_xUartHandle, ulId, pucBuf, 0); - uint32_t baudrate = 0; uint8_t mode = pucBuf[PKT_HEADER]; memcpy(&baudrate, &pucBuf[PKT_HEADER+1], (uint32_t)retCode); - vECU_InitiateUartToCanTransmit(&g_xUartHandle, ulId, pucBuf, 0); + vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x01, pucBuf, 0); if( mode == 0 ) { g_u32UartSpeed = baudrate; - xECU_UARTReInit(&g_xUartHandle, g_u32UartSpeed); +// xECU_UARTReInit(&g_xUartHandle, g_u32UartSpeed); } else if( mode == 1 ) { g_u16CanSpeed = (uint16_t)baudrate; - xECU_CanReInit(CANFD0, g_u16CanSpeed); +// xECU_CanReInit(CANFD0, g_u16CanSpeed); } + vMCAL_DelayTicks(100); + vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x01, pucBuf, 0); } - else{ + if ( retCode == 0 && ulId == 0){ + vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x0, pucBuf, 0); + } + if ( retCode >= 0 && ulId > 0x00 && ulId < 0xffffffff ) + { xECU_WriteDataOverCAN(pucBuf, ulId, retCode, 0); } } diff --git a/utils/utils.c b/utils/utils.c index 92a1405..b9ba17b 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -258,4 +258,7 @@ IVEC_McalStatus_e xMCAL_VrefInit(void) return IVEC_MCAL_STATUS_INIT_FAIL; } - +void xMCAL_SoftReset(void) +{ + DL_SYSCTL_resetDevice(DL_SYSCTL_RESET_CPU); +} diff --git a/utils/utils.h b/utils/utils.h index f6af1d2..624a4ae 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -103,7 +103,7 @@ xCoreStatus_t xMCAL_SYSTICK_INIT(xTicks_t tick); int i32MCAL_getTicks(); void vMCAL_DelayTicks(int i32Delay_ms); - +void xMCAL_SoftReset(void); void xMCAL_McuInit(void); void delay (uint32_t us); IVEC_McalStatus_e xMCAL_VrefInit(void);