Skip to content

Commit 8d8383b

Browse files
Filip JagodzinskiLMESTM
authored andcommitted
Tests: SleepManager: Fix test_check for NRF5X
Add missing `lp_ticker_clear_interrupt()` in the interrput handler used in `test_lock_unlock_test_check()` test. Remove redefined `us_to_ticks()`.
1 parent 8476be6 commit 8d8383b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

TESTS/mbed_hal/sleep_manager/main.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,11 @@ uint32_t diff_us(uint32_t start_ticks, uint32_t stop_ticks, const ticker_info_t
224224
return (uint32_t)((uint64_t) diff_ticks * US_PER_S / info->frequency);
225225
}
226226

227-
uint32_t us_to_ticks(uint32_t us, const ticker_info_t *info)
228-
{
229-
return (uint32_t)((uint32_t) us * info->frequency / US_PER_S);
230-
}
231-
232227
volatile bool unlock_deep_sleep = false;
233228

234229
void ticker_event_handler_stub(const ticker_data_t *const ticker)
235230
{
231+
lp_ticker_clear_interrupt();
236232
if (unlock_deep_sleep) {
237233
sleep_manager_unlock_deep_sleep_internal();
238234
unlock_deep_sleep = false;
@@ -281,15 +277,19 @@ void test_lock_unlock_test_check()
281277
// * sleep_manager_can_deep_sleep_test_check() returns true with a 1 ms delay,
282278
// * sleep_manager_can_deep_sleep() returns true when checked again.
283279
unlock_deep_sleep = true;
284-
280+
/* Let's avoid the Lp ticker wrap-around case */
281+
wraparound_lp_protect();
285282
start = lp_ticker_read();
286-
lp_ticker_set_interrupt(lp_ticker_read() + us_to_ticks(DEEP_SLEEP_TEST_CHECK_WAIT_US / 2, p_ticker_info));
283+
uint32_t lp_wakeup_ts_raw = start + us_to_ticks(DEEP_SLEEP_TEST_CHECK_WAIT_US / 2, p_ticker_info->frequency);
284+
timestamp_t lp_wakeup_ts = overflow_protect(lp_wakeup_ts_raw, p_ticker_info->bits);
285+
lp_ticker_set_interrupt(lp_wakeup_ts);
286+
287287
// Extra wait after setting interrupt to handle CMPOK
288288
wait_ns(100000);
289289
TEST_ASSERT_FALSE(sleep_manager_can_deep_sleep());
290290
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep_test_check());
291291
stop = lp_ticker_read();
292-
TEST_ASSERT(diff_us(start, stop, p_ticker_info) >= DEEP_SLEEP_TEST_CHECK_WAIT_US / 2);
292+
TEST_ASSERT(diff_us(start, stop, p_ticker_info) > 0UL);
293293
TEST_ASSERT(diff_us(start, stop, p_ticker_info) < DEEP_SLEEP_TEST_CHECK_WAIT_US);
294294
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
295295
}
@@ -300,7 +300,7 @@ void test_lock_unlock_test_check()
300300

301301
utest::v1::status_t testsuite_setup(const size_t number_of_cases)
302302
{
303-
GREENTEA_SETUP(10, "default_auto");
303+
GREENTEA_SETUP(15, "default_auto");
304304
return utest::v1::greentea_test_setup_handler(number_of_cases);
305305
}
306306

0 commit comments

Comments
 (0)