Skip to content

Commit 8acfcfb

Browse files
authored
Merge pull request #5096 from c1728p9/remove_direct_ticker_use
Remove direct use of us and lp ticker from tests
2 parents 181d7bc + 47b0f31 commit 8acfcfb

File tree

6 files changed

+55
-46
lines changed

6 files changed

+55
-46
lines changed

TESTS/mbed_drivers/lp_timeout/main.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "greentea-client/test_env.h"
2424

2525
#include "mbed.h"
26-
#include "us_ticker_api.h"
2726

2827
using namespace utest::v1;
2928

@@ -42,6 +41,7 @@ void cb_done() {
4241
void lp_timeout_1s_deepsleep(void)
4342
{
4443
complete = false;
44+
LowPowerTimer timer;
4545

4646
/*
4747
* Since deepsleep() may shut down the UART peripheral, we wait for 10ms
@@ -54,48 +54,47 @@ void lp_timeout_1s_deepsleep(void)
5454
wait_ms(10);
5555

5656
/*
57-
* We use here lp_ticker_read() instead of us_ticker_read() for start and
57+
* We use here the low power timer instead of microsecond timer for start and
5858
* end because the microseconds timer might be disable during deepsleep.
5959
*/
60-
timestamp_t start = lp_ticker_read();
60+
timer.start();
6161
lpt.attach(&cb_done, 1);
6262
deepsleep();
6363
while (!complete);
64-
timestamp_t end = lp_ticker_read();
6564

6665
/* It takes longer to wake up from deep sleep */
67-
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
66+
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, timer.read_us());
6867
TEST_ASSERT_TRUE(complete);
6968
}
7069

7170
void lp_timeout_1s_sleep(void)
7271
{
7372
complete = false;
73+
Timer timer;
74+
timer.start();
7475

7576
sleep_manager_lock_deep_sleep();
76-
timestamp_t start = us_ticker_read();
7777
lpt.attach(&cb_done, 1);
7878
sleep();
7979
while (!complete);
80-
timestamp_t end = us_ticker_read();
8180
sleep_manager_unlock_deep_sleep();
8281

83-
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
82+
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, timer.read_us());
8483
TEST_ASSERT_TRUE(complete);
8584
}
8685
#endif /* DEVICE_SLEEP */
8786

8887
void lp_timeout_us(uint32_t delay_us, uint32_t tolerance)
8988
{
9089
complete = false;
90+
Timer timer;
91+
timer.start();
9192

92-
timestamp_t start = us_ticker_read();
9393
lpt.attach_us(&cb_done, delay_us);
9494
while (!complete);
95-
timestamp_t end = us_ticker_read();
9695

9796
/* Using RTC which is less accurate */
98-
TEST_ASSERT_UINT32_WITHIN(tolerance, delay_us, end - start);
97+
TEST_ASSERT_UINT32_WITHIN(tolerance, delay_us, timer.read_us());
9998
TEST_ASSERT_TRUE(complete);
10099
}
101100

TESTS/mbed_hal/lp_ticker/main.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,24 @@
2323
#include "greentea-client/test_env.h"
2424

2525
#include "mbed.h"
26-
#include "us_ticker_api.h"
2726
#include "lp_ticker_api.h"
28-
#include "TimerEvent.h"
2927

3028
using namespace utest::v1;
3129

3230
static volatile bool complete;
33-
static volatile timestamp_t complete_timestamp;
31+
static volatile timestamp_t complete_time;
3432
static ticker_event_t delay_event;
3533
static const ticker_data_t *lp_ticker_data = get_lp_ticker_data();
36-
34+
static Timer timer;
35+
static LowPowerTimer lp_timer;
3736

3837
/* Timeouts are quite arbitrary due to large number of boards with varying level of accuracy */
3938
#define LONG_TIMEOUT (100000)
4039
#define SHORT_TIMEOUT (600)
4140

4241
void cb_done(uint32_t id) {
4342
if ((uint32_t)&delay_event == id) {
44-
complete_timestamp = us_ticker_read();
43+
complete_time = timer.read_us();
4544
complete = true;
4645
} else {
4746
// Normal ticker handling
@@ -51,7 +50,7 @@ void cb_done(uint32_t id) {
5150

5251
void cb_done_deepsleep(uint32_t id) {
5352
if ((uint32_t)&delay_event == id) {
54-
complete_timestamp = lp_ticker_read();
53+
complete_time = lp_timer.read_us();
5554
complete = true;
5655
} else {
5756
// Normal ticker handling
@@ -66,14 +65,15 @@ void lp_ticker_delay_us(uint32_t delay_us, uint32_t tolerance)
6665

6766
ticker_set_handler(lp_ticker_data, cb_done);
6867
ticker_remove_event(lp_ticker_data, &delay_event);
69-
delay_ts = lp_ticker_read() + delay_us;
68+
delay_ts = ticker_read(lp_ticker_data) + delay_us;
7069

71-
timestamp_t start = us_ticker_read();
70+
timer.reset();
71+
timer.start();
7272
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
7373
while (!complete);
74-
timestamp_t end = complete_timestamp;
74+
timer.stop();
7575

76-
TEST_ASSERT_UINT32_WITHIN(tolerance, delay_us, end - start);
76+
TEST_ASSERT_UINT32_WITHIN(tolerance, delay_us, complete_time);
7777
TEST_ASSERT_TRUE(complete);
7878
}
7979

@@ -95,19 +95,20 @@ void lp_ticker_1s_deepsleep()
9595

9696
ticker_set_handler(lp_ticker_data, cb_done_deepsleep);
9797
ticker_remove_event(lp_ticker_data, &delay_event);
98-
delay_ts = lp_ticker_read() + 1000000;
98+
delay_ts = ticker_read(lp_ticker_data) + 1000000;
9999

100100
/*
101-
* We use here lp_ticker_read() instead of us_ticker_read() for start and
101+
* We use here the low power timer instead of microsecond timer for start and
102102
* end because the microseconds timer might be disable during deepsleep.
103103
*/
104-
timestamp_t start = lp_ticker_read();
104+
lp_timer.reset();
105+
lp_timer.start();
105106
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
106107
deepsleep();
107108
while (!complete);
108-
timestamp_t end = complete_timestamp;
109+
lp_timer.stop();
109110

110-
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
111+
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, complete_time);
111112
TEST_ASSERT_TRUE(complete);
112113
}
113114

@@ -118,17 +119,18 @@ void lp_ticker_1s_sleep()
118119

119120
ticker_set_handler(lp_ticker_data, cb_done);
120121
ticker_remove_event(lp_ticker_data, &delay_event);
121-
delay_ts = lp_ticker_read() + 1000000;
122+
delay_ts = ticker_read(lp_ticker_data) + 1000000;
122123

123124
sleep_manager_lock_deep_sleep();
124-
timestamp_t start = us_ticker_read();
125+
timer.reset();
126+
timer.start();
125127
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
126128
sleep();
127129
while (!complete);
128-
timestamp_t end = complete_timestamp;
130+
timer.stop();
129131
sleep_manager_unlock_deep_sleep();
130132

131-
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
133+
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, complete_time);
132134
TEST_ASSERT_TRUE(complete);
133135
}
134136
#endif /* DEVICE_SLEEP */

TESTS/mbedmicro-rtos-mbed/mutex/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,12 @@ void test_dual_thread_lock_trylock_thread(Mutex *mutex)
191191

192192
void test_dual_thread_lock_lock_thread(Mutex *mutex)
193193
{
194-
uint32_t start = us_ticker_read();
194+
Timer timer;
195+
timer.start();
195196

196197
osStatus stat = mutex->lock(TEST_DELAY);
197198
TEST_ASSERT_EQUAL(osErrorTimeout, stat);
198-
TEST_ASSERT_UINT32_WITHIN(5000, TEST_DELAY*1000, us_ticker_read() - start);
199+
TEST_ASSERT_UINT32_WITHIN(5000, TEST_DELAY*1000, timer.read_us());
199200
}
200201

201202
/** Test dual thread lock

TESTS/mbedmicro-rtos-mbed/queue/main.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,12 @@ void test_get_empty_no_timeout()
135135
void test_get_empty_timeout()
136136
{
137137
Queue<uint32_t, 1> q;
138-
uint32_t start = us_ticker_read();
138+
Timer timer;
139+
timer.start();
139140

140141
osEvent evt = q.get(50);
141142
TEST_ASSERT_EQUAL(osEventTimeout, evt.status);
142-
TEST_ASSERT_UINT32_WITHIN(5000, 50000, us_ticker_read() - start);
143+
TEST_ASSERT_UINT32_WITHIN(5000, 50000, timer.read_us());
143144
}
144145

145146
/** Test get empty wait forever
@@ -157,12 +158,13 @@ void test_get_empty_wait_forever()
157158

158159
t.start(callback(thread_put_uint_msg<TEST_TIMEOUT>, &q));
159160

160-
uint32_t start = us_ticker_read();
161+
Timer timer;
162+
timer.start();
161163

162164
osEvent evt = q.get();
163165
TEST_ASSERT_EQUAL(osEventMessage, evt.status);
164166
TEST_ASSERT_EQUAL(TEST_UINT_MSG, evt.value.v);
165-
TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, us_ticker_read() - start);
167+
TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, timer.read_us());
166168
}
167169

168170
/** Test put full no timeout
@@ -195,11 +197,12 @@ void test_put_full_timeout()
195197
osStatus stat = q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT);
196198
TEST_ASSERT_EQUAL(osOK, stat);
197199

198-
uint32_t start = us_ticker_read();
200+
Timer timer;
201+
timer.start();
199202

200203
stat = q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT);
201204
TEST_ASSERT_EQUAL(osErrorTimeout, stat);
202-
TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, us_ticker_read() - start);
205+
TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, timer.read_us());
203206
}
204207

205208
/** Test put full wait forever
@@ -220,10 +223,11 @@ void test_put_full_waitforever()
220223
osStatus stat = q.put((uint32_t*) TEST_UINT_MSG);
221224
TEST_ASSERT_EQUAL(osOK, stat);
222225

223-
uint32_t start = us_ticker_read();
226+
Timer timer;
227+
timer.start();
224228
stat = q.put((uint32_t*) TEST_UINT_MSG, osWaitForever);
225229
TEST_ASSERT_EQUAL(osOK, stat);
226-
TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, us_ticker_read() - start);
230+
TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, timer.read_us());
227231

228232
t.join();
229233
}

TESTS/mbedmicro-rtos-mbed/semaphore/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,16 @@ void test_timeout()
152152
Semaphore sem(0);
153153
osStatus res;
154154

155-
uint32_t start = us_ticker_read();
155+
Timer timer;
156+
timer.start();
156157
res = t.start(callback(timeout_thread, &sem));
157158
TEST_ASSERT_EQUAL(osOK, res);
158159
Thread::wait(SHORT_WAIT);
159160

160161
TEST_ASSERT_EQUAL(Thread::WaitingSemaphore, t.get_state());
161162

162163
t.join();
163-
TEST_ASSERT_UINT32_WITHIN(5000, 30000, us_ticker_read() - start);
164+
TEST_ASSERT_UINT32_WITHIN(5000, 30000, timer.read_us());
164165
}
165166

166167
/** Test no timeouts
@@ -180,12 +181,13 @@ void test_no_timeout()
180181
{
181182
Semaphore sem(T);
182183

183-
uint32_t start = us_ticker_read();
184+
Timer timer;
185+
timer.start();
184186

185187
int32_t cnt = sem.wait(0);
186188
TEST_ASSERT_EQUAL(T, cnt);
187189

188-
TEST_ASSERT_UINT32_WITHIN(5000, 0, us_ticker_read() - start);
190+
TEST_ASSERT_UINT32_WITHIN(5000, 0, timer.read_us());
189191
}
190192

191193
/** Test multiple tokens wait

TESTS/mbedmicro-rtos-mbed/threads/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,12 @@ void test_thread_stack_info() {
377377
then the thread sleeps for given amount of time
378378
*/
379379
void test_thread_wait() {
380-
uint32_t start = us_ticker_read();
380+
Timer timer;
381+
timer.start();
381382

382383
Thread::wait(150);
383384

384-
TEST_ASSERT_UINT32_WITHIN(50000, 150000, us_ticker_read() - start);
385+
TEST_ASSERT_UINT32_WITHIN(50000, 150000, timer.read_us());
385386
}
386387

387388
/** Testing thread name

0 commit comments

Comments
 (0)