From 854494109d7e72171607a9a7bd4cd30cbce7c5ce Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Wed, 17 Dec 2014 12:42:27 +0100 Subject: [PATCH] Atmel 230bb: always increase the rx frame ringbuffer cursor in rf230_read(). Avoids packet reordering in cases when RF230_CONF_RX_BUFFERS > 1. --- cpu/avr/radio/rf230bb/rf230bb.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/cpu/avr/radio/rf230bb/rf230bb.c b/cpu/avr/radio/rf230bb/rf230bb.c index aee2f6d29..c85608e09 100644 --- a/cpu/avr/radio/rf230bb/rf230bb.c +++ b/cpu/avr/radio/rf230bb/rf230bb.c @@ -552,7 +552,19 @@ rf230_is_ready_to_send() { static void flushrx(void) { + /* Clear the length field to allow buffering of the next packet */ rxframe[rxframe_head].length=0; + rxframe_head++; + if (rxframe_head >= RF230_CONF_RX_BUFFERS) { + rxframe_head=0; + } + /* If another packet has been buffered, schedule another receive poll */ + if (rxframe[rxframe_head].length) { + rf230_interrupt(); + } + else { + rf230_pending = 0; + } } /*---------------------------------------------------------------------------*/ static void @@ -1434,6 +1446,7 @@ rf230_read(void *buf, unsigned short bufsize) #if RADIOALWAYSON && DEBUGFLOWSIZE if (RF230_receive_on==0) {if (debugflow[debugflowsize-1]!='z') DEBUGFLOW('z');} //cxmac calls with radio off? #endif + flushrx(); return 0; } @@ -1476,19 +1489,8 @@ rf230_read(void *buf, unsigned short bufsize) memcpy(buf,framep,len-AUX_LEN+CHECKSUM_LEN); rf230_last_correlation = rxframe[rxframe_head].lqi; - /* Clear the length field to allow buffering of the next packet */ - rxframe[rxframe_head].length=0; - rxframe_head++; - if (rxframe_head >= RF230_CONF_RX_BUFFERS) { - rxframe_head=0; - } - /* If another packet has been buffered, schedule another receive poll */ - if (rxframe[rxframe_head].length) { - rf230_interrupt(); - } - else { - rf230_pending = 0; - } + /* Prepare to receive another packet */ + flushrx(); /* Point to the checksum */ framep+=len-AUX_LEN;