Skip to content

Commit d7b7223

Browse files
authored
Merge pull request ARMmbed#12218 from mprse/ticker_interrupt_test_fix
tests-mbed_hal-common_tickers: adapt ticker_interrupt_test() test case for high frequency tickers - WIP
2 parents ec3fc67 + db8e776 commit d7b7223

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

TESTS/mbed_hal/common_tickers/main.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern "C" {
5353
#define TICKER_100_TICKS 100
5454
#define TICKER_500_TICKS 500
5555

56-
#define MAX_FUNC_EXEC_TIME_US 30
56+
#define MAX_FUNC_EXEC_TIME_US 20
5757
#define DELTA_FUNC_EXEC_TIME_US 5
5858
#define NUM_OF_CALLS 100
5959

@@ -62,6 +62,8 @@ extern "C" {
6262
#define US_TICKER_OV_LIMIT 35000
6363
#define LP_TICKER_OV_LIMIT 4000
6464

65+
#define TICKS_TO_US(ticks, freq) ((uint32_t) ((uint64_t)ticks * US_PER_S /freq))
66+
6567
using namespace utest::v1;
6668

6769
volatile int intFlag = 0;
@@ -216,11 +218,20 @@ void ticker_info_test(void)
216218
/* Test that ticker interrupt fires only when the ticker counter increments to the value set by ticker_set_interrupt. */
217219
void ticker_interrupt_test(void)
218220
{
219-
uint32_t ticker_timeout[] = { 100, 200, 300, 500 };
221+
uint32_t ticker_timeout[] = { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200 };
222+
uint8_t run_count = 0;
223+
const ticker_info_t *p_ticker_info = intf->get_info();
220224

221225
overflow_protect();
222226

223227
for (uint32_t i = 0; i < (sizeof(ticker_timeout) / sizeof(uint32_t)); i++) {
228+
229+
/* Skip timeout if less than max allowed execution time of set_interrupt() - 20 us */
230+
if (TICKS_TO_US(ticker_timeout[i], p_ticker_info->frequency) < (MAX_FUNC_EXEC_TIME_US + DELTA_FUNC_EXEC_TIME_US)) {
231+
continue;
232+
}
233+
234+
run_count++;
224235
intFlag = 0;
225236
const uint32_t tick_count = intf->read();
226237

@@ -251,6 +262,9 @@ void ticker_interrupt_test(void)
251262

252263
TEST_ASSERT_EQUAL(1, intFlag);
253264
}
265+
266+
/* At least 3 sub test cases must be executed. */
267+
TEST_ASSERT_MESSAGE(run_count >= 3, "At least 3 sub test cases must be executed");
254268
}
255269

256270
/* Test that ticker interrupt is not triggered when ticker_set_interrupt */

0 commit comments

Comments
 (0)