Skip to content

tests-mbed_drivers-timer: change delay method #7752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions TESTS/mbed_drivers/timer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ static Timer *p_timer = NULL;
*/
static uint32_t curr_ticker_ticks_val;


/* Replacement for generic wait functions to avoid invoking OS scheduling stuff. */
void busy_wait_us(int us)
{
const ticker_data_t *const ticker = get_us_ticker_data();
uint32_t start = ticker_read(ticker);
while ((ticker_read(ticker) - start) < (uint32_t)us);
}

void busy_wait_ms(int ms)
{
busy_wait_us(ms * US_PER_MSEC);
}

/* User ticker interface function. */
static void stub_interface_init()
{
Expand Down Expand Up @@ -203,7 +217,7 @@ void test_timer_creation_os_ticker()

/* Wait 10 ms.
* After that operation timer read routines should still return 0. */
wait_ms(10);
busy_wait_ms(10);

/* Check results. */
TEST_ASSERT_EQUAL_FLOAT(0, p_timer->read());
Expand Down Expand Up @@ -413,7 +427,7 @@ void test_timer_time_accumulation_os_ticker()
p_timer->start();

/* Wait 10 ms. */
wait_ms(10);
busy_wait_ms(10);

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

/* ------ */

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

/* Wait 20 ms. */
wait_ms(20);
busy_wait_ms(20);

/* Stop the timer. */
p_timer->stop();
Expand All @@ -456,7 +470,7 @@ void test_timer_time_accumulation_os_ticker()
p_timer->start();

/* Wait 30 ms. */
wait_ms(30);
busy_wait_ms(30);

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

/* ------ */

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

/* Wait 1 sec. */
wait_ms(1000);
busy_wait_ms(1000);

/* Stop the timer. */
p_timer->stop();
Expand Down Expand Up @@ -507,7 +521,7 @@ void test_timer_reset_os_ticker()
p_timer->start();

/* Wait 10 ms. */
wait_ms(10);
busy_wait_ms(10);

/* Stop the timer. */
p_timer->stop();
Expand All @@ -525,7 +539,7 @@ void test_timer_reset_os_ticker()
p_timer->start();

/* Wait 20 ms. */
wait_ms(20);
busy_wait_ms(20);

/* Stop the timer. */
p_timer->stop();
Expand Down Expand Up @@ -603,13 +617,13 @@ void test_timer_start_started_timer_os_ticker()
p_timer->start();

/* Wait 10 ms. */
wait_ms(10);
busy_wait_ms(10);

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

/* Wait 20 ms. */
wait_ms(20);
busy_wait_ms(20);

/* Stop the timer. */
p_timer->stop();
Expand Down Expand Up @@ -673,7 +687,7 @@ void test_timer_float_operator_os_ticker()
p_timer->start();

/* Wait 10 ms. */
wait_ms(10);
busy_wait_ms(10);

/* Stop the timer. */
p_timer->stop();
Expand Down Expand Up @@ -728,7 +742,7 @@ void test_timer_time_measurement()
p_timer->start();

/* Wait <wait_val_us> us. */
wait_us(wait_val_us);
busy_wait_us(wait_val_us);

/* Stop the timer. */
p_timer->stop();
Expand Down