From c67c048cac9a0120ecf386146a1a0578951e7da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Thu, 7 Nov 2013 15:17:38 +0100 Subject: [PATCH] Clean up setting channel and CCA-threshold for CC2420 based motes. The CCA-threshold now defaults to -46 which give better simulation results and typically also better experimental results. This adjustment is also needed due to commit 0a13f99 in mspsim. As promised in https://github.com/mspsim/mspsim/pull/18 it broke the regression tests. --- core/dev/cc2420.c | 12 +++++++++++- platform/exp5438/contiki-conf.h | 14 +++++++++++--- platform/exp5438/contiki-exp5438-main.c | 10 ++-------- platform/micaz/contiki-conf.h | 14 +++++++++++--- platform/micaz/init-net.c | 8 +++----- platform/sky/contiki-conf.h | 14 +++++++++++--- platform/sky/contiki-sky-main.c | 15 ++++++--------- platform/z1/contiki-conf.h | 14 +++++++++++--- platform/z1/contiki-z1-main.c | 11 +++-------- 9 files changed, 69 insertions(+), 43 deletions(-) diff --git a/core/dev/cc2420.c b/core/dev/cc2420.c index 3e6857215..4816650f6 100644 --- a/core/dev/cc2420.c +++ b/core/dev/cc2420.c @@ -60,6 +60,15 @@ #define CC2420_CONF_CHECKSUM 0 #endif /* CC2420_CONF_CHECKSUM */ +#ifndef CC2420_CONF_CHANNEL +#define CC2420_CONF_CHANNEL 26 +#endif /* CC2420_CONF_CHANNEL */ + +#ifndef CC2420_CONF_CCA_THRESH +#define CC2420_CONF_CCA_THRESH -45 +#endif /* CC2420_CONF_CCA_THRESH */ + + #ifndef CC2420_CONF_AUTOACK #define CC2420_CONF_AUTOACK 0 #endif /* CC2420_CONF_AUTOACK */ @@ -331,7 +340,8 @@ cc2420_init(void) setreg(CC2420_SECCTRL0, reg); cc2420_set_pan_addr(0xffff, 0x0000, NULL); - cc2420_set_channel(26); + cc2420_set_channel(CC2420_CONF_CHANNEL); + cc2420_set_cca_threshold(CC2420_CONF_CCA_THRESH); flushrx(); diff --git a/platform/exp5438/contiki-conf.h b/platform/exp5438/contiki-conf.h index fc7eb8133..b7058450c 100644 --- a/platform/exp5438/contiki-conf.h +++ b/platform/exp5438/contiki-conf.h @@ -90,9 +90,17 @@ #define PACKETBUF_CONF_ATTRS_INLINE 1 -#ifndef RF_CHANNEL -#define RF_CHANNEL 26 -#endif /* RF_CHANNEL */ +#ifdef RF_CHANNEL +#define CC2420_CONF_CHANNEL RF_CHANNEL +#endif + +#ifndef CC2420_CONF_CHANNEL +#define CC2420_CONF_CHANNEL 26 +#endif /* CC2420_CONF_CHANNEL */ + +#ifndef CC2420_CONF_CCA_THRESH +#define CC2420_CONF_CCA_THRESH -45 +#endif /* CC2420_CONF_CCA_THRESH */ #define CONTIKIMAC_CONF_BROADCAST_RATE_LIMIT 0 diff --git a/platform/exp5438/contiki-exp5438-main.c b/platform/exp5438/contiki-exp5438-main.c index 662243444..59ced9328 100644 --- a/platform/exp5438/contiki-exp5438-main.c +++ b/platform/exp5438/contiki-exp5438-main.c @@ -71,10 +71,6 @@ extern unsigned char node_mac[8]; //SENSORS(&button_sensor); /*---------------------------------------------------------------------------*/ -#ifndef RF_CHANNEL -#define RF_CHANNEL 26 -#endif -/*---------------------------------------------------------------------------*/ static void set_rime_addr(void) { @@ -200,8 +196,6 @@ main(int argc, char **argv) cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } - cc2420_set_channel(RF_CHANNEL); - leds_off(LEDS_ALL); if(node_id > 0) { @@ -224,7 +218,7 @@ main(int argc, char **argv) NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), - RF_CHANNEL); + CC2420_CONF_CHANNEL); process_start(&tcpip_process, NULL); @@ -265,7 +259,7 @@ main(int argc, char **argv) NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), - RF_CHANNEL); + CC2420_CONF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP6 diff --git a/platform/micaz/contiki-conf.h b/platform/micaz/contiki-conf.h index b4aadf206..e12140445 100644 --- a/platform/micaz/contiki-conf.h +++ b/platform/micaz/contiki-conf.h @@ -90,9 +90,17 @@ #define PACKETBUF_CONF_ATTRS_INLINE 1 -#ifndef RF_CHANNEL -#define RF_CHANNEL 26 -#endif /* RF_CHANNEL */ +#ifdef RF_CHANNEL +#define CC2420_CONF_CHANNEL RF_CHANNEL +#endif + +#ifndef CC2420_CONF_CHANNEL +#define CC2420_CONF_CHANNEL 26 +#endif /* CC2420_CONF_CHANNEL */ + +#ifndef CC2420_CONF_CCA_THRESH +#define CC2420_CONF_CCA_THRESH -45 +#endif /* CC2420_CONF_CCA_THRESH */ #define CONTIKIMAC_CONF_BROADCAST_RATE_LIMIT 0 diff --git a/platform/micaz/init-net.c b/platform/micaz/init-net.c index 4bfebd1c4..6e67c43ae 100644 --- a/platform/micaz/init-net.c +++ b/platform/micaz/init-net.c @@ -139,14 +139,12 @@ init_net(void) cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } - cc2420_set_channel(RF_CHANNEL); - #if WITH_UIP6 memcpy(&uip_lladdr.addr, ds2401_id, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */ - /* printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */ + /* printf(" %s channel %u\n", sicslowmac_driver.name, CC2420_CONF_CHANNEL); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); @@ -158,7 +156,7 @@ init_net(void) NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), - RF_CHANNEL); + CC2420_CONF_CHANNEL); process_start(&tcpip_process, NULL); @@ -199,7 +197,7 @@ init_net(void) NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), - RF_CHANNEL); + CC2420_CONF_CHANNEL); #endif /* WITH_UIP6 */ diff --git a/platform/sky/contiki-conf.h b/platform/sky/contiki-conf.h index b151f9c51..402164e9c 100644 --- a/platform/sky/contiki-conf.h +++ b/platform/sky/contiki-conf.h @@ -90,9 +90,17 @@ #define PACKETBUF_CONF_ATTRS_INLINE 1 -#ifndef RF_CHANNEL -#define RF_CHANNEL 26 -#endif /* RF_CHANNEL */ +#ifdef RF_CHANNEL +#define CC2420_CONF_CHANNEL RF_CHANNEL +#endif + +#ifndef CC2420_CONF_CHANNEL +#define CC2420_CONF_CHANNEL 26 +#endif /* CC2420_CONF_CHANNEL */ + +#ifndef CC2420_CONF_CCA_THRESH +#define CC2420_CONF_CCA_THRESH -45 +#endif /* CC2420_CONF_CCA_THRESH */ #define CONTIKIMAC_CONF_BROADCAST_RATE_LIMIT 0 diff --git a/platform/sky/contiki-sky-main.c b/platform/sky/contiki-sky-main.c index ad042b588..361d47878 100644 --- a/platform/sky/contiki-sky-main.c +++ b/platform/sky/contiki-sky-main.c @@ -115,10 +115,7 @@ force_float_inclusion() #endif /*---------------------------------------------------------------------------*/ void uip_log(char *msg) { puts(msg); } -/*---------------------------------------------------------------------------*/ -#ifndef RF_CHANNEL -#define RF_CHANNEL 26 -#endif + /*---------------------------------------------------------------------------*/ #if 0 void @@ -272,7 +269,6 @@ main(int argc, char **argv) cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } - cc2420_set_channel(RF_CHANNEL); printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { @@ -289,7 +285,7 @@ main(int argc, char **argv) memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */ -/* printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */ +/* printf(" %s channel %u\n", sicslowmac_driver.name, CC2420_CONF_CCA_THRESH); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); @@ -297,11 +293,12 @@ main(int argc, char **argv) NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); - printf("%s %s, channel check rate %lu Hz, radio channel %u\n", + printf("%s %s, channel check rate %lu Hz, radio channel %u, CCA threshold %i\n", NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), - RF_CHANNEL); + CC2420_CONF_CHANNEL, + CC2420_CONF_CCA_THRESH); process_start(&tcpip_process, NULL); @@ -342,7 +339,7 @@ main(int argc, char **argv) NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), - RF_CHANNEL); + CC2420_CONF_CCA_THRESH); #endif /* WITH_UIP6 */ #if !WITH_UIP && !WITH_UIP6 diff --git a/platform/z1/contiki-conf.h b/platform/z1/contiki-conf.h index b5a9d57b2..1a00b0df0 100644 --- a/platform/z1/contiki-conf.h +++ b/platform/z1/contiki-conf.h @@ -92,9 +92,17 @@ #define PACKETBUF_CONF_ATTRS_INLINE 1 -#ifndef RF_CHANNEL -#define RF_CHANNEL 26 -#endif /* RF_CHANNEL */ +#ifdef RF_CHANNEL +#define CC2420_CONF_CHANNEL RF_CHANNEL +#endif + +#ifndef CC2420_CONF_CHANNEL +#define CC2420_CONF_CHANNEL 26 +#endif /* CC2420_CONF_CHANNEL */ + +#ifndef CC2420_CONF_CCA_THRESH +#define CC2420_CONF_CCA_THRESH -45 +#endif /* CC2420_CONF_CCA_THRESH */ #define IEEE802154_CONF_PANID 0xABCD diff --git a/platform/z1/contiki-z1-main.c b/platform/z1/contiki-z1-main.c index 5e9660216..fafea096a 100644 --- a/platform/z1/contiki-z1-main.c +++ b/platform/z1/contiki-z1-main.c @@ -123,10 +123,6 @@ force_float_inclusion() /*---------------------------------------------------------------------------*/ void uip_log(char *msg) { puts(msg); } /*---------------------------------------------------------------------------*/ -#ifndef RF_CHANNEL -#define RF_CHANNEL 26 -#endif -/*---------------------------------------------------------------------------*/ #if 0 void force_inclusion(int d1, int d2) @@ -289,7 +285,6 @@ main(int argc, char **argv) cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } - cc2420_set_channel(RF_CHANNEL); leds_off(LEDS_ALL); @@ -306,7 +301,7 @@ main(int argc, char **argv) memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */ -/* printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */ +/* printf(" %s channel %u\n", sicslowmac_driver.name, CC2420_CONF_CHANNEL); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); @@ -319,7 +314,7 @@ main(int argc, char **argv) NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), - RF_CHANNEL); + CC2420_CONF_CHANNEL); process_start(&tcpip_process, NULL); @@ -360,7 +355,7 @@ main(int argc, char **argv) NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), - RF_CHANNEL); + CC2420_CONF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP && !WITH_UIP6