From 75249e0330afc8b2b6c9bea9fa3aacd45aa72466 Mon Sep 17 00:00:00 2001 From: skarg Date: Fri, 10 Dec 2010 23:16:02 +0000 Subject: [PATCH] Added byte sized timer that can be used inside an 8-bit microcontroller ISR for up to 255mS of elapsed timing. --- bacnet-stack/ports/bdk-atxx4-mstp/timer.c | 20 ++++++++++++++++++++ bacnet-stack/ports/bdk-atxx4-mstp/timer.h | 8 ++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/timer.c b/bacnet-stack/ports/bdk-atxx4-mstp/timer.c index 384c7161..b38677cc 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/timer.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/timer.c @@ -303,6 +303,26 @@ void timer_interval_restart( } } +/************************************************************************* +* Description: Return the elapsed time +* Returns: number of milliseconds elapsed +* Notes: only up to 255ms elapsed +**************************************************************************/ +uint8_t timer_milliseconds_delta(uint8_t start) +{ + return (timer_milliseconds_byte() - start); +} + +/************************************************************************* +* Description: Mark the start of a delta timer +* Returns: mark timer starting tick +* Notes: only up to 255ms elapsed +**************************************************************************/ +uint8_t timer_milliseconds_mark(void) +{ + return timer_milliseconds_byte(); +} + #ifdef TEST #include #include diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/timer.h b/bacnet-stack/ports/bdk-atxx4-mstp/timer.h index fb9bf0e0..f5a9aeaf 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/timer.h +++ b/bacnet-stack/ports/bdk-atxx4-mstp/timer.h @@ -48,8 +48,8 @@ extern "C" { void); uint32_t timer_milliseconds( void); - uint32_t timer_milliseconds_set( - uint32_t value); + uint8_t timer_milliseconds_byte( + void); /* these functions are in the generic timer.c module */ @@ -103,6 +103,10 @@ extern "C" { void timer_interval_restart( struct itimer *t); + /* special for 8-bit microcontrollers - limited to 255ms */ + uint8_t timer_milliseconds_delta(uint8_t start); + uint8_t timer_milliseconds_mark(void); + #ifdef __cplusplus } #endif /* __cplusplus */