1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 22:13:52 +01:00

boards/xx/driver_cc2420: fix race condition in CCA determination

Ensure that CS is active and IRQ disabled when querying CCA
on CC2420 (cc2420_get_cca() function).
Also do a little refactoring (renamed c variable into count,
and named the constant corresponding to RSSI "timeout").
This commit is contained in:
Kévin Roussel 2014-07-08 16:03:37 +02:00
parent 65e240f950
commit bee4698158
3 changed files with 27 additions and 6 deletions

View File

@ -17,6 +17,7 @@
#include "cc2420.h"
#include "cc2420_arch.h"
#include "cc2420_spi.h"
#define ENABLE_DEBUG (1)
#include "debug.h"
@ -106,14 +107,21 @@ uint8_t cc2420_get_sfd(void)
return CC2420_SFD;
}
#define MAX_RSSI_WAIT 1000
uint8_t cc2420_get_cca(void)
{
uint8_t status;
long c = 0;
long count = 0;
do {
unsigned int sr = disableIRQ();
cc2420_spi_select();
status = cc2420_txrx(NOBYTE);
if (c++ == 1000000) {
core_panic(0x2420, "cc2420_get_cca() alarm");
cc2420_spi_unselect();
restoreIRQ(sr);
count++;
if (count >= MAX_RSSI_WAIT) {
core_panic(0x2420, "cc2420_get_cca(): RSSI never valid!");
}
} while (!(status & CC2420_STATUS_RSSI_VALID));
return CC2420_GIO1;

View File

@ -17,6 +17,7 @@
#include "cc2420.h"
#include "cc2420_arch.h"
#include "cc2420_spi.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
@ -109,14 +110,21 @@ uint8_t cc2420_get_fifop(void)
return CC2420_GDO2;
}
#define MAX_RSSI_WAIT 1000
uint8_t cc2420_get_cca(void)
{
uint8_t status;
long c = 0;
long count = 0;
do {
unsigned int sr = disableIRQ();
cc2420_spi_select();
status = cc2420_txrx(NOBYTE);
if (c++ == 1000000) {
core_panic(0x2420, "cc2420_get_cca() alarm");
cc2420_spi_unselect();
restoreIRQ(sr);
count++;
if (count >= MAX_RSSI_WAIT) {
core_panic(0x2420, "cc2420_get_cca(): RSSI never valid!");
}
} while (!(status & CC2420_STATUS_RSSI_VALID));
return CC2420_CCA;

View File

@ -32,6 +32,7 @@
#include "cc2420.h"
#include "cc2420_arch.h"
#include "cc2420_spi.h"
#define ENABLE_DEBUG (1)
#include "debug.h"
@ -128,7 +129,11 @@ uint8_t cc2420_get_cca(void)
uint8_t status;
long count = 0;
do {
unsigned int sr = disableIRQ();
cc2420_spi_select();
status = cc2420_txrx(NOBYTE);
cc2420_spi_unselect();
restoreIRQ(sr);
count++;
if (count >= MAX_RSSI_WAIT) {
core_panic(0x2420, "cc2420_get_cca(): RSSI never valid!");