feat: Ensure runtime filters are re-applied during CAN reinitialization

- Added functionality to retain and reapply runtime filters automatically when CAN is reinitialized.
(Addressed an issue where excessive packets caused CAN errors when charger and daughter board were connected. )
stable
Rakshita 2025-01-08 15:42:05 +05:30
parent 9f0e5a215d
commit bbd2a74cbf
3 changed files with 37 additions and 15 deletions

View File

@ -1,6 +1,8 @@
#include "../ivec_ECU/ivec_ecu_can/inc/ivec_ecu_can.h"
#include "../ivec_ECU/ivec_ecu_uart/inc/ivec_ecu_uart.h"
#include "../Core/Include/ivec_mcal_uart.h"
extern int maskCount;
extern int filterCount;
static can_buff_t g_canBuffer[1024] = {0}; /*All the CAN Id, Len and Data are stored in this array*/
QUEUE(g_canQueue, g_canBuffer);
@ -61,6 +63,12 @@ IVEC_EcuCommonErr_e xECU_CanReInit(MCAN_Regs* MCAN,uint16_t speed)
{
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
uint8_t l_i32Ret;
if(maskCount >= 0)
{
vCanFilterReset();
}
l_i32Ret = xMCAL_MCANDeInit(MCAN);
if(l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
{
@ -76,6 +84,10 @@ IVEC_EcuCommonErr_e xECU_CanReInit(MCAN_Regs* MCAN,uint16_t speed)
DL_GPIO_initPeripheralOutputFunction(GPIO_MCAN0_IOMUX_CAN_TX, GPIO_MCAN0_IOMUX_CAN_TX_FUNC);
DL_GPIO_initPeripheralInputFunction(GPIO_MCAN0_IOMUX_CAN_RX, GPIO_MCAN0_IOMUX_CAN_RX_FUNC);
l_i32Ret = xMCAL_MCANInit(MCAN,speed);
if(maskCount >= 0)
{
vCanConfigFilter();
}
if(l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
{
l_xFuncStatus = commonECU_INIT_FAIL;

View File

@ -26,9 +26,9 @@ uint32_t maskValues[MAX_FILTERS];
uint32_t filterValues[MAX_FILTERS];
bool isExtendedID[MAX_FILTERS];
uint32_t maskCount = 0;
int maskCount = -1;
// Buffers to store parsed data
uint32_t filterCount = 0;
int filterCount = -1;
uint16_t extendedFilter = 0;
uint16_t standardFilter = 0;
@ -288,7 +288,7 @@ void vCanFilterReset() {
// Function to configure CAN filters
void vCanConfigFilter() {
xECU_CanReInit(CANFD0,g_u16CanSpeed);
//xECU_CanReInit(CANFD0,g_u16CanSpeed);
DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_SW_INIT);
@ -323,8 +323,8 @@ void vCanConfigFilter() {
extFilterElement.efec = 001;
extFilterElement.eft = 10;
DL_MCAN_addExtMsgIDFilter(CANFD0, extendedFilterNumber, (DL_MCAN_StdMsgIDFilterElement *) &extFilterElement);
filterValues[i] = 0;
maskValues[i] = 0;
// filterValues[i] = 0;
// maskValues[i] = 0;
extendedFilterNumber++;
}
@ -336,8 +336,8 @@ void vCanConfigFilter() {
stdFilterElement.sfec = 001;
stdFilterElement.sft = 10;
DL_MCAN_addStdMsgIDFilter(CANFD0, stadardFilterNumber,(DL_MCAN_StdMsgIDFilterElement *) &stdFilterElement);
filterValues[i] = 0;
maskValues[i] = 0;
// filterValues[i] = 0;
// maskValues[i] = 0;
stadardFilterNumber++;
}
@ -350,8 +350,8 @@ void vCanConfigFilter() {
// Reset counters after applying filters
maskCount = 0;
filterCount = 0;
// maskCount = 0;
// filterCount = 0;
extendedFilter = 0;
standardFilter = 0;
@ -393,15 +393,24 @@ void vRTE_UARTDataProcess(void)
vCanFilterSaveVal((g_pu8Buf[PKT_HEADER+1] - 1), filterId, isExtended);
if( g_pu8Buf[PKT_HEADER+2] )//All filter received. Trigger Filter Settings
{
vCanFilterReset();
vCanConfigFilter();
//vCanFilterReset();
xECU_CanReInit(CANFD0,g_u16CanSpeed);
//vCanConfigFilter();
}
else
return;
}
else{
vCanFilterReset();
vCanConfigFilter();
// memset(maskValues, 0, sizeof(maskValues));
// memset(vCanFilterReset, 0, sizeof(vCanFilterReset));
//vCanFilterReset();
xECU_CanReInit(CANFD0,g_u16CanSpeed);
//maskCount = -1;
//vCanConfigFilter();
}
}
else if ( mode == 3 )
@ -424,7 +433,7 @@ void vRTE_UARTDataProcess(void)
vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x01, g_pu8Buf, 0);
}
if ( retCode == 0 && ulId == 0){
vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x0, g_pu8Buf, 0);
vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x0, g_pu8Buf, 0); //interface okay response
}
if ( retCode >= 0 && (ulId > 0x00 && ulId < 0xffffffff) )
{

3
main.c
View File

@ -16,7 +16,7 @@
#include "../Core/Include/ivec_mcal_uart.h"
#include "string.h"
#include "ivec_rte.h"
extern McalUartHandle_s g_xUartHandle;
void vMCAL_TimerCallback(void)
{
#if UART_PIN_SELECTION == 1
@ -49,6 +49,7 @@ int main(void)
#endif
vRTE_InitUARTCANEcho();
vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x6, NULL, 0);
while(1)
{
vRTE_UARTDataProcess();