29
29
#define TICKER_INT_VAL 500
30
30
#define TICKER_DELTA 10
31
31
32
- #define LP_TICKER_OVERFLOW_DELTA 0 // this will allow to detect that ticker counter rollovers to 0
33
- #define US_TICKER_OVERFLOW_DELTA 50
32
+ #define LP_TICKER_OVERFLOW_DELTA1 0 // this will allow to detect that ticker counter rollovers to 0
33
+ #define LP_TICKER_OVERFLOW_DELTA2 0
34
+ #define US_TICKER_OVERFLOW_DELTA1 50
35
+ #define US_TICKER_OVERFLOW_DELTA2 60
34
36
35
37
#define TICKER_100_TICKS 100
36
38
@@ -48,7 +50,18 @@ using namespace utest::v1;
48
50
volatile int intFlag = 0 ;
49
51
const ticker_interface_t * intf;
50
52
ticker_irq_handler_type prev_irq_handler;
51
- unsigned int ticker_overflow_delta;
53
+ /* Some targets might fail overflow test uncertainly due to getting trapped in busy
54
+ * intf->read() loop. In the loop, some ticker values wouldn't get caught in time
55
+ * because of:
56
+ * 1. Lower CPU clock
57
+ * 2. Compiled code with worse performance
58
+ * 3. Interrupt at that time
59
+ *
60
+ * We fix it by checking small ticker value range rather than one exact ticker point
61
+ * in near overflow check.
62
+ */
63
+ unsigned int ticker_overflow_delta1;
64
+ unsigned int ticker_overflow_delta2;
52
65
53
66
/* Auxiliary function to count ticker ticks elapsed during execution of N cycles of empty while loop.
54
67
* Parameter <step> is used to disable compiler optimisation. */
@@ -293,12 +306,13 @@ void ticker_overflow_test(void)
293
306
intFlag = 0 ;
294
307
295
308
/* Wait for max count. */
296
- while (intf->read () != (max_count - ticker_overflow_delta)) {
309
+ while (intf->read () >= (max_count - ticker_overflow_delta2) &&
310
+ intf->read () <= (max_count - ticker_overflow_delta1)) {
297
311
/* Just wait. */
298
312
}
299
313
300
314
/* Now we are near/at the overflow point. Detect rollover. */
301
- while (intf->read () > ticker_overflow_delta );
315
+ while (intf->read () > ticker_overflow_delta1 );
302
316
303
317
const uint32_t after_overflow = intf->read ();
304
318
@@ -310,7 +324,7 @@ void ticker_overflow_test(void)
310
324
const uint32_t next_after_overflow = intf->read ();
311
325
312
326
/* Check that after the overflow ticker continue count. */
313
- TEST_ASSERT (after_overflow <= ticker_overflow_delta );
327
+ TEST_ASSERT (after_overflow <= ticker_overflow_delta1 );
314
328
TEST_ASSERT (next_after_overflow >= TICKER_100_TICKS);
315
329
TEST_ASSERT_EQUAL (0 , intFlag);
316
330
@@ -465,7 +479,8 @@ utest::v1::status_t us_ticker_setup(const Case *const source, const size_t index
465
479
466
480
prev_irq_handler = set_us_ticker_irq_handler (ticker_event_handler_stub);
467
481
468
- ticker_overflow_delta = US_TICKER_OVERFLOW_DELTA;
482
+ ticker_overflow_delta1 = US_TICKER_OVERFLOW_DELTA1;
483
+ ticker_overflow_delta2 = US_TICKER_OVERFLOW_DELTA2;
469
484
470
485
return greentea_case_setup_handler (source, index_of_case);
471
486
}
@@ -493,7 +508,8 @@ utest::v1::status_t lp_ticker_setup(const Case *const source, const size_t index
493
508
494
509
prev_irq_handler = set_lp_ticker_irq_handler (ticker_event_handler_stub);
495
510
496
- ticker_overflow_delta = LP_TICKER_OVERFLOW_DELTA;
511
+ ticker_overflow_delta1 = LP_TICKER_OVERFLOW_DELTA1;
512
+ ticker_overflow_delta2 = LP_TICKER_OVERFLOW_DELTA2;
497
513
498
514
return greentea_case_setup_handler (source, index_of_case);
499
515
}
0 commit comments