Merge branch 'develop' into contrib/generic-leds
This commit is contained in:
commit
c1d9be1d01
@ -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 */
|
||||
@ -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
|
||||
@ -281,7 +287,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 +316,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 +371,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 +390,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) {
|
||||
|
@ -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);
|
||||
|
@ -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__ */
|
||||
/** @} */
|
||||
|
@ -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;
|
||||
}
|
||||
@ -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"));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user