From 40bd02039474d12ae074ff912b536807f37681ef Mon Sep 17 00:00:00 2001 From: David Kopf Date: Mon, 9 Apr 2012 09:58:12 -0400 Subject: [PATCH 01/10] Fix wrong register addresses. --- .../radio/rf230bb/atmega128rfa1_registermap.h | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h b/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h index 2a86c547d..7eeb068ab 100644 --- a/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h +++ b/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h @@ -53,6 +53,8 @@ #define SR_TX_AUTO_CRC_ON 0x144, 0x20, 5 #define SR_TRAC_STATUS 0x142, 0xe0, 5 #define SR_CHANNEL 0x148, 0x1f, 0 +#define SR_CCA_MODE 0x148, 0x60, 5 +#define SR_CCA_REQUEST 0x148, 0x80, 7 #define RG_PAN_ID_0 PAN_ID_0 #define RG_PAN_ID_1 PAN_ID_1 #define RG_SHORT_ADDR_0 SHORT_ADDR_0 @@ -69,19 +71,17 @@ #define RG_PHY_ED_LEVEL PHY_ED_LEVEL #define RG_RX_SYN RX_SYN #define SR_RSSI 0x146, 0x1f, 0 -#define SR_PLL_CF_START 0x1a, 0x80, 7 -#define SR_PLL_DCU_START 0x1b, 0x80, 7 -#define SR_MAX_CSMA_RETRIES 0x2c, 0x0e, 1 +#define SR_PLL_CF_START 0x15a, 0x80, 7 +#define SR_PLL_DCU_START 0x15b, 0x80, 7 +#define SR_MAX_CSMA_RETRIES 0x16c, 0x0e, 1 #define RG_CSMA_BE CSMA_BE #define RG_CSMA_SEED_0 CSMA_SEED_0 #define RG_PHY_RSSI PHY_RSSI -#define SR_CCA_MODE 0x08, 0x60, 5 -//#define SR_CCA_CS_THRES 0x09, 0xf0, 4 -#define SR_CCA_ED_THRES 0x09, 0x0f, 0 -#define SR_CCA_REQUEST 0x08, 0x80, 7 -#define SR_CCA_DONE 0x01, 0x80, 7 -#define SR_CCA_STATUS 0x01, 0x40, 6 -#define SR_AACK_SET_PD 0x2e, 0x20, 5 +//#define SR_CCA_CS_THRES 0x149, 0xf0, 4 +#define SR_CCA_ED_THRES 0x149, 0x0f, 0 +#define SR_CCA_DONE 0x141, 0x80, 7 +#define SR_CCA_STATUS 0x141, 0x40, 6 +#define SR_AACK_SET_PD 0x16e, 0x20, 5 /* RF230 register assignments, for reference */ From 0612f771c68a62302dc62d389ebe137207990742 Mon Sep 17 00:00:00 2001 From: David Kopf Date: Mon, 9 Apr 2012 10:04:41 -0400 Subject: [PATCH 02/10] Restart ajax on changed update time, remove unused variable. --- apps/webserver-nano/httpd-cgi.c | 1 - apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/webserver-nano/httpd-cgi.c b/apps/webserver-nano/httpd-cgi.c index 7d73adcbc..de0b8c675 100644 --- a/apps/webserver-nano/httpd-cgi.c +++ b/apps/webserver-nano/httpd-cgi.c @@ -1057,7 +1057,6 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr)) static int iter; static char buf[128]; static uint8_t numprinted; - uint16_t dt; PSOCK_BEGIN(&s->sout); #if WEBSERVER_CONF_PASSQUERY diff --git a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js index cdd7cebc7..858a2a677 100644 --- a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js +++ b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js @@ -3,7 +3,7 @@ function e(el){return document.getElementById(el);} function ls(){try{r=new XMLHttpRequest();}catch(e){alert("Browswer does not support Ajax");return false;}r.open("GET","/ajaxdata.shtml",true); x=0;r.onreadystatechange=function(){e('date').innerHTML=(new Date()).toTimeString();if(r.readyState>0){j=r.responseText.substr(x);x+=j.length;eval(j);}};r.send(null);} -function tb(x){var t=e('ss');if(x||t.value=="RUN"){t.value="STOP";ls();}else{t.value="RUN";r.abort();}} +function tb(x){var t=e('ss');try{r.abort();}if(x||t.value=="RUN"){t.value="STOP";ls();}else t.value="RUN";} function s(el,n,max,text){e(el).innerHTML=''+''+''+''+'
'+text+'  
';} function wt(m){document.title=m;e('v').innerHTML=m;} function dc(n,d){return n.toFixed(d);} From c31f57ffb1b7a5e55df37ccb065218b7802e18c5 Mon Sep 17 00:00:00 2001 From: David Kopf Date: Mon, 9 Apr 2012 10:09:21 -0400 Subject: [PATCH 03/10] RPL is now default. --- examples/webserver-ipv6-raven/Makefile.webserver | 2 +- examples/webserver-ipv6-raven/README | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/webserver-ipv6-raven/Makefile.webserver b/examples/webserver-ipv6-raven/Makefile.webserver index 24fc0853a..2ec84da1a 100644 --- a/examples/webserver-ipv6-raven/Makefile.webserver +++ b/examples/webserver-ipv6-raven/Makefile.webserver @@ -5,7 +5,7 @@ APPS=raven-webserver raven-lcd-interface TARGET=avr-raven UIP_CONF_IPV6=1 -#WITH_RPL=1 //RPL is not yet the default. +#UIP_CONF_RPL=0 //RPL is now the default. #RF230BB=1 //Use radio driver that communicates with the core MAC layer. Now the default. #COFFEE_FILES=1 //Static coffee file system in EEPROM #COFFEE_FILES=2 //Dynamic coffee file system in EEPROM diff --git a/examples/webserver-ipv6-raven/README b/examples/webserver-ipv6-raven/README index 50d5887d6..514a75cde 100644 --- a/examples/webserver-ipv6-raven/README +++ b/examples/webserver-ipv6-raven/README @@ -41,8 +41,8 @@ so requires PERL. A bare $make after that will not regenerate httpd-fsdata.c. Use $make WEBDIR=default to switch back to the default /http-fs/ content. See Makefile.webserver for optional switches for RPL or a coffee file system. -$make WITH_RPL=1 for a RPL node, or if rpl has become the contiki default, -$make WITH_RPL=0 to override +$make UIP_CONF_RPL=1 for a RPL node, or if rpl has become the contiki default, +$make UIP_CONF_RPL=0 to override Much headbanging can result if you do not $make clean when changing make options, as the normal build dependencies are bypassed and the needed object modules From ea667cef2d8a8555340e2a4bb5cb479f5cb20412 Mon Sep 17 00:00:00 2001 From: David Kopf Date: Mon, 9 Apr 2012 10:10:45 -0400 Subject: [PATCH 04/10] Change Huginn and Muninn for params.c storage --- examples/webserver-ipv6-raven/Huginn/makefsdata.h | 9 ++++++--- examples/webserver-ipv6-raven/Muninn/makefsdata.h | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/webserver-ipv6-raven/Huginn/makefsdata.h b/examples/webserver-ipv6-raven/Huginn/makefsdata.h index 745c64687..654cb1eab 100644 --- a/examples/webserver-ipv6-raven/Huginn/makefsdata.h +++ b/examples/webserver-ipv6-raven/Huginn/makefsdata.h @@ -1,6 +1,9 @@ #include /* Link layer ipv6 address will become fe80::2 */ -uint8_t mac_address[8] EEMEM = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}; -uint8_t server_name[16] EEMEM = "huginn"; -uint8_t domain_name[30] EEMEM = "localhost"; +uint8_t default_mac_address[8] PROGMEM = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}; +uint8_t default_server_name[16] PROGMEM = "huginn"; +uint8_t default_domain_name[30] PROGMEM = "localhost"; +uint8_t eemem_mac_address[8] EEMEM = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}; +uint8_t eemem_server_name[16] EEMEM = "huginn"; +uint8_t eemem_domain_name[30] EEMEM = "localhost"; diff --git a/examples/webserver-ipv6-raven/Muninn/makefsdata.h b/examples/webserver-ipv6-raven/Muninn/makefsdata.h index 19c86149d..51b1a428e 100644 --- a/examples/webserver-ipv6-raven/Muninn/makefsdata.h +++ b/examples/webserver-ipv6-raven/Muninn/makefsdata.h @@ -1,6 +1,9 @@ #include /* Link layer ipv6 address will become fe80::1 */ -uint8_t mac_address[8] EEMEM = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; -uint8_t server_name[16] EEMEM = "muninn"; -uint8_t domain_name[30] EEMEM = "localhost"; +uint8_t default_mac_address[8] PROGMEM = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; +uint8_t default_server_name[16] PROGMEM = "muninn"; +uint8_t default_domain_name[30] PROGMEM = "localhost"; +uint8_t eemem_mac_address[8] EEMEM = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; +uint8_t eemem_server_name[16] EEMEM = "muninn"; +uint8_t eemem_domain_name[30] EEMEM = "localhost"; From cac4e9a2221b61fff61331446d0ec326521a7c67 Mon Sep 17 00:00:00 2001 From: David Kopf Date: Mon, 9 Apr 2012 15:49:53 -0400 Subject: [PATCH 05/10] Add clock_delay_us and clock_set_seconds to clock.h. Modify clock_wait to use clock_time_t. Remove the troublesome avr/dev/delay.* files. Add PLATFORM_NAME and combine the confusing *_REVISION defines into a single PLATFORM_TYPE --- core/sys/clock.h | 86 ++- cpu/avr/dev/clock.c | 492 ++++++++++++------ cpu/avr/dev/delay.c | 29 -- cpu/avr/dev/delay.h | 9 - cpu/avr/dev/rtl8019.c | 49 +- cpu/avr/radio/rf230/hal.h | 16 +- cpu/avr/radio/rf230bb/hal.h | 52 +- cpu/avr/rtimer-arch.c | 1 - cpu/cc2430/dev/clock.c | 2 +- cpu/cc253x/dev/clock.c | 2 +- cpu/mc1322x/clock.c | 85 ++- cpu/mc1322x/contiki-mc1322x-conf.h | 7 +- cpu/msp430/f1xxx/clock.c | 2 +- cpu/msp430/f5xxx/clock.c | 2 +- cpu/stm32w108/clock.c | 3 +- platform/avr-atmega128rfa1/contiki-conf.h | 53 +- .../apps/raven-lcd-interface/raven-lcd.c | 1 - platform/avr-raven/contiki-conf.h | 61 +-- platform/avr-ravenusb/contiki-conf.h | 53 +- platform/avr-rcb/contiki-conf.h | 39 +- platform/avr-zigbit/contiki-conf.h | 44 +- platform/esb/contiki-conf.h | 2 - platform/esb/dev/beep.c | 1 + platform/exp5438/clock.c | 2 +- platform/iris/contiki-conf.h | 7 - platform/iris/platform-conf.h | 29 +- platform/mb851/dev/acc-sensor.c | 3 +- platform/mbxxx/clock.c | 2 +- platform/mbxxx/dev/acc-sensor.c | 3 +- platform/micaz/contiki-conf.h | 23 +- platform/micaz/contiki-micaz-main.c | 5 +- platform/micaz/dev/clock.c | 4 +- platform/micaz/platform-conf.h | 33 +- platform/redbee-econotag/contiki-conf.h | 5 + platform/stk500/contiki-conf.h | 39 +- platform/stk501/contiki-conf.h | 37 +- platform/stk501/contiki-stk501-main.c | 2 +- platform/z1/contiki-z1-main.c | 2 +- tools/stm32w/uip6_bridge/uip6-bridge-tap.c | 4 +- 39 files changed, 810 insertions(+), 481 deletions(-) delete mode 100644 cpu/avr/dev/delay.c delete mode 100644 cpu/avr/dev/delay.h diff --git a/core/sys/clock.h b/core/sys/clock.h index b14db6112..986f6ae33 100644 --- a/core/sys/clock.h +++ b/core/sys/clock.h @@ -6,17 +6,28 @@ * \defgroup clock Clock library * * The clock library is the interface between Contiki and the platform - * specific clock functionality. The clock library performs a single - * function: measuring time. Additionally, the clock library provides - * a macro, CLOCK_SECOND, which corresponds to one second of system - * time. + * specific clock functionality. The clock library defines a macro, + * CLOCK_SECOND, to convert seconds into the tick resolution of the platform. + * Typically this is 1-10 milliseconds, e.g. 4*CLOCK_SECOND could be 512. + * A 16 bit counter would thus overflow every 1-10 minutes. + * Platforms use the tick interrupt to maintain a long term count + * of seconds since startup. + * + * Platforms may also implement rtimers for greater time resolution + * and for real-time interrupts, These use a corresponding RTIMER_SECOND. + * + * \note These timers do not necessarily have a common divisor or are phase locked. + * One may be crystal controlled and the other may not. Low power operation + * or sleep will often use one for wake and disable the other, then give + * it a tick correction after wakeup. * * \note The clock library need in many cases not be used - * directly. Rather, the \ref timer "timer library" or the \ref etimer - * "event timers" should be used. + * directly. Rather, the \ref timer "timer library", \ref etimer + * "event timers", or \ref trimer "rtimer library" should be used. * * \sa \ref timer "Timer library" * \sa \ref etimer "Event timers" + * \sa \ref rtimer "Realtime library" * * @{ */ @@ -53,24 +64,22 @@ * * Author: Adam Dunkels * - * $Id: clock.h,v 1.11 2009/01/24 15:20:11 adamdunkels Exp $ */ #ifndef __CLOCK_H__ #define __CLOCK_H__ #include "contiki-conf.h" -#if 0 /* XXX problems with signedness and use in timer_expired(). #if:ed it out for now. */ /** - * Check if a clock time value is less than another clock time value. - * - * This macro checks if a clock time value is less than another clock - * time value. This macro is needed to correctly handle wrap-around of - * clock time values. + * A second, measured in system clock time. * + * \hideinitializer */ -#define CLOCK_LT(a, b) ((clock_time_t)((a) - (b)) < ((clock_time_t)(~((clock_time_t)0)) >> 1)) -#endif /* 0 */ +#ifdef CLOCK_CONF_SECOND +#define CLOCK_SECOND CLOCK_CONF_SECOND +#else +#define CLOCK_SECOND (clock_time_t)32 +#endif /** * Initialize the clock library. @@ -90,24 +99,45 @@ void clock_init(void); */ CCIF clock_time_t clock_time(void); -void clock_delay(unsigned int); - /** - * A second, measured in system clock time. + * Get the current value of the platform seconds. * - * \hideinitializer + * This could be the number of seconds since startup, or + * since a standard epoch. + * + * \return The value. */ -#ifdef CLOCK_CONF_SECOND -#define CLOCK_SECOND CLOCK_CONF_SECOND -#else -#define CLOCK_SECOND (clock_time_t)32 -#endif - -int clock_fine_max(void); -unsigned short clock_fine(void); - CCIF unsigned long clock_seconds(void); +/** + * Set the value of the platform seconds. + * \param sec The value to set. + * + */ +void clock_set_seconds(unsigned long sec); + +/** + * Wait for a given number of ticks. + * \param t How many ticks. + * + */ +void clock_wait(clock_time_t t); + +/** + * Delay a given number of microseconds. + * \param dt How many microseconds to delay. + * + * \note Interrupts could increase the delay by a variable amount. + */ +void clock_delay_usec(uint16_t dt); + +/** + * Deprecated platform-specific routines. + * + */ +int clock_fine_max(void); +unsigned short clock_fine(void); +void clock_delay(unsigned int delay); #endif /* __CLOCK_H__ */ diff --git a/cpu/avr/dev/clock.c b/cpu/avr/dev/clock.c index 42a2c00a8..cc50364ec 100644 --- a/cpu/avr/dev/clock.c +++ b/cpu/avr/dev/clock.c @@ -1,4 +1,69 @@ - +/* + * Copyright (c) 2012, Swedish Institute of Computer Science. + * 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. + * + */ + /** + * \brief This module contains AVR-specific code to implement + * the Contiki core clock functions. + * + * \author David Kopf and others. + * +*/ +/** \addtogroup avr + * @{ + */ + /** + * \defgroup avrclock AVR clock implementation + * @{ + */ +/** + * \file + * This file contains AVR-specific code to implement the Contiki core clock functions. + * + */ +/** + * These routines define the AVR-specific calls declared in /core/sys/clock.h + * CLOCK_SECOND is the number of ticks per second. + * It is defined through CONF_CLOCK_SECOND in the contiki-conf.h for each platform. + * The usual AVR defaults are 128 or 125 ticks per second, counting a prescaled CPU clock + * using the 8 bit timer0. + * + * clock_time_t is usually declared by the platform as an unsigned 16 bit data type, + * thus intervals up to 512 or 524 seconds can be measured with ~8 millisecond precision. + * For longer intervals the 32 bit clock_seconds() is available. + * + * Since a carry to a higer byte can occur during an interrupt, declaring them non-static + * for direct examination can cause occasional time reversals! + * + * clock-avr.h contains the specific setup code for each mcu. + */ #include "sys/clock.h" #include "dev/clock-avr.h" #include "sys/etimer.h" @@ -6,25 +71,18 @@ #include #include -/* - CLOCK_SECOND is the number of ticks per second. - It is defined through CONF_CLOCK_SECOND in the contiki-conf.h for each platform. - The usual AVR defaults are 128 or 125 ticks per second, counting a prescaled CPU clock - using the 8 bit timer0. - - As clock_time_t is an unsigned 16 bit data type, intervals up to 512 or 524 seconds - can be measured with ~8 millisecond precision. - For longer intervals a 32 bit global is incremented every second. - - clock-avr.h contains the specific setup code for each mcu. +/* Two tick counters avoid a software divide when CLOCK_SECOND is not a power of two. */ +#if CLOCK_SECOND && (CLOCK_SECOND - 1) +#define TWO_COUNTERS 1 +#endif -*/ - -/* count is a 16 bit tick counter that wraps every ~10 minutes, returned by clock_time() */ +/* count is usually a 16 bit variable, although the platform can declare it otherwise */ static volatile clock_time_t count; +#if TWO_COUNTERS /* scount is the 8 bit counter that counts ticks modulo CLOCK_SECONDS */ static volatile uint8_t scount; -/* seconds is the number of seconds since startup, returned by clock_seconds() */ +#endif +/* seconds is available globally but non-atomic update during interrupt can cause time reversals */ volatile unsigned long seconds; /* sleepseconds is the number of seconds sleeping since startup, available globally */ long sleepseconds; @@ -50,99 +108,243 @@ extern volatile uint8_t rf230_calibrate; static uint8_t calibrate_interval; #endif +/*---------------------------------------------------------------------------*/ +/** + * Start the clock by enabling the timer comparison interrupts. + */ +void +clock_init(void) +{ + cli (); + OCRSetup(); + sei (); +} +/*---------------------------------------------------------------------------*/ +/** + * Return the tick counter. When 16 bit it typically wraps every 10 minutes. + * The comparison avoids the need to disable clock interrupts for an atomic + * read of the multi-byte variable. + */ +clock_time_t +clock_time(void) +{ + clock_time_t tmp; + do { + tmp = count; + } while(tmp != count); + return tmp; +} +/*---------------------------------------------------------------------------*/ +/** + * Return seconds, default is time since startup. + * The comparison avoids the need to disable clock interrupts for an atomic + * read of the four-byte variable. + */ +unsigned long +clock_seconds(void) +{ + unsigned long tmp; + do { + tmp = seconds; + } while(tmp != seconds); + return tmp; +} +/*---------------------------------------------------------------------------*/ +/** + * Set seconds, e.g. to a standard epoch for an absolute date/time. + */ +void +clock_set_seconds(unsigned long sec) +{ + seconds = sec; +} +/*---------------------------------------------------------------------------*/ +/** + * Wait for a number of clock ticks. + */ +void +clock_wait(clock_time_t t) +{ + clock_time_t endticks = clock_time() + t; + if (sizeof(clock_time_t) == 1) { + while ((signed char )(clock_time() - endticks) < 0) {;} + } else if (sizeof(clock_time_t) == 2) { + while ((signed short)(clock_time() - endticks) < 0) {;} + } else { + while ((signed long )(clock_time() - endticks) < 0) {;} + } +} +/*---------------------------------------------------------------------------*/ +/** + * Delay the CPU for up to 65535*(4000000/F_CPU) microseconds. + * Copied from _delay_loop_2 in AVR library delay_basic.h, 4 clocks per loop. + * For accurate short delays, inline _delay_loop_2 in the caller, use a constant + * value for the delay, and disable interrupts if necessary. + */ +static inline void my_delay_loop_2(uint16_t __count) __attribute__((always_inline)); +void +my_delay_loop_2(uint16_t __count) +{ + __asm__ volatile ( + "1: sbiw %0,1" "\n\t" + "brne 1b" + : "=w" (__count) + : "0" (__count) + ); +} +void +clock_delay_usec(uint16_t howlong) +{ +#if 0 +/* Accurate delay at any frequency, but introduces a 64 bit intermediate + * and has a 279 clock overhead. + */ + if(howlong<=(uint16_t)(279000000UL/F_CPU)) return; + howlong-=(uint16_t) (279000000UL/F_CPU); + my_delay_loop_2(((uint64_t)(howlong) * (uint64_t) F_CPU) / 4000000ULL); + /* Remaining numbers tweaked for the breakpoint CPU frequencies */ + /* Add other frequencies as necessary */ +#elif F_CPU>=16000000UL + if(howlong<1) return; + my_delay_loop_2((howlong*(uint16_t)(F_CPU/3250000))); +#elif F_CPU >= 12000000UL + if(howlong<2) return; + howlong-=(uint16_t) (3*12000000/F_CPU); + my_delay_loop_2((howlong*(uint16_t)(F_CPU/3250000))); +#elif F_CPU >= 8000000UL + if(howlong<4) return; + howlong-=(uint16_t) (3*8000000/F_CPU); + my_delay_loop_2((howlong*(uint16_t)(F_CPU/2000000))/2); +#elif F_CPU >= 4000000UL + if(howlong<5) return; + howlong-=(uint16_t) (4*4000000/F_CPU); + my_delay_loop_2((howlong*(uint16_t)(F_CPU/2000000))/2); +#elif F_CPU >= 2000000UL + if(howlong<11) return; + howlong-=(uint16_t) (10*2000000/F_CPU); + my_delay_loop_2((howlong*(uint16_t)(F_CPU/1000000))/4); +#elif F_CPU >= 1000000UL + if(howlong<=17) return; + howlong-=(uint16_t) (17*1000000/F_CPU); + my_delay_loop_2((howlong*(uint16_t)(F_CPU/1000000))/4); +#else + howlong >> 5; + if (howlong < 1) return; + my_delay_loop_2(howlong); +#endif +} #if 0 /*---------------------------------------------------------------------------*/ -/* This routine can be called to add seconds to the clock after a sleep - * of an integral number of seconds. +/** + * Legacy delay. The original clock_delay for the msp430 used a granularity + * of 2.83 usec. This approximates that delay for values up to 1456 usec. + * (The largest core call in leds.c uses 400). */ -void clock_adjust_seconds(uint8_t howmany) { - seconds += howmany; - sleepseconds +=howmany; - count += howmany * CLOCK_SECOND; -#if RADIOSTATS - if (RF230_receive_on) radioontime += howmany; -#endif +void +clock_delay(unsigned int howlong) +{ + if(howlong<2) return; + clock_delay_usec((45*howlong)>>4); } #endif +/*---------------------------------------------------------------------------*/ +/** + * Delay up to 65535 milliseconds. + * \param dt How many milliseconds to delay. + * + * Neither interrupts nor the watchdog timer is disabled over the delay. + * Platforms are not required to implement this call. + * \note This will break for CPUs clocked above 260 MHz. + */ +void +clock_delay_msec(uint16_t howlong) +{ -/*---------------------------------------------------------------------------*/ -/* This routine can be called to add ticks to the clock after a sleep. - * Leap ticks or seconds can (rarely) be introduced if the ISR is not blocked. - */ -void clock_adjust_ticks(uint16_t howmany) { -// uint8_t sreg = SREG;cli(); - count += howmany; - howmany+= scount; - while(howmany >= CLOCK_SECOND) { - howmany -= CLOCK_SECOND; - seconds++; - sleepseconds++; -#if RADIOSTATS - if (RF230_receive_on) radioontime += 1; +#if F_CPU>=16000000 + while(howlong--) clock_delay_usec(1000); +#elif F_CPU>=8000000 + uint16_t i=996; + while(howlong--) {clock_delay_usec(i);i=999;} +#elif F_CPU>=4000000 + uint16_t i=992; + while(howlong--) {clock_delay_usec(i);i=999;} +#elif F_CPU>=2000000 + uint16_t i=989; + while(howlong--) {clock_delay_usec(i);i=999;} +#else + uint16_t i=983; + while(howlong--) {clock_delay_usec(i);i=999;} #endif - } - scount = howmany; -// SREG=sreg; } /*---------------------------------------------------------------------------*/ -//SIGNAL(SIG_OUTPUT_COMPARE0) +/** + * Adjust the system current clock time. + * \param dt How many ticks to add + * + * Typically used to add ticks after an MCU sleep + * clock_seconds will increment if necessary to reflect the tick addition. + * Leap ticks or seconds can (rarely) be introduced if the ISR is not blocked. + */ +void +clock_adjust_ticks(clock_time_t howmany) +{ + uint8_t sreg = SREG;cli(); + count += howmany; +#if TWO_COUNTERS + howmany+= scount; +#endif + while(howmany >= CLOCK_SECOND) { + howmany -= CLOCK_SECOND; + seconds++; + sleepseconds++; +#if RADIOSTATS + if (RF230_receive_on) radioontime += 1; +#endif + } +#if TWO_COUNTERS + scount = howmany; +#endif + SREG=sreg; +} +/*---------------------------------------------------------------------------*/ +/* This it the timer comparison match interrupt. + * It maintains the tick counter, clock_seconds, and etimer updates. + * + * If the interrupts derive from an external crystal, the CPU instruction + * clock can optionally be phase locked to it. This allows accurate rtimer + * interrupts for strobe detection during radio duty cycling. + * Phase lock is accomplished by adjusting OSCCAL based on the phase error + * since the last interrupt. + */ +/*---------------------------------------------------------------------------*/ +#if defined(DOXYGEN) +/** \brief ISR for the TIMER0 or TIMER2 interrupt as defined in + * clock-avr.h for the particular MCU. + */ +void AVR_OUTPUT_COMPARE_INT(void); +#else ISR(AVR_OUTPUT_COMPARE_INT) { - count++; + count++; +#if TWO_COUNTERS if(++scount >= CLOCK_SECOND) { scount = 0; +#else + if(count%CLOCK_SECOND==0) { +#endif seconds++; - } - -#if F_CPU == 0x800000 && USE_32K_CRYSTAL -/* Special routine to phase lock CPU to 32768 watch crystal. - We are interrupting 128 times per second. - If RTIMER_ARCH_SECOND is a multiple of 128 we can use the residual modulo - 128 to determine whether the clock is too fast or too slow. - E.g. for 8192 the phase should be constant modulo 0x40 - OSCCAL is started in the lower range at 90, allowed to stabilize, then - rapidly raised or lowered based on the phase comparison. - It gives less phase noise to do this every tick and doesn't seem to hurt anything. -*/ -#include "rtimer-arch.h" -{ -volatile static uint8_t lockcount; -volatile static int16_t last_phase; -volatile static uint8_t osccalhigh,osccallow; - if (seconds < 60) { //give a minute to stabilize - if(++lockcount >= 8192UL*128/RTIMER_ARCH_SECOND) { - lockcount=0; - rtimer_phase = TCNT3 & 0x0fff; - if (seconds < 2) OSCCAL=100; - if (last_phase > rtimer_phase) osccalhigh=++OSCCAL; else osccallow=--OSCCAL; - last_phase = rtimer_phase; - } - } else { -#if TICK_MODULO - static uint8_t lock_clock; - if (++lock_clock>=TICK_MODULO) { - lock_clock=0; -#endif - uint8_t error = (TCNT3 - last_phase) & 0x3f; - if (error == 0) { - } else if (error<32) { - OSCCAL=osccallow-1; - } else { - OSCCAL=osccalhigh+1; - } -#if TICK_MODULO - } -#endif - } -} -#endif #if RADIO_CONF_CALIBRATE_INTERVAL - if (++calibrate_interval==0) { - rf230_calibrate=1; - } + /* Force a radio PLL frequency calibration every 256 seconds */ + if (++calibrate_interval==0) { + rf230_calibrate=1; + } #endif + + } + #if RADIOSTATS + /* Sample radio on time. Less accurate than ENERGEST but a smaller footprint */ if (RF230_receive_on) { if (++rcount >= CLOCK_SECOND) { rcount=0; @@ -150,6 +352,41 @@ volatile static uint8_t osccalhigh,osccallow; } } #endif + +#if F_CPU == 0x800000 && USE_32K_CRYSTAL +/* Special routine to phase lock CPU to 32768 watch crystal. + * We are interrupting 128 times per second. + * If RTIMER_ARCH_SECOND is a multiple of 128 we can use the residual modulo + * 128 to determine whether the clock is too fast or too slow. + * E.g. for 8192 the phase should be constant modulo 0x40 + * OSCCAL is started in the lower range at 90, allowed to stabilize, then + * rapidly raised or lowered based on the phase comparison. + * It gives less phase noise to do this every tick and doesn't seem to hurt anything. + */ +#include "rtimer-arch.h" +{ +volatile static uint8_t lockcount; +volatile static int16_t last_phase; +volatile static uint8_t osccalhigh,osccallow; + if (seconds < 60) { //give a minute to stabilize + if(++lockcount >= 8192UL*128/RTIMER_ARCH_SECOND) { + lockcount=0; + rtimer_phase = TCNT3 & 0x0fff; + if (seconds < 2) OSCCAL=100; + if (last_phase > rtimer_phase) osccalhigh=++OSCCAL; else osccallow=--OSCCAL; + last_phase = rtimer_phase; + } + } else { + uint8_t error = (TCNT3 - last_phase) & 0x3f; + if (error == 0) { + } else if (error<32) { + OSCCAL=osccallow-1; + } else { + OSCCAL=osccalhigh+1; + } + } +} +#endif #if 1 /* gcc will save all registers on the stack if an external routine is called */ @@ -166,80 +403,17 @@ volatile static uint8_t osccalhigh,osccallow; #define PROCESS_STATE_CALLED 2 if (timerlist) { - if(etimer_process.state == PROCESS_STATE_RUNNING || - etimer_process.state == PROCESS_STATE_CALLED) { + if(etimer_process.state == PROCESS_STATE_RUNNING || etimer_process.state == PROCESS_STATE_CALLED) { etimer_process.needspoll = 1; poll_requested = 1; } } #endif } - +#endif /* defined(DOXYGEN) */ /*---------------------------------------------------------------------------*/ -void -clock_init(void) -{ - cli (); - OCRSetup(); -//scount = count = 0; - sei (); -} +/* Debugging aids */ -/*---------------------------------------------------------------------------*/ -clock_time_t -clock_time(void) -{ - clock_time_t tmp; - do { - tmp = count; - } while(tmp != count); - return tmp; -} -#if 0 -/*---------------------------------------------------------------------------*/ -/** - * Delay the CPU for a multiple of TODO - */ -void -clock_delay(unsigned int i) -{ - for (; i > 0; i--) { /* Needs fixing XXX */ - unsigned j; - for (j = 50; j > 0; j--) - asm volatile("nop"); - } -} - -/*---------------------------------------------------------------------------*/ -/** - * Wait for a number of clock ticks. - * - */ -void -clock_wait(int i) -{ - clock_time_t start; - - start = clock_time(); - while(clock_time() - start < (clock_time_t)i); -} -/*---------------------------------------------------------------------------*/ -void -clock_set_seconds(unsigned long sec) -{ - seconds = sec; -} -#endif - -unsigned long -clock_seconds(void) -{ - unsigned long tmp; - do { - tmp = seconds; - } while(tmp != seconds); - return tmp; -} #ifdef HANDLE_UNSUPPORTED_INTERRUPTS /* Ignore unsupported interrupts, optionally hang for debugging */ /* BADISR is a gcc weak symbol that matches any undefined interrupt */ @@ -334,4 +508,6 @@ ISR( _VECTOR(76)) {while (1) x++;} ISR( _VECTOR(77)) {while (1) x++;} ISR( _VECTOR(78)) {while (1) x++;} ISR( _VECTOR(79)) {while (1) x++;} -#endif \ No newline at end of file +#endif +/** @} */ +/** @} */ diff --git a/cpu/avr/dev/delay.c b/cpu/avr/dev/delay.c deleted file mode 100644 index 01cc3e4e2..000000000 --- a/cpu/avr/dev/delay.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "delay.h" - -//---------------------------------------------------------------------------- -// Wait for a specific time in 100 uSec -// (15 + t*( ((K_DELAY_100us-1)*6)+5 )) -//---------------------------------------------------------------------------- -void Delay_100us(unsigned char t) { - unsigned int i; - if (t==0) return; - while (t--) for(i=0;i=16000000 + while(howlong--) clock_delay_usec(1000); +#elif F_CPU>=8000000 + uint16_t i=996; + while(howlong--) {clock_delay_usec(i);i=999;} +#elif F_CPU>=4000000 + uint16_t i=992; + while(howlong--) {clock_delay_usec(i);i=999;} +#elif F_CPU>=2000000 + uint16_t i=989; + while(howlong--) {clock_delay_usec(i);i=999;} +#else + uint16_t i=983; + while(howlong--) {clock_delay_usec(i);i=999;} +#endif +} /***************************************************************************** * readRTL(RTL_ADDRESS) * Args: unsigned char RTL_ADDRESS - register offset of RTL register @@ -191,7 +210,7 @@ volatile unsigned char *base = (unsigned char *)0x8300; * Description: Simply toggles the pin that resets the NIC *****************************************************************************/ /*#define HARD_RESET_RTL8019() do{ sbi(RTL8019_RESET_PORT, RTL8019_RESET_PIN); \ - Delay_10ms(1); \ + delay_msec(10); \ cbi(RTL8019_RESET_PORT, RTL8019_RESET_PIN);} \ while(0)*/ @@ -503,7 +522,7 @@ void overrun(void) data_L = readRTL(CR); writeRTL(CR, 0x21); - Delay_1ms(2); + delay_msec(2); writeRTL(RBCR0, 0x00); writeRTL(RBCR1, 0x00); if(!(data_L & 0x04)) @@ -686,7 +705,11 @@ void initRTL8019(void) */ nic_write(NIC_PG3_EECR, 0); /* NutSleep(WAIT500);*/ - Delay_10ms(50); + + delay_msec(500); + + + /* * Switch to register page 0 and set data configuration register @@ -772,7 +795,10 @@ void initRTL8019(void) nic_write(NIC_PG0_TCR, 0); /* NutSleep(WAIT500);*/ - Delay_10ms(50); + delay_msec(500); + + + #endif /* 0 */ @@ -788,7 +814,8 @@ void initRTL8019(void) nic_write(NIC_PG3_CONFIG2, NIC_CONFIG2_BSELB); nic_write(NIC_PG3_EECR, 0); /* Delay(50000);*/ - Delay_10ms(200); + delay_msec(2000); + nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2); nic_write(NIC_PG0_DCR, NIC_DCR_LS | NIC_DCR_FT1); nic_write(NIC_PG0_RBCR0, 0); @@ -813,7 +840,7 @@ void initRTL8019(void) nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2); nic_write(NIC_PG0_TCR, 0); /* Delay(1000000)*/ - Delay_10ms(200); + delay_msec(2000); nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2 | NIC_CR_PS0 | NIC_CR_PS1); @@ -874,10 +901,10 @@ void initRTL8019(void) // do soft reset writeRTL( ISR, readRTL(ISR) ) ; - Delay_10ms(5); + delay_msec(50); writeRTL(CR,0x21); // stop the NIC, abort DMA, page 0 - Delay_1ms(2); // make sure nothing is coming in or going out + delay_msec(2); // make sure nothing is coming in or going out writeRTL(DCR, DCR_INIT); // 0x58 writeRTL(RBCR0,0x00); writeRTL(RBCR1,0x00); @@ -888,7 +915,7 @@ void initRTL8019(void) writeRTL(BNRY, RXSTART_INIT); writeRTL(PSTOP, RXSTOP_INIT); writeRTL(CR, 0x61); - Delay_1ms(2); + delay_msec(2); writeRTL(CURR, RXSTART_INIT); writeRTL(PAR0+0, MYMAC_0); diff --git a/cpu/avr/radio/rf230/hal.h b/cpu/avr/radio/rf230/hal.h index 0f4ba42ea..f7c80d707 100644 --- a/cpu/avr/radio/rf230/hal.h +++ b/cpu/avr/radio/rf230/hal.h @@ -76,16 +76,16 @@ // RCB_B : RZ200 kit from Atmel based on 1281V // ZIGBIT : Zigbit module from Meshnetics // IRIS : IRIS Mote from MEMSIC -#define RAVEN_D 4 -#define RAVENUSB_C 1 -#define RCB_B 2 -#define ZIGBIT 3 +#define RAVEN_D 1 +#define RAVENUSB_C 2 +#define RCB_B 3 +#define ZIGBIT 4 #define IRIS 5 -#if RCB_REVISION == RCB_B +#if PLATFORM_TYPE == RCB_B /* 1281 rcb */ # define SSPORT B # define SSPIN (0x00) @@ -104,7 +104,7 @@ # define TICKTIMER 3 # define HAS_SPARE_TIMER -#elif HARWARE_REVISION == ZIGBIT +#elif PLATFORM_TYPE == ZIGBIT /* 1281V Zigbit */ # define SSPORT B # define SSPIN (0x00) @@ -170,7 +170,7 @@ # define HAS_CW_MODE # define HAS_SPARE_TIMER -#elif HARWARE_REVISION == IRIS +#elif PLATFORM_TYPE == IRIS /* 1281 IRIS */ # define SSPORT B # define SSPIN (0x00) @@ -296,7 +296,7 @@ #error "Clock speed not supported." #endif -#if HARWARE_REVISION == ZIGBIT +#if PLATFORM_TYPE == ZIGBIT // IRQ E5 for Zigbit example #define RADIO_VECT INT5_vect #define HAL_ENABLE_RADIO_INTERRUPT( ) { ( EIMSK |= ( 1 << INT5 ) ) ; EICRB |= 0x0C ; PORTE &= ~(1< 1 + adc_service(); #endif } - +#if CLOCK_CONF_SAMPLEADC == 1 + adc_service(); +#endif if(etimer_pending() && (etimer_next_expiration_time() - current_clock - 1) > MAX_TICKS) { etimer_request_poll(); @@ -98,9 +109,9 @@ void tmr0_isr(void) { /* clear the compare flags */ - clear_bit(*TMR(0,SCTRL),TCF); - clear_bit(*TMR(0,CSCTRL),TCF1); - clear_bit(*TMR(0,CSCTRL),TCF2); + clear_bit(*TMR(0,SCTRL),TCF); + clear_bit(*TMR(0,CSCTRL),TCF1); + clear_bit(*TMR(0,CSCTRL),TCF2); return; } else { /* this timer didn't create an interrupt condition */ @@ -120,13 +131,63 @@ clock_seconds(void) return seconds; } -/* clock delay from cc2430 */ -/* I don't see any documentation about how this routine is suppose to behave */ void -clock_delay(unsigned int len) +clock_wait(clock_time_t t) { - unsigned int i; - for(i = 0; i< len; i++) { - asm("nop"); - } + clock_time_t endticks = current_clock + t; + while ((signed long)(current_clock - endticks) < 0) {;} +} +/*---------------------------------------------------------------------------*/ +/** + * Delay the CPU for up to 65535 microseconds. + * Use the 250KHz MACA clock for longer delays to avoid interrupt effects. + * However that can't be used if the radio is being power cycled! + */ +void +clock_delay_usec(uint16_t howlong) +{ + if(howlong<2) return; +#if 0 + if(howlong>400) { + volatile register uint32_t i=*MACA_CLK+howlong/4; + while (i > *MACA_CLK) ; + return; + } +#endif + /* These numbers at 25MHz, gcc -Os */ + volatile register uint32_t i=4000*howlong/2301; + while(--i); +} +/*---------------------------------------------------------------------------*/ +/** + * Delay the CPU for up to 65535 milliseconds. The watchdog is NOT disabled. + */ +void +clock_delay_msec(uint16_t howlong) +{ + while(howlong--) clock_delay_usec(1000); +} +/*---------------------------------------------------------------------------*/ +/** + * Legacy delay. The original clock_delay for the msp430 used a granularity + * of 2.83 usec. This approximates that delay for values up to 1456 usec. + * (The largest core call in leds.c uses 400). + */ +void +clock_delay(unsigned int howlong) +{ + if(howlong--) return; + clock_delay_usec((283*howlong)/100); +} +/*---------------------------------------------------------------------------*/ +/** + * Adjust clock ticks after a cpu sleep. + */ +void clock_adjust_ticks(clock_time_t howmany) { +/* Add seconds */ + seconds+=howmany/CLOCK_CONF_SECOND; +/* Handle tick overflow */ + if(((current_clock % CLOCK_CONF_SECOND) + (howmany % CLOCK_CONF_SECOND)) >= CLOCK_CONF_SECOND) seconds++; +/* Add ticks */ + current_clock+=howmany; } diff --git a/cpu/mc1322x/contiki-mc1322x-conf.h b/cpu/mc1322x/contiki-mc1322x-conf.h index e7fce0aaa..da8f6582a 100644 --- a/cpu/mc1322x/contiki-mc1322x-conf.h +++ b/cpu/mc1322x/contiki-mc1322x-conf.h @@ -55,9 +55,4 @@ typedef unsigned short uip_stats_t; typedef uint32_t clock_time_t; -void clock_delay(unsigned int us2); -void clock_wait(int ms10); -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); - -#endif +#endif \ No newline at end of file diff --git a/cpu/msp430/f1xxx/clock.c b/cpu/msp430/f1xxx/clock.c index 8e0be8728..b17694f2a 100644 --- a/cpu/msp430/f1xxx/clock.c +++ b/cpu/msp430/f1xxx/clock.c @@ -186,7 +186,7 @@ clock_delay(unsigned int i) * */ void -clock_wait(int i) +clock_wait(clock_time_t i) { clock_time_t start; diff --git a/cpu/msp430/f5xxx/clock.c b/cpu/msp430/f5xxx/clock.c index d0cca7e83..3cda89232 100644 --- a/cpu/msp430/f5xxx/clock.c +++ b/cpu/msp430/f5xxx/clock.c @@ -183,7 +183,7 @@ clock_delay(unsigned int i) * */ void -clock_wait(int i) +clock_wait(clock_time_t i) { clock_time_t start; diff --git a/cpu/stm32w108/clock.c b/cpu/stm32w108/clock.c index aa47d39c7..f85073079 100644 --- a/cpu/stm32w108/clock.c +++ b/cpu/stm32w108/clock.c @@ -46,6 +46,7 @@ #include "dev/stm32w_systick.h" #include "contiki.h" +#include "sys/clock.h" #include "uart1.h" #include "dev/leds.h" @@ -122,7 +123,7 @@ void clock_delay(unsigned int i) * Wait for a multiple of 1 ms. * */ -void clock_wait(int i) +void clock_wait(clock_timt_t i) { clock_time_t start; diff --git a/platform/avr-atmega128rfa1/contiki-conf.h b/platform/avr-atmega128rfa1/contiki-conf.h index 5ca971204..0cf995e34 100644 --- a/platform/avr-atmega128rfa1/contiki-conf.h +++ b/platform/avr-atmega128rfa1/contiki-conf.h @@ -41,38 +41,36 @@ #ifndef __CONTIKI_CONF_H__ #define __CONTIKI_CONF_H__ -/* MCU and clock rate */ -#define PLATFORM PLATFORM_AVR -#define HARWARE_REVISION ATMEGA128RFA1 +/* Platform name, type, and MCU clock rate */ +#define PLATFORM_NAME "RFA1" +#define PLATFORM_TYPE ATMEGA128RFA1 #ifndef F_CPU #define F_CPU 8000000UL #endif + #include -/* These names are deprecated, use C99 names. */ -typedef int32_t s32_t; -typedef unsigned char u8_t; -typedef unsigned short u16_t; -typedef unsigned long u32_t; - -typedef unsigned short clock_time_t; -typedef unsigned short uip_stats_t; -typedef unsigned long off_t; - -void clock_delay(unsigned int us2); -void clock_wait(int ms10); -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); - -/* Maximum timer interval for 16 bit clock_time_t */ -#define INFINITE_TIME 0xffff - -/* Clock ticks per second */ +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. + */ + /* Clock ticks per second */ #define CLOCK_CONF_SECOND 128 - -/* Maximum tick interval is 0xffff/128 = 511 seconds */ +#if 1 +/* 16 bit counter overflows every ~10 minutes */ +typedef unsigned short clock_time_t; +#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) +#define INFINITE_TIME 0xffff #define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ #define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#else +typedef unsigned long clock_time_t; +#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0) +#define INFINITE_TIME 0xffffffff +#endif +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); /* Michael Hartman's atmega128rfa1 board has an external 32768Hz crystal connected to TOSC1 and 2 pins similar to the Raven 1284p */ /* and theoretically can use TIMER2 with it to keep time. Else TIMER0 is used. */ @@ -94,7 +92,8 @@ unsigned long clock_seconds(void); /* Default is 4096. Currently used only when elfloader is present. Not tested on Raven */ //#define MMEM_CONF_SIZE 256 -/* Starting address for code received via the codeprop facility. Not tested on Raven */ +/* Starting address for code received via the codeprop facility. Not tested. */ +typedef unsigned long off_t; //#define EEPROMFS_ADDR_CODEPROP 0x8000 /* Logging adds 200 bytes to program size. RS232 output slows down webserver. */ @@ -107,6 +106,10 @@ unsigned long clock_seconds(void); /* More extensive stats, via main loop printfs or webserver status pages */ #define ENERGEST_CONF_ON 1 +/* Packet statistics */ +typedef unsigned short uip_stats_t; +#define UIP_STATISTICS 0 + /* Available watchdog timeouts depend on mcu. Default is WDTO_2S. -1 Disables the watchdog. */ /* AVR Studio simulator tends to reboot due to clocking the WD 8 times too fast */ //#define WATCHDOG_CONF_TIMEOUT -1 diff --git a/platform/avr-raven/apps/raven-lcd-interface/raven-lcd.c b/platform/avr-raven/apps/raven-lcd-interface/raven-lcd.c index 070e5db5f..4cb93813b 100644 --- a/platform/avr-raven/apps/raven-lcd-interface/raven-lcd.c +++ b/platform/avr-raven/apps/raven-lcd-interface/raven-lcd.c @@ -215,7 +215,6 @@ void micro_sleep(uint8_t howlong) sleep_mode(); // Sleep /* Adjust clock.c for the time spent sleeping */ - extern void clock_adjust_ticks(uint16_t howmany); clock_adjust_ticks(howlong * CLOCK_SECOND); // if (TIMSK2&(1< -/* These names are deprecated, use C99 names. */ -typedef int32_t s32_t; -typedef unsigned char u8_t; -typedef unsigned short u16_t; -typedef unsigned long u32_t; - -typedef unsigned short clock_time_t; -typedef unsigned short uip_stats_t; -typedef unsigned long off_t; - -void clock_delay(unsigned int us2); -void clock_wait(int ms10); -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); - -/* Maximum timer interval for 16 bit clock_time_t */ -#define INFINITE_TIME 0xffff - +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. + */ /* Clock ticks per second */ #define CLOCK_CONF_SECOND 128 - -/* Maximum tick interval is 0xffff/128 = 511 seconds */ +#if 1 +/* 16 bit counter overflows every ~10 minutes */ +typedef unsigned short clock_time_t; +#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) +#define INFINITE_TIME 0xffff #define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ #define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#else +typedef unsigned long clock_time_t; +#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0) +#define INFINITE_TIME 0xffffffff +#endif +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); /* The 1284p can use TIMER2 with the external 32768Hz crystal to keep time. Else TIMER0 is used. */ /* The sleep timer in raven-lcd.c also uses the crystal and adds a TIMER2 interrupt routine if not already define by clock.c */ @@ -100,6 +97,7 @@ unsigned long clock_seconds(void); //#define MMEM_CONF_SIZE 256 /* Starting address for code received via the codeprop facility. Not tested on Raven */ +typedef unsigned long off_t; //#define EEPROMFS_ADDR_CODEPROP 0x8000 /* RADIO_CONF_CALIBRATE_INTERVAL is used in rf230bb and clock.c. If nonzero a 256 second interval is used */ @@ -112,6 +110,11 @@ unsigned long clock_seconds(void); /* More extensive stats */ #define ENERGEST_CONF_ON 1 +/* Packet statistics */ +typedef unsigned short uip_stats_t; +#define UIP_STATISTICS 0 + + /* Possible watchdog timeouts depend on mcu. Default is WDTO_2S. -1 Disables the watchdog. */ /* AVR Studio simulator tends to reboot due to clocking the WD 8 times too fast */ //#define WATCHDOG_CONF_TIMEOUT -1 @@ -143,7 +146,7 @@ unsigned long clock_seconds(void); /* TX routine does automatic cca and optional backoff */ #define RDC_CONF_HARDWARE_CSMA 1 /* Allow MCU sleeping between channel checks */ -#define RDC_CONF_MCU_SLEEP 1 +#define RDC_CONF_MCU_SLEEP 0 #else #define PACKETBUF_CONF_HDR_SIZE 0 //RF230 combined driver/mac handles headers internally #endif /*RF230BB */ @@ -270,11 +273,11 @@ unsigned long clock_seconds(void); #define QUEUEBUF_CONF_REF_NUM 2 /* Allocate remaining RAM. Not much left due to queuebuf increase */ #define UIP_CONF_MAX_CONNECTIONS 2 -#define UIP_CONF_MAX_LISTENPORTS 4 -#define UIP_CONF_UDP_CONNS 5 -#define UIP_CONF_DS6_NBR_NBU 4 +#define UIP_CONF_MAX_LISTENPORTS 2 +#define UIP_CONF_UDP_CONNS 4 +#define UIP_CONF_DS6_NBR_NBU 10 #define UIP_CONF_DS6_DEFRT_NBU 2 -#define UIP_CONF_DS6_PREFIX_NBU 3 +#define UIP_CONF_DS6_PREFIX_NBU 2 #define UIP_CONF_DS6_ROUTE_NBU 4 #define UIP_CONF_DS6_ADDR_NBU 3 #define UIP_CONF_DS6_MADDR_NBU 0 diff --git a/platform/avr-ravenusb/contiki-conf.h b/platform/avr-ravenusb/contiki-conf.h index 663703997..0571502b2 100644 --- a/platform/avr-ravenusb/contiki-conf.h +++ b/platform/avr-ravenusb/contiki-conf.h @@ -47,40 +47,38 @@ //#pragma mark Basic Configuration /* ************************************************************************** */ -/* MCU and clock rate */ -#define PLATFORM PLATFORM_AVR -#define RAVEN_REVISION RAVENUSB_C +/* Platform name, type, and MCU clock rate */ +#define PLATFORM_NAME "RAVENUSB" +#define PLATFORM_TYPE RAVENUSB_C #ifndef F_CPU -#define F_CPU 8000000UL +#define F_CPU 8000000UL #endif #include #include #include -/* These names are deprecated, use C99 names. */ -typedef int32_t s32_t; -typedef unsigned char u8_t; -typedef unsigned short u16_t; -typedef unsigned long u32_t; -typedef unsigned short clock_time_t; -typedef unsigned short uip_stats_t; -typedef unsigned long off_t; - -void clock_delay(unsigned int us2); -void clock_wait(int ms10); -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); - -/* Maximum timer interval for 16 bit clock_time_t */ -#define INFINITE_TIME 0xffff - -/* Clock ticks per second */ +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. + */ + /* Clock ticks per second */ #define CLOCK_CONF_SECOND 125 - -/* Maximum tick interval is 0xffff/125 = 524 seconds */ -#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */ -#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */ +#if 1 +/* 16 bit counter overflows every ~10 minutes */ +typedef unsigned short clock_time_t; +#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) +#define INFINITE_TIME 0xffff +#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#else +typedef unsigned long clock_time_t; +#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0) +#define INFINITE_TIME 0xffffffff +#endif +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); /* Use EEPROM settings manager, or hard-coded EEPROM reads? */ /* Generate random MAC address on first startup? */ @@ -98,6 +96,7 @@ unsigned long clock_seconds(void); //#define MMEM_CONF_SIZE 256 /* Starting address for code received via the codeprop facility. Not tested on Jackdaw */ +typedef unsigned long off_t; //#define EEPROMFS_ADDR_CODEPROP 0x8000 /* Simple stack monitor. Status is displayed from the USB menu with 'm' command */ @@ -265,6 +264,8 @@ extern void mac_log_802_15_4_rx(const uint8_t* buffer, size_t total_len); #define UIP_CONF_UDP_CHECKSUMS 1 #define UIP_CONF_TCP_SPLIT 0 + +typedef unsigned short uip_stats_t; #define UIP_CONF_STATISTICS 1 /* Network setup */ diff --git a/platform/avr-rcb/contiki-conf.h b/platform/avr-rcb/contiki-conf.h index c02fd0cc1..b2cc0053e 100644 --- a/platform/avr-rcb/contiki-conf.h +++ b/platform/avr-rcb/contiki-conf.h @@ -44,17 +44,39 @@ #include -typedef int32_t s32_t; +//typedef int32_t s32_t; /* * MCU and clock rate */ -#define MCU_MHZ 8 -#define PLATFORM PLATFORM_AVR -#define RCB_REVISION RCB_B + /* Platform name, type, and MCU clock rate */ +#define PLATFORM_NAME "RCB" +#define PLATFORM_TYPE RCB_B +#ifndef F_CPU +#define F_CPU 8000000UL +#endif +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. + */ /* Clock ticks per second */ #define CLOCK_CONF_SECOND 125 +#if 1 +/* 16 bit counter overflows every ~10 minutes */ +typedef unsigned short clock_time_t; +#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) +#define INFINITE_TIME 0xffff +#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#else +typedef unsigned long clock_time_t; +#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0) +#define INFINITE_TIME 0xffffffff +#endif +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); /* COM port to be used for SLIP connection */ #define SLIP_PORT RS232_PORT_0 @@ -114,18 +136,13 @@ typedef int32_t s32_t; #define UIP_CONF_TCP_SPLIT 0 -typedef unsigned short clock_time_t; /* These names are deprecated, use C99 names. */ -typedef unsigned char u8_t; +/*typedef unsigned char u8_t; typedef unsigned short u16_t; typedef unsigned long u32_t; +*/ typedef unsigned short uip_stats_t; typedef unsigned long off_t; -void clock_delay(unsigned int us2); -void clock_wait(int ms10); -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); - #endif /* __CONTIKI_CONF_H__ */ diff --git a/platform/avr-zigbit/contiki-conf.h b/platform/avr-zigbit/contiki-conf.h index 53aa6bf23..03943d991 100644 --- a/platform/avr-zigbit/contiki-conf.h +++ b/platform/avr-zigbit/contiki-conf.h @@ -42,18 +42,36 @@ #ifndef __CONTIKI_CONF_H__ #define __CONTIKI_CONF_H__ -/* MCU and clock rate */ -#define PLATFORM PLATFORM_AVR -#define HARWARE_REVISION ZIGBIT +/* Platform name, type, and MCU clock rate */ +#define PLATFORM_NAME "Zigbit" +#define PLATFORM_TYPE ZIGBIT +#ifndef F_CPU +#define F_CPU 8000000UL +#endif +#include + +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. + */ /* Clock ticks per second */ #define CLOCK_CONF_SECOND 125 - -/* Since clock_time_t is 16 bits, maximum interval is 524 seconds */ -#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /*Default uses 600*/ - -/* Maximum time interval (used for timers) */ +#if 1 +/* 16 bit counter overflows every ~10 minutes */ +typedef unsigned short clock_time_t; +#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) #define INFINITE_TIME 0xffff +#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#else +typedef unsigned long clock_time_t; +#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0) +#define INFINITE_TIME 0xffffffff +#endif +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); /* COM port to be used for SLIP connection */ #define SLIP_PORT RS232_PORT_0 @@ -143,21 +161,15 @@ #define UIP_CONF_TCP_SPLIT 1 -#include - /* These names are deprecated, use C99 names. */ -typedef unsigned short clock_time_t; +/* typedef unsigned char u8_t; typedef unsigned short u16_t; typedef unsigned long u32_t; typedef int32_t s32_t; - +*/ typedef unsigned short uip_stats_t; typedef unsigned long off_t; -void clock_delay(unsigned int us2); -void clock_wait(int ms10); -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); #endif /* __CONTIKI_CONF_H__ */ diff --git a/platform/esb/contiki-conf.h b/platform/esb/contiki-conf.h index 7b3ef0252..ad11e2142 100644 --- a/platform/esb/contiki-conf.h +++ b/platform/esb/contiki-conf.h @@ -42,8 +42,6 @@ typedef unsigned long clock_time_t; -void clock_wait(int ms10); - #define LOG_CONF_ENABLED 0 #define PACKETBUF_CONF_ATTRS_INLINE 1 diff --git a/platform/esb/dev/beep.c b/platform/esb/dev/beep.c index b5b6e6f8b..f16e2a90c 100644 --- a/platform/esb/dev/beep.c +++ b/platform/esb/dev/beep.c @@ -33,6 +33,7 @@ #include "contiki.h" #include "contiki-esb.h" +#include "sys/clock.h" #define ON 1 #define OFF 0 diff --git a/platform/exp5438/clock.c b/platform/exp5438/clock.c index 0b0973c97..f701af9b7 100644 --- a/platform/exp5438/clock.c +++ b/platform/exp5438/clock.c @@ -214,7 +214,7 @@ __delay_cycles(int c) * */ void -clock_wait(int i) +clock_wait(clock_time_t i) { clock_time_t start; diff --git a/platform/iris/contiki-conf.h b/platform/iris/contiki-conf.h index 00a1401c3..1c8c48a7f 100644 --- a/platform/iris/contiki-conf.h +++ b/platform/iris/contiki-conf.h @@ -188,16 +188,9 @@ #define UIP_CONF_TCP_SPLIT 0 - -typedef unsigned short clock_time_t; typedef unsigned short uip_stats_t; typedef unsigned long off_t; -void clock_delay(unsigned int us2); -void clock_wait(int ms10); -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); - #ifdef PROJECT_CONF_H #include PROJECT_CONF_H #endif /* PROJECT_CONF_H */ diff --git a/platform/iris/platform-conf.h b/platform/iris/platform-conf.h index fc39ea646..f31087944 100644 --- a/platform/iris/platform-conf.h +++ b/platform/iris/platform-conf.h @@ -44,13 +44,34 @@ * Definitions below are dictated by the hardware and not really * changeable! */ -#define PLATFORM PLATFORM_AVR - -#define HARWARE_REVISION IRIS +/* Platform name, type, and MCU clock rate */ +#define PLATFORM_NAME "Iris" +#define PLATFORM_TYPE IRIS +#ifndef F_CPU +#define F_CPU 8000000UL +#endif +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. + */ /* Clock ticks per second */ #define CLOCK_CONF_SECOND 128 - +#if 1 +/* 16 bit counter overflows every ~10 minutes */ +typedef unsigned short clock_time_t; +#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) +#define INFINITE_TIME 0xffff +#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#else +typedef unsigned long clock_time_t; +#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0) +#define INFINITE_TIME 0xffffffff +#endif +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); /* LED ports */ #define LEDS_PxDIR DDRA // port direction register diff --git a/platform/mb851/dev/acc-sensor.c b/platform/mb851/dev/acc-sensor.c index e3e6221c9..032c7465d 100644 --- a/platform/mb851/dev/acc-sensor.c +++ b/platform/mb851/dev/acc-sensor.c @@ -43,8 +43,7 @@ #include "dev/acc-sensor.h" #include "mems.h" - -void clock_wait(int i); +#include "sys/clock.h" #define FALSE 0 #define TRUE 1 diff --git a/platform/mbxxx/clock.c b/platform/mbxxx/clock.c index 5128f639a..145a6fd07 100644 --- a/platform/mbxxx/clock.c +++ b/platform/mbxxx/clock.c @@ -130,7 +130,7 @@ void clock_delay(unsigned int i) * Wait for a multiple of 1 ms. * */ -void clock_wait(int i) +void clock_wait(clock_time_t i) { clock_time_t start; diff --git a/platform/mbxxx/dev/acc-sensor.c b/platform/mbxxx/dev/acc-sensor.c index e3e6221c9..93dab123f 100644 --- a/platform/mbxxx/dev/acc-sensor.c +++ b/platform/mbxxx/dev/acc-sensor.c @@ -42,10 +42,9 @@ #include "dev/acc-sensor.h" +#include "sys/clock.h" #include "mems.h" -void clock_wait(int i); - #define FALSE 0 #define TRUE 1 diff --git a/platform/micaz/contiki-conf.h b/platform/micaz/contiki-conf.h index 20ee75a18..493ed08b1 100644 --- a/platform/micaz/contiki-conf.h +++ b/platform/micaz/contiki-conf.h @@ -47,12 +47,17 @@ #include "platform-conf.h" -#if WITH_UIP6 +#if UIP_CONF_IPV6 +#define WITH_UIP6 1 +#endif +#if WITH_UIP6 /* Network setup for IPv6 */ #define NETSTACK_CONF_NETWORK sicslowpan_driver -#define NETSTACK_CONF_MAC csma_driver -#define NETSTACK_CONF_RDC nullrdc_driver +//#define NETSTACK_CONF_MAC csma_driver +#define NETSTACK_CONF_MAC nullmac_driver +//#define NETSTACK_CONF_RDC nullrdc_driver +#define NETSTACK_CONF_RDC sicslowmac_driver #define NETSTACK_CONF_FRAMER framer_802154 #define CC2420_CONF_AUTOACK 1 @@ -66,6 +71,7 @@ #define NETSTACK_CONF_NETWORK rime_driver #define NETSTACK_CONF_MAC csma_driver +#define NETSTACK_CONF_MAC nullmac_driver #define NETSTACK_CONF_RDC cxmac_driver #define NETSTACK_CONF_FRAMER framer_802154 @@ -109,8 +115,8 @@ #define UIP_CONF_LL_802154 1 #define UIP_CONF_LLH_LEN 0 -#define UIP_CONF_ROUTER 1 -#define UIP_CONF_IPV6_RPL 1 +#define UIP_CONF_ROUTER 0 +#define UIP_CONF_IPV6_RPL 0 /* configure number of neighbors and routes */ #define UIP_CONF_DS6_NBR_NBU 5 @@ -188,14 +194,7 @@ #define UIP_CONF_TCP_SPLIT 0 - -typedef unsigned short clock_time_t; typedef unsigned short uip_stats_t; typedef unsigned long off_t; -void clock_delay(unsigned int us2); -void clock_wait(int ms10); -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); - #endif /* __CONTIKI_CONF_H__ */ diff --git a/platform/micaz/contiki-micaz-main.c b/platform/micaz/contiki-micaz-main.c index ba60027f8..a2fdba71d 100644 --- a/platform/micaz/contiki-micaz-main.c +++ b/platform/micaz/contiki-micaz-main.c @@ -64,7 +64,8 @@ init_usart(void) USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); #if WITH_UIP || WITH_UIP6 - slip_arch_init(USART_BAUD_115200); + // slip_arch_init(USART_BAUD_115200); + rs232_redirect_stdout(RS232_PORT_0); #else rs232_redirect_stdout(RS232_PORT_0); #endif /* WITH_UIP */ @@ -103,7 +104,7 @@ main(void) ctimer_init(); leds_on(LEDS_YELLOW); - + init_net(); printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u\n"), node_id); diff --git a/platform/micaz/dev/clock.c b/platform/micaz/dev/clock.c index d69b7a83d..2ed808637 100644 --- a/platform/micaz/dev/clock.c +++ b/platform/micaz/dev/clock.c @@ -134,12 +134,12 @@ clock_delay(unsigned int i) * */ void -clock_wait(int i) +clock_wait(clock_time_t i) { clock_time_t start; start = clock_time(); - while(clock_time() - start < (clock_time_t)i); + while(clock_time() - start < i); } /*---------------------------------------------------------------------------*/ void diff --git a/platform/micaz/platform-conf.h b/platform/micaz/platform-conf.h index a2521131d..2be1483f8 100644 --- a/platform/micaz/platform-conf.h +++ b/platform/micaz/platform-conf.h @@ -44,17 +44,34 @@ * Definitions below are dictated by the hardware and not really * changeable! */ -#define PLATFORM PLATFORM_AVR + /* Platform name, type, and MCU clock rate */ +#define PLATFORM_NAME "MicaZ" +#define PLATFORM_TYPE MICAZ +#ifndef F_CPU +#define F_CPU 7372800UL +#endif -/* - * MCU and clock rate. - * MICAZ runs on 7.3728 MHz clock. +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. */ -#define MCU_MHZ 7 - -/* Clock ticks per second */ + /* Clock ticks per second */ #define CLOCK_CONF_SECOND 128 - +#if 1 +/* 16 bit counter overflows every ~10 minutes */ +typedef unsigned short clock_time_t; +#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) +#define INFINITE_TIME 0xffff +#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#else +typedef unsigned long clock_time_t; +#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0) +#define INFINITE_TIME 0xffffffff +#endif +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); /* LED ports */ #define LEDS_PxDIR DDRA // port direction register diff --git a/platform/redbee-econotag/contiki-conf.h b/platform/redbee-econotag/contiki-conf.h index 1aee86f44..35290dd6d 100644 --- a/platform/redbee-econotag/contiki-conf.h +++ b/platform/redbee-econotag/contiki-conf.h @@ -51,6 +51,8 @@ #include +#define PLATFORM_NAME "Econotag" +#define PLATFORM_TYPE MC1322X /* mc1322x files */ #include "contiki-mc1322x-conf.h" /* this is from cpu/mc1322x/board */ @@ -62,6 +64,9 @@ /* FIXME setting this will break the sensor button (and other gpio) */ /* since leds_arch hits the entire gpio_data */ #define BLINK_SECONDS 0 +/* Set to 1 to sample an ADC channel every second, 9 second refresh */ +/* Set >1 to sample an ADC channel every tick, 90 msec refresh */ +#define CLOCK_CONF_SAMPLEADC 1 #define CCIF #define CLIF diff --git a/platform/stk500/contiki-conf.h b/platform/stk500/contiki-conf.h index c0b26336b..169aa6c9c 100644 --- a/platform/stk500/contiki-conf.h +++ b/platform/stk500/contiki-conf.h @@ -3,15 +3,37 @@ #include +/* Platform name, type, and MCU clock rate */ +#define PLATFORM_NAME "STK500" +#define PLATFORM_TYPE STK500 +#ifndef F_CPU +#define F_CPU 8000000UL +#endif + #define CCIF #define CLIF -typedef unsigned short clock_time_t; +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. + */ + /* Clock ticks per second */ #define CLOCK_CONF_SECOND 125 -/* Maximum tick interval is 0xffff/125 = 524 seconds */ -#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */ -#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */ - +#if 1 +/* 16 bit counter overflows every ~10 minutes */ +typedef unsigned short clock_time_t; +#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) +#define INFINITE_TIME 0xffff +#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#else +typedef unsigned long clock_time_t; +#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0) +#define INFINITE_TIME 0xffffffff +#endif +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); #define SLIP_PORT 0 @@ -56,13 +78,6 @@ typedef unsigned short clock_time_t; #define NETSTACK_CONF_NETWORK rime_driver #endif /* UIP_CONF_IPV6 */ -void clock_delay(unsigned int us2); - -void clock_wait(int ms10); - -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); - typedef unsigned short uip_stats_t; /* These names are deprecated, use C99 names. */ diff --git a/platform/stk501/contiki-conf.h b/platform/stk501/contiki-conf.h index b0fe93b5c..d2ac3da96 100644 --- a/platform/stk501/contiki-conf.h +++ b/platform/stk501/contiki-conf.h @@ -45,17 +45,40 @@ /* * MCU and clock rate. Various MCUs can be inserted in the ZIF socket. */ + /* Platform name, type, and MCU clock rate */ +#define PLATFORM_NAME "STK501" +#define PLATFORM_TYPE STK501 #ifndef MCU #define MCU atmega128 #endif #ifndef F_CPU -#define F_CPU 16000000UL +#define F_CPU 16000000UL #endif -#define PLATFORM PLATFORM_AVR -/* Cock ticks per second */ +#define HAVE_STDINT_H +#include "avrdef.h" + +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. + */ + /* Clock ticks per second */ #define CLOCK_CONF_SECOND 125 -#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /*Default uses 600*/ +#if 1 +/* 16 bit counter overflows every ~10 minutes */ +typedef unsigned short clock_time_t; +#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) +#define INFINITE_TIME 0xffff +#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */ +#else +typedef unsigned long clock_time_t; +#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0) +#define INFINITE_TIME 0xffffffff +#endif +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); /* COM port to be used for SLIP connection */ #define SLIP_PORT RS232_PORT_0 @@ -83,13 +106,7 @@ #define HAVE_STDINT_H #include "avrdef.h" -typedef unsigned short clock_time_t; typedef unsigned short uip_stats_t; typedef unsigned long off_t; -void clock_delay(unsigned int us2); -void clock_wait(int ms10); -void clock_set_seconds(unsigned long s); -unsigned long clock_seconds(void); - #endif /* __CONTIKI_CONF_H__ */ diff --git a/platform/stk501/contiki-stk501-main.c b/platform/stk501/contiki-stk501-main.c index 0baf2a259..3223bbfae 100644 --- a/platform/stk501/contiki-stk501-main.c +++ b/platform/stk501/contiki-stk501-main.c @@ -138,7 +138,7 @@ main(void) /* Perform rest of initializations */ process_start(&contiki_stk501_main_init_process, NULL); - PRINTF"Initialized.\n"); + PRINTF("Initialized.\n"); #ifdef MT_DEMO mt_start (&threads[0], thread_handler1, &d1); diff --git a/platform/z1/contiki-z1-main.c b/platform/z1/contiki-z1-main.c index e721c8cdf..3b6195437 100644 --- a/platform/z1/contiki-z1-main.c +++ b/platform/z1/contiki-z1-main.c @@ -46,6 +46,7 @@ #include "net/mac/frame802154.h" #include "dev/button-sensor.h" #include "dev/adxl345.h" +#include "sys/clock.h" #if WITH_UIP6 #include "net/uip-ds6.h" @@ -105,7 +106,6 @@ static uint8_t is_gateway; #endif void init_platform(void); -void clock_wait(int i); /*---------------------------------------------------------------------------*/ #if 0 diff --git a/tools/stm32w/uip6_bridge/uip6-bridge-tap.c b/tools/stm32w/uip6_bridge/uip6-bridge-tap.c index 02366972b..0f9da30ee 100644 --- a/tools/stm32w/uip6_bridge/uip6-bridge-tap.c +++ b/tools/stm32w/uip6_bridge/uip6-bridge-tap.c @@ -26,7 +26,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uip6-bridge-tap.c,v 1.2 2011/01/19 09:13:06 salvopitru Exp $ * */ @@ -43,6 +42,7 @@ #include "dev/slip.h" #include "dev/leds.h" #include "sicslow_ethernet.h" +#include "sys/clock.h" #include "net/packetbuf.h" @@ -50,8 +50,6 @@ #include #include -void clock_wait(int i); - #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) PROCESS(uip6_bridge, "IPv6/6lowpan TAP bridge"); From 6dd1c42e8d716f2051a8d70abd7d597d1d910154 Mon Sep 17 00:00:00 2001 From: Fredrik Osterlind Date: Tue, 10 Apr 2012 12:45:11 +0200 Subject: [PATCH 06/10] added powertracker plugin as default cooja plugin. the powertracker plugin was previously available via contiki projects. --- tools/cooja/apps/powertracker/build.xml | 43 ++ tools/cooja/apps/powertracker/cooja.config | 2 + .../apps/powertracker/java/PowerTracker.java | 524 ++++++++++++++++++ .../config/external_tools_freebsd.config | 2 +- .../cooja/config/external_tools_linux.config | 2 +- .../config/external_tools_linux_64.config | 2 +- .../cooja/config/external_tools_macosx.config | 2 +- .../cooja/config/external_tools_win32.config | 2 +- 8 files changed, 574 insertions(+), 5 deletions(-) create mode 100644 tools/cooja/apps/powertracker/build.xml create mode 100644 tools/cooja/apps/powertracker/cooja.config create mode 100644 tools/cooja/apps/powertracker/java/PowerTracker.java diff --git a/tools/cooja/apps/powertracker/build.xml b/tools/cooja/apps/powertracker/build.xml new file mode 100644 index 000000000..cd608277f --- /dev/null +++ b/tools/cooja/apps/powertracker/build.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/cooja/apps/powertracker/cooja.config b/tools/cooja/apps/powertracker/cooja.config new file mode 100644 index 000000000..1df154e2b --- /dev/null +++ b/tools/cooja/apps/powertracker/cooja.config @@ -0,0 +1,2 @@ +se.sics.cooja.GUI.PLUGINS = + PowerTracker +se.sics.cooja.GUI.JARFILES = + powertracker.jar diff --git a/tools/cooja/apps/powertracker/java/PowerTracker.java b/tools/cooja/apps/powertracker/java/PowerTracker.java new file mode 100644 index 000000000..0601cb32e --- /dev/null +++ b/tools/cooja/apps/powertracker/java/PowerTracker.java @@ -0,0 +1,524 @@ +/* + * Copyright (c) 2012, Swedish Institute of Computer Science. + * 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. + */ + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.Timer; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; + +import org.apache.log4j.Logger; +import org.jdom.Element; + +import se.sics.cooja.ClassDescription; +import se.sics.cooja.GUI; +import se.sics.cooja.Mote; +import se.sics.cooja.PluginType; +import se.sics.cooja.SimEventCentral.MoteCountListener; +import se.sics.cooja.Simulation; +import se.sics.cooja.VisPlugin; +import se.sics.cooja.interfaces.Radio; + +/** + * Tracks radio events to sum up transmission, reception, and radio on times. + * This plugin can be run without visualization, i.e. from a Contiki test. + * + * @author Fredrik Osterlind, Adam Dunkels + */ +@ClassDescription("PowerTracker") +@PluginType(PluginType.SIM_PLUGIN) +public class PowerTracker extends VisPlugin { + private static Logger logger = Logger.getLogger(PowerTracker.class); + + private static final int POWERTRACKER_UPDATE_INTERVAL = 100; /* ms */ + + private static final int COLUMN_MOTE = 0; + private static final int COLUMN_RADIOON = 1; + private static final int COLUMN_RADIOTX = 2; + private static final int COLUMN_RADIORX = 3; + + private Simulation simulation; + private MoteCountListener moteCountListener; + private ArrayList moteTrackers = new ArrayList(); + + private JTable table; + private int tableMaxRadioOnIndex = -1; + + public PowerTracker(final Simulation simulation, final GUI gui) { + super("PowerTracker", gui, false); + this.simulation = simulation; + + /* Automatically add/delete motes */ + simulation.getEventCentral().addMoteCountListener(moteCountListener = new MoteCountListener() { + public void moteWasAdded(Mote mote) { + addMote(mote); + table.invalidate(); + table.repaint(); + } + public void moteWasRemoved(Mote mote) { + removeMote(mote); + table.invalidate(); + table.repaint(); + } + }); + for (Mote m: simulation.getMotes()) { + addMote(m); + } + + if (!GUI.isVisualized()) { + return; + } + + AbstractTableModel model = new AbstractTableModel() { + public int getRowCount() { + return moteTrackers.size()+1; + } + public int getColumnCount() { + return 4; + } + public String getColumnName(int col) { + if (col == COLUMN_MOTE) { + return "Mote"; + } + if (col == COLUMN_RADIOON) { + return "Radio on (%)"; + } + if (col == COLUMN_RADIOTX) { + return "Radio TX (%)"; + } + if (col == COLUMN_RADIORX) { + return "Radio RX (%)"; + } + return null; + } + public Object getValueAt(int rowIndex, int col) { + if (rowIndex < 0 || rowIndex >= moteTrackers.size()+1) { + return null; + } + + if (rowIndex == moteTrackers.size()) { + /* Average */ + long radioOn = 0; + long radioTx = 0; + long radioRx = 0; + long duration = 0; + for (MoteTracker mt: moteTrackers) { + radioOn += mt.radioOn; + radioTx += mt.radioTx; + radioRx += mt.radioRx; + + duration += mt.duration; + } + + if (col == COLUMN_MOTE) { + return "AVERAGE"; + } + if (col == COLUMN_RADIOON) { + return String.format("%2.2f%%", 100.0*radioOn/duration); + } + if (col == COLUMN_RADIOTX) { + return String.format("%2.2f%%", 100.0*radioTx/duration); + } + if (col == COLUMN_RADIORX) { + return String.format("%2.2f%%", 100.0*radioRx/duration); + } + return null; + } + + MoteTracker rule = moteTrackers.get(rowIndex); + if (col == COLUMN_MOTE) { + return rule.mote.toString(); + } + if (col == COLUMN_RADIOON) { + return String.format("%2.2f%%", 100.0*rule.getRadioOnRatio()); + } + if (col == COLUMN_RADIOTX) { + return String.format("%2.2f%%", 100.0*rule.getRadioTxRatio()); + } + if (col == COLUMN_RADIORX) { + return String.format("%2.2f%%", 100.0*rule.getRadioRxRatio()); + } + return null; + } + }; + table = new JTable(model) { + public String getToolTipText(MouseEvent e) { + java.awt.Point p = e.getPoint(); + int rowIndex = table.rowAtPoint(p); + if (rowIndex < 0 || rowIndex >= moteTrackers.size()) { + return null; + } + MoteTracker mt = moteTrackers.get(rowIndex); + return "
" + mt.toString() + "";
+      }
+    };
+    table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
+      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+        Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
+        if (row == tableMaxRadioOnIndex) {
+          setBackground(isSelected ? table.getSelectionBackground():Color.RED);
+          setForeground(isSelected ? table.getSelectionForeground():Color.WHITE);
+        } else {
+          setBackground(isSelected ? table.getSelectionBackground():table.getBackground());
+          setForeground(isSelected ? table.getSelectionForeground():table.getForeground());
+        }
+        return c;
+      }
+    });
+
+    Box control = Box.createHorizontalBox();
+    control.add(Box.createHorizontalGlue());
+    control.add(new JButton(printAction));
+    control.add(new JButton(resetAction));
+
+    this.getContentPane().add(BorderLayout.CENTER, new JScrollPane(table));
+    this.getContentPane().add(BorderLayout.SOUTH, control);
+    setSize(400, 400);
+
+    repaintTimer.start();
+  }
+
+  private Action resetAction = new AbstractAction("Reset") {
+    public void actionPerformed(ActionEvent e) {
+      Runnable r = new Runnable() {
+        public void run() {
+          reset();
+        }
+      };
+      if (simulation.isRunning()) {
+        simulation.invokeSimulationThread(r);
+      } else {
+        r.run();
+      }
+    }
+  };
+
+  private Action printAction = new AbstractAction("Print to console/Copy to clipboard") {
+    public void actionPerformed(ActionEvent e) {
+      String output = radioStatistics(true, true, false);
+      logger.info("PowerTracker output:\n\n" + output);
+
+      Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+      StringSelection stringSelection = new StringSelection(output);
+      clipboard.setContents(stringSelection, null);
+    }
+  };
+
+  public String radioStatistics() {
+    return radioStatistics(true, true, false);
+  }
+
+  public String radioStatistics(boolean radioHW, boolean radioRXTX, boolean onlyAverage) {
+    StringBuilder sb = new StringBuilder();
+
+    /* Average */
+    long radioOn = 0;
+    long radioTx = 0;
+    long radioRx = 0;
+    long radioInterfered = 0;
+    long duration = 0;
+    for (MoteTracker mt: moteTrackers) {
+      radioOn += mt.radioOn;
+      radioTx += mt.radioTx;
+      radioRx += mt.radioRx;
+      radioInterfered += mt.radioInterfered;
+
+      duration += mt.duration;
+    }
+    if (radioHW) {
+      sb.append(String.format("AVG" + " ON " + (radioOn + " us ") + "%2.2f %%", 100.0*radioOn/duration) + "\n");
+    }
+    if (radioRXTX) {
+      sb.append(String.format("AVG" + " TX " + (radioTx + " us ") + "%2.2f %%", 100.0*radioTx/duration) + "\n");
+      sb.append(String.format("AVG" + " RX " + (radioRx + " us ") + "%2.2f %%", 100.0*radioRx/duration) + "\n");
+      sb.append(String.format("AVG" + " INT " + (radioInterfered + " us ") + "%2.2f %%", 100.0*radioInterfered/duration) + "\n");
+    }
+
+    if (onlyAverage) {
+      return sb.toString();
+    }
+
+    for (MoteTracker mt: moteTrackers) {
+      sb.append(mt.toString(radioHW, radioRXTX));
+    }
+    return sb.toString();
+  }
+
+  private static class MoteTracker implements Observer {
+    /* last radio state */
+    private boolean radioWasOn;
+    private RadioState lastRadioState;
+    private long lastUpdateTime;
+
+    /* accumulating radio state durations */
+    long duration = 0;
+    long radioOn = 0;
+    long radioTx = 0;
+    long radioRx = 0;
+    long radioInterfered = 0;
+
+    private Simulation simulation;
+    private Mote mote;
+    private Radio radio;
+
+    public MoteTracker(Mote mote) {
+      this.simulation = mote.getSimulation();
+      this.mote = mote;
+      this.radio = mote.getInterfaces().getRadio();
+
+      radioWasOn = radio.isReceiverOn();
+      if (radio.isTransmitting()) {
+        lastRadioState = RadioState.TRANSMITTING;
+      } else if (radio.isReceiving()) {
+        lastRadioState = RadioState.RECEIVING;
+      } else if (radio.isInterfered()){
+        lastRadioState = RadioState.INTERFERED;
+      } else {
+        lastRadioState = RadioState.IDLE;
+      }
+      lastUpdateTime = simulation.getSimulationTime();
+
+      radio.addObserver(this);
+    }
+
+    public void update(Observable o, Object arg) {
+      update();
+    }
+    public void update() {
+      long now = simulation.getSimulationTime();
+
+      accumulateDuration(now - lastUpdateTime);
+
+      /* Radio on/off */
+      if (radioWasOn) {
+        accumulateRadioOn(now - lastUpdateTime);
+      }
+
+      /* Radio tx/rx */
+      if (lastRadioState == RadioState.TRANSMITTING) {
+        accumulateRadioTx(now - lastUpdateTime);
+      } else if (lastRadioState == RadioState.RECEIVING) {
+        accumulateRadioRx(now - lastUpdateTime);
+      } else if (lastRadioState == RadioState.INTERFERED) {
+        accumulateRadioIntefered(now - lastUpdateTime);
+      }
+
+      /* Await next radio event */
+      if (radio.isTransmitting()) {
+        lastRadioState = RadioState.TRANSMITTING;
+      } else if (!radio.isReceiverOn()) {
+        lastRadioState = RadioState.IDLE;
+      } else if (radio.isInterfered()) {
+        lastRadioState = RadioState.INTERFERED;
+      } else if (radio.isReceiving()) {
+        lastRadioState = RadioState.RECEIVING;
+      } else {
+        lastRadioState = RadioState.IDLE;
+      }
+      radioWasOn = radio.isReceiverOn();
+      lastUpdateTime = now;
+    }
+
+    protected void accumulateDuration(long t) {
+      duration += t;
+    }
+    protected void accumulateRadioOn(long t) {
+      radioOn += t;
+    }
+    protected void accumulateRadioTx(long t) {
+      radioTx += t;
+    }
+    protected void accumulateRadioRx(long t) {
+      radioRx += t;
+    }
+    protected void accumulateRadioIntefered(long t) {
+      radioInterfered += t;
+    }
+
+    protected double getRadioOnRatio() {
+      return 1.0*radioOn/duration;
+    }
+
+    protected double getRadioTxRatio() {
+      return 1.0*radioTx/duration;
+    }
+
+    protected double getRadioInterferedRatio() {
+      return 1.0*radioInterfered/duration;
+    }
+
+    protected double getRadioRxRatio() {
+      return 1.0*radioRx/duration;
+    }
+
+    public Mote getMote() {
+      return mote;
+    }
+
+    public void dispose() {
+      radio.deleteObserver(this);
+      radio = null;
+      mote = null;
+    }
+
+    public String toString() {
+      return toString(true, true);
+    }
+    public String toString(boolean radioHW, boolean radioRXTX) {
+      StringBuilder sb = new StringBuilder();
+      String moteString = mote.toString().replace(' ', '_');
+
+      sb.append(moteString + " MONITORED " + duration + " us\n");
+      if (radioHW) {
+        sb.append(String.format(moteString + " ON " + (radioOn + " us ") + "%2.2f %%", 100.0*getRadioOnRatio()) + "\n");
+      }
+      if (radioRXTX) {
+        sb.append(String.format(moteString + " TX " + (radioTx + " us ") + "%2.2f %%", 100.0*getRadioTxRatio()) + "\n");
+        sb.append(String.format(moteString + " RX " + (radioRx + " us ") + "%2.2f %%", 100.0*getRadioRxRatio()) + "\n");
+        sb.append(String.format(moteString + " INT " + (radioInterfered + " us ") + "%2.2f %%", 100.0*getRadioInterferedRatio()) + "\n");
+      }
+      return sb.toString();
+    }
+  }
+
+  private MoteTracker createMoteTracker(Mote mote) {
+    final Radio moteRadio = mote.getInterfaces().getRadio();
+    if (moteRadio == null) {
+      return null;
+    }
+
+    /* Radio observer */
+    MoteTracker tracker = new MoteTracker(mote);
+    tracker.update(null, null);
+    return tracker;
+  }
+
+  public void reset() {
+    while (moteTrackers.size() > 0) {
+      removeMote(moteTrackers.get(0).mote);
+    }
+    for (Mote m: simulation.getMotes()) {
+      addMote(m);
+    }
+  }
+
+  private void addMote(Mote mote) {
+    if (mote == null) {
+      return;
+    }
+
+    MoteTracker t = createMoteTracker(mote);
+    if (t != null) {
+      moteTrackers.add(t);
+    }
+
+    setTitle("PowerTracker: " + moteTrackers.size() + " motes");
+  }
+
+  private void removeMote(Mote mote) {
+    /* Remove mote tracker(s) */
+    MoteTracker[] trackers = moteTrackers.toArray(new MoteTracker[0]);
+    for (MoteTracker t: trackers) {
+      if (t.getMote() == mote) {
+        t.dispose();
+        moteTrackers.remove(t);
+      }
+    }
+
+    setTitle("PowerTracker: " + moteTrackers.size() + " motes");
+  }
+
+  public void closePlugin() {
+    /* Remove repaint timer */
+    repaintTimer.stop();
+
+    simulation.getEventCentral().removeMoteCountListener(moteCountListener);
+
+    /* Remove mote trackers */
+    for (Mote m: simulation.getMotes()) {
+      removeMote(m);
+    }
+    if (!moteTrackers.isEmpty()) {
+      logger.fatal("Mote observers not cleaned up correctly");
+      for (MoteTracker t: moteTrackers.toArray(new MoteTracker[0])) {
+        t.dispose();
+      }
+    }
+  }
+
+  public enum RadioState {
+    IDLE, RECEIVING, TRANSMITTING, INTERFERED
+  }
+
+  private Timer repaintTimer = new Timer(POWERTRACKER_UPDATE_INTERVAL, new ActionListener() {
+    public void actionPerformed(ActionEvent e) {
+      /* Identify max radio on */
+      double maxRadioOn = 0;
+      int maxRadioOnIndex = -1;
+      for (int i=0; i < moteTrackers.size(); i++) {
+        MoteTracker mt = moteTrackers.get(i);
+        if (mt.getRadioOnRatio() > maxRadioOn) {
+          maxRadioOn = mt.getRadioOnRatio();
+          maxRadioOnIndex = i;
+        }
+      }
+      if (maxRadioOnIndex >= 0) {
+        tableMaxRadioOnIndex = maxRadioOnIndex;
+      }
+
+      table.repaint();
+    }
+  });
+
+  public Collection getConfigXML() {
+    return null;
+  }
+  public boolean setConfigXML(Collection configXML, boolean visAvailable) {
+    return true;
+  }
+
+}
diff --git a/tools/cooja/config/external_tools_freebsd.config b/tools/cooja/config/external_tools_freebsd.config
index b0564ec31..333b16cd4 100644
--- a/tools/cooja/config/external_tools_freebsd.config
+++ b/tools/cooja/config/external_tools_freebsd.config
@@ -22,7 +22,7 @@ AR_COMMAND_2 =
 CONTIKI_STANDARD_PROCESSES = sensors_process;etimer_process
 CORECOMM_TEMPLATE_FILENAME = corecomm_template.java
 PATH_JAVAC = javac
-DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view
+DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view;[CONTIKI_DIR]/tools/cooja/apps/powertracker
 
 PARSE_WITH_COMMAND=false
 PARSE_COMMAND=nm -a $(LIBFILE)
diff --git a/tools/cooja/config/external_tools_linux.config b/tools/cooja/config/external_tools_linux.config
index 8e433b543..8c4d8826b 100644
--- a/tools/cooja/config/external_tools_linux.config
+++ b/tools/cooja/config/external_tools_linux.config
@@ -22,7 +22,7 @@ AR_COMMAND_2 =
 CONTIKI_STANDARD_PROCESSES = sensors_process;etimer_process
 CORECOMM_TEMPLATE_FILENAME = corecomm_template.java
 PATH_JAVAC = javac
-DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view
+DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view;[CONTIKI_DIR]/tools/cooja/apps/powertracker
 
 PARSE_WITH_COMMAND=false
 PARSE_COMMAND=nm -a $(LIBFILE)
diff --git a/tools/cooja/config/external_tools_linux_64.config b/tools/cooja/config/external_tools_linux_64.config
index 7609ca905..2d238b504 100644
--- a/tools/cooja/config/external_tools_linux_64.config
+++ b/tools/cooja/config/external_tools_linux_64.config
@@ -22,7 +22,7 @@ AR_COMMAND_2 =
 CONTIKI_STANDARD_PROCESSES = sensors_process;etimer_process
 CORECOMM_TEMPLATE_FILENAME = corecomm_template.java
 PATH_JAVAC = javac
-DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view
+DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view;[CONTIKI_DIR]/tools/cooja/apps/powertracker
 
 PARSE_WITH_COMMAND=false
 PARSE_COMMAND=nm -a $(LIBFILE)
diff --git a/tools/cooja/config/external_tools_macosx.config b/tools/cooja/config/external_tools_macosx.config
index f15ba75da..45efce1d1 100644
--- a/tools/cooja/config/external_tools_macosx.config
+++ b/tools/cooja/config/external_tools_macosx.config
@@ -22,7 +22,7 @@ AR_COMMAND_2 =
 CONTIKI_STANDARD_PROCESSES = sensors_process;etimer_process
 CORECOMM_TEMPLATE_FILENAME = corecomm_template.java
 PATH_JAVAC = javac
-DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view
+DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view;[CONTIKI_DIR]/tools/cooja/apps/powertracker
 
 PARSE_WITH_COMMAND = true
 PARSE_COMMAND = /opt/contiki-2.x/tools/cooja/examples/jni_test/mac_users/nmandsize $(LIBFILE)
diff --git a/tools/cooja/config/external_tools_win32.config b/tools/cooja/config/external_tools_win32.config
index c35ab48cb..012750a63 100644
--- a/tools/cooja/config/external_tools_win32.config
+++ b/tools/cooja/config/external_tools_win32.config
@@ -22,7 +22,7 @@ AR_COMMAND_2 =
 CONTIKI_STANDARD_PROCESSES = sensors_process;etimer_process
 CORECOMM_TEMPLATE_FILENAME = corecomm_template.java
 PATH_JAVAC = javac
-DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view
+DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view;[CONTIKI_DIR]/tools/cooja/apps/powertracker
 
 PARSE_WITH_COMMAND = true
 PARSE_COMMAND=nm -n -C $(LIBFILE)

From 88eafcf479b90c17f282821ef9c43bd11b4ee247 Mon Sep 17 00:00:00 2001
From: Fredrik Osterlind 
Date: Tue, 10 Apr 2012 13:52:12 +0200
Subject: [PATCH 07/10] example script demonstrating how to interface
 powertracker plugin

---
 tools/cooja/config/scripts/plugins.js | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/cooja/config/scripts/plugins.js b/tools/cooja/config/scripts/plugins.js
index 9e9881dd3..16963fabd 100644
--- a/tools/cooja/config/scripts/plugins.js
+++ b/tools/cooja/config/scripts/plugins.js
@@ -38,16 +38,18 @@ while (counter<10) {
   GENERATE_MSG(1000, "wait");
   YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
 
-  /* Extract Timeline statistics */
-  plugin = mote.getSimulation().getGUI().getStartedPlugin("se.sics.cooja.plugins.TimeLine");
+  /* Extract PowerTracker statistics */
+  plugin = mote.getSimulation().getGUI().getStartedPlugin("PowerTracker");
   if (plugin != null) {
     plugins++;
-    stats = plugin.extractStatistics();
+    stats = plugin.radioStatistics();
     if (stats.length() > 40) {
       /* Stripping */
       stats = stats.substring(0, 40) + "...";
     }
-    log.log("Timeline: Extracted statistics:\n" + stats + "\n");
+    log.log("PowerTracker: Extracted statistics:\n" + stats + "\n");
+  } else {
+    log.log("No PowerTracker plugin\n");
   }
 
   GENERATE_MSG(1000, "wait");

From 57a166c3db1fea9ac37cdca1ddc3b080b0fb1cdb Mon Sep 17 00:00:00 2001
From: Niclas Finne 
Date: Tue, 10 Apr 2012 15:27:44 +0200
Subject: [PATCH 08/10] Corrected compiler flags for the IAR compiler

---
 cpu/msp430/Makefile.msp430 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430
index 4057b3c5a..a5eeb7ff3 100644
--- a/cpu/msp430/Makefile.msp430
+++ b/cpu/msp430/Makefile.msp430
@@ -141,7 +141,7 @@ PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)}
 
 ifdef IAR
 %.ihex: %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
-	$(LD) $(LDFLAGSNO) -Fintel-extended -yn $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
+	$(LD) $(LDFLAGSNO) -Fintel-extended $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
 else
 %.ihex: %.$(TARGET)
 	$(OBJCOPY) $^ -O ihex $@

From 1b13b6981478d07bb64e466d7ffbc3bf47c3a27e Mon Sep 17 00:00:00 2001
From: Niclas Finne 
Date: Tue, 10 Apr 2012 16:05:10 +0200
Subject: [PATCH 09/10] Added support for mspgcc 4.6+ that no longer supports
 generic MCU identifiers such as msp430x1611

---
 cpu/msp430/Makefile.msp430        | 59 ++++++++++++++++++++++---------
 platform/esb/Makefile.esb         |  2 +-
 platform/exp5438/Makefile.exp5438 |  4 +--
 platform/msb430/Makefile.msb430   |  2 +-
 platform/sky/Makefile.common      |  2 +-
 platform/wismote/Makefile.wismote |  2 +-
 platform/z1/Makefile.common       |  2 +-
 7 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430
index a5eeb7ff3..8e9ffd2c2 100644
--- a/cpu/msp430/Makefile.msp430
+++ b/cpu/msp430/Makefile.msp430
@@ -11,19 +11,24 @@ CONTIKI_CPU=$(CONTIKI)/cpu/msp430
 
 ### Define the source files we have in the MSP430 port
 
-ifneq (,$(findstring msp430x1,$(MCU)))
- CONTIKI_CPU_FAM_DIR = f1xxx
-else
- ifneq (,$(findstring msp430x5,$(MCU)))
-  CONTIKI_CPU_FAM_DIR = f5xxx
- else
-   ifneq (,$(findstring msp430x2,$(MCU)))
-     CONTIKI_CPU_FAM_DIR = f2xxx f1xxx
-   else
-     ${error Unhandled MSP430 family: "$(MCU)"}
-   endif
+ifndef CONTIKI_CPU_FAM_DIR
+ ifneq (,$(findstring msp430f1,$(MCU)))
+  CONTIKI_CPU_FAM_DIR = f1xxx
  endif
 endif
+ifndef CONTIKI_CPU_FAM_DIR
+ ifneq (,$(findstring msp430f5,$(MCU)))
+  CONTIKI_CPU_FAM_DIR = f5xxx
+ endif
+endif
+ifndef CONTIKI_CPU_FAM_DIR
+ ifneq (,$(findstring msp430f2,$(MCU)))
+  CONTIKI_CPU_FAM_DIR = f2xxx f1xxx
+ endif
+endif
+ifndef CONTIKI_CPU_FAM_DIR
+ ${error Unhandled MSP430 family: "$(MCU)"}
+endif
 
 CONTIKI_CPU_DIRS = $(CONTIKI_CPU_FAM_DIR) . dev
 
@@ -54,9 +59,9 @@ STRIP    = strip
 
 ifndef IAR_PATH
 # This works with cygwin...
-IAR_BIN_PATH = $(shell dirname "`which $(CC)`")
-IAR_PATH_C = $(shell dirname "$(IAR_BIN_PATH)")
-IAR_PATH = $(shell cygpath -m "$(IAR_PATH_C)")
+IAR_BIN_PATH := $(shell dirname "`which $(CC)`")
+IAR_PATH_C := $(shell dirname "$(IAR_BIN_PATH)")
+IAR_PATH := $(shell cygpath -m "$(IAR_PATH_C)")
 endif
 
 CFLAGS += --diag_suppress=Pa050 --silent
@@ -101,11 +106,33 @@ NM       = msp430-nm
 OBJCOPY  = msp430-objcopy
 STRIP    = msp430-strip
 BSL      = msp430-bsl
+
+# From version 4.6.x, mspgcc does not support generic MCU identifiers such as
+# msp430x1611 in contrast to msp430f1611
+ifndef CC_MCU
+ ifndef MSPGCC_VERSION
+  MSPGCC_VERSION := ${shell $(CC) -dumpversion}
+ endif
+endif
+ifndef CC_MCU
+ ifneq (,$(findstring 4.4.,$(MSPGCC_VERSION)))
+  CC_MCU := ${subst msp430f,msp430x,$(MCU)}
+ endif
+endif
+ifndef CC_MCU
+ ifneq (,$(findstring 3.2.,$(MSPGCC_VERSION)))
+  CC_MCU := ${subst msp430f,msp430x,$(MCU)}
+ endif
+endif
+ifndef CC_MCU
+ CC_MCU := $(MCU)
+endif
+
 ifndef CFLAGSNO
-CFLAGSNO = -Wall -mmcu=$(MCU) -g $(CFLAGSWERROR)
+CFLAGSNO = -Wall -mmcu=$(CC_MCU) -g $(CFLAGSWERROR)
 endif
 CFLAGS  += -Os -fno-strict-aliasing
-LDFLAGS += -mmcu=$(MCU) -Wl,-Map=contiki-$(TARGET).map
+LDFLAGS += -mmcu=$(CC_MCU) -Wl,-Map=contiki-$(TARGET).map
 
 ### These flags can reduce the code size and RAM usage with up to 10%
 ifeq ($(SMALL),1)
diff --git a/platform/esb/Makefile.esb b/platform/esb/Makefile.esb
index 4fa71d2d3..9e82880f3 100644
--- a/platform/esb/Makefile.esb
+++ b/platform/esb/Makefile.esb
@@ -50,7 +50,7 @@ endif
 
 include $(CONTIKI)/platform/$(TARGET)/apps/Makefile.apps
 
-MCU=msp430x149
+MCU=msp430f149
 include $(CONTIKI)/cpu/msp430/Makefile.msp430
 
 ifdef IAR
diff --git a/platform/exp5438/Makefile.exp5438 b/platform/exp5438/Makefile.exp5438
index a3e57fc90..d1780dc39 100644
--- a/platform/exp5438/Makefile.exp5438
+++ b/platform/exp5438/Makefile.exp5438
@@ -47,9 +47,9 @@ endif
 CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS)
 
 ifdef IAR
-MCU=msp430x5438a
+MCU=msp430f5438a
 else
-MCU=msp430x5438
+MCU=msp430f5438
 endif
 include $(CONTIKI)/cpu/msp430/Makefile.msp430
 
diff --git a/platform/msb430/Makefile.msb430 b/platform/msb430/Makefile.msb430
index af5c95caa..8ac7f68f9 100644
--- a/platform/msb430/Makefile.msb430
+++ b/platform/msb430/Makefile.msb430
@@ -12,7 +12,7 @@ endif
 
 CONTIKI_TARGET_SOURCEFILES += $(SENSORS) $(MSB) $(CONTIKI_TARGET_MAIN)
 
-MCU=msp430x1612
+MCU=msp430f1612
 include $(CONTIKI)/cpu/msp430/Makefile.msp430
 
 contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
diff --git a/platform/sky/Makefile.common b/platform/sky/Makefile.common
index 77e13ee84..492a7371a 100644
--- a/platform/sky/Makefile.common
+++ b/platform/sky/Makefile.common
@@ -21,7 +21,7 @@ endif
 
 CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS)
 
-MCU=msp430x1611
+MCU=msp430f1611
 include $(CONTIKI)/cpu/msp430/Makefile.msp430
 
 contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
diff --git a/platform/wismote/Makefile.wismote b/platform/wismote/Makefile.wismote
index 1a675f7ad..e24d9d002 100644
--- a/platform/wismote/Makefile.wismote
+++ b/platform/wismote/Makefile.wismote
@@ -30,7 +30,7 @@ endif
 
 CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS)
 
-MCU=msp430x5437
+MCU=msp430f5437
 include $(CONTIKI)/cpu/msp430/Makefile.msp430
 
 ifdef IAR
diff --git a/platform/z1/Makefile.common b/platform/z1/Makefile.common
index 2c21dc75e..aab1a55ad 100644
--- a/platform/z1/Makefile.common
+++ b/platform/z1/Makefile.common
@@ -36,7 +36,7 @@ endif
 CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS)
 CONTIKI_TARGET_SOURCEFILES += i2cmaster.c adxl345.c
 
-MCU=msp430x2617
+MCU=msp430f2617
 include $(CONTIKI)/cpu/msp430/Makefile.msp430
 
 # Add LDFLAGS after IAR_PATH is set

From 74b27510726a8611639f837c41e9a23bb540c8df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= 
Date: Tue, 10 Apr 2012 15:44:31 +0200
Subject: [PATCH 10/10] Fix building of powertracker

---
 tools/cooja/apps/powertracker/build.xml | 7 ++++---
 tools/cooja/build.xml                   | 2 ++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/cooja/apps/powertracker/build.xml b/tools/cooja/apps/powertracker/build.xml
index cd608277f..7306a374e 100644
--- a/tools/cooja/apps/powertracker/build.xml
+++ b/tools/cooja/apps/powertracker/build.xml
@@ -1,17 +1,18 @@
 
 
 
-	
+  
   
 
-  
-  
+
 
   
     
   
 	
   
+    
+    
     
     
       
diff --git a/tools/cooja/build.xml b/tools/cooja/build.xml
index ac98ecce7..287da6bb3 100644
--- a/tools/cooja/build.xml
+++ b/tools/cooja/build.xml
@@ -96,6 +96,7 @@ The COOJA Simulator
     
     
     
+	
   
 
   
@@ -189,6 +190,7 @@ The COOJA Simulator
     
     
     
+