@@ -47,21 +47,20 @@ ticker_irq_handler_type prev_handler;
47
47
48
48
#define LP_TICKER_OV_LIMIT 4000
49
49
50
- /* Flush serial buffer before deep sleep
50
+ /* To prevent a loss of Greentea data, the serial buffers have to be flushed
51
+ * before the UART peripheral shutdown. The UART shutdown happens when the
52
+ * device is entering the deepsleep mode or performing a reset.
51
53
*
52
- * Since deepsleep() may shut down the UART peripheral, we wait for some time
53
- * to allow for hardware serial buffers to completely flush.
54
+ * With the current API, it is not possible to check if the hardware buffers
55
+ * are empty. However, it is possible to determine the time required for the
56
+ * buffers to flush.
54
57
*
55
- * Take NUMAKER_PFM_NUC472 as an example:
56
- * Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush
57
- * Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to
58
- * 20ms here for safe.
59
- *
60
- * This should be replaced with a better function that checks if the
61
- * hardware buffers are empty. However, such an API does not exist now,
62
- * so we'll use the busy_wait_ms() function for now.
58
+ * Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
59
+ * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
60
+ * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
61
+ * To be on the safe side, set the wait time to 150 ms.
63
62
*/
64
- #define SERIAL_FLUSH_TIME_MS 20
63
+ #define SERIAL_FLUSH_TIME_MS 150
65
64
66
65
void busy_wait_ms (int ms)
67
66
{
0 commit comments