Multiple bugfixes and updates to xmac code by Niclas
This commit is contained in:
parent
88de583f94
commit
1cb3bad088
2 changed files with 181 additions and 110 deletions
|
@ -1,5 +1,3 @@
|
||||||
/* XXX: TODO: turn radio off when a packet not destined for us is heard. */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
@ -30,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.8 2007/10/23 21:27:57 adamdunkels Exp $
|
* $Id: xmac.c,v 1.9 2007/11/12 22:29:37 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,59 +44,61 @@
|
||||||
#include "dev/leds.h"
|
#include "dev/leds.h"
|
||||||
#include "net/rime.h"
|
#include "net/rime.h"
|
||||||
#include "dev/radio.h"
|
#include "dev/radio.h"
|
||||||
|
#include "lib/random.h"
|
||||||
|
/*#include "lib/bb.h"*/
|
||||||
|
|
||||||
#include "contiki-conf.h"
|
#include "contiki-conf.h"
|
||||||
|
|
||||||
#ifdef CHAMELEON
|
#if CHAMELEON
|
||||||
#include "net/chameleon/packattr.h"
|
#include "net/chameleon/packattr.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WITH_RECEIVER 1
|
#define WITH_RECEIVER 1
|
||||||
#define WITH_QUEUE 0
|
#define WITH_QUEUE 0
|
||||||
|
|
||||||
/*
|
#if !CHAMELEON
|
||||||
#undef XMAC_CONF_ON_TIME
|
|
||||||
#undef XMAC_CONF_OFF_TIME
|
|
||||||
|
|
||||||
#define XMAC_CONF_ON_TIME RTIMER_ARCH_SECOND / 100
|
|
||||||
#define XMAC_CONF_OFF_TIME RTIMER_ARCH_SECOND / 10
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if WITH_RECEIVER
|
#if WITH_RECEIVER
|
||||||
extern
|
extern
|
||||||
#else
|
#else
|
||||||
static
|
static
|
||||||
#endif
|
#endif
|
||||||
rimeaddr_t uc_receiver;
|
rimeaddr_t uc_receiver;
|
||||||
|
#endif /* !CHAMELEON */
|
||||||
|
|
||||||
struct powercycle {
|
/* struct powercycle { */
|
||||||
struct pt pt;
|
/* struct pt pt; */
|
||||||
struct rtimer rt;
|
/* struct rtimer rt; */
|
||||||
rtimer_clock_t ontime, offtime;
|
/* rtimer_clock_t ontime, offtime; */
|
||||||
int num_strobes;
|
/* int num_strobes; */
|
||||||
};
|
/* }; */
|
||||||
|
|
||||||
struct xmac_hdr {
|
struct xmac_hdr {
|
||||||
rimeaddr_t sender;
|
rimeaddr_t sender;
|
||||||
rimeaddr_t receiver;
|
rimeaddr_t receiver;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct rtimer rt;
|
|
||||||
static struct pt pt;
|
|
||||||
|
|
||||||
#ifdef XMAC_CONF_ON_TIME
|
#ifdef XMAC_CONF_ON_TIME
|
||||||
#define ON_TIME (XMAC_CONF_ON_TIME)
|
#define DEFAULT_ON_TIME (XMAC_CONF_ON_TIME)
|
||||||
#else
|
#else
|
||||||
#define ON_TIME (RTIMER_ARCH_SECOND / 100)
|
#define DEFAULT_ON_TIME (RTIMER_ARCH_SECOND / 50)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XMAC_CONF_OFF_TIME
|
#ifdef XMAC_CONF_OFF_TIME
|
||||||
#define OFF_TIME (XMAC_CONF_OFF_TIME)
|
#define DEFAULT_OFF_TIME (XMAC_CONF_OFF_TIME)
|
||||||
#else
|
#else
|
||||||
#define OFF_TIME (ON_TIME * 10)
|
#define DEFAULT_OFF_TIME ((RTIMER_ARCH_SECOND / 5) - DEFAULT_ON_TIME)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STROBE_WAIT_TIME (ON_TIME) / 2
|
#define DEFAULT_STROBE_WAIT_TIME (DEFAULT_ON_TIME) / 2
|
||||||
|
struct xmac_config xmac_config = {
|
||||||
|
DEFAULT_ON_TIME, DEFAULT_OFF_TIME,
|
||||||
|
DEFAULT_ON_TIME + DEFAULT_OFF_TIME,
|
||||||
|
DEFAULT_STROBE_WAIT_TIME
|
||||||
|
};
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
static struct rtimer rt;
|
||||||
|
static struct pt pt;
|
||||||
|
|
||||||
static volatile unsigned char should_be_awake = 0;
|
static volatile unsigned char should_be_awake = 0;
|
||||||
static volatile unsigned char someone_is_sending = 0;
|
static volatile unsigned char someone_is_sending = 0;
|
||||||
|
@ -112,13 +112,15 @@ static const struct radio_driver *radio;
|
||||||
#undef LEDS_OFF
|
#undef LEDS_OFF
|
||||||
#undef LEDS_TOGGLE
|
#undef LEDS_TOGGLE
|
||||||
|
|
||||||
#include <stdio.h>
|
#define BB_SET(x,y)
|
||||||
|
#define BB_INC(x,y)
|
||||||
#define DEBUG 0
|
/* #define BB_SET(x,y) bb_set(x,y) */
|
||||||
#if DEBUG
|
/* #define BB_INC(x,y) bb_inc(x,y) */
|
||||||
#define LEDS_ON(x) leds_on(x)
|
#define LEDS_ON(x) leds_on(x)
|
||||||
#define LEDS_OFF(x) leds_off(x)
|
#define LEDS_OFF(x) leds_off(x)
|
||||||
#define LEDS_TOGGLE(x) leds_toggle(x)
|
#define LEDS_TOGGLE(x) leds_toggle(x)
|
||||||
|
#define DEBUG 0
|
||||||
|
#if DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define PRINTF(...) printf(__VA_ARGS__)
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
|
@ -147,24 +149,36 @@ powercycle(struct rtimer *t, void *ptr)
|
||||||
/* rtimer_clock_t t1, t2; */
|
/* rtimer_clock_t t1, t2; */
|
||||||
|
|
||||||
/* t1 = rtimer_arch_now(); */
|
/* t1 = rtimer_arch_now(); */
|
||||||
if(should_be_awake == 0) {
|
if(we_are_sending) {
|
||||||
radio->off();
|
PRINTF("xmac: we are sending 1, stopping timer\n");
|
||||||
radio_is_on = 0;
|
PT_YIELD(&pt);
|
||||||
LEDS_OFF(LEDS_RED);
|
}
|
||||||
} else {
|
|
||||||
should_be_awake++;
|
/* Only wait for some cycles to pass for someone to start sending */
|
||||||
if(should_be_awake > 2) {
|
if(someone_is_sending > 0) {
|
||||||
should_be_awake = 0;
|
someone_is_sending--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(xmac_config.off_time > 0) {
|
||||||
|
if(should_be_awake == 0) {
|
||||||
|
radio->off();
|
||||||
|
LEDS_OFF(LEDS_RED);
|
||||||
|
radio_is_on = 0;
|
||||||
|
} else {
|
||||||
|
should_be_awake++;
|
||||||
|
if(should_be_awake > 2) {
|
||||||
|
should_be_awake = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r = rtimer_set(t, RTIMER_TIME(t) + xmac_config.off_time, 1,
|
||||||
|
(void (*)(struct rtimer *, void *))powercycle, ptr);
|
||||||
|
if(r) {
|
||||||
|
PRINTF("xmac: 1 could not set rtimer %d\n", r);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
r = rtimer_set(t, RTIMER_TIME(t) + OFF_TIME, 1,
|
|
||||||
(void (*)(struct rtimer *, void *))powercycle, ptr);
|
|
||||||
if(r) {
|
|
||||||
PRINTF("xmac: 1 could not set rtimer %d\n", r);
|
|
||||||
}
|
|
||||||
/* t2 = rtimer_arch_now(); */
|
/* t2 = rtimer_arch_now(); */
|
||||||
/* printf("xmac 1 %d\n", t2 - t1); */
|
/* printf("xmac 1 %d\n", t2 - t1); */
|
||||||
PT_YIELD(&pt);
|
PT_YIELD(&pt);
|
||||||
|
}
|
||||||
|
|
||||||
if(we_are_sending) {
|
if(we_are_sending) {
|
||||||
PRINTF("xmac: we are sending 1, stopping timer\n");
|
PRINTF("xmac: we are sending 1, stopping timer\n");
|
||||||
|
@ -174,10 +188,10 @@ powercycle(struct rtimer *t, void *ptr)
|
||||||
/* t1 = rtimer_arch_now(); */
|
/* t1 = rtimer_arch_now(); */
|
||||||
if(radio_is_on == 0) {
|
if(radio_is_on == 0) {
|
||||||
radio->on();
|
radio->on();
|
||||||
radio_is_on = 1;
|
|
||||||
LEDS_ON(LEDS_RED);
|
LEDS_ON(LEDS_RED);
|
||||||
|
radio_is_on = 1;
|
||||||
}
|
}
|
||||||
r = rtimer_set(t, RTIMER_TIME(t) + ON_TIME, 1,
|
r = rtimer_set(t, RTIMER_TIME(t) + xmac_config.on_time, 1,
|
||||||
(void (*)(struct rtimer *, void *))powercycle, ptr);
|
(void (*)(struct rtimer *, void *))powercycle, ptr);
|
||||||
if(r) {
|
if(r) {
|
||||||
PRINTF("xmac: 2 could not set rtimer %d\n", r);
|
PRINTF("xmac: 2 could not set rtimer %d\n", r);
|
||||||
|
@ -194,14 +208,16 @@ powercycle(struct rtimer *t, void *ptr)
|
||||||
|
|
||||||
if(long_off) {
|
if(long_off) {
|
||||||
|
|
||||||
/* XXX should wait for a complete packet that is not destined to
|
if(xmac_config.off_time > 0) {
|
||||||
us to swisch past us. */
|
/* XXX should wait for a complete packet that is not destined to
|
||||||
radio->off();
|
us to swisch past us. */
|
||||||
radio_is_on = 0;
|
radio->off();
|
||||||
LEDS_OFF(LEDS_RED);
|
LEDS_OFF(LEDS_RED);
|
||||||
if(rtimer_set(t, RTIMER_TIME(t) + OFF_TIME, 1,
|
radio_is_on = 0;
|
||||||
(void (*)(struct rtimer *, void *))powercycle, ptr)) {
|
if(rtimer_set(t, RTIMER_TIME(t) + xmac_config.off_time, 1,
|
||||||
PRINTF("xmac: could not set long off rtimer\n");
|
(void (*)(struct rtimer *, void *))powercycle, ptr)) {
|
||||||
|
PRINTF("xmac: could not set long off rtimer\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
long_off = 0;
|
long_off = 0;
|
||||||
someone_is_sending = 0;
|
someone_is_sending = 0;
|
||||||
|
@ -215,17 +231,18 @@ powercycle(struct rtimer *t, void *ptr)
|
||||||
static int
|
static int
|
||||||
send(void)
|
send(void)
|
||||||
{
|
{
|
||||||
rtimer_clock_t t0, t1;
|
rtimer_clock_t t0;
|
||||||
|
rtimer_clock_t t;
|
||||||
int strobes;
|
int strobes;
|
||||||
struct xmac_hdr *hdr;
|
struct xmac_hdr *hdr;
|
||||||
int got_ack = 0;
|
int got_ack = 0;
|
||||||
struct xmac_hdr msg;
|
struct xmac_hdr msg;
|
||||||
rtimer_clock_t t;
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
we_are_sending = 1;
|
we_are_sending = 1;
|
||||||
|
|
||||||
radio->on();
|
radio->on();
|
||||||
|
LEDS_ON(LEDS_RED);
|
||||||
radio_is_on = 1;
|
radio_is_on = 1;
|
||||||
|
|
||||||
/* printf("xmac_send\n");*/
|
/* printf("xmac_send\n");*/
|
||||||
|
@ -250,11 +267,19 @@ send(void)
|
||||||
t0 = RTIMER_NOW();
|
t0 = RTIMER_NOW();
|
||||||
strobes = 0;
|
strobes = 0;
|
||||||
|
|
||||||
|
BB_SET(XMAC_RECEIVER, hdr->receiver.u16[0]);
|
||||||
|
|
||||||
|
LEDS_ON(LEDS_YELLOW);
|
||||||
do {
|
do {
|
||||||
|
|
||||||
|
if(strobes & 1) {
|
||||||
|
LEDS_OFF(LEDS_GREEN);
|
||||||
|
} else {
|
||||||
|
LEDS_ON(LEDS_GREEN);
|
||||||
|
}
|
||||||
|
|
||||||
t = RTIMER_NOW();
|
t = RTIMER_NOW();
|
||||||
|
|
||||||
LEDS_TOGGLE(LEDS_GREEN);
|
|
||||||
rimeaddr_copy(&msg.sender, &rimeaddr_node_addr);
|
rimeaddr_copy(&msg.sender, &rimeaddr_node_addr);
|
||||||
#if CHAMELEON
|
#if CHAMELEON
|
||||||
rimeaddr_copy(&msg.receiver, packattr_aget(PACKATTR_RECEIVER));
|
rimeaddr_copy(&msg.receiver, packattr_aget(PACKATTR_RECEIVER));
|
||||||
|
@ -268,26 +293,38 @@ send(void)
|
||||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);*/
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);*/
|
||||||
radio->send((const u8_t *)&msg, sizeof(struct xmac_hdr));
|
radio->send((const u8_t *)&msg, sizeof(struct xmac_hdr));
|
||||||
|
|
||||||
while(RTIMER_CLOCK_LT(RTIMER_NOW(), t + STROBE_WAIT_TIME)) {
|
while(RTIMER_CLOCK_LT(RTIMER_NOW(), t + xmac_config.strobe_wait_time)) {
|
||||||
printf("now %d then %d wait %d\n",
|
PRINTF("xmac: now %u then %u wait %d\n",
|
||||||
RTIMER_NOW(), t, STROBE_WAIT_TIME);
|
RTIMER_NOW(), t, xmac_config.strobe_wait_time);
|
||||||
/* See if we got an ACK */
|
/* See if we got an ACK */
|
||||||
/* printf("befor read\n");*/
|
/* printf("before read\n");*/
|
||||||
len = radio->read((u8_t *)&msg, sizeof(struct xmac_hdr));
|
len = radio->read((u8_t *)&msg, sizeof(struct xmac_hdr));
|
||||||
|
|
||||||
/* printf("after read len %d\n", len);*/
|
/* printf("after read len %d\n", len);*/
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
PRINTF("xmac len %d sender %d.%d receiver %d.%d node %d.%d.\n", len,
|
PRINTF("xmac: len %d sender %d.%d receiver %d.%d node %d.%d.\n", len,
|
||||||
msg.sender.u8[0],msg.sender.u8[1],
|
msg.sender.u8[0],msg.sender.u8[1],
|
||||||
msg.receiver.u8[0],msg.receiver.u8[1],
|
msg.receiver.u8[0],msg.receiver.u8[1],
|
||||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||||
if(rimeaddr_cmp(&msg.receiver, &rimeaddr_node_addr)) {
|
/* if(rimeaddr_cmp(&msg.receiver, &rimeaddr_node_addr)) { */
|
||||||
|
if(rimeaddr_cmp(&msg.sender, &rimeaddr_node_addr) &&
|
||||||
|
rimeaddr_cmp(&msg.receiver, &rimeaddr_node_addr)) {
|
||||||
|
|
||||||
/* 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. */
|
||||||
got_ack = 1;
|
got_ack = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* } else if(rimeaddr_cmp(&msg.sender, &hdr->receiver)) { */
|
||||||
|
/* /\* We did not get an ACK from the receiver, but the receiver */
|
||||||
|
/* is active so we can send the packet after a short random */
|
||||||
|
/* duration. *\/ */
|
||||||
|
/* clock_delay(random_rand() & 0x1ff); */
|
||||||
|
/* got_ack = 1; */
|
||||||
|
/* break; */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
RIMESTATS_ADD(sendingdrop);
|
/* RIMESTATS_ADD(sendingdrop);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,21 +334,31 @@ send(void)
|
||||||
if(got_ack) {
|
if(got_ack) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + OFF_TIME + ON_TIME));
|
} while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + xmac_config.strobe_time));
|
||||||
|
LEDS_OFF(LEDS_YELLOW);
|
||||||
|
|
||||||
radio->send(rimebuf_hdrptr(), rimebuf_totlen());
|
radio->send(rimebuf_hdrptr(), rimebuf_totlen());
|
||||||
|
|
||||||
PRINTF("xmac: send, done\n");
|
PRINTF("xmac: send (strobes=%u,len=%u,%s), done\n", strobes,
|
||||||
|
rimebuf_totlen(), got_ack ? "ack" : "no ack");
|
||||||
|
|
||||||
|
BB_SET(XMAC_STROBES, strobes);
|
||||||
|
if(got_ack) {
|
||||||
|
BB_INC(XMAC_SEND_WITH_ACK, 1);
|
||||||
|
} else {
|
||||||
|
BB_INC(XMAC_SEND_WITH_NOACK, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/* printf("Strobe %d got_ack %d\n", strobes, got_ack);*/
|
/* printf("Strobe %d got_ack %d\n", strobes, got_ack);*/
|
||||||
|
|
||||||
|
we_are_sending = 0;
|
||||||
LEDS_OFF(LEDS_GREEN);
|
LEDS_OFF(LEDS_GREEN);
|
||||||
PT_INIT(&pt);
|
PT_INIT(&pt);
|
||||||
if(rtimer_set(&rt, RTIMER_NOW() + ON_TIME, 1,
|
if((len = rtimer_set(&rt, RTIMER_NOW() + xmac_config.on_time, 1,
|
||||||
(void (*)(struct rtimer *, void *))powercycle, NULL)) {
|
(void (*)(struct rtimer *, void *))powercycle, NULL)) != 0) {
|
||||||
PRINTF("xmac: could not set rtimer after send\n");
|
PRINTF("xmac: could not set rtimer after send (%d)\n", len);
|
||||||
}
|
}
|
||||||
we_are_sending = 0;
|
/* we_are_sending = 0; */
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -324,14 +371,14 @@ qsend(void)
|
||||||
PRINTF("xmac: should queue packet, now just dropping %d %d %d %d.\n",
|
PRINTF("xmac: should queue packet, now just dropping %d %d %d %d.\n",
|
||||||
should_be_awake, someone_is_sending, we_are_sending, radio_is_on);
|
should_be_awake, someone_is_sending, we_are_sending, radio_is_on);
|
||||||
if(queued_packet != NULL) {
|
if(queued_packet != NULL) {
|
||||||
RIMESTATS_ADD(contentiondrop);
|
RIMESTATS_ADD(sendingdrop);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
#if WITH_QUEUE
|
#if WITH_QUEUE
|
||||||
queued_packet = queuebuf_new_from_rimebuf();
|
queued_packet = queuebuf_new_from_rimebuf();
|
||||||
return 1;
|
return 1;
|
||||||
#else
|
#else
|
||||||
RIMESTATS_ADD(contentiondrop);
|
RIMESTATS_ADD(sendingdrop);
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -363,7 +410,7 @@ read(void)
|
||||||
PRINTF("%d bytes\n", len);
|
PRINTF("%d bytes\n", len);
|
||||||
|
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
someone_is_sending = 1;
|
someone_is_sending = 2;
|
||||||
rimebuf_set_datalen(len);
|
rimebuf_set_datalen(len);
|
||||||
hdr = rimebuf_dataptr();
|
hdr = rimebuf_dataptr();
|
||||||
|
|
||||||
|
@ -372,6 +419,8 @@ read(void)
|
||||||
should_be_awake = 1;
|
should_be_awake = 1;
|
||||||
PRINTF("xmac: for us\n");
|
PRINTF("xmac: for us\n");
|
||||||
|
|
||||||
|
/* Only send strobe ack if the packet itself is not a strobe ack
|
||||||
|
to us. */
|
||||||
if(!rimeaddr_cmp(&hdr->sender, &rimeaddr_node_addr) &&
|
if(!rimeaddr_cmp(&hdr->sender, &rimeaddr_node_addr) &&
|
||||||
rimebuf_totlen() == 0) {
|
rimebuf_totlen() == 0) {
|
||||||
/* XXX Send an ACK and wait for packet . */
|
/* XXX Send an ACK and wait for packet . */
|
||||||
|
@ -383,6 +432,8 @@ read(void)
|
||||||
{
|
{
|
||||||
struct xmac_hdr msg;
|
struct xmac_hdr msg;
|
||||||
rimeaddr_copy(&msg.receiver, &hdr->sender);
|
rimeaddr_copy(&msg.receiver, &hdr->sender);
|
||||||
|
/* Using the same address as both sender and receiver will
|
||||||
|
flag the message as a strobe ack. */
|
||||||
rimeaddr_copy(&msg.sender, &hdr->sender);
|
rimeaddr_copy(&msg.sender, &hdr->sender);
|
||||||
PRINTF("xmac: sending sender %d.%d receiver %d.%d\n",
|
PRINTF("xmac: sending sender %d.%d receiver %d.%d\n",
|
||||||
msg.sender.u8[0],msg.sender.u8[1],
|
msg.sender.u8[0],msg.sender.u8[1],
|
||||||
|
@ -400,7 +451,6 @@ read(void)
|
||||||
/* Go back to sleep. XXX should not turn on the radio again
|
/* Go back to sleep. XXX should not turn on the radio again
|
||||||
until this packet has passed. */
|
until this packet has passed. */
|
||||||
should_be_awake = 0;
|
should_be_awake = 0;
|
||||||
someone_is_sending = 1;
|
|
||||||
long_off = 1;
|
long_off = 1;
|
||||||
/* XXX set timer to turn someone_is_sending off again and send queued packet. */
|
/* XXX set timer to turn someone_is_sending off again and send queued packet. */
|
||||||
/* PRINTF("xmac: not for us\n");*/
|
/* PRINTF("xmac: not for us\n");*/
|
||||||
|
@ -426,6 +476,26 @@ read(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
const struct mac_driver *
|
||||||
|
xmac_init(const struct radio_driver *d)
|
||||||
|
{
|
||||||
|
radio_is_on = 0;
|
||||||
|
should_be_awake = 0;
|
||||||
|
PT_INIT(&pt);
|
||||||
|
rtimer_set(&rt, RTIMER_NOW() + xmac_config.off_time, 1,
|
||||||
|
(void (*)(struct rtimer *, void *))powercycle, NULL);
|
||||||
|
|
||||||
|
radio = d;
|
||||||
|
radio->set_receive_function(input);
|
||||||
|
|
||||||
|
BB_SET("xmac.state_addr", (int) &should_be_awake);
|
||||||
|
BB_SET(XMAC_RECEIVER, 0);
|
||||||
|
BB_SET(XMAC_STROBES, 0);
|
||||||
|
BB_SET(XMAC_SEND_WITH_ACK, 0);
|
||||||
|
BB_SET(XMAC_SEND_WITH_NOACK, 0);
|
||||||
|
return &xmac_driver;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
on(void)
|
on(void)
|
||||||
{
|
{
|
||||||
|
@ -446,18 +516,3 @@ const struct mac_driver xmac_driver =
|
||||||
on,
|
on,
|
||||||
off
|
off
|
||||||
};
|
};
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
const struct mac_driver *
|
|
||||||
xmac_init(const struct radio_driver *d)
|
|
||||||
{
|
|
||||||
radio_is_on = 0;
|
|
||||||
should_be_awake = 0;
|
|
||||||
PT_INIT(&pt);
|
|
||||||
rtimer_set(&rt, RTIMER_NOW() + OFF_TIME, 1,
|
|
||||||
(void (*)(struct rtimer *, void *))powercycle, NULL);
|
|
||||||
|
|
||||||
radio = d;
|
|
||||||
radio->set_receive_function(input);
|
|
||||||
return &xmac_driver;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: xmac.h,v 1.5 2007/10/23 20:57:37 adamdunkels Exp $
|
* $Id: xmac.h,v 1.6 2007/11/12 22:29:37 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,11 +41,27 @@
|
||||||
#ifndef __XMAC_H__
|
#ifndef __XMAC_H__
|
||||||
#define __XMAC_H__
|
#define __XMAC_H__
|
||||||
|
|
||||||
|
#include "sys/rtimer.h"
|
||||||
#include "net/mac/mac.h"
|
#include "net/mac/mac.h"
|
||||||
#include "dev/radio.h"
|
#include "dev/radio.h"
|
||||||
|
|
||||||
|
#define XMAC_RECEIVER "xmac.recv"
|
||||||
|
#define XMAC_STROBES "xmac.strobes"
|
||||||
|
#define XMAC_SEND_WITH_ACK "xmac.send.ack"
|
||||||
|
#define XMAC_SEND_WITH_NOACK "xmac.send.noack"
|
||||||
|
|
||||||
|
|
||||||
|
struct xmac_config {
|
||||||
|
rtimer_clock_t on_time;
|
||||||
|
rtimer_clock_t off_time;
|
||||||
|
rtimer_clock_t strobe_time;
|
||||||
|
rtimer_clock_t strobe_wait_time;
|
||||||
|
};
|
||||||
|
|
||||||
extern const struct mac_driver xmac_driver;
|
extern const struct mac_driver xmac_driver;
|
||||||
|
|
||||||
const struct mac_driver *xmac_init(const struct radio_driver *d);
|
const struct mac_driver *xmac_init(const struct radio_driver *d);
|
||||||
|
|
||||||
|
extern struct xmac_config xmac_config;
|
||||||
|
|
||||||
#endif /* __XMAC_H__ */
|
#endif /* __XMAC_H__ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue