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.
|
|
|
|
*
|
2009-04-06 16:12:58 +02:00
|
|
|
* @(#)$Id: contiki-sky-main.c,v 1.52 2009/04/06 14:12:58 nifi Exp $
|
2007-03-15 22:44:28 +01:00
|
|
|
*/
|
|
|
|
|
2007-05-22 23:13:26 +02:00
|
|
|
#include <signal.h>
|
2007-03-15 22:44:28 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <io.h>
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
|
2007-03-22 00:26:34 +01:00
|
|
|
#include "dev/button-sensor.h"
|
2007-03-15 22:44:28 +01:00
|
|
|
#include "dev/ds2411.h"
|
|
|
|
#include "dev/leds.h"
|
|
|
|
#include "dev/light.h"
|
2008-09-18 23:29:06 +02:00
|
|
|
#include "dev/battery-sensor.h"
|
2009-03-17 16:56:32 +01:00
|
|
|
#include "dev/serial-line.h"
|
2008-02-03 22:03:19 +01:00
|
|
|
#include "dev/sht11.h"
|
2008-07-01 23:02:51 +02:00
|
|
|
#include "dev/cc2420.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"
|
2007-03-22 00:26:34 +01:00
|
|
|
|
2009-03-01 21:42:10 +01:00
|
|
|
#include "lib/random.h"
|
|
|
|
|
2009-04-06 15:31:00 +02:00
|
|
|
#include "net/mac/frame802154.h"
|
2007-05-22 23:13:26 +02:00
|
|
|
#include "net/mac/nullmac.h"
|
2008-02-03 22:03:19 +01:00
|
|
|
#include "net/mac/xmac.h"
|
2009-02-11 12:08:53 +01:00
|
|
|
#include "net/mac/lpp.h"
|
2009-04-06 16:12:58 +02:00
|
|
|
|
|
|
|
#if WITH_UIP6
|
|
|
|
#include "net/sicslowpan.h"
|
|
|
|
#include "net/uip-netif.h"
|
|
|
|
#include "net/mac/sicslowmac.h"
|
|
|
|
#if UIP_CONF_ROUTER
|
|
|
|
#include "net/routing/rimeroute.h"
|
|
|
|
#include "net/rime/rime-udp.h"
|
|
|
|
#endif /* UIP_CONF_ROUTER*/
|
|
|
|
#endif /* WITH_UIP6 */
|
|
|
|
|
2007-03-22 00:26:34 +01:00
|
|
|
#include "net/rime.h"
|
|
|
|
|
2008-02-03 22:03:19 +01:00
|
|
|
#include "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"
|
2008-02-03 22:03:19 +01:00
|
|
|
#include "sys/profile.h"
|
2007-03-15 22:44:28 +01:00
|
|
|
|
|
|
|
SENSORS(&button_sensor);
|
2009-02-04 20:32:20 +01:00
|
|
|
|
|
|
|
#if DCOSYNCH_CONF_ENABLED
|
|
|
|
static struct timer mgt_timer;
|
|
|
|
#endif
|
|
|
|
|
2008-02-03 22:03:19 +01:00
|
|
|
#ifndef WITH_UIP
|
2007-05-22 23:13:26 +02:00
|
|
|
#define WITH_UIP 0
|
2008-02-03 22:03:19 +01:00
|
|
|
#endif
|
2007-03-22 20:04:43 +01:00
|
|
|
|
|
|
|
#if WITH_UIP
|
2008-02-03 22:03:19 +01:00
|
|
|
#include "net/uip.h"
|
|
|
|
#include "net/uip-fw.h"
|
|
|
|
#include "net/uip-fw-drv.h"
|
|
|
|
#include "net/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)};
|
|
|
|
|
2008-11-05 16:34:04 +01:00
|
|
|
#endif /* WITH_UIP */
|
|
|
|
|
2008-11-09 13:22:04 +01:00
|
|
|
#define UIP_OVER_MESH_CHANNEL 8
|
2009-01-19 14:44:04 +01:00
|
|
|
#if WITH_UIP
|
2008-11-09 13:22:04 +01:00
|
|
|
static uint8_t is_gateway;
|
2009-01-19 14:44:04 +01:00
|
|
|
#endif /* WITH_UIP */
|
2008-02-03 22:03:19 +01:00
|
|
|
|
2007-10-23 23:29:40 +02:00
|
|
|
#ifdef EXPERIMENT_SETUP
|
|
|
|
#include "experiment-setup.h"
|
|
|
|
#endif
|
|
|
|
|
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); }
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-11-21 17:41:44 +01:00
|
|
|
#ifndef RF_CHANNEL
|
2007-03-15 22:44:28 +01:00
|
|
|
#define RF_CHANNEL 26
|
2007-11-21 17:41:44 +01:00
|
|
|
#endif
|
2007-03-15 22:44:28 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-22 23:13:26 +02:00
|
|
|
void
|
|
|
|
force_inclusion(int d1, int d2)
|
|
|
|
{
|
|
|
|
snprintf(NULL, 0, "%d", d1 % d2);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-25 19:21:49 +02:00
|
|
|
static void
|
|
|
|
set_rime_addr(void)
|
|
|
|
{
|
|
|
|
rimeaddr_t addr;
|
2007-12-17 13:35:23 +01:00
|
|
|
int i;
|
2008-11-06 16:14:24 +01:00
|
|
|
|
2007-12-17 13:35:23 +01:00
|
|
|
memset(&addr, 0, sizeof(rimeaddr_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) {
|
|
|
|
for(i = 0; i < sizeof(rimeaddr_t); ++i) {
|
|
|
|
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
|
2007-03-25 19:21:49 +02:00
|
|
|
rimeaddr_set_node_addr(&addr);
|
2008-11-06 16:14:24 +01:00
|
|
|
printf("Rime started with address ");
|
|
|
|
for(i = 0; i < sizeof(addr.u8) - 1; i++) {
|
|
|
|
printf("%d.", addr.u8[i]);
|
|
|
|
}
|
|
|
|
printf("%d\n", addr.u8[i]);
|
2007-03-25 19:21:49 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
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');
|
|
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------*/
|
2008-02-24 22:13:03 +01:00
|
|
|
#if WITH_UIP
|
|
|
|
static void
|
|
|
|
set_gateway(void)
|
|
|
|
{
|
|
|
|
if(!is_gateway) {
|
|
|
|
leds_on(LEDS_RED);
|
2008-11-09 13:22:04 +01:00
|
|
|
printf("%d.%d: making myself the IP network gateway.\n",
|
2008-02-24 22:13:03 +01:00
|
|
|
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
|
|
|
uip_over_mesh_set_gateway(&rimeaddr_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* WITH_UIP */
|
|
|
|
/*---------------------------------------------------------------------------*/
|
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
|
|
|
|
2008-02-11 11:44:12 +01:00
|
|
|
uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
|
2008-02-24 22:13:03 +01:00
|
|
|
#if WITH_UIP
|
2008-02-11 11:44:12 +01:00
|
|
|
slip_arch_init(BAUD2UBR(115200));
|
2007-05-22 23:13:26 +02:00
|
|
|
#endif /* WITH_UIP */
|
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
|
|
|
|
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
|
|
|
|
|
|
|
/* Restore node id if such has been stored in external mem */
|
|
|
|
node_id_restore();
|
|
|
|
|
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);
|
|
|
|
process_start(&sensors_process, NULL);
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2008-09-14 22:47:30 +02:00
|
|
|
/*
|
2009-04-06 16:12:58 +02:00
|
|
|
* Initialize light and humidity/temp sensors.
|
2008-09-14 22:47:30 +02:00
|
|
|
*/
|
2008-07-08 01:44:58 +02:00
|
|
|
sensors_light_init();
|
2008-09-18 23:29:06 +02:00
|
|
|
battery_sensor.activate();
|
2008-07-08 10:23:24 +02:00
|
|
|
sht11_init();
|
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
|
|
|
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_init();
|
2009-04-06 15:31:00 +02:00
|
|
|
cc2420_set_pan_addr(IEEE802154_PANID, 0 /*XXX*/, ds2411_id);
|
2008-07-02 11:05:40 +02:00
|
|
|
cc2420_set_channel(RF_CHANNEL);
|
2008-11-05 16:34:04 +01:00
|
|
|
|
2009-02-11 12:08:53 +01:00
|
|
|
random_init(ds2411_id[0] + node_id);
|
2009-02-07 17:49:36 +01:00
|
|
|
|
2007-11-21 17:41:44 +01:00
|
|
|
printf(CONTIKI_VERSION_STRING " started. ");
|
|
|
|
if(node_id > 0) {
|
|
|
|
printf("Node id is set to %u.\n", node_id);
|
|
|
|
} else {
|
|
|
|
printf("Node id is not set.\n");
|
|
|
|
}
|
2008-02-03 22:03:19 +01:00
|
|
|
set_rime_addr();
|
2008-11-24 15:31:08 +01: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],
|
|
|
|
ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);
|
2008-11-21 11:35:46 +01:00
|
|
|
|
2008-11-05 16:34:04 +01:00
|
|
|
#if WITH_UIP6
|
|
|
|
memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr));
|
2009-04-06 16:12:58 +02:00
|
|
|
sicslowpan_init(sicslowmac_init(&cc2420_driver));
|
2008-11-05 16:34:04 +01:00
|
|
|
process_start(&tcpip_process, NULL);
|
2009-04-06 16:12:58 +02:00
|
|
|
printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL);
|
|
|
|
#if UIP_CONF_ROUTER
|
|
|
|
rime_init(rime_udp_init(NULL));
|
|
|
|
uip_router_register(&rimeroute);
|
|
|
|
#endif /* UIP_CONF_ROUTER */
|
|
|
|
#else /* WITH_UIP6 */
|
|
|
|
#if WITH_NULLMAC
|
|
|
|
rime_init(nullmac_init(&cc2420_driver));
|
|
|
|
#else /* WITH_NULLMAC */
|
|
|
|
rime_init(xmac_init(&cc2420_driver));
|
|
|
|
#endif /* WITH_NULLMAC */
|
|
|
|
printf(" %s channel %u\n", rime_mac->name, RF_CHANNEL);
|
2008-11-05 16:34:04 +01:00
|
|
|
#endif /* WITH_UIP6 */
|
|
|
|
|
2008-11-09 13:22:04 +01:00
|
|
|
#if !WITH_UIP && !WITH_UIP6
|
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
|
|
|
#if PROFILE_CONF_ON
|
|
|
|
profile_init();
|
|
|
|
#endif /* PROFILE_CONF_ON */
|
|
|
|
|
|
|
|
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();
|
|
|
|
timesynch_set_authority_level(rimeaddr_node_addr.u8[0]);
|
2009-03-31 15:25:50 +02:00
|
|
|
#endif /* TIMESYNCH_CONF_ENABLED */
|
2008-11-09 13:22:04 +01:00
|
|
|
|
2007-03-22 20:04:43 +01:00
|
|
|
#if WITH_UIP
|
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,
|
|
|
|
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
|
|
|
|
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);
|
2008-02-24 22:13:03 +01:00
|
|
|
printf("uIP started with IP address %d.%d.%d.%d\n",
|
|
|
|
uip_ipaddr_to_quad(&hostaddr));
|
2008-02-03 22:03:19 +01:00
|
|
|
}
|
2007-03-22 20:04:43 +01:00
|
|
|
#endif /* WITH_UIP */
|
|
|
|
|
2007-03-25 19:21:49 +02:00
|
|
|
button_sensor.activate();
|
2007-11-28 15:45:22 +01:00
|
|
|
|
|
|
|
energest_init();
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
2008-11-05 16:34:04 +01:00
|
|
|
|
2008-02-03 22:03:19 +01:00
|
|
|
print_processes(autostart_processes);
|
|
|
|
autostart_start(autostart_processes);
|
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
|
2007-11-17 11:29:33 +01:00
|
|
|
watchdog_start();
|
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-10-25 12:21:48 +02:00
|
|
|
#if PROFILE_CONF_ON
|
2007-10-23 23:29:40 +02:00
|
|
|
profile_episode_start();
|
2007-10-25 12:21:48 +02:00
|
|
|
#endif /* PROFILE_CONF_ON */
|
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);
|
2007-10-25 12:21:48 +02:00
|
|
|
#if PROFILE_CONF_ON
|
2007-10-23 23:29:40 +02:00
|
|
|
profile_episode_end();
|
2007-10-25 12:21:48 +02:00
|
|
|
#endif /* PROFILE_CONF_ON */
|
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 */
|
|
|
|
if (timer_expired(&mgt_timer)) {
|
|
|
|
timer_reset(&mgt_timer);
|
|
|
|
msp430_sync_dco();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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();
|
2008-09-18 19:58:21 +02:00
|
|
|
_BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
|
2007-12-17 13:35:23 +01:00
|
|
|
statement will block
|
|
|
|
until the CPU is
|
|
|
|
woken up by an
|
|
|
|
interrupt that sets
|
|
|
|
the wake up flag. */
|
2007-10-23 23:29:40 +02:00
|
|
|
|
2008-11-21 11:35:46 +01:00
|
|
|
|
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 */
|