From cd21a31416f7725bb794b920886bc85cdd27fb56 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 3 May 2022 21:29:21 +0200 Subject: [PATCH] vfs: usb_serial_jtag: consider O_NONBLOCK flag when reading via driver Closes https://github.com/espressif/esp-idf/issues/8839 --- components/vfs/vfs_usb_serial_jtag.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/vfs/vfs_usb_serial_jtag.c b/components/vfs/vfs_usb_serial_jtag.c index 20bb4dd4db..f5ab0b1f79 100644 --- a/components/vfs/vfs_usb_serial_jtag.c +++ b/components/vfs/vfs_usb_serial_jtag.c @@ -71,8 +71,11 @@ typedef struct { // Read and write locks, lazily initialized _lock_t read_lock; _lock_t write_lock; - // Non-blocking flag. Note: default implementation does not honor this - // flag, all reads are non-blocking. ToDo: implement driver that honours this. + // Non-blocking flag. + // The default implementation does not honor this flag, all reads + // are non-blocking. + // When the driver is used (via esp_vfs_usb_serial_jtag_use_driver), + // reads are either blocking or non-blocking depending on this flag. bool non_blocking; // Newline conversion mode when transmitting esp_line_endings_t tx_mode; @@ -389,7 +392,8 @@ esp_err_t esp_vfs_dev_usb_serial_jtag_register(void) static int usbjtag_rx_char_via_driver(int fd) { uint8_t c; - int n = usb_serial_jtag_read_bytes(&c, 1, portMAX_DELAY); + TickType_t timeout = s_ctx.non_blocking ? 0 : portMAX_DELAY; + int n = usb_serial_jtag_read_bytes(&c, 1, timeout); if (n <= 0) { return NONE; }