Skip to content

Commit e98a9d6

Browse files
committed
tests-mbed_hal-common_tickers: adapt ticker_interrupt_test() test case for high frequency tickers
On some targets with very fast counters used for us ticker (e.g. 26 MHz) tested interrupt delays provided in the ticker_timeout array may be too short (execution of the set_interrupt() function takes longer than the tested delay). We will skip tested ticker delay if the delay is less than assumed max set_interrupt() function execution time (20 us). Also, the test array will be extended.
1 parent 5d71e69 commit e98a9d6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

TESTS/mbed_hal/common_tickers/main.cpp

Lines changed: 14 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;
@@ -213,14 +215,24 @@ void ticker_info_test(void)
213215
TEST_ASSERT(p_ticker_info->bits >= 8);
214216
}
215217

218+
219+
216220
/* Test that ticker interrupt fires only when the ticker counter increments to the value set by ticker_set_interrupt. */
217221
void ticker_interrupt_test(void)
218222
{
219-
uint32_t ticker_timeout[] = { 100, 200, 300, 500 };
223+
uint32_t ticker_timeout[] = { 100, 200, 300, 500, 600, 700, 800, 900, 1000, 1100, 1200 };
224+
225+
const ticker_info_t *p_ticker_info = intf->get_info();
220226

221227
overflow_protect();
222228

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

0 commit comments

Comments
 (0)