Provide boot sequence hooks (Sky)
This commit is contained in:
parent
d776ba035b
commit
902b8154b7
|
@ -3,11 +3,11 @@
|
||||||
ARCH=spi.c ds2411.c xmem.c i2c.c node-id.c sensors.c cfs-coffee.c \
|
ARCH=spi.c ds2411.c xmem.c i2c.c node-id.c sensors.c cfs-coffee.c \
|
||||||
cc2420.c cc2420-arch.c cc2420-arch-sfd.c \
|
cc2420.c cc2420-arch.c cc2420-arch-sfd.c \
|
||||||
sky-sensors.c uip-ipchksum.c \
|
sky-sensors.c uip-ipchksum.c \
|
||||||
uart1.c slip_uart1.c uart1-putchar.c
|
uart1.c slip_uart1.c uart1-putchar.c platform.c
|
||||||
|
|
||||||
CONTIKI_TARGET_DIRS = . dev apps net
|
CONTIKI_TARGET_DIRS = . dev apps net
|
||||||
ifndef CONTIKI_TARGET_MAIN
|
ifndef CONTIKI_TARGET_MAIN
|
||||||
CONTIKI_TARGET_MAIN = contiki-sky-main.c
|
CONTIKI_TARGET_MAIN = contiki-main.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef IAR
|
ifdef IAR
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include "lib/random.h"
|
#include "lib/random.h"
|
||||||
#include "net/netstack.h"
|
#include "net/netstack.h"
|
||||||
#include "net/mac/framer/frame802154.h"
|
#include "net/mac/framer/frame802154.h"
|
||||||
#include "net/queuebuf.h"
|
|
||||||
|
|
||||||
#if NETSTACK_CONF_WITH_IPV6
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
#include "net/ipv6/uip-ds6.h"
|
#include "net/ipv6/uip-ds6.h"
|
||||||
|
@ -53,13 +52,6 @@
|
||||||
#include "cfs/cfs-coffee.h"
|
#include "cfs/cfs-coffee.h"
|
||||||
#include "sys/autostart.h"
|
#include "sys/autostart.h"
|
||||||
|
|
||||||
#if BUILD_WITH_ORCHESTRA
|
|
||||||
#include "orchestra.h"
|
|
||||||
#endif /* BUILD_WITH_ORCHESTRA */
|
|
||||||
#if BUILD_WITH_SHELL
|
|
||||||
#include "serial-shell.h"
|
|
||||||
#endif /* BUILD_WITH_SHELL */
|
|
||||||
|
|
||||||
#if DCOSYNCH_CONF_ENABLED
|
#if DCOSYNCH_CONF_ENABLED
|
||||||
static struct timer mgt_timer;
|
static struct timer mgt_timer;
|
||||||
#endif
|
#endif
|
||||||
|
@ -150,18 +142,21 @@ print_processes(struct process * const processes[])
|
||||||
uint16_t TOS_NODE_ID = 0x1234; /* non-zero */
|
uint16_t TOS_NODE_ID = 0x1234; /* non-zero */
|
||||||
uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */
|
uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */
|
||||||
#endif /* WITH_TINYOS_AUTO_IDS */
|
#endif /* WITH_TINYOS_AUTO_IDS */
|
||||||
int
|
void
|
||||||
main(int argc, char **argv)
|
platform_init_stage_one(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Initalize hardware.
|
* Initalize hardware.
|
||||||
*/
|
*/
|
||||||
msp430_cpu_init();
|
msp430_cpu_init();
|
||||||
clock_init();
|
|
||||||
leds_init();
|
leds_init();
|
||||||
leds_on(LEDS_RED);
|
leds_on(LEDS_RED);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
platform_init_stage_two(void)
|
||||||
|
{
|
||||||
uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
|
uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
|
||||||
|
|
||||||
leds_on(LEDS_GREEN);
|
leds_on(LEDS_GREEN);
|
||||||
|
@ -176,16 +171,10 @@ main(int argc, char **argv)
|
||||||
xmem_init();
|
xmem_init();
|
||||||
|
|
||||||
leds_off(LEDS_RED);
|
leds_off(LEDS_RED);
|
||||||
rtimer_init();
|
|
||||||
/*
|
/*
|
||||||
* Hardware initialization done!
|
* Hardware initialization done!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Initialize energest first (but after rtimer)
|
|
||||||
*/
|
|
||||||
energest_init();
|
|
||||||
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
|
||||||
|
|
||||||
#if WITH_TINYOS_AUTO_IDS
|
#if WITH_TINYOS_AUTO_IDS
|
||||||
node_id = TOS_NODE_ID;
|
node_id = TOS_NODE_ID;
|
||||||
#else /* WITH_TINYOS_AUTO_IDS */
|
#else /* WITH_TINYOS_AUTO_IDS */
|
||||||
|
@ -205,63 +194,47 @@ main(int argc, char **argv)
|
||||||
random_init(ds2411_id[0] + node_id);
|
random_init(ds2411_id[0] + node_id);
|
||||||
|
|
||||||
leds_off(LEDS_BLUE);
|
leds_off(LEDS_BLUE);
|
||||||
/*
|
|
||||||
* Initialize Contiki and our processes.
|
|
||||||
*/
|
|
||||||
process_init();
|
|
||||||
process_start(&etimer_process, NULL);
|
|
||||||
|
|
||||||
ctimer_init();
|
|
||||||
|
|
||||||
init_platform();
|
|
||||||
|
|
||||||
set_lladdr();
|
set_lladdr();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
cc2420_init();
|
cc2420_init();
|
||||||
{
|
}
|
||||||
uint8_t longaddr[8];
|
/*---------------------------------------------------------------------------*/
|
||||||
uint16_t shortaddr;
|
void
|
||||||
|
platform_init_stage_three(void)
|
||||||
|
{
|
||||||
|
uint8_t longaddr[8];
|
||||||
|
uint16_t shortaddr;
|
||||||
|
|
||||||
shortaddr = (linkaddr_node_addr.u8[0] << 8) +
|
init_platform();
|
||||||
linkaddr_node_addr.u8[1];
|
|
||||||
memset(longaddr, 0, sizeof(longaddr));
|
|
||||||
linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr);
|
|
||||||
PRINTF("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
|
|
||||||
longaddr[0], longaddr[1], longaddr[2], longaddr[3],
|
|
||||||
longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
|
|
||||||
|
|
||||||
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
|
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);
|
||||||
|
PRINTF("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
|
||||||
|
longaddr[0], longaddr[1], longaddr[2], longaddr[3],
|
||||||
|
longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
|
||||||
|
|
||||||
|
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
|
||||||
|
|
||||||
PRINTF(CONTIKI_VERSION_STRING " started. ");
|
|
||||||
if(node_id > 0) {
|
if(node_id > 0) {
|
||||||
PRINTF("Node id is set to %u.\n", node_id);
|
PRINTF("Node id is set to %u.\n", node_id);
|
||||||
} else {
|
} else {
|
||||||
PRINTF("Node id is not set.\n");
|
PRINTF("Node id is not set.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PRINTF("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
|
|
||||||
ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
|
|
||||||
ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);*/
|
|
||||||
|
|
||||||
#if NETSTACK_CONF_WITH_IPV6
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr));
|
|
||||||
/* Setup nullmac-like MAC for 802.15.4 */
|
|
||||||
/* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */
|
|
||||||
/* PRINTF(" %s channel %u\n", sicslowmac_driver.name, CC2420_CONF_CCA_THRESH); */
|
|
||||||
|
|
||||||
/* Setup X-MAC for 802.15.4 */
|
|
||||||
queuebuf_init();
|
|
||||||
NETSTACK_MAC.init();
|
|
||||||
NETSTACK_NETWORK.init();
|
|
||||||
|
|
||||||
PRINTF("%s, radio channel %u, CCA threshold %i\n",
|
PRINTF("%s, radio channel %u, CCA threshold %i\n",
|
||||||
NETSTACK_MAC.name,
|
NETSTACK_MAC.name,
|
||||||
CC2420_CONF_CHANNEL,
|
CC2420_CONF_CHANNEL,
|
||||||
CC2420_CONF_CCA_THRESH);
|
CC2420_CONF_CCA_THRESH);
|
||||||
|
|
||||||
process_start(&tcpip_process, NULL);
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
PRINTF("Tentative link-local IPv6 address ");
|
PRINTF("Tentative link-local IPv6 address ");
|
||||||
{
|
{
|
||||||
|
@ -291,10 +264,6 @@ main(int argc, char **argv)
|
||||||
ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
|
ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
|
||||||
}
|
}
|
||||||
#else /* NETSTACK_CONF_WITH_IPV6 */
|
#else /* NETSTACK_CONF_WITH_IPV6 */
|
||||||
|
|
||||||
NETSTACK_MAC.init();
|
|
||||||
NETSTACK_NETWORK.init();
|
|
||||||
|
|
||||||
PRINTF("%s, radio channel %u\n",
|
PRINTF("%s, radio channel %u\n",
|
||||||
NETSTACK_MAC.name, CC2420_CONF_CHANNEL);
|
NETSTACK_MAC.name, CC2420_CONF_CHANNEL);
|
||||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||||
|
@ -311,19 +280,9 @@ main(int argc, char **argv)
|
||||||
timesynch_set_authority_level((linkaddr_node_addr.u8[0] << 4) + 16);
|
timesynch_set_authority_level((linkaddr_node_addr.u8[0] << 4) + 16);
|
||||||
#endif /* TIMESYNCH_CONF_ENABLED */
|
#endif /* TIMESYNCH_CONF_ENABLED */
|
||||||
|
|
||||||
watchdog_start();
|
|
||||||
|
|
||||||
#if BUILD_WITH_ORCHESTRA
|
|
||||||
orchestra_init();
|
|
||||||
#endif /* BUILD_WITH_ORCHESTRA */
|
|
||||||
#if BUILD_WITH_SHELL
|
|
||||||
serial_shell_init();
|
|
||||||
#endif /* BUILD_WITH_SHELL */
|
|
||||||
|
|
||||||
#if !PROCESS_CONF_NO_PROCESS_NAMES
|
#if !PROCESS_CONF_NO_PROCESS_NAMES
|
||||||
print_processes(autostart_processes);
|
print_processes(autostart_processes);
|
||||||
#endif /* !PROCESS_CONF_NO_PROCESS_NAMES */
|
#endif /* !PROCESS_CONF_NO_PROCESS_NAMES */
|
||||||
autostart_start(autostart_processes);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the scheduler loop.
|
* This is the scheduler loop.
|
||||||
|
@ -331,54 +290,46 @@ main(int argc, char **argv)
|
||||||
#if DCOSYNCH_CONF_ENABLED
|
#if DCOSYNCH_CONF_ENABLED
|
||||||
timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND);
|
timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
/* watchdog_stop();*/
|
/*---------------------------------------------------------------------------*/
|
||||||
while(1) {
|
void
|
||||||
int r;
|
platform_idle(void)
|
||||||
do {
|
{
|
||||||
/* Reset watchdog. */
|
/*
|
||||||
watchdog_periodic();
|
* Idle processing.
|
||||||
r = process_run();
|
*/
|
||||||
} while(r > 0);
|
int s = splhigh(); /* Disable interrupts. */
|
||||||
|
/* uart1_active is for avoiding LPM3 when still sending or receiving */
|
||||||
/*
|
if(process_nevents() != 0 || uart1_active()) {
|
||||||
* Idle processing.
|
splx(s); /* Re-enable interrupts. */
|
||||||
*/
|
} else {
|
||||||
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 {
|
|
||||||
#if DCOSYNCH_CONF_ENABLED
|
#if DCOSYNCH_CONF_ENABLED
|
||||||
/* before going down to sleep possibly do some management */
|
/* before going down to sleep possibly do some management */
|
||||||
if(timer_expired(&mgt_timer)) {
|
if(timer_expired(&mgt_timer)) {
|
||||||
watchdog_periodic();
|
watchdog_periodic();
|
||||||
timer_reset(&mgt_timer);
|
timer_reset(&mgt_timer);
|
||||||
msp430_sync_dco();
|
msp430_sync_dco();
|
||||||
#if CC2420_CONF_SFD_TIMESTAMPS
|
#if CC2420_CONF_SFD_TIMESTAMPS
|
||||||
cc2420_arch_sfd_init();
|
cc2420_arch_sfd_init();
|
||||||
#endif /* CC2420_CONF_SFD_TIMESTAMPS */
|
#endif /* CC2420_CONF_SFD_TIMESTAMPS */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Re-enable interrupts and go to sleep atomically. */
|
/* Re-enable interrupts and go to sleep atomically. */
|
||||||
ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM);
|
ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM);
|
||||||
watchdog_stop();
|
watchdog_stop();
|
||||||
/* check if the DCO needs to be on - if so - only LPM 1 */
|
/* check if the DCO needs to be on - if so - only LPM 1 */
|
||||||
if (msp430_dco_required) {
|
if (msp430_dco_required) {
|
||||||
_BIS_SR(GIE | CPUOFF); /* LPM1 sleep for DMA to work!. */
|
_BIS_SR(GIE | CPUOFF); /* LPM1 sleep for DMA to work!. */
|
||||||
} else {
|
} else {
|
||||||
_BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
|
_BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
|
||||||
statement will block
|
statement will block
|
||||||
until the CPU is
|
until the CPU is
|
||||||
woken up by an
|
woken up by an
|
||||||
interrupt that sets
|
interrupt that sets
|
||||||
the wake up flag. */
|
the wake up flag. */
|
||||||
}
|
|
||||||
watchdog_start();
|
|
||||||
ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
|
|
||||||
}
|
}
|
||||||
|
watchdog_start();
|
||||||
|
ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue