From fbb66f9cd5fe15637d11f16c0eb4f6dbcb5b5213 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Mon, 6 Jun 2016 23:12:09 +0300 Subject: [PATCH] TSCH: allow to configure channel scanning duration during the join phase --- core/net/mac/tsch/tsch-conf.h | 7 +++++++ core/net/mac/tsch/tsch.c | 13 +++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/net/mac/tsch/tsch-conf.h b/core/net/mac/tsch/tsch-conf.h index 631f47d03..d8d58f0ff 100644 --- a/core/net/mac/tsch/tsch-conf.h +++ b/core/net/mac/tsch/tsch-conf.h @@ -191,4 +191,11 @@ #define TSCH_RADIO_ON_DURING_TIMESLOT 0 #endif +/* How long to scan each channel in the scanning phase */ +#ifdef TSCH_CONF_CHANNEL_SCAN_DURATION +#define TSCH_CHANNEL_SCAN_DURATION TSCH_CONF_CHANNEL_SCAN_DURATION +#else +#define TSCH_CHANNEL_SCAN_DURATION CLOCK_SECOND +#endif + #endif /* __TSCH_CONF_H__ */ diff --git a/core/net/mac/tsch/tsch.c b/core/net/mac/tsch/tsch.c index de6619dc5..292744ecc 100644 --- a/core/net/mac/tsch/tsch.c +++ b/core/net/mac/tsch/tsch.c @@ -609,24 +609,25 @@ PT_THREAD(tsch_scan(struct pt *pt)) static struct input_packet input_eb; static struct etimer scan_timer; + /* Time when we started scanning on current_channel */ + static clock_time_t current_channel_since; ASN_INIT(current_asn, 0, 0); etimer_set(&scan_timer, CLOCK_SECOND / TSCH_ASSOCIATION_POLL_FREQUENCY); + current_channel_since = clock_time(); while(!tsch_is_associated && !tsch_is_coordinator) { /* Hop to any channel offset */ - static int current_channel = 0; - /* Time when we started scanning on current_channel */ - static clock_time_t current_channel_since = 0; + static uint8_t current_channel = 0; /* We are not coordinator, try to associate */ rtimer_clock_t t0; int is_packet_pending = 0; - clock_time_t now_seconds = clock_seconds(); + clock_time_t now_time = clock_time(); /* Switch to a (new) channel for scanning */ - if(current_channel == 0 || now_seconds != current_channel_since) { + if(current_channel == 0 || now_time - current_channel_since > TSCH_CHANNEL_SCAN_DURATION) { /* Pick a channel at random in TSCH_JOIN_HOPPING_SEQUENCE */ uint8_t scan_channel = TSCH_JOIN_HOPPING_SEQUENCE[ random_rand() % sizeof(TSCH_JOIN_HOPPING_SEQUENCE)]; @@ -635,7 +636,7 @@ PT_THREAD(tsch_scan(struct pt *pt)) current_channel = scan_channel; PRINTF("TSCH: scanning on channel %u\n", scan_channel); } - current_channel_since = now_seconds; + current_channel_since = now_time; } /* Turn radio on and wait for EB */