Skip to content

Commit 1cbfa00

Browse files
author
Cruz Monrreal
authored
Merge pull request #7471 from mprse/lp_timer_test_fix
tests-mbed_drivers-lp_timer: change delay method
2 parents 1145d6b + b1b4f6e commit 1cbfa00

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

TESTS/mbed_drivers/lp_timer/main.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ extern uint32_t SystemCoreClock;
5555
#define DELTA_MS(delay_ms) (1 + ((delay_ms) * US_PER_MSEC / 20 / US_PER_MSEC))
5656
#define DELTA_S(delay_ms) (0.000500f + (((float)(delay_ms)) / MSEC_PER_SEC / 20))
5757

58+
void busy_wait_us(int us)
59+
{
60+
const ticker_data_t *const ticker = get_us_ticker_data();
61+
uint32_t start = ticker_read(ticker);
62+
while ((ticker_read(ticker) - start) < (uint32_t)us);
63+
}
64+
65+
void busy_wait_ms(int ms)
66+
{
67+
busy_wait_us(ms * US_PER_MSEC);
68+
}
69+
5870
/* This test verifies if low power timer is stopped after
5971
* creation.
6072
*
@@ -74,7 +86,7 @@ void test_lptimer_creation()
7486

7587
/* Wait 10 ms.
7688
* After that operation timer read routines should still return 0. */
77-
wait_ms(10);
89+
busy_wait_ms(10);
7890

7991
/* Check results. */
8092
TEST_ASSERT_EQUAL_FLOAT(0, lp_timer.read());
@@ -102,7 +114,7 @@ void test_lptimer_time_accumulation()
102114
lp_timer.start();
103115

104116
/* Wait 10 ms. */
105-
wait_ms(10);
117+
busy_wait_ms(10);
106118

107119
/* Stop the timer. */
108120
lp_timer.stop();
@@ -116,15 +128,15 @@ void test_lptimer_time_accumulation()
116128
/* Wait 50 ms - this is done to show that time elapsed when
117129
* the timer is stopped does not have influence on the
118130
* timer counted time. */
119-
wait_ms(50);
131+
busy_wait_ms(50);
120132

121133
/* ------ */
122134

123135
/* Start the timer. */
124136
lp_timer.start();
125137

126138
/* Wait 20 ms. */
127-
wait_ms(20);
139+
busy_wait_ms(20);
128140

129141
/* Stop the timer. */
130142
lp_timer.stop();
@@ -145,7 +157,7 @@ void test_lptimer_time_accumulation()
145157
lp_timer.start();
146158

147159
/* Wait 30 ms. */
148-
wait_ms(30);
160+
busy_wait_ms(30);
149161

150162
/* Stop the timer. */
151163
lp_timer.stop();
@@ -159,15 +171,15 @@ void test_lptimer_time_accumulation()
159171
/* Wait 50 ms - this is done to show that time elapsed when
160172
* the timer is stopped does not have influence on the
161173
* timer time. */
162-
wait_ms(50);
174+
busy_wait_ms(50);
163175

164176
/* ------ */
165177

166178
/* Start the timer. */
167179
lp_timer.start();
168180

169181
/* Wait 1 sec. */
170-
wait_ms(1000);
182+
busy_wait_ms(1000);
171183

172184
/* Stop the timer. */
173185
lp_timer.stop();
@@ -196,7 +208,7 @@ void test_lptimer_reset()
196208
lp_timer.start();
197209

198210
/* Wait 10 ms. */
199-
wait_ms(10);
211+
busy_wait_ms(10);
200212

201213
/* Stop the timer. */
202214
lp_timer.stop();
@@ -214,7 +226,7 @@ void test_lptimer_reset()
214226
lp_timer.start();
215227

216228
/* Wait 20 ms. */
217-
wait_ms(20);
229+
busy_wait_ms(20);
218230

219231
/* Stop the timer. */
220232
lp_timer.stop();
@@ -241,13 +253,13 @@ void test_lptimer_start_started_timer()
241253
lp_timer.start();
242254

243255
/* Wait 10 ms. */
244-
wait_ms(10);
256+
busy_wait_ms(10);
245257

246258
/* Now start timer again. */
247259
lp_timer.start();
248260

249261
/* Wait 20 ms. */
250-
wait_ms(20);
262+
busy_wait_ms(20);
251263

252264
/* Stop the timer. */
253265
lp_timer.stop();
@@ -274,7 +286,7 @@ void test_lptimer_float_operator()
274286
lp_timer.start();
275287

276288
/* Wait 10 ms. */
277-
wait_ms(10);
289+
busy_wait_ms(10);
278290

279291
/* Stop the timer. */
280292
lp_timer.stop();
@@ -302,7 +314,7 @@ void test_lptimer_time_measurement()
302314
lp_timer.start();
303315

304316
/* Wait <wait_val_us> us. */
305-
wait_us(wait_val_us);
317+
busy_wait_us(wait_val_us);
306318

307319
/* Stop the timer. */
308320
lp_timer.stop();

0 commit comments

Comments
 (0)