2013-07-11 17:50:15 +02:00
|
|
|
/**
|
|
|
|
* \addtogroup mbxxx-platform
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2011-04-01 10:22:29 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010, STMicroelectronics.
|
|
|
|
* 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. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OS
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* \file
|
2013-07-11 17:50:15 +02:00
|
|
|
* Contiki main file.
|
2011-04-01 10:22:29 +02:00
|
|
|
* \author
|
2013-07-11 17:50:15 +02:00
|
|
|
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
|
|
|
* Chi-Anh La <la@imag.fr>
|
2011-04-01 10:22:29 +02:00
|
|
|
*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
#include PLATFORM_HEADER
|
|
|
|
#include "hal/error.h"
|
|
|
|
#include "hal/hal.h"
|
|
|
|
#include BOARD_HEADER
|
|
|
|
#include "micro/adc.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
|
|
|
|
#include "dev/watchdog.h"
|
|
|
|
#include "dev/leds.h"
|
|
|
|
#include "dev/button-sensor.h"
|
|
|
|
#include "dev/temperature-sensor.h"
|
|
|
|
#include "dev/acc-sensor.h"
|
2013-07-11 17:50:15 +02:00
|
|
|
#include "dev/contact-sensor.h"
|
2011-04-01 10:22:29 +02:00
|
|
|
#include "dev/uart1.h"
|
|
|
|
#include "dev/serial-line.h"
|
|
|
|
|
|
|
|
#include "dev/stm32w-radio.h"
|
|
|
|
#include "net/netstack.h"
|
2013-12-12 23:58:52 +01:00
|
|
|
#include "net/linkaddr.h"
|
2013-12-12 20:50:07 +01:00
|
|
|
#include "net/rime/rime.h"
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ip/uip.h"
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ipv6/uip-ds6.h"
|
2014-12-01 21:02:57 +01:00
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
#define DEBUG 1
|
|
|
|
#if DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
2012-02-20 20:32:05 +01:00
|
|
|
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
|
2011-04-01 10:22:29 +02:00
|
|
|
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",lladdr.u8[0], lladdr.u8[1], lladdr.u8[2], lladdr.u8[3],lladdr.u8[4], lladdr.u8[5], lladdr.u8[6], lladdr.u8[7])
|
|
|
|
#else
|
|
|
|
#define PRINTF(...)
|
|
|
|
#define PRINT6ADDR(addr)
|
|
|
|
#define PRINTLLADDR(addr)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2012-10-28 20:42:16 +01:00
|
|
|
PROCINIT(&tcpip_process, &sensors_process);
|
2011-04-01 10:22:29 +02:00
|
|
|
#else
|
2012-10-28 20:42:16 +01:00
|
|
|
PROCINIT(&sensors_process);
|
2011-04-01 10:22:29 +02:00
|
|
|
#warning "No TCP/IP process!"
|
|
|
|
#endif
|
|
|
|
|
2013-07-11 17:50:15 +02:00
|
|
|
SENSORS(&button_sensor, &temperature_sensor, &acc_sensor, &contact_sensor);
|
|
|
|
|
|
|
|
/* The default CCA threshold is set to -77, which is the same as the
|
|
|
|
default setting on the TI CC2420. */
|
|
|
|
#define DEFAULT_RADIO_CCA_THRESHOLD -77
|
2011-04-01 10:22:29 +02:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
set_rime_addr(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
union {
|
2012-02-20 20:32:05 +01:00
|
|
|
uint8_t u8[8];
|
2013-07-11 17:50:15 +02:00
|
|
|
} eui64;
|
|
|
|
|
|
|
|
uint8_t *stm32w_eui64 = ST_RadioGetEui64();
|
2011-04-01 10:22:29 +02:00
|
|
|
{
|
2013-07-11 17:50:15 +02:00
|
|
|
uint8_t c;
|
|
|
|
/* Copy the EUI-64 to lladdr converting from Little-Endian to
|
|
|
|
Big-Endian. */
|
|
|
|
for(c = 0; c < 8; c++) {
|
|
|
|
eui64.u8[c] = stm32w_eui64[7 - c];
|
|
|
|
}
|
2011-04-01 10:22:29 +02:00
|
|
|
}
|
2012-10-28 20:42:16 +01:00
|
|
|
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2011-04-01 10:22:29 +02:00
|
|
|
memcpy(&uip_lladdr.addr, &eui64, sizeof(uip_lladdr.addr));
|
|
|
|
#endif
|
|
|
|
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_set_node_addr((linkaddr_t *)&eui64);
|
2012-10-28 20:42:16 +01:00
|
|
|
#else
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_set_node_addr((linkaddr_t *)&eui64.u8[8 - LINKADDR_SIZE]);
|
2011-04-01 10:22:29 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("Rime started with address ");
|
2013-12-12 23:58:52 +01:00
|
|
|
for(i = 0; i < sizeof(linkaddr_t) - 1; i++) {
|
|
|
|
printf("%d.", linkaddr_node_addr.u8[i]);
|
2011-04-01 10:22:29 +02:00
|
|
|
}
|
2013-12-12 23:58:52 +01:00
|
|
|
printf("%d\n", linkaddr_node_addr.u8[i]);
|
2011-04-01 10:22:29 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
/*
|
2013-07-11 17:50:15 +02:00
|
|
|
* Initalize hardware.
|
2011-04-01 10:22:29 +02:00
|
|
|
*/
|
|
|
|
halInit();
|
|
|
|
clock_init();
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
uart1_init(115200);
|
2013-07-11 17:50:15 +02:00
|
|
|
|
|
|
|
/* Led initialization */
|
2011-04-01 10:22:29 +02:00
|
|
|
leds_init();
|
2013-07-11 17:50:15 +02:00
|
|
|
|
|
|
|
INTERRUPTS_ON();
|
2011-04-01 10:22:29 +02:00
|
|
|
|
|
|
|
PRINTF("\r\nStarting ");
|
|
|
|
PRINTF(CONTIKI_VERSION_STRING);
|
2013-07-11 17:50:15 +02:00
|
|
|
PRINTF(" on %s\r\n", boardDescription->name);
|
|
|
|
boardPrintStringDescription();
|
|
|
|
PRINTF("\r\n");
|
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize Contiki and our processes.
|
|
|
|
*/
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
process_init();
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
#if WITH_SERIAL_LINE_INPUT
|
|
|
|
uart1_set_input(serial_line_input_byte);
|
|
|
|
serial_line_init();
|
|
|
|
#endif
|
2013-07-11 17:50:15 +02:00
|
|
|
/* rtimer and ctimer should be initialized before radio duty cycling
|
|
|
|
layers */
|
2012-10-28 20:42:16 +01:00
|
|
|
rtimer_init();
|
|
|
|
/* etimer_process should be initialized before ctimer */
|
2013-07-11 17:50:15 +02:00
|
|
|
process_start(&etimer_process, NULL);
|
2012-10-28 20:42:16 +01:00
|
|
|
ctimer_init();
|
|
|
|
|
|
|
|
netstack_init();
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2012-03-20 16:15:51 +01:00
|
|
|
set_rime_addr();
|
|
|
|
|
|
|
|
printf("%s %s, channel check rate %lu Hz\n",
|
|
|
|
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
|
|
|
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
|
|
|
|
NETSTACK_RDC.channel_check_interval()));
|
|
|
|
printf("802.15.4 PAN ID 0x%x, EUI-%d:",
|
|
|
|
IEEE802154_CONF_PANID, UIP_CONF_LL_802154?64:16);
|
2013-12-12 23:58:52 +01:00
|
|
|
uip_debug_lladdr_print(&linkaddr_node_addr);
|
2012-10-28 20:42:16 +01:00
|
|
|
printf(", radio channel %u\n", RF_CHANNEL);
|
|
|
|
|
|
|
|
procinit_init();
|
2011-04-01 10:22:29 +02:00
|
|
|
|
|
|
|
energest_init();
|
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
2012-10-28 20:42:16 +01:00
|
|
|
|
2013-07-11 17:50:15 +02:00
|
|
|
/* Set the Clear Channel Assessment (CCA) threshold of the
|
|
|
|
radio. The CCA threshold is used both for sending packets and for
|
|
|
|
waking up ContikiMAC nodes. If the CCA threshold is too high,
|
|
|
|
ContikiMAC will not wake up from neighbor transmissions. If the
|
|
|
|
CCA threshold is too low, transmissions will be too restrictive
|
|
|
|
and no packets will be sent. DEFAULT_RADIO_CCA_THRESHOLD is
|
|
|
|
defined in this file. */
|
|
|
|
ST_RadioSetEdCcaThreshold(DEFAULT_RADIO_CCA_THRESHOLD);
|
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
autostart_start(autostart_processes);
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2013-07-11 17:50:15 +02:00
|
|
|
printf("Tentative link-local IPv6 address ");
|
|
|
|
{
|
|
|
|
uip_ds6_addr_t *lladdr;
|
|
|
|
int i;
|
|
|
|
lladdr = uip_ds6_get_link_local(-1);
|
|
|
|
for(i = 0; i < 7; ++i) {
|
|
|
|
printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
|
|
|
|
lladdr->ipaddr.u8[i * 2 + 1]);
|
|
|
|
}
|
|
|
|
printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
|
|
|
|
}
|
2012-10-28 20:42:16 +01:00
|
|
|
|
|
|
|
|
2013-07-11 17:50:15 +02:00
|
|
|
if(!UIP_CONF_IPV6_RPL) {
|
|
|
|
uip_ipaddr_t ipaddr;
|
|
|
|
int i;
|
|
|
|
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
|
|
|
uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
|
|
|
|
printf("Tentative global IPv6 address ");
|
|
|
|
for(i = 0; i < 7; ++i) {
|
|
|
|
printf("%02x%02x:",
|
|
|
|
ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
|
|
|
|
}
|
|
|
|
printf("%02x%02x\n",
|
|
|
|
ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
|
|
|
|
}
|
2014-12-01 21:02:57 +01:00
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
2013-07-11 17:50:15 +02:00
|
|
|
|
|
|
|
watchdog_start();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
|
|
|
int r;
|
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
do {
|
|
|
|
/* Reset watchdog. */
|
|
|
|
watchdog_periodic();
|
|
|
|
r = process_run();
|
|
|
|
} while(r > 0);
|
2013-07-11 17:50:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_CPU);
|
2013-07-11 17:50:15 +02:00
|
|
|
/* watchdog_stop(); */
|
2011-04-01 10:22:29 +02:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_LPM);
|
|
|
|
/* Go to idle mode. */
|
|
|
|
halSleepWithOptions(SLEEPMODE_IDLE,0);
|
|
|
|
/* We are awake. */
|
2013-07-11 17:50:15 +02:00
|
|
|
/* watchdog_start(); */
|
2011-04-01 10:22:29 +02:00
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_LPM);
|
2013-07-11 17:50:15 +02:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
}
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-11 17:50:15 +02:00
|
|
|
/*uint8_t errcode __attribute__(( section(".noinit") ));
|
2011-04-01 10:22:29 +02:00
|
|
|
|
|
|
|
void halBaseBandIsr(){
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
errcode = 1;
|
|
|
|
leds_on(LEDS_RED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BusFault_Handler(){
|
2013-07-11 17:50:15 +02:00
|
|
|
|
|
|
|
errcode = 2;
|
2011-04-01 10:22:29 +02:00
|
|
|
leds_on(LEDS_RED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void halDebugIsr(){
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
errcode = 3;
|
2013-07-11 17:50:15 +02:00
|
|
|
leds_on(LEDS_RED);
|
2011-04-01 10:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebugMon_Handler(){
|
2013-07-11 17:50:15 +02:00
|
|
|
|
2011-04-01 10:22:29 +02:00
|
|
|
errcode = 4;
|
2013-07-11 17:50:15 +02:00
|
|
|
//leds_on(LEDS_RED);
|
2011-04-01 10:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void HardFault_Handler(){
|
2013-07-11 17:50:15 +02:00
|
|
|
|
|
|
|
errcode = 5;
|
2011-04-01 10:22:29 +02:00
|
|
|
//leds_on(LEDS_RED);
|
|
|
|
//halReboot();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemManage_Handler(){
|
2013-07-11 17:50:15 +02:00
|
|
|
|
|
|
|
errcode = 6;
|
2011-04-01 10:22:29 +02:00
|
|
|
//leds_on(LEDS_RED);
|
|
|
|
//halReboot();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UsageFault_Handler(){
|
2013-07-11 17:50:15 +02:00
|
|
|
|
|
|
|
errcode = 7;
|
2011-04-01 10:22:29 +02:00
|
|
|
//leds_on(LEDS_RED);
|
|
|
|
//halReboot();
|
2013-07-11 17:50:15 +02:00
|
|
|
}
|
2011-04-01 10:22:29 +02:00
|
|
|
|
2013-07-11 17:50:15 +02:00
|
|
|
void Default_Handler()
|
|
|
|
{
|
|
|
|
//errcode = 8;
|
2011-04-01 10:22:29 +02:00
|
|
|
leds_on(LEDS_RED);
|
|
|
|
halReboot();
|
2013-07-11 17:50:15 +02:00
|
|
|
}*/
|
|
|
|
/** @} */
|