41 #ifndef __ENERGEST_H__
42 #define __ENERGEST_H__
48 unsigned long current;
55 ENERGEST_TYPE_LED_GREEN,
56 ENERGEST_TYPE_LED_YELLOW,
57 ENERGEST_TYPE_LED_RED,
58 ENERGEST_TYPE_TRANSMIT,
61 ENERGEST_TYPE_FLASH_READ,
62 ENERGEST_TYPE_FLASH_WRITE,
64 ENERGEST_TYPE_SENSORS,
71 void energest_init(
void);
72 unsigned long energest_type_time(
int type);
73 #ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS
74 unsigned long energest_leveldevice_leveltime(
int powerlevel);
76 void energest_type_set(
int type,
unsigned long value);
77 void energest_flush(
void);
81 extern energest_t energest_total_time[ENERGEST_TYPE_MAX];
82 extern rtimer_clock_t energest_current_time[ENERGEST_TYPE_MAX];
83 extern unsigned char energest_current_mode[ENERGEST_TYPE_MAX];
85 #ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS
86 extern energest_t energest_leveldevice_current_leveltime[ENERGEST_CONF_LEVELDEVICE_LEVELS];
89 #define ENERGEST_ON(type) do { \
91 energest_current_time[type] = RTIMER_NOW(); \
92 energest_current_mode[type] = 1; \
96 #define ENERGEST_OFF(type) if(energest_current_mode[type] != 0) do { \
97 if (RTIMER_NOW() < energest_current_time[type]) energest_total_time[type].current += RTIMER_ARCH_SECOND; \
98 energest_total_time[type].current += (rtimer_clock_t)(RTIMER_NOW() - \
99 energest_current_time[type]); \
100 energest_current_mode[type] = 0; \
103 #define ENERGEST_OFF_LEVEL(type,level) do { \
104 if (RTIMER_NOW() < energest_current_time[type]) energest_total_time[type].current += RTIMER_ARCH_SECOND; \
105 energest_leveldevice_current_leveltime[level].current += (rtimer_clock_t)(RTIMER_NOW() - \
106 energest_current_time[type]); \
107 energest_current_mode[type] = 0; \
110 #define ENERGEST_OFF(type) if(energest_current_mode[type] != 0) do { \
111 energest_total_time[type].current += (rtimer_clock_t)(RTIMER_NOW() - \
112 energest_current_time[type]); \
113 energest_current_mode[type] = 0; \
116 #define ENERGEST_OFF_LEVEL(type,level) do { \
117 energest_leveldevice_current_leveltime[level].current += (rtimer_clock_t)(RTIMER_NOW() - \
118 energest_current_time[type]); \
119 energest_current_mode[type] = 0; \
125 #define ENERGEST_ON(type) do { } while(0)
126 #define ENERGEST_OFF(type) do { } while(0)
127 #define ENERGEST_OFF_LEVEL(type,level) do { } while(0)