* Changed implementation for dealing with retransmissions to be
strictly event driven. The old implementation was rather process like and the new one is still implemented as a process.
This commit is contained in:
parent
f528ff9fe2
commit
81b684414d
1 changed files with 42 additions and 50 deletions
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: cc2420.c,v 1.17 2007/05/21 14:24:51 bg- Exp $
|
* @(#)$Id: cc2420.c,v 1.18 2007/05/31 10:15:57 bg- Exp $
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* This code is almost device independent and should be easy to port.
|
* This code is almost device independent and should be easy to port.
|
||||||
|
@ -196,7 +196,7 @@ cc2420_send(struct hdr_802_15 *hdr, u8_t hdr_len,
|
||||||
const u8_t *payload, u8_t payload_len)
|
const u8_t *payload, u8_t payload_len)
|
||||||
{
|
{
|
||||||
u8_t spiStatusByte;
|
u8_t spiStatusByte;
|
||||||
int s, ret;
|
int s;
|
||||||
|
|
||||||
/* struct hdr_802_15::len shall *not* be counted, thus the -1.
|
/* struct hdr_802_15::len shall *not* be counted, thus the -1.
|
||||||
* 2 == sizeof(footer).
|
* 2 == sizeof(footer).
|
||||||
|
@ -231,14 +231,8 @@ cc2420_send(struct hdr_802_15 *hdr, u8_t hdr_len,
|
||||||
FASTSPI_WRITE_FIFO(payload, payload_len);
|
FASTSPI_WRITE_FIFO(payload, payload_len);
|
||||||
splx(s);
|
splx(s);
|
||||||
|
|
||||||
ret = cc2420_resend(); /* Send stuff from FIFO. */
|
/* Send stuff from FIFO now! */
|
||||||
if (hdr->dst == 0xffff && ret == UIP_FW_OK) {
|
process_post_synch(&cc2420_retransmit_process, PROCESS_EVENT_MSG, NULL);
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
process_post(&cc2420_retransmit_process,
|
|
||||||
PROCESS_EVENT_MSG,
|
|
||||||
(void *)(unsigned)last_used_seq);
|
|
||||||
|
|
||||||
return UIP_FW_OK;
|
return UIP_FW_OK;
|
||||||
}
|
}
|
||||||
|
@ -510,52 +504,50 @@ unsigned neigbour_find(u16_t mac);
|
||||||
|
|
||||||
PROCESS_THREAD(cc2420_retransmit_process, ev, data)
|
PROCESS_THREAD(cc2420_retransmit_process, ev, data)
|
||||||
{
|
{
|
||||||
static u8_t seq, n;
|
static char n;
|
||||||
static struct etimer etimer;
|
static struct etimer etimer;
|
||||||
|
|
||||||
PROCESS_BEGIN();
|
switch (ev) {
|
||||||
|
default:
|
||||||
|
case PROCESS_EVENT_INIT:
|
||||||
|
return PT_WAITING;
|
||||||
|
|
||||||
while (1) {
|
case PROCESS_EVENT_EXIT:
|
||||||
PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_MSG);
|
return PT_ENDED;
|
||||||
seq = (unsigned)data;
|
|
||||||
|
|
||||||
n = 0;
|
case PROCESS_EVENT_POLL: /* Cancel future retransmissions. */
|
||||||
do {
|
etimer_stop(&etimer);
|
||||||
etimer_set(&etimer, RETRANSMIT_TIMEOUT);
|
|
||||||
PROCESS_WAIT_UNTIL(etimer_expired(&etimer) || ev == PROCESS_EVENT_POLL);
|
|
||||||
if (ev == PROCESS_EVENT_POLL) {
|
|
||||||
etimer_stop(&etimer);
|
|
||||||
break;
|
|
||||||
} else if (seq != last_used_seq)
|
|
||||||
break; /* Transmitting different packet. */
|
|
||||||
else if (last_dst == 0xffff) {
|
|
||||||
n++;
|
|
||||||
if (cc2420_resend() == UIP_FW_OK) {
|
|
||||||
PRINTF("REBCAST %d\n", n);
|
|
||||||
etimer_stop(&etimer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (n < MAX_RETRANSMISSIONS) {
|
|
||||||
if (cc2420_resend() == UIP_FW_OK) {
|
|
||||||
n++;
|
|
||||||
PRINTF("RETRANS %d to %d.%d\n", n, last_dst & 0xff, last_dst >> 8);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (1);
|
|
||||||
neigbour_update(last_dst, n);
|
neigbour_update(last_dst, n);
|
||||||
#if 0
|
return PT_WAITING;
|
||||||
#define CORRELATION_2_X(c) (((c) < 48) ? 0 : ((c) - 48))
|
|
||||||
PRINTF("%04x %2d %2d %2u %u\n",
|
|
||||||
last_dst, n,
|
|
||||||
RSSI_2_ED(cc2420_last_rssi),
|
|
||||||
CORRELATION_2_X(cc2420_last_correlation),
|
|
||||||
clock_time());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
PROCESS_END();
|
case PROCESS_EVENT_MSG: /* Send new packet. */
|
||||||
|
n = -1;
|
||||||
|
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
case PROCESS_EVENT_TIMER:
|
||||||
|
if (last_dst == 0xffff) {
|
||||||
|
n++;
|
||||||
|
if (cc2420_resend() == UIP_FW_OK) {
|
||||||
|
PRINTF("REBCAST %d\n", n);
|
||||||
|
return PT_WAITING; /* Final transmission attempt. */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (cc2420_resend() == UIP_FW_OK) {
|
||||||
|
n++;
|
||||||
|
PRINTF("RETRANS %d to %d.%d\n", n, last_dst & 0xff, last_dst >> 8);
|
||||||
|
}
|
||||||
|
if (n == MAX_RETRANSMISSIONS) {
|
||||||
|
neigbour_update(last_dst, n);
|
||||||
|
return PT_WAITING; /* Final transmission attempt. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Schedule retransmission.
|
||||||
|
*/
|
||||||
|
etimer_set(&etimer, RETRANSMIT_TIMEOUT);
|
||||||
|
return PT_WAITING;
|
||||||
|
}
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue