@@ -65,6 +65,20 @@ static Timer *p_timer = NULL;
65
65
*/
66
66
static uint32_t curr_ticker_ticks_val;
67
67
68
+
69
+ /* Replacement for generic wait functions to avoid invoking OS scheduling stuff. */
70
+ void busy_wait_us (int us)
71
+ {
72
+ const ticker_data_t *const ticker = get_us_ticker_data ();
73
+ uint32_t start = ticker_read (ticker);
74
+ while ((ticker_read (ticker) - start) < (uint32_t )us);
75
+ }
76
+
77
+ void busy_wait_ms (int ms)
78
+ {
79
+ busy_wait_us (ms * US_PER_MSEC);
80
+ }
81
+
68
82
/* User ticker interface function. */
69
83
static void stub_interface_init ()
70
84
{
@@ -203,7 +217,7 @@ void test_timer_creation_os_ticker()
203
217
204
218
/* Wait 10 ms.
205
219
* After that operation timer read routines should still return 0. */
206
- wait_ms (10 );
220
+ busy_wait_ms (10 );
207
221
208
222
/* Check results. */
209
223
TEST_ASSERT_EQUAL_FLOAT (0 , p_timer->read ());
@@ -413,7 +427,7 @@ void test_timer_time_accumulation_os_ticker()
413
427
p_timer->start ();
414
428
415
429
/* Wait 10 ms. */
416
- wait_ms (10 );
430
+ busy_wait_ms (10 );
417
431
418
432
/* Stop the timer. */
419
433
p_timer->stop ();
@@ -427,15 +441,15 @@ void test_timer_time_accumulation_os_ticker()
427
441
/* Wait 50 ms - this is done to show that time elapsed when
428
442
* the timer is stopped does not have influence on the
429
443
* timer counted time. */
430
- wait_ms (50 );
444
+ busy_wait_ms (50 );
431
445
432
446
/* ------ */
433
447
434
448
/* Start the timer. */
435
449
p_timer->start ();
436
450
437
451
/* Wait 20 ms. */
438
- wait_ms (20 );
452
+ busy_wait_ms (20 );
439
453
440
454
/* Stop the timer. */
441
455
p_timer->stop ();
@@ -456,7 +470,7 @@ void test_timer_time_accumulation_os_ticker()
456
470
p_timer->start ();
457
471
458
472
/* Wait 30 ms. */
459
- wait_ms (30 );
473
+ busy_wait_ms (30 );
460
474
461
475
/* Stop the timer. */
462
476
p_timer->stop ();
@@ -470,15 +484,15 @@ void test_timer_time_accumulation_os_ticker()
470
484
/* Wait 50 ms - this is done to show that time elapsed when
471
485
* the timer is stopped does not have influence on the
472
486
* timer time. */
473
- wait_ms (50 );
487
+ busy_wait_ms (50 );
474
488
475
489
/* ------ */
476
490
477
491
/* Start the timer. */
478
492
p_timer->start ();
479
493
480
494
/* Wait 1 sec. */
481
- wait_ms (1000 );
495
+ busy_wait_ms (1000 );
482
496
483
497
/* Stop the timer. */
484
498
p_timer->stop ();
@@ -507,7 +521,7 @@ void test_timer_reset_os_ticker()
507
521
p_timer->start ();
508
522
509
523
/* Wait 10 ms. */
510
- wait_ms (10 );
524
+ busy_wait_ms (10 );
511
525
512
526
/* Stop the timer. */
513
527
p_timer->stop ();
@@ -525,7 +539,7 @@ void test_timer_reset_os_ticker()
525
539
p_timer->start ();
526
540
527
541
/* Wait 20 ms. */
528
- wait_ms (20 );
542
+ busy_wait_ms (20 );
529
543
530
544
/* Stop the timer. */
531
545
p_timer->stop ();
@@ -603,13 +617,13 @@ void test_timer_start_started_timer_os_ticker()
603
617
p_timer->start ();
604
618
605
619
/* Wait 10 ms. */
606
- wait_ms (10 );
620
+ busy_wait_ms (10 );
607
621
608
622
/* Now start timer again. */
609
623
p_timer->start ();
610
624
611
625
/* Wait 20 ms. */
612
- wait_ms (20 );
626
+ busy_wait_ms (20 );
613
627
614
628
/* Stop the timer. */
615
629
p_timer->stop ();
@@ -673,7 +687,7 @@ void test_timer_float_operator_os_ticker()
673
687
p_timer->start ();
674
688
675
689
/* Wait 10 ms. */
676
- wait_ms (10 );
690
+ busy_wait_ms (10 );
677
691
678
692
/* Stop the timer. */
679
693
p_timer->stop ();
@@ -728,7 +742,7 @@ void test_timer_time_measurement()
728
742
p_timer->start ();
729
743
730
744
/* Wait <wait_val_us> us. */
731
- wait_us (wait_val_us);
745
+ busy_wait_us (wait_val_us);
732
746
733
747
/* Stop the timer. */
734
748
p_timer->stop ();
0 commit comments