Back off a guard time for every non-ack packet

This commit is contained in:
adamdunkels 2010-03-29 21:50:01 +00:00
parent 1241aa34d0
commit b4b7e942b6

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: phase.c,v 1.4 2010/03/14 22:59:23 adamdunkels Exp $ * $Id: phase.c,v 1.5 2010/03/29 21:50:01 adamdunkels Exp $
*/ */
/** /**
@ -81,7 +81,9 @@ phase_update(const struct phase_list *list,
/* If we have an entry for this neighbor already, we renew it. */ /* If we have an entry for this neighbor already, we renew it. */
for(e = list_head(*list->list); e != NULL; e = e->next) { for(e = list_head(*list->list); e != NULL; e = e->next) {
if(rimeaddr_cmp(neighbor, &e->neighbor)) { if(rimeaddr_cmp(neighbor, &e->neighbor)) {
if(mac_status == MAC_TX_OK) {
e->time = time; e->time = time;
}
/* If the neighbor didn't reply to us, it may have switched /* If the neighbor didn't reply to us, it may have switched
phase (rebooted). We try a number of transmissions to it phase (rebooted). We try a number of transmissions to it
@ -139,10 +141,10 @@ phase_wait(struct phase_list *list,
{ {
struct phase *e; struct phase *e;
/* We go through the list of phases to find if we have recorded /* We go through the list of phases to find if we have recorded a
an phase with this particular neighbor. If so, we can compute phase for this particular neighbor. If so, we can compute the
the time for the next expected phase and setup a ctimer to time for the next expected phase and setup a ctimer to switch on
switch on the radio just before the phase. */ the radio just before the phase. */
for(e = list_head(*list->list); e != NULL; e = e->next) { for(e = list_head(*list->list); e != NULL; e = e->next) {
const rimeaddr_t *neighbor = packetbuf_addr(PACKETBUF_ADDR_RECEIVER); const rimeaddr_t *neighbor = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
@ -157,8 +159,10 @@ phase_wait(struct phase_list *list,
on the radio within the CYCLE_TIME period, we compute the on the radio within the CYCLE_TIME period, we compute the
waiting time with modulo CYCLE_TIME. */ waiting time with modulo CYCLE_TIME. */
/* printf("neighbor phase 0x%02x (cycle 0x%02x)\n", e->time & (cycle_time - 1),
cycle_time);*/
now = RTIMER_NOW(); now = RTIMER_NOW();
wait = (rtimer_clock_t)((e->time - now) & (cycle_time - 1)); wait = (rtimer_clock_t)((e->time - now - e->noacks * cycle_time) & (cycle_time - 1));
if(wait < wait_before) { if(wait < wait_before) {
wait += cycle_time; wait += cycle_time;
} }
@ -186,7 +190,6 @@ phase_wait(struct phase_list *list,
if(!RTIMER_CLOCK_LT(expected, now)) { if(!RTIMER_CLOCK_LT(expected, now)) {
/* Wait until the receiver is expected to be awake */ /* Wait until the receiver is expected to be awake */
while(RTIMER_CLOCK_LT(RTIMER_NOW(), expected)) { while(RTIMER_CLOCK_LT(RTIMER_NOW(), expected)) {
watchdog_periodic();
} }
} }
return PHASE_SEND_NOW; return PHASE_SEND_NOW;