mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
Rewrote the timesynch code to use the Rime sniffer interface instead of the kludge of running timesynch as a MAC layer
This commit is contained in:
parent
02ee418313
commit
34bd11905c
@ -34,7 +34,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: timesynch.c,v 1.1 2008/01/14 14:22:16 adamdunkels Exp $
|
* $Id: timesynch.c,v 1.2 2008/01/14 14:50:01 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,9 +49,6 @@
|
|||||||
#include "net/rime.h"
|
#include "net/rime.h"
|
||||||
#include "dev/simple-cc2420.h"
|
#include "dev/simple-cc2420.h"
|
||||||
|
|
||||||
static const struct mac_driver *mac;
|
|
||||||
static void (* receiver_callback)(const struct mac_driver *);
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static int authority_level;
|
static int authority_level;
|
||||||
@ -88,44 +85,28 @@ timesynch_offset(void)
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
|
||||||
send_packet(void)
|
|
||||||
{
|
|
||||||
return mac->send();
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
static void
|
||||||
adjust_offset(rtimer_clock_t authoritative_time, rtimer_clock_t local_time)
|
adjust_offset(rtimer_clock_t authoritative_time, rtimer_clock_t local_time)
|
||||||
{
|
{
|
||||||
offset = offset + authoritative_time - local_time;
|
offset = offset + authoritative_time - local_time;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static void
|
||||||
read_packet(void)
|
incoming_packet(void)
|
||||||
{
|
{
|
||||||
int len;
|
if(rimebuf_totlen() != 0) {
|
||||||
|
/* We check the authority level of the sender of the incoming
|
||||||
len = mac->read();
|
packet. If the sending node has a lower authority level than we
|
||||||
|
have, we synchronize to the time of the sending node and set our
|
||||||
if(len == 0) {
|
own authority level to be one more than the sending node. */
|
||||||
return 0;
|
if(simple_cc2420_authority_level_of_sender < authority_level) {
|
||||||
}
|
adjust_offset(simple_cc2420_time_of_departure,
|
||||||
|
simple_cc2420_time_of_arrival);
|
||||||
/* We check the authority level of the sender of the incoming
|
if(simple_cc2420_authority_level_of_sender + 1 != authority_level) {
|
||||||
packet. If the sending node has a lower authority level than we
|
authority_level = simple_cc2420_authority_level_of_sender + 1;
|
||||||
have, we synchronize to the time of the sending node and set our
|
}
|
||||||
own authority level to be one more than the sending node. */
|
|
||||||
if(simple_cc2420_authority_level_of_sender < authority_level) {
|
|
||||||
|
|
||||||
adjust_offset(simple_cc2420_time_of_departure,
|
|
||||||
simple_cc2420_time_of_arrival);
|
|
||||||
if(simple_cc2420_authority_level_of_sender + 1 != authority_level) {
|
|
||||||
authority_level = simple_cc2420_authority_level_of_sender + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#if 0
|
#if 0
|
||||||
@ -137,47 +118,12 @@ periodic_authority_increase(void *ptr)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
RIME_SNIFFER(sniffer, incoming_packet, NULL);
|
||||||
set_receive_function(void (* recv)(const struct mac_driver *))
|
|
||||||
{
|
|
||||||
receiver_callback = recv;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
void
|
||||||
on(void)
|
timesynch_init(void)
|
||||||
{
|
{
|
||||||
return mac->on();
|
rime_sniffer_add(&sniffer);
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int
|
|
||||||
off(void)
|
|
||||||
{
|
|
||||||
return mac->off();
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static const struct mac_driver timesynch_driver = {
|
|
||||||
send_packet,
|
|
||||||
read_packet,
|
|
||||||
set_receive_function,
|
|
||||||
on,
|
|
||||||
off,
|
|
||||||
};
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
input_packet(const struct mac_driver *d)
|
|
||||||
{
|
|
||||||
if(receiver_callback) {
|
|
||||||
receiver_callback(×ynch_driver);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
const struct mac_driver *
|
|
||||||
timesynch_init(const struct mac_driver *d)
|
|
||||||
{
|
|
||||||
mac = d;
|
|
||||||
mac->set_receive_function(input_packet);
|
|
||||||
mac->on();
|
|
||||||
return ×ynch_driver;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: timesynch.h,v 1.1 2008/01/14 14:22:16 adamdunkels Exp $
|
* $Id: timesynch.h,v 1.2 2008/01/14 14:50:02 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,16 +72,13 @@
|
|||||||
#include "sys/rtimer.h"
|
#include "sys/rtimer.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initialize the timesynch module; should be called during the MAC initialization procedure
|
* \brief Initialize the timesynch module
|
||||||
* \param r The underlying MAC driver
|
|
||||||
* \return A pointer to the timesynch module's meta MAC driver
|
|
||||||
*
|
*
|
||||||
* This function initializes the timesynch module. The
|
* This function initializes the timesynch module. This
|
||||||
* function should be called as part of the MAC
|
* function must not be called before rime_init().
|
||||||
* initialization procedure.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
const struct mac_driver *timesynch_init(const struct mac_driver *r);
|
void timesynch_init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Get the current time-synchronized time
|
* \brief Get the current time-synchronized time
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#)$Id: contiki-sky-main.c,v 1.22 2008/01/14 14:22:17 adamdunkels Exp $
|
* @(#)$Id: contiki-sky-main.c,v 1.23 2008/01/14 14:50:02 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -151,7 +151,7 @@ main(int argc, char **argv)
|
|||||||
#endif /* WITH_UIP */
|
#endif /* WITH_UIP */
|
||||||
|
|
||||||
/* printf("Starting %s " */
|
/* printf("Starting %s " */
|
||||||
/* "($Id: contiki-sky-main.c,v 1.22 2008/01/14 14:22:17 adamdunkels Exp $)\n", __FILE__); */
|
/* "($Id: contiki-sky-main.c,v 1.23 2008/01/14 14:50:02 adamdunkels Exp $)\n", __FILE__); */
|
||||||
leds_on(LEDS_GREEN);
|
leds_on(LEDS_GREEN);
|
||||||
ds2411_init();
|
ds2411_init();
|
||||||
sensors_light_init();
|
sensors_light_init();
|
||||||
@ -211,9 +211,9 @@ main(int argc, char **argv)
|
|||||||
simple_cc2420_init();
|
simple_cc2420_init();
|
||||||
simple_cc2420_set_chan_pan_addr(RF_CHANNEL, panId, 0 /*XXX*/, ds2411_id);
|
simple_cc2420_set_chan_pan_addr(RF_CHANNEL, panId, 0 /*XXX*/, ds2411_id);
|
||||||
/* rime_init(nullmac_init(&simple_cc2420_driver));*/
|
/* rime_init(nullmac_init(&simple_cc2420_driver));*/
|
||||||
/* rime_init(xmac_init(&simple_cc2420_driver));*/
|
rime_init(xmac_init(&simple_cc2420_driver));
|
||||||
/* rime_init(timesynch_init(nullmac_init(&simple_cc2420_driver)));*/
|
|
||||||
rime_init(timesynch_init(xmac_init(&simple_cc2420_driver)));
|
timesynch_init();
|
||||||
|
|
||||||
|
|
||||||
timesynch_set_authority_level(rimeaddr_node_addr.u8[0]);
|
timesynch_set_authority_level(rimeaddr_node_addr.u8[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user