Skip to content

Commit fa0cd20

Browse files
authored
Merge pull request #4094 from pan-/fix_hal_ticker
[HAL] Add support for 64 bit us timestamp
2 parents 9381a7a + 045b026 commit fa0cd20

File tree

13 files changed

+2518
-201
lines changed

13 files changed

+2518
-201
lines changed

TESTS/mbed_hal/lp_ticker/main.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929
using namespace utest::v1;
3030

31-
volatile static bool complete;
31+
static volatile bool complete;
32+
static volatile timestamp_t complete_timestamp;
3233
static ticker_event_t delay_event;
3334
static const ticker_data_t *lp_ticker_data = get_lp_ticker_data();
3435

@@ -38,6 +39,12 @@ static const ticker_data_t *lp_ticker_data = get_lp_ticker_data();
3839
#define SHORT_TIMEOUT (600)
3940

4041
void cb_done(uint32_t id) {
42+
complete_timestamp = us_ticker_read();
43+
complete = true;
44+
}
45+
46+
void cb_done_deepsleep(uint32_t id) {
47+
complete_timestamp = lp_ticker_read();
4148
complete = true;
4249
}
4350

@@ -53,7 +60,7 @@ void lp_ticker_delay_us(uint32_t delay_us, uint32_t tolerance)
5360
timestamp_t start = us_ticker_read();
5461
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
5562
while (!complete);
56-
timestamp_t end = us_ticker_read();
63+
timestamp_t end = complete_timestamp;
5764

5865
TEST_ASSERT_UINT32_WITHIN(tolerance, delay_us, end - start);
5966
TEST_ASSERT_TRUE(complete);
@@ -75,7 +82,7 @@ void lp_ticker_1s_deepsleep()
7582
*/
7683
wait_ms(10);
7784

78-
ticker_set_handler(lp_ticker_data, cb_done);
85+
ticker_set_handler(lp_ticker_data, cb_done_deepsleep);
7986
ticker_remove_event(lp_ticker_data, &delay_event);
8087
delay_ts = lp_ticker_read() + 1000000;
8188

@@ -87,7 +94,7 @@ void lp_ticker_1s_deepsleep()
8794
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
8895
deepsleep();
8996
while (!complete);
90-
timestamp_t end = lp_ticker_read();
97+
timestamp_t end = complete_timestamp;
9198

9299
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
93100
TEST_ASSERT_TRUE(complete);
@@ -106,7 +113,7 @@ void lp_ticker_1s_sleep()
106113
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
107114
sleep();
108115
while (!complete);
109-
timestamp_t end = us_ticker_read();
116+
timestamp_t end = complete_timestamp;
110117

111118
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
112119
TEST_ASSERT_TRUE(complete);

0 commit comments

Comments
 (0)