From 50c33f3fdb216f6ca6bae3938c8c218dba92ab82 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 15 Oct 2015 14:59:55 +0000 Subject: Virtual timers new functionality added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8363 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chvt.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'os') diff --git a/os/rt/include/chvt.h b/os/rt/include/chvt.h index d44d0b91b..e124a14e3 100644 --- a/os/rt/include/chvt.h +++ b/os/rt/include/chvt.h @@ -324,6 +324,41 @@ static inline bool chVTIsSystemTimeWithin(systime_t start, systime_t end) { return chVTIsTimeWithinX(chVTGetSystemTime(), start, end); } +/** + * @brief Returns the time interval until the next timer event. + * @note The return value is not perfectly accurate and can report values + * in excess of @p CH_CFG_ST_TIMEDELTA ticks. + * @note The interval returned by this function is only meaningful if + * more timers are not added to the list until the returned time. + * + * @param[out] timep pointer to a variable that will contain the time + * interval until the next timer elapses. This pointer + * can be @p NULL if the information is not required. + * @return The time, in ticks, until next time event. + * @retval false if the timers list is empty. + * @retbal true if the timers list contains at least one timer. + * + * @iclass + */ +static inline bool chVTGetTimersStateI(systime_t *timep) { + + chDbgCheckClassI(); + + if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.vt_next) + return false; + + if (timep != NULL) { +#if CH_CFG_ST_TIMEDELTA == 0 + *timep = ch.vtlist.vt_next->vt_delta; +#else + *timep = ch.vtlist.vt_lasttime + ch.vtlist.vt_next->vt_delta + + CH_CFG_ST_TIMEDELTA - chVTGetSystemTimeX(); +#endif + } + + return true; +} + /** * @brief Returns @p true if the specified timer is armed. * @pre The timer must have been initialized using @p chVTObjectInit() -- cgit v1.2.3