26
26
#endif
27
27
28
28
#define FORCE_OVERFLOW_TEST (false )
29
- #define TICKER_INT_VAL 2000
29
+ #define TICKER_INT_VAL 500
30
30
#define TICKER_DELTA 50
31
31
32
32
#define LP_TICKER_OVERFLOW_DELTA 0 // this will allow to detect that ticker counter rollovers to 0
@@ -51,9 +51,6 @@ unsigned int ticker_overflow_delta;
51
51
* Parameter <step> is used to disable compiler optimisation. */
52
52
uint32_t count_ticks (volatile uint32_t cycles, uint32_t step)
53
53
{
54
- /* Init the ticker. */
55
- intf->init ();
56
-
57
54
core_util_critical_section_enter ();
58
55
59
56
const uint32_t start = intf->read ();
@@ -133,9 +130,7 @@ void ticker_info_test(void)
133
130
/* Test that ticker interrupt fires only when the ticker counter increments to the value set by ticker_set_interrupt. */
134
131
void ticker_interrupt_test (void )
135
132
{
136
- uint32_t ticker_timeout[] = { 100 , 500 , 1000 , 2000 };
137
-
138
- intf->init ();
133
+ uint32_t ticker_timeout[] = { 100 , 200 , 300 , 500 };
139
134
140
135
for (uint32_t i = 0 ; i < (sizeof (ticker_timeout) / sizeof (uint32_t )); i++) {
141
136
intFlag = 0 ;
@@ -175,8 +170,6 @@ void ticker_past_test(void)
175
170
{
176
171
intFlag = 0 ;
177
172
178
- intf->init ();
179
-
180
173
const uint32_t tick_count = intf->read ();
181
174
182
175
/* Set interrupt tick count to value in the past.
@@ -193,8 +186,6 @@ void ticker_repeat_reschedule_test(void)
193
186
{
194
187
intFlag = 0 ;
195
188
196
- intf->init ();
197
-
198
189
const uint32_t tick_count = intf->read ();
199
190
200
191
/* Set interrupt. Interrupt should be fired when tick count is equal to:
@@ -227,8 +218,6 @@ void ticker_fire_now_test(void)
227
218
{
228
219
intFlag = 0 ;
229
220
230
- intf->init ();
231
-
232
221
intf->fire_interrupt ();
233
222
234
223
/* On some platforms set_interrupt function sets interrupt in the nearest feature. */
@@ -256,8 +245,6 @@ void ticker_overflow_test(void)
256
245
257
246
intFlag = 0 ;
258
247
259
- intf->init ();
260
-
261
248
/* Wait for max count. */
262
249
while (intf->read () != (max_count - ticker_overflow_delta)) {
263
250
/* Just wait. */
@@ -296,8 +283,6 @@ void ticker_overflow_test(void)
296
283
/* Test that the ticker increments by one on each tick. */
297
284
void ticker_increment_test (void )
298
285
{
299
- intf->init ();
300
-
301
286
const ticker_info_t * p_ticker_info = intf->get_info ();
302
287
303
288
/* Perform test based on ticker speed. */
@@ -334,8 +319,6 @@ void ticker_speed_test(void)
334
319
Timer timer;
335
320
int counter = NUM_OF_CALLS;
336
321
337
- intf->init ();
338
-
339
322
/* ---- Test ticker_read function. ---- */
340
323
timer.reset ();
341
324
timer.start ();
@@ -391,15 +374,38 @@ void ticker_speed_test(void)
391
374
TEST_ASSERT (timer.read_us () < (NUM_OF_CALLS * (MAX_FUNC_EXEC_TIME_US + DELTA_FUNC_EXEC_TIME_US)));
392
375
}
393
376
377
+ /* Since according to the ticker requirements min acceptable counter size is
378
+ * 12 bits (low power timer) for which max count is
379
+ * 4095, then all test cases must be executed in this time window.
380
+ * HAL ticker layer handles overflow and it is not handled in the target
381
+ * ticker drivers.
382
+ */
383
+ void overflow_protect ()
384
+ {
385
+ const uint32_t ticks_now = intf->read ();
386
+ const ticker_info_t * p_ticker_info = intf->get_info ();
387
+
388
+ const uint32_t max_count = (1 << p_ticker_info->bits - 1 );
389
+
390
+ if ((max_count - ticks_now) > 4000 ) {
391
+ return ;
392
+ }
393
+
394
+ while (intf->read () > ticks_now);
395
+ }
394
396
395
397
utest::v1::status_t hf_ticker_setup (const Case *const source, const size_t index_of_case)
396
398
{
397
399
intf = get_us_ticker_data ()->interface ;
398
400
401
+ intf->init ();
402
+
399
403
set_us_ticker_irq_handler (ticker_event_handler_stub);
400
404
401
405
ticker_overflow_delta = HF_TICKER_OVERFLOW_DELTA;
402
406
407
+ overflow_protect ();
408
+
403
409
return greentea_case_setup_handler (source, index_of_case);
404
410
}
405
411
@@ -408,10 +414,14 @@ utest::v1::status_t lp_ticker_setup(const Case *const source, const size_t index
408
414
{
409
415
intf = get_lp_ticker_data ()->interface ;
410
416
417
+ intf->init ();
418
+
411
419
set_lp_ticker_irq_handler (ticker_event_handler_stub);
412
420
413
421
ticker_overflow_delta = LP_TICKER_OVERFLOW_DELTA;
414
422
423
+ overflow_protect ();
424
+
415
425
return greentea_case_setup_handler (source, index_of_case);
416
426
}
417
427
#endif
0 commit comments