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() diff --git a/readme.txt b/readme.txt index 6482c39a4..fb8ed472e 100644 --- a/readme.txt +++ b/readme.txt @@ -73,6 +73,8 @@ ***************************************************************************** *** 3.1.0 *** +- RT: Added new function chVTGetTimersStateI() returning the state of the + timers list. - HAL: Now STM32 USARTv2 driver initializes the ISR vectors statically on initialization. Disabling them was not necessary and added to the code size.