Skip to content

Commit 0f80394

Browse files
committed
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.
1 parent c85856b commit 0f80394

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

TESTS/mbed_hal/common_tickers/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "ticker_api_tests.h"
2121
#include "hal/us_ticker_api.h"
2222
#include "hal/lp_ticker_api.h"
23+
#include "hal/mbed_lp_ticker_wrapper.h"
2324

2425
#ifdef __cplusplus
2526
extern "C" {
@@ -469,6 +470,15 @@ utest::v1::status_t us_ticker_setup(const Case *const source, const size_t index
469470

470471
OS_Tick_Disable();
471472

473+
#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0)
474+
// After the OS is disabled wait until the microsecond timer
475+
// is no longer in use by the lp ticker wrapper code.
476+
// This prevents the low power ticker wrapper code from
477+
// getting stuck in a state where it is waiting for
478+
// the microsecond Timeout to run.
479+
while (lp_ticker_get_timeout_pending());
480+
#endif
481+
472482
intf->init();
473483

474484
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
497507

498508
OS_Tick_Disable();
499509

510+
#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0)
511+
// After the OS is disabled wait until the microsecond timer
512+
// is no longer in use by the lp ticker wrapper code.
513+
// This prevents the low power ticker wrapper code from
514+
// getting stuck in a state where it is waiting for
515+
// the microsecond Timeout to run.
516+
while (lp_ticker_get_timeout_pending());
517+
#endif
518+
500519
intf->init();
501520

502521
prev_irq_handler = set_lp_ticker_irq_handler(ticker_event_handler_stub);

TESTS/mbed_hal/sleep/main.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "utest/utest.h"
2424
#include "unity/unity.h"
2525
#include "greentea-client/test_env.h"
26+
#include "mbed_lp_ticker_wrapper.h"
2627

2728
#include "sleep_api_tests.h"
2829

@@ -256,12 +257,23 @@ utest::v1::status_t greentea_failure_handler(const Case * const source, const fa
256257
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
257258
{
258259
GREENTEA_SETUP(60, "default_auto");
260+
/* Suspend RTOS Kernel to enable sleep modes. */
261+
osKernelSuspend();
262+
263+
#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0)
264+
// After the OS is disabled wait until the microsecond timer
265+
// is no longer in use by the lp ticker wrapper code.
266+
// This prevents the low power ticker wrapper code from
267+
// getting stuck in a state where it is waiting for
268+
// the microsecond Timeout to run.
269+
while (lp_ticker_get_timeout_pending());
270+
#endif
271+
259272
us_ticker_init();
260273
#if DEVICE_LPTICKER
261274
lp_ticker_init();
262275
#endif
263-
/* Suspend RTOS Kernel to enable sleep modes. */
264-
osKernelSuspend();
276+
265277
return greentea_test_setup_handler(number_of_cases);
266278
}
267279

0 commit comments

Comments
 (0)