47
47
48
48
using namespace utest ::v1;
49
49
50
+ static char info[512 ] = {0 };
51
+
50
52
/* The following ticker frequencies are possible:
51
53
* high frequency ticker: 250 KHz (1 tick per 4 us) - 8 Mhz (1 tick per 1/8 us)
52
54
* low power ticker: 8 KHz (1 tick per 125 us) - 64 KHz (1 tick per ~15.6 us)
@@ -140,14 +142,20 @@ void sleep_usticker_test()
140
142
141
143
const ticker_irq_handler_type us_ticker_irq_handler_org = set_us_ticker_irq_handler (us_ticker_isr);
142
144
145
+ /* Give some time Green Tea to finish UART transmission before entering
146
+ * sleep mode.
147
+ */
148
+ busy_wait_ms (SERIAL_FLUSH_TIME_MS);
149
+
143
150
/* Test only sleep functionality. */
144
151
sleep_manager_lock_deep_sleep ();
145
152
TEST_ASSERT_FALSE_MESSAGE (sleep_manager_can_deep_sleep (), " deep sleep should be locked" );
146
153
147
154
/* Testing wake-up time 10 us. */
148
155
for (timestamp_t i = 100 ; i < 1000 ; i += 100 ) {
149
156
/* note: us_ticker_read() operates on ticks. */
150
- const timestamp_t next_match_timestamp = overflow_protect (us_ticker_read () + us_to_ticks (i, ticker_freq),
157
+ const timestamp_t start_timestamp = us_ticker_read ();
158
+ const timestamp_t next_match_timestamp = overflow_protect (start_timestamp + us_to_ticks (i, ticker_freq),
151
159
ticker_width);
152
160
153
161
us_ticker_set_interrupt (next_match_timestamp);
@@ -156,9 +164,11 @@ void sleep_usticker_test()
156
164
157
165
const unsigned int wakeup_timestamp = us_ticker_read ();
158
166
159
- TEST_ASSERT (
160
- compare_timestamps (us_to_ticks (sleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp,
161
- wakeup_timestamp));
167
+ sprintf (info, " Delta ticks: %u, Ticker width: %u, Expected wake up tick: %d, Actual wake up tick: %d, delay ticks: %d, wake up after ticks: %d" ,
168
+ us_to_ticks (sleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp, wakeup_timestamp, us_to_ticks (i, ticker_freq) , wakeup_timestamp - start_timestamp);
169
+
170
+ TEST_ASSERT_MESSAGE (compare_timestamps (us_to_ticks (sleep_mode_delta_us, ticker_freq),
171
+ ticker_width, next_match_timestamp, wakeup_timestamp), info);
162
172
}
163
173
164
174
set_us_ticker_irq_handler (us_ticker_irq_handler_org);
@@ -189,15 +199,20 @@ void deepsleep_lpticker_test()
189
199
/* Testing wake-up time 10 ms. */
190
200
for (timestamp_t i = 20000 ; i < 200000 ; i += 20000 ) {
191
201
/* note: lp_ticker_read() operates on ticks. */
192
- const timestamp_t next_match_timestamp = overflow_protect (lp_ticker_read () + us_to_ticks (i, ticker_freq), ticker_width);
202
+ const timestamp_t start_timestamp = lp_ticker_read ();
203
+ const timestamp_t next_match_timestamp = overflow_protect (start_timestamp + us_to_ticks (i, ticker_freq), ticker_width);
193
204
194
205
lp_ticker_set_interrupt (next_match_timestamp);
195
206
196
207
sleep ();
197
208
198
209
const timestamp_t wakeup_timestamp = lp_ticker_read ();
199
210
200
- TEST_ASSERT (compare_timestamps (us_to_ticks (deepsleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp, wakeup_timestamp));
211
+ sprintf (info, " Delta ticks: %u, Ticker width: %u, Expected wake up tick: %d, Actual wake up tick: %d, delay ticks: %d, wake up after ticks: %d" ,
212
+ us_to_ticks (deepsleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp, wakeup_timestamp, us_to_ticks (i, ticker_freq) , wakeup_timestamp - start_timestamp);
213
+
214
+ TEST_ASSERT_MESSAGE (compare_timestamps (us_to_ticks (deepsleep_mode_delta_us, ticker_freq), ticker_width,
215
+ next_match_timestamp, wakeup_timestamp), info);
201
216
}
202
217
203
218
set_lp_ticker_irq_handler (lp_ticker_irq_handler_org);
@@ -240,8 +255,12 @@ void deepsleep_high_speed_clocks_turned_off_test()
240
255
241
256
TEST_ASSERT_UINT32_WITHIN (1000 , 0 , ticks_to_us (us_ticks_diff, us_ticker_freq));
242
257
258
+ sprintf (info, " Delta ticks: %u, Ticker width: %u, Expected wake up tick: %d, Actual wake up tick: %d" ,
259
+ us_to_ticks (deepsleep_mode_delta_us, lp_ticker_freq), lp_ticker_width, wakeup_time, lp_ticks_after_sleep);
260
+
243
261
/* Check if we have woken-up after expected time. */
244
- TEST_ASSERT (compare_timestamps (us_to_ticks (deepsleep_mode_delta_us, lp_ticker_freq), lp_ticker_width, wakeup_time, lp_ticks_after_sleep));
262
+ TEST_ASSERT_MESSAGE (compare_timestamps (us_to_ticks (deepsleep_mode_delta_us, lp_ticker_freq), lp_ticker_width,
263
+ wakeup_time, lp_ticks_after_sleep), info);
245
264
}
246
265
247
266
#endif
0 commit comments