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.
|
|
|
|
*
|
2007-11-10 20:44:30 +00:00
|
|
|
* @(#)$Id: contiki-sky-main.c,v 1.14 2007/11/10 20:44:30 adamdunkels Exp $
|
2007-03-15 21:44:28 +00:00
|
|
|
*/
|
|
|
|
|
2007-05-22 21:13:26 +00:00
|
|
|
#include <signal.h>
|
2007-03-15 21:44:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <io.h>
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
|
2007-03-21 23:26:34 +00:00
|
|
|
#include "dev/button-sensor.h"
|
2007-03-15 21:44:28 +00:00
|
|
|
#include "dev/ds2411.h"
|
2007-05-22 21:13:26 +00:00
|
|
|
#include "dev/sht11.h"
|
2007-03-15 21:44:28 +00:00
|
|
|
#include "dev/leds.h"
|
|
|
|
#include "dev/light.h"
|
|
|
|
#include "dev/xmem.h"
|
|
|
|
#include "dev/simple-cc2420.h"
|
2007-05-22 21:13:26 +00:00
|
|
|
|
2007-03-22 19:04:43 +00:00
|
|
|
#include "dev/slip.h"
|
2007-03-15 21:44:28 +00:00
|
|
|
#include "dev/uart1.h"
|
2007-03-21 23:26:34 +00:00
|
|
|
|
2007-05-22 21:13:26 +00:00
|
|
|
#include "net/mac/xmac.h"
|
2007-11-10 20:44:30 +00:00
|
|
|
#include "net/mac/cxmac.h"
|
2007-05-22 21:13:26 +00:00
|
|
|
#include "net/mac/nullmac.h"
|
|
|
|
|
2007-03-23 16:05:47 +00:00
|
|
|
#include "node-id.h"
|
|
|
|
|
2007-10-23 21:29:40 +00:00
|
|
|
#include "sys/profile.h"
|
2007-03-21 23:26:34 +00:00
|
|
|
#include "net/rime.h"
|
|
|
|
|
2007-03-15 21:44:28 +00:00
|
|
|
#include "sys/autostart.h"
|
|
|
|
|
|
|
|
/*#include "codeprop/codeprop.h"*/
|
|
|
|
|
|
|
|
SENSORS(&button_sensor);
|
2007-03-22 19:04:43 +00:00
|
|
|
|
2007-05-22 21:13:26 +00:00
|
|
|
#define WITH_UIP 0
|
2007-03-22 19:04:43 +00:00
|
|
|
|
|
|
|
#if WITH_UIP
|
|
|
|
static struct uip_fw_netif slipif =
|
|
|
|
{UIP_FW_NETIF(192,168,1,2, 255,255,255,255, slip_send)};
|
|
|
|
#endif /* WITH_UIP */
|
|
|
|
|
2007-10-23 21:29:40 +00:00
|
|
|
#ifdef EXPERIMENT_SETUP
|
|
|
|
#include "experiment-setup.h"
|
|
|
|
#endif
|
|
|
|
|
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); }
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Radio stuff in network byte order. */
|
|
|
|
static u16_t panId = 0x2024;
|
|
|
|
|
|
|
|
#define RF_CHANNEL 26
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-22 21:13:26 +00:00
|
|
|
void
|
|
|
|
force_inclusion(int d1, int d2)
|
|
|
|
{
|
|
|
|
snprintf(NULL, 0, "%d", d1 % d2);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-25 17:21:49 +00:00
|
|
|
static void
|
|
|
|
set_rime_addr(void)
|
|
|
|
{
|
|
|
|
rimeaddr_t addr;
|
|
|
|
addr.u16[0] = node_id;
|
|
|
|
rimeaddr_set_node_addr(&addr);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-15 21:44:28 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Initalize hardware.
|
|
|
|
*/
|
|
|
|
msp430_cpu_init();
|
|
|
|
clock_init();
|
|
|
|
leds_init();
|
2007-11-10 20:44:30 +00:00
|
|
|
leds_on(LEDS_RED);
|
2007-03-15 21:44:28 +00:00
|
|
|
|
2007-05-22 21:13:26 +00:00
|
|
|
#if WITH_UIP
|
2007-03-22 19:04:43 +00:00
|
|
|
slip_arch_init(BAUD2UBR(115200)); /* Must come before first printf */
|
2007-05-22 21:13:26 +00:00
|
|
|
#else /* WITH_UIP */
|
|
|
|
uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
|
|
|
|
#endif /* WITH_UIP */
|
|
|
|
|
2007-03-15 21:44:28 +00:00
|
|
|
printf("Starting %s "
|
2007-11-10 20:44:30 +00:00
|
|
|
"($Id: contiki-sky-main.c,v 1.14 2007/11/10 20:44:30 adamdunkels Exp $)\n", __FILE__);
|
|
|
|
leds_on(LEDS_GREEN);
|
2007-03-15 21:44:28 +00:00
|
|
|
ds2411_init();
|
|
|
|
sensors_light_init();
|
2007-05-22 21:13:26 +00:00
|
|
|
sht11_init();
|
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-04-03 19:04:50 +00:00
|
|
|
rtimer_init();
|
2007-03-15 21:44:28 +00:00
|
|
|
/*
|
|
|
|
* Hardware initialization done!
|
|
|
|
*/
|
2007-03-23 16:05:47 +00:00
|
|
|
|
|
|
|
/* Restore node id if such has been stored in external mem */
|
|
|
|
node_id_restore();
|
|
|
|
|
2007-11-10 20:44:30 +00:00
|
|
|
leds_off(LEDS_BLUE);
|
|
|
|
|
2007-03-15 21:44:28 +00:00
|
|
|
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
|
|
|
|
ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);
|
|
|
|
|
2007-03-22 19:04:43 +00:00
|
|
|
#if WITH_UIP
|
|
|
|
uip_init();
|
|
|
|
uip_sethostaddr(&slipif.ipaddr);
|
|
|
|
uip_setnetmask(&slipif.netmask);
|
|
|
|
uip_fw_default(&slipif); /* Point2point, no default router. */
|
|
|
|
tcpip_set_forwarding(0);
|
|
|
|
#endif /* WITH_UIP */
|
|
|
|
|
2007-03-15 21:44:28 +00:00
|
|
|
/*
|
|
|
|
* Initialize Contiki and our processes.
|
|
|
|
*/
|
|
|
|
process_init();
|
|
|
|
process_start(&etimer_process, NULL);
|
|
|
|
process_start(&sensors_process, NULL);
|
2007-10-25 10:21:48 +00:00
|
|
|
#if PROFILE_CONF_ON
|
2007-10-23 21:29:40 +00:00
|
|
|
profile_init();
|
2007-10-25 10:21:48 +00:00
|
|
|
#endif /* PROFILE_CONF_ON */
|
2007-10-23 21:29:40 +00:00
|
|
|
ctimer_init();
|
2007-03-15 21:44:28 +00:00
|
|
|
|
2007-11-10 20:44:30 +00:00
|
|
|
leds_off(LEDS_GREEN);
|
|
|
|
|
2007-03-25 17:21:49 +00:00
|
|
|
set_rime_addr();
|
2007-03-15 21:44:28 +00:00
|
|
|
|
2007-05-25 08:08:36 +00:00
|
|
|
simple_cc2420_init();
|
2007-10-12 12:47:32 +00:00
|
|
|
simple_cc2420_set_chan_pan_addr(RF_CHANNEL, panId, 0 /*XXX*/, ds2411_id);
|
2007-10-23 21:29:40 +00:00
|
|
|
/* rime_init(nullmac_init(&simple_cc2420_driver));*/
|
|
|
|
rime_init(xmac_init(&simple_cc2420_driver));
|
2007-05-22 21:13:26 +00:00
|
|
|
|
2007-03-21 23:26:34 +00:00
|
|
|
/* rimeaddr_set_node_addr*/
|
2007-03-22 19:04:43 +00:00
|
|
|
#if WITH_UIP
|
|
|
|
process_start(&tcpip_process, NULL);
|
|
|
|
process_start(&uip_fw_process, NULL); /* Start IP output */
|
|
|
|
process_start(&slip_process, NULL);
|
|
|
|
#endif /* WITH_UIP */
|
2007-03-15 21:44:28 +00:00
|
|
|
|
2007-03-25 17:21:49 +00:00
|
|
|
button_sensor.activate();
|
|
|
|
|
2007-03-15 21:44:28 +00:00
|
|
|
printf("Autostarting processes\n");
|
|
|
|
autostart_start((struct process **) autostart_processes);
|
2007-05-22 21:13:26 +00:00
|
|
|
|
|
|
|
energest_init();
|
2007-03-15 21:44:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the scheduler loop.
|
|
|
|
*/
|
|
|
|
printf("process_run()...\n");
|
2007-05-22 21:13:26 +00:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
2007-03-15 21:44:28 +00:00
|
|
|
while (1) {
|
2007-10-23 21:29:40 +00:00
|
|
|
int r;
|
2007-10-25 10:21:48 +00:00
|
|
|
#if PROFILE_CONF_ON
|
2007-10-23 21:29:40 +00:00
|
|
|
profile_episode_start();
|
2007-10-25 10:21:48 +00:00
|
|
|
#endif /* PROFILE_CONF_ON */
|
2007-03-15 21:44:28 +00:00
|
|
|
do {
|
|
|
|
/* Reset watchdog. */
|
2007-10-23 21:29:40 +00:00
|
|
|
r = process_run();
|
|
|
|
} while(r > 0);
|
2007-10-25 10:21:48 +00:00
|
|
|
#if PROFILE_CONF_ON
|
2007-10-23 21:29:40 +00:00
|
|
|
profile_episode_end();
|
2007-10-25 10:21:48 +00:00
|
|
|
#endif /* PROFILE_CONF_ON */
|
|
|
|
|
2007-03-15 21:44:28 +00:00
|
|
|
/*
|
|
|
|
* Idle processing.
|
|
|
|
*/
|
|
|
|
int s = splhigh(); /* Disable interrupts. */
|
|
|
|
if(process_nevents() != 0) {
|
|
|
|
splx(s); /* Re-enable interrupts. */
|
|
|
|
} else {
|
2007-05-22 21:13:26 +00:00
|
|
|
static unsigned long irq_energest = 0;
|
2007-03-15 21:44:28 +00:00
|
|
|
/* Re-enable interrupts and go to sleep atomically. */
|
2007-05-22 21:13:26 +00: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-10-23 21:29:40 +00:00
|
|
|
|
|
|
|
_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 21:13:26 +00: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();
|
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_LPM);
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
2007-10-25 10:21:48 +00:00
|
|
|
#if PROFILE_CONF_ON
|
2007-10-23 21:29:40 +00:00
|
|
|
profile_clear_timestamps();
|
2007-10-25 10:21:48 +00:00
|
|
|
#endif /* PROFILE_CONF_ON */
|
2007-03-15 21:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|