Refactor with params.c, h
This commit is contained in:
parent
9a1ce7cf75
commit
36b290a1cd
5 changed files with 584 additions and 223 deletions
|
@ -29,11 +29,23 @@
|
|||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
||||
|
||||
#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
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "uip-debug.h" ////Does #define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args) for AVR
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#define PRINTD(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
||||
#else
|
||||
#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
|
||||
|
@ -51,20 +63,12 @@ uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
|
|||
#include "loader/symbols-def.h"
|
||||
#include "loader/symtab.h"
|
||||
|
||||
#if RF230BB //radio driver using contiki core mac
|
||||
#include "params.h"
|
||||
#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"
|
||||
|
@ -73,7 +77,6 @@ uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
|
|||
#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
|
||||
|
@ -97,11 +100,12 @@ uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
|
|||
|
||||
/* 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
|
||||
//#define PINGS 64
|
||||
#define ROUTES 128
|
||||
#define STAMPS 30
|
||||
#define ROUTES 600
|
||||
#define STAMPS 60
|
||||
#define STACKMONITOR 1024
|
||||
uint32_t clocktime;
|
||||
#define TESTRTIMER 0
|
||||
|
@ -112,111 +116,86 @@ void rtimercycle(void) {rtimerflag=1;}
|
|||
#endif
|
||||
#endif
|
||||
|
||||
uint16_t ledtimer;
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/*----------------------Configuration of the .elf file---------------------*/
|
||||
typedef struct {unsigned char B2;unsigned char B1;unsigned char B0;} __signature_t;
|
||||
#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;
|
||||
#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,
|
||||
.B2 = 0x01,//SIGNATURE_2, //ATMEGA128rfa1
|
||||
.B1 = 0xA7,//SIGNATURE_1, //128KB flash
|
||||
.B0 = 0x1E,//SIGNATURE_0, //Atmel
|
||||
};
|
||||
//JTAG+SPI, Boot 4096 words @ $F000, Internal oscillator, startup 6 CK + 65 ms, Brownout disabled
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
/* JTAG, SPI enabled, Internal RC osc, Boot flash size 4K, 6CK+65msec delay, 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 */
|
||||
#if AVR_WEBSERVER
|
||||
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
|
||||
uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
|
||||
/* JTAG+SPI, Boot 4096 words @ $F000, Internal oscillator, startup 6 CK +0 ms, Brownout 1.8 volts */
|
||||
FUSES ={.low = 0xC2, .high = 0x99, .extended = 0xfe,};
|
||||
#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
|
||||
uint8_t
|
||||
rng_get_uint8(void) {
|
||||
#if 1
|
||||
/* Upper two RSSI reg bits (RND_VALUE) are random in rf231 */
|
||||
uint8_t j;
|
||||
j = (PHY_RSSI>>6) | (PHY_RSSI>>4) | (PHY_RSSI>>4) | PHY_RSSI;
|
||||
#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;
|
||||
/* Get a pseudo random number using the ADC */
|
||||
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
|
||||
#endif
|
||||
PRINTD("rng issues %d\n",j);
|
||||
return j;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
watchdog_init();
|
||||
watchdog_start();
|
||||
|
||||
/* The Raven implements a serial command and data interface via uart0 to a 3290p,
|
||||
* which could be duplicated using another host computer.
|
||||
*/
|
||||
#if !RF230BB_CONF_LEDONPORTE1 //Conflicts with USART0
|
||||
#if RAVEN_LCD_INTERFACE
|
||||
/* First rs232 port for Raven 3290 port */
|
||||
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||
/* Set input handler for 3290 port */
|
||||
rs232_set_input(0,raven_lcd_serial_input);
|
||||
#ifdef RAVEN_LCD_INTERFACE
|
||||
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||
rs232_set_input(0,raven_lcd_serial_input);
|
||||
#else
|
||||
//Slip border router on uart0
|
||||
/* Generic or slip connection on uart0 */
|
||||
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Second rs232 port for debugging or slip alternative */
|
||||
rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||
// rs232_init(RS232_PORT_1, USART_BAUD_115200,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||
|
||||
/* Redirect stdout to second port */
|
||||
rs232_redirect_stdout(RS232_PORT_1);
|
||||
clock_init();
|
||||
|
||||
#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();
|
||||
|
||||
if(MCUSR & (1<<PORF )) PRINTD("Power-on reset.\n");
|
||||
if(MCUSR & (1<<EXTRF)) PRINTD("External reset!\n");
|
||||
if(MCUSR & (1<<BORF )) PRINTD("Brownout reset!\n");
|
||||
if(MCUSR & (1<<WDRF )) PRINTD("Watchdog reset!\n");
|
||||
if(MCUSR & (1<<JTRF )) PRINTD("JTAG reset!\n");
|
||||
|
||||
#if STACKMONITOR
|
||||
/* Simple stack pointer highwater monitor. Checks for magic numbers in the main
|
||||
|
@ -232,85 +211,78 @@ uint16_t p=(uint16_t)&__bss_end;
|
|||
} while (p<SP-10); //don't overwrite our own stack
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
/* 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.
|
||||
*/
|
||||
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.
|
||||
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
|
||||
#endif
|
||||
|
||||
#define CONF_CALIBRATE_OSCCAL 0
|
||||
#if CONF_CALIBRATE_OSCCAL
|
||||
void calibrate_rc_osc_32k();
|
||||
{
|
||||
extern uint8_t osccal_calibrated;
|
||||
uint8_t i;
|
||||
watchdog_stop();
|
||||
PRINTA("\nBefore calibration OSCCAL=%x\n",OSCCAL);
|
||||
PRINTD("\nBefore calibration OSCCAL=%x\n",OSCCAL);
|
||||
for (i=0;i<10;i++) {
|
||||
calibrate_rc_osc_32k();
|
||||
PRINTA("Calibrated=%x\n",osccal_calibrated);
|
||||
PRINTD("Calibrated=%x\n",osccal_calibrated);
|
||||
//#include <util/delay_basic.h>
|
||||
//#define delay_us( us ) ( _delay_loop_2(1+(us*F_CPU)/4000000UL) )
|
||||
// delay_us(50000);
|
||||
}
|
||||
clock_init();
|
||||
watchdog_start();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ANNOUNCE_BOOT
|
||||
PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
|
||||
#endif
|
||||
|
||||
/* rtimers needed for radio cycling */
|
||||
rtimer_init();
|
||||
|
||||
/* Initialize process subsystem */
|
||||
process_init();
|
||||
/* etimers must be started before ctimer_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();
|
||||
|
||||
#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
|
||||
/* Get a random 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.
|
||||
*/
|
||||
random_init(rng_get_uint8());
|
||||
|
||||
/* Set addresses BEFORE starting tcpip process */
|
||||
|
||||
rimeaddr_t addr;
|
||||
memset(&addr, 0, sizeof(rimeaddr_t));
|
||||
get_mac_from_eeprom(addr.u8);
|
||||
|
||||
if (params_get_eui64(addr.u8)) {
|
||||
PRINTA("Random EUI64 address generated\n");
|
||||
}
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
memcpy(&uip_lladdr.addr, &addr.u8, 8);
|
||||
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);
|
||||
#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);
|
||||
|
||||
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]);
|
||||
rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
|
||||
rf230_set_channel(params_get_channel());
|
||||
rf230_set_txpower(params_get_txpower());
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
PRINTA("EUI-64 MAC: %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]);
|
||||
#else
|
||||
PRINTA("MAC address ");
|
||||
uint8_t i;
|
||||
for (i=sizeof(rimeaddr_t); i>0; i--){
|
||||
PRINTA("%x:",addr.u8[i-1]);
|
||||
}
|
||||
PRINTA("\n");
|
||||
#endif
|
||||
|
||||
/* Initialize stack protocols */
|
||||
queuebuf_init();
|
||||
|
@ -319,7 +291,7 @@ uint8_t i;
|
|||
NETSTACK_NETWORK.init();
|
||||
|
||||
#if ANNOUNCE_BOOT
|
||||
PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
|
||||
PRINTA("%s %s, channel %u power %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel(),rf230_get_txpower());
|
||||
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:\
|
||||
|
@ -327,24 +299,18 @@ uint8_t i;
|
|||
if (tmp<65535) PRINTA(", check rate %u Hz",tmp);
|
||||
}
|
||||
PRINTA("\n");
|
||||
#endif
|
||||
|
||||
#if UIP_CONF_IPV6_RPL
|
||||
PRINTA("RPL Enabled\n");
|
||||
#endif
|
||||
#if UIP_CONF_ROUTER
|
||||
#if ANNOUNCE_BOOT
|
||||
PRINTA("Routing Enabled\n");
|
||||
#endif
|
||||
// rime_init(rime_udp_init(NULL));
|
||||
// uip_router_register(&rimeroute);
|
||||
#endif
|
||||
|
||||
#endif /* ANNOUNCE_BOOT */
|
||||
|
||||
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
|
||||
|
@ -352,20 +318,17 @@ uint8_t i;
|
|||
/* 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
|
||||
PRINTF("No index.html file found, creating upload.html!\n");
|
||||
PRINTA("No index.html file found, creating upload.html!\n");
|
||||
PRINTA("Formatting FLASH file system for coffee...");
|
||||
cfs_coffee_format();
|
||||
PRINTA("Done!\n");
|
||||
fa = cfs_open( "/index.html", CFS_WRITE);
|
||||
int r = cfs_write(fa, &"It works!", 9);
|
||||
if (r<0) PRINTF("Can''t create /index.html!\n");
|
||||
if (r<0) PRINTA("Can''t create /index.html!\n");
|
||||
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>
|
||||
|
@ -384,9 +347,8 @@ uint8_t i;
|
|||
|
||||
/*--------------------------Announce the configuration---------------------*/
|
||||
#if ANNOUNCE_BOOT
|
||||
|
||||
#if AVR_WEBSERVER
|
||||
uint8_t i;
|
||||
{ uint8_t i;
|
||||
char buf[80];
|
||||
unsigned int size;
|
||||
|
||||
|
@ -396,11 +358,15 @@ uint8_t i;
|
|||
PRINTA("IPv6 Address: %s\n",buf);
|
||||
}
|
||||
}
|
||||
eeprom_read_block (buf,server_name, sizeof(server_name));
|
||||
buf[sizeof(server_name)]=0;
|
||||
cli();
|
||||
eeprom_read_block (buf,eemem_server_name, sizeof(eemem_server_name));
|
||||
sei();
|
||||
buf[sizeof(eemem_server_name)]=0;
|
||||
PRINTA("%s",buf);
|
||||
eeprom_read_block (buf,domain_name, sizeof(domain_name));
|
||||
buf[sizeof(domain_name)]=0;
|
||||
cli();
|
||||
eeprom_read_block (buf,eemem_domain_name, sizeof(eemem_domain_name));
|
||||
sei();
|
||||
buf[sizeof(eemem_domain_name)]=0;
|
||||
size=httpd_fs_get_size();
|
||||
#ifndef COFFEE_FILES
|
||||
PRINTA(".%s online with fixed %u byte web content\n",buf,size);
|
||||
|
@ -413,25 +379,40 @@ uint8_t i;
|
|||
#elif COFFEE_FILES==4
|
||||
PRINTA(".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
|
||||
#endif /* COFFEE_FILES */
|
||||
|
||||
}
|
||||
#else
|
||||
PRINTA("Online\n");
|
||||
#endif /* AVR_WEBSERVER */
|
||||
|
||||
#endif /* ANNOUNCE_BOOT */
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void log_message(char *m1, char *m2)
|
||||
{
|
||||
PRINTA("%s%s\n", m1, m2);
|
||||
}
|
||||
|
||||
#if RF230BB
|
||||
extern char rf230_interrupt_flag, rf230processflag;
|
||||
#endif
|
||||
#endif /* ANNOUNCE_BOOT */
|
||||
|
||||
uint16_t ledtimer;
|
||||
#if RF230BB_CONF_LEDONPORTE1
|
||||
/* NB: PORTE1 conflicts with UART0 */
|
||||
DDRE|=(1<<DDE1); //set led pin to output (Micheal Hatrtman board)
|
||||
PORTE&=~(1<<PE1); //and low to turn led off
|
||||
#endif
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/*------------------------- Main Scheduler loop----------------------------*/
|
||||
|
@ -439,37 +420,25 @@ uint16_t ledtimer;
|
|||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
initialize();
|
||||
|
||||
#if RF230BB_CONF_LEDONPORTE1
|
||||
/* NB: PORTE1 conflicts with UART0 */
|
||||
DDRE|=(1<<DDE1); //set led pin to output (Micheal Hatrtman board)
|
||||
PORTE&=~(1<<PE1); //and low to turn led off
|
||||
#endif
|
||||
|
||||
while(1) {
|
||||
process_run();
|
||||
process_run();
|
||||
watchdog_periodic();
|
||||
|
||||
#if DEBUGFLOWSIZE
|
||||
if (debugflowsize) {
|
||||
debugflow[debugflowsize]=0;
|
||||
PRINTA("%s",debugflow);
|
||||
debugflowsize=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if RF230BB_CONF_LEDONPORTE1
|
||||
/* Turn off LED after a while */
|
||||
if (ledtimer) {
|
||||
if (--ledtimer==0) {
|
||||
#if RF230BB_CONF_LEDONPORTE1
|
||||
PORTE&=~(1<<PE1);
|
||||
/* Currently LED was turned on by received ping; ping the other way for testing */
|
||||
extern void raven_ping6(void);
|
||||
// raven_ping6(); //ping back
|
||||
#endif
|
||||
#if defined(RAVEN_LCD_INTERFACE)&&0
|
||||
/* ledtimer can be set by received ping; ping the other way for testing */
|
||||
extern void raven_ping6(void);
|
||||
raven_ping6();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* Various entry points for debugging in the AVR Studio simulator.
|
||||
|
@ -483,18 +452,26 @@ main(void)
|
|||
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;
|
||||
if (rf230_calibrated) {
|
||||
PRINTA("\nRF230 calibrated!\n");
|
||||
PRINTD("\nRF230 calibrated!\n");
|
||||
rf230_calibrated=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set DEBUGFLOWSIZE in contiki-conf.h to track path through MAC, RDC, and RADIO */
|
||||
#if DEBUGFLOWSIZE
|
||||
if (debugflowsize) {
|
||||
debugflow[debugflowsize]=0;
|
||||
PRINTF("%s",debugflow);
|
||||
debugflowsize=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PERIODICPRINTS
|
||||
#if TESTRTIMER
|
||||
/* Timeout can be increased up to 8 seconds maximum.
|
||||
|
@ -516,9 +493,9 @@ if ((clocktime%STAMPS)==0) {
|
|||
print_stats();
|
||||
#elif RADIOSTATS
|
||||
extern volatile unsigned long radioontime;
|
||||
PRINTA("%u(%u)s\n",clocktime,radioontime);
|
||||
PRINTF("%u(%u)s\n",clocktime,radioontime);
|
||||
#else
|
||||
PRINTA("%us\n",clocktime);
|
||||
PRINTF("%us\n",clocktime);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -530,7 +507,7 @@ extern volatile unsigned long radioontime;
|
|||
#if PINGS && UIP_CONF_IPV6
|
||||
extern void raven_ping6(void);
|
||||
if ((clocktime%PINGS)==1) {
|
||||
PRINTA("**Ping\n");
|
||||
PRINTF("**Ping\n");
|
||||
raven_ping6();
|
||||
}
|
||||
#endif
|
||||
|
@ -543,38 +520,38 @@ extern uip_ds6_route_t uip_ds6_routing_table[];
|
|||
extern uip_ds6_netif_t uip_ds6_if;
|
||||
|
||||
uint8_t i,j;
|
||||
PRINTA("\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
|
||||
PRINTF("\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
|
||||
for (i=0;i<UIP_DS6_ADDR_NB;i++) {
|
||||
if (uip_ds6_if.addr_list[i].isused) {
|
||||
uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
PRINTA("\n");
|
||||
ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
PRINTF("\n");
|
||||
}
|
||||
}
|
||||
PRINTA("\nNeighbors [%u max]\n",UIP_DS6_NBR_NB);
|
||||
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) {
|
||||
uip_debug_ipaddr_print(&uip_ds6_nbr_cache[i].ipaddr);
|
||||
PRINTA("\n");
|
||||
ipaddr_add(&uip_ds6_nbr_cache[i].ipaddr);
|
||||
PRINTF("\n");
|
||||
j=0;
|
||||
}
|
||||
}
|
||||
if (j) PRINTA(" <none>");
|
||||
PRINTA("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
|
||||
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) {
|
||||
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);
|
||||
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) {
|
||||
PRINTA(") %lus\n", uip_ds6_routing_table[i].state.lifetime);
|
||||
PRINTF(") %lus\n", uip_ds6_routing_table[i].state.lifetime);
|
||||
// } else {
|
||||
// PRINTA(")\n");
|
||||
// PRINTF(")\n");
|
||||
// }
|
||||
j=0;
|
||||
}
|
||||
}
|
||||
if (j) PRINTA(" <none>");
|
||||
PRINTA("\n---------\n");
|
||||
if (j) PRINTF(" <none>");
|
||||
PRINTF("\n---------\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -584,7 +561,7 @@ if ((clocktime%STACKMONITOR)==3) {
|
|||
uint16_t p=(uint16_t)&__bss_end;
|
||||
do {
|
||||
if (*(uint16_t *)p != 0x4242) {
|
||||
PRINTA("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
|
||||
PRINTF("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
|
||||
break;
|
||||
}
|
||||
p+=10;
|
||||
|
@ -596,20 +573,29 @@ if ((clocktime%STACKMONITOR)==3) {
|
|||
#endif /* PERIODICPRINTS */
|
||||
|
||||
#if RF230BB&&0
|
||||
extern uint8_t rf230processflag;
|
||||
if (rf230processflag) {
|
||||
PRINTA("rf230p%d",rf230processflag);
|
||||
PRINTF("rf230p%d",rf230processflag);
|
||||
rf230processflag=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if RF230BB&&0
|
||||
extern uint8_t rf230_interrupt_flag;
|
||||
if (rf230_interrupt_flag) {
|
||||
// if (rf230_interrupt_flag!=11) {
|
||||
PRINTA("**RI%u",rf230_interrupt_flag);
|
||||
PRINTF("**RI%u",rf230_interrupt_flag);
|
||||
// }
|
||||
rf230_interrupt_flag=0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void log_message(char *m1, char *m2)
|
||||
{
|
||||
PRINTF("%s%s\n", m1, m2);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue