6161 * are empty. However, it is possible to determine the time required for the
6262 * buffers to flush.
6363 *
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.
6868 */
69- #define SERIAL_FLUSH_TIME_MS 20
69+ #define SERIAL_FLUSH_TIME_MS 150
7070
7171#define TIMEOUT_US (1000 * (TIMEOUT_MS))
7272#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS))
@@ -111,10 +111,11 @@ void test_simple_reset()
111111 // Phase 1. -- run the test code.
112112 // Init the watchdog and wait for a device reset.
113113 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 ) {
115115 TEST_ASSERT_MESSAGE (0 , " Dev-host communication error." );
116116 return ;
117117 }
118+ wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
118119 TEST_ASSERT_EQUAL (WATCHDOG_STATUS_OK, hal_watchdog_init (&config));
119120 // Watchdog should fire before twice the timeout value.
120121 wait_us (2 * TIMEOUT_US); // Device reset expected.
@@ -138,10 +139,11 @@ void test_sleep_reset()
138139
139140 // Phase 1. -- run the test code.
140141 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 ) {
142143 TEST_ASSERT_MESSAGE (0 , " Dev-host communication error." );
143144 return ;
144145 }
146+ wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
145147 TEST_ASSERT_EQUAL (WATCHDOG_STATUS_OK, hal_watchdog_init (&config));
146148 sleep_manager_lock_deep_sleep ();
147149 if (sleep_manager_can_deep_sleep ()) {
@@ -176,6 +178,7 @@ void test_deepsleep_reset()
176178 return ;
177179 }
178180 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.
179182 TEST_ASSERT_EQUAL (WATCHDOG_STATUS_OK, hal_watchdog_init (&config));
180183 if (!sleep_manager_can_deep_sleep ()) {
181184 TEST_ASSERT_MESSAGE (0 , " Deepsleep should be allowed." );
@@ -221,10 +224,11 @@ void test_restart_reset()
221224 // The watchdog should trigger before twice the timeout value.
222225 wait_us (TIMEOUT_US / 2 + TIMEOUT_US);
223226
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 ) {
225228 TEST_ASSERT_MESSAGE (0 , " Dev-host communication error." );
226229 return ;
227230 }
231+ wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
228232 TEST_ASSERT_EQUAL (WATCHDOG_STATUS_OK, hal_watchdog_init (&config));
229233 // Watchdog should fire before twice the timeout value.
230234 wait_us (2 * TIMEOUT_US); // Device reset expected.
@@ -254,10 +258,11 @@ void test_kick_reset()
254258 wait_us (TIMEOUT_US - KICK_ADVANCE_US);
255259 hal_watchdog_kick ();
256260 }
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 ) {
258262 TEST_ASSERT_MESSAGE (0 , " Dev-host communication error." );
259263 return ;
260264 }
265+ wait_us (SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
261266 // Watchdog should fire before twice the timeout value.
262267 wait_us (2 * TIMEOUT_US); // Device reset expected.
263268
0 commit comments