diff --git a/.cproject b/.cproject index 4f14b6d..9e01d05 100644 --- a/.cproject +++ b/.cproject @@ -238,6 +238,493 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index b281844..219eb49 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /dvt/ /.jxbrowser.userdata /AAR/ +/Test__GNU diff --git a/Core/Source/ivec_mcal_mcan.c b/Core/Source/ivec_mcal_mcan.c index 79372aa..6bc6a99 100644 --- a/Core/Source/ivec_mcal_mcan.c +++ b/Core/Source/ivec_mcal_mcan.c @@ -25,7 +25,7 @@ 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; -#define MCAN_FILTER_SIZE 2u +#define MCAN_FILTER_SIZE 0u /*REQUIRED MCAN CONFIGS*/ @@ -72,10 +72,10 @@ static DL_MCAN_ConfigParams gMCAN0ConfigParams={ .timeoutCntEnable = false, .filterConfig.rrfs = false, .filterConfig.rrfe = false, -// .filterConfig.anfe = 0, -// .filterConfig.anfs = 0, - .filterConfig.anfe = 3, - .filterConfig.anfs = 3, + .filterConfig.anfe = 0, + .filterConfig.anfs = 0, +// .filterConfig.anfe = 3, +// .filterConfig.anfs = 3, }; @@ -137,7 +137,7 @@ static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParams ={ /* Extended ID Filter List Start Address. */ .flesa = 48 , /* List Size: Extended ID. */ - .lse = 2 , + .lse = 0, /* Tx Buffers Start Address. */ .txStartAddr = 10 , /* Number of Dedicated Transmit Buffers. */ @@ -219,8 +219,8 @@ static DL_MCAN_BitTimingParams gMCAN0BitTimes_250 = { static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem1 = { .sfec = 001, .sft = 0x00, - .sfid1 = 0, - .sfid2 = 100, + .sfid1 = 0x1, + .sfid2 = 0x539, }; //static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem1 = { @@ -233,8 +233,8 @@ static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem1 = { static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem2 = { .sfec = 0x1, .sft = 0x00, - .sfid1 = 200, - .sfid2 = 300, + .sfid1 = 0x541, + .sfid2 = 0x2046, }; static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem3 = { @@ -261,8 +261,8 @@ static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem5 = { static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFiltelem1 = { .efec = 0x1, .eft = 0x0, - .efid1 = 3000, - .efid2 = 3500, + .efid1 = 2047, + .efid2 = 0x1FFFFFFF, }; static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFiltelem2 = { @@ -467,9 +467,9 @@ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD) DL_MCAN_msgRAMConfig(MCAN, (DL_MCAN_MsgRAMConfigParams*) &gMCAN0MsgRAMConfigParams); /* Configure Standard ID filter element */ - DL_MCAN_addStdMsgIDFilter(MCAN, 0U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem1); + // DL_MCAN_addStdMsgIDFilter(MCAN, 0U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem1); // - DL_MCAN_addStdMsgIDFilter(MCAN, 1U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem2); + ///DL_MCAN_addStdMsgIDFilter(MCAN, 1U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem2); // // DL_MCAN_addStdMsgIDFilter(MCAN, 2U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem3); // @@ -477,9 +477,9 @@ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD) // // DL_MCAN_addStdMsgIDFilter(MCAN, 4U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem5); // - DL_MCAN_addExtMsgIDFilter(MCAN, 0U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem1); +// DL_MCAN_addExtMsgIDFilter(MCAN, 0U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem1); // - DL_MCAN_addExtMsgIDFilter(MCAN, 1U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem2); + // DL_MCAN_addExtMsgIDFilter(MCAN, 1U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem2); // // DL_MCAN_addExtMsgIDFilter(MCAN, 2U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem3); @@ -533,17 +533,39 @@ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD) * @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); +// +// NVIC_DisableIRQ(CANFD0_INT_IRQn); +// DL_MCAN_disablePower(MCAN); +// b_MCAN_InitFlag = 0; +// +// return IVEC_MCAL_STATUS_SUCCESS; +// +//} IVEC_McalStatus_e xMCAL_MCANDeInit(MCAN_Regs* MCAN) { assert(MCAN == CANFD0); - assert(b_MCAN_InitFlag != 0); + assert(b_MCAN_InitFlag != 0); // Ensure the module was initialized before deinitializing. + /* Disable MSPM0 MCAN interrupt */ NVIC_DisableIRQ(CANFD0_INT_IRQn); - DL_MCAN_disablePower(MCAN); + DL_MCAN_disableInterrupt(MCAN, DL_MCAN_MSP_INTERRUPT_LINE1); + + 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 */ b_MCAN_InitFlag = 0; return IVEC_MCAL_STATUS_SUCCESS; - } /** diff --git a/ivec_RTE/src/ivec_rte.c b/ivec_RTE/src/ivec_rte.c index 88ffbb1..c2af55c 100644 --- a/ivec_RTE/src/ivec_rte.c +++ b/ivec_RTE/src/ivec_rte.c @@ -16,7 +16,7 @@ McalUartHandle_s g_xUartHandle; uint32_t g_u32UartSpeed = 0; -uint16_t g_u16CanSpeed = 0; +xCAN_baud_t g_u16CanSpeed = 0; #define MAX_FILTERS 10 uint32_t maskValues[MAX_FILTERS]; @@ -26,12 +26,17 @@ bool isExtendedID[MAX_FILTERS]; uint32_t maskCount = 0; // Buffers to store parsed data uint32_t filterCount = 0; +uint16_t extendedFilter = 0; +uint16_t standardFilter = 0; static uint8_t __gprv_u8Idx = 0; extern ExtU_socTouchDisplay_T socTouchDisplay_U; extern ExtY_socTouchDisplay_T socTouchDisplay_Y; +extern volatile bool b_MCAN_InitFlag; /*!< CAN initialization flag */ +//DL_MCAN_StdMsgIDFilterElement stdFilterElement; +#define MCAN_FILTER_SIZE 0u // New configuration instance to override filter settings dynamically static DL_MCAN_ConfigParams gMCAN0ConfigParamsFiltered = { @@ -50,30 +55,53 @@ static DL_MCAN_ConfigParams gMCAN0ConfigParamsFiltered = { }; // Adjust MsgRAMConfigParams as necessary for filter list sizes -static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParamsFiltered = { + +static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParamsFiltered ={ + + /* Standard ID Filter List Start Address. */ .flssa = 1, - .lss = 0, // Adjust according to actual standard filter count - .flesa = 48, - .lse = 0, // Adjust according to actual extended filter count - .txStartAddr = 10, - .txBufNum = 10, + /* List Size: Standard ID. */ + .lss = MCAN_FILTER_SIZE, + /* Extended ID Filter List Start Address. */ + .flesa = 48 , + /* 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, - .txEventFIFOStartAddr = 640, - .txEventFIFOSize = 10, + /* Tx Event FIFO Start Address. */ + .txEventFIFOStartAddr = 640 , + /* Event FIFO Size. */ + .txEventFIFOSize = 10 , + /* Level for Tx Event FIFO watermark interrupt. */ .txEventFIFOWaterMark = 0, - .rxFIFO0startAddr = 170, - .rxFIFO0size = 10, + /* Rx FIFO0 Start Address. */ + .rxFIFO0startAddr = 170 , + /* Number of Rx FIFO elements. */ + .rxFIFO0size = 10 , + /* Rx FIFO0 Watermark. */ .rxFIFO0waterMark = 0, .rxFIFO0OpMode = 0, - .rxFIFO1startAddr = 190, - .rxFIFO1size = 10, + /* 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, - .rxBufStartAddr = 208, + /* 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, }; @@ -193,8 +221,17 @@ void vCanFilterMaskSaveVal(uint8_t ucIdx, uint32_t mask, bool isExtended) maskCount = ucIdx; maskValues[maskCount] = mask; isExtendedID[maskCount++] = isExtended; + if(isExtended) + { + extendedFilter++; + } + else + { + standardFilter++; + } } + void vCanFilterSaveVal(uint8_t ucIdx, uint32_t Filter, bool isExtended) { filterCount = ucIdx; @@ -232,14 +269,22 @@ void vCanFilterReset() { } // Function to configure CAN filters -static void vCanConfigFilter() { +void vCanConfigFilter() { - // Disable CAN before configuring filters - xECU_CANDeInit(CANFD0); - uint16_t extendedFilter = 0; - uint16_t standardFilter = 0; + xECU_CanReInit(CANFD0,g_u16CanSpeed); + DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_SW_INIT); + gMCAN0MsgRAMConfigParamsFiltered.lse = extendedFilter; //0; // Set dynamically based on actual filters + gMCAN0MsgRAMConfigParamsFiltered.lss = standardFilter; //1; // Set dynamically based on actual filters + DL_MCAN_config(CANFD0, (DL_MCAN_ConfigParams*) &gMCAN0ConfigParamsFiltered); + DL_MCAN_msgRAMConfig(CANFD0, (DL_MCAN_MsgRAMConfigParams*) &gMCAN0MsgRAMConfigParamsFiltered); + +// maskCount = 1; +// isExtendedID[0] = 0; +// filterValues[0] = 0xc8; +// maskValues[0] = 0X7FE; for (int i = 0; i < maskCount; i++) { + if (isExtendedID[i]) { // Extended ID filter DL_MCAN_ExtMsgIDFilterElement extFilterElement; @@ -247,34 +292,39 @@ static void vCanConfigFilter() { extFilterElement.efid2 = maskValues[i]; extFilterElement.efec = 001; extFilterElement.eft = 10; - DL_MCAN_addExtMsgIDFilter(CANFD0, i, &extFilterElement); - extendedFilter++; + DL_MCAN_addExtMsgIDFilter(CANFD0, i, (DL_MCAN_StdMsgIDFilterElement *) &extFilterElement); + } else { // Standard ID filter DL_MCAN_StdMsgIDFilterElement stdFilterElement; stdFilterElement.sfid1 = filterValues[i]; stdFilterElement.sfid2 = maskValues[i]; +// stdFilterElement.sfid1 = 0xc8; +// stdFilterElement.sfid2 = 0x7fe; stdFilterElement.sfec = 001; stdFilterElement.sft = 10; - DL_MCAN_addStdMsgIDFilter(CANFD0, i, &stdFilterElement); - standardFilter++; + DL_MCAN_addStdMsgIDFilter(CANFD0, i,(DL_MCAN_StdMsgIDFilterElement *) &stdFilterElement); + } } + /* Set Extended ID Mask. */ + DL_MCAN_setExtIDAndMask(CANFD0, (0x1FFFFFFFU)); + /* Take MCAN out of the SW initialization mode */ + DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL); - - gMCAN0MsgRAMConfigParamsFiltered.lse = standardFilter; // Set dynamically based on actual filters - gMCAN0MsgRAMConfigParamsFiltered.lss = extendedFilter; // Set dynamically based on actual filters - DL_MCAN_config(CANFD0, (DL_MCAN_ConfigParams*) &gMCAN0ConfigParamsFiltered); - DL_MCAN_msgRAMConfig(CANFD0, &gMCAN0MsgRAMConfigParamsFiltered); +// gMCAN0MsgRAMConfigParamsFiltered.lse = standardFilter; // Set dynamically based on actual filters +// gMCAN0MsgRAMConfigParamsFiltered.lss = extendedFilter; // Set dynamically based on actual filters +// DL_MCAN_config(CANFD0, (DL_MCAN_ConfigParams*) &gMCAN0ConfigParamsFiltered); +// DL_MCAN_msgRAMConfig(CANFD0, &gMCAN0MsgRAMConfigParamsFiltered); // Reset counters after applying filters maskCount = 0; filterCount = 0; - // Re-enable CAN after filters - xECU_CANInit(CANFD0,g_u16CanSpeed); +// // Re-enable CAN after filters + //CANInitF(CANFD0,g_u16CanSpeed); } @@ -309,7 +359,8 @@ void vRTE_UARTDataProcess(void) if( pucBuf[PKT_HEADER+1] != 0 ){//22(20+2) rx filter available send each id in a frame uint32_t filterId = 0; memcpy(&filterId, &pucBuf[PKT_HEADER+3], sizeof(uint32_t)); - bool isExtended = (filterId > 0x7FF); // Standard IDs are <= 0x7FF + bool isExtended = 0; + isExtended = (filterId > 0x7FF); // Standard IDs are <= 0x7FF vCanFilterSaveVal((pucBuf[PKT_HEADER+1] - 1), filterId, isExtended); if( pucBuf[PKT_HEADER+2] )//All filter received. Trigger Filter Settings { @@ -329,7 +380,8 @@ void vRTE_UARTDataProcess(void) return; uint32_t maskId = 0; memcpy(&maskId, &pucBuf[PKT_HEADER+3], sizeof(uint32_t)); - bool isExtended = (maskId > 0x7FF); // Standard IDs are <= 0x7FF + bool isExtended = 0; + isExtended = (maskId > 0x7FF); // Standard IDs are <= 0x7FF vCanFilterMaskSaveVal((pucBuf[PKT_HEADER+1] - 1), maskId, isExtended); } vMCAL_DelayTicks(100);