From 02091b083aca19cdcd198faf65b77fbaa1dd7c54 Mon Sep 17 00:00:00 2001 From: dak664 Date: Fri, 11 Mar 2011 13:47:47 -0500 Subject: [PATCH] MAC address to EEMEM, not PROGMEM Sync atmega128rfa1 main routine to the raven (timed route prints, etc.) --- platform/avr-atmega128rfa1/contiki-main.c | 266 +++++++++++++++------- platform/avr-raven/contiki-raven-main.c | 2 +- 2 files changed, 185 insertions(+), 83 deletions(-) diff --git a/platform/avr-atmega128rfa1/contiki-main.c b/platform/avr-atmega128rfa1/contiki-main.c index a607b6700..7253707c8 100644 --- a/platform/avr-atmega128rfa1/contiki-main.c +++ b/platform/avr-atmega128rfa1/contiki-main.c @@ -30,16 +30,15 @@ * * @(#)$$ */ +#define LED_ON_PORTE1 0 //for Michael Hartman's prototype board #define ANNOUNCE_BOOT 1 //adds about 600 bytes to program size +#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args) #define DEBUG 0 #if DEBUG -#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args) -#define PRINTSHORT(FORMAT,args...) printf_P(PSTR(FORMAT),##args) - +#define PRINTFD(FORMAT,args...) printf_P(PSTR(FORMAT),##args) #else -#define PRINTF(...) -#define PRINTSHORT(...) +#define PRINTFD(...) #endif #include @@ -120,7 +119,7 @@ extern uint8_t mac_address[8]; //These are defined in httpd-fsdata.c via mak extern uint8_t server_name[16]; extern uint8_t domain_name[30]; #else -uint8_t mac_address[8] PROGMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55}; +uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55}; #endif @@ -173,13 +172,17 @@ void initialize(void) { watchdog_init(); watchdog_start(); - -#ifdef RAVEN_LCD_INTERFACE + +#if !LED_ON_PORTE1 //Conflicts with USART0 +#if RAVEN_LCD_INTERFACE /* First rs232 port for Raven 3290 port */ - //conflicts with led on Hartmann's board, so bypass for now -// rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); + 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); + 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 #endif /* Second rs232 port for debugging */ @@ -188,14 +191,29 @@ void initialize(void) rs232_redirect_stdout(RS232_PORT_1); clock_init(); -#define CONF_CALIBRATE_OSCCAL 1 +#if STACKMONITOR + /* Simple stack pointer highwater monitor. Checks for magic numbers in the main + * loop. In conjuction with TESTRTIMER, never-used stack will be printed + * every STACKMONITOR seconds. + */ +{ +extern uint16_t __bss_end; +uint16_t p=(uint16_t)&__bss_end; + do { + *(uint16_t *)p = 0x4242; + p+=10; + } while (p //#define delay_us( us ) ( _delay_loop_2(1+(us*F_CPU)/4000000UL) ) // delay_us(50000); @@ -205,7 +223,7 @@ uint8_t i; #endif #if ANNOUNCE_BOOT - printf_P(PSTR("\n*******Booting %s*******\n"),CONTIKI_VERSION_STRING); + PRINTF("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif watchdog_start(); /* rtimers needed for radio cycling */ @@ -240,7 +258,7 @@ uint8_t i; 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]); + PRINTFD("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]); /* Initialize stack protocols */ queuebuf_init(); @@ -249,19 +267,19 @@ uint8_t i; NETSTACK_NETWORK.init(); #if ANNOUNCE_BOOT - printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); + PRINTF("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); 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()); - if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp); + if (tmp<65535) PRINTF(", check rate %u Hz",tmp); } - printf_P(PSTR("\n")); + PRINTF("\n"); #endif #if UIP_CONF_ROUTER #if ANNOUNCE_BOOT - printf_P(PSTR("Routing Enabled\n")); + PRINTF("Routing Enabled\n"); #endif // rime_init(rime_udp_init(NULL)); // uip_router_register(&rimeroute); @@ -289,13 +307,13 @@ uint8_t i; #if COFFEE_FILES int fa = cfs_open( "/index.html", CFS_READ); if (fa<0) { //Make some default web content - printf_P(PSTR("No index.html file found, creating upload.html!\n")); - printf_P(PSTR("Formatting FLASH file system for coffee...")); + PRINTF("No index.html file found, creating upload.html!\n"); + PRINTF("Formatting FLASH file system for coffee..."); cfs_coffee_format(); - printf_P(PSTR("Done!\n")); + PRINTF("Done!\n"); fa = cfs_open( "/index.html", CFS_WRITE); int r = cfs_write(fa, &"It works!", 9); - if (r<0) printf_P(PSTR("Can''t create /index.html!\n")); + if (r<0) PRINTF("Can''t create /index.html!\n"); cfs_close(fa); // fa = cfs_open("upload.html"), CFW_WRITE); //
@@ -323,29 +341,29 @@ uint8_t i; for (i=0;i>10); + PRINTF(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10); #elif COFFEE_FILES==3 - printf_P(PSTR(".%s online with static %u byte program memory file system\n"),buf,size); + PRINTF(".%s online with static %u byte program memory file system\n",buf,size); #elif COFFEE_FILES==4 - printf_P(PSTR(".%s online with dynamic %u KB program memory file system\n"),buf,size>>10); + PRINTF(".%s online with dynamic %u KB program memory file system\n",buf,size>>10); #endif /* COFFEE_FILES */ #else - printf_P(PSTR("Online\n")); + PRINTF("Online\n"); #endif /* WEBSERVER */ #endif /* ANNOUNCE_BOOT */ @@ -354,17 +372,22 @@ uint8_t i; /*---------------------------------------------------------------------------*/ void log_message(char *m1, char *m2) { - printf_P(PSTR("%s%s\n"), m1, m2); + PRINTF("%s%s\n", m1, m2); } -/* Test rtimers, also useful for pings and time stamps in simulator */ -#define TESTRTIMER 0 +/* Test rtimers, also for pings, stack monitor, neighbor/route printout and time stamps */ +#define TESTRTIMER 1 #if TESTRTIMER -#define PINGS 60 +//#define PINGS 64 +#define ROUTES 64 #define STAMPS 30 +#define STACKMONITOR 128 + uint8_t rtimerflag=1; uint16_t rtime; struct rtimer rt; void rtimercycle(void) {rtimerflag=1;} +static void ipaddr_add(const uip_ipaddr_t *addr); + #endif /* TESTRTIMER */ #if RF230BB @@ -379,85 +402,140 @@ uint16_t ledtimer; int main(void) { -#define CONFIG_STACK_MONITOR 1 -#if CONFIG_STACK_MONITOR -extern uint16_t __bss_end; - __bss_end = 0x4242; - *(uint16_t *)(&__bss_end+100) = 0x4242; -#endif initialize(); +#if LED_ON_PORTE1 /* NB: PORTE1 conflicts with UART0 */ - DDRE|=(1<>16)); -#endif - } +#if STAMPS +if ((rtime%STAMPS)==0) { + PRINTF("%us ",rtime); +} #endif rtime+=1; + #if PINGS - if ((rtime%PINGS)==0) { - PRINTF("**Ping\n"); - raven_ping6(); - } +if ((rtime%PINGS)==1) { + PRINTF("**Ping\n"); + raven_ping6(); +} #endif + +#if ROUTES +if ((rtime%ROUTES)==2) { + + //#if UIP_CONF_IPV6_RPL +//#include "rpl.h" +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"); + 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(" "); + PRINTF("\n---------\n"); +} #endif +#if STACKMONITOR +if ((rtime%STACKMONITOR)==3) { + 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 (pu8[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 diff --git a/platform/avr-raven/contiki-raven-main.c b/platform/avr-raven/contiki-raven-main.c index fe9f482e7..722d90bc8 100644 --- a/platform/avr-raven/contiki-raven-main.c +++ b/platform/avr-raven/contiki-raven-main.c @@ -130,7 +130,7 @@ extern uint8_t mac_address[8]; //These are defined in httpd-fsdata.c via mak extern uint8_t server_name[16]; extern uint8_t domain_name[30]; #else -uint8_t mac_address[8] PROGMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55}; +uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55}; #endif