2007-03-15 22:44:28 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006, 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-09-11 17:18:02 +02:00
|
|
|
#include "contiki.h"
|
2013-11-28 14:04:34 +01:00
|
|
|
#include "cc2420.h"
|
2013-11-28 15:01:40 +01:00
|
|
|
#include "dev/ds2411/ds2411.h"
|
2007-03-15 22:44:28 +01:00
|
|
|
#include "dev/leds.h"
|
2009-03-17 16:56:32 +01:00
|
|
|
#include "dev/serial-line.h"
|
2007-03-22 20:04:43 +01:00
|
|
|
#include "dev/slip.h"
|
2007-03-15 22:44:28 +01:00
|
|
|
#include "dev/uart1.h"
|
2008-02-03 22:03:19 +01:00
|
|
|
#include "dev/watchdog.h"
|
|
|
|
#include "dev/xmem.h"
|
2009-03-01 21:42:10 +01:00
|
|
|
#include "lib/random.h"
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
#include "net/netstack.h"
|
2010-05-03 15:55:26 +02:00
|
|
|
#include "net/mac/frame802154.h"
|
2009-04-06 16:12:58 +02:00
|
|
|
|
2014-11-12 10:18:29 +01:00
|
|
|
#if UIP_CONF_IPV6
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ipv6/uip-ds6.h"
|
2014-11-12 10:18:29 +01:00
|
|
|
#endif /* UIP_CONF_IPV6 */
|
2009-04-06 16:12:58 +02:00
|
|
|
|
2013-12-12 20:50:07 +01:00
|
|
|
#include "net/rime/rime.h"
|
2007-03-22 00:26:34 +01:00
|
|
|
|
2012-11-20 19:57:20 +01:00
|
|
|
#include "sys/node-id.h"
|
2008-11-05 16:34:04 +01:00
|
|
|
#include "cfs-coffee-arch.h"
|
|
|
|
#include "cfs/cfs-coffee.h"
|
2007-03-15 22:44:28 +01:00
|
|
|
#include "sys/autostart.h"
|
|
|
|
|
2010-03-01 15:46:57 +01:00
|
|
|
#if UIP_CONF_ROUTER
|
|
|
|
|
|
|
|
#ifndef UIP_ROUTER_MODULE
|
|
|
|
#ifdef UIP_CONF_ROUTER_MODULE
|
|
|
|
#define UIP_ROUTER_MODULE UIP_CONF_ROUTER_MODULE
|
|
|
|
#else /* UIP_CONF_ROUTER_MODULE */
|
|
|
|
#define UIP_ROUTER_MODULE rimeroute
|
|
|
|
#endif /* UIP_CONF_ROUTER_MODULE */
|
|
|
|
#endif /* UIP_ROUTER_MODULE */
|
|
|
|
|
|
|
|
extern const struct uip_router UIP_ROUTER_MODULE;
|
|
|
|
#endif /* UIP_CONF_ROUTER */
|
|
|
|
|
2009-02-04 20:32:20 +01:00
|
|
|
#if DCOSYNCH_CONF_ENABLED
|
|
|
|
static struct timer mgt_timer;
|
|
|
|
#endif
|
2011-01-05 13:04:23 +01:00
|
|
|
extern int msp430_dco_required;
|
2009-02-04 20:32:20 +01:00
|
|
|
|
2014-11-12 10:18:29 +01:00
|
|
|
#ifndef UIP_CONF_IPV4
|
|
|
|
#define UIP_CONF_IPV4 0
|
2008-02-03 22:03:19 +01:00
|
|
|
#endif
|
2007-03-22 20:04:43 +01:00
|
|
|
|
2014-11-12 10:18:29 +01:00
|
|
|
#if UIP_CONF_IPV4
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ip/uip.h"
|
|
|
|
#include "net/ipv4/uip-fw.h"
|
2013-11-26 16:17:39 +01:00
|
|
|
#include "net/ipv4/uip-fw-drv.h"
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ipv4/uip-over-mesh.h"
|
2007-03-22 20:04:43 +01:00
|
|
|
static struct uip_fw_netif slipif =
|
2008-02-03 22:03:19 +01:00
|
|
|
{UIP_FW_NETIF(192,168,1,2, 255,255,255,255, slip_send)};
|
|
|
|
static struct uip_fw_netif meshif =
|
|
|
|
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
|
|
|
|
|
2014-11-12 10:18:29 +01:00
|
|
|
#endif /* UIP_CONF_IPV4 */
|
2008-11-05 16:34:04 +01:00
|
|
|
|
2008-11-09 13:22:04 +01:00
|
|
|
#define UIP_OVER_MESH_CHANNEL 8
|
2014-11-12 10:18:29 +01:00
|
|
|
#if UIP_CONF_IPV4
|
2008-11-09 13:22:04 +01:00
|
|
|
static uint8_t is_gateway;
|
2014-11-12 10:18:29 +01:00
|
|
|
#endif /* UIP_CONF_IPV4 */
|
2008-02-03 22:03:19 +01:00
|
|
|
|
2007-10-23 23:29:40 +02:00
|
|
|
#ifdef EXPERIMENT_SETUP
|
|
|
|
#include "experiment-setup.h"
|
|
|
|
#endif
|
|
|
|
|
2013-06-05 15:26:54 +02:00
|
|
|
#define DEBUG 1
|
|
|
|
#if DEBUG
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else /* DEBUG */
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2010-05-03 15:51:11 +02:00
|
|
|
void init_platform(void);
|
|
|
|
|
2007-03-15 22:44:28 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#if 0
|
|
|
|
int
|
|
|
|
force_float_inclusion()
|
|
|
|
{
|
|
|
|
extern int __fixsfsi;
|
|
|
|
extern int __floatsisf;
|
|
|
|
extern int __mulsf3;
|
|
|
|
extern int __subsf3;
|
|
|
|
|
|
|
|
return __fixsfsi + __floatsisf + __mulsf3 + __subsf3;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void uip_log(char *msg) { puts(msg); }
|
2013-11-07 15:17:38 +01:00
|
|
|
|
2007-03-15 22:44:28 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-01-14 21:18:23 +01:00
|
|
|
#if 0
|
2007-05-22 23:13:26 +02:00
|
|
|
void
|
|
|
|
force_inclusion(int d1, int d2)
|
|
|
|
{
|
|
|
|
snprintf(NULL, 0, "%d", d1 % d2);
|
|
|
|
}
|
2010-01-14 21:18:23 +01:00
|
|
|
#endif
|
2007-05-22 23:13:26 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-25 19:21:49 +02:00
|
|
|
static void
|
|
|
|
set_rime_addr(void)
|
|
|
|
{
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_t addr;
|
2007-12-17 13:35:23 +01:00
|
|
|
int i;
|
2008-11-06 16:14:24 +01:00
|
|
|
|
2013-12-12 23:58:52 +01:00
|
|
|
memset(&addr, 0, sizeof(linkaddr_t));
|
2008-11-06 16:14:24 +01:00
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
memcpy(addr.u8, ds2411_id, sizeof(addr.u8));
|
|
|
|
#else
|
2007-12-17 13:35:23 +01:00
|
|
|
if(node_id == 0) {
|
2013-12-12 23:58:52 +01:00
|
|
|
for(i = 0; i < sizeof(linkaddr_t); ++i) {
|
2007-12-17 13:35:23 +01:00
|
|
|
addr.u8[i] = ds2411_id[7 - i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addr.u8[0] = node_id & 0xff;
|
|
|
|
addr.u8[1] = node_id >> 8;
|
|
|
|
}
|
2008-11-06 16:14:24 +01:00
|
|
|
#endif
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_set_node_addr(&addr);
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("Rime started with address ");
|
2008-11-06 16:14:24 +01:00
|
|
|
for(i = 0; i < sizeof(addr.u8) - 1; i++) {
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("%d.", addr.u8[i]);
|
2008-11-06 16:14:24 +01:00
|
|
|
}
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("%d\n", addr.u8[i]);
|
2007-03-25 19:21:49 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-05-09 15:07:51 +02:00
|
|
|
#if !PROCESS_CONF_NO_PROCESS_NAMES
|
2007-11-21 17:41:44 +01:00
|
|
|
static void
|
2008-02-03 22:03:19 +01:00
|
|
|
print_processes(struct process * const processes[])
|
2007-11-21 17:41:44 +01:00
|
|
|
{
|
2008-02-03 22:03:19 +01:00
|
|
|
/* const struct process * const * p = processes;*/
|
2007-11-21 17:41:44 +01:00
|
|
|
printf("Starting");
|
|
|
|
while(*processes != NULL) {
|
|
|
|
printf(" '%s'", (*processes)->name);
|
|
|
|
processes++;
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2012-05-09 15:07:51 +02:00
|
|
|
#endif /* !PROCESS_CONF_NO_PROCESS_NAMES */
|
2007-11-21 17:41:44 +01:00
|
|
|
/*--------------------------------------------------------------------------*/
|
2014-11-12 10:18:29 +01:00
|
|
|
#if UIP_CONF_IPV4
|
2008-02-24 22:13:03 +01:00
|
|
|
static void
|
|
|
|
set_gateway(void)
|
|
|
|
{
|
|
|
|
if(!is_gateway) {
|
|
|
|
leds_on(LEDS_RED);
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("%d.%d: making myself the IP network gateway.\n\n",
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("IPv4 address of the gateway: %d.%d.%d.%d\n\n",
|
2009-05-12 19:32:49 +02:00
|
|
|
uip_ipaddr_to_quad(&uip_hostaddr));
|
2013-12-12 23:58:52 +01:00
|
|
|
uip_over_mesh_set_gateway(&linkaddr_node_addr);
|
2008-11-09 13:22:04 +01:00
|
|
|
uip_over_mesh_make_announced_gateway();
|
2008-02-24 22:13:03 +01:00
|
|
|
is_gateway = 1;
|
|
|
|
}
|
|
|
|
}
|
2014-11-12 10:18:29 +01:00
|
|
|
#endif /* UIP_CONF_IPV4 */
|
2008-02-24 22:13:03 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-05-24 15:14:40 +02:00
|
|
|
static void
|
|
|
|
start_autostart_processes()
|
|
|
|
{
|
|
|
|
#if !PROCESS_CONF_NO_PROCESS_NAMES
|
|
|
|
print_processes(autostart_processes);
|
|
|
|
#endif /* !PROCESS_CONF_NO_PROCESS_NAMES */
|
|
|
|
autostart_start(autostart_processes);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-11-12 10:18:29 +01:00
|
|
|
#if UIP_CONF_IPV6
|
2013-05-24 15:14:40 +02:00
|
|
|
static void
|
|
|
|
start_uip6()
|
|
|
|
{
|
|
|
|
NETSTACK_NETWORK.init();
|
|
|
|
|
|
|
|
process_start(&tcpip_process, NULL);
|
|
|
|
|
2013-06-05 15:26:54 +02:00
|
|
|
#if DEBUG
|
|
|
|
PRINTF("Tentative link-local IPv6 address ");
|
2013-05-24 15:14:40 +02:00
|
|
|
{
|
|
|
|
uip_ds6_addr_t *lladdr;
|
|
|
|
int i;
|
|
|
|
lladdr = uip_ds6_get_link_local(-1);
|
|
|
|
for(i = 0; i < 7; ++i) {
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("%02x%02x:", lladdr->ipaddr.u8[i * 2],
|
2013-05-24 15:14:40 +02:00
|
|
|
lladdr->ipaddr.u8[i * 2 + 1]);
|
|
|
|
}
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
|
2013-05-24 15:14:40 +02:00
|
|
|
}
|
2013-06-05 15:26:54 +02:00
|
|
|
#endif /* DEBUG */
|
2013-05-24 15:14:40 +02:00
|
|
|
|
|
|
|
if(!UIP_CONF_IPV6_RPL) {
|
|
|
|
uip_ipaddr_t ipaddr;
|
|
|
|
int i;
|
|
|
|
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
|
|
|
uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("Tentative global IPv6 address ");
|
2013-05-24 15:14:40 +02:00
|
|
|
for(i = 0; i < 7; ++i) {
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("%02x%02x:",
|
2013-05-24 15:14:40 +02:00
|
|
|
ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
|
|
|
|
}
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("%02x%02x\n",
|
2013-05-24 15:14:40 +02:00
|
|
|
ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
|
|
|
|
}
|
|
|
|
}
|
2014-11-12 10:18:29 +01:00
|
|
|
#endif /* UIP_CONF_IPV6 */
|
2013-05-24 15:14:40 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
start_network_layer()
|
|
|
|
{
|
2014-11-12 10:18:29 +01:00
|
|
|
#if UIP_CONF_IPV6
|
2013-05-24 15:14:40 +02:00
|
|
|
start_uip6();
|
2014-11-12 10:18:29 +01:00
|
|
|
#endif /* UIP_CONF_IPV6 */
|
2013-05-24 15:14:40 +02:00
|
|
|
start_autostart_processes();
|
2014-11-12 10:18:29 +01:00
|
|
|
/* To support link layer security in combination with UIP_CONF_IPV4 and
|
2013-05-24 15:14:40 +02:00
|
|
|
* TIMESYNCH_CONF_ENABLED further things may need to be moved here */
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-02-11 15:27:14 +01:00
|
|
|
#if WITH_TINYOS_AUTO_IDS
|
|
|
|
uint16_t TOS_NODE_ID = 0x1234; /* non-zero */
|
|
|
|
uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */
|
|
|
|
#endif /* WITH_TINYOS_AUTO_IDS */
|
2007-03-15 22:44:28 +01:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Initalize hardware.
|
|
|
|
*/
|
|
|
|
msp430_cpu_init();
|
|
|
|
clock_init();
|
|
|
|
leds_init();
|
2007-11-10 21:44:30 +01:00
|
|
|
leds_on(LEDS_RED);
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2010-12-16 23:52:12 +01:00
|
|
|
|
2008-02-11 11:44:12 +01:00
|
|
|
uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2007-11-10 21:44:30 +01:00
|
|
|
leds_on(LEDS_GREEN);
|
2007-03-15 22:44:28 +01:00
|
|
|
ds2411_init();
|
2008-09-14 22:47:30 +02:00
|
|
|
|
2009-04-10 02:40:08 +02:00
|
|
|
/* XXX hack: Fix it so that the 802.15.4 MAC address is compatible
|
|
|
|
with an Ethernet MAC address - byte 0 (byte 2 in the DS ID)
|
|
|
|
cannot be odd. */
|
|
|
|
ds2411_id[2] &= 0xfe;
|
2010-03-19 15:08:15 +01:00
|
|
|
|
2007-11-10 21:44:30 +01:00
|
|
|
leds_on(LEDS_BLUE);
|
2007-03-15 22:44:28 +01:00
|
|
|
xmem_init();
|
2007-04-03 21:04:50 +02:00
|
|
|
|
2007-11-10 21:44:30 +01:00
|
|
|
leds_off(LEDS_RED);
|
2007-04-03 21:04:50 +02:00
|
|
|
rtimer_init();
|
2007-03-15 22:44:28 +01:00
|
|
|
/*
|
|
|
|
* Hardware initialization done!
|
|
|
|
*/
|
2007-03-23 17:05:47 +01:00
|
|
|
|
2014-04-14 15:48:03 +02:00
|
|
|
/* Initialize energest first (but after rtimer)
|
|
|
|
*/
|
|
|
|
energest_init();
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
2009-04-10 02:40:08 +02:00
|
|
|
|
2011-02-11 15:27:14 +01:00
|
|
|
#if WITH_TINYOS_AUTO_IDS
|
|
|
|
node_id = TOS_NODE_ID;
|
|
|
|
#else /* WITH_TINYOS_AUTO_IDS */
|
2007-03-23 17:05:47 +01:00
|
|
|
/* Restore node id if such has been stored in external mem */
|
|
|
|
node_id_restore();
|
2011-02-11 15:27:14 +01:00
|
|
|
#endif /* WITH_TINYOS_AUTO_IDS */
|
2007-03-23 17:05:47 +01:00
|
|
|
|
2010-03-19 15:08:15 +01:00
|
|
|
/* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
|
|
|
|
#ifdef IEEE_802154_MAC_ADDRESS
|
|
|
|
{
|
|
|
|
uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
|
|
|
|
memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr));
|
|
|
|
ds2411_id[7] = node_id & 0xff;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-04-10 02:40:08 +02:00
|
|
|
random_init(ds2411_id[0] + node_id);
|
|
|
|
|
2007-11-10 21:44:30 +01:00
|
|
|
leds_off(LEDS_BLUE);
|
2008-03-03 21:23:53 +01:00
|
|
|
/*
|
|
|
|
* Initialize Contiki and our processes.
|
|
|
|
*/
|
|
|
|
process_init();
|
|
|
|
process_start(&etimer_process, NULL);
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2008-05-19 14:07:49 +02:00
|
|
|
ctimer_init();
|
2008-03-03 21:23:53 +01:00
|
|
|
|
2014-11-12 10:18:29 +01:00
|
|
|
#if UIP_CONF_IPV4
|
2012-05-30 12:59:42 +02:00
|
|
|
slip_arch_init(BAUD2UBR(115200));
|
2014-11-12 10:18:29 +01:00
|
|
|
#endif /* UIP_CONF_IPV4 */
|
2012-05-30 12:59:42 +02:00
|
|
|
|
2010-05-03 15:51:11 +02:00
|
|
|
init_platform();
|
|
|
|
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
set_rime_addr();
|
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_init();
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
{
|
|
|
|
uint8_t longaddr[8];
|
|
|
|
uint16_t shortaddr;
|
|
|
|
|
2013-12-12 23:58:52 +01:00
|
|
|
shortaddr = (linkaddr_node_addr.u8[0] << 8) +
|
|
|
|
linkaddr_node_addr.u8[1];
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
memset(longaddr, 0, sizeof(longaddr));
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr);
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
longaddr[0], longaddr[1], longaddr[2], longaddr[3],
|
|
|
|
longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
|
|
|
|
|
|
|
|
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
|
|
|
|
}
|
2008-11-05 16:34:04 +01:00
|
|
|
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF(CONTIKI_VERSION_STRING " started. ");
|
2007-11-21 17:41:44 +01:00
|
|
|
if(node_id > 0) {
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("Node id is set to %u.\n", node_id);
|
2007-11-21 17:41:44 +01:00
|
|
|
} else {
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("Node id is not set.\n");
|
2007-11-21 17:41:44 +01:00
|
|
|
}
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
|
2013-06-05 15:26:54 +02:00
|
|
|
/* PRINTF("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
|
2007-03-15 22:44:28 +01:00
|
|
|
ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);*/
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2014-11-12 10:18:29 +01:00
|
|
|
#if UIP_CONF_IPV6
|
2008-11-05 16:34:04 +01:00
|
|
|
memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr));
|
2009-10-19 22:55:52 +02:00
|
|
|
/* Setup nullmac-like MAC for 802.15.4 */
|
|
|
|
/* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */
|
2013-06-05 15:26:54 +02:00
|
|
|
/* PRINTF(" %s channel %u\n", sicslowmac_driver.name, CC2420_CONF_CCA_THRESH); */
|
2009-10-19 22:55:52 +02:00
|
|
|
|
|
|
|
/* Setup X-MAC for 802.15.4 */
|
|
|
|
queuebuf_init();
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
NETSTACK_RDC.init();
|
|
|
|
NETSTACK_MAC.init();
|
|
|
|
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("%s %s %s, channel check rate %lu Hz, radio channel %u, CCA threshold %i\n",
|
2013-05-24 15:14:40 +02:00
|
|
|
NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
|
2010-02-23 21:54:09 +01:00
|
|
|
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
|
|
|
|
NETSTACK_RDC.channel_check_interval()),
|
2013-11-07 15:17:38 +01:00
|
|
|
CC2420_CONF_CHANNEL,
|
|
|
|
CC2420_CONF_CCA_THRESH);
|
2009-10-19 22:55:52 +02:00
|
|
|
|
2014-11-12 10:18:29 +01:00
|
|
|
#else /* UIP_CONF_IPV6 */
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
|
|
|
|
NETSTACK_RDC.init();
|
|
|
|
NETSTACK_MAC.init();
|
|
|
|
NETSTACK_NETWORK.init();
|
|
|
|
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("%s %s %s, channel check rate %lu Hz, radio channel %u\n",
|
2013-05-24 15:14:40 +02:00
|
|
|
NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
|
2010-02-23 21:54:09 +01:00
|
|
|
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
|
|
|
|
NETSTACK_RDC.channel_check_interval()),
|
2014-02-18 11:42:02 +01:00
|
|
|
CC2420_CONF_CHANNEL);
|
2014-11-12 10:18:29 +01:00
|
|
|
#endif /* UIP_CONF_IPV6 */
|
2008-11-05 16:34:04 +01:00
|
|
|
|
2014-11-12 10:18:29 +01:00
|
|
|
#if !UIP_CONF_IPV4 && !UIP_CONF_IPV6
|
2009-03-17 16:56:32 +01:00
|
|
|
uart1_set_input(serial_line_input_byte);
|
|
|
|
serial_line_init();
|
2008-11-09 13:22:04 +01:00
|
|
|
#endif
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2008-11-09 13:22:04 +01:00
|
|
|
leds_off(LEDS_GREEN);
|
|
|
|
|
2009-03-31 15:25:50 +02:00
|
|
|
#if TIMESYNCH_CONF_ENABLED
|
2008-11-09 13:22:04 +01:00
|
|
|
timesynch_init();
|
2013-12-12 23:58:52 +01:00
|
|
|
timesynch_set_authority_level((linkaddr_node_addr.u8[0] << 4) + 16);
|
2009-03-31 15:25:50 +02:00
|
|
|
#endif /* TIMESYNCH_CONF_ENABLED */
|
2008-11-09 13:22:04 +01:00
|
|
|
|
2014-11-12 10:18:29 +01:00
|
|
|
#if UIP_CONF_IPV4
|
2008-11-09 13:22:04 +01:00
|
|
|
process_start(&tcpip_process, NULL);
|
|
|
|
process_start(&uip_fw_process, NULL); /* Start IP output */
|
|
|
|
process_start(&slip_process, NULL);
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2008-11-09 13:22:04 +01:00
|
|
|
slip_set_input_callback(set_gateway);
|
|
|
|
|
2008-02-03 22:03:19 +01:00
|
|
|
{
|
|
|
|
uip_ipaddr_t hostaddr, netmask;
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2008-02-03 22:03:19 +01:00
|
|
|
uip_init();
|
|
|
|
|
|
|
|
uip_ipaddr(&hostaddr, 172,16,
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_node_addr.u8[0],linkaddr_node_addr.u8[1]);
|
2008-02-03 22:03:19 +01:00
|
|
|
uip_ipaddr(&netmask, 255,255,0,0);
|
|
|
|
uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2008-02-03 22:03:19 +01:00
|
|
|
uip_sethostaddr(&hostaddr);
|
|
|
|
uip_setnetmask(&netmask);
|
|
|
|
uip_over_mesh_set_net(&hostaddr, &netmask);
|
|
|
|
/* uip_fw_register(&slipif);*/
|
|
|
|
uip_over_mesh_set_gateway_netif(&slipif);
|
|
|
|
uip_fw_default(&meshif);
|
|
|
|
uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
|
2013-06-05 15:26:54 +02:00
|
|
|
PRINTF("uIP started with IP address %d.%d.%d.%d\n",
|
2008-02-24 22:13:03 +01:00
|
|
|
uip_ipaddr_to_quad(&hostaddr));
|
2008-02-03 22:03:19 +01:00
|
|
|
}
|
2014-11-12 10:18:29 +01:00
|
|
|
#endif /* UIP_CONF_IPV4 */
|
2007-03-22 20:04:43 +01:00
|
|
|
|
2010-03-19 14:28:27 +01:00
|
|
|
watchdog_start();
|
|
|
|
|
2013-05-24 15:14:40 +02:00
|
|
|
NETSTACK_LLSEC.bootstrap(start_network_layer);
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2007-03-15 22:44:28 +01:00
|
|
|
/*
|
|
|
|
* This is the scheduler loop.
|
|
|
|
*/
|
2009-02-04 20:32:20 +01:00
|
|
|
#if DCOSYNCH_CONF_ENABLED
|
|
|
|
timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND);
|
|
|
|
#endif
|
2010-03-19 14:28:27 +01:00
|
|
|
|
2008-03-03 21:23:53 +01:00
|
|
|
/* watchdog_stop();*/
|
2008-11-05 16:34:04 +01:00
|
|
|
while(1) {
|
2007-10-23 23:29:40 +02:00
|
|
|
int r;
|
2007-03-15 22:44:28 +01:00
|
|
|
do {
|
|
|
|
/* Reset watchdog. */
|
2007-11-17 11:29:33 +01:00
|
|
|
watchdog_periodic();
|
2007-10-23 23:29:40 +02:00
|
|
|
r = process_run();
|
|
|
|
} while(r > 0);
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2007-03-15 22:44:28 +01:00
|
|
|
/*
|
|
|
|
* Idle processing.
|
|
|
|
*/
|
|
|
|
int s = splhigh(); /* Disable interrupts. */
|
2009-01-31 13:45:03 +01:00
|
|
|
/* uart1_active is for avoiding LPM3 when still sending or receiving */
|
|
|
|
if(process_nevents() != 0 || uart1_active()) {
|
2007-03-15 22:44:28 +01:00
|
|
|
splx(s); /* Re-enable interrupts. */
|
|
|
|
} else {
|
2007-05-22 23:13:26 +02:00
|
|
|
static unsigned long irq_energest = 0;
|
2009-02-04 20:32:20 +01:00
|
|
|
|
|
|
|
#if DCOSYNCH_CONF_ENABLED
|
|
|
|
/* before going down to sleep possibly do some management */
|
2010-12-16 23:52:12 +01:00
|
|
|
if(timer_expired(&mgt_timer)) {
|
|
|
|
watchdog_periodic();
|
2009-02-04 20:32:20 +01:00
|
|
|
timer_reset(&mgt_timer);
|
|
|
|
msp430_sync_dco();
|
2011-01-09 22:03:42 +01:00
|
|
|
#if CC2420_CONF_SFD_TIMESTAMPS
|
2010-12-16 23:52:12 +01:00
|
|
|
cc2420_arch_sfd_init();
|
2011-01-09 22:03:42 +01:00
|
|
|
#endif /* CC2420_CONF_SFD_TIMESTAMPS */
|
2009-02-04 20:32:20 +01:00
|
|
|
}
|
|
|
|
#endif
|
2010-12-16 23:52:12 +01:00
|
|
|
|
2007-03-15 22:44:28 +01:00
|
|
|
/* Re-enable interrupts and go to sleep atomically. */
|
2007-05-22 23:13:26 +02:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_CPU);
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_LPM);
|
|
|
|
/* We only want to measure the processing done in IRQs when we
|
|
|
|
are asleep, so we discard the processing time done when we
|
|
|
|
were awake. */
|
|
|
|
energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
|
2007-11-17 11:29:33 +01:00
|
|
|
watchdog_stop();
|
2011-01-05 13:04:23 +01:00
|
|
|
/* check if the DCO needs to be on - if so - only LPM 1 */
|
|
|
|
if (msp430_dco_required) {
|
|
|
|
_BIS_SR(GIE | CPUOFF); /* LPM1 sleep for DMA to work!. */
|
|
|
|
} else {
|
|
|
|
_BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
|
|
|
|
statement will block
|
|
|
|
until the CPU is
|
|
|
|
woken up by an
|
|
|
|
interrupt that sets
|
|
|
|
the wake up flag. */
|
|
|
|
}
|
2007-05-22 23:13:26 +02:00
|
|
|
/* We get the current processing time for interrupts that was
|
|
|
|
done during the LPM and store it for next time around. */
|
|
|
|
dint();
|
|
|
|
irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
|
|
|
|
eint();
|
2007-11-17 11:29:33 +01:00
|
|
|
watchdog_start();
|
2007-05-22 23:13:26 +02:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_LPM);
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
2007-03-15 22:44:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-11-21 11:35:46 +01:00
|
|
|
#if LOG_CONF_ENABLED
|
|
|
|
void
|
|
|
|
log_message(char *m1, char *m2)
|
|
|
|
{
|
|
|
|
printf("%s%s\n", m1, m2);
|
|
|
|
}
|
|
|
|
#endif /* LOG_CONF_ENABLED */
|