From 9f12e55340f79a154209dce538bf1fd17ec8ea7c Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 13 May 2019 15:21:58 +0100 Subject: [PATCH 1/3] SysTimer: default to us ticker if lp ticker is unavailable --- rtos/TARGET_CORTEX/SysTimer.cpp | 14 +++++++++++--- rtos/TARGET_CORTEX/SysTimer.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/rtos/TARGET_CORTEX/SysTimer.cpp b/rtos/TARGET_CORTEX/SysTimer.cpp index e1c6bb6b23..c58763d451 100644 --- a/rtos/TARGET_CORTEX/SysTimer.cpp +++ b/rtos/TARGET_CORTEX/SysTimer.cpp @@ -21,8 +21,9 @@ */ #include "rtos/TARGET_CORTEX/SysTimer.h" -#if DEVICE_LPTICKER +#if MBED_TICKLESS +#include "hal/us_ticker_api.h" #include "hal/lp_ticker_api.h" #include "mbed_critical.h" #include "mbed_assert.h" @@ -58,7 +59,12 @@ namespace rtos { namespace internal { SysTimer::SysTimer() : - TimerEvent(get_lp_ticker_data()), _time_us(0), _tick(0) +#if DEVICE_LPTICKER + TimerEvent(get_lp_ticker_data()), +#else + TimerEvent(get_us_ticker_data()), +#endif + _time_us(0), _tick(0) { _time_us = ticker_read_us(_ticker_data); _suspend_time_passed = true; @@ -69,6 +75,8 @@ SysTimer::SysTimer(const ticker_data_t *data) : TimerEvent(data), _time_us(0), _tick(0) { _time_us = ticker_read_us(_ticker_data); + _suspend_time_passed = true; + _suspended = false; } void SysTimer::setup_irq() @@ -194,4 +202,4 @@ void SysTimer::handler() } } -#endif +#endif // MBED_TICKLESS diff --git a/rtos/TARGET_CORTEX/SysTimer.h b/rtos/TARGET_CORTEX/SysTimer.h index 68b6eec891..653ffbe895 100644 --- a/rtos/TARGET_CORTEX/SysTimer.h +++ b/rtos/TARGET_CORTEX/SysTimer.h @@ -22,7 +22,7 @@ #ifndef MBED_SYS_TIMER_H #define MBED_SYS_TIMER_H -#if DEVICE_LPTICKER || defined(DOXYGEN_ONLY) +#if MBED_TICKLESS || defined(DOXYGEN_ONLY) #include "platform/NonCopyable.h" #include "drivers/TimerEvent.h" From 9fc54c977483d5ea009061ca800aa654b2c31368 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Thu, 16 May 2019 09:48:06 +0100 Subject: [PATCH 2/3] systimer tests: do not require lp ticker SysTimer can run on us ticker now. Only deep sleep test strictly requires lp ticker and it already has build conditions in place. --- TESTS/mbedmicro-rtos-mbed/systimer/main.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/TESTS/mbedmicro-rtos-mbed/systimer/main.cpp b/TESTS/mbedmicro-rtos-mbed/systimer/main.cpp index dbf60b8014..bdbbeddeb6 100644 --- a/TESTS/mbedmicro-rtos-mbed/systimer/main.cpp +++ b/TESTS/mbedmicro-rtos-mbed/systimer/main.cpp @@ -17,10 +17,6 @@ #error [NOT_SUPPORTED] Tickless mode not supported for this target. #endif -#if !DEVICE_LPTICKER -#error [NOT_SUPPORTED] Current SysTimer implementation requires lp ticker support. -#endif - #include "mbed.h" #include "greentea-client/test_env.h" #include "unity.h" From 427c7db627563c23fee91b13c85421d5686abcdc Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 13 May 2019 14:35:45 +0100 Subject: [PATCH 3/3] mbed_rtx_idle: fix ticker macro checks If a ticker is unavailable, its macro is undefined and cannot be checked with MBED_STATIC_ASSERT. --- rtos/TARGET_CORTEX/mbed_rtx_idle.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/rtos/TARGET_CORTEX/mbed_rtx_idle.cpp b/rtos/TARGET_CORTEX/mbed_rtx_idle.cpp index 2ae99f5bfb..7504ac71b9 100644 --- a/rtos/TARGET_CORTEX/mbed_rtx_idle.cpp +++ b/rtos/TARGET_CORTEX/mbed_rtx_idle.cpp @@ -38,10 +38,13 @@ extern "C" { #ifdef MBED_TICKLESS - MBED_STATIC_ASSERT(!MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER || DEVICE_USTICKER, - "Microsecond ticker required when MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER is true"); - MBED_STATIC_ASSERT(MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER || DEVICE_LPTICKER, - "Low power ticker required when MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER is false"); +#if MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER && !DEVICE_USTICKER +#error Microsecond ticker required when MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER is true +#endif + +#if !MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER && !DEVICE_LPTICKER +#error Low power ticker required when MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER is false +#endif #include "rtos/TARGET_CORTEX/SysTimer.h" @@ -137,7 +140,7 @@ extern "C" { } -#else +#else // MBED_TICKLESS static void default_idle_hook(void) { @@ -149,7 +152,7 @@ extern "C" { core_util_critical_section_exit(); } -#endif // (defined(MBED_TICKLESS) && DEVICE_LPTICKER) +#endif // MBED_TICKLESS static void (*idle_hook_fptr)(void) = &default_idle_hook;