@@ -224,15 +224,11 @@ uint32_t diff_us(uint32_t start_ticks, uint32_t stop_ticks, const ticker_info_t
224
224
return (uint32_t )((uint64_t ) diff_ticks * US_PER_S / info->frequency );
225
225
}
226
226
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
-
232
227
volatile bool unlock_deep_sleep = false ;
233
228
234
229
void ticker_event_handler_stub (const ticker_data_t *const ticker)
235
230
{
231
+ lp_ticker_clear_interrupt ();
236
232
if (unlock_deep_sleep) {
237
233
sleep_manager_unlock_deep_sleep_internal ();
238
234
unlock_deep_sleep = false ;
@@ -281,15 +277,19 @@ void test_lock_unlock_test_check()
281
277
// * sleep_manager_can_deep_sleep_test_check() returns true with a 1 ms delay,
282
278
// * sleep_manager_can_deep_sleep() returns true when checked again.
283
279
unlock_deep_sleep = true ;
284
-
280
+ /* Let's avoid the Lp ticker wrap-around case */
281
+ wraparound_lp_protect ();
285
282
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
+
287
287
// Extra wait after setting interrupt to handle CMPOK
288
288
wait_ns (100000 );
289
289
TEST_ASSERT_FALSE (sleep_manager_can_deep_sleep ());
290
290
TEST_ASSERT_TRUE (sleep_manager_can_deep_sleep_test_check ());
291
291
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 );
293
293
TEST_ASSERT (diff_us (start, stop, p_ticker_info) < DEEP_SLEEP_TEST_CHECK_WAIT_US);
294
294
TEST_ASSERT_TRUE (sleep_manager_can_deep_sleep ());
295
295
}
@@ -300,7 +300,7 @@ void test_lock_unlock_test_check()
300
300
301
301
utest::v1::status_t testsuite_setup (const size_t number_of_cases)
302
302
{
303
- GREENTEA_SETUP (10 , " default_auto" );
303
+ GREENTEA_SETUP (15 , " default_auto" );
304
304
return utest::v1::greentea_test_setup_handler (number_of_cases);
305
305
}
306
306
0 commit comments