Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
JQ
Level 1
Level 1
Distributor - Future(GC)
10 replies posted 5 comments on blog First comment on blog

g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_0  - IfxCan_RxBufferId_7;   can  enter receive interrupt

g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_8 -IfxCan_RxBufferId_63  can   not enter receive interrupt

Is there any configuration error?

g_mcmcan.canFilter.number = 2;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = CAN_MESSAGE_RX_ID3;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_8;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);

0 Likes
1 Solution
Jeremy_Z
Moderator
Moderator
Moderator
250 sign-ins 100 likes received 750 replies posted

Hi @JQ 
It seems a bit weird, I'd like to know whether you can replicate this phenomenon on the MCMCAN_FD_1_KIT_TC334_LK demo.
If yes, please illustrates how to modify the code, as it can help me to figure it out.
BR,
Jeremy

 

View solution in original post

0 Likes
2 Replies
Jeremy_Z
Moderator
Moderator
Moderator
250 sign-ins 100 likes received 750 replies posted

Hi @JQ 
It seems a bit weird, I'd like to know whether you can replicate this phenomenon on the MCMCAN_FD_1_KIT_TC334_LK demo.
If yes, please illustrates how to modify the code, as it can help me to figure it out.
BR,
Jeremy

 

0 Likes
JQ
Level 1
Level 1
Distributor - Future(GC)
10 replies posted 5 comments on blog First comment on blog

Hi jeremy:

                  以ID号0x1234563为例,可以在TC334_LK demo复现,把g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_0 可以正常进中断接收报文,

改为g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_8就进不了中断,此时while(1)函数进不去死机了,

 

#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

#include "Ifx_Types.h"
#include "IfxCan_Can.h"
#include "IfxCan.h"
#include "IfxCpu_Irq.h"
#include "IfxPort.h"
#include "./SysSe/Bsp/Bsp.h"

#define LED0 &MODULE_P00,5
#define LED1 &MODULE_P00,6
#define LED2 &MODULE_P13,2
#define LED3 &MODULE_P13,3

#define MODULE_CAN0_RAM 0xF0200000
#define NODE0_RAM_OFFSET 0x0
//#define NODE1_RAM_OFFSET 0x1000

#define CAN_MESSAGE_TX_ID0 (uint32)0x1234567
#define CAN_MESSAGE_RX_ID1 (uint32)0x1234561
#define CAN_MESSAGE_RX_ID2 (uint32)0x1234562
#define CAN_MESSAGE_RX_ID3 (uint32)0x1234563

#define ISR_PRIORITY_CAN_TX 2 /* Define the CAN TX interrupt priority */
#define ISR_PRIORITY_CAN_RX 1 /* Define the CAN RX interrupt priority */
#define MAXIMUM_CAN_DATA_PAYLOAD 2 /* Define maximum classical CAN payload in 4-byte words */

IFX_CONST IfxCan_Can_Pins Can00_pins = {
&IfxCan_TXD00_P20_8_OUT, IfxPort_OutputMode_pushPull, // CAN00_TX
&IfxCan_RXD00B_P20_7_IN, IfxPort_InputMode_pullUp, // CAN00_RX
IfxPort_PadDriver_cmosAutomotiveSpeed4
};

typedef struct
{
IfxCan_Can_Config canConfig; /* CAN module configuration structure */
IfxCan_Can canModule; /* CAN module handle */
IfxCan_Can_Node can00Node; /* CAN source node handle data structure */
IfxCan_Can_NodeConfig canNodeConfig; /* CAN node configuration structure */
IfxCan_Filter canFilter; /* CAN filter configuration structure */
IfxCan_Message txMsg; /* Transmitted CAN message structure */
IfxCan_Message rxMsg; /* Received CAN message structure */
uint32 txData[MAXIMUM_CAN_DATA_PAYLOAD]; /* Transmitted CAN data array */
uint32 rxData[MAXIMUM_CAN_DATA_PAYLOAD]; /* Received CAN data array */
} McmcanType;

McmcanType g_mcmcan;

IFX_INTERRUPT(canIsrTxHandler, 0, ISR_PRIORITY_CAN_TX);
void canIsrTxHandler(void)
{
/* Clear the "Transmission Completed" interrupt flag */
IfxCan_Node_clearInterruptFlag(g_mcmcan.can00Node.node, IfxCan_Interrupt_transmissionCompleted);

// IfxPort_togglePin(LED0); //transmit indicator
}

IFX_INTERRUPT(canIsrRxHandler, 0, ISR_PRIORITY_CAN_RX);
void canIsrRxHandler(void)
{
IfxCan_RxBufferId rxBufferId = IfxCan_RxBufferId_0;
/* Clear the "Message stored to Dedicated RX Buffer" interrupt flag */
IfxCan_Node_clearInterruptFlag(g_mcmcan.can00Node.node, IfxCan_Interrupt_messageStoredToDedicatedRxBuffer);
/* Clear the "New Data" flag; as long as the "New Data" flag is set, the respective Rx buffer is
* locked against updates from received matching frames.
*/

while(!IfxCan_Node_isRxBufferNewDataUpdated(g_mcmcan.can00Node.node, rxBufferId))
{
rxBufferId++;
}

g_mcmcan.rxMsg.bufferNumber = (uint8)rxBufferId;

/* Read the received CAN message */
IfxCan_Can_readMessage(&g_mcmcan.can00Node, &g_mcmcan.rxMsg, g_mcmcan.rxData);


/* Check if the received data matches with the transmitted one */
if((g_mcmcan.rxMsg.messageId == CAN_MESSAGE_RX_ID1))
{
if(g_mcmcan.rxData[0] == 0x3412)
{ //send 0x
IfxPort_setPinState(LED1, IfxPort_State_low); //LED ON
}
}

if((g_mcmcan.rxMsg.messageId == CAN_MESSAGE_RX_ID2))

{
if(g_mcmcan.rxData[0] == 0x7856)
{

IfxPort_setPinState(LED1, IfxPort_State_high);
}
}

if((g_mcmcan.rxMsg.messageId == CAN_MESSAGE_RX_ID3))
{
if(g_mcmcan.rxData[0] == 0x2345)
{
IfxPort_togglePin(LED0);
}
}

g_mcmcan.rxData[0]=rxBufferId;
IfxCan_Can_sendMessage(&g_mcmcan.can00Node, &g_mcmcan.rxMsg, &g_mcmcan.rxData[0]);
}

void initCAN0(void)
{
/*******CAN module configuration and initialization*******/
IfxCan_Can_initModuleConfig(&g_mcmcan.canConfig, &MODULE_CAN0);
IfxCan_Can_initModule(&g_mcmcan.canModule, &g_mcmcan.canConfig);

/*******CAN00 node configuration and initialization*******/
IfxCan_Can_initNodeConfig(&g_mcmcan.canNodeConfig, &g_mcmcan.canModule);

g_mcmcan.canNodeConfig.nodeId = IfxCan_NodeId_0;
g_mcmcan.canNodeConfig.clockSource = IfxCan_ClockSource_both;
g_mcmcan.canNodeConfig.frame.type = IfxCan_FrameType_transmitAndReceive;
g_mcmcan.canNodeConfig.frame.mode = IfxCan_FrameMode_standard; //Classic CAN

g_mcmcan.canNodeConfig.txConfig.txMode = IfxCan_TxMode_dedicatedBuffers;
g_mcmcan.canNodeConfig.txConfig.dedicatedTxBuffersNumber = 255;
g_mcmcan.canNodeConfig.txConfig.txBufferDataFieldSize = IfxCan_DataFieldSize_8;

g_mcmcan.canNodeConfig.rxConfig.rxMode = IfxCan_RxMode_dedicatedBuffers;
g_mcmcan.canNodeConfig.rxConfig.rxBufferDataFieldSize = IfxCan_DataFieldSize_8;

g_mcmcan.canNodeConfig.filterConfig.extendedListSize = 255; //Extended Frame
g_mcmcan.canNodeConfig.filterConfig.messageIdLength = IfxCan_MessageIdLength_extended;

g_mcmcan.canNodeConfig.messageRAM.extendedFilterListStartAddress = 0x600; //Extended Frame
g_mcmcan.canNodeConfig.messageRAM.rxBuffersStartAddress = 0x000;
g_mcmcan.canNodeConfig.messageRAM.txBuffersStartAddress = 0x400;
g_mcmcan.canNodeConfig.messageRAM.baseAddress = MODULE_CAN0_RAM + NODE0_RAM_OFFSET;

g_mcmcan.canNodeConfig.baudRate.baudrate = 500000; //500KBaud

//transmit interrupt
g_mcmcan.canNodeConfig.interruptConfig.transmissionCompletedEnabled = TRUE;
g_mcmcan.canNodeConfig.interruptConfig.traco.priority = ISR_PRIORITY_CAN_TX;
g_mcmcan.canNodeConfig.interruptConfig.traco.interruptLine = IfxCan_InterruptLine_0;
g_mcmcan.canNodeConfig.interruptConfig.traco.typeOfService = IfxSrc_Tos_cpu0;

//receive interrupt
g_mcmcan.canNodeConfig.interruptConfig.messageStoredToDedicatedRxBufferEnabled = TRUE;
g_mcmcan.canNodeConfig.interruptConfig.reint.priority = ISR_PRIORITY_CAN_RX;
g_mcmcan.canNodeConfig.interruptConfig.reint.interruptLine = IfxCan_InterruptLine_1;
g_mcmcan.canNodeConfig.interruptConfig.reint.typeOfService = IfxSrc_Tos_cpu0;

//binding pin
g_mcmcan.canNodeConfig.pins = &Can00_pins;

IfxCan_Can_initNode(&g_mcmcan.can00Node, &g_mcmcan.canNodeConfig);

/*******CAN filter configuration and initialization*******/
g_mcmcan.canFilter.number = 0;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = CAN_MESSAGE_RX_ID1;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);

g_mcmcan.canFilter.number = 1;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = CAN_MESSAGE_RX_ID2;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_1;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);

g_mcmcan.canFilter.number = 2;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = CAN_MESSAGE_RX_ID3;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_2;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);

g_mcmcan.canFilter.number = 3;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = (uint32)0x1234564;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_3;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);

g_mcmcan.canFilter.number = 4;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = (uint32)0x1234565;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_4;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);

g_mcmcan.canFilter.number = 5;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = (uint32)0x1234566;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_5;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);

g_mcmcan.canFilter.number = 6;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = (uint32)0x1234567;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_6;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);

g_mcmcan.canFilter.number = 7;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = (uint32)0x1234568;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_7;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);

g_mcmcan.canFilter.number = 8;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = (uint32)0x1234569;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_8;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter);
}

void initLED(void)
{
IfxPort_setPinMode(LED0, IfxPort_Mode_outputPushPullGeneral); /* Initialize LED port pin */
IfxPort_setPinMode(LED1, IfxPort_Mode_outputPushPullGeneral);
IfxPort_setPinMode(LED2, IfxPort_Mode_outputPushPullGeneral);
IfxPort_setPinMode(LED3, IfxPort_Mode_outputPushPullGeneral);
IfxPort_setPinState(LED0, IfxPort_State_high); /* Turn off LED (LED is low-level active) */
IfxPort_setPinState(LED1, IfxPort_State_high);
IfxPort_setPinState(LED2, IfxPort_State_high);
IfxPort_setPinState(LED3, IfxPort_State_high);

IfxPort_setPinMode(&MODULE_P20,9, IfxPort_Mode_outputPushPullGeneral);
IfxPort_setPinState(&MODULE_P20,9, IfxPort_State_low);

}


void core0_main(void)
{
IfxCpu_enableInterrupts();

/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());

/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);

initLED();
//initTime();
initCAN0();

IfxCan_Can_initMessage(&g_mcmcan.txMsg);
g_mcmcan.txMsg.messageId = CAN_MESSAGE_TX_ID0;
g_mcmcan.txMsg.bufferNumber = 0;
g_mcmcan.txMsg.dataLengthCode = IfxCan_DataLengthCode_8;//8 bytes
g_mcmcan.txMsg.frameMode = IfxCan_FrameMode_standard; //Classic CAN
g_mcmcan.txMsg.messageIdLength=IfxCan_MessageIdLength_extended; //Extended Frame
g_mcmcan.txData[0] = 0x98BADCFE;
g_mcmcan.txData[1] = 0x10325476;
//you will receive: FE DC BA 98 76 54 32 10

IfxCan_Can_initMessage(&g_mcmcan.rxMsg);
g_mcmcan.rxMsg.messageIdLength=IfxCan_MessageIdLength_extended;
g_mcmcan.rxMsg.bufferNumber = 0;

while(1)
{
// g_mcmcan.txData[0]=IfxCan_Node_getLastErroCodeStatus(&g_mcmcan.can00Node.node);
// IfxCan_Can_sendMessage(&g_mcmcan.can00Node, &g_mcmcan.txMsg, &g_mcmcan.txData[0]);

IfxPort_togglePin(LED0);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 1000));
}
}

0 Likes