TSCH: allow to configure channel scanning duration during the join phase

This commit is contained in:
Atis Elsts 2016-06-06 23:12:09 +03:00
parent b57009e564
commit fbb66f9cd5
2 changed files with 14 additions and 6 deletions

View File

@ -191,4 +191,11 @@
#define TSCH_RADIO_ON_DURING_TIMESLOT 0 #define TSCH_RADIO_ON_DURING_TIMESLOT 0
#endif #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__ */ #endif /* __TSCH_CONF_H__ */

View File

@ -609,24 +609,25 @@ PT_THREAD(tsch_scan(struct pt *pt))
static struct input_packet input_eb; static struct input_packet input_eb;
static struct etimer scan_timer; 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); ASN_INIT(current_asn, 0, 0);
etimer_set(&scan_timer, CLOCK_SECOND / TSCH_ASSOCIATION_POLL_FREQUENCY); etimer_set(&scan_timer, CLOCK_SECOND / TSCH_ASSOCIATION_POLL_FREQUENCY);
current_channel_since = clock_time();
while(!tsch_is_associated && !tsch_is_coordinator) { while(!tsch_is_associated && !tsch_is_coordinator) {
/* Hop to any channel offset */ /* Hop to any channel offset */
static int current_channel = 0; static uint8_t current_channel = 0;
/* Time when we started scanning on current_channel */
static clock_time_t current_channel_since = 0;
/* We are not coordinator, try to associate */ /* We are not coordinator, try to associate */
rtimer_clock_t t0; rtimer_clock_t t0;
int is_packet_pending = 0; 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 */ /* 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 */ /* Pick a channel at random in TSCH_JOIN_HOPPING_SEQUENCE */
uint8_t scan_channel = TSCH_JOIN_HOPPING_SEQUENCE[ uint8_t scan_channel = TSCH_JOIN_HOPPING_SEQUENCE[
random_rand() % sizeof(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; current_channel = scan_channel;
PRINTF("TSCH: scanning on channel %u\n", 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 */ /* Turn radio on and wait for EB */