From 1c4622bad661ab376a3dca135450fb89bd799434 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 31 Oct 2017 19:54:23 +0100 Subject: [PATCH 1/3] energest: Added new energest type ENERGEST_TYPE_DEEP_LPM to support energy estimations of both sleep and deep sleep CPU modes. Added configurable type ENERGEST_TIME_T to re-add support for clocks with wrapping time as energest time source. --- arch/cpu/msp430/f1xxx/clock.c | 2 ++ arch/cpu/msp430/f5xxx/clock.c | 2 ++ os/sys/energest.c | 21 ++++++++++++++++++--- os/sys/energest.h | 32 ++++++++++++++++++++++++++------ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/arch/cpu/msp430/f1xxx/clock.c b/arch/cpu/msp430/f1xxx/clock.c index 74832da0d..8a0ab8393 100644 --- a/arch/cpu/msp430/f1xxx/clock.c +++ b/arch/cpu/msp430/f1xxx/clock.c @@ -32,6 +32,7 @@ #include "contiki.h" #include "sys/clock.h" #include "sys/etimer.h" +#include "sys/energest.h" #include "rtimer-arch.h" #include "dev/watchdog.h" #include "isr_compat.h" @@ -86,6 +87,7 @@ ISR(TIMERA1, timera1) #endif if(count % CLOCK_CONF_SECOND == 0) { ++seconds; + energest_flush(); } last_tar = read_tar(); } diff --git a/arch/cpu/msp430/f5xxx/clock.c b/arch/cpu/msp430/f5xxx/clock.c index 74560bc35..9cb88f67f 100644 --- a/arch/cpu/msp430/f5xxx/clock.c +++ b/arch/cpu/msp430/f5xxx/clock.c @@ -32,6 +32,7 @@ #include "contiki.h" #include "sys/clock.h" #include "sys/etimer.h" +#include "sys/energest.h" #include "rtimer-arch.h" #include "dev/watchdog.h" #include "isr_compat.h" @@ -86,6 +87,7 @@ ISR(TIMER1_A1, timera1) #endif if(count % CLOCK_CONF_SECOND == 0) { ++seconds; + energest_flush(); } last_tar = read_tar(); } diff --git a/os/sys/energest.c b/os/sys/energest.c index b698f089d..af0a2949b 100644 --- a/os/sys/energest.c +++ b/os/sys/energest.c @@ -43,7 +43,7 @@ #if ENERGEST_CONF_ON uint64_t energest_total_time[ENERGEST_TYPE_MAX]; -uint64_t energest_current_time[ENERGEST_TYPE_MAX]; +ENERGEST_TIME_T energest_current_time[ENERGEST_TYPE_MAX]; unsigned char energest_current_mode[ENERGEST_TYPE_MAX]; /*---------------------------------------------------------------------------*/ @@ -52,7 +52,7 @@ energest_init(void) { int i; for(i = 0; i < ENERGEST_TYPE_MAX; ++i) { - energest_total_time[i].current = energest_current_time[i] = 0; + energest_total_time[i] = energest_current_time[i] = 0; energest_current_mode[i] = 0; } } @@ -65,12 +65,21 @@ energest_flush(void) for(i = 0; i < ENERGEST_TYPE_MAX; i++) { if(energest_current_mode[i]) { now = ENERGEST_CURRENT_TIME(); - energest_total_time[i].current += now - energest_current_time[i]; + energest_total_time[i] += + (ENERGEST_TIME_T)(now - energest_current_time[i]); energest_current_time[i] = now; } } } /*---------------------------------------------------------------------------*/ +uint64_t +energest_get_total_time(void) +{ + return energest_type_time(ENERGEST_TYPE_CPU) + + energest_type_time(ENERGEST_TYPE_LPM) + + energest_type_time(ENERGEST_TYPE_DEEP_LPM); +} +/*---------------------------------------------------------------------------*/ #else /* ENERGEST_CONF_ON */ void @@ -83,4 +92,10 @@ energest_flush(void) { } +uint64_t +energest_get_total_time(void) +{ + return 0; +} + #endif /* ENERGEST_CONF_ON */ diff --git a/os/sys/energest.h b/os/sys/energest.h index f5f336d47..a9620c351 100644 --- a/os/sys/energest.h +++ b/os/sys/energest.h @@ -48,9 +48,18 @@ #else #define ENERGEST_CURRENT_TIME RTIMER_NOW #define ENERGEST_SECOND RTIMER_SECOND +#define ENERGEST_TIME_T rtimer_clock_t #endif /* ENERGEST_CONF_TIME */ #endif /* ENERGEST_TIME */ +#ifndef ENERGEST_TIME_T +#ifdef ENERGEST_CONF_TIME_T +#define ENERGEST_TIME_T ENERGEST_CONF_TIME_T +#else +#define ENERGEST_TIME_T rtimer_clock_t +#endif /* ENERGEST_CONF_TIME_T */ +#endif /* ENERGEST_TIME_T */ + #ifndef ENERGEST_SECOND #ifdef ENERGEST_CONF_SECOND #define ENERGEST_SECOND ENERGEST_CONF_SECOND @@ -59,6 +68,14 @@ #endif /* ENERGEST_CONF_SECOND */ #endif /* ENERGEST_SECOND */ +#ifndef ENERGEST_GET_TOTAL_TIME +#ifdef ENERGEST_CONF_GET_TOTAL_TIME +#define ENERGEST_GET_TOTAL_TIME ENERGEST_CONF_GET_TOTAL_TIME +#else /* ENERGEST_CONF_GET_TOTAL_TIME */ +#define ENERGEST_GET_TOTAL_TIME energest_get_total_time +#endif /* ENERGEST_CONF_GET_TOTAL_TIME */ +#endif /* ENERGEST_GET_TOTAL_TIME */ + /* * Optional support for more energest types. * @@ -69,6 +86,7 @@ typedef enum energest_type { ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM, + ENERGEST_TYPE_DEEP_LPM, ENERGEST_TYPE_TRANSMIT, ENERGEST_TYPE_LISTEN, @@ -86,10 +104,12 @@ typedef enum energest_type { void energest_init(void); void energest_flush(void); +uint64_t ENERGEST_GET_TOTAL_TIME(void); + #if ENERGEST_CONF_ON extern uint64_t energest_total_time[ENERGEST_TYPE_MAX]; -extern uint64_t energest_current_time[ENERGEST_TYPE_MAX]; +extern ENERGEST_TIME_T energest_current_time[ENERGEST_TYPE_MAX]; extern unsigned char energest_current_mode[ENERGEST_TYPE_MAX]; static inline uint64_t @@ -118,8 +138,8 @@ static inline void energest_off(energest_type_t type) { if(energest_current_mode[type] != 0) { - energest_total_time[type].current += - ENERGEST_CURRENT_TIME() - energest_current_time[type]; + energest_total_time[type] += + (ENERGEST_TIME_T)(ENERGEST_CURRENT_TIME() - energest_current_time[type]); energest_current_mode[type] = 0; } } @@ -128,10 +148,10 @@ energest_off(energest_type_t type) static inline void energest_switch(energest_type_t type_off, energest_type_t type_on) { - uint64_t energest_local_variable_now = ENERGEST_CURRENT_TIME(); + ENERGEST_TIME_T energest_local_variable_now = ENERGEST_CURRENT_TIME(); if(energest_current_mode[type_off] != 0) { - energest_total_time[type_off].current += - energest_local_variable_now - energest_current_time[type_off]; + energest_total_time[type_off] += (ENERGEST_TIME_T) + (energest_local_variable_now - energest_current_time[type_off]); energest_current_mode[type_off] = 0; } if(energest_current_mode[type_on] == 0) { From cffe0c59f20376f26d6fd777f28b96d74d68297e Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 31 Oct 2017 19:57:58 +0100 Subject: [PATCH 2/3] energest: activate energest type CPU at init --- os/contiki-main.c | 1 - os/sys/energest.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/os/contiki-main.c b/os/contiki-main.c index d699dc286..b78138472 100644 --- a/os/contiki-main.c +++ b/os/contiki-main.c @@ -79,7 +79,6 @@ main(void) watchdog_init(); energest_init(); - ENERGEST_ON(ENERGEST_TYPE_CPU); platform_init_stage_two(); diff --git a/os/sys/energest.c b/os/sys/energest.c index af0a2949b..3fbb8f46f 100644 --- a/os/sys/energest.c +++ b/os/sys/energest.c @@ -55,6 +55,7 @@ energest_init(void) energest_total_time[i] = energest_current_time[i] = 0; energest_current_mode[i] = 0; } + ENERGEST_ON(ENERGEST_TYPE_CPU); } /*---------------------------------------------------------------------------*/ void From e6ba2664b8fae777cd6818ac17292d07ac919558 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 31 Oct 2017 22:12:47 +0100 Subject: [PATCH 3/3] energest: removed include of energest from contiki.h to avoid circular dependency --- arch/dev/cc1200/cc1200.c | 1 + arch/dev/cc2420/cc2420.c | 1 + arch/platform/jn516x/dev/micromac-radio.c | 1 + arch/platform/jn516x/platform.c | 1 + arch/platform/sky/platform.c | 1 + os/contiki-main.c | 1 + os/contiki.h | 2 -- os/sys/energest.c | 2 +- 8 files changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/dev/cc1200/cc1200.c b/arch/dev/cc1200/cc1200.c index 78f379161..3d9b1befc 100644 --- a/arch/dev/cc1200/cc1200.c +++ b/arch/dev/cc1200/cc1200.c @@ -40,6 +40,7 @@ #include "net/netstack.h" #include "net/packetbuf.h" #include "dev/watchdog.h" +#include "sys/energest.h" #include "dev/leds.h" diff --git a/arch/dev/cc2420/cc2420.c b/arch/dev/cc2420/cc2420.c index a9f56d8a9..00ec64675 100644 --- a/arch/dev/cc2420/cc2420.c +++ b/arch/dev/cc2420/cc2420.c @@ -36,6 +36,7 @@ #include #include "contiki.h" +#include "sys/energest.h" #include "dev/leds.h" #include "dev/spi.h" diff --git a/arch/platform/jn516x/dev/micromac-radio.c b/arch/platform/jn516x/dev/micromac-radio.c index 6e221c72f..c3117c6f8 100644 --- a/arch/platform/jn516x/dev/micromac-radio.c +++ b/arch/platform/jn516x/dev/micromac-radio.c @@ -44,6 +44,7 @@ #include "contiki.h" #include "dev/leds.h" #include "sys/rtimer.h" +#include "sys/energest.h" #include "net/packetbuf.h" #include "net/netstack.h" #include "net/mac/framer/frame802154.h" diff --git a/arch/platform/jn516x/platform.c b/arch/platform/jn516x/platform.c index f1f4ad431..20dabfb61 100644 --- a/arch/platform/jn516x/platform.c +++ b/arch/platform/jn516x/platform.c @@ -52,6 +52,7 @@ #include "dev/uart-driver.h" #include "contiki.h" +#include "sys/energest.h" #include "net/netstack.h" #include "dev/serial-line.h" diff --git a/arch/platform/sky/platform.c b/arch/platform/sky/platform.c index 24296653f..b14858d9a 100644 --- a/arch/platform/sky/platform.c +++ b/arch/platform/sky/platform.c @@ -31,6 +31,7 @@ #include #include #include "contiki.h" +#include "sys/energest.h" #include "cc2420.h" #include "dev/ds2411/ds2411.h" #include "dev/leds.h" diff --git a/os/contiki-main.c b/os/contiki-main.c index b78138472..a995d5ee5 100644 --- a/os/contiki-main.c +++ b/os/contiki-main.c @@ -43,6 +43,7 @@ #include "contiki.h" #include "contiki-net.h" #include "sys/platform.h" +#include "sys/energest.h" #include "dev/watchdog.h" #if BUILD_WITH_ORCHESTRA diff --git a/os/contiki.h b/os/contiki.h index a929afeba..a964758f4 100644 --- a/os/contiki.h +++ b/os/contiki.h @@ -49,6 +49,4 @@ #include "sys/clock.h" -#include "sys/energest.h" - #endif /* CONTIKI_H_ */ diff --git a/os/sys/energest.c b/os/sys/energest.c index 3fbb8f46f..beaf411bc 100644 --- a/os/sys/energest.c +++ b/os/sys/energest.c @@ -37,8 +37,8 @@ * Adam Dunkels */ -#include "sys/energest.h" #include "contiki.h" +#include "sys/energest.h" #if ENERGEST_CONF_ON