Permalink
Browse files

Merged in the latest version of timer functions from the Contiki GIT …

…repository.

git://github.com/contiki/contiki-mirror.git
  • Loading branch information...
1 parent b86ad00 commit 4ef07391b137d0d802f1c8da719ec3f67707b9f7 @njh njh committed Jan 8, 2012
Showing with 25 additions and 2 deletions.
  1. +22 −2 timer.cpp
  2. +3 −0 timer.h
View
@@ -74,7 +74,7 @@ timer_set(struct timer *t, clock_time_t interval)
* given to the timer_set() function. The start point of the interval
* is the exact time that the timer last expired. Therefore, this
* function will cause the timer to be stable over time, unlike the
- * timer_rester() function.
+ * timer_restart() function.
*
* \param t A pointer to the timer.
*
@@ -120,7 +120,27 @@ timer_restart(struct timer *t)
int
timer_expired(struct timer *t)
{
- return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;
+ /* Note: Can not return diff >= t->interval so we add 1 to diff and return
+ t->interval < diff - required to avoid an internal error in mspgcc. */
+ clock_time_t diff = (clock_time() - t->start) + 1;
+ return t->interval < diff;
+
+}
+/*---------------------------------------------------------------------------*/
+/**
+ * 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
@@ -80,7 +80,10 @@ 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__ */
/** @} */
+/** @} */

0 comments on commit 4ef0739

Please sign in to comment.