MCF5213 FlexCAN problems

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

MCF5213 FlexCAN problems

1,582 Views
alex_a
Contributor I
Hi,

I'm trying to write CAN driver (open/close/get_msg/send_msg) for MCF5213 (M5213EVB). I'm using CodeWarrior 7.1 SE.
I have some questions (cause 5213 RM chapter about FlexCAN IMHO is not perfect.)

1) It doesn't clear what should i do on frame receiving in RX interrupt service routine to safely grab a message. Should I only lock that buffer (read code, grab and read time stamp) or deactivate the buffer (write INACTIVE code, grab, write RX_EMPTY code )?
I'm afraid of frames lost.

2) Is it possible to switch off self-received messages on hw level or I have to do this "manually" by caching sent messages?

3) Is it possible to treat any incoming RTR frame as other incoming frames? This is important cause my driver have to deliver this RTR message to the upper level. 
I have to receive RTR frames with any ID and pass them to software RX FIFO buffer.


Thank you.

  

Labels (1)
0 Kudos
2 Replies

339 Views
mjbcswitzerland
Specialist V
Hi Alex

It is a long time since I worked on the M5213 CAN driver but here are some ideas (based on quickly looking at out code)

>>It doesn't clear what should i do on frame receiving in RX interrupt service routine to safely grab a message. Should I only lock that buffer (read code, grab and read time stamp) or deactivate the buffer (write INACTIVE code, grab, write RX_EMPTY code )?
I'm afraid of frames lost.

On Rx interrupt we do
        COLDFIRE_CAN_BUF *ptrMessageBuffer = MBUFF0_ADD;
        ptrMessageBuffer += iIntBuf;
        *(unsigned char *)ptrMessageBuffer = 0;        // deactivate buffer so that it doesn't get overwritten

    CAN_IFLAG = (0x0001 << iIntBuf);                      // clear interrupt flag


Then the receiver can extract the message 'off-line' (outside of critical interrupt).


>>Is it possible to switch off self-received messages on hw level or I have to do this "manually" by caching sent messages?
I don't remember the details (or whether HW filtering is possible) but there is always an interrupt and it is possible to detect whether it is one of the following cases:
- buffer has just transmitted a remote frame request
- a remote response has been detected
- remote frame transmission message successfully acked
- tx message successfully acked

>>Is it possible to treat any incoming RTR frame as other incoming frames? This is important cause my driver have to deliver this RTR message to the upper level. 
I have to receive RTR frames with any ID and pass them to software RX FIFO buffer.

RTR frames cause the used tx buffer to automatically revert to rx buffer after transmission. The reception process is then the same as for any buffer. I think that it is therefore a case of the driver remembering the mode of the buffer use and reacting accordingly.

Take a look at the following documenmt which describes our implementation on the Coldifre:
http://www.utasker.com/docs/uTasker/uTaskerCAN.PDF

On page 6/9 Remote frame operation is discussed (at the user level). Maybe it will give an idea of whether this is what you want to do (in which case it is possible) or not.

Sorry if the response it a little vague but it really is a long time since I worked on the CAN driver and so I am very rusty...


Regards

Mark

www.uTasker.com






0 Kudos

339 Views
alex_a
Contributor I
Thaks for reply.

As I understand the ref manual suggested code for RX interrupt is not good because deactivation of a message buffer without freezing "may produce undesirable result" (MCF5213 RM p.25-24, "Message Buffer Deactivation")

Anyway, the main problem is incoming RTR frames. RM says: "The mask registers are not used in remote frame ID matching. All ID
bits (except RTR) of the incoming received frame must match for the remote frame to trigger a response
transmission. "  But what should i do if i write a driver which will be used by upper level lib (e.g. CANopen Canfestival lib)? My driver doesn't know about what RTR frames should be replied  and doesn't know about how to reply. It would be great to treat incoming RTR frames as any other frames. (just pass them to the upper level).

Is there any other doc that describes FlexCAN module?

Thank you.
0 Kudos