From f0891be21833833bc48e3aca7bfb9e4fce67fc96 Mon Sep 17 00:00:00 2001 From: nvt-se Date: Thu, 20 Dec 2007 14:44:31 +0000 Subject: [PATCH] added clear channel assessment timeout. long to begin with. --- platform/msb430/contiki-conf.h | 5 +++-- platform/msb430/dev/cc1020.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/platform/msb430/contiki-conf.h b/platform/msb430/contiki-conf.h index 3bf86c7e6..332dd980b 100644 --- a/platform/msb430/contiki-conf.h +++ b/platform/msb430/contiki-conf.h @@ -24,14 +24,15 @@ #define CC_CONF_REGISTER_ARGS 1 #define CC_CONF_FUNCTION_POINTER_ARGS 1 - #define CC_CONF_INLINE inline - #define CC_CONF_VA_ARGS 1 #define CCIF #define CLIF +/* Clear channel assessment timeout for sending with the CC1020 radio. (ms) */ +#define CC1020_CONF_CCA_TIMEOUT 50 + // Clock typedef unsigned short clock_time_t; #define CLOCK_CONF_SECOND 100 diff --git a/platform/msb430/dev/cc1020.c b/platform/msb430/dev/cc1020.c index 28f967c1e..675e0a7a5 100644 --- a/platform/msb430/dev/cc1020.c +++ b/platform/msb430/dev/cc1020.c @@ -214,6 +214,8 @@ cc1020_set_power(uint8_t pa_power) int cc1020_send(const void *buf, unsigned short len) { + int try; + if (cc1020_state == CC1020_OFF) return -2; @@ -237,7 +239,15 @@ cc1020_send(const void *buf, unsigned short len) // Wait for the medium to become idle. if (cc1020_carrier_sense()) { - while (cc1020_carrier_sense()); + for (try = 0; try < CC1020_CONF_CCA_TIMEOUT; try++) { + MS_DELAY(1); + if (!cc1020_carrier_sense()) { + break; + } + } + if (try == CC1020_CONF_CCA_TIMEOUT) { + return -3; + } // Then wait for a short pseudo-random time before sending. clock_delay(100 * ((random_rand() + 1) & 0xf));