32 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
34 #define ANNOUNCE_BOOT 1 //adds about 600 bytes to program size
36 #define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
43 #define PRINTD(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
50 uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
51 #define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c
56 #include <avr/pgmspace.h>
58 #include <avr/eeprom.h>
61 #include <dev/watchdog.h>
63 #include "loader/symbols-def.h"
64 #include "loader/symtab.h"
73 #include "contiki-net.h"
74 #include "contiki-lib.h"
76 #include "dev/rs232.h"
80 #ifdef RAVEN_LCD_INTERFACE
81 #include "raven-lcd.h"
86 #include "httpd-cgi.h"
94 #if UIP_CONF_ROUTER&&0
95 #include "net/routing/rimeroute.h"
104 #define PERIODICPRINTS 1
109 #define STACKMONITOR 1024
113 uint8_t rtimerflag=1;
115 void rtimercycle(
void) {rtimerflag=1;}
125 #include <avr/signature.h>
128 typedef struct {
const unsigned char B2;
const unsigned char B1;
const unsigned char B0;} __signature_t;
129 #define SIGNATURE __signature_t __signature __attribute__((section (".signature")))
139 FUSES ={.low = 0xe2, .high = 0x99, .extended = 0xff,};
142 FUSES ={.low = 0xC2, .high = 0x99, .extended = 0xfe,};
146 rng_get_uint8(
void) {
150 j = (PHY_RSSI>>6) | (PHY_RSSI>>4) | (PHY_RSSI>>4) | PHY_RSSI;
159 while (ADCSRA&(1<<ADSC));
164 PRINTD(
"rng issues %d\n",j);
170 void initialize(
void)
178 #if !RF230BB_CONF_LEDONPORTE1 //Conflicts with USART0
179 #ifdef RAVEN_LCD_INTERFACE
180 rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
184 rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
189 rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
191 rs232_redirect_stdout(RS232_PORT_1);
194 if(MCUSR & (1<<PORF )) PRINTD(
"Power-on reset.\n");
195 if(MCUSR & (1<<EXTRF)) PRINTD(
"External reset!\n");
196 if(MCUSR & (1<<BORF )) PRINTD(
"Brownout reset!\n");
197 if(MCUSR & (1<<WDRF )) PRINTD(
"Watchdog reset!\n");
198 if(MCUSR & (1<<JTRF )) PRINTD(
"JTAG reset!\n");
206 extern uint16_t __bss_end;
207 uint16_t p=(uint16_t)&__bss_end;
209 *(uint16_t *)p = 0x4242;
215 #define CONF_CALIBRATE_OSCCAL 0
216 #if CONF_CALIBRATE_OSCCAL
219 extern uint8_t osccal_calibrated;
221 PRINTD(
"\nBefore calibration OSCCAL=%x\n",OSCCAL);
224 PRINTD(
"Calibrated=%x\n",osccal_calibrated);
233 PRINTA(
"\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
246 NETSTACK_RADIO.init();
252 random_init(rng_get_uint8());
258 if (params_get_eui64(addr.u8)) {
259 PRINTA(
"Random EUI64 address generated\n");
263 memcpy(&
uip_lladdr.addr, &addr.u8,
sizeof(rimeaddr_t));
265 node_id=get_panaddr_from_eeprom();
266 addr.u8[1]=node_id&0xff;
267 addr.u8[0]=(node_id&0xff00)>>8;
268 PRINTA(
"Node ID from eeprom: %X\n",node_id);
272 rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
273 rf230_set_channel(params_get_channel());
274 rf230_set_txpower(params_get_txpower());
277 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]);
279 PRINTA(
"MAC address ");
281 for (i=
sizeof(rimeaddr_t); i>0; i--){
282 PRINTA(
"%x:",addr.u8[i-1]);
291 NETSTACK_NETWORK.init();
294 PRINTA(
"%s %s, channel %u power %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel(),rf230_get_txpower());
295 if (NETSTACK_RDC.channel_check_interval) {
297 tmp=
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
298 NETSTACK_RDC.channel_check_interval());
299 if (tmp<65535) PRINTA(
", check rate %u Hz",tmp);
303 #if UIP_CONF_IPV6_RPL
304 PRINTA(
"RPL Enabled\n");
307 PRINTA(
"Routing Enabled\n");
314 #ifdef RAVEN_LCD_INTERFACE
319 autostart_start(autostart_processes);
325 PRINTA(
"No index.html file found, creating upload.html!\n");
326 PRINTA(
"Formatting FLASH file system for coffee...");
330 int r = cfs_write(fa, &
"It works!", 9);
331 if (r<0) PRINTA(
"Can''t create /index.html!\n");
341 uip_ip6addr_t ipaddr;
343 uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
355 for (i=0;i<UIP_DS6_ADDR_NB;i++) {
356 if (uip_ds6_if.addr_list[i].isused) {
357 httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf);
358 PRINTA(
"IPv6 Address: %s\n",buf);
362 eeprom_read_block (buf,eemem_server_name,
sizeof(eemem_server_name));
364 buf[
sizeof(eemem_server_name)]=0;
367 eeprom_read_block (buf,eemem_domain_name,
sizeof(eemem_domain_name));
369 buf[
sizeof(eemem_domain_name)]=0;
370 size=httpd_fs_get_size();
372 PRINTA(
".%s online with fixed %u byte web content\n",buf,size);
373 #elif COFFEE_FILES==1
374 PRINTA(
".%s online with static %u byte EEPROM file system\n",buf,size);
375 #elif COFFEE_FILES==2
376 PRINTA(
".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10);
377 #elif COFFEE_FILES==3
378 PRINTA(
".%s online with static %u byte program memory file system\n",buf,size);
379 #elif COFFEE_FILES==4
380 PRINTA(
".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
388 #if RF230BB_CONF_LEDONPORTE1
395 #if ROUTES && UIP_CONF_IPV6
402 a = (addr->u8[i] << 8) + addr->u8[i + 1];
403 if(a == 0 && f >= 0) {
404 if(f++ == 0) PRINTF(
"::");
432 #if RF230BB_CONF_LEDONPORTE1
435 #if defined(RAVEN_LCD_INTERFACE)&&0
437 extern void raven_ping6(
void);
452 NETSTACK_RDC.input();
459 extern uint8_t rf230_calibrated;
460 if (rf230_calibrated) {
461 PRINTD(
"\nRF230 calibrated!\n");
469 debugflow[debugflowsize]=0;
470 PRINTF(
"%s",debugflow);
485 if (clocktime!=clock_seconds()) {
486 clocktime=clock_seconds();
490 if ((clocktime%STAMPS)==0) {
495 extern volatile unsigned long radioontime;
496 PRINTF(
"%u(%u)s\n",clocktime,radioontime);
498 PRINTF(
"%us\n",clocktime);
507 #if PINGS && UIP_CONF_IPV6
508 extern void raven_ping6(
void);
509 if ((clocktime%PINGS)==1) {
515 #if ROUTES && UIP_CONF_IPV6
516 if ((clocktime%ROUTES)==2) {
523 PRINTF(
"\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
524 for (i=0;i<UIP_DS6_ADDR_NB;i++) {
525 if (uip_ds6_if.addr_list[i].isused) {
526 ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr);
530 PRINTF(
"\nNeighbors [%u max]\n",UIP_DS6_NBR_NB);
531 for(i = 0,j=1; i < UIP_DS6_NBR_NB; i++) {
532 if(uip_ds6_nbr_cache[i].isused) {
533 ipaddr_add(&uip_ds6_nbr_cache[i].ipaddr);
538 if (j) PRINTF(
" <none>");
539 PRINTF(
"\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
540 for(i = 0,j=1; i < UIP_DS6_ROUTE_NB; i++) {
541 if(uip_ds6_routing_table[i].isused) {
542 ipaddr_add(&uip_ds6_routing_table[i].ipaddr);
543 PRINTF(
"/%u (via ", uip_ds6_routing_table[i].length);
544 ipaddr_add(&uip_ds6_routing_table[i].nexthop);
546 PRINTF(
") %lus\n", uip_ds6_routing_table[i].state.lifetime);
553 if (j) PRINTF(
" <none>");
554 PRINTF(
"\n---------\n");
559 if ((clocktime%STACKMONITOR)==3) {
560 extern uint16_t __bss_end;
561 uint16_t p=(uint16_t)&__bss_end;
563 if (*(uint16_t *)p != 0x4242) {
564 PRINTF(
"Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
568 }
while (p<RAMEND-10);
576 extern uint8_t rf230processflag;
577 if (rf230processflag) {
578 PRINTF(
"rf230p%d",rf230processflag);
584 extern uint8_t rf230_interrupt_flag;
585 if (rf230_interrupt_flag) {
587 PRINTF(
"**RI%u",rf230_interrupt_flag);
589 rf230_interrupt_flag=0;
598 void log_message(
char *m1,
char *m2)
600 PRINTF(
"%s%s\n", m1, m2);