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

cross mob
GY
Level 2
Level 2
5 questions asked 10 sign-ins First solution authored

Hello Infineon,

I want to know the Node ID of the received rx interrupt.
I initialized node 0~2 of CAN0 with rx interrupt.
Is there any way to know the Node ID of a received packet?

 

uint8_t rxCANData[3][64];
void canIsrRxHandler(void)
{
/* Clear the "RX FIFO 0 new message" interrupt flag */
IfxCan_Node_clearInterruptFlag(g_mcmcan.canDstNode.node, IfxCan_Interrupt_rxFifo0NewMessage);

/* Received message content should be updated with the data stored in the RX FIFO 0 */
g_mcmcan.rxMsg.readFromRxFifo0 = TRUE;

/* Read the received CAN message */
IfxCan_Can_readMessage(&g_mcmcan.canDstNode, &g_mcmcan.rxMsg, (uint32*)&g_mcmcan.rxData[0]);

/* Increment the counter confirming to the source node that the previous message has been received */
g_isrRxCount++;

uint32_t length = IfxCan_Node_getDataLength(g_mcmcan.rxMsg.dataLengthCode);
uint8_t node_id = ???;

// For example
memcpy(&rxCANData[node_id], g_mcmcan.rxData, length);
}

 

#define NUMBER_OF_CAN_FD_CASES 3

void initMcmcan(void)
{
/* ==========================================================================================
* CAN module configuration and initialization:
* ==========================================================================================
* - load default CAN module configuration into configuration structure
* - initialize CAN module with the default configuration
* ==========================================================================================
*/
IfxCan_Can_initModuleConfig(&g_mcmcan.canConfig, &MODULE_CAN0);

IfxCan_Can_initModule(&g_mcmcan.canModule, &g_mcmcan.canConfig);

/* ==========================================================================================
* Source CAN node configuration and initialization:
* ==========================================================================================
* - load default CAN node configuration into configuration structure
* - assign source CAN node to CAN node 0
* - initialize the source CAN node with the modified configuration
* ==========================================================================================
*/
IfxCan_Can_initNodeConfig(&g_mcmcan.canNodeConfig, &g_mcmcan.canModule);

g_mcmcan.canNodeConfig.nodeId = IfxCan_NodeId_0;
g_mcmcan.canNodeConfig.rxConfig.rxMode = IfxCan_RxMode_fifo0;
g_mcmcan.canNodeConfig.rxConfig.rxFifo0Size = NUMBER_OF_CAN_FD_CASES;

g_mcmcan.canNodeConfig.interruptConfig.rxFifo0NewMessageEnabled = TRUE;
g_mcmcan.canNodeConfig.interruptConfig.rxf0n.priority = ISR_PRIORITY_CAN_RX;
g_mcmcan.canNodeConfig.interruptConfig.rxf0n.interruptLine = IfxCan_InterruptLine_0;
g_mcmcan.canNodeConfig.interruptConfig.rxf0n.typeOfService = IfxSrc_Tos_cpu0;

g_mcmcan.canNodeConfig.pins = NULL; // conpig pins Later

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

/* ==========================================================================================
* Destination CAN node configuration and initialization:
* ==========================================================================================
* - load default CAN node configuration into configuration structure
* - assign destination CAN node to CAN node 1
* - initialize the destination CAN node with the modified configuration
* ==========================================================================================
*/
IfxCan_Can_initNodeConfig(&g_mcmcan.canNodeConfig, &g_mcmcan.canModule);

g_mcmcan.canNodeConfig.nodeId = IfxCan_NodeId_1;
g_mcmcan.canNodeConfig.rxConfig.rxMode = IfxCan_RxMode_fifo0;
g_mcmcan.canNodeConfig.rxConfig.rxFifo0Size = NUMBER_OF_CAN_FD_CASES;

g_mcmcan.canNodeConfig.interruptConfig.rxFifo0NewMessageEnabled = TRUE;
g_mcmcan.canNodeConfig.interruptConfig.rxf0n.priority = ISR_PRIORITY_CAN_RX;
g_mcmcan.canNodeConfig.interruptConfig.rxf0n.interruptLine = IfxCan_InterruptLine_1;
g_mcmcan.canNodeConfig.interruptConfig.rxf0n.typeOfService = IfxSrc_Tos_cpu0;

g_mcmcan.canNodeConfig.pins = NULL; // conpig pins Later

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

/* ==========================================================================================
* Destination CAN node configuration and initialization:
* ==========================================================================================
* - load default CAN node configuration into configuration structure
* - assign destination CAN node to CAN node 1
* - initialize the destination CAN node with the modified configuration
* ==========================================================================================
*/
IfxCan_Can_initNodeConfig(&g_mcmcan.canNodeConfig, &g_mcmcan.canModule);

g_mcmcan.canNodeConfig.nodeId = IfxCan_NodeId_2;
g_mcmcan.canNodeConfig.rxConfig.rxMode = IfxCan_RxMode_fifo0;
g_mcmcan.canNodeConfig.rxConfig.rxFifo0Size = NUMBER_OF_CAN_FD_CASES;

g_mcmcan.canNodeConfig.interruptConfig.rxFifo0NewMessageEnabled = TRUE;
g_mcmcan.canNodeConfig.interruptConfig.rxf0n.priority = ISR_PRIORITY_CAN_RX;
g_mcmcan.canNodeConfig.interruptConfig.rxf0n.interruptLine = IfxCan_InterruptLine_2;
g_mcmcan.canNodeConfig.interruptConfig.rxf0n.typeOfService = IfxSrc_Tos_cpu0;

g_mcmcan.canNodeConfig.pins = NULL; // conpig pins Later

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

/* Received message content should be updated with the data stored in the RX FIFO 0 */
g_mcmcan.rxMsg.readFromRxFifo0 = TRUE;

/* Initialization of the RX message with the default configuration */
IfxCan_Can_initMessage(&g_mcmcan.rxMsg);
}

0 Likes
4 Replies
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi GY,

Please refer to User Manual Interrupt Signalling Register i

ISREGi (i=0-3)
Interrupt Signalling Register i

For Node i, there are 16 interrupt type and will be flagged here, so you could know which node has interrupt.

 

dw

0 Likes
GY
Level 2
Level 2
5 questions asked 10 sign-ins First solution authored

 

 

Ifx_CAN_N *node1_Pointer;

IFX_INTERRUPT(canIsrRxHandler, 0, ISR_PRIORITY_CAN_RX);

 

void canIsrRxHandler(void)

{

...

   /* Read the received CAN message */
   IfxCan_Can_readMessage(&g_mcmcan.canDstNode, &g_mcmcan.rxMsg, (uint32*)&g_mcmcan.rxData[0]);

   uint8 can_ch;
   if (node1_Pointer->ISREG == g_mcmcan.canDstNode.node->ISREG) {
      can_ch = CAN_CH1;
   }
   else if (node2_Pointer->ISREG == g_mcmcan.canDstNode.node->ISREG) {
      can_ch = CAN_CH2;
   }
   else if (node3_Pointer->ISREG == g_mcmcan.canDstNode.node->ISREG) {
      can_ch = CAN_CH3;
   }

...

}

void initMcmcan(void)

{

...

node1_Pointer = IfxCan_getNodePointer(g_mcmcan.canNodeConfig.can, g_mcmcan.canNodeConfig.nodeId);

...

}

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi GY,

Thanks for your reply, does it work? Hopefully get your confirm.

dw

0 Likes
GY
Level 2
Level 2
5 questions asked 10 sign-ins First solution authored

I am going to modify the code below and test it.

I don't have a test board right now.
I will answer the test result after receiving the board this month or next month.

void canIsrRxHandler(void)

{

...

   node1_Pointer = IfxCan_getNodePointer(g_mcmcan.canNodeConfig.can, g_mcmcan.canNodeConfig.nodeId);
   node2_Pointer = IfxCan_getNodePointer(g_mcmcan.canNodeConfig.can, g_mcmcan.canNodeConfig.nodeId);
   node3_Pointer = IfxCan_getNodePointer(g_mcmcan.canNodeConfig.can, g_mcmcan.canNodeConfig.nodeId);

   uint8 can_ch;
   if (node1_Pointer->ISREG.B.RXF0N) {
      can_ch = CAN_CH1;
      node1_Pointer->ISREG.B.RXF0N = 0;
   }
   else if (node2_Pointer->ISREG.B.RXF0N) {
      can_ch = CAN_CH2;
      node2_Pointer->ISREG.B.RXF0N = 0;
   }
   else if (node3_Pointer->ISREG.B.RXF0N) {
      can_ch = CAN_CH3;
      node3_Pointer->ISREG.B.RXF0N = 0;
   }

...

}

0 Likes