Made timetable code optional

This commit is contained in:
adamdunkels 2008-01-24 06:17:51 +00:00
parent e7fb51b14c
commit bf8b5c093d

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: xmac.c,v 1.14 2008/01/23 15:00:54 adamdunkels Exp $ * $Id: xmac.c,v 1.15 2008/01/24 06:17:51 adamdunkels Exp $
*/ */
/** /**
@ -56,7 +56,8 @@
#include "net/chameleon/packattr.h" #include "net/chameleon/packattr.h"
#endif #endif
#define WITH_CHANNEL_CHECK 0 /* Seems to work bad */ #define WITH_TIMETABLE 0
#define WITH_CHANNEL_CHECK 0 /* Seems to work bad when enabled */
#define WITH_TIMESYNCH 1 #define WITH_TIMESYNCH 1
#define WITH_RECEIVER 1 #define WITH_RECEIVER 1
#define WITH_QUEUE 0 #define WITH_QUEUE 0
@ -139,8 +140,10 @@ static const struct radio_driver *radio;
static void (* receiver_callback)(const struct mac_driver *); static void (* receiver_callback)(const struct mac_driver *);
#if WITH_TIMETABLE
#define xmac_timetable_size 256 #define xmac_timetable_size 256
TIMETABLE_NONSTATIC(xmac_timetable); TIMETABLE_NONSTATIC(xmac_timetable);
#endif /* WITH_TIMETABLE */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
set_receive_function(void (* recv)(const struct mac_driver *)) set_receive_function(void (* recv)(const struct mac_driver *))
@ -156,7 +159,9 @@ on(void)
radio->on(); radio->on();
LEDS_ON(LEDS_RED); LEDS_ON(LEDS_RED);
CPRINTF("/"); CPRINTF("/");
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "on"); TIMETABLE_TIMESTAMP(xmac_timetable, "on");
#endif
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -166,7 +171,9 @@ off(void)
if(radio_is_on != 0) { if(radio_is_on != 0) {
radio_is_on = 0; radio_is_on = 0;
radio->off(); radio->off();
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "off"); TIMETABLE_TIMESTAMP(xmac_timetable, "off");
#endif
LEDS_OFF(LEDS_RED); LEDS_OFF(LEDS_RED);
CPRINTF("\\"); CPRINTF("\\");
} }
@ -203,7 +210,9 @@ powercycle(struct rtimer *t, void *ptr)
power cycles without having heard a packet, so we turn off power cycles without having heard a packet, so we turn off
the radio. */ the radio. */
waiting_for_packet = 0; waiting_for_packet = 0;
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "off waiting"); TIMETABLE_TIMESTAMP(xmac_timetable, "off waiting");
#endif
off(); off();
} }
} }
@ -263,7 +272,10 @@ send_packet(void)
struct xmac_hdr msg; struct xmac_hdr msg;
int len; int len;
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "send"); TIMETABLE_TIMESTAMP(xmac_timetable, "send");
#endif
#if WITH_CHANNEL_CHECK #if WITH_CHANNEL_CHECK
/* Check if there are other strobes in the air. */ /* Check if there are other strobes in the air. */
waiting_for_packet = 1; waiting_for_packet = 1;
@ -279,7 +291,10 @@ send_packet(void)
while(someone_is_sending); /* {printf("z");}*/ while(someone_is_sending); /* {printf("z");}*/
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "send 2"); TIMETABLE_TIMESTAMP(xmac_timetable, "send 2");
#endif /* WITH_TIMETABLE */
#endif /* WITH_CHANNEL_CHECK */ #endif /* WITH_CHANNEL_CHECK */
/* By setting we_are_sending to one, we ensure that the rtimer /* By setting we_are_sending to one, we ensure that the rtimer
@ -327,7 +342,9 @@ send_packet(void)
rimeaddr_copy(&msg.receiver, &uc_receiver); rimeaddr_copy(&msg.receiver, &uc_receiver);
#endif #endif
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "send strobe"); TIMETABLE_TIMESTAMP(xmac_timetable, "send strobe");
#endif
/* Send the strobe packet. */ /* Send the strobe packet. */
radio->send((const u8_t *)&msg, sizeof(struct xmac_hdr)); radio->send((const u8_t *)&msg, sizeof(struct xmac_hdr));
CPRINTF("+"); CPRINTF("+");
@ -340,7 +357,9 @@ send_packet(void)
CPRINTF("_"); CPRINTF("_");
if(rimeaddr_cmp(&msg.sender, &rimeaddr_node_addr) && if(rimeaddr_cmp(&msg.sender, &rimeaddr_node_addr) &&
rimeaddr_cmp(&msg.receiver, &rimeaddr_node_addr)) { rimeaddr_cmp(&msg.receiver, &rimeaddr_node_addr)) {
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "send ack received"); TIMETABLE_TIMESTAMP(xmac_timetable, "send ack received");
#endif
CPRINTF("@"); CPRINTF("@");
/* We got an ACK from the receiver, so we can immediately send /* We got an ACK from the receiver, so we can immediately send
the packet. */ the packet. */
@ -360,7 +379,9 @@ send_packet(void)
} }
if(got_ack /* XXX && needs_ack */) { if(got_ack /* XXX && needs_ack */) {
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "send got ack"); TIMETABLE_TIMESTAMP(xmac_timetable, "send got ack");
#endif
on(); /* Wait for possible ACK packet */ on(); /* Wait for possible ACK packet */
} else { } else {
on(); /* shell ping don't seem to work with off() here, so we'll on(); /* shell ping don't seem to work with off() here, so we'll
@ -368,7 +389,9 @@ send_packet(void)
} }
if(rimeaddr_cmp(&hdr->receiver, &rimeaddr_null) || got_ack) { if(rimeaddr_cmp(&hdr->receiver, &rimeaddr_null) || got_ack) {
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "send packet"); TIMETABLE_TIMESTAMP(xmac_timetable, "send packet");
#endif
radio->send(rimebuf_hdrptr(), rimebuf_totlen()); radio->send(rimebuf_hdrptr(), rimebuf_totlen());
CPRINTF("#"); CPRINTF("#");
} }
@ -386,7 +409,9 @@ send_packet(void)
/* printf("Strobe %d got_ack %d\n", strobes, got_ack);*/ /* printf("Strobe %d got_ack %d\n", strobes, got_ack);*/
we_are_sending = 0; we_are_sending = 0;
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "send we_are_sending = 0"); TIMETABLE_TIMESTAMP(xmac_timetable, "send we_are_sending = 0");
#endif
LEDS_OFF(LEDS_BLUE); LEDS_OFF(LEDS_BLUE);
return 1; return 1;
@ -462,7 +487,9 @@ read_packet(void)
acknowledge the strobe and wait for the packet. By using acknowledge the strobe and wait for the packet. By using
the same address as both sender and receiver, we flag the the same address as both sender and receiver, we flag the
message is a strobe ack. */ message is a strobe ack. */
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "read send ack"); TIMETABLE_TIMESTAMP(xmac_timetable, "read send ack");
#endif
rimeaddr_copy(&msg.receiver, &hdr->sender); rimeaddr_copy(&msg.receiver, &hdr->sender);
rimeaddr_copy(&msg.sender, &hdr->sender); rimeaddr_copy(&msg.sender, &hdr->sender);
CPRINTF("!"); CPRINTF("!");
@ -489,7 +516,9 @@ read_packet(void)
someone_is_sending = 0; someone_is_sending = 0;
if(rimeaddr_cmp(&hdr->receiver, &rimeaddr_node_addr) || if(rimeaddr_cmp(&hdr->receiver, &rimeaddr_node_addr) ||
rimeaddr_cmp(&hdr->receiver, &rimeaddr_null)) { rimeaddr_cmp(&hdr->receiver, &rimeaddr_null)) {
#if WITH_TIMETABLE
TIMETABLE_TIMESTAMP(xmac_timetable, "read got packet"); TIMETABLE_TIMESTAMP(xmac_timetable, "read got packet");
#endif
/* This is a regular packet that is destined to us or to the /* This is a regular packet that is destined to us or to the
broadcast address. */ broadcast address. */
@ -514,7 +543,9 @@ read_packet(void)
const struct mac_driver * const struct mac_driver *
xmac_init(const struct radio_driver *d) xmac_init(const struct radio_driver *d)
{ {
#if WITH_TIMETABLE
timetable_clear(&xmac_timetable); timetable_clear(&xmac_timetable);
#endif
radio_is_on = 0; radio_is_on = 0;
waiting_for_packet = 0; waiting_for_packet = 0;
PT_INIT(&pt); PT_INIT(&pt);