Hi Christian, On 08/06/2010 04:34 PM, christian pellegrin wrote: > On Fri, Aug 6, 2010 at 3:56 PM, Wolfgang Grandegger <[email protected]> > wrote: >> To be clear, out-of-order messages are also not OK. > > Yes I was looking at this with some interleave analysis. I think the > problem lies in the following race: > > // suppose we come here with RXB0 filled with packet X > u8 intf = mcp251x_read_reg(spi, CANINTF); > u8 eflag; > int can_id = 0, data1 = 0; > > // packet X+1 arrives and lands in RXB1 > > if (intf & CANINTF_RX0IF) { > mcp251x_hw_rx(spi, 0); > /* Free one buffer ASAP */ > mcp251x_write_bits(spi, CANINTF, intf & CANINTF_RX0IF, > 0x00); > } > > // packet X+2 arrives and lands in RXB0 > // unfortunately variable intf is old and doesn't show that we have > something in RXB1 > // (*1) > if (intf & CANINTF_RX1IF) > mcp251x_hw_rx(spi, 1); > > now on the next turn we will have packet X+2 in RXB0 and X+1 in RXB1 > so we read them out-of-order. The easiest way to solve the problem is > to take out the line: > > /* Free one buffer ASAP */ > mcp251x_write_bits(spi, CANINTF, intf & CANINTF_RX0IF, > 0x00); > > but we risk to lose more packets. Perhaps also rereading intf in (*1) > could work but we must be careful when we reset CANINTF register to > not lose an interrupt for RXB0. I will do some tests but after next > week because I don't have the access to the hardware until then.
I personally don't known that controller. Anyway, avoiding out-of-order messages with more than one TX objects is tricky on other controllers as well, e.g. AT91 and MSCAN. For that purpose I commited some time ago the utility "canfdtest" to the SVN utils: http://svn.berlios.de/viewvc/socketcan/trunk/can-utils/canfdtest.c?revision=1088&view=markup Might be useful here as well. Wolfgang. _______________________________________________ Socketcan-users mailing list [email protected] https://lists.berlios.de/mailman/listinfo/socketcan-users
