@@ -73,6 +73,35 @@ uint32_t count_ticks(uint32_t cycles, uint32_t step)
73
73
return (diff);
74
74
}
75
75
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
+
76
105
void ticker_event_handler_stub (const ticker_data_t * const ticker)
77
106
{
78
107
if (ticker == get_us_ticker_data ()) {
@@ -99,6 +128,8 @@ void wait_cycles(volatile unsigned int cycles)
99
128
*/
100
129
void ticker_init_test ()
101
130
{
131
+ overflow_protect ();
132
+
102
133
intFlag = 0 ;
103
134
104
135
intf->init ();
@@ -139,6 +170,8 @@ void ticker_interrupt_test(void)
139
170
{
140
171
uint32_t ticker_timeout[] = { 100 , 200 , 300 , 500 };
141
172
173
+ overflow_protect ();
174
+
142
175
for (uint32_t i = 0 ; i < (sizeof (ticker_timeout) / sizeof (uint32_t )); i++) {
143
176
intFlag = 0 ;
144
177
const uint32_t tick_count = intf->read ();
@@ -191,6 +224,8 @@ void ticker_past_test(void)
191
224
/* Test that ticker can be rescheduled repeatedly before the handler has been called. */
192
225
void ticker_repeat_reschedule_test (void )
193
226
{
227
+ overflow_protect ();
228
+
194
229
intFlag = 0 ;
195
230
196
231
const uint32_t tick_count = intf->read ();
@@ -395,27 +430,6 @@ void ticker_speed_test(void)
395
430
TEST_ASSERT (timer.read_us () < (NUM_OF_CALLS * (MAX_FUNC_EXEC_TIME_US + DELTA_FUNC_EXEC_TIME_US)));
396
431
}
397
432
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
-
419
433
utest::v1::status_t us_ticker_setup (const Case *const source, const size_t index_of_case)
420
434
{
421
435
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
426
440
427
441
ticker_overflow_delta = US_TICKER_OVERFLOW_DELTA;
428
442
429
- overflow_protect (20000 );
430
-
431
443
return greentea_case_setup_handler (source, index_of_case);
432
444
}
433
445
@@ -442,8 +454,6 @@ utest::v1::status_t lp_ticker_setup(const Case *const source, const size_t index
442
454
443
455
ticker_overflow_delta = LP_TICKER_OVERFLOW_DELTA;
444
456
445
- overflow_protect (4000 );
446
-
447
457
return greentea_case_setup_handler (source, index_of_case);
448
458
}
449
459
#endif
0 commit comments