From 0f803947ecd33a6cf97b1f602f4135bfe02c0999 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Thu, 12 Jul 2018 11:48:16 -0500 Subject: [PATCH] Fix tests to work with LPTICKER_DELAY_TICKS Fix the HAL common_tickers and sleep tests so they work correctly when the define LPTICKER_DELAY_TICKS is set. --- TESTS/mbed_hal/common_tickers/main.cpp | 19 +++++++++++++++++++ TESTS/mbed_hal/sleep/main.cpp | 16 ++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/TESTS/mbed_hal/common_tickers/main.cpp b/TESTS/mbed_hal/common_tickers/main.cpp index 495765c2d50..39e942624fd 100644 --- a/TESTS/mbed_hal/common_tickers/main.cpp +++ b/TESTS/mbed_hal/common_tickers/main.cpp @@ -20,6 +20,7 @@ #include "ticker_api_tests.h" #include "hal/us_ticker_api.h" #include "hal/lp_ticker_api.h" +#include "hal/mbed_lp_ticker_wrapper.h" #ifdef __cplusplus extern "C" { @@ -469,6 +470,15 @@ utest::v1::status_t us_ticker_setup(const Case *const source, const size_t index OS_Tick_Disable(); +#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0) + // After the OS is disabled wait until the microsecond timer + // is no longer in use by the lp ticker wrapper code. + // This prevents the low power ticker wrapper code from + // getting stuck in a state where it is waiting for + // the microsecond Timeout to run. + while (lp_ticker_get_timeout_pending()); +#endif + intf->init(); prev_irq_handler = set_us_ticker_irq_handler(ticker_event_handler_stub); @@ -497,6 +507,15 @@ utest::v1::status_t lp_ticker_setup(const Case *const source, const size_t index OS_Tick_Disable(); +#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0) + // After the OS is disabled wait until the microsecond timer + // is no longer in use by the lp ticker wrapper code. + // This prevents the low power ticker wrapper code from + // getting stuck in a state where it is waiting for + // the microsecond Timeout to run. + while (lp_ticker_get_timeout_pending()); +#endif + intf->init(); prev_irq_handler = set_lp_ticker_irq_handler(ticker_event_handler_stub); diff --git a/TESTS/mbed_hal/sleep/main.cpp b/TESTS/mbed_hal/sleep/main.cpp index 23e5839f26c..1f1b88f97a0 100644 --- a/TESTS/mbed_hal/sleep/main.cpp +++ b/TESTS/mbed_hal/sleep/main.cpp @@ -23,6 +23,7 @@ #include "utest/utest.h" #include "unity/unity.h" #include "greentea-client/test_env.h" +#include "mbed_lp_ticker_wrapper.h" #include "sleep_api_tests.h" @@ -256,12 +257,23 @@ utest::v1::status_t greentea_failure_handler(const Case * const source, const fa utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { GREENTEA_SETUP(60, "default_auto"); + /* Suspend RTOS Kernel to enable sleep modes. */ + osKernelSuspend(); + +#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0) + // After the OS is disabled wait until the microsecond timer + // is no longer in use by the lp ticker wrapper code. + // This prevents the low power ticker wrapper code from + // getting stuck in a state where it is waiting for + // the microsecond Timeout to run. + while (lp_ticker_get_timeout_pending()); +#endif + us_ticker_init(); #if DEVICE_LPTICKER lp_ticker_init(); #endif - /* Suspend RTOS Kernel to enable sleep modes. */ - osKernelSuspend(); + return greentea_test_setup_handler(number_of_cases); }