Account for 16 bit rtimer wraparound, else ENERGEST way underreports AVR times.

This commit is contained in:
David Kopf 2011-08-17 16:51:22 -04:00
parent 3ea102050b
commit 2feed121d2

View File

@ -91,7 +91,22 @@ extern energest_t energest_leveldevice_current_leveltime[ENERGEST_CONF_LEVELDEVI
energest_current_time[type] = RTIMER_NOW(); \
energest_current_mode[type] = 1; \
} while(0)
#ifdef __AVR__
/* Handle 16 bit rtimer wraparound */
#define ENERGEST_OFF(type) if(energest_current_mode[type] != 0) do { \
if (RTIMER_NOW() < energest_current_time[type]) energest_total_time[type].current += RTIMER_ARCH_SECOND; \
energest_total_time[type].current += (rtimer_clock_t)(RTIMER_NOW() - \
energest_current_time[type]); \
energest_current_mode[type] = 0; \
} while(0)
#define ENERGEST_OFF_LEVEL(type,level) do { \
if (RTIMER_NOW() < energest_current_time[type]) energest_total_time[type].current += RTIMER_ARCH_SECOND; \
energest_leveldevice_current_leveltime[level].current += (rtimer_clock_t)(RTIMER_NOW() - \
energest_current_time[type]); \
energest_current_mode[type] = 0; \
} while(0)
#else
#define ENERGEST_OFF(type) if(energest_current_mode[type] != 0) do { \
energest_total_time[type].current += (rtimer_clock_t)(RTIMER_NOW() - \
energest_current_time[type]); \
@ -103,6 +118,7 @@ extern energest_t energest_leveldevice_current_leveltime[ENERGEST_CONF_LEVELDEVI
energest_current_time[type]); \
energest_current_mode[type] = 0; \
} while(0)
#endif
#else /* ENERGEST_CONF_ON */