Skip to content

Commit

Permalink
Fix tests to work with LPTICKER_DELAY_TICKS
Browse files Browse the repository at this point in the history
Fix the HAL common_tickers and sleep tests so they work correctly when
the define LPTICKER_DELAY_TICKS is set.
  • Loading branch information
c1728p9 committed Jul 16, 2018
1 parent c85856b commit 0f80394
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
19 changes: 19 additions & 0 deletions TESTS/mbed_hal/common_tickers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions TESTS/mbed_hal/sleep/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 0f80394

Please sign in to comment.