Skip to content

tests-mbed_drivers-lp_timer: change delay method #7471

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
Jul 13, 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
38 changes: 25 additions & 13 deletions TESTS/mbed_drivers/lp_timer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ extern uint32_t SystemCoreClock;
#define DELTA_MS(delay_ms) (1 + ((delay_ms) * US_PER_MSEC / 20 / US_PER_MSEC))
#define DELTA_S(delay_ms) (0.000500f + (((float)(delay_ms)) / MSEC_PER_SEC / 20))

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);
}

/* This test verifies if low power timer is stopped after
* creation.
*
Expand All @@ -74,7 +86,7 @@ void test_lptimer_creation()

/* 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, lp_timer.read());
Expand Down Expand Up @@ -102,7 +114,7 @@ void test_lptimer_time_accumulation()
lp_timer.start();

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

/* Stop the timer. */
lp_timer.stop();
Expand All @@ -116,15 +128,15 @@ void test_lptimer_time_accumulation()
/* 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. */
lp_timer.start();

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

/* Stop the timer. */
lp_timer.stop();
Expand All @@ -145,7 +157,7 @@ void test_lptimer_time_accumulation()
lp_timer.start();

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

/* Stop the timer. */
lp_timer.stop();
Expand All @@ -159,15 +171,15 @@ void test_lptimer_time_accumulation()
/* 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. */
lp_timer.start();

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

/* Stop the timer. */
lp_timer.stop();
Expand Down Expand Up @@ -196,7 +208,7 @@ void test_lptimer_reset()
lp_timer.start();

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

/* Stop the timer. */
lp_timer.stop();
Expand All @@ -214,7 +226,7 @@ void test_lptimer_reset()
lp_timer.start();

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

/* Stop the timer. */
lp_timer.stop();
Expand All @@ -241,13 +253,13 @@ void test_lptimer_start_started_timer()
lp_timer.start();

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

/* Now start timer again. */
lp_timer.start();

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

/* Stop the timer. */
lp_timer.stop();
Expand All @@ -274,7 +286,7 @@ void test_lptimer_float_operator()
lp_timer.start();

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

/* Stop the timer. */
lp_timer.stop();
Expand Down Expand Up @@ -302,7 +314,7 @@ void test_lptimer_time_measurement()
lp_timer.start();

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

/* Stop the timer. */
lp_timer.stop();
Expand Down