Skip to content

Commit efe9e44

Browse files
tests-mbed_drivers-timer: change delay method
1 parent 54f40a0 commit efe9e44

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

TESTS/mbed_drivers/timer/main.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ static Timer *p_timer = NULL;
6565
*/
6666
static uint32_t curr_ticker_ticks_val;
6767

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+
6882
/* User ticker interface function. */
6983
static void stub_interface_init()
7084
{
@@ -203,7 +217,7 @@ void test_timer_creation_os_ticker()
203217

204218
/* Wait 10 ms.
205219
* After that operation timer read routines should still return 0. */
206-
wait_ms(10);
220+
busy_wait_ms(10);
207221

208222
/* Check results. */
209223
TEST_ASSERT_EQUAL_FLOAT(0, p_timer->read());
@@ -413,7 +427,7 @@ void test_timer_time_accumulation_os_ticker()
413427
p_timer->start();
414428

415429
/* Wait 10 ms. */
416-
wait_ms(10);
430+
busy_wait_ms(10);
417431

418432
/* Stop the timer. */
419433
p_timer->stop();
@@ -427,15 +441,15 @@ void test_timer_time_accumulation_os_ticker()
427441
/* Wait 50 ms - this is done to show that time elapsed when
428442
* the timer is stopped does not have influence on the
429443
* timer counted time. */
430-
wait_ms(50);
444+
busy_wait_ms(50);
431445

432446
/* ------ */
433447

434448
/* Start the timer. */
435449
p_timer->start();
436450

437451
/* Wait 20 ms. */
438-
wait_ms(20);
452+
busy_wait_ms(20);
439453

440454
/* Stop the timer. */
441455
p_timer->stop();
@@ -456,7 +470,7 @@ void test_timer_time_accumulation_os_ticker()
456470
p_timer->start();
457471

458472
/* Wait 30 ms. */
459-
wait_ms(30);
473+
busy_wait_ms(30);
460474

461475
/* Stop the timer. */
462476
p_timer->stop();
@@ -470,15 +484,15 @@ void test_timer_time_accumulation_os_ticker()
470484
/* Wait 50 ms - this is done to show that time elapsed when
471485
* the timer is stopped does not have influence on the
472486
* timer time. */
473-
wait_ms(50);
487+
busy_wait_ms(50);
474488

475489
/* ------ */
476490

477491
/* Start the timer. */
478492
p_timer->start();
479493

480494
/* Wait 1 sec. */
481-
wait_ms(1000);
495+
busy_wait_ms(1000);
482496

483497
/* Stop the timer. */
484498
p_timer->stop();
@@ -507,7 +521,7 @@ void test_timer_reset_os_ticker()
507521
p_timer->start();
508522

509523
/* Wait 10 ms. */
510-
wait_ms(10);
524+
busy_wait_ms(10);
511525

512526
/* Stop the timer. */
513527
p_timer->stop();
@@ -525,7 +539,7 @@ void test_timer_reset_os_ticker()
525539
p_timer->start();
526540

527541
/* Wait 20 ms. */
528-
wait_ms(20);
542+
busy_wait_ms(20);
529543

530544
/* Stop the timer. */
531545
p_timer->stop();
@@ -603,13 +617,13 @@ void test_timer_start_started_timer_os_ticker()
603617
p_timer->start();
604618

605619
/* Wait 10 ms. */
606-
wait_ms(10);
620+
busy_wait_ms(10);
607621

608622
/* Now start timer again. */
609623
p_timer->start();
610624

611625
/* Wait 20 ms. */
612-
wait_ms(20);
626+
busy_wait_ms(20);
613627

614628
/* Stop the timer. */
615629
p_timer->stop();
@@ -673,7 +687,7 @@ void test_timer_float_operator_os_ticker()
673687
p_timer->start();
674688

675689
/* Wait 10 ms. */
676-
wait_ms(10);
690+
busy_wait_ms(10);
677691

678692
/* Stop the timer. */
679693
p_timer->stop();
@@ -728,7 +742,7 @@ void test_timer_time_measurement()
728742
p_timer->start();
729743

730744
/* Wait <wait_val_us> us. */
731-
wait_us(wait_val_us);
745+
busy_wait_us(wait_val_us);
732746

733747
/* Stop the timer. */
734748
p_timer->stop();

0 commit comments

Comments
 (0)