7#include "esp_intr_alloc.h"
8#include "esp_tx_double_buffer.hpp"
10#include "soc/soc_caps.h"
13#if SOC_USB_SERIAL_JTAG_SUPPORTED && \
14 ((defined(CONFIG_IDF_TARGET_ESP32C3) && CONFIG_IDF_TARGET_ESP32C3) || \
15 (defined(CONFIG_IDF_TARGET_ESP32C6) && CONFIG_IDF_TARGET_ESP32C6))
29class ESP32CDCJtagReadPort :
public ReadPort
38 explicit ESP32CDCJtagReadPort(
size_t size, ESP32CDCJtag& owner)
39 : ReadPort(size), owner_(owner)
46 void OnRxDequeue(
bool in_isr)
override;
48 ESP32CDCJtagReadPort& operator=(ReadFun fun)
50 ReadPort::operator=(fun);
58#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
60 "ESP32CDCJtag conflicts with ESP-IDF primary USB Serial/JTAG console. "
61 "Set CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=n or disable this backend.");
72class ESP32CDCJtag :
public UART
74 friend class ESP32CDCJtagReadPort;
87 explicit ESP32CDCJtag(
size_t rx_buffer_size = 1024,
size_t tx_buffer_size = 512,
88 uint32_t tx_queue_size = 5,
89 UART::Configuration config = {115200, UART::Parity::NO_PARITY, 8,
95 ErrorCode SetConfig(UART::Configuration config)
override;
112 static void IsrEntry(
void* arg);
123 void HandleInterrupt();
129 void DrainRxToQueue(
bool in_isr);
139 bool LoadActiveTxFromQueue(
bool in_isr);
144 bool LoadPendingTxFromQueue(
bool in_isr);
150 bool StartPendingTxIfIdle(
bool in_isr);
156 bool DequeueTxToSlot(uint8_t* slot,
size_t& size, WriteInfoBlock& info,
bool in_isr);
161 bool StartActiveTransfer(
bool in_isr);
167 bool StartAndReportActive(
bool in_isr);
172 void StopTxTransfer();
177 void OnTxTransferDone(
bool in_isr, ErrorCode result);
182 bool PumpTx(
bool in_isr);
187 void PushRxBytes(
const uint8_t* data,
size_t size,
bool in_isr);
192 void ClearActiveTx();
197 void ClearPendingTx();
202 void ResetTxState(
bool in_isr);
204 UART::Configuration config_;
205 uint8_t* tx_slot_storage_ =
nullptr;
206 ESPTxDoubleBuffer tx_double_buffer_;
207 intr_handle_t intr_handle_ =
nullptr;
208 bool intr_installed_ =
false;
209 bool hw_inited_ =
false;
210 Flag::Atomic tx_busy_{};
211 Flag::Atomic rx_draining_{};
212 Flag::Plain in_tx_isr_;
214 ESP32CDCJtagReadPort _read_port;
215 WritePort _write_port;
ErrorCode(* ReadFun)(ReadPort &port, bool in_isr)
Function pointer type for read notifications.
ErrorCode(* WriteFun)(WritePort &port, bool in_isr)
Function pointer type for write operations.