diff --git a/core/lib/print-stats.c b/core/lib/print-stats.c index f0d68dedc..29b6e83e4 100644 --- a/core/lib/print-stats.c +++ b/core/lib/print-stats.c @@ -44,14 +44,25 @@ #include "sys/energest.h" #include +#ifdef __AVR__ +#include +#define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args) +#else +#define PRINTA(...) printf(__VA_ARGS__) +#endif /*---------------------------------------------------------------------------*/ void print_stats(void) { - printf("S %d.%d clock %lu tx %lu rx %lu rtx %lu rrx %lu rexmit %lu acktx %lu noacktx %lu ackrx %lu timedout %lu badackrx %lu toolong %lu tooshort %lu badsynch %lu badcrc %lu contentiondrop %lu sendingdrop %lu lltx %lu llrx %lu\n", + PRINTA("S %d.%d clock %lu tx %lu rx %lu rtx %lu rrx %lu rexmit %lu acktx %lu noacktx %lu ackrx %lu timedout %lu badackrx %lu toolong %lu tooshort %lu badsynch %lu badcrc %lu contentiondrop %lu sendingdrop %lu lltx %lu llrx %lu\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], +#ifdef __AVR__ + clock_seconds(), +#else (unsigned long)clock_time() / CLOCK_SECOND, + +#endif rimestats.tx, rimestats.rx, rimestats.reliabletx, rimestats.reliablerx, rimestats.rexmit, rimestats.acktx, rimestats.noacktx, @@ -61,9 +72,14 @@ print_stats(void) rimestats.contentiondrop, rimestats.sendingdrop, rimestats.lltx, rimestats.llrx); #if ENERGEST_CONF_ON - printf("E %d.%d clock %lu cpu %lu lpm %lu irq %lu gled %lu yled %lu rled %lu tx %lu listen %lu sensors %lu serial %lu\n", + PRINTA("E %d.%d clock %lu cpu %lu lpm %lu irq %lu gled %lu yled %lu rled %lu tx %lu listen %lu sensors %lu serial %lu\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], - (unsigned long)(clock_time() / CLOCK_SECOND), +#ifdef __AVR__ + clock_seconds(), +#else + (unsigned long)clock_time() / CLOCK_SECOND, + +#endif energest_total_time[ENERGEST_TYPE_CPU].current, energest_total_time[ENERGEST_TYPE_LPM].current, energest_total_time[ENERGEST_TYPE_IRQ].current, diff --git a/platform/avr-atmega128rfa1/contiki-main.c b/platform/avr-atmega128rfa1/contiki-main.c index 93bbe4496..552f071af 100644 --- a/platform/avr-atmega128rfa1/contiki-main.c +++ b/platform/avr-atmega128rfa1/contiki-main.c @@ -37,6 +37,13 @@ #define DEBUG DEBUG_PRINT #include "uip-debug.h" ////Does #define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args) for AVR +#if DEBUGFLOWSIZE +uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE]; +#define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c +#else +#define DEBUGFLOW(c) +#endif + #include #include #include @@ -91,20 +98,22 @@ #include "net/rime.h" -/* Test rtimers, also for pings, stack monitor, neighbor/route printout and time stamps */ -#define TESTRTIMER 1 -#if TESTRTIMER +/* 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 //#define PINGS 64 -#define ROUTES 64 +#define ROUTES 128 #define STAMPS 30 -#define STACKMONITOR 128 - +#define STACKMONITOR 1024 +uint16_t clocktime; +#define TESTRTIMER 0 +#if TESTRTIMER uint8_t rtimerflag=1; -uint16_t rtime; struct rtimer rt; void rtimercycle(void) {rtimerflag=1;} - -#endif /* TESTRTIMER */ +#endif +#endif /*-------------------------------------------------------------------------*/ /*----------------------Configuration of the .elf file---------------------*/ @@ -212,7 +221,7 @@ void initialize(void) #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 + * loop. In conjuction with PERIODICPRINTS, never-used stack will be printed * every STACKMONITOR seconds. */ { @@ -224,19 +233,21 @@ uint16_t p=(uint16_t)&__bss_end; } while (p>6) | (PHY_RSSI>>4) | (PHY_RSSI>>4) | PHY_RSSI; + PRINTF("rnd=%d\n", somebits); + random_init(somebits); +} +#endif + /* Set addresses BEFORE starting tcpip process */ rimeaddr_t addr; @@ -432,6 +452,14 @@ main(void) while(1) { process_run(); +#if DEBUGFLOWSIZE + if (debugflowsize) { + debugflow[debugflowsize]=0; + PRINTA("%s",debugflow); + debugflowsize=0; + } +#endif + #if LED_ON_PORTE1 /* Turn off LED after a while */ if (ledtimer) { @@ -468,33 +496,48 @@ main(void) } #endif +#if PERIODICPRINTS #if TESTRTIMER /* 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. - * My raven is 6% slow. */ if (rtimerflag) { rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL); rtimerflag=0; +#else + if (clocktime!=clock_seconds()) { + clocktime=clock_seconds(); +#endif #if STAMPS -if ((rtime%STAMPS)==0) { - PRINTA("%us ",rtime); +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 + } #endif - rtime+=1; +#if TESTRTIMER + clocktime+=1; +#endif #if PINGS && UIP_CONF_IPV6 extern void raven_ping6(void); -if ((rtime%PINGS)==1) { +if ((clocktime%PINGS)==1) { PRINTA("**Ping\n"); raven_ping6(); } #endif #if ROUTES && UIP_CONF_IPV6 -if ((rtime%ROUTES)==2) { +if ((clocktime%ROUTES)==2) { extern uip_ds6_nbr_t uip_ds6_nbr_cache[]; extern uip_ds6_route_t uip_ds6_routing_table[]; @@ -537,7 +580,7 @@ extern uip_ds6_netif_t uip_ds6_if; #endif #if STACKMONITOR -if ((rtime%STACKMONITOR)==3) { +if ((clocktime%STACKMONITOR)==3) { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { @@ -551,17 +594,7 @@ if ((rtime%STACKMONITOR)==3) { #endif } -#endif /* TESTRTIMER */ - -//Use with RF230BB DEBUGFLOW to show path through driver -#if RF230BB&&0 -extern uint8_t debugflowsize,debugflow[]; - if (debugflowsize) { - debugflow[debugflowsize]=0; - PRINTA("%s",debugflow); - debugflowsize=0; - } -#endif +#endif /* PERIODICPRINTS */ #if RF230BB&&0 if (rf230processflag) {