AnsweredAssumed Answered

CAN messages missing

Question asked by rahul krishna on Mar 6, 2015
Latest reply on Mar 10, 2015 by rahul krishna

Hi everyone,

I have seen an implementation of the CAN driver on the Xgate and the processing on the s12x using the following code. The goal of the project is to do processing on some msgs and direct to other channels some other messages.

 

In the Xgate core

void __interrupt XGATE_CAN_RECEIVE(XGCANstruct * channel)

{

  release[msg_index]=1;

// do some processing

  rxmsg[msg_index].msgID = rxid;

  release[msg_index] =0;

msg_index++;

if(msg_index == 10)

  msg_index=0;

-sif();

}


In the s12x core

void __interrupt CAN1_rxnotificationisr(void)

{

XGATE.xgif_50 = BIT9;

}

 

main()

{

while(1)

{

// some logic here

can_rx();

}

}

void can_rx(void)

{

for(index=0; index<=msg_index; index++)

{

  while(release[index] == 1)

  {

  }

  // do the processing some big logic here

}

msg_index=0;

}

 

i had serious doubts about the above implementation and modified as shown below.

 

Xgate core

void __interrupt XGATE_CAN_RECEIVE(XGCANstruct * channel)

{

// do some processing

rxmsg[l_canrxcounter_u8].msgID = rxid;

-sif();

}

 

S12x core

void __interrupt CAN1_rxnotificationisr(void)

{

l_canrxcounter_u8++;

}

and in the main file

int main(void)

{

while(1)

{

  // some big logic here

  can_rx();

}

 

void can_rx(void)

{

  if(l_canrxcounter_u8 > 0)

  {

    //do the message processing

    rxmsg[l_canrxcounter_u8-1];

    l_canrxcounter_u8--;

     // do processing on

    }

}

 

I have written the variable l_canrxcounter_u8 as the shared variable between the two cores without semaphores. Please help me if it is correct and do i need to implement using semaphores. How should i ensure that i am not missing any messages, because in the first implementation i saw that a lot of messages are received but not all by passed to other channels, some messages are missing and also not immediately after the message received it is happening after some messages.

For example

Channel1: msg1 rxed

channel1:msg2 rxed

channel2: msg1 txed

channel1:msg3 rxed

channel1: msg4 rxed

channel2: msg2 txed.

after that the sequence is completely missing. Please help me.   

Outcomes