2007-03-15 21:44:28 +00: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 15:18:02 +00:00
|
|
|
#include "contiki.h"
|
2017-10-31 21:12:47 +00:00
|
|
|
#include "sys/energest.h"
|
2013-11-28 13:04:34 +00:00
|
|
|
#include "cc2420.h"
|
2013-11-28 14:01:40 +00:00
|
|
|
#include "dev/ds2411/ds2411.h"
|
2007-03-15 21:44:28 +00:00
|
|
|
#include "dev/leds.h"
|
2009-03-17 15:56:32 +00:00
|
|
|
#include "dev/serial-line.h"
|
2007-03-22 19:04:43 +00:00
|
|
|
#include "dev/slip.h"
|
2007-03-15 21:44:28 +00:00
|
|
|
#include "dev/uart1.h"
|
2008-02-03 21:03:19 +00:00
|
|
|
#include "dev/watchdog.h"
|
|
|
|
#include "dev/xmem.h"
|
2009-03-01 20:42:10 +00: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 21:48:39 +00:00
|
|
|
#include "net/netstack.h"
|
2017-05-16 16:20:34 +00:00
|
|
|
#include "net/mac/framer/frame802154.h"
|
2018-10-03 11:36:46 +00:00
|
|
|
#include "net/mac/tsch/tsch.h"
|
2009-04-06 14:12:58 +00:00
|
|
|
|
2014-12-01 20:02:57 +00:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2013-11-22 08:17:54 +00:00
|
|
|
#include "net/ipv6/uip-ds6.h"
|
2014-12-01 20:02:57 +00:00
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
2009-04-06 14:12:58 +00:00
|
|
|
|
2012-11-20 18:57:20 +00:00
|
|
|
#include "sys/node-id.h"
|
2008-11-05 15:34:04 +00:00
|
|
|
#include "cfs-coffee-arch.h"
|
|
|
|
#include "cfs/cfs-coffee.h"
|
2007-03-15 21:44:28 +00:00
|
|
|
|
2009-02-04 19:32:20 +00:00
|
|
|
#if DCOSYNCH_CONF_ENABLED
|
|
|
|
static struct timer mgt_timer;
|
|
|
|
#endif
|
2011-01-05 12:04:23 +00:00
|
|
|
extern int msp430_dco_required;
|
2009-02-04 19:32:20 +00:00
|
|
|
|
2008-11-09 12:22:04 +00:00
|
|
|
#define UIP_OVER_MESH_CHANNEL 8
|
2008-02-03 21:03:19 +00:00
|
|
|
|
2007-10-23 21:29:40 +00:00
|
|
|
#ifdef EXPERIMENT_SETUP
|
|
|
|
#include "experiment-setup.h"
|
|
|
|
#endif
|
|
|
|
|
2010-05-03 13:51:11 +00:00
|
|
|
void init_platform(void);
|
2017-10-17 23:17:51 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Log configuration */
|
|
|
|
#include "sys/log.h"
|
|
|
|
#define LOG_MODULE "Sky"
|
|
|
|
#define LOG_LEVEL LOG_LEVEL_MAIN
|
2007-03-15 21:44:28 +00: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 14:17:38 +00:00
|
|
|
|
2007-03-15 21:44:28 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-01-14 20:18:23 +00:00
|
|
|
#if 0
|
2007-05-22 21:13:26 +00:00
|
|
|
void
|
|
|
|
force_inclusion(int d1, int d2)
|
|
|
|
{
|
|
|
|
snprintf(NULL, 0, "%d", d1 % d2);
|
|
|
|
}
|
2010-01-14 20:18:23 +00:00
|
|
|
#endif
|
2007-05-22 21:13:26 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-25 17:21:49 +00:00
|
|
|
static void
|
2017-06-22 16:27:04 +00:00
|
|
|
set_lladdr(void)
|
2007-03-25 17:21:49 +00:00
|
|
|
{
|
2013-12-12 22:58:52 +00:00
|
|
|
linkaddr_t addr;
|
2008-11-06 15:14:24 +00:00
|
|
|
|
2013-12-12 22:58:52 +00:00
|
|
|
memset(&addr, 0, sizeof(linkaddr_t));
|
2014-12-01 20:02:57 +00:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2008-11-06 15:14:24 +00:00
|
|
|
memcpy(addr.u8, ds2411_id, sizeof(addr.u8));
|
|
|
|
#else
|
2018-05-16 18:25:14 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < sizeof(linkaddr_t); ++i) {
|
|
|
|
addr.u8[i] = ds2411_id[7 - i];
|
2007-12-17 12:35:23 +00:00
|
|
|
}
|
2008-11-06 15:14:24 +00:00
|
|
|
#endif
|
2013-12-12 22:58:52 +00:00
|
|
|
linkaddr_set_node_addr(&addr);
|
2007-11-21 16:41:44 +00:00
|
|
|
}
|
2008-02-24 21:13:03 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2017-10-15 16:09:04 +00:00
|
|
|
void
|
|
|
|
platform_init_stage_one(void)
|
2007-03-15 21:44:28 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Initalize hardware.
|
|
|
|
*/
|
|
|
|
msp430_cpu_init();
|
2017-10-15 16:09:04 +00:00
|
|
|
|
2007-03-15 21:44:28 +00:00
|
|
|
leds_init();
|
2007-11-10 20:44:30 +00:00
|
|
|
leds_on(LEDS_RED);
|
2017-10-15 16:09:04 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
platform_init_stage_two(void)
|
|
|
|
{
|
2008-02-11 10:44:12 +00:00
|
|
|
uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
|
2008-11-21 10:35:46 +00:00
|
|
|
|
2007-11-10 20:44:30 +00:00
|
|
|
leds_on(LEDS_GREEN);
|
2007-03-15 21:44:28 +00:00
|
|
|
ds2411_init();
|
2008-09-14 20:47:30 +00:00
|
|
|
|
2009-04-10 00:40:08 +00: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 14:08:15 +00:00
|
|
|
|
2007-11-10 20:44:30 +00:00
|
|
|
leds_on(LEDS_BLUE);
|
2007-03-15 21:44:28 +00:00
|
|
|
xmem_init();
|
2007-04-03 19:04:50 +00:00
|
|
|
|
2007-11-10 20:44:30 +00:00
|
|
|
leds_off(LEDS_RED);
|
2007-03-15 21:44:28 +00:00
|
|
|
/*
|
|
|
|
* Hardware initialization done!
|
|
|
|
*/
|
2007-03-23 16:05:47 +00:00
|
|
|
|
2018-05-16 18:25:14 +00:00
|
|
|
random_init(ds2411_id[0]);
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2007-11-10 20:44:30 +00:00
|
|
|
leds_off(LEDS_BLUE);
|
2017-10-15 16:09:04 +00:00
|
|
|
|
|
|
|
set_lladdr();
|
|
|
|
|
2008-03-03 20:23:53 +00:00
|
|
|
/*
|
2017-10-15 16:09:04 +00:00
|
|
|
* main() will turn the radio on inside netstack_init(). The CC2420
|
|
|
|
* must already be initialised by that time, so we do this here early.
|
|
|
|
* Later on in stage three we set correct values for PANID and radio
|
|
|
|
* short/long address.
|
2008-03-03 20:23:53 +00:00
|
|
|
*/
|
2017-10-15 16:09:04 +00:00
|
|
|
cc2420_init();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
platform_init_stage_three(void)
|
|
|
|
{
|
|
|
|
uint8_t longaddr[8];
|
|
|
|
uint16_t shortaddr;
|
2008-03-03 20:23:53 +00:00
|
|
|
|
2010-05-03 13:51:11 +00:00
|
|
|
init_platform();
|
|
|
|
|
2017-10-15 16:09:04 +00:00
|
|
|
shortaddr = (linkaddr_node_addr.u8[0] << 8) + linkaddr_node_addr.u8[1];
|
|
|
|
memset(longaddr, 0, sizeof(longaddr));
|
|
|
|
linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr);
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2017-10-15 16:09:04 +00:00
|
|
|
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
|
2008-11-05 15:34:04 +00:00
|
|
|
|
2018-04-13 09:58:40 +00:00
|
|
|
LOG_INFO("CC2420 CCA threshold %i\n", CC2420_CONF_CCA_THRESH);
|
2008-11-05 15:34:04 +00:00
|
|
|
|
2017-06-16 15:02:42 +00:00
|
|
|
#if !NETSTACK_CONF_WITH_IPV6
|
2009-03-17 15:56:32 +00:00
|
|
|
uart1_set_input(serial_line_input_byte);
|
|
|
|
serial_line_init();
|
2008-11-09 12:22:04 +00:00
|
|
|
#endif
|
2008-11-21 10:35:46 +00:00
|
|
|
|
2008-11-09 12:22:04 +00:00
|
|
|
leds_off(LEDS_GREEN);
|
|
|
|
|
2009-03-31 13:25:50 +00:00
|
|
|
#if TIMESYNCH_CONF_ENABLED
|
2008-11-09 12:22:04 +00:00
|
|
|
timesynch_init();
|
2013-12-12 22:58:52 +00:00
|
|
|
timesynch_set_authority_level((linkaddr_node_addr.u8[0] << 4) + 16);
|
2009-03-31 13:25:50 +00:00
|
|
|
#endif /* TIMESYNCH_CONF_ENABLED */
|
2008-11-09 12:22:04 +00:00
|
|
|
|
2007-03-15 21:44:28 +00:00
|
|
|
/*
|
|
|
|
* This is the scheduler loop.
|
|
|
|
*/
|
2009-02-04 19:32:20 +00:00
|
|
|
#if DCOSYNCH_CONF_ENABLED
|
|
|
|
timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND);
|
|
|
|
#endif
|
2017-10-15 16:09:04 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
platform_idle(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Idle processing.
|
|
|
|
*/
|
|
|
|
int s = splhigh(); /* Disable interrupts. */
|
|
|
|
/* uart1_active is for avoiding LPM3 when still sending or receiving */
|
|
|
|
if(process_nevents() != 0 || uart1_active()) {
|
|
|
|
splx(s); /* Re-enable interrupts. */
|
|
|
|
} else {
|
2009-02-04 19:32:20 +00:00
|
|
|
#if DCOSYNCH_CONF_ENABLED
|
2017-10-15 16:09:04 +00:00
|
|
|
/* before going down to sleep possibly do some management */
|
|
|
|
if(timer_expired(&mgt_timer)) {
|
|
|
|
watchdog_periodic();
|
|
|
|
timer_reset(&mgt_timer);
|
|
|
|
msp430_sync_dco();
|
2011-01-09 21:03:42 +00:00
|
|
|
#if CC2420_CONF_SFD_TIMESTAMPS
|
2017-10-15 16:09:04 +00:00
|
|
|
cc2420_arch_sfd_init();
|
2011-01-09 21:03:42 +00:00
|
|
|
#endif /* CC2420_CONF_SFD_TIMESTAMPS */
|
2017-10-15 16:09:04 +00:00
|
|
|
}
|
2009-02-04 19:32:20 +00:00
|
|
|
#endif
|
2017-05-13 11:09:58 +00:00
|
|
|
|
2017-10-15 16:09:04 +00:00
|
|
|
/* Re-enable interrupts and go to sleep atomically. */
|
|
|
|
ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM);
|
|
|
|
watchdog_stop();
|
|
|
|
/* 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
|
2011-01-05 12:04:23 +00:00
|
|
|
statement will block
|
|
|
|
until the CPU is
|
|
|
|
woken up by an
|
|
|
|
interrupt that sets
|
|
|
|
the wake up flag. */
|
2007-03-15 21:44:28 +00:00
|
|
|
}
|
2017-10-15 16:09:04 +00:00
|
|
|
watchdog_start();
|
|
|
|
ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
|
2007-03-15 21:44:28 +00:00
|
|
|
}
|
|
|
|
}
|