From 59528d6a180519cdc64514b367759f4bdce42132 Mon Sep 17 00:00:00 2001 From: Paul Szczeanek Date: Mon, 8 Jun 2020 18:26:06 +0100 Subject: [PATCH] expose WsfTimerNextExpiration in the wsf api --- .../TARGET_CORDIO/stack/wsf/include/wsf_timer.h | 13 +++++++++++++ .../stack/wsf/sources/port/baremetal/wsf_timer.c | 11 ++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/stack/wsf/include/wsf_timer.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/stack/wsf/include/wsf_timer.h index c6851a0efc..c07c1ec5d1 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/stack/wsf/include/wsf_timer.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/stack/wsf/include/wsf_timer.h @@ -112,6 +112,19 @@ void WsfTimerStop(wsfTimer_t *pTimer); /*************************************************************************************************/ void WsfTimerUpdate(wsfTimerTicks_t ticks); +/*************************************************************************************************/ +/*! + * \brief Return the number of ticks until the next timer expiration. Note that this + * function can return zero even if a timer is running, indicating the timer + * has expired but has not yet been serviced. + * + * \param pTimerRunning Returns TRUE if a timer is running, FALSE if no timers running. + * + * \return The number of ticks until the next timer expiration. + */ +/*************************************************************************************************/ +wsfTimerTicks_t WsfTimerNextExpiration(bool_t *pTimerRunning); + /*************************************************************************************************/ /*! * \brief Service expired timers for the given task. This function is typically called only diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/stack/wsf/sources/port/baremetal/wsf_timer.c b/features/FEATURE_BLE/targets/TARGET_CORDIO/stack/wsf/sources/port/baremetal/wsf_timer.c index df2c9dd1e9..151fddca90 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/stack/wsf/sources/port/baremetal/wsf_timer.c +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/stack/wsf/sources/port/baremetal/wsf_timer.c @@ -201,10 +201,12 @@ static uint32_t wsfTimerTicksToRtc(wsfTimerTicks_t wsfTicks) * function can return zero even if a timer is running, indicating a timer * has expired but has not yet been serviced. * + * \param pTimerRunning Returns TRUE if a timer is running, FALSE if no timers running. + * * \return The number of ticks until the next timer expiration. */ /*************************************************************************************************/ -static wsfTimerTicks_t wsfTimerNextExpiration(void) +wsfTimerTicks_t WsfTimerNextExpiration(bool_t *pTimerRunning) { wsfTimerTicks_t ticks; @@ -213,10 +215,12 @@ static wsfTimerTicks_t wsfTimerNextExpiration(void) if (wsfTimerTimerQueue.pHead == NULL) { + *pTimerRunning = FALSE; ticks = 0; } else { + *pTimerRunning = TRUE; ticks = ((wsfTimer_t *) wsfTimerTimerQueue.pHead)->ticks; } @@ -391,9 +395,10 @@ void WsfTimerSleep(void) return; } - nextExpiration = wsfTimerNextExpiration(); + bool_t running; + nextExpiration = WsfTimerNextExpiration(&running); - if (nextExpiration > 0) + if (running) { uint32_t awake = wsfTimerTicksToRtc(nextExpiration); uint32_t rtcCurrentTicks = PalRtcCounterGet();