Skip to content

Commit

Permalink
[USB Serial/JTAG] [VFS] add flag if driver has ever received bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Nov 9, 2022
1 parent 4c8f4ff commit ba7252b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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_has_ever_received_bytes_since_install();

/**
* @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_ever_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_ever_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_has_ever_received_bytes_since_install()
{
if (p_usb_serial_jtag_obj != NULL){
return p_usb_serial_jtag_obj->rx_has_ever_received_bytes;
}
return false;
}

esp_err_t usb_serial_jtag_driver_uninstall(void)
{
if(p_usb_serial_jtag_obj == NULL) {
Expand Down

0 comments on commit ba7252b

Please sign in to comment.