From f127b3e24c9725690ce3ed0022a38e61296e4dd9 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Sun, 21 Sep 2008 08:58:05 +0000 Subject: [PATCH] Added a timer_remaining() function that returns the time until the timer expires --- core/sys/timer.c | 18 +++++++++++++++++- core/sys/timer.h | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/sys/timer.c b/core/sys/timer.c index 064af4b74..5807bc1a6 100644 --- a/core/sys/timer.c +++ b/core/sys/timer.c @@ -42,7 +42,7 @@ * * Author: Adam Dunkels * - * $Id: timer.c,v 1.3 2008/08/15 19:16:09 adamdunkels Exp $ + * $Id: timer.c,v 1.4 2008/09/21 08:58:05 adamdunkels Exp $ */ #include "contiki-conf.h" @@ -124,5 +124,21 @@ timer_expired(struct timer *t) return CLOCK_LT(clock_time(), t->start + t->interval); } /*---------------------------------------------------------------------------*/ +/** + * The time until the timer expires + * + * This function returns the time until the timer expires. + * + * \param t A pointer to the timer + * + * \return The time until the timer expires + * + */ +clock_time_t +timer_remaining(struct timer *t) +{ + return t->start + t->interval - clock_time(); +} +/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/core/sys/timer.h b/core/sys/timer.h index aefd34e48..40f2be80b 100644 --- a/core/sys/timer.h +++ b/core/sys/timer.h @@ -69,7 +69,7 @@ * * Author: Adam Dunkels * - * $Id: timer.h,v 1.1 2006/06/17 22:41:20 adamdunkels Exp $ + * $Id: timer.h,v 1.2 2008/09/21 08:58:05 adamdunkels Exp $ */ #ifndef __TIMER_H__ #define __TIMER_H__ @@ -93,6 +93,8 @@ void timer_set(struct timer *t, clock_time_t interval); void timer_reset(struct timer *t); void timer_restart(struct timer *t); int timer_expired(struct timer *t); +clock_time_t timer_remaining(struct timer *t); + #endif /* __TIMER_H__ */