2011-02-07 19:15:21 +01: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-03-13 19:07:17 +01:00
|
|
|
#ifndef LED_ON_PORT1E
|
2011-03-11 19:47:47 +01:00
|
|
|
#define LED_ON_PORTE1 0 //for Michael Hartman's prototype board
|
2011-03-13 19:07:17 +01:00
|
|
|
#endif
|
2011-02-07 19:15:21 +01:00
|
|
|
#define ANNOUNCE_BOOT 1 //adds about 600 bytes to program size
|
|
|
|
|
2011-03-13 19:07:17 +01:00
|
|
|
#define DEBUG DEBUG_PRINT
|
|
|
|
#include "uip-debug.h" ////Does #define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args) for AVR
|
2011-02-07 19:15:21 +01:00
|
|
|
|
2011-08-15 20:55:18 +02:00
|
|
|
#if DEBUGFLOWSIZE
|
|
|
|
uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
|
|
|
|
#define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c
|
|
|
|
#else
|
|
|
|
#define DEBUGFLOW(c)
|
|
|
|
#endif
|
|
|
|
|
2011-02-07 19:15:21 +01:00
|
|
|
#include <avr/pgmspace.h>
|
|
|
|
#include <avr/fuse.h>
|
|
|
|
#include <avr/eeprom.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <dev/watchdog.h>
|
|
|
|
|
|
|
|
#include "loader/symbols-def.h"
|
|
|
|
#include "loader/symtab.h"
|
|
|
|
|
|
|
|
#if RF230BB //radio driver using contiki core mac
|
|
|
|
#include "radio/rf230bb/rf230bb.h"
|
|
|
|
#include "net/mac/frame802154.h"
|
|
|
|
#include "net/mac/framer-802154.h"
|
|
|
|
#include "net/sicslowpan.h"
|
|
|
|
|
|
|
|
#else //radio driver using Atmel/Cisco 802.15.4'ish MAC
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "mac.h"
|
|
|
|
#include "sicslowmac.h"
|
|
|
|
#include "sicslowpan.h"
|
|
|
|
#include "ieee-15-4-manager.h"
|
|
|
|
#endif /*RF230BB*/
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "contiki-net.h"
|
|
|
|
#include "contiki-lib.h"
|
|
|
|
|
|
|
|
#include "dev/rs232.h"
|
|
|
|
#include "dev/serial-line.h"
|
|
|
|
#include "dev/slip.h"
|
|
|
|
|
|
|
|
/* No 3290p to talk to but the lcd process still needed for uip stack ping callbacks */
|
|
|
|
#ifdef RAVEN_LCD_INTERFACE
|
|
|
|
#include "raven-lcd.h"
|
|
|
|
#endif
|
|
|
|
|
2011-07-24 17:43:17 +02:00
|
|
|
#if AVR_WEBSERVER
|
2011-02-07 19:15:21 +01:00
|
|
|
#include "httpd-fs.h"
|
|
|
|
#include "httpd-cgi.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef COFFEE_FILES
|
|
|
|
#include "cfs/cfs.h"
|
|
|
|
#include "cfs/cfs-coffee.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UIP_CONF_ROUTER&&0
|
|
|
|
#include "net/routing/rimeroute.h"
|
|
|
|
#include "net/rime/rime-udp.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "net/rime.h"
|
|
|
|
|
2011-08-15 20:55:18 +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 */
|
|
|
|
#define PERIODICPRINTS 1
|
|
|
|
#if PERIODICPRINTS
|
2011-03-11 22:28:02 +01:00
|
|
|
//#define PINGS 64
|
2011-08-15 20:55:18 +02:00
|
|
|
#define ROUTES 128
|
2011-03-11 22:28:02 +01:00
|
|
|
#define STAMPS 30
|
2011-08-15 20:55:18 +02:00
|
|
|
#define STACKMONITOR 1024
|
|
|
|
uint16_t clocktime;
|
|
|
|
#define TESTRTIMER 0
|
|
|
|
#if TESTRTIMER
|
2011-03-11 22:28:02 +01:00
|
|
|
uint8_t rtimerflag=1;
|
|
|
|
struct rtimer rt;
|
|
|
|
void rtimercycle(void) {rtimerflag=1;}
|
2011-08-15 20:55:18 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2011-03-11 22:28:02 +01:00
|
|
|
|
2011-02-07 19:15:21 +01:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/*----------------------Configuration of the .elf file---------------------*/
|
|
|
|
typedef struct {unsigned char B2;unsigned char B1;unsigned char B0;} __signature_t;
|
|
|
|
#define SIGNATURE __signature_t __signature __attribute__((section (".signature")))
|
|
|
|
SIGNATURE = {
|
|
|
|
/* Older AVR-GCCs may not define the SIGNATURE_n bytes so use explicit ATmega128rfa1 values */
|
|
|
|
.B2 = SIGNATURE_2,//0x01,//SIGNATURE_2,
|
|
|
|
.B1 = SIGNATURE_1,//0xA7,//SIGNATURE_1,
|
|
|
|
.B0 = SIGNATURE_0,//0x1E,//SIGNATURE_0,
|
|
|
|
};
|
|
|
|
//JTAG+SPI, Boot 4096 words @ $F000, Internal oscillator, startup 6 CK + 65 ms, Brownout disabled
|
|
|
|
FUSES ={.low = 0xe2, .high = 0x99, .extended = 0xff,};
|
|
|
|
//JTAG+SPI, Boot 4096 words @ $F000, Internal oscillator, startup 6 CK +0 ms, Brownout 1.8 volts
|
|
|
|
//FUSES ={.low = 0xC2, .high = 0x99, .extended = 0xfe,};
|
|
|
|
|
|
|
|
/*----------------------Configuration of EEPROM---------------------------*/
|
|
|
|
/* Use existing EEPROM if it passes the integrity test, else reinitialize with build values */
|
|
|
|
|
|
|
|
/* Put default MAC address in EEPROM */
|
2011-07-24 17:43:17 +02:00
|
|
|
#if AVR_WEBSERVER
|
2011-02-07 19:15:21 +01:00
|
|
|
extern uint8_t mac_address[8]; //These are defined in httpd-fsdata.c via makefsdata.h
|
|
|
|
extern uint8_t server_name[16];
|
|
|
|
extern uint8_t domain_name[30];
|
|
|
|
#else
|
2011-03-11 19:47:47 +01:00
|
|
|
uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
|
2011-02-07 19:15:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CHANNEL_802_15_4
|
|
|
|
uint8_t rf_channel[2] EEMEM = {CHANNEL_802_15_4, ~CHANNEL_802_15_4};
|
|
|
|
//uint8_t rf_channel[2] EEMEM = {11, ~11}; //econotag test
|
|
|
|
#else
|
|
|
|
uint8_t rf_channel[2] EEMEM = {26, ~26};
|
|
|
|
#endif
|
|
|
|
static uint8_t get_channel_from_eeprom() {
|
|
|
|
uint8_t eeprom_channel;
|
|
|
|
uint8_t eeprom_check;
|
|
|
|
|
|
|
|
eeprom_channel = eeprom_read_byte(&rf_channel[0]);
|
|
|
|
eeprom_check = eeprom_read_byte(&rf_channel[1]);
|
|
|
|
|
|
|
|
if(eeprom_channel==~eeprom_check)
|
|
|
|
return eeprom_channel;
|
|
|
|
|
|
|
|
#ifdef CHANNEL_802_15_4
|
|
|
|
//return(11);
|
|
|
|
return(CHANNEL_802_15_4);
|
|
|
|
#else
|
|
|
|
return 26;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool get_mac_from_eeprom(uint8_t* macptr) {
|
|
|
|
eeprom_read_block ((void *)macptr, &mac_address, 8);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t get_panid_from_eeprom(void) {
|
|
|
|
// TODO: Writeme!
|
|
|
|
return IEEE802154_PANID;
|
|
|
|
//return 0xaaaa; //econotag ack test
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t get_panaddr_from_eeprom(void) {
|
|
|
|
// TODO: Writeme!
|
|
|
|
return 0;
|
|
|
|
// return 0x1111; //econotag ack test
|
|
|
|
}
|
|
|
|
|
|
|
|
void calibrate_rc_osc_32k();
|
|
|
|
extern uint8_t osccal_calibrated;
|
|
|
|
/*-------------------------Low level initialization------------------------*/
|
|
|
|
/*------Done in a subroutine to keep main routine stack usage small--------*/
|
|
|
|
void initialize(void)
|
|
|
|
{
|
2011-03-11 19:47:47 +01:00
|
|
|
#if !LED_ON_PORTE1 //Conflicts with USART0
|
|
|
|
#if RAVEN_LCD_INTERFACE
|
2011-02-07 19:15:21 +01:00
|
|
|
/* First rs232 port for Raven 3290 port */
|
2011-03-11 19:47:47 +01:00
|
|
|
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
2011-02-07 19:15:21 +01:00
|
|
|
/* Set input handler for 3290 port */
|
2011-03-11 19:47:47 +01:00
|
|
|
rs232_set_input(0,raven_lcd_serial_input);
|
|
|
|
#else
|
|
|
|
//Slip border router on uart0
|
|
|
|
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
|
|
|
#endif
|
2011-02-07 19:15:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Second rs232 port for debugging */
|
|
|
|
rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
|
|
|
/* Redirect stdout to second port */
|
|
|
|
rs232_redirect_stdout(RS232_PORT_1);
|
|
|
|
clock_init();
|
2011-03-13 19:07:17 +01:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
if(MCUSR & (1<<PORF )) PRINTA("Power-on reset.\n");
|
|
|
|
if(MCUSR & (1<<EXTRF)) PRINTA("External reset!\n");
|
|
|
|
if(MCUSR & (1<<BORF )) PRINTA("Brownout reset!\n");
|
|
|
|
if(MCUSR & (1<<WDRF )) PRINTA("Watchdog reset!\n");
|
|
|
|
if(MCUSR & (1<<JTRF )) PRINTA("JTAG reset!\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
watchdog_init();
|
|
|
|
watchdog_start();
|
2011-02-07 19:15:21 +01:00
|
|
|
|
2011-03-11 19:47:47 +01:00
|
|
|
#if STACKMONITOR
|
|
|
|
/* Simple stack pointer highwater monitor. Checks for magic numbers in the main
|
2011-08-15 20:55:18 +02:00
|
|
|
* loop. In conjuction with PERIODICPRINTS, never-used stack will be printed
|
2011-03-11 19:47:47 +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-15 20:55:18 +02:00
|
|
|
#if 0
|
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-15 20:55:18 +02:00
|
|
|
ADMUX =0x5E; //Select AVDD as reference, measure 1.1 volt bandgap reference.
|
|
|
|
//ADCSRB|=1<<MUX5;
|
|
|
|
// ADMUX =0x49; //Select AVDD as reference, measure ADC0 10x differential.
|
2011-08-13 17:31:20 +02:00
|
|
|
ADCSRA=1<<ADEN; //Enable ADC, not free running, interrupt disabled, fastest clock
|
|
|
|
ADCSRA|=1<<ADSC; //Start conversion
|
|
|
|
while (ADCSRA&(1<<ADSC)); //Wait till done
|
|
|
|
PRINTF("ADC=%d\n",ADC);
|
|
|
|
random_init(ADC);
|
|
|
|
ADCSRA=0; //Disable ADC
|
2011-08-15 20:55:18 +02:00
|
|
|
#endif
|
2011-03-11 19:47:47 +01:00
|
|
|
#define CONF_CALIBRATE_OSCCAL 0
|
2011-02-07 19:15:21 +01:00
|
|
|
#if CONF_CALIBRATE_OSCCAL
|
|
|
|
{
|
|
|
|
uint8_t i;
|
2011-03-13 19:07:17 +01:00
|
|
|
watchdog_stop();
|
|
|
|
PRINTA("\nBefore calibration OSCCAL=%x\n",OSCCAL);
|
2011-02-07 19:15:21 +01:00
|
|
|
for (i=0;i<10;i++) {
|
|
|
|
calibrate_rc_osc_32k();
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("Calibrated=%x\n",osccal_calibrated);
|
2011-02-07 19:15:21 +01:00
|
|
|
//#include <util/delay_basic.h>
|
|
|
|
//#define delay_us( us ) ( _delay_loop_2(1+(us*F_CPU)/4000000UL) )
|
|
|
|
// delay_us(50000);
|
|
|
|
}
|
|
|
|
clock_init();
|
2011-03-13 19:07:17 +01:00
|
|
|
watchdog_start();
|
2011-02-07 19:15:21 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ANNOUNCE_BOOT
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
|
2011-02-07 19:15:21 +01:00
|
|
|
#endif
|
2011-03-13 19:07:17 +01:00
|
|
|
|
2011-02-07 19:15:21 +01:00
|
|
|
/* rtimers needed for radio cycling */
|
|
|
|
rtimer_init();
|
|
|
|
|
|
|
|
/* Initialize process subsystem */
|
|
|
|
process_init();
|
|
|
|
/* etimers must be started before ctimer_init */
|
|
|
|
process_start(&etimer_process, NULL);
|
|
|
|
|
|
|
|
#if RF230BB
|
|
|
|
|
|
|
|
ctimer_init();
|
|
|
|
/* Start radio and radio receive process */
|
|
|
|
NETSTACK_RADIO.init();
|
|
|
|
|
2011-08-15 20:55:18 +02:00
|
|
|
#if 1
|
|
|
|
{uint8_t somebits;
|
|
|
|
/* Upper two RSSI reg bits (RND_VALUE) are random in rf231 */
|
|
|
|
somebits= (PHY_RSSI>>6) | (PHY_RSSI>>4) | (PHY_RSSI>>4) | PHY_RSSI;
|
|
|
|
PRINTF("rnd=%d\n", somebits);
|
|
|
|
random_init(somebits);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-07 19:15:21 +01:00
|
|
|
/* Set addresses BEFORE starting tcpip process */
|
|
|
|
|
|
|
|
rimeaddr_t addr;
|
|
|
|
memset(&addr, 0, sizeof(rimeaddr_t));
|
|
|
|
get_mac_from_eeprom(addr.u8);
|
|
|
|
|
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
memcpy(&uip_lladdr.addr, &addr.u8, 8);
|
|
|
|
#endif
|
|
|
|
rf230_set_pan_addr(
|
|
|
|
get_panid_from_eeprom(),
|
|
|
|
get_panaddr_from_eeprom(),
|
|
|
|
(uint8_t *)&addr.u8
|
|
|
|
);
|
|
|
|
rf230_set_channel(get_channel_from_eeprom());
|
|
|
|
|
|
|
|
rimeaddr_set_node_addr(&addr);
|
|
|
|
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
|
2011-02-07 19:15:21 +01:00
|
|
|
|
|
|
|
/* Initialize stack protocols */
|
|
|
|
queuebuf_init();
|
|
|
|
NETSTACK_RDC.init();
|
|
|
|
NETSTACK_MAC.init();
|
|
|
|
NETSTACK_NETWORK.init();
|
|
|
|
|
|
|
|
#if ANNOUNCE_BOOT
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
|
2011-02-07 19:15:21 +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-03-13 19:07:17 +01:00
|
|
|
if (tmp<65535) PRINTA(", check rate %u Hz",tmp);
|
2011-02-07 19:15:21 +01:00
|
|
|
}
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("\n");
|
2011-02-07 19:15:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UIP_CONF_ROUTER
|
|
|
|
#if ANNOUNCE_BOOT
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("Routing Enabled\n");
|
2011-02-07 19:15:21 +01:00
|
|
|
#endif
|
|
|
|
// rime_init(rime_udp_init(NULL));
|
|
|
|
// uip_router_register(&rimeroute);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
process_start(&tcpip_process, NULL);
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* mac process must be started before tcpip process! */
|
|
|
|
process_start(&mac_process, NULL);
|
|
|
|
process_start(&tcpip_process, NULL);
|
|
|
|
#endif /*RF230BB*/
|
|
|
|
|
|
|
|
#ifdef RAVEN_LCD_INTERFACE
|
|
|
|
process_start(&raven_lcd_process, NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Autostart other processes */
|
|
|
|
autostart_start(autostart_processes);
|
|
|
|
|
|
|
|
//Give ourselves a prefix
|
|
|
|
// 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-03-11 19:47:47 +01:00
|
|
|
PRINTF("No index.html file found, creating upload.html!\n");
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("Formatting FLASH file system for coffee...");
|
2011-02-07 19:15:21 +01:00
|
|
|
cfs_coffee_format();
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("Done!\n");
|
2011-02-07 19:15:21 +01:00
|
|
|
fa = cfs_open( "/index.html", CFS_WRITE);
|
|
|
|
int r = cfs_write(fa, &"It works!", 9);
|
2011-03-11 19:47:47 +01:00
|
|
|
if (r<0) PRINTF("Can''t create /index.html!\n");
|
2011-02-07 19:15:21 +01: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>
|
|
|
|
}
|
|
|
|
#endif /* COFFEE_FILES */
|
|
|
|
|
|
|
|
/* Add addresses for testing */
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
uip_ip6addr_t ipaddr;
|
|
|
|
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
|
|
|
// uip_ds6_prefix_add(&ipaddr,64,0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*--------------------------Announce the configuration---------------------*/
|
|
|
|
#if ANNOUNCE_BOOT
|
|
|
|
|
2011-07-24 17:43:17 +02:00
|
|
|
#if AVR_WEBSERVER
|
2011-02-07 19:15:21 +01:00
|
|
|
uint8_t i;
|
|
|
|
char buf[80];
|
|
|
|
unsigned int size;
|
|
|
|
|
|
|
|
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-03-13 19:07:17 +01:00
|
|
|
PRINTA("IPv6 Address: %s\n",buf);
|
2011-02-07 19:15:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
eeprom_read_block (buf,server_name, sizeof(server_name));
|
|
|
|
buf[sizeof(server_name)]=0;
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("%s",buf);
|
2011-02-07 19:15:21 +01:00
|
|
|
eeprom_read_block (buf,domain_name, sizeof(domain_name));
|
|
|
|
buf[sizeof(domain_name)]=0;
|
|
|
|
size=httpd_fs_get_size();
|
|
|
|
#ifndef COFFEE_FILES
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA(".%s online with fixed %u byte web content\n",buf,size);
|
2011-02-07 19:15:21 +01:00
|
|
|
#elif COFFEE_FILES==1
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA(".%s online with static %u byte EEPROM file system\n",buf,size);
|
2011-02-07 19:15:21 +01:00
|
|
|
#elif COFFEE_FILES==2
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10);
|
2011-02-07 19:15:21 +01:00
|
|
|
#elif COFFEE_FILES==3
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA(".%s online with static %u byte program memory file system\n",buf,size);
|
2011-02-07 19:15:21 +01:00
|
|
|
#elif COFFEE_FILES==4
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA(".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
|
2011-02-07 19:15:21 +01:00
|
|
|
#endif /* COFFEE_FILES */
|
|
|
|
|
|
|
|
#else
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("Online\n");
|
2011-07-24 17:43:17 +02:00
|
|
|
#endif /* AVR_WEBSERVER */
|
2011-02-07 19:15:21 +01:00
|
|
|
|
|
|
|
#endif /* ANNOUNCE_BOOT */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void log_message(char *m1, char *m2)
|
|
|
|
{
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("%s%s\n", m1, m2);
|
2011-02-07 19:15:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if RF230BB
|
|
|
|
extern char rf230_interrupt_flag, rf230processflag;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint16_t ledtimer;
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/*------------------------- Main Scheduler loop----------------------------*/
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
2011-03-11 19:47:47 +01:00
|
|
|
#if LED_ON_PORTE1
|
2011-02-07 19:15:21 +01:00
|
|
|
/* NB: PORTE1 conflicts with UART0 */
|
2011-03-11 19:47:47 +01:00
|
|
|
DDRE|=(1<<DDE1); //set led pin to output (Micheal Hatrtman board)
|
2011-02-07 19:15:21 +01:00
|
|
|
PORTE&=~(1<<PE1); //and low to turn led off
|
2011-03-11 19:47:47 +01:00
|
|
|
#endif
|
2011-02-07 19:15:21 +01:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
process_run();
|
|
|
|
|
2011-08-15 20:55:18 +02:00
|
|
|
#if DEBUGFLOWSIZE
|
|
|
|
if (debugflowsize) {
|
|
|
|
debugflow[debugflowsize]=0;
|
|
|
|
PRINTA("%s",debugflow);
|
|
|
|
debugflowsize=0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-11 19:47:47 +01:00
|
|
|
#if LED_ON_PORTE1
|
2011-02-07 19:15:21 +01:00
|
|
|
/* Turn off LED after a while */
|
|
|
|
if (ledtimer) {
|
|
|
|
if (--ledtimer==0) {
|
2011-03-11 19:47:47 +01:00
|
|
|
PORTE&=~(1<<PE1);
|
2011-02-07 19:15:21 +01:00
|
|
|
/* Currently LED was turned on by received ping; ping the other way for testing */
|
|
|
|
extern void raven_ping6(void);
|
2011-03-11 19:47:47 +01:00
|
|
|
// raven_ping6(); //ping back
|
2011-02-07 19:15:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
2011-03-11 19:47:47 +01:00
|
|
|
/* 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();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
watchdog_periodic();
|
|
|
|
#if 0
|
|
|
|
/* 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 19:15:21 +01:00
|
|
|
if (rf230_calibrated) {
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("\nRF230 calibrated!\n");
|
2011-02-07 19:15:21 +01:00
|
|
|
rf230_calibrated=0;
|
|
|
|
}
|
2011-03-11 19:47:47 +01:00
|
|
|
#endif
|
|
|
|
|
2011-08-15 20:55:18 +02:00
|
|
|
#if PERIODICPRINTS
|
2011-02-07 19:15:21 +01:00
|
|
|
#if TESTRTIMER
|
2011-03-11 19:47:47 +01:00
|
|
|
/* Timeout can be increased up to 8 seconds maximum.
|
|
|
|
* A one second cycle is convenient for triggering the various debug printouts.
|
|
|
|
* The triggers are staggered to avoid printing everything at once.
|
|
|
|
*/
|
|
|
|
if (rtimerflag) {
|
2011-02-07 19:15:21 +01:00
|
|
|
rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
|
|
|
|
rtimerflag=0;
|
2011-08-15 20:55:18 +02:00
|
|
|
#else
|
|
|
|
if (clocktime!=clock_seconds()) {
|
|
|
|
clocktime=clock_seconds();
|
|
|
|
#endif
|
2011-02-07 19:15:21 +01:00
|
|
|
|
2011-03-11 19:47:47 +01:00
|
|
|
#if STAMPS
|
2011-08-15 20:55:18 +02:00
|
|
|
if ((clocktime%STAMPS)==0) {
|
|
|
|
#if ENERGEST_CONF_ON
|
|
|
|
#include "lib/print-stats.h"
|
|
|
|
print_stats();
|
|
|
|
#elif RADIOSTATS
|
|
|
|
extern volatile unsigned long radioontime;
|
|
|
|
PRINTA("%u(%u)s",clocktime,radioontime);
|
|
|
|
#else
|
|
|
|
PRINTA("%us ",clocktime);
|
|
|
|
#endif
|
|
|
|
|
2011-03-11 19:47:47 +01:00
|
|
|
}
|
2011-02-07 19:15:21 +01:00
|
|
|
#endif
|
2011-08-15 20:55:18 +02:00
|
|
|
#if TESTRTIMER
|
|
|
|
clocktime+=1;
|
|
|
|
#endif
|
2011-03-11 19:47:47 +01:00
|
|
|
|
2011-05-18 17:09:16 +02:00
|
|
|
#if PINGS && UIP_CONF_IPV6
|
2011-03-13 19:07:17 +01:00
|
|
|
extern void raven_ping6(void);
|
2011-08-15 20:55:18 +02:00
|
|
|
if ((clocktime%PINGS)==1) {
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("**Ping\n");
|
2011-03-11 19:47:47 +01:00
|
|
|
raven_ping6();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-05-18 17:09:16 +02:00
|
|
|
#if ROUTES && UIP_CONF_IPV6
|
2011-08-15 20:55:18 +02:00
|
|
|
if ((clocktime%ROUTES)==2) {
|
2011-03-11 19:47:47 +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;
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
|
2011-03-11 19:47:47 +01:00
|
|
|
for (i=0;i<UIP_DS6_ADDR_NB;i++) {
|
2011-03-13 19:07:17 +01:00
|
|
|
if (uip_ds6_if.addr_list[i].isused) {
|
|
|
|
uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
|
|
|
|
PRINTA("\n");
|
2011-03-11 19:47:47 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("\nNeighbors [%u max]\n",UIP_DS6_NBR_NB);
|
2011-03-11 19:47:47 +01:00
|
|
|
for(i = 0,j=1; i < UIP_DS6_NBR_NB; i++) {
|
|
|
|
if(uip_ds6_nbr_cache[i].isused) {
|
2011-03-13 19:07:17 +01:00
|
|
|
uip_debug_ipaddr_print(&uip_ds6_nbr_cache[i].ipaddr);
|
|
|
|
PRINTA("\n");
|
2011-03-11 19:47:47 +01:00
|
|
|
j=0;
|
|
|
|
}
|
|
|
|
}
|
2011-03-13 19:07:17 +01:00
|
|
|
if (j) PRINTA(" <none>");
|
|
|
|
PRINTA("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
|
2011-03-11 19:47:47 +01:00
|
|
|
for(i = 0,j=1; i < UIP_DS6_ROUTE_NB; i++) {
|
|
|
|
if(uip_ds6_routing_table[i].isused) {
|
2011-03-13 19:07:17 +01:00
|
|
|
uip_debug_ipaddr_print(&uip_ds6_routing_table[i].ipaddr);
|
|
|
|
PRINTA("/%u (via ", uip_ds6_routing_table[i].length);
|
|
|
|
uip_debug_ipaddr_print(&uip_ds6_routing_table[i].nexthop);
|
2011-03-11 19:47:47 +01:00
|
|
|
// if(uip_ds6_routing_table[i].state.lifetime < 600) {
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA(") %lus\n", uip_ds6_routing_table[i].state.lifetime);
|
2011-03-11 19:47:47 +01:00
|
|
|
// } else {
|
2011-03-13 19:07:17 +01:00
|
|
|
// PRINTA(")\n");
|
2011-03-11 19:47:47 +01:00
|
|
|
// }
|
|
|
|
j=0;
|
|
|
|
}
|
|
|
|
}
|
2011-03-13 19:07:17 +01:00
|
|
|
if (j) PRINTA(" <none>");
|
|
|
|
PRINTA("\n---------\n");
|
2011-03-11 19:47:47 +01:00
|
|
|
}
|
2011-02-07 19:15:21 +01:00
|
|
|
#endif
|
2011-03-11 19:47:47 +01:00
|
|
|
|
|
|
|
#if STACKMONITOR
|
2011-08-15 20:55:18 +02:00
|
|
|
if ((clocktime%STACKMONITOR)==3) {
|
2011-03-11 19:47:47 +01:00
|
|
|
extern uint16_t __bss_end;
|
|
|
|
uint16_t p=(uint16_t)&__bss_end;
|
|
|
|
do {
|
|
|
|
if (*(uint16_t *)p != 0x4242) {
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
|
2011-03-11 19:47:47 +01:00
|
|
|
break;
|
2011-02-07 19:15:21 +01:00
|
|
|
}
|
2011-03-11 19:47:47 +01:00
|
|
|
p+=10;
|
|
|
|
} while (p<RAMEND-10);
|
|
|
|
}
|
2011-02-07 19:15:21 +01:00
|
|
|
#endif
|
|
|
|
|
2011-03-11 19:47:47 +01:00
|
|
|
}
|
2011-08-15 20:55:18 +02:00
|
|
|
#endif /* PERIODICPRINTS */
|
2011-02-07 19:15:21 +01:00
|
|
|
|
|
|
|
#if RF230BB&&0
|
|
|
|
if (rf230processflag) {
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("rf230p%d",rf230processflag);
|
2011-02-07 19:15:21 +01:00
|
|
|
rf230processflag=0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RF230BB&&0
|
|
|
|
if (rf230_interrupt_flag) {
|
|
|
|
// if (rf230_interrupt_flag!=11) {
|
2011-03-13 19:07:17 +01:00
|
|
|
PRINTA("**RI%u",rf230_interrupt_flag);
|
2011-02-07 19:15:21 +01:00
|
|
|
// }
|
|
|
|
rf230_interrupt_flag=0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return 0;
|
2011-03-13 19:07:17 +01:00
|
|
|
}
|