Peter Pap de Pesteny

Suspicious Freescale recommended CAN-polling technique

Discussion created by Peter Pap de Pesteny on Jun 17, 2009
Latest reply on Jun 17, 2009 by Peter Pap de Pesteny

Freescales recommendations for polling of CAN-frames are as follows:

 

For each RX-MB where flag is raised:
    reset_flag();

    busy = 1;
    while (busy)
    {
        dummy = mbuff->CS.B.CODE; // locks MB
        busy = (uint8)(0x1 & dummy);
    }
    canId = mbuff->ID;  // extract canID from hardware 
    length = mbuff->CS.B.LENGTH;
    memcpy(data, (uint8*)mbuff->DATA.B, length);
    dummy = touCan->TIMER.R;   // releases lock of MB

 

This introduces a problematic while-loop. We do not want to let this loop potentionally run forever resulting in a watchdog-reset. At the same time limiting the loop so it runs maybe maxumum 10 times may result in lost CAN-frames. If we allow it to run longer, maybe 1000 times this could result in timing issues in our OS.

 

How should we proceed with this while-loop? Does anyone have any ideas it would be gratly appreciated!

 

Best regards,

Peter Pap

Outcomes