Added a timer_remaining() function that returns the time until the timer expires

This commit is contained in:
adamdunkels 2008-09-21 08:58:05 +00:00
parent 44914851fd
commit f127b3e24c
2 changed files with 20 additions and 2 deletions

View file

@ -42,7 +42,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $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();
}
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -69,7 +69,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $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__ */