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.

This commit is contained in:
nifi 2010-02-23 20:09:11 +00:00
parent bb62749de7
commit c20047f657
18 changed files with 135 additions and 61 deletions

View file

@ -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,

View file

@ -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__ */

View file

@ -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,

View file

@ -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__ */

View file

@ -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,

View file

@ -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__ */

View file

@ -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,

View file

@ -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__ */

73
core/net/mac/rdc.h Normal file
View file

@ -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 <adam@sics.se>
* Niclas Finne <nfi@sics.se>
*/
#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__ */

View file

@ -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,

View file

@ -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__ */

View file

@ -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,

View file

@ -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);

View file

@ -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);

View file

@ -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 {

View file

@ -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
};
/** @} */

View file

@ -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
};
/*--------------------------------------------------------------------*/
/** @} */

View file

@ -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__ */