fixed energest to always add positive values and to use all bits, removed energest arch

This commit is contained in:
joxe 2008-09-29 11:44:37 +00:00
parent 673d73bfa3
commit 193bbc9ffa
2 changed files with 16 additions and 21 deletions

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: energest.c,v 1.1 2008/07/03 23:36:30 adamdunkels Exp $
* $Id: energest.c,v 1.2 2008/09/29 11:44:37 joxe Exp $
*/
/**
@ -45,7 +45,7 @@
int energest_total_count;
energest_t energest_total_time[ENERGEST_TYPE_MAX];
unsigned short energest_current_time[ENERGEST_TYPE_MAX];
rtimer_clock_t energest_current_time[ENERGEST_TYPE_MAX];
#ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS
energest_t energest_leveldevice_current_leveltime[ENERGEST_CONF_LEVELDEVICE_LEVELS];
#endif
@ -74,8 +74,8 @@ energest_type_time(int type)
#ifndef ENERGEST_CONF_LEVELDEVICE_LEVELS
if(energest_current_mode[type]) {
rtimer_clock_t now = RTIMER_NOW();
energest_total_time[type].current += (unsigned long)
((signed short)now - (signed short)energest_current_time[type]);
energest_total_time[type].current += (rtimer_clock_t)
(now - energest_current_time[type]);
energest_current_time[type] = now;
}
#endif /* ENERGEST_CONF_LEVELDEVICE_LEVELS */
@ -107,8 +107,8 @@ energest_flush(void)
for(i = 0; i < ENERGEST_TYPE_MAX; i++) {
if(energest_current_mode[i]) {
now = RTIMER_NOW();
energest_total_time[i].current += (unsigned long)
((signed short)now - (signed short)energest_current_time[i]);
energest_total_time[i].current += (rtimer_clock_t)
(now - energest_current_time[i]);
energest_current_time[i] = now;
}
}

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: energest.h,v 1.1 2008/07/03 23:36:30 adamdunkels Exp $
* $Id: energest.h,v 1.2 2008/09/29 11:44:37 joxe Exp $
*/
/**
@ -57,11 +57,11 @@ enum energest_type {
ENERGEST_TYPE_LED_RED,
ENERGEST_TYPE_TRANSMIT,
ENERGEST_TYPE_LISTEN,
ENERGEST_TYPE_SENSORS,
ENERGEST_TYPE_SERIAL,
ENERGEST_TYPE_MAX
};
@ -76,7 +76,7 @@ void energest_flush(void);
#if ENERGEST_CONF_ON
/*extern int energest_total_count;*/
extern energest_t energest_total_time[ENERGEST_TYPE_MAX];
extern unsigned short energest_current_time[ENERGEST_TYPE_MAX];
extern rtimer_clock_t energest_current_time[ENERGEST_TYPE_MAX];
extern unsigned char energest_current_mode[ENERGEST_TYPE_MAX];
#ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS
@ -90,16 +90,16 @@ extern energest_t energest_leveldevice_current_leveltime[ENERGEST_CONF_LEVELDEVI
} while(0)
#define ENERGEST_OFF(type) do { \
energest_total_time[type].current += (unsigned long)((signed short)RTIMER_NOW() - \
(signed short)energest_current_time[type]); \
energest_total_time[type].current += (rtimer_clock_t)(RTIMER_NOW() - \
energest_current_time[type]); \
energest_current_mode[type] = 0; \
} while(0)
} while(0)
#define ENERGEST_OFF_LEVEL(type,level) do { \
energest_leveldevice_current_leveltime[level].current += (unsigned long)((signed short)RTIMER_NOW() - \
(signed short)energest_current_time[type]); \
energest_leveldevice_current_leveltime[level].current += (rtimer_clock_t)(RTIMER_NOW() - \
energest_current_time[type]); \
energest_current_mode[type] = 0; \
} while(0)
} while(0)
#else /* ENERGEST_CONF_ON */
@ -108,9 +108,4 @@ extern energest_t energest_leveldevice_current_leveltime[ENERGEST_CONF_LEVELDEVI
#define ENERGEST_OFF_LEVEL(type,level) do { } while(0)
#endif /* ENERGEST_CONF_ON */
#define ENERGEST_SECOND RTIMER_ARCH_SECOND
unsigned long energest_arch_current_estimate(void);
unsigned short energest_arch_now(void);
#endif /* __ENERGEST_H__ */