CC2420: Eliminated duplicated code in cc2420_read
This commit is contained in:
parent
e3eb924f13
commit
e977da8fe2
|
@ -775,61 +775,47 @@ cc2420_read(void *buf, unsigned short bufsize)
|
||||||
|
|
||||||
if(len > CC2420_MAX_PACKET_LEN) {
|
if(len > CC2420_MAX_PACKET_LEN) {
|
||||||
/* Oops, we must be out of sync. */
|
/* Oops, we must be out of sync. */
|
||||||
flushrx();
|
|
||||||
RIMESTATS_ADD(badsynch);
|
RIMESTATS_ADD(badsynch);
|
||||||
RELEASE_LOCK();
|
} else if(len <= FOOTER_LEN) {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(len <= FOOTER_LEN) {
|
|
||||||
flushrx();
|
|
||||||
RIMESTATS_ADD(tooshort);
|
RIMESTATS_ADD(tooshort);
|
||||||
RELEASE_LOCK();
|
} else if(len - FOOTER_LEN > bufsize) {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(len - FOOTER_LEN > bufsize) {
|
|
||||||
flushrx();
|
|
||||||
RIMESTATS_ADD(toolong);
|
RIMESTATS_ADD(toolong);
|
||||||
RELEASE_LOCK();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
getrxdata(buf, len - FOOTER_LEN);
|
|
||||||
getrxdata(footer, FOOTER_LEN);
|
|
||||||
|
|
||||||
if(footer[1] & FOOTER1_CRC_OK) {
|
|
||||||
cc2420_last_rssi = footer[0];
|
|
||||||
cc2420_last_correlation = footer[1] & FOOTER1_CORRELATION;
|
|
||||||
|
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, cc2420_last_rssi);
|
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, cc2420_last_correlation);
|
|
||||||
|
|
||||||
RIMESTATS_ADD(llrx);
|
|
||||||
} else {
|
} else {
|
||||||
RIMESTATS_ADD(badcrc);
|
getrxdata(buf, len - FOOTER_LEN);
|
||||||
len = FOOTER_LEN;
|
getrxdata(footer, FOOTER_LEN);
|
||||||
}
|
|
||||||
|
if(footer[1] & FOOTER1_CRC_OK) {
|
||||||
if(CC2420_FIFOP_IS_1) {
|
cc2420_last_rssi = footer[0];
|
||||||
if(!CC2420_FIFO_IS_1) {
|
cc2420_last_correlation = footer[1] & FOOTER1_CORRELATION;
|
||||||
/* Clean up in case of FIFO overflow! This happens for every
|
|
||||||
* full length frame and is signaled by FIFOP = 1 and FIFO =
|
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, cc2420_last_rssi);
|
||||||
* 0. */
|
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, cc2420_last_correlation);
|
||||||
flushrx();
|
|
||||||
|
RIMESTATS_ADD(llrx);
|
||||||
} else {
|
} else {
|
||||||
/* Another packet has been received and needs attention. */
|
RIMESTATS_ADD(badcrc);
|
||||||
process_poll(&cc2420_process);
|
len = FOOTER_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(CC2420_FIFOP_IS_1) {
|
||||||
|
if(!CC2420_FIFO_IS_1) {
|
||||||
|
/* Clean up in case of FIFO overflow! This happens for every
|
||||||
|
* full length frame and is signaled by FIFOP = 1 and FIFO =
|
||||||
|
* 0. */
|
||||||
|
flushrx();
|
||||||
|
} else {
|
||||||
|
/* Another packet has been received and needs attention. */
|
||||||
|
process_poll(&cc2420_process);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RELEASE_LOCK();
|
||||||
|
return len - FOOTER_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flushrx();
|
||||||
RELEASE_LOCK();
|
RELEASE_LOCK();
|
||||||
|
return 0;
|
||||||
if(len < FOOTER_LEN) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return len - FOOTER_LEN;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue