Skip to content

Commit 981691f

Browse files
authored
Merge pull request #12519 from mprse/sleepmanaget_test_fix
tests-mbed_hal-sleep_manager: fix counter wraparound handling
2 parents 9fc8ac2 + 42a9cc1 commit 981691f

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

TESTS/mbed_hal/sleep_manager/main.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void test_sleep_auto()
141141
const ticker_info_t *lp_ticker_info = get_lp_ticker_data()->interface->get_info();
142142
const unsigned lp_ticker_mask = ((1 << lp_ticker_info->bits) - 1);
143143
const ticker_irq_handler_type lp_ticker_irq_handler_org = set_lp_ticker_irq_handler(lp_ticker_isr);
144-
us_timestamp_t us_ts1, us_ts2, lp_ts1, lp_ts2, us_diff1, us_diff2, lp_diff1, lp_diff2;
144+
uint32_t us_ts1, us_ts2, lp_ts1, lp_ts2, us_diff1, us_diff2, lp_diff1, lp_diff2;
145145

146146
/* Let's avoid the Lp ticker wrap-around case */
147147
wraparound_lp_protect();
@@ -155,14 +155,16 @@ void test_sleep_auto()
155155

156156
sleep_manager_lock_deep_sleep();
157157

158-
us_ts1 = ticks_to_us(us_ticker_read(), us_ticker_info->frequency);
159-
lp_ts1 = ticks_to_us(lp_ticker_read(), lp_ticker_info->frequency);
158+
us_ts1 = us_ticker_read();
159+
lp_ts1 = lp_ticker_read();
160160

161161
sleep_manager_sleep_auto();
162-
us_ts2 = ticks_to_us(us_ticker_read(), us_ticker_info->frequency);
163-
us_diff1 = (us_ts1 <= us_ts2) ? (us_ts2 - us_ts1) : (us_ticker_mask - us_ts1 + us_ts2 + 1);
164-
lp_ts2 = ticks_to_us(lp_ticker_read(), lp_ticker_info->frequency);
165-
lp_diff1 = (lp_ts1 <= lp_ts2) ? (lp_ts2 - lp_ts1) : (lp_ticker_mask - lp_ts1 + lp_ts2 + 1);
162+
163+
us_ts2 = us_ticker_read();
164+
lp_ts2 = lp_ticker_read();
165+
166+
us_diff1 = ticks_to_us((us_ts1 <= us_ts2) ? (us_ts2 - us_ts1) : (us_ticker_mask - us_ts1 + us_ts2 + 1), us_ticker_info->frequency);
167+
lp_diff1 = ticks_to_us((lp_ts1 <= lp_ts2) ? (lp_ts2 - lp_ts1) : (lp_ticker_mask - lp_ts1 + lp_ts2 + 1), lp_ticker_info->frequency);
166168

167169
// Deep sleep locked -- ordinary sleep mode used:
168170
// * us_ticker powered ON,
@@ -190,15 +192,16 @@ void test_sleep_auto()
190192
* set and forbid deep_sleep during that period. Let this period pass */
191193
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep_test_check());
192194

193-
us_ts1 = ticks_to_us(us_ticker_read(), us_ticker_info->frequency);
194-
lp_ts1 = ticks_to_us(lp_ticker_read(), lp_ticker_info->frequency);
195+
us_ts1 = us_ticker_read();
196+
lp_ts1 = lp_ticker_read();
195197

196198
sleep_manager_sleep_auto();
197199

198-
us_ts2 = ticks_to_us(us_ticker_read(), us_ticker_info->frequency);
199-
us_diff2 = (us_ts1 <= us_ts2) ? (us_ts2 - us_ts1) : (us_ticker_mask - us_ts1 + us_ts2 + 1);
200-
lp_ts2 = ticks_to_us(lp_ticker_read(), lp_ticker_info->frequency);
201-
lp_diff2 = (lp_ts1 <= lp_ts2) ? (lp_ts2 - lp_ts1) : (lp_ticker_mask - lp_ts1 + lp_ts2 + 1);
200+
us_ts2 = us_ticker_read();
201+
lp_ts2 = lp_ticker_read();
202+
203+
us_diff2 = ticks_to_us((us_ts1 <= us_ts2) ? (us_ts2 - us_ts1) : (us_ticker_mask - us_ts1 + us_ts2 + 1), us_ticker_info->frequency);
204+
lp_diff2 = ticks_to_us((lp_ts1 <= lp_ts2) ? (lp_ts2 - lp_ts1) : (lp_ticker_mask - lp_ts1 + lp_ts2 + 1), lp_ticker_info->frequency);
202205

203206
// Deep sleep unlocked -- deep sleep mode used:
204207
// * us_ticker powered OFF,

0 commit comments

Comments
 (0)