From 319e1a7186f348f446096caa5b099a3dc259f226 Mon Sep 17 00:00:00 2001 From: Chip Weinberger Date: Thu, 17 Nov 2022 13:10:30 -0800 Subject: [PATCH] [USB Serial/JTAG] [VFS] add flag if driver has ever received bytes --- components/driver/include/driver/usb_serial_jtag.h | 10 ++++++++++ components/driver/usb_serial_jtag.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/components/driver/include/driver/usb_serial_jtag.h b/components/driver/include/driver/usb_serial_jtag.h index f9d0d3f7f476..205fe2d3d59f 100644 --- a/components/driver/include/driver/usb_serial_jtag.h +++ b/components/driver/include/driver/usb_serial_jtag.h @@ -72,6 +72,16 @@ int usb_serial_jtag_read_bytes(void* buf, uint32_t length, TickType_t ticks_to_w */ int usb_serial_jtag_write_bytes(const void* src, size_t size, TickType_t ticks_to_wait); + +/** + * @brief Returns true if the USB Serial/JTAG Controller driver has ever + * received any bytes over its serial port since the driver was installed. + * + * This can be used as a simple way to determine that a serial + * console has definitely been attached at some point + */ +bool usb_serial_jtag_driver_has_received_bytes(); + /** * @brief Uninstall USB-SERIAL-JTAG driver. * diff --git a/components/driver/usb_serial_jtag.c b/components/driver/usb_serial_jtag.c index 94879aa117f8..01c928feb764 100644 --- a/components/driver/usb_serial_jtag.c +++ b/components/driver/usb_serial_jtag.c @@ -28,6 +28,7 @@ typedef struct{ RingbufHandle_t rx_ring_buf; /*!< RX ring buffer handler */ uint32_t rx_buf_size; /*!< TX buffer size */ uint8_t rx_data_buf[64]; /*!< Data buffer to stash FIFO data */ + bool rx_has_received_bytes; /*!< True if the driver has ever received bytes since install */ // TX parameters uint32_t tx_buf_size; /*!< TX buffer size */ @@ -73,6 +74,7 @@ static void usb_serial_jtag_isr_handler_default(void *arg) { if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT) { // read rx buffer(max length is 64), and send avaliable data to ringbuffer. // Ensure the rx buffer size is larger than RX_MAX_SIZE. + p_usb_serial_jtag_obj->rx_has_received_bytes = true; usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT); uint32_t rx_fifo_len = usb_serial_jtag_ll_read_rxfifo(p_usb_serial_jtag_obj->rx_data_buf, USB_SER_JTAG_RX_MAX_SIZE); xRingbufferSendFromISR(p_usb_serial_jtag_obj->rx_ring_buf, p_usb_serial_jtag_obj->rx_data_buf, rx_fifo_len, &xTaskWoken); @@ -169,6 +171,14 @@ int usb_serial_jtag_write_bytes(const void* src, size_t size, TickType_t ticks_t return size; } +bool usb_serial_jtag_driver_has_received_bytes() +{ + if (p_usb_serial_jtag_obj != NULL){ + return p_usb_serial_jtag_obj->rx_has_received_bytes; + } + return false; +} + esp_err_t usb_serial_jtag_driver_uninstall(void) { if(p_usb_serial_jtag_obj == NULL) {