Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 4ef07391b137d0d802f1c8da719ec3f67707b9f7 1 parent b86ad00
@njh njh authored
Showing with 25 additions and 2 deletions.
  1. +22 −2 timer.cpp
  2. +3 −0  timer.h
View
24 timer.cpp
@@ -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
3  timer.h
@@ -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__ */
/** @} */
+/** @} */
Please sign in to comment.
Something went wrong with that request. Please try again.