CAN Code with Non Blocking Functionality

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAN Code with Non Blocking Functionality

604 Views
Dilip1441
Contributor I

Hi,

I'm Using can_pal_s32k144 Example Code.

In that code if i didn't receive any message from other end, The Code is blocked at

/* Wait until the previous FlexCAN receive is completed */
while(CAN_GetTransferStatus(INST_CAN_PAL1, RX_MAILBOX) == STATUS_BUSY);

Can you please Suggest to Achieve the Both Cases

1.When ever the CAN Msg Received it need to have the Capable of Reading without any issue.

2.When ever the CAN Msg didn't Received, It'll move forward for the next Functionalities without blocking at CAN_GetTransferStatus

 

 

Thank you

0 Kudos
4 Replies

466 Views
Dilip1441
Contributor I

Hi,

 

In below function RX_MSG_ID indicates only one particular CAN Message ID to Receive.

Ex: RX_MSG_ID = 7; it'll receive CAN Message ID 7 only, If send Message ID 6,5,8 It won't receive.

 

/* Configure RX buffer with index RX_MAILBOX */
CAN_ConfigRxBuff(INST_CAN_PAL1, RX_MAILBOX, &buffCfg, RX_MSG_ID);

 

 

Can you please suggest me to receive all messages which i sent from other end.

 

and what is TX_MAILBOX and RX_MAILBOX?

0 Kudos

599 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

instead of while statement use if condition

if(CAN_GetTransferStatus(INST_CAN_PAL1, RX_MAILBOX) != STATUS_BUSY)
{
     // read data from receive buffer
     // call Receive function again
}

BR, Petr

0 Kudos

594 Views
Dilip1441
Contributor I

Hi,
Thanks for the Reply.

Currently the code is for Rx is like below.

while(1)

{

   CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);

   /* Wait until the previous FlexCAN receive is completed */
   while(CAN_GetTransferStatus(INST_CAN_PAL1, RX_MAILBOX) == STATUS_BUSY);//If no message received it's blocking on Here

   /* Check the received message ID and payload */
   if((recvMsg.data[0] == LED0_CHANGE_REQUESTED) &&
   recvMsg.id == RX_MSG_ID)
   {
          /* Toggle output value LED1 */
          PINS_DRV_TogglePins(GPIO_PORT, (1 << LED0));

   }

}

If i removed the while condition, The LED Toggling is not working

also if i changed the code like below also the Toggling is not working.

 

CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);

if(CAN_GetTransferStatus(INST_CAN_PAL1, RX_MAILBOX) != STATUS_BUSY)
{
     // read data from receive buffer

     CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);

}

0 Kudos

558 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

code should be rather below...

CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);

while(1)
{

   /* check if FlexCAN receive is completed */
   if(CAN_GetTransferStatus(INST_CAN_PAL1, RX_MAILBOX) != STATUS_BUSY)
   {
        /* Check the received message ID and payload */
        if((recvMsg.data[0] == LED0_CHANGE_REQUESTED) &&recvMsg.id == RX_MSG_ID)
        {
              /* Toggle output value LED1 */
              PINS_DRV_TogglePins(GPIO_PORT, (1 << LED0));

        }
        CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);
    }

}

BR, Petr

0 Kudos