From b2eba53df9c1cd67e9203847770a4aa1000b22fa Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Fri, 23 Feb 2018 14:15:36 +0000 Subject: [PATCH 1/5] TSCH: fix a bug in tsch_schedule_slot_operation scheduling --- os/net/mac/tsch/tsch-slot-operation.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index 3596b913c..607b552fe 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -297,15 +297,16 @@ tsch_schedule_slot_operation(struct rtimer *tm, rtimer_clock_t ref_time, rtimer_ "!dl-miss %s %d %d", str, (int)(now-ref_time), (int)offset); ); + } else { + r = rtimer_set(tm, ref_time + offset, 1, (void (*)(struct rtimer *, void *))tsch_slot_operation, NULL); + if(r == RTIMER_OK) { + return 1; + } + } - return 0; - } - ref_time += offset; - r = rtimer_set(tm, ref_time, 1, (void (*)(struct rtimer *, void *))tsch_slot_operation, NULL); - if(r != RTIMER_OK) { - return 0; - } - return 1; + /* block until the time to schedule comes */ + BUSYWAIT_UNTIL_ABS(0, ref_time, offset); + return 0; } /*---------------------------------------------------------------------------*/ /* Schedule slot operation conditionally, and YIELD if success only. @@ -315,8 +316,8 @@ tsch_schedule_slot_operation(struct rtimer *tm, rtimer_clock_t ref_time, rtimer_ do { \ if(tsch_schedule_slot_operation(tm, ref_time, offset - RTIMER_GUARD, str)) { \ PT_YIELD(pt); \ + BUSYWAIT_UNTIL_ABS(0, ref_time, offset); \ } \ - BUSYWAIT_UNTIL_ABS(0, ref_time, offset); \ } while(0); /*---------------------------------------------------------------------------*/ /* Get EB, broadcast or unicast packet to be sent, and target neighbor. */ @@ -1010,12 +1011,12 @@ PT_THREAD(tsch_slot_operation(struct rtimer *t, void *ptr)) TSCH_ASN_INC(tsch_current_asn, timeslot_diff); /* Time to next wake up */ time_to_next_active_slot = timeslot_diff * tsch_timing[tsch_ts_timeslot_length] + drift_correction; + time_to_next_active_slot += tsch_timesync_adaptive_compensate(time_to_next_active_slot); drift_correction = 0; is_drift_correction_used = 0; /* Update current slot start */ prev_slot_start = current_slot_start; current_slot_start += time_to_next_active_slot; - current_slot_start += tsch_timesync_adaptive_compensate(time_to_next_active_slot); } while(!tsch_schedule_slot_operation(t, prev_slot_start, time_to_next_active_slot, "main")); } From 61880704b1818600c56d96ddd85323e23b9bcb8f Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sat, 24 Feb 2018 15:32:36 -0800 Subject: [PATCH 2/5] CSMA: adopt default values from IEEE for CSMA_MIN_BE and CSMA_MAX_BE --- os/net/mac/csma/csma-output.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 0bbc34fb0..65403324e 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -66,14 +66,14 @@ #ifdef CSMA_CONF_MIN_BE #define CSMA_MIN_BE CSMA_CONF_MIN_BE #else -#define CSMA_MIN_BE 0 +#define CSMA_MIN_BE 3 #endif /* macMaxBE: Maximum backoff exponent. Range 3--8 */ #ifdef CSMA_CONF_MAX_BE #define CSMA_MAX_BE CSMA_CONF_MAX_BE #else -#define CSMA_MAX_BE 4 +#define CSMA_MAX_BE 5 #endif /* macMaxCSMABackoffs: Maximum number of backoffs in case of channel busy/collision. Range 0--5 */ @@ -281,7 +281,7 @@ schedule_transmission(struct neighbor_queue *n) clock_time_t delay; int backoff_exponent; /* BE in IEEE 802.15.4 */ - backoff_exponent = MIN(n->collisions, CSMA_MAX_BE); + backoff_exponent = MIN(n->collisions + CSMA_MIN_BE, CSMA_MAX_BE); /* Compute max delay as per IEEE 802.15.4: 2^BE-1 backoff periods */ delay = ((1 << backoff_exponent) - 1) * backoff_period(); @@ -310,7 +310,7 @@ free_packet(struct neighbor_queue *n, struct packet_queue *p, int status) if(list_head(n->packet_queue) != NULL) { /* There is a next packet. We reset current tx information */ n->transmissions = 0; - n->collisions = CSMA_MIN_BE; + n->collisions = 0; /* Schedule next transmissions */ schedule_transmission(n); } else { @@ -365,7 +365,7 @@ collision(struct packet_queue *q, struct neighbor_queue *n, n->collisions += num_transmissions; if(n->collisions > CSMA_MAX_BACKOFF) { - n->collisions = CSMA_MIN_BE; + n->collisions = 0; /* Increment to indicate a next retry */ n->transmissions++; } @@ -384,7 +384,7 @@ noack(struct packet_queue *q, struct neighbor_queue *n, int num_transmissions) metadata = (struct qbuf_metadata *)q->ptr; - n->collisions = CSMA_MIN_BE; + n->collisions = 0; n->transmissions += num_transmissions; if(n->transmissions >= metadata->max_transmissions) { From d526323ce24a5dfb63c369aa0caa4ebb6f951792 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sat, 24 Feb 2018 15:35:58 -0800 Subject: [PATCH 3/5] CSMA for Cooja motes: increase backoff_period --- os/net/mac/csma/csma-output.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 65403324e..74803ecf1 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -154,9 +154,15 @@ neighbor_queue_from_addr(const linkaddr_t *addr) static clock_time_t backoff_period(void) { +#if CONTIKI_TARGET_COOJA + /* Increase normal value by 20 to compensate for the coarse-grained + radio medium with Cooja motes */ + return MAX(20 * CLOCK_SECOND / 3125, 1); +#else /* CONTIKI_TARGET_COOJA */ /* Use the default in IEEE 802.15.4: aUnitBackoffPeriod which is * 20 symbols i.e. 320 usec. That is, 1/3125 second. */ return MAX(CLOCK_SECOND / 3125, 1); +#endif /* CONTIKI_TARGET_COOJA */ } /*---------------------------------------------------------------------------*/ static int From b2148b87650e09cb12796ca68ba9b185737e5402 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 2 Mar 2018 02:42:11 -0800 Subject: [PATCH 4/5] Remove uses of obsolete flag CONTIKI_TARGET_COOJA_IP64 --- os/net/mac/tsch/tsch-private.h | 8 ++++---- os/net/mac/tsch/tsch-slot-operation.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/os/net/mac/tsch/tsch-private.h b/os/net/mac/tsch/tsch-private.h index fd2d9d42b..fc5559b38 100644 --- a/os/net/mac/tsch/tsch-private.h +++ b/os/net/mac/tsch/tsch-private.h @@ -53,10 +53,10 @@ #include "net/linkaddr.h" #include "net/mac/tsch/tsch-asn.h" #include "net/mac/tsch/tsch-conf.h" -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA #include "lib/simEnvChange.h" #include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */ +#endif /* CONTIKI_TARGET_COOJA */ /************ Types ***********/ @@ -124,7 +124,7 @@ void tsch_disassociate(void); #define TSCH_CLOCK_TO_SLOTS(c, timeslot_length) (TSCH_CLOCK_TO_TICKS(c) / timeslot_length) /* Wait for a condition with timeout t0+offset. */ -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA #define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \ while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) { \ simProcessRunValue = 1; \ @@ -133,6 +133,6 @@ void tsch_disassociate(void); #else #define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \ while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) ; -#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */ +#endif /* CONTIKI_TARGET_COOJA */ #endif /* __TSCH_PRIVATE_H__ */ /** @} */ diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index 3596b913c..d70ed56c4 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -59,10 +59,10 @@ #include "net/mac/tsch/tsch-packet.h" #include "net/mac/tsch/tsch-security.h" #include "net/mac/tsch/tsch-adaptive-timesync.h" -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA #include "lib/simEnvChange.h" #include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */ +#endif /* CONTIKI_TARGET_COOJA */ #include "sys/log.h" /* TSCH debug macros, i.e. to set LEDs or GPIOs on various TSCH @@ -107,7 +107,7 @@ #if RTIMER_SECOND < (32 * 1024) #error "TSCH: RTIMER_SECOND < (32 * 1024)" #endif -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA /* Use 0 usec guard time for Cooja Mote with a 1 MHz Rtimer*/ #define RTIMER_GUARD 0u #elif RTIMER_SECOND >= 200000 @@ -208,10 +208,10 @@ tsch_get_lock(void) busy_wait = 1; busy_wait_time = RTIMER_NOW(); while(tsch_in_slot_operation) { -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA simProcessRunValue = 1; cooja_mt_yield(); -#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */ +#endif /* CONTIKI_TARGET_COOJA */ } busy_wait_time = RTIMER_NOW() - busy_wait_time; } From aaa8658e8daedcd035e8fae969362ad3b67a36b6 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 2 Mar 2018 04:14:23 -0800 Subject: [PATCH 5/5] tsch-log: fixed alignement of the log fields --- os/net/mac/tsch/tsch-log.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/os/net/mac/tsch/tsch-log.c b/os/net/mac/tsch/tsch-log.c index 54fca2710..fdaaf3b53 100644 --- a/os/net/mac/tsch/tsch-log.c +++ b/os/net/mac/tsch/tsch-log.c @@ -85,10 +85,10 @@ tsch_log_process_pending(void) while((log_index = ringbufindex_peek_get(&log_ringbuf)) != -1) { struct tsch_log_t *log = &log_array[log_index]; if(log->link == NULL) { - printf("[INFO: TSCH-LOG ] {asn-%x.%lx link-NULL} ", log->asn.ms1b, log->asn.ls4b); + printf("[INFO: TSCH-LOG ] {asn %02x.%08lx link-NULL} ", log->asn.ms1b, log->asn.ls4b); } else { struct tsch_slotframe *sf = tsch_schedule_get_slotframe_by_handle(log->link->slotframe_handle); - printf("[INFO: TSCH-LOG ] {asn-%x.%lx link-%u-%u-%u-%u ch-%u} ", + printf("[INFO: TSCH-LOG ] {asn %02x.%08lx link %2u %3u %3u %2u ch %2u} ", log->asn.ms1b, log->asn.ls4b, log->link->slotframe_handle, sf ? sf->size.val : 0, log->link->timeslot, log->link->channel_offset, tsch_calculate_channel(&log->asn, log->link->channel_offset)); @@ -100,10 +100,10 @@ tsch_log_process_pending(void) log_lladdr_compact(&linkaddr_node_addr); printf("->"); log_lladdr_compact(&log->tx.dest); - printf(", len %u, seq %u, st %d %d", + printf(", len %3u, seq %3u, st %d %2d", log->tx.datalen, log->tx.seqno, log->tx.mac_tx_status, log->tx.num_tx); if(log->tx.drift_used) { - printf(", dr %d", log->tx.drift); + printf(", dr %3d", log->tx.drift); } printf("\n"); break; @@ -113,12 +113,14 @@ tsch_log_process_pending(void) log_lladdr_compact(&log->rx.src); printf("->"); log_lladdr_compact(log->rx.is_unicast ? &linkaddr_node_addr : NULL); - printf(", len %u, seq %u", + printf(", len %3u, seq %3u", log->rx.datalen, log->rx.seqno); + printf(", edr %3d", (int)log->rx.estimated_drift); if(log->rx.drift_used) { - printf(", dr %d", log->rx.drift); + printf(", dr %3d\n", log->rx.drift); + } else { + printf("\n"); } - printf(", edr %d\n", log->rx.estimated_drift); break; case tsch_log_message: printf("%s\n", log->message);