2008-10-14 11:40:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006, Technical University of Munich
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @(#)$$
|
|
|
|
*/
|
2011-02-28 22:26:28 +01:00
|
|
|
#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
2010-02-28 22:29:19 +01:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#define ANNOUNCE_BOOT 1 //adds about 600 bytes to program size
|
|
|
|
#if ANNOUNCE_BOOT
|
|
|
|
#define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
|
|
|
#else
|
|
|
|
#define PRINTA(...)
|
|
|
|
#endif
|
|
|
|
|
2010-03-02 17:25:47 +01:00
|
|
|
#define DEBUG 0
|
2009-07-23 18:16:07 +02:00
|
|
|
#if DEBUG
|
2011-08-28 22:22:39 +02:00
|
|
|
#define PRINTD(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
2009-07-23 18:16:07 +02:00
|
|
|
#else
|
2011-08-28 22:22:39 +02:00
|
|
|
#define PRINTD(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Track interrupt flow through mac, rdc and radio driver */
|
|
|
|
#if DEBUGFLOWSIZE
|
|
|
|
uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
|
|
|
|
#define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c
|
|
|
|
#else
|
|
|
|
#define DEBUGFLOW(c)
|
2009-07-23 18:16:07 +02:00
|
|
|
#endif
|
2008-10-14 11:40:30 +02:00
|
|
|
|
|
|
|
#include <avr/pgmspace.h>
|
2008-10-14 23:29:23 +02:00
|
|
|
#include <avr/fuse.h>
|
|
|
|
#include <avr/eeprom.h>
|
2008-10-14 11:40:30 +02:00
|
|
|
#include <stdio.h>
|
2009-07-08 17:26:17 +02:00
|
|
|
#include <string.h>
|
2010-11-03 17:51:55 +01:00
|
|
|
#include <dev/watchdog.h>
|
2008-10-14 11:40:30 +02:00
|
|
|
|
|
|
|
#include "loader/symbols-def.h"
|
|
|
|
#include "loader/symtab.h"
|
2009-07-08 17:26:17 +02:00
|
|
|
|
2010-02-23 18:43:20 +01:00
|
|
|
#if RF230BB //radio driver using contiki core mac
|
2009-07-26 14:10:38 +02:00
|
|
|
#include "radio/rf230bb/rf230bb.h"
|
2009-07-08 17:26:17 +02:00
|
|
|
#include "net/mac/frame802154.h"
|
2010-02-18 18:23:19 +01:00
|
|
|
#include "net/mac/framer-802154.h"
|
2009-07-08 17:26:17 +02:00
|
|
|
#include "net/sicslowpan.h"
|
2010-02-16 23:22:13 +01:00
|
|
|
|
2009-07-23 18:16:07 +02:00
|
|
|
#else //radio driver using Atmel/Cisco 802.15.4'ish MAC
|
|
|
|
#include <stdbool.h>
|
2008-10-14 11:40:30 +02:00
|
|
|
#include "mac.h"
|
2009-07-26 14:10:38 +02:00
|
|
|
#include "sicslowmac.h"
|
2008-10-14 11:40:30 +02:00
|
|
|
#include "sicslowpan.h"
|
|
|
|
#include "ieee-15-4-manager.h"
|
2009-07-08 17:26:17 +02:00
|
|
|
#endif /*RF230BB*/
|
2008-10-14 11:40:30 +02:00
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "contiki-net.h"
|
|
|
|
#include "contiki-lib.h"
|
|
|
|
|
|
|
|
#include "dev/rs232.h"
|
2009-03-17 21:19:11 +01:00
|
|
|
#include "dev/serial-line.h"
|
2008-10-14 11:40:30 +02:00
|
|
|
#include "dev/slip.h"
|
|
|
|
|
2008-10-15 16:38:20 +02:00
|
|
|
#ifdef RAVEN_LCD_INTERFACE
|
2008-10-14 11:40:30 +02:00
|
|
|
#include "raven-lcd.h"
|
2008-10-15 16:38:20 +02:00
|
|
|
#endif
|
2008-10-14 11:40:30 +02:00
|
|
|
|
2011-07-24 17:43:17 +02:00
|
|
|
#if AVR_WEBSERVER
|
2009-07-23 18:16:07 +02:00
|
|
|
#include "httpd-fs.h"
|
2010-02-09 15:43:16 +01:00
|
|
|
#include "httpd-cgi.h"
|
2009-07-26 14:10:38 +02:00
|
|
|
#endif
|
|
|
|
|
2009-07-23 18:16:07 +02:00
|
|
|
#ifdef COFFEE_FILES
|
|
|
|
#include "cfs/cfs.h"
|
|
|
|
#include "cfs/cfs-coffee.h"
|
|
|
|
#endif
|
|
|
|
|
2010-11-03 17:51:55 +01:00
|
|
|
#if UIP_CONF_ROUTER&&0
|
2009-07-08 17:26:17 +02:00
|
|
|
#include "net/routing/rimeroute.h"
|
|
|
|
#include "net/rime/rime-udp.h"
|
2009-07-26 14:10:38 +02:00
|
|
|
#endif
|
|
|
|
|
2009-07-08 17:26:17 +02:00
|
|
|
#include "net/rime.h"
|
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
/* Get periodic prints from idle loop, from clock seconds or rtimer interrupts */
|
|
|
|
/* Use of rtimer will conflict with other rtimer interrupts such as contikimac radio cycling */
|
|
|
|
/* STAMPS will print ENERGEST outputs if that is enabled. */
|
|
|
|
#define PERIODICPRINTS 1
|
|
|
|
#if PERIODICPRINTS
|
2011-02-28 22:26:28 +01:00
|
|
|
//#define PINGS 64
|
2011-08-28 22:22:39 +02:00
|
|
|
#define ROUTES 600
|
2011-08-05 21:14:35 +02:00
|
|
|
#define STAMPS 60
|
|
|
|
#define STACKMONITOR 600
|
2011-08-28 22:22:39 +02:00
|
|
|
uint32_t clocktime;
|
|
|
|
#define TESTRTIMER 0
|
|
|
|
#if TESTRTIMER
|
2011-02-28 22:26:28 +01:00
|
|
|
uint8_t rtimerflag=1;
|
|
|
|
struct rtimer rt;
|
|
|
|
void rtimercycle(void) {rtimerflag=1;}
|
2011-08-28 22:22:39 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2011-02-28 22:26:28 +01:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#if WITH_NODE_ID
|
|
|
|
uint16_t node_id;
|
|
|
|
#endif
|
2011-02-28 22:26:28 +01:00
|
|
|
|
2009-07-23 18:16:07 +02:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/*----------------------Configuration of the .elf file---------------------*/
|
2011-08-28 22:22:39 +02:00
|
|
|
#if 1
|
|
|
|
/* The proper way to set the signature is */
|
|
|
|
#include <avr/signature.h>
|
|
|
|
#else
|
|
|
|
/* Older avr-gcc's may not define the needed SIGNATURE bytes. Do it manually if you get an error */
|
|
|
|
typedef struct {const unsigned char B2;const unsigned char B1;const unsigned char B0;} __signature_t;
|
2009-07-08 17:26:17 +02:00
|
|
|
#define SIGNATURE __signature_t __signature __attribute__((section (".signature")))
|
2009-07-23 18:16:07 +02:00
|
|
|
SIGNATURE = {
|
2011-08-28 22:22:39 +02:00
|
|
|
.B2 = 0x05,//SIGNATURE_2, //ATMEGA1284p
|
|
|
|
.B1 = 0x97,//SIGNATURE_1, //128KB flash
|
|
|
|
.B0 = 0x1E,//SIGNATURE_0, //Atmel
|
2009-07-08 17:26:17 +02:00
|
|
|
};
|
2011-08-28 22:22:39 +02:00
|
|
|
#endif
|
2008-10-14 23:29:23 +02:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
/* JTAG, SPI enabled, Internal RC osc, Boot flash size 4K, 6CK+65msec delay, brownout disabled */
|
|
|
|
FUSES ={.low = 0xe2, .high = 0x99, .extended = 0xff,};
|
2011-02-07 20:06:53 +01:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
/* Put the default settings into program flash memory */
|
|
|
|
/* Webserver builds can set some defaults in httpd-fsdata.c via makefsdata.h */
|
2011-07-24 17:43:17 +02:00
|
|
|
#if AVR_WEBSERVER
|
2011-08-28 22:22:39 +02:00
|
|
|
extern uint8_t default_mac_address[8];
|
|
|
|
extern uint8_t default_server_name[16];
|
|
|
|
extern uint8_t default_domain_name[30];
|
|
|
|
#else
|
|
|
|
#ifdef MAC_ADDRESS
|
|
|
|
uint8_t default_mac_address[8] PROGMEM = MAC_ADDRESS;
|
2009-07-26 14:10:38 +02:00
|
|
|
#else
|
2011-08-28 22:22:39 +02:00
|
|
|
uint8_t default_mac_address[8] PROGMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
|
2009-07-26 14:10:38 +02:00
|
|
|
#endif
|
2011-08-28 22:22:39 +02:00
|
|
|
#ifdef SERVER_NAME
|
|
|
|
uint8_t default_server_name[16] PROGMEM = SERVER_NAME;
|
|
|
|
#else
|
|
|
|
uint8_t default_server_name[16] PROGMEM = "Raven_webserver";
|
|
|
|
#endif
|
|
|
|
#ifdef DOMAIN_NAME
|
|
|
|
uint8_t default_domain_name[30] PROGMEM = DOMAIN_NAME
|
|
|
|
#else
|
|
|
|
uint8_t default_domain_name[30] PROGMEM = "localhost";
|
|
|
|
#endif
|
|
|
|
#endif /* AVR_WEBSERVER */
|
2008-10-14 11:40:30 +02:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#ifdef NODE_ID
|
|
|
|
uint16_t default_nodeid PROGMEM = NODEID;
|
|
|
|
#else
|
|
|
|
uint16_t default_nodeid PROGMEM = 0;
|
|
|
|
#endif
|
2011-02-07 20:06:53 +01:00
|
|
|
#ifdef CHANNEL_802_15_4
|
2011-08-28 22:22:39 +02:00
|
|
|
uint8_t default_channel PROGMEM = CHANNEL_802_15_4;
|
|
|
|
#else
|
|
|
|
uint8_t default_channel PROGMEM = 26;
|
|
|
|
#endif
|
|
|
|
#ifdef IEEE802154_PANID
|
|
|
|
uint16_t default_panid PROGMEM = IEEE802154_PANID;
|
|
|
|
#else
|
|
|
|
uint16_t default_panid PROGMEM = 0xABCD;
|
|
|
|
#endif
|
|
|
|
#ifdef IEEE802154_PANADDR
|
|
|
|
uint16_t default_panaddr PROGMEM = IEEE802154_PANID;
|
|
|
|
#else
|
|
|
|
uint16_t default_panaddr PROGMEM = 0;
|
|
|
|
#endif
|
|
|
|
#ifdef RF230_MAX_TX_POWER
|
|
|
|
uint8_t default_txpower PROGMEM = RF230_MAX_TX_POWER;
|
2011-02-07 20:06:53 +01:00
|
|
|
#else
|
2011-08-28 22:22:39 +02:00
|
|
|
uint8_t default_txpower PROGMEM = 0;
|
2011-02-07 20:06:53 +01:00
|
|
|
#endif
|
2010-09-17 23:59:09 +02:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
/* Get a pseudo random number using the ADC */
|
|
|
|
static uint8_t
|
|
|
|
rng_get_uint8(void) {
|
|
|
|
uint8_t i,j;
|
|
|
|
ADCSRA=1<<ADEN; //Enable ADC, not free running, interrupt disabled, fastest clock
|
|
|
|
for (i=0;i<4;i++) {
|
|
|
|
ADMUX = 0; //toggle reference to increase noise
|
|
|
|
ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference.
|
|
|
|
ADCSRA|=1<<ADSC; //Start conversion
|
|
|
|
while (ADCSRA&(1<<ADSC)); //Wait till done
|
|
|
|
j = (j<<2) + ADC;
|
|
|
|
}
|
|
|
|
ADCSRA=0; //Disable ADC
|
|
|
|
PRINTD("rng issues %d\n",j);
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CONTIKI_CONF_RANDOM_MAC
|
|
|
|
static void
|
|
|
|
generate_new_eui64(uint8_t eui64[8]) {
|
|
|
|
eui64[0] = 0x02;
|
|
|
|
eui64[1] = rng_get_uint8();
|
|
|
|
eui64[2] = rng_get_uint8();
|
|
|
|
eui64[3] = 0xFF;
|
|
|
|
eui64[4] = 0xFE;
|
|
|
|
eui64[5] = rng_get_uint8();
|
|
|
|
eui64[6] = rng_get_uint8();
|
|
|
|
eui64[7] = rng_get_uint8();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !CONTIKI_CONF_SETTINGS_MANAGER
|
|
|
|
/****************************No settings manager*****************************/
|
|
|
|
/* If not using the settings manager, put the default values into EEMEM
|
|
|
|
* These can be manually changed and kept over program reflash.
|
|
|
|
* The channel and bit complement are used to check EEMEM integrity,
|
|
|
|
* If corrupt all values will be rewritten with the default flash values.
|
|
|
|
* To make this work, get the channel before anything else.
|
|
|
|
*/
|
|
|
|
#if AVR_WEBSERVER
|
|
|
|
extern uint8_t eemem_mac_address[8]; //These are defined in httpd-fsdata.c via makefsdata.h
|
|
|
|
extern uint8_t eemem_server_name[16];
|
|
|
|
extern uint8_t eemem_domain_name[30];
|
|
|
|
#else
|
|
|
|
#ifdef MAC_ADDRESS
|
|
|
|
uint8_t eemem_mac_address[8] EEMEM = MAC_ADDRESS;
|
|
|
|
#else
|
|
|
|
uint8_t eemem_mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
|
|
|
|
#endif
|
|
|
|
#ifdef SERVER_NAME
|
|
|
|
uint8_t eemem_server_name[16] EEMEM = SERVER_NAME;
|
|
|
|
#else
|
|
|
|
uint8_t eemem_server_name[16] EEMEM = "Raven_webserver";
|
|
|
|
#endif
|
|
|
|
#ifdef DOMAIN_NAME
|
|
|
|
uint8_t eemem_domain_name[30] EEMEM = DOMAIN_NAME
|
|
|
|
#else
|
|
|
|
uint8_t eemem_domain_name[30] EEMEM = "localhost";
|
|
|
|
#endif
|
|
|
|
#endif /*AVR_WEBSERVER */
|
2010-12-03 21:42:01 +01:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#ifdef NODE_ID
|
|
|
|
uint16_t eemem_nodeid EEMEM = NODEID;
|
|
|
|
#else
|
|
|
|
uint16_t eemem_nodeid EEMEM = 0;
|
|
|
|
#endif
|
2010-12-03 21:42:01 +01:00
|
|
|
#ifdef CHANNEL_802_15_4
|
2011-08-28 22:22:39 +02:00
|
|
|
uint8_t eemem_channel[2] EEMEM = {CHANNEL_802_15_4, ~CHANNEL_802_15_4};
|
2010-12-03 21:42:01 +01:00
|
|
|
#else
|
2011-08-28 22:22:39 +02:00
|
|
|
uint8_t eemem_channel[2] EMEM = {26, ~26};
|
|
|
|
#endif
|
|
|
|
#ifdef IEEE802154_PANID
|
|
|
|
uint16_t eemem_panid EEMEM = IEEE802154_PANID;
|
|
|
|
#else
|
|
|
|
uint16_t eemem_panid EEMEM = 0xABCD;
|
|
|
|
#endif
|
|
|
|
#ifdef IEEE802154_PANADDR
|
|
|
|
uint16_t eemem_panaddr EEMEM = IEEE802154_PANADDR;
|
|
|
|
#else
|
|
|
|
uint16_t eemem_panaddr EEMEM = 0;
|
|
|
|
#endif
|
|
|
|
#ifdef RF230_MAX_TX_POWER
|
|
|
|
uint8_t eemem_txpower EEMEM = RF230_MAX_TX_POWER;
|
|
|
|
#else
|
|
|
|
uint8_t eemem_txpower EEMEM = 0;
|
2010-12-03 21:42:01 +01:00
|
|
|
#endif
|
2010-09-17 23:59:09 +02:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
static uint8_t
|
|
|
|
get_channel_from_eeprom() {
|
|
|
|
uint8_t x[2];
|
|
|
|
*(uint16_t *)x = eeprom_read_word ((uint16_t *)&eemem_channel);
|
|
|
|
/* Don't return an invalid channel number */
|
|
|
|
if( (x[0]<11) || (x[0] > 26)) x[1]=x[0];
|
|
|
|
/* Do exclusive or test on the two values read */
|
|
|
|
if((uint8_t)x[0]!=(uint8_t)~x[1]) {//~x[1] can promote comparison to 16 bit
|
|
|
|
/* Verification fails, rewrite everything */
|
|
|
|
uint8_t i,buffer[32];
|
|
|
|
PRINTD("EEPROM is corrupt, rewriting with defaults.\n");
|
|
|
|
#if CONTIKI_CONF_RANDOM_MAC
|
|
|
|
PRINTA("Generating random MAC address.\n");
|
|
|
|
generate_new_eui64(&buffer);
|
|
|
|
#else
|
|
|
|
for (i=0;i<sizeof(default_mac_address);i++) buffer[i] = pgm_read_byte_near(default_mac_address+i);
|
|
|
|
#endif
|
|
|
|
cli();
|
|
|
|
eeprom_write_block(&buffer, &eemem_mac_address, sizeof(eemem_mac_address));
|
|
|
|
for (i=0;i<sizeof(default_server_name);i++) buffer[i] = pgm_read_byte_near(default_server_name+i);
|
|
|
|
eeprom_write_block(&buffer, &eemem_server_name, sizeof(eemem_server_name));
|
|
|
|
for (i=0;i<sizeof(default_domain_name);i++) buffer[i] = pgm_read_byte_near(default_domain_name+i);
|
|
|
|
eeprom_write_block(&buffer, &eemem_domain_name, sizeof(eemem_domain_name));
|
|
|
|
eeprom_write_word(&eemem_panid , pgm_read_word_near(&default_panid));
|
|
|
|
eeprom_write_word(&eemem_panaddr, pgm_read_word_near(&default_panaddr));
|
|
|
|
eeprom_write_byte(&eemem_txpower, pgm_read_byte_near(&default_txpower));
|
|
|
|
eeprom_write_word(&eemem_nodeid, pgm_read_word_near(&default_nodeid));
|
|
|
|
x[0] = pgm_read_byte_near(&default_channel);
|
|
|
|
x[1]= ~x[0];
|
|
|
|
eeprom_write_word((uint16_t *)&eemem_channel, *(uint16_t *)x);
|
|
|
|
sei();
|
|
|
|
}
|
|
|
|
/* Always returns a valid channel */
|
|
|
|
return x[0];
|
2010-09-17 23:59:09 +02:00
|
|
|
}
|
2011-08-28 22:22:39 +02:00
|
|
|
static bool
|
|
|
|
get_eui64_from_eeprom(uint8_t macptr[sizeof(rimeaddr_t)]) {
|
|
|
|
cli();
|
|
|
|
eeprom_read_block ((void *)macptr, &eemem_mac_address, sizeof(rimeaddr_t));
|
|
|
|
sei();
|
|
|
|
return macptr[0]!=0xFF;
|
2010-09-17 23:59:09 +02:00
|
|
|
}
|
2011-08-28 22:22:39 +02:00
|
|
|
static uint16_t
|
|
|
|
get_panid_from_eeprom(void) {
|
|
|
|
return eeprom_read_word(&eemem_panid);
|
|
|
|
}
|
|
|
|
static uint16_t
|
|
|
|
get_panaddr_from_eeprom(void) {
|
|
|
|
return eeprom_read_word (&eemem_panaddr);
|
|
|
|
}
|
|
|
|
static uint8_t
|
|
|
|
get_txpower_from_eeprom(void)
|
|
|
|
{
|
|
|
|
return eeprom_read_byte(&eemem_txpower);
|
2010-09-17 23:59:09 +02:00
|
|
|
}
|
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#else /* !CONTIKI_CONF_SETTINGS_MANAGER */
|
|
|
|
/******************************Settings manager******************************/
|
|
|
|
#include "settings.h"
|
|
|
|
/* Disable the settings add routines to reduce eeprom wear during testing */
|
|
|
|
#if 0
|
|
|
|
#define settings_add(...) 0
|
|
|
|
#define settings_add_uint8(...) 0
|
|
|
|
#define settings_add_uint16(...) 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AVR_WEBSERVER
|
|
|
|
extern uint8_t eemem_mac_address[8]; //These are defined in httpd-fsdata.c via makefsdata.h
|
|
|
|
extern uint8_t eemem_server_name[16];
|
|
|
|
extern uint8_t eemem_domain_name[30];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static uint8_t
|
|
|
|
get_channel_from_eeprom() {
|
|
|
|
uint8_t x;
|
|
|
|
size_t size = 1;
|
|
|
|
if (settings_get(SETTINGS_KEY_CHANNEL, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
|
|
|
if ((x<11) || (x>26)) {
|
|
|
|
PRINTF("Unusual RF channel %u in EEPROM\n",x);
|
|
|
|
}
|
|
|
|
PRINTD("<=Get RF channel %u.\n",x);
|
|
|
|
} else {
|
|
|
|
x = pgm_read_byte_near(&default_channel);
|
|
|
|
if (settings_add_uint8(SETTINGS_KEY_CHANNEL,x ) == SETTINGS_STATUS_OK) {
|
|
|
|
PRINTD("->Set EEPROM RF channel to %d.\n",x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
static bool
|
|
|
|
get_eui64_from_eeprom(uint8_t macptr[8]) {
|
|
|
|
size_t size = sizeof(rimeaddr_t);
|
|
|
|
if(settings_get(SETTINGS_KEY_EUI64, 0, (unsigned char*)macptr, &size) == SETTINGS_STATUS_OK) {
|
|
|
|
PRINTD("<=Get MAC address.\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#if CONTIKI_CONF_RANDOM_MAC
|
|
|
|
PRINTD("--Generating random MAC address.\n");
|
|
|
|
generate_new_eui64(macptr);
|
|
|
|
#else
|
|
|
|
{uint8_t i;for (i=0;i<8;i++) macptr[i] = pgm_read_byte_near(default_mac_address+i);}
|
|
|
|
#endif
|
|
|
|
if (settings_add(SETTINGS_KEY_EUI64,(unsigned char*)macptr,8)) {
|
|
|
|
PRINTD("->Set EEPROM MAC address.\n");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
static uint16_t
|
|
|
|
get_panid_from_eeprom(void) {
|
|
|
|
uint16_t x;
|
|
|
|
size_t size = 2;
|
|
|
|
if (settings_get(SETTINGS_KEY_PAN_ID, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
|
|
|
PRINTD("<-Get PAN ID of %04x.\n",x);
|
|
|
|
} else {
|
|
|
|
x=pgm_read_word_near(&default_panid);
|
|
|
|
if (settings_add_uint16(SETTINGS_KEY_PAN_ID,x)==SETTINGS_STATUS_OK) {
|
|
|
|
PRINTD("->Set EEPROM PAN ID to %04x.\n",x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
static uint16_t
|
|
|
|
get_panaddr_from_eeprom(void) {
|
|
|
|
uint16_t x;
|
|
|
|
size_t size = 2;
|
|
|
|
if (settings_get(SETTINGS_KEY_PAN_ADDR, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
|
|
|
PRINTD("<-Get PAN address of %04x.\n",x);
|
|
|
|
} else {
|
|
|
|
x=pgm_read_word_near(&default_panaddr);
|
|
|
|
if (settings_add_uint16(SETTINGS_KEY_PAN_ADDR,x)==SETTINGS_STATUS_OK) {
|
|
|
|
PRINTD("->Set EEPROM PAN address to %04x.\n",x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
static uint8_t
|
|
|
|
get_txpower_from_eeprom(void) {
|
|
|
|
uint8_t x;
|
|
|
|
size_t size = 1;
|
|
|
|
if (settings_get(SETTINGS_KEY_TXPOWER, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
|
|
|
PRINTD("<-Get tx power of %d. (0=max)\n",x);
|
|
|
|
} else {
|
|
|
|
x=pgm_read_byte_near(&default_txpower);
|
|
|
|
if (settings_add_uint8(SETTINGS_KEY_TXPOWER,x)==SETTINGS_STATUS_OK) {
|
|
|
|
PRINTD("->Set EEPROM tx power of %d. (0=max)\n",x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
#endif /* CONTIKI_CONF_SETTINGS_MANAGER */
|
2010-09-17 23:59:09 +02:00
|
|
|
|
2009-07-23 18:16:07 +02:00
|
|
|
/*-------------------------Low level initialization------------------------*/
|
|
|
|
/*------Done in a subroutine to keep main routine stack usage small--------*/
|
|
|
|
void initialize(void)
|
2008-10-14 11:40:30 +02:00
|
|
|
{
|
2010-09-17 23:59:09 +02:00
|
|
|
watchdog_init();
|
|
|
|
watchdog_start();
|
2011-02-07 20:06:53 +01:00
|
|
|
|
2008-10-15 16:38:20 +02:00
|
|
|
#ifdef RAVEN_LCD_INTERFACE
|
2008-10-14 11:40:30 +02:00
|
|
|
/* First rs232 port for Raven 3290 port */
|
2009-07-23 18:16:07 +02:00
|
|
|
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
2008-10-14 11:40:30 +02:00
|
|
|
/* Set input handler for 3290 port */
|
|
|
|
rs232_set_input(0,raven_lcd_serial_input);
|
2008-10-15 16:38:20 +02:00
|
|
|
#endif
|
2008-10-14 11:40:30 +02:00
|
|
|
|
|
|
|
/* Second rs232 port for debugging */
|
2009-07-23 18:16:07 +02:00
|
|
|
rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
2008-10-14 11:40:30 +02:00
|
|
|
/* Redirect stdout to second port */
|
|
|
|
rs232_redirect_stdout(RS232_PORT_1);
|
2009-07-23 18:16:07 +02:00
|
|
|
clock_init();
|
2011-02-28 22:26:28 +01:00
|
|
|
|
|
|
|
#if STACKMONITOR
|
|
|
|
/* Simple stack pointer highwater monitor. Checks for magic numbers in the main
|
2011-08-28 22:22:39 +02:00
|
|
|
* loop. In conjuction with PERIODICPRINTS, never-used stack will be printed
|
2011-02-28 22:26:28 +01:00
|
|
|
* every STACKMONITOR seconds.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
extern uint16_t __bss_end;
|
|
|
|
uint16_t p=(uint16_t)&__bss_end;
|
|
|
|
do {
|
|
|
|
*(uint16_t *)p = 0x4242;
|
|
|
|
p+=10;
|
|
|
|
} while (p<SP-10); //don't overwrite our own stack
|
|
|
|
}
|
|
|
|
#endif
|
2011-08-13 17:31:20 +02:00
|
|
|
|
|
|
|
/* Get a random (or probably different) seed for the 802.15.4 packet sequence number.
|
|
|
|
* Some layers will ignore duplicates found in a history (e.g. Contikimac)
|
|
|
|
* causing the initial packets to be ignored after a short-cycle restart.
|
|
|
|
*/
|
2011-08-28 22:22:39 +02:00
|
|
|
random_init(rng_get_uint8());
|
|
|
|
|
2011-02-07 20:06:53 +01:00
|
|
|
#define CONF_CALIBRATE_OSCCAL 0
|
|
|
|
#if CONF_CALIBRATE_OSCCAL
|
2011-08-28 22:22:39 +02:00
|
|
|
void calibrate_rc_osc_32k();
|
2011-02-07 20:06:53 +01:00
|
|
|
{
|
|
|
|
extern uint8_t osccal_calibrated;
|
|
|
|
uint8_t i;
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTD("\nBefore calibration OSCCAL=%x\n",OSCCAL);
|
2011-02-07 20:06:53 +01:00
|
|
|
for (i=0;i<10;i++) {
|
|
|
|
calibrate_rc_osc_32k();
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTD("Calibrated=%x\n",osccal_calibrated);
|
2011-02-07 20:06:53 +01:00
|
|
|
//#include <util/delay_basic.h>
|
|
|
|
//#define delay_us( us ) ( _delay_loop_2(1+(us*F_CPU)/4000000UL) )
|
|
|
|
// delay_us(50000);
|
|
|
|
}
|
|
|
|
clock_init();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
|
2009-07-23 18:16:07 +02:00
|
|
|
|
2010-02-28 22:29:19 +01:00
|
|
|
/* rtimers needed for radio cycling */
|
|
|
|
rtimer_init();
|
2010-02-18 18:23:19 +01:00
|
|
|
|
2009-07-23 18:16:07 +02:00
|
|
|
/* Initialize process subsystem */
|
|
|
|
process_init();
|
2011-08-28 22:22:39 +02:00
|
|
|
|
|
|
|
/* etimers must be started before ctimer_init */
|
2010-02-18 18:23:19 +01:00
|
|
|
process_start(&etimer_process, NULL);
|
2009-07-23 18:16:07 +02:00
|
|
|
|
2010-02-23 18:43:20 +01:00
|
|
|
#if RF230BB
|
2010-02-28 22:29:19 +01:00
|
|
|
|
2010-02-18 18:23:19 +01:00
|
|
|
ctimer_init();
|
2009-07-23 18:16:07 +02:00
|
|
|
/* Start radio and radio receive process */
|
2010-02-28 22:29:19 +01:00
|
|
|
NETSTACK_RADIO.init();
|
2009-07-23 18:16:07 +02:00
|
|
|
|
|
|
|
/* Set addresses BEFORE starting tcpip process */
|
|
|
|
|
2009-07-08 17:26:17 +02:00
|
|
|
rimeaddr_t addr;
|
2011-08-28 22:22:39 +02:00
|
|
|
// memset(&addr, 0, sizeof(rimeaddr_t));
|
|
|
|
get_eui64_from_eeprom(addr.u8);
|
2009-07-08 17:26:17 +02:00
|
|
|
|
2010-11-12 18:15:00 +01:00
|
|
|
#if UIP_CONF_IPV6
|
2011-08-28 22:22:39 +02:00
|
|
|
memcpy(&uip_lladdr.addr, &addr.u8, sizeof(rimeaddr_t));
|
|
|
|
#elif WITH_NODE_ID
|
|
|
|
node_id=get_panaddr_from_eeprom();
|
|
|
|
addr.u8[1]=node_id&0xff;
|
|
|
|
addr.u8[0]=(node_id&0xff00)>>8;
|
|
|
|
PRINTA("Node ID from eeprom: %X\n",node_id);
|
2010-11-12 18:15:00 +01:00
|
|
|
#endif
|
2011-08-28 22:22:39 +02:00
|
|
|
rimeaddr_set_node_addr(&addr);
|
|
|
|
|
2010-09-17 23:59:09 +02:00
|
|
|
rf230_set_pan_addr(
|
|
|
|
get_panid_from_eeprom(),
|
|
|
|
get_panaddr_from_eeprom(),
|
|
|
|
(uint8_t *)&addr.u8
|
|
|
|
);
|
|
|
|
rf230_set_channel(get_channel_from_eeprom());
|
2011-08-28 22:22:39 +02:00
|
|
|
rf230_set_txpower(get_txpower_from_eeprom());
|
2010-02-18 18:23:19 +01:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
|
|
|
|
#else
|
|
|
|
PRINTA("MAC address ");
|
|
|
|
uint8_t i;
|
|
|
|
for (i=sizeof(rimeaddr_t); i>0; i--){
|
|
|
|
PRINTA("%x:",addr.u8[i-1]);
|
|
|
|
}
|
|
|
|
PRINTA("\n");
|
|
|
|
#endif
|
2010-02-22 23:23:18 +01:00
|
|
|
|
2010-03-02 17:25:47 +01:00
|
|
|
/* Initialize stack protocols */
|
2010-02-18 18:23:19 +01:00
|
|
|
queuebuf_init();
|
2010-02-28 22:29:19 +01:00
|
|
|
NETSTACK_RDC.init();
|
2010-02-22 23:23:18 +01:00
|
|
|
NETSTACK_MAC.init();
|
|
|
|
NETSTACK_NETWORK.init();
|
2010-02-28 22:29:19 +01:00
|
|
|
|
|
|
|
#if ANNOUNCE_BOOT
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA("%s %s, channel %u power %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()),rf230_get_txpower();
|
2010-02-28 22:29:19 +01:00
|
|
|
if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac
|
|
|
|
unsigned short tmp;
|
|
|
|
tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
|
|
|
|
NETSTACK_RDC.channel_check_interval());
|
2011-08-28 22:22:39 +02:00
|
|
|
if (tmp<65535) PRINTA(", check rate %u Hz",tmp);
|
2010-02-28 22:29:19 +01:00
|
|
|
}
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA("\n");
|
2009-07-08 17:26:17 +02:00
|
|
|
|
2011-02-28 22:26:28 +01:00
|
|
|
#if UIP_CONF_IPV6_RPL
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA("RPL Enabled\n");
|
2011-02-28 22:26:28 +01:00
|
|
|
#endif
|
2009-07-08 17:26:17 +02:00
|
|
|
#if UIP_CONF_ROUTER
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA("Routing Enabled\n");
|
2010-02-28 22:29:19 +01:00
|
|
|
#endif
|
2011-02-28 22:26:28 +01:00
|
|
|
|
|
|
|
#endif /* ANNOUNCE_BOOT */
|
|
|
|
|
|
|
|
// rime_init(rime_udp_init(NULL));
|
2010-08-03 21:56:27 +02:00
|
|
|
// uip_router_register(&rimeroute);
|
2010-02-18 18:23:19 +01:00
|
|
|
|
|
|
|
process_start(&tcpip_process, NULL);
|
2010-03-02 17:25:47 +01:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#else /* !RF230BB */
|
2011-02-28 22:26:28 +01:00
|
|
|
/* Original RF230 combined mac/radio driver */
|
2010-02-18 18:23:19 +01:00
|
|
|
/* mac process must be started before tcpip process! */
|
|
|
|
process_start(&mac_process, NULL);
|
|
|
|
process_start(&tcpip_process, NULL);
|
2011-08-28 22:22:39 +02:00
|
|
|
#endif /* RF230BB */
|
2010-02-18 18:23:19 +01:00
|
|
|
|
|
|
|
#ifdef RAVEN_LCD_INTERFACE
|
|
|
|
process_start(&raven_lcd_process, NULL);
|
|
|
|
#endif
|
2008-10-14 11:40:30 +02:00
|
|
|
|
2010-02-18 18:23:19 +01:00
|
|
|
/* Autostart other processes */
|
2008-10-14 11:40:30 +02:00
|
|
|
autostart_start(autostart_processes);
|
|
|
|
|
|
|
|
//Give ourselves a prefix
|
2009-07-23 18:16:07 +02:00
|
|
|
// init_net();
|
|
|
|
|
|
|
|
/*---If using coffee file system create initial web content if necessary---*/
|
|
|
|
#if COFFEE_FILES
|
|
|
|
int fa = cfs_open( "/index.html", CFS_READ);
|
|
|
|
if (fa<0) { //Make some default web content
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA("No index.html file found, creating upload.html!\n");
|
|
|
|
PRINTA("Formatting FLASH file system for coffee...");
|
2009-07-23 18:16:07 +02:00
|
|
|
cfs_coffee_format();
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA("Done!\n");
|
2009-07-23 18:16:07 +02:00
|
|
|
fa = cfs_open( "/index.html", CFS_WRITE);
|
|
|
|
int r = cfs_write(fa, &"It works!", 9);
|
2011-08-28 22:22:39 +02:00
|
|
|
if (r<0) PRINTA("Can''t create /index.html!\n");
|
2009-07-23 18:16:07 +02:00
|
|
|
cfs_close(fa);
|
|
|
|
// fa = cfs_open("upload.html"), CFW_WRITE);
|
|
|
|
// <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html>
|
|
|
|
}
|
2010-02-28 22:29:19 +01:00
|
|
|
#endif /* COFFEE_FILES */
|
|
|
|
|
2010-03-17 21:19:33 +01:00
|
|
|
/* Add addresses for testing */
|
2010-02-28 22:29:19 +01:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
uip_ip6addr_t ipaddr;
|
|
|
|
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
2010-03-17 21:19:33 +01:00
|
|
|
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
|
|
|
// uip_ds6_prefix_add(&ipaddr,64,0);
|
2010-02-28 22:29:19 +01:00
|
|
|
}
|
2009-07-23 18:16:07 +02:00
|
|
|
#endif
|
2008-10-14 11:40:30 +02:00
|
|
|
|
2009-07-23 18:16:07 +02:00
|
|
|
/*--------------------------Announce the configuration---------------------*/
|
2010-02-09 15:43:16 +01:00
|
|
|
#if ANNOUNCE_BOOT
|
2011-08-28 22:22:39 +02:00
|
|
|
{
|
2011-07-24 17:43:17 +02:00
|
|
|
#if AVR_WEBSERVER
|
2010-02-09 15:43:16 +01:00
|
|
|
uint8_t i;
|
2009-07-26 14:10:38 +02:00
|
|
|
char buf[80];
|
|
|
|
unsigned int size;
|
2010-02-28 22:29:19 +01:00
|
|
|
|
2010-03-17 21:19:33 +01:00
|
|
|
for (i=0;i<UIP_DS6_ADDR_NB;i++) {
|
|
|
|
if (uip_ds6_if.addr_list[i].isused) {
|
|
|
|
httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf);
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA("IPv6 Address: %s\n",buf);
|
2010-03-17 21:19:33 +01:00
|
|
|
}
|
2010-02-28 22:29:19 +01:00
|
|
|
}
|
2011-08-28 22:22:39 +02:00
|
|
|
cli();
|
|
|
|
eeprom_read_block (buf,eemem_server_name, sizeof(eemem_server_name));
|
|
|
|
sei();
|
|
|
|
buf[sizeof(eemem_server_name)]=0;
|
|
|
|
PRINTA("%s",buf);
|
|
|
|
cli();
|
|
|
|
eeprom_read_block (buf,eemem_domain_name, sizeof(eemem_domain_name));
|
|
|
|
sei();
|
|
|
|
buf[sizeof(eemem_domain_name)]=0;
|
2009-07-23 18:16:07 +02:00
|
|
|
size=httpd_fs_get_size();
|
|
|
|
#ifndef COFFEE_FILES
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA(".%s online with fixed %u byte web content\n",buf,size);
|
2009-07-23 18:16:07 +02:00
|
|
|
#elif COFFEE_FILES==1
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA(".%s online with static %u byte EEPROM file system\n",buf,size);
|
2009-07-23 18:16:07 +02:00
|
|
|
#elif COFFEE_FILES==2
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10);
|
2009-07-23 18:16:07 +02:00
|
|
|
#elif COFFEE_FILES==3
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA(".%s online with static %u byte program memory file system\n",buf,size);
|
2009-07-23 18:16:07 +02:00
|
|
|
#elif COFFEE_FILES==4
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA(".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
|
2010-02-28 22:29:19 +01:00
|
|
|
#endif /* COFFEE_FILES */
|
2010-02-09 15:43:16 +01:00
|
|
|
|
2009-07-26 14:10:38 +02:00
|
|
|
#else
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTA("Online\n");
|
2011-07-24 17:43:17 +02:00
|
|
|
#endif /* AVR_WEBSERVER */
|
2010-02-09 15:43:16 +01:00
|
|
|
|
|
|
|
#endif /* ANNOUNCE_BOOT */
|
2009-07-23 18:16:07 +02:00
|
|
|
}
|
2011-08-28 22:22:39 +02:00
|
|
|
}
|
2010-02-28 22:29:19 +01:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#if ROUTES && UIP_CONF_IPV6
|
|
|
|
static void
|
|
|
|
ipaddr_add(const uip_ipaddr_t *addr)
|
|
|
|
{
|
|
|
|
uint16_t a;
|
|
|
|
int8_t i, f;
|
|
|
|
for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) {
|
|
|
|
a = (addr->u8[i] << 8) + addr->u8[i + 1];
|
|
|
|
if(a == 0 && f >= 0) {
|
|
|
|
if(f++ == 0) PRINTF("::");
|
|
|
|
} else {
|
|
|
|
if(f > 0) {
|
|
|
|
f = -1;
|
|
|
|
} else if(i > 0) {
|
|
|
|
PRINTF(":");
|
|
|
|
}
|
|
|
|
PRINTF("%x",a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-02 17:25:47 +01:00
|
|
|
#endif
|
2011-02-28 22:26:28 +01:00
|
|
|
|
2009-07-23 18:16:07 +02:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/*------------------------- Main Scheduler loop----------------------------*/
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
initialize();
|
2010-02-28 22:29:19 +01:00
|
|
|
|
2008-10-14 11:40:30 +02:00
|
|
|
while(1) {
|
|
|
|
process_run();
|
2011-02-28 22:26:28 +01:00
|
|
|
watchdog_periodic();
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Various entry points for debugging in the AVR Studio simulator.
|
|
|
|
* Set as next statement and step into the routine.
|
|
|
|
*/
|
|
|
|
NETSTACK_RADIO.send(packetbuf_hdrptr(), 42);
|
|
|
|
process_poll(&rf230_process);
|
|
|
|
packetbuf_clear();
|
|
|
|
len = rf230_read(packetbuf_dataptr(), PACKETBUF_SIZE);
|
|
|
|
packetbuf_set_datalen(42);
|
|
|
|
NETSTACK_RDC.input();
|
2011-02-07 20:06:53 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
2011-02-28 22:26:28 +01:00
|
|
|
/* Clock.c can trigger a periodic PLL calibration in the RF230BB driver.
|
|
|
|
* This can show when that happens.
|
|
|
|
*/
|
|
|
|
extern uint8_t rf230_calibrated;
|
2011-02-07 20:06:53 +01:00
|
|
|
if (rf230_calibrated) {
|
2011-08-28 22:22:39 +02:00
|
|
|
PRINTD("\nRF230 calibrated!\n");
|
2011-02-07 20:06:53 +01:00
|
|
|
rf230_calibrated=0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#if DEBUGFLOWSIZE
|
|
|
|
if (debugflowsize) {
|
|
|
|
debugflow[debugflowsize]=0;
|
|
|
|
PRINTF("%s",debugflow);
|
|
|
|
debugflowsize=0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
watchdog_periodic();
|
|
|
|
|
|
|
|
#if PERIODICPRINTS
|
2010-02-28 22:29:19 +01:00
|
|
|
#if TESTRTIMER
|
2011-08-28 22:22:39 +02:00
|
|
|
/* Timeout can be increased up to 8 seconds maximum.
|
2011-02-28 22:26:28 +01:00
|
|
|
* A one second cycle is convenient for triggering the various debug printouts.
|
|
|
|
* The triggers are staggered to avoid printing everything at once.
|
|
|
|
*/
|
|
|
|
if (rtimerflag) {
|
2010-02-28 22:29:19 +01:00
|
|
|
rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
|
|
|
|
rtimerflag=0;
|
2011-08-28 22:22:39 +02:00
|
|
|
#else
|
|
|
|
if (clocktime!=clock_seconds()) {
|
|
|
|
clocktime=clock_seconds();
|
|
|
|
#endif
|
2011-02-28 22:26:28 +01:00
|
|
|
|
2010-02-28 22:29:19 +01:00
|
|
|
#if STAMPS
|
2011-08-28 22:22:39 +02:00
|
|
|
if ((clocktime%STAMPS)==0) {
|
|
|
|
#if ENERGEST_CONF_ON
|
|
|
|
#include "lib/print-stats.h"
|
|
|
|
print_stats();
|
|
|
|
#elif RADIOSTATS
|
|
|
|
extern volatile unsigned long radioontime;
|
|
|
|
PRINTF("%u(%u)s\n",clocktime,radioontime);
|
|
|
|
#else
|
|
|
|
PRINTF("%us\n",clocktime);
|
|
|
|
#endif
|
|
|
|
|
2011-02-28 22:26:28 +01:00
|
|
|
}
|
2010-02-28 22:29:19 +01:00
|
|
|
#endif
|
2011-08-28 22:22:39 +02:00
|
|
|
#if TESTRTIMER
|
|
|
|
clocktime+=1;
|
|
|
|
#endif
|
2011-02-28 22:26:28 +01:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#if PINGS && UIP_CONF_IPV6
|
|
|
|
extern void raven_ping6(void);
|
|
|
|
if ((clocktime%PINGS)==1) {
|
2011-02-28 22:26:28 +01:00
|
|
|
PRINTF("**Ping\n");
|
|
|
|
raven_ping6();
|
|
|
|
}
|
2010-02-28 22:29:19 +01:00
|
|
|
#endif
|
2011-02-28 22:26:28 +01:00
|
|
|
|
2011-08-28 22:22:39 +02:00
|
|
|
#if ROUTES && UIP_CONF_IPV6
|
|
|
|
if ((clocktime%ROUTES)==2) {
|
2011-02-28 22:26:28 +01:00
|
|
|
|
|
|
|
extern uip_ds6_nbr_t uip_ds6_nbr_cache[];
|
|
|
|
extern uip_ds6_route_t uip_ds6_routing_table[];
|
|
|
|
extern uip_ds6_netif_t uip_ds6_if;
|
|
|
|
|
|
|
|
uint8_t i,j;
|
|
|
|
PRINTF("\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
|
|
|
|
for (i=0;i<UIP_DS6_ADDR_NB;i++) {
|
2011-08-28 22:22:39 +02:00
|
|
|
if (uip_ds6_if.addr_list[i].isused) {
|
2011-02-28 22:26:28 +01:00
|
|
|
ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr);
|
|
|
|
PRINTF("\n");
|
2010-02-18 18:23:19 +01:00
|
|
|
}
|
2011-02-28 22:26:28 +01:00
|
|
|
}
|
|
|
|
PRINTF("\nNeighbors [%u max]\n",UIP_DS6_NBR_NB);
|
|
|
|
for(i = 0,j=1; i < UIP_DS6_NBR_NB; i++) {
|
|
|
|
if(uip_ds6_nbr_cache[i].isused) {
|
|
|
|
ipaddr_add(&uip_ds6_nbr_cache[i].ipaddr);
|
|
|
|
PRINTF("\n");
|
|
|
|
j=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j) PRINTF(" <none>");
|
|
|
|
PRINTF("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
|
|
|
|
for(i = 0,j=1; i < UIP_DS6_ROUTE_NB; i++) {
|
|
|
|
if(uip_ds6_routing_table[i].isused) {
|
|
|
|
ipaddr_add(&uip_ds6_routing_table[i].ipaddr);
|
|
|
|
PRINTF("/%u (via ", uip_ds6_routing_table[i].length);
|
|
|
|
ipaddr_add(&uip_ds6_routing_table[i].nexthop);
|
|
|
|
// if(uip_ds6_routing_table[i].state.lifetime < 600) {
|
|
|
|
PRINTF(") %lus\n", uip_ds6_routing_table[i].state.lifetime);
|
|
|
|
// } else {
|
|
|
|
// PRINTF(")\n");
|
|
|
|
// }
|
|
|
|
j=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j) PRINTF(" <none>");
|
|
|
|
PRINTF("\n---------\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if STACKMONITOR
|
2011-08-28 22:22:39 +02:00
|
|
|
if ((clocktime%STACKMONITOR)==3) {
|
2011-02-28 22:26:28 +01:00
|
|
|
extern uint16_t __bss_end;
|
|
|
|
uint16_t p=(uint16_t)&__bss_end;
|
|
|
|
do {
|
|
|
|
if (*(uint16_t *)p != 0x4242) {
|
|
|
|
PRINTF("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p+=10;
|
|
|
|
} while (p<RAMEND-10);
|
|
|
|
}
|
2010-02-18 18:23:19 +01:00
|
|
|
#endif
|
2010-02-28 22:29:19 +01:00
|
|
|
|
2011-02-28 22:26:28 +01:00
|
|
|
}
|
2011-08-28 22:22:39 +02:00
|
|
|
#endif /* PERIODICPRINTS */
|
2010-02-28 22:29:19 +01:00
|
|
|
|
|
|
|
#if RF230BB&&0
|
2011-08-28 22:22:39 +02:00
|
|
|
extern uint8_t rf230processflag;
|
2010-02-18 18:23:19 +01:00
|
|
|
if (rf230processflag) {
|
2011-02-28 22:26:28 +01:00
|
|
|
PRINTF("rf230p%d",rf230processflag);
|
2010-02-18 18:23:19 +01:00
|
|
|
rf230processflag=0;
|
2010-02-28 22:29:19 +01:00
|
|
|
}
|
2010-02-18 18:23:19 +01:00
|
|
|
#endif
|
2009-07-08 17:26:17 +02:00
|
|
|
|
2010-02-28 22:29:19 +01:00
|
|
|
#if RF230BB&&0
|
2011-08-28 22:22:39 +02:00
|
|
|
extern uint8_t rf230_interrupt_flag;
|
2009-07-08 17:26:17 +02:00
|
|
|
if (rf230_interrupt_flag) {
|
2010-02-28 22:29:19 +01:00
|
|
|
// if (rf230_interrupt_flag!=11) {
|
2011-02-28 22:26:28 +01:00
|
|
|
PRINTF("**RI%u",rf230_interrupt_flag);
|
2010-02-28 22:29:19 +01:00
|
|
|
// }
|
|
|
|
rf230_interrupt_flag=0;
|
2009-07-08 17:26:17 +02:00
|
|
|
}
|
2009-07-23 18:16:07 +02:00
|
|
|
#endif
|
2008-10-14 11:40:30 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-28 22:26:28 +01:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
void log_message(char *m1, char *m2)
|
|
|
|
{
|
|
|
|
PRINTF("%s%s\n", m1, m2);
|
|
|
|
}
|