61
61
* are empty. However, it is possible to determine the time required for the
62
62
* buffers to flush.
63
63
*
64
- * Take NUMAKER_PFM_NUC472 as an example:
65
- * The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600,
66
- * flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13 .3 ms.
67
- * To be on the safe side, set the wait time to 20 ms.
64
+ * Assuming the biggest Tx FIFO of 128 bytes ( as for CY8CPROTO_062_4343W)
65
+ * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
66
+ * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133 .3 ms.
67
+ * To be on the safe side, set the wait time to 150 ms.
68
68
*/
69
- #define SERIAL_FLUSH_TIME_MS 20
69
+ #define SERIAL_FLUSH_TIME_MS 150
70
70
71
71
#define TIMEOUT_US (1000 * (TIMEOUT_MS))
72
72
#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS))
@@ -111,10 +111,11 @@ void test_simple_reset()
111
111
// Phase 1. -- run the test code.
112
112
// Init the watchdog and wait for a device reset.
113
113
watchdog_config_t config = { TIMEOUT_MS };
114
- if (send_reset_notification (¤t_case, 2 * TIMEOUT_MS) == false ) {
114
+ if (send_reset_notification (¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS ) == false ) {
115
115
TEST_ASSERT_MESSAGE (0 , " Dev-host communication error." );
116
116
return ;
117
117
}
118
+ wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
118
119
TEST_ASSERT_EQUAL (WATCHDOG_STATUS_OK, hal_watchdog_init (&config));
119
120
// Watchdog should fire before twice the timeout value.
120
121
wait_us (2 * TIMEOUT_US); // Device reset expected.
@@ -138,10 +139,11 @@ void test_sleep_reset()
138
139
139
140
// Phase 1. -- run the test code.
140
141
watchdog_config_t config = { TIMEOUT_MS };
141
- if (send_reset_notification (¤t_case, 2 * TIMEOUT_MS) == false ) {
142
+ if (send_reset_notification (¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS ) == false ) {
142
143
TEST_ASSERT_MESSAGE (0 , " Dev-host communication error." );
143
144
return ;
144
145
}
146
+ wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
145
147
TEST_ASSERT_EQUAL (WATCHDOG_STATUS_OK, hal_watchdog_init (&config));
146
148
sleep_manager_lock_deep_sleep ();
147
149
if (sleep_manager_can_deep_sleep ()) {
@@ -176,6 +178,7 @@ void test_deepsleep_reset()
176
178
return ;
177
179
}
178
180
wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
181
+ wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
179
182
TEST_ASSERT_EQUAL (WATCHDOG_STATUS_OK, hal_watchdog_init (&config));
180
183
if (!sleep_manager_can_deep_sleep ()) {
181
184
TEST_ASSERT_MESSAGE (0 , " Deepsleep should be allowed." );
@@ -221,10 +224,11 @@ void test_restart_reset()
221
224
// The watchdog should trigger before twice the timeout value.
222
225
wait_us (TIMEOUT_US / 2 + TIMEOUT_US);
223
226
224
- if (send_reset_notification (¤t_case, 2 * TIMEOUT_MS) == false ) {
227
+ if (send_reset_notification (¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS ) == false ) {
225
228
TEST_ASSERT_MESSAGE (0 , " Dev-host communication error." );
226
229
return ;
227
230
}
231
+ wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
228
232
TEST_ASSERT_EQUAL (WATCHDOG_STATUS_OK, hal_watchdog_init (&config));
229
233
// Watchdog should fire before twice the timeout value.
230
234
wait_us (2 * TIMEOUT_US); // Device reset expected.
@@ -254,10 +258,11 @@ void test_kick_reset()
254
258
wait_us (TIMEOUT_US - KICK_ADVANCE_US);
255
259
hal_watchdog_kick ();
256
260
}
257
- if (send_reset_notification (¤t_case, 2 * TIMEOUT_MS) == false ) {
261
+ if (send_reset_notification (¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS ) == false ) {
258
262
TEST_ASSERT_MESSAGE (0 , " Dev-host communication error." );
259
263
return ;
260
264
}
265
+ wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
261
266
// Watchdog should fire before twice the timeout value.
262
267
wait_us (2 * TIMEOUT_US); // Device reset expected.
263
268
0 commit comments