2007-06-28 12:49:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007, 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.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Main system file for the MSB-430 port.
|
|
|
|
* \author
|
|
|
|
* Michael Baar <baar@inf.fu-berlin.de>, Nicolas Tsiftes <nvt@sics.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <io.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-12-17 13:33:09 +00:00
|
|
|
#include "contiki.h"
|
2007-06-28 12:49:57 +00:00
|
|
|
#include "contiki-msb430.h"
|
2009-04-08 14:56:00 +00:00
|
|
|
#include "dev/adc.h"
|
2009-09-22 15:20:51 +00:00
|
|
|
#include "dev/sd.h"
|
2009-03-24 15:02:03 +00:00
|
|
|
#include "dev/serial-line.h"
|
2009-04-08 14:56:00 +00:00
|
|
|
#include "dev/sht11.h"
|
|
|
|
#include "dev/watchdog.h"
|
2007-06-28 12:49:57 +00:00
|
|
|
|
2007-12-13 12:51:38 +00:00
|
|
|
extern volatile bool uart_edge;
|
|
|
|
|
2009-09-22 16:27:17 +00:00
|
|
|
extern void init_net(void);
|
|
|
|
|
2007-06-28 12:49:57 +00:00
|
|
|
SENSORS(NULL);
|
|
|
|
|
|
|
|
static void
|
|
|
|
msb_ports_init(void)
|
|
|
|
{
|
2007-12-13 13:10:02 +00:00
|
|
|
P1SEL = 0x00; P1OUT = 0x00; P1DIR = 0x00;
|
|
|
|
P2SEL = 0x00; P2OUT = 0x18; P2DIR = 0x1A;
|
|
|
|
P3SEL = 0x00; P3OUT = 0x09; P3DIR = 0x21;
|
|
|
|
P4SEL = 0x00; P4OUT = 0x00; P4DIR = 0x00;
|
|
|
|
P5SEL = 0x0E; P5OUT = 0xF9; P5DIR = 0xFD;
|
|
|
|
P6SEL = 0x07; P6OUT = 0x00; P6DIR = 0xC8;
|
2007-06-28 12:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2009-09-22 15:35:45 +00:00
|
|
|
#if WITH_SD
|
|
|
|
int r;
|
|
|
|
#endif /* WITH_SD */
|
|
|
|
|
2007-06-28 12:49:57 +00:00
|
|
|
msp430_cpu_init();
|
2008-02-28 15:49:01 +00:00
|
|
|
watchdog_stop();
|
2007-06-28 12:49:57 +00:00
|
|
|
|
|
|
|
/* Platform-specific initialization. */
|
|
|
|
msb_ports_init();
|
|
|
|
adc_init();
|
|
|
|
|
|
|
|
clock_init();
|
2007-12-13 13:10:02 +00:00
|
|
|
rtimer_init();
|
|
|
|
|
|
|
|
sht11_init();
|
2007-06-28 12:49:57 +00:00
|
|
|
leds_init();
|
|
|
|
leds_on(LEDS_ALL);
|
|
|
|
|
|
|
|
process_init();
|
|
|
|
|
2009-09-22 15:20:51 +00:00
|
|
|
/* serial interface */
|
2009-03-24 15:02:03 +00:00
|
|
|
rs232_set_input(serial_line_input_byte);
|
2007-06-28 12:49:57 +00:00
|
|
|
rs232_init();
|
2009-03-24 15:02:03 +00:00
|
|
|
serial_line_init();
|
2007-06-28 12:49:57 +00:00
|
|
|
|
|
|
|
uart_lock(UART_MODE_RS232);
|
|
|
|
uart_unlock(UART_MODE_RS232);
|
2007-07-31 07:54:44 +00:00
|
|
|
#if WITH_UIP
|
|
|
|
slip_arch_init(BAUD2UBR(115200));
|
|
|
|
#endif
|
|
|
|
|
2009-09-22 15:20:51 +00:00
|
|
|
|
|
|
|
#if WITH_SD
|
|
|
|
r = sd_initialize();
|
|
|
|
if(r < 0) {
|
|
|
|
printf("Failed to initialize the SD driver: %s\n", sd_error_string(r));
|
|
|
|
} else {
|
|
|
|
sd_offset_t capacity;
|
|
|
|
printf("The SD driver was successfully initialized\n");
|
|
|
|
capacity = sd_get_capacity();
|
|
|
|
if(capacity < 0) {
|
2009-09-22 16:24:03 +00:00
|
|
|
printf("Failed to get the SD card capacity: %s\n", sd_error_string(r));
|
2009-09-22 15:20:51 +00:00
|
|
|
} else {
|
2009-09-22 16:24:03 +00:00
|
|
|
printf("SD card capacity: %u MB\n",
|
|
|
|
(unsigned)(capacity / (1024UL * 1024)));
|
2009-09-22 15:20:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-31 07:54:44 +00:00
|
|
|
/* System services */
|
|
|
|
process_start(&etimer_process, NULL);
|
2008-03-31 14:01:26 +00:00
|
|
|
ctimer_init();
|
2007-06-28 12:49:57 +00:00
|
|
|
|
2007-12-13 12:51:38 +00:00
|
|
|
node_id_restore();
|
2007-06-28 12:49:57 +00:00
|
|
|
|
2007-12-17 13:33:09 +00:00
|
|
|
init_net();
|
2007-12-13 12:51:38 +00:00
|
|
|
|
2007-12-13 13:10:02 +00:00
|
|
|
energest_init();
|
2007-12-13 12:51:38 +00:00
|
|
|
|
|
|
|
#if PROFILE_CONF_ON
|
|
|
|
profile_init();
|
|
|
|
#endif /* PROFILE_CONF_ON */
|
2007-07-31 07:54:44 +00:00
|
|
|
|
2007-12-13 12:51:38 +00:00
|
|
|
leds_off(LEDS_ALL);
|
|
|
|
|
2009-03-19 14:14:06 +00:00
|
|
|
printf(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n",
|
|
|
|
node_id, rime_mac->name);
|
2007-08-02 08:14:00 +00:00
|
|
|
|
2008-02-10 22:36:36 +00:00
|
|
|
autostart_start(autostart_processes);
|
2007-06-28 12:49:57 +00:00
|
|
|
|
2007-12-13 12:51:38 +00:00
|
|
|
/*
|
|
|
|
* This is the scheduler loop.
|
|
|
|
*/
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int r;
|
|
|
|
#if PROFILE_CONF_ON
|
|
|
|
profile_episode_start();
|
|
|
|
#endif /* PROFILE_CONF_ON */
|
|
|
|
do {
|
|
|
|
/* Reset watchdog. */
|
2008-11-04 15:46:59 +00:00
|
|
|
watchdog_periodic();
|
2007-12-13 12:51:38 +00:00
|
|
|
r = process_run();
|
|
|
|
} while(r > 0);
|
|
|
|
|
|
|
|
#if PROFILE_CONF_ON
|
|
|
|
profile_episode_end();
|
|
|
|
#endif /* PROFILE_CONF_ON */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Idle processing.
|
|
|
|
*/
|
|
|
|
int s = splhigh(); /* Disable interrupts. */
|
|
|
|
if (process_nevents() != 0) {
|
|
|
|
splx(s); /* Re-enable interrupts. */
|
|
|
|
} else {
|
|
|
|
static unsigned long irq_energest = 0;
|
|
|
|
/* Re-enable interrupts and go to sleep atomically. */
|
2007-12-10 12:49:08 +00:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_CPU);
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_LPM);
|
2007-12-13 12:51:38 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
if (uart_edge) {
|
2008-05-29 22:06:18 +00:00
|
|
|
_BIC_SR(LPM1_bits + GIE);
|
2007-12-13 12:51:38 +00:00
|
|
|
} else {
|
|
|
|
_BIS_SR(LPM1_bits + GIE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-12-10 12:49:08 +00:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_LPM);
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
2007-12-13 12:51:38 +00:00
|
|
|
#if PROFILE_CONF_ON
|
|
|
|
profile_clear_timestamps();
|
|
|
|
#endif /* PROFILE_CONF_ON */
|
2007-07-31 07:54:44 +00:00
|
|
|
}
|
2007-06-28 12:49:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|