Skip to content

Commit 6c960b2

Browse files
mprse0xc0170
authored andcommitted
lp_us_tickers test: fix overflow protection
On slow targets with fast high frequency tickers like NRF51_DK (16 Mhz CPU/1MHz ticker) time window for test case execution without overflow needs to be increased. Add parameter to `overflow_protect` function to be able to set different time window without overflow for us ticker and lp ticker.
1 parent 4d7167c commit 6c960b2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

TESTS/mbed_hal/common_tickers/main.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,20 @@ void ticker_speed_test(void)
396396
}
397397

398398
/* Since according to the ticker requirements min acceptable counter size is
399-
* 12 bits (low power timer) for which max count is
400-
* 4095, then all test cases must be executed in this time window.
401-
* HAL ticker layer handles overflow and it is not handled in the target
402-
* ticker drivers.
399+
* - 12 bits for low power timer - max count = 4095,
400+
* - 16 bits for high frequency timer - max count = 65535
401+
* then all test cases must be executed in this time windows.
402+
* HAL ticker layer handles counter overflow and it is not handled in the target
403+
* ticker drivers. Ensure we have enough time to execute test case without overflow.
403404
*/
404-
void overflow_protect()
405+
void overflow_protect(uint32_t time_window)
405406
{
406407
const uint32_t ticks_now = intf->read();
407408
const ticker_info_t* p_ticker_info = intf->get_info();
408409

409-
const uint32_t max_count = (1 << p_ticker_info->bits - 1);
410+
const uint32_t max_count = ((1 << p_ticker_info->bits) - 1);
410411

411-
if ((max_count - ticks_now) > 4000) {
412+
if ((max_count - ticks_now) > time_window) {
412413
return;
413414
}
414415

@@ -425,7 +426,7 @@ utest::v1::status_t us_ticker_setup(const Case *const source, const size_t index
425426

426427
ticker_overflow_delta = US_TICKER_OVERFLOW_DELTA;
427428

428-
overflow_protect();
429+
overflow_protect(20000);
429430

430431
return greentea_case_setup_handler(source, index_of_case);
431432
}
@@ -441,7 +442,7 @@ utest::v1::status_t lp_ticker_setup(const Case *const source, const size_t index
441442

442443
ticker_overflow_delta = LP_TICKER_OVERFLOW_DELTA;
443444

444-
overflow_protect();
445+
overflow_protect(4000);
445446

446447
return greentea_case_setup_handler(source, index_of_case);
447448
}

0 commit comments

Comments
 (0)