diff --git a/core/net/mac/ctdma_mac.c b/core/net/mac/ctdma_mac.c index 5d04467072186f1c35d03340f4d96f0adf15a693..6ce287f1d6ed01e91b10c07871827b70bfe0510e 100644 --- a/core/net/mac/ctdma_mac.c +++ b/core/net/mac/ctdma_mac.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: ctdma_mac.c,v 1.3 2009/03/12 21:58:20 adamdunkels Exp $ + * $Id: ctdma_mac.c,v 1.4 2009/06/22 11:14:11 nifi Exp $ */ #include "contiki.h" @@ -215,12 +215,16 @@ on(void) } /*---------------------------------------------------------------------------*/ static int -off(void) +off(int keep_radio_on) { - return radio->off(); + if(keep_radio_on) { + return radio->on(); + } else { + return radio->off(); + } } /*---------------------------------------------------------------------------*/ -void +const struct mac_driver * ctdma_mac_init(const struct radio_driver *d) { int i; @@ -232,9 +236,12 @@ ctdma_mac_init(const struct radio_driver *d) radio = d; radio->set_receive_function(input); radio->on(); + return &ctdma_mac_driver; } /*---------------------------------------------------------------------------*/ const struct mac_driver ctdma_mac_driver = { + "CTDMA", + ctdma_mac_init, send, read, set_receive_function, diff --git a/core/net/mac/ctdma_mac.h b/core/net/mac/ctdma_mac.h index 22e1f6daee93cff3de3156672936264fa28ca935..2e1565304305a0548b993f2898ad0102eec82a84 100644 --- a/core/net/mac/ctdma_mac.h +++ b/core/net/mac/ctdma_mac.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: ctdma_mac.h,v 1.1 2007/09/18 10:36:36 fros4943 Exp $ + * $Id: ctdma_mac.h,v 1.2 2009/06/22 11:14:11 nifi Exp $ */ #ifndef __CTDMA_MAC_H__ @@ -39,6 +39,6 @@ extern const struct mac_driver ctdma_mac_driver; -void ctdma_mac_init(const struct radio_driver *r); +const struct mac_driver *ctdma_mac_init(const struct radio_driver *r); #endif /* __CTDMA_MAC_H__ */ diff --git a/core/net/mac/cxmac.c b/core/net/mac/cxmac.c index 66458b02ab7cfdf996b7b6278b4e49694f27e771..f34cdddc80052e8896896a01fd82588bb77964e3 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.3 2009/03/12 21:58:20 adamdunkels Exp $ + * $Id: cxmac.c,v 1.4 2009/06/22 11:14:11 nifi Exp $ */ /** @@ -481,7 +481,7 @@ read(void) return 0; } /*---------------------------------------------------------------------------*/ -void +const struct mac_driver * cxmac_init(const struct radio_driver *d) { radio_is_on = 0; @@ -494,6 +494,7 @@ cxmac_init(const struct radio_driver *d) radio = d; radio->set_receive_function(input); + return &cxmac_driver; } /*---------------------------------------------------------------------------*/ static int @@ -511,22 +512,20 @@ on(void) } /*---------------------------------------------------------------------------*/ static int -off(int radio_status) +off(int keep_radio_on) { should_stop = 1; - return radio->off(); - -/* switch(radio_status) { - case MAC_RADIO_ON: + if(keep_radio_on) { return radio->on(); - case MAC_RADIO_OFF: + } else { return radio->off(); } - return 0; */ } /*---------------------------------------------------------------------------*/ const struct mac_driver cxmac_driver = { + "CXMAC", + cxmac_init, qsend, read, set_receive_function, diff --git a/core/net/mac/cxmac.h b/core/net/mac/cxmac.h index 87eefc55117c5603faee9be3e6fa5cb55cf7e8b6..e8ba6252865be252c1c2331e1dd750987f39a9bf 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.1 2007/09/18 10:35:39 fros4943 Exp $ + * $Id: cxmac.h,v 1.2 2009/06/22 11:14:11 nifi Exp $ */ /** @@ -46,6 +46,6 @@ extern const struct mac_driver cxmac_driver; -void cxmac_init(const struct radio_driver *d); +const struct mac_driver *cxmac_init(const struct radio_driver *d); #endif /* __CXMAC_H__ */ diff --git a/core/net/mac/lpp.c b/core/net/mac/lpp.c index 8e42fdd04b4c5aab4f4163f0c6045d910bace56d..3a702d020c227914c0d5241fde2d7e7a155821c0 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.22 2009/05/10 21:09:05 adamdunkels Exp $ + * $Id: lpp.c,v 1.23 2009/06/22 11:14:11 nifi Exp $ */ /** @@ -818,8 +818,9 @@ off(int keep_radio_on) return 1; } /*---------------------------------------------------------------------------*/ -static const struct mac_driver lpp_driver = { +const struct mac_driver lpp_driver = { "LPP", + lpp_init, send_packet, read_packet, set_receive_function, diff --git a/core/net/mac/lpp.h b/core/net/mac/lpp.h index 9587e8320a26b95583f567c80bd032e636c55a55..be9152ad27155cadcfe293c8fa2196a195c1a45b 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.1 2008/05/15 08:56:29 adamdunkels Exp $ + * $Id: lpp.h,v 1.2 2009/06/22 11:14:11 nifi Exp $ */ /** @@ -47,6 +47,8 @@ #include "net/mac/mac.h" #include "dev/radio.h" +extern const struct mac_driver lpp_driver; + const struct mac_driver *lpp_init(const struct radio_driver *d); #endif /* __LPP_H__ */ diff --git a/core/net/mac/mac.h b/core/net/mac/mac.h index c9f671075b4974f33a60450dc04128a8446dc3bd..3f93b5bc8bb750b0e89fe5f90ee220230696a357 100644 --- a/core/net/mac/mac.h +++ b/core/net/mac/mac.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: mac.h,v 1.4 2008/07/02 14:10:28 adamdunkels Exp $ + * $Id: mac.h,v 1.5 2009/06/22 11:14:11 nifi Exp $ */ /** @@ -41,12 +41,17 @@ #ifndef __MAC_H__ #define __MAC_H__ +#include "dev/radio.h" + /** * The structure of a MAC protocol driver in Contiki. */ struct mac_driver { char *name; - + + /** Initialize the MAC driver */ + const struct mac_driver *(* init)(const struct radio_driver *r); + /** Send a packet from the Rime buffer */ int (* send)(void); diff --git a/core/net/mac/nullmac.c b/core/net/mac/nullmac.c index 95a8cbe8821d8030ae647413363b53b0f0c2d748..0b3a22d3c63dc1ee76e4c081a57f7f80b75cf748 100644 --- a/core/net/mac/nullmac.c +++ b/core/net/mac/nullmac.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: nullmac.c,v 1.9 2009/03/12 21:58:20 adamdunkels Exp $ + * $Id: nullmac.c,v 1.10 2009/06/22 11:14:11 nifi Exp $ */ /** @@ -92,6 +92,7 @@ off(int keep_radio_on) /*---------------------------------------------------------------------------*/ const struct mac_driver nullmac_driver = { "nullmac", + nullmac_init, send_packet, read_packet, set_receive_function, diff --git a/core/net/mac/sicslowmac.c b/core/net/mac/sicslowmac.c index dbc24779e0a602a4d9cceb07290965d3f1ab50c2..86f13f12d95b7aa6f332a664a311448bf14ec6bb 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.2 2009/05/26 12:08:29 nifi Exp $ + * $Id: sicslowmac.c,v 1.3 2009/06/22 11:14:11 nifi Exp $ */ @@ -234,6 +234,7 @@ off(int keep_radio_on) /*---------------------------------------------------------------------------*/ const struct mac_driver sicslowmac_driver = { "sicslowmac", + sicslowmac_init, send_packet, read_packet, set_receive_function, diff --git a/core/net/mac/tdma_mac.c b/core/net/mac/tdma_mac.c index 71e648c79f1244103e221984fd0648cb45503ccd..14e1ea7399becc712111c630514f20200a2d74ad 100644 --- a/core/net/mac/tdma_mac.c +++ b/core/net/mac/tdma_mac.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: tdma_mac.c,v 1.6 2009/03/12 21:58:20 adamdunkels Exp $ + * $Id: tdma_mac.c,v 1.7 2009/06/22 11:14:11 nifi Exp $ */ #include "contiki.h" @@ -221,9 +221,13 @@ on(void) } /*---------------------------------------------------------------------------*/ static int -off(void) +off(int keep_radio_on) { - return radio->off(); + if(keep_radio_on) { + return radio->on(); + } else { + return radio->off(); + } } /*---------------------------------------------------------------------------*/ const struct mac_driver * @@ -243,6 +247,7 @@ tdma_mac_init(const struct radio_driver *d) /*---------------------------------------------------------------------------*/ const struct mac_driver tdma_mac_driver = { "TDMA MAC", + tdma_mac_init, send, read, set_receive_function, diff --git a/core/net/mac/xmac.c b/core/net/mac/xmac.c index f3fdb7549cc2fef449e852e830ad25c59c6e4259..856bc53018c664fc3a5ca032c7f0d9ff84016fd4 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.33 2009/05/06 15:05:28 adamdunkels Exp $ + * $Id: xmac.c,v 1.34 2009/06/22 11:14:11 nifi Exp $ */ /** @@ -745,6 +745,7 @@ turn_off(int keep_radio_on) const struct mac_driver xmac_driver = { "X-MAC", + xmac_init, qsend_packet, read_packet, set_receive_function, diff --git a/platform/sky/contiki-conf.h b/platform/sky/contiki-conf.h index 86210cce0afc73acfab1cd734fe92b3aae66a831..3285804b15b7b097e6c175ffc2d4523fcc181669 100644 --- a/platform/sky/contiki-conf.h +++ b/platform/sky/contiki-conf.h @@ -1,9 +1,12 @@ /* -*- C -*- */ -/* @(#)$Id: contiki-conf.h,v 1.53 2009/05/18 10:32:56 fros4943 Exp $ */ +/* @(#)$Id: contiki-conf.h,v 1.54 2009/06/22 11:14:11 nifi Exp $ */ #ifndef CONTIKI_CONF_H #define CONTIKI_CONF_H +/* Specifies the default MAC driver */ +#define MAC_CONF_DRIVER xmac_driver + #define XMAC_CONF_COMPOWER 1 #define XMAC_CONF_ANNOUNCEMENTS 1 #define RIME_CONF_NO_POLITE_ANNOUCEMENTS 1 diff --git a/platform/sky/contiki-sky-main.c b/platform/sky/contiki-sky-main.c index bcf954f6af9ad6d09cfdc53b298cf3e9ae5c4011..092c18ec0efd9dc38ee19273fbe59e9e6d8ba5ac 100644 --- a/platform/sky/contiki-sky-main.c +++ b/platform/sky/contiki-sky-main.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)$Id: contiki-sky-main.c,v 1.55 2009/05/12 17:32:49 adamdunkels Exp $ + * @(#)$Id: contiki-sky-main.c,v 1.56 2009/06/22 11:14:11 nifi Exp $ */ #include <signal.h> @@ -53,9 +53,6 @@ #include "lib/random.h" #include "net/mac/frame802154.h" -#include "net/mac/nullmac.h" -#include "net/mac/xmac.h" -#include "net/mac/lpp.h" #if WITH_UIP6 #include "net/sicslowpan.h" @@ -106,6 +103,20 @@ static uint8_t is_gateway; #include "experiment-setup.h" #endif +#if WITH_NULLMAC +#define MAC_DRIVER nullmac_driver +#endif /* WITH_NULLMAC */ + +#ifndef MAC_DRIVER +#ifdef MAC_CONF_DRIVER +#define MAC_DRIVER MAC_CONF_DRIVER +#else +#define MAC_DRIVER xmac_driver +#endif /* MAC_CONF_DRIVER */ +#endif /* MAC_DRIVER */ + +extern const struct mac_driver MAC_DRIVER; + /*---------------------------------------------------------------------------*/ #if 0 int @@ -271,11 +282,7 @@ main(int argc, char **argv) uip_router_register(&rimeroute); #endif /* UIP_CONF_ROUTER */ #else /* WITH_UIP6 */ -#if WITH_NULLMAC - rime_init(nullmac_init(&cc2420_driver)); -#else /* WITH_NULLMAC */ - rime_init(xmac_init(&cc2420_driver)); -#endif /* WITH_NULLMAC */ + rime_init(MAC_DRIVER.init(&cc2420_driver)); printf(" %s channel %u\n", rime_mac->name, RF_CHANNEL); #endif /* WITH_UIP6 */