Skip to content

Commit 48cae05

Browse files
mprse0xc0170
authored andcommitted
lp_us_tickers test: call overflow_protect function in test functions instead test setup handler.
This is done to bypass green-tea setup handler which takes additional time.
1 parent 6c960b2 commit 48cae05

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

TESTS/mbed_hal/common_tickers/main.cpp

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,35 @@ uint32_t count_ticks(uint32_t cycles, uint32_t step)
7373
return (diff);
7474
}
7575

76+
/* Since according to the ticker requirements min acceptable counter size is
77+
* - 12 bits for low power timer - max count = 4095,
78+
* - 16 bits for high frequency timer - max count = 65535
79+
* then all test cases must be executed in this time windows.
80+
* HAL ticker layer handles counter overflow and it is not handled in the target
81+
* ticker drivers. Ensure we have enough time to execute test case without overflow.
82+
*/
83+
void overflow_protect()
84+
{
85+
uint32_t time_window;
86+
87+
if (intf == get_us_ticker_data()->interface) {
88+
time_window = US_TICKER_OV_LIMIT;
89+
} else {
90+
time_window = LP_TICKER_OV_LIMIT;
91+
}
92+
93+
const uint32_t ticks_now = intf->read();
94+
const ticker_info_t* p_ticker_info = intf->get_info();
95+
96+
const uint32_t max_count = ((1 << p_ticker_info->bits) - 1);
97+
98+
if ((max_count - ticks_now) > time_window) {
99+
return;
100+
}
101+
102+
while (intf->read() > ticks_now);
103+
}
104+
76105
void ticker_event_handler_stub(const ticker_data_t * const ticker)
77106
{
78107
if (ticker == get_us_ticker_data()) {
@@ -99,6 +128,8 @@ void wait_cycles(volatile unsigned int cycles)
99128
*/
100129
void ticker_init_test()
101130
{
131+
overflow_protect();
132+
102133
intFlag = 0;
103134

104135
intf->init();
@@ -139,6 +170,8 @@ void ticker_interrupt_test(void)
139170
{
140171
uint32_t ticker_timeout[] = { 100, 200, 300, 500 };
141172

173+
overflow_protect();
174+
142175
for (uint32_t i = 0; i < (sizeof(ticker_timeout) / sizeof(uint32_t)); i++) {
143176
intFlag = 0;
144177
const uint32_t tick_count = intf->read();
@@ -191,6 +224,8 @@ void ticker_past_test(void)
191224
/* Test that ticker can be rescheduled repeatedly before the handler has been called. */
192225
void ticker_repeat_reschedule_test(void)
193226
{
227+
overflow_protect();
228+
194229
intFlag = 0;
195230

196231
const uint32_t tick_count = intf->read();
@@ -395,27 +430,6 @@ void ticker_speed_test(void)
395430
TEST_ASSERT(timer.read_us() < (NUM_OF_CALLS * (MAX_FUNC_EXEC_TIME_US + DELTA_FUNC_EXEC_TIME_US)));
396431
}
397432

398-
/* Since according to the ticker requirements min acceptable counter size is
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.
404-
*/
405-
void overflow_protect(uint32_t time_window)
406-
{
407-
const uint32_t ticks_now = intf->read();
408-
const ticker_info_t* p_ticker_info = intf->get_info();
409-
410-
const uint32_t max_count = ((1 << p_ticker_info->bits) - 1);
411-
412-
if ((max_count - ticks_now) > time_window) {
413-
return;
414-
}
415-
416-
while (intf->read() > ticks_now);
417-
}
418-
419433
utest::v1::status_t us_ticker_setup(const Case *const source, const size_t index_of_case)
420434
{
421435
intf = get_us_ticker_data()->interface;
@@ -426,8 +440,6 @@ utest::v1::status_t us_ticker_setup(const Case *const source, const size_t index
426440

427441
ticker_overflow_delta = US_TICKER_OVERFLOW_DELTA;
428442

429-
overflow_protect(20000);
430-
431443
return greentea_case_setup_handler(source, index_of_case);
432444
}
433445

@@ -442,8 +454,6 @@ utest::v1::status_t lp_ticker_setup(const Case *const source, const size_t index
442454

443455
ticker_overflow_delta = LP_TICKER_OVERFLOW_DELTA;
444456

445-
overflow_protect(4000);
446-
447457
return greentea_case_setup_handler(source, index_of_case);
448458
}
449459
#endif

0 commit comments

Comments
 (0)