From c20047f6572f5d898dab60bf2f0142d54f3d7a61 Mon Sep 17 00:00:00 2001 From: nifi Date: Tue, 23 Feb 2010 20:09:11 +0000 Subject: [PATCH] Changed the network stack to use different structures for the different layers (network_driver, mac_driver, rdc_driver, radio_driver). This helps to avoid incorrect configuration. --- core/net/mac/contikimac.c | 4 +-- core/net/mac/contikimac.h | 6 ++-- core/net/mac/cxmac.c | 4 +-- core/net/mac/cxmac.h | 6 ++-- core/net/mac/lpp.c | 4 +-- core/net/mac/lpp.h | 8 ++--- core/net/mac/nullrdc.c | 4 +-- core/net/mac/nullrdc.h | 7 ++-- core/net/mac/rdc.h | 73 +++++++++++++++++++++++++++++++++++++++ core/net/mac/sicslowmac.c | 4 +-- core/net/mac/sicslowmac.h | 8 ++--- core/net/mac/xmac.c | 4 +-- core/net/mac/xmac.h | 6 ++-- core/net/netstack.h | 28 +++++++++++---- core/net/rime.h | 4 +-- core/net/rime/rime.c | 10 ++---- core/net/sicslowpan.c | 12 +++---- core/net/sicslowpan.h | 4 +-- 18 files changed, 135 insertions(+), 61 deletions(-) create mode 100644 core/net/mac/rdc.h diff --git a/core/net/mac/contikimac.c b/core/net/mac/contikimac.c index 0c359556c..4f097ce8e 100644 --- a/core/net/mac/contikimac.c +++ b/core/net/mac/contikimac.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: contikimac.c,v 1.4 2010/02/23 18:49:05 adamdunkels Exp $ + * $Id: contikimac.c,v 1.5 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -866,7 +866,7 @@ duty_cycle(void) return (1ul * CLOCK_SECOND * CYCLE_TIME) / RTIMER_ARCH_SECOND; } /*---------------------------------------------------------------------------*/ -const struct mac_driver contikimac_driver = { +const struct rdc_driver contikimac_driver = { "ContikiMAC", init, qsend_packet, diff --git a/core/net/mac/contikimac.h b/core/net/mac/contikimac.h index f1148791c..96f7ff86c 100644 --- a/core/net/mac/contikimac.h +++ b/core/net/mac/contikimac.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: contikimac.h,v 1.2 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: contikimac.h,v 1.3 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -42,9 +42,9 @@ #define __CONTIKIMAC_H__ #include "sys/rtimer.h" -#include "net/mac/mac.h" +#include "net/mac/rdc.h" #include "dev/radio.h" -extern const struct mac_driver contikimac_driver; +extern const struct rdc_driver contikimac_driver; #endif /* __CONTIKIMAC_H__ */ diff --git a/core/net/mac/cxmac.c b/core/net/mac/cxmac.c index cfab6f77a..846f0f78e 100644 --- a/core/net/mac/cxmac.c +++ b/core/net/mac/cxmac.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: cxmac.c,v 1.10 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: cxmac.c,v 1.11 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -911,7 +911,7 @@ channel_check_interval(void) return (1ul * CLOCK_SECOND * DEFAULT_PERIOD) / RTIMER_ARCH_SECOND; } /*---------------------------------------------------------------------------*/ -const struct mac_driver cxmac_driver = +const struct rdc_driver cxmac_driver = { "CX-MAC", cxmac_init, diff --git a/core/net/mac/cxmac.h b/core/net/mac/cxmac.h index e9d9605b2..67a8a1ea1 100644 --- a/core/net/mac/cxmac.h +++ b/core/net/mac/cxmac.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: cxmac.h,v 1.4 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: cxmac.h,v 1.5 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -42,7 +42,7 @@ #define __CXMAC_H__ #include "sys/rtimer.h" -#include "net/mac/mac.h" +#include "net/mac/rdc.h" #include "dev/radio.h" #define CXMAC_RECEIVER "cxmac.recv" @@ -58,7 +58,7 @@ struct cxmac_config { rtimer_clock_t strobe_wait_time; }; -extern const struct mac_driver cxmac_driver; +extern const struct rdc_driver cxmac_driver; #endif /* __CXMAC_H__ */ diff --git a/core/net/mac/lpp.c b/core/net/mac/lpp.c index 66e367347..6b18b9508 100644 --- a/core/net/mac/lpp.c +++ b/core/net/mac/lpp.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: lpp.c,v 1.31 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: lpp.c,v 1.32 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -913,7 +913,7 @@ init(void) list_init(pending_packets_list); } /*---------------------------------------------------------------------------*/ -const struct mac_driver lpp_driver = { +const struct rdc_driver lpp_driver = { "LPP", init, send_packet, diff --git a/core/net/mac/lpp.h b/core/net/mac/lpp.h index be9152ad2..7ba4c31a7 100644 --- a/core/net/mac/lpp.h +++ b/core/net/mac/lpp.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: lpp.h,v 1.2 2009/06/22 11:14:11 nifi Exp $ + * $Id: lpp.h,v 1.3 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -44,11 +44,9 @@ #ifndef __LPP_H__ #define __LPP_H__ -#include "net/mac/mac.h" +#include "net/mac/rdc.h" #include "dev/radio.h" -extern const struct mac_driver lpp_driver; - -const struct mac_driver *lpp_init(const struct radio_driver *d); +extern const struct rdc_driver lpp_driver; #endif /* __LPP_H__ */ diff --git a/core/net/mac/nullrdc.c b/core/net/mac/nullrdc.c index f30be8f25..6b581bb9f 100644 --- a/core/net/mac/nullrdc.c +++ b/core/net/mac/nullrdc.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: nullrdc.c,v 1.1 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: nullrdc.c,v 1.2 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -89,7 +89,7 @@ init(void) on(); } /*---------------------------------------------------------------------------*/ -const struct mac_driver nullrdc_driver = { +const struct rdc_driver nullrdc_driver = { "nullrdc", init, send_packet, diff --git a/core/net/mac/nullrdc.h b/core/net/mac/nullrdc.h index f2e9f3729..0d3d42993 100644 --- a/core/net/mac/nullrdc.h +++ b/core/net/mac/nullrdc.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: nullrdc.h,v 1.1 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: nullrdc.h,v 1.2 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -41,10 +41,9 @@ #ifndef __NULLRDC_H__ #define __NULLRDC_H__ -#include "net/mac/mac.h" +#include "net/mac/rdc.h" #include "dev/radio.h" -extern const struct mac_driver nullrdc_driver; - +extern const struct rdc_driver nullrdc_driver; #endif /* __NULLRDC_H__ */ diff --git a/core/net/mac/rdc.h b/core/net/mac/rdc.h new file mode 100644 index 000000000..5106d8888 --- /dev/null +++ b/core/net/mac/rdc.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * $Id: rdc.h,v 1.1 2010/02/23 20:09:11 nifi Exp $ + */ + +/** + * \file + * RDC driver header file + * \author + * Adam Dunkels + * Niclas Finne + */ + +#ifndef __RDC_H__ +#define __RDC_H__ + +#include "contiki-conf.h" +#include "net/mac/mac.h" + +/** + * The structure of a RDC (radio duty cycling) driver in Contiki. + */ +struct rdc_driver { + char *name; + + /** Initialize the RDC driver */ + void (* init)(void); + + /** Send a packet from the Rime buffer */ + void (* send)(mac_callback_t sent_callback, void *ptr); + + /** Callback for getting notified of incoming packet. */ + void (* input)(void); + + /** Turn the MAC layer on. */ + int (* on)(void); + + /** Turn the MAC layer off. */ + int (* off)(int keep_radio_on); + + /** Returns the channel check interval, expressed in clock_time_t ticks. */ + unsigned short (* channel_check_interval)(void); +}; + +#endif /* __RDC_H__ */ diff --git a/core/net/mac/sicslowmac.c b/core/net/mac/sicslowmac.c index 5ed776af5..c3d39d0b7 100644 --- a/core/net/mac/sicslowmac.c +++ b/core/net/mac/sicslowmac.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: sicslowmac.c,v 1.5 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: sicslowmac.c,v 1.6 2010/02/23 20:09:11 nifi Exp $ */ @@ -238,7 +238,7 @@ init(void) NETSTACK_RADIO.on(); } /*---------------------------------------------------------------------------*/ -const struct mac_driver sicslowmac_driver = { +const struct rdc_driver sicslowmac_driver = { "sicslowmac", init, send_packet, diff --git a/core/net/mac/sicslowmac.h b/core/net/mac/sicslowmac.h index d5b52729c..f0b780c82 100644 --- a/core/net/mac/sicslowmac.h +++ b/core/net/mac/sicslowmac.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: sicslowmac.h,v 1.1 2009/04/06 13:19:03 nifi Exp $ + * $Id: sicslowmac.h,v 1.2 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -46,11 +46,9 @@ #ifndef __SICSLOWMAC_H__ #define __SICSLOWMAC_H__ -#include "net/mac/mac.h" +#include "net/mac/rdc.h" #include "dev/radio.h" -extern const struct mac_driver sicslowmac_driver; - -const struct mac_driver *sicslowmac_init(const struct radio_driver *r); +extern const struct rdc_driver sicslowmac_driver; #endif /* __SICSLOWMAC_H__ */ diff --git a/core/net/mac/xmac.c b/core/net/mac/xmac.c index de2df1c47..08aaf6a7f 100644 --- a/core/net/mac/xmac.c +++ b/core/net/mac/xmac.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: xmac.c,v 1.53 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: xmac.c,v 1.54 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -904,7 +904,7 @@ channel_check_interval(void) return (1ul * CLOCK_SECOND * DEFAULT_PERIOD) / RTIMER_ARCH_SECOND; } /*---------------------------------------------------------------------------*/ -const struct mac_driver xmac_driver = +const struct rdc_driver xmac_driver = { "X-MAC", init, diff --git a/core/net/mac/xmac.h b/core/net/mac/xmac.h index 8e78a2ba3..80376f563 100644 --- a/core/net/mac/xmac.h +++ b/core/net/mac/xmac.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: xmac.h,v 1.8 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: xmac.h,v 1.9 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -42,7 +42,7 @@ #define __XMAC_H__ #include "sys/rtimer.h" -#include "net/mac/mac.h" +#include "net/mac/rdc.h" #include "dev/radio.h" #define XMAC_RECEIVER "xmac.recv" @@ -58,7 +58,7 @@ struct xmac_config { rtimer_clock_t strobe_wait_time; }; -extern const struct mac_driver xmac_driver; +extern const struct rdc_driver xmac_driver; void xmac_set_announcement_radio_txpower(int txpower); diff --git a/core/net/netstack.h b/core/net/netstack.h index 8425caa21..3f7c511cc 100644 --- a/core/net/netstack.h +++ b/core/net/netstack.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: netstack.h,v 1.3 2010/02/23 18:28:04 adamdunkels Exp $ + * $Id: netstack.h,v 1.4 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -55,7 +55,7 @@ #ifdef NETSTACK_CONF_MAC #define NETSTACK_MAC NETSTACK_CONF_MAC #else /* NETSTACK_CONF_MAC */ -#define NETSTACK_MAC nullrdc_driver +#define NETSTACK_MAC nullmac_driver #endif /* NETSTACK_CONF_MAC */ #endif /* NETSTACK_MAC */ @@ -63,7 +63,7 @@ #ifdef NETSTACK_CONF_RDC #define NETSTACK_RDC NETSTACK_CONF_RDC #else /* NETSTACK_CONF_RDC */ -#define NETSTACK_RDC nullmac_driver +#define NETSTACK_RDC nullrdc_driver #endif /* NETSTACK_CONF_RDC */ #endif /* NETSTACK_RDC */ @@ -76,12 +76,26 @@ #endif /* NETSTACK_RADIO */ #include "net/mac/mac.h" +#include "net/mac/rdc.h" #include "dev/radio.h" -extern const struct mac_driver NETSTACK_NETWORK; -extern const struct mac_driver NETSTACK_RDC; -extern const struct mac_driver NETSTACK_MAC; -extern const struct radio_driver NETSTACK_RADIO; +/** + * The structure of a network driver in Contiki. + */ +struct network_driver { + char *name; + + /** Initialize the network driver */ + void (* init)(void); + + /** Callback for getting notified of incoming packet. */ + void (* input)(void); +}; + +extern const struct network_driver NETSTACK_NETWORK; +extern const struct rdc_driver NETSTACK_RDC; +extern const struct mac_driver NETSTACK_MAC; +extern const struct radio_driver NETSTACK_RADIO; void netstack_init(void); diff --git a/core/net/rime.h b/core/net/rime.h index 418af7d58..bfc862039 100644 --- a/core/net/rime.h +++ b/core/net/rime.h @@ -33,7 +33,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rime.h,v 1.26 2010/02/23 18:29:53 adamdunkels Exp $ + * $Id: rime.h,v 1.27 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -105,7 +105,7 @@ static struct rime_sniffer name = { NULL, input_callback, output_callback } void rime_sniffer_add(struct rime_sniffer *s); void rime_sniffer_remove(struct rime_sniffer *s); -extern const struct mac_driver rime_driver; +extern const struct network_driver rime_driver; /* Generic Rime return values. */ enum { diff --git a/core/net/rime/rime.c b/core/net/rime/rime.c index 6c34a0492..e57dfa374 100644 --- a/core/net/rime/rime.c +++ b/core/net/rime/rime.c @@ -33,7 +33,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rime.c,v 1.26 2010/02/23 18:29:53 adamdunkels Exp $ + * $Id: rime.c,v 1.27 2010/02/23 20:09:11 nifi Exp $ */ /** @@ -188,13 +188,9 @@ rime_output(struct channel *c) return 0; } /*---------------------------------------------------------------------------*/ -const struct mac_driver rime_driver = { +const struct network_driver rime_driver = { "Rime", init, - NULL, - input, - NULL, - NULL, - NULL, + input }; /** @} */ diff --git a/core/net/sicslowpan.c b/core/net/sicslowpan.c index 87b960148..03593cb5c 100644 --- a/core/net/sicslowpan.c +++ b/core/net/sicslowpan.c @@ -32,7 +32,7 @@ * * This file is part of the Contiki operating system. * - * $Id: sicslowpan.c,v 1.18 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: sicslowpan.c,v 1.19 2010/02/23 20:09:11 nifi Exp $ */ /** * \file @@ -1518,14 +1518,10 @@ sicslowpan_init(void) #endif /*SICSLOWPAN_CONF_COMPRESSION == SICSLOWPAN_CONF_COMPRESSION_HC01*/ } /*--------------------------------------------------------------------*/ -const struct mac_driver sicslowpan_driver = { - "Rime", +const struct network_driver sicslowpan_driver = { + "sicslowpan", sicslowpan_init, - NULL, - input, - NULL, - NULL, - NULL, + input }; /*--------------------------------------------------------------------*/ /** @} */ diff --git a/core/net/sicslowpan.h b/core/net/sicslowpan.h index e4830909f..0cfb54608 100644 --- a/core/net/sicslowpan.h +++ b/core/net/sicslowpan.h @@ -33,7 +33,7 @@ * * This file is part of the Contiki operating system. * - * $Id: sicslowpan.h,v 1.6 2010/02/18 21:48:39 adamdunkels Exp $ + * $Id: sicslowpan.h,v 1.7 2010/02/23 20:09:11 nifi Exp $ */ /** * \file @@ -249,7 +249,7 @@ struct sicslowpan_addr_context { /** @} */ -extern const struct mac_driver sicslowpan_driver; +extern const struct network_driver sicslowpan_driver; extern const struct mac_driver *sicslowpan_mac; #endif /* __SICSLOWPAN_H__ */