Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[USB Serial/JTAG] [VFS] add flag if driver has ever received bytes (IDFGH-8651) #10097

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/driver/include/driver/usb_serial_jtag.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions components/driver/usb_serial_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down