HCS12X MSCAN and ISR priority

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

HCS12X MSCAN and ISR priority

964 Views
sonar_ru_alias
Contributor I

Hi for All,

 

I`m use MSCAN MC9S12XET256MAG.

 

Module MSCAN is interrupt driven with priority 3.

If I use additional timer interrupt with priority 5 than CAN messages is lost ( not passed ).

 

Why?

 Best regards.

Labels (1)
Tags (1)
0 Kudos
7 Replies

532 Views
kef
Specialist I

It can happen in case timer interrupt takes so long that all 5 receive buffers are filled with messages and you get overrun flag set. Is it the case? If so, then try triming your timer interrupt. If you can't ( though there are no reasons for that), then you can use interrupt nesting to fix the problem. To do so, reverse priorities. Long ISR's must have least interrupt priority. To make enormously long ISR's interrupted by higher priority interrupts, add asm("CLI") or enable_interrupts at top of long ISR's.

0 Kudos

532 Views
sonar_ru_alias
Contributor I

Hi, Kef.

 

TX CAN messages not transfered.

Timer interrupt is ECT and used FreeRTOS ( tick timer ) .

CAN TX interrupt don't disable global interrupt and so it is possible to switch context.

But this should not lead to loss TX messages, only additional delay?

 

And messages lost under heavy load CANbus ( with other node with a higher priority messages).

 

PS: It seems that the request for transfer of CAN messages
       ( in reg. CAN4TFLG ) is reset if the unit has lost arbitration on the bus. 

0 Kudos

532 Views
kef
Specialist I
  • PS: It seems that the request for transfer of CAN messages        ( in
  • reg. CAN4TFLG ) is reset if the unit has lost arbitration on the bus.

No.

 

Show you code how do you send CAN messages.

0 Kudos

532 Views
sonar_ru_alias
Contributor I

Hello,

 

ISR is:

 

ISR(CANrez_InterruptTx){  byte buffer = (CAN4TFLG & CAN4TIER) & 7; /* Temporary variable */  CAN4TIER &= ~buffer;                 /* Clear appropriate transmit flags and release TX buffer */  if (CANrez_EnEvent) {                /* Are events enabled? */    CANrez_OnFreeTxBuffer((word)buffer); /* If yes then invoke user event */  }}

 Here is not disable global interrupt. And event handler:

 

void CANrez_OnFreeTxBuffer(word BufferMask){  /* Write your code here ... */    MsgCANbus msg_isr_tx_can; // сообщение CAN для передачи контроллеру  portBASE_TYPE mng_woken = FALSE; // пробуждение менеджера  unsigned char num_buf = 0; // номер используемого аппаратного буфера    if ( uxQueueMessagesWaiting( q_isr_tx_can ) ) // CAN очередь не пустая  {    if ( 1 == ( CANrez_GetStateTX() & CAN4TFLG_TXE0_MASK ) ) // есть свободные    {      // Принимаем CAN сообщение от менеджера            if ( pdPASS == xQueueReceiveFromISR( q_isr_tx_can, & msg_isr_tx_can, & mng_woken ) ) // прочитали сообщение      {        if ( MI_CANmng2isr == msg_isr_tx_can.id ) // сообщение от менеджера        {          CANrez_SendFrame( num_buf, msg_isr_tx_can.can_id | CAN_EXTENDED_FRAME_ID,            msg_isr_tx_can.frm_type, msg_isr_tx_can.len, msg_isr_tx_can.data ); // передали сообщение контроллеру        }      }    }  }}

 

 So, sended messages are in the queue ( I use FreeRTOS ).

May be influenced by a context switch?

Although it seems to me that this should lead only to further delay.

 

Best regards,

Sergey. 

0 Kudos

532 Views
kef
Specialist I

I don't see what happens in SendFrame(), but you are calling it always with the same num_buf=0. It could be that ISR disables interrupt for buf2 and calls SendFrame to fill buf0, which will fail in case buf0 is busy.

0 Kudos

532 Views
sonar_ru_alias
Contributor I

Hello, Kef.

 

Thanks for the answer, but it still does not understand. 

I did interrupt levels of the ECT and CAN identical, there seems to be no more mistakes 

0 Kudos

532 Views
kef
Specialist I

ISR priority has nothing to do with sending CAN messages. Look for errors in your software.

0 Kudos