libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
esp_cdc_jtag.hpp
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include "esp_def.hpp"
7#include "esp_intr_alloc.h"
8#include "esp_private/critical_section.h"
9#include "serialized_service.hpp"
10#include "soc/soc_caps.h"
11#include "uart.hpp"
12
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))) || \
16 defined(__DOXYGEN__)
17
18namespace LibXR
19{
20
21class ESP32CDCJtag;
22
27{
28 public:
30 explicit ESP32CDCJtagReadPort(size_t size, ESP32CDCJtag& owner)
31 : ReadPort(size), owner_(owner)
32 {
33 }
34
35 protected:
37 void OnReadQueueSpaceAvailable(bool in_isr) override;
38
39 private:
41 ESP32CDCJtag& owner_;
42};
43
44#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
45static_assert(false,
46 "ESP32CDCJtag conflicts with ESP-IDF primary USB Serial/JTAG console. "
47 "Set CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=n or disable this backend.");
48#endif
49
60class ESP32CDCJtag : public UART
61{
62 friend class ESP32CDCJtagReadPort;
63
64 public:
75 explicit ESP32CDCJtag(size_t rx_buffer_size = 1024, size_t tx_buffer_size = 512,
76 uint32_t tx_queue_size = 5,
78 1});
79
88 ErrorCode SetConfig(UART::Configuration config, bool in_isr = false) override;
89
91 static void WriteFun(WritePort& port, bool in_isr);
92
93 private:
94 static constexpr uint32_t EVENT_WRITE = 1U << 0U;
95 static constexpr uint32_t EVENT_TX_EMPTY = 1U << 1U;
96 static constexpr uint32_t EVENT_RX_DATA = 1U << 2U;
97 static constexpr uint32_t EVENT_RX_SPACE = 1U << 3U;
98
100 static void IsrEntry(void* arg);
102 ErrorCode InitHardware();
103
105 void ServiceEvents(uint32_t events, bool in_isr);
107 void ResumeRx(bool in_isr);
109 void ServiceRx(ReadPort::ReadQueue& queue, bool in_isr);
111 void DrainRxToQueue(ReadPort::ReadQueue& queue, bool in_isr);
113 void PushRxBytes(ReadPort::ReadQueue& queue, const uint8_t* data, size_t size,
114 bool in_isr);
115
117 void ProgressTx(bool in_isr);
119 size_t FillTxFifo(WritePort::WriteQueue& queue, bool in_isr);
121 void ArmTxEmptyInterrupt();
123 void DisarmTxEmptyInterrupt();
125 void FlushTxFifo();
127 void HandleInterrupt();
128
130 void EnableInterrupt(uint32_t mask);
132 void DisableInterrupt(uint32_t mask);
134 void ClearInterrupt(uint32_t mask);
136 void DisableAndClearInterrupt(uint32_t mask);
138 uint32_t CaptureInterrupt(uint32_t mask);
139
141 intr_handle_t intr_handle_ = nullptr;
143 bool hw_inited_ = false;
145 bool tx_empty_interrupt_armed_ = false;
147 bool tx_flush_pending_ = false;
148
150 DECLARE_CRIT_SECTION_LOCK_IN_STRUCT(irq_lock_)
152 SerializedService service_{};
154 ESP32CDCJtagReadPort _read_port;
156 WritePort _write_port;
157};
158
159} // namespace LibXR
160
161#endif
直接使用硬件 FIFO 的 ESP USB Serial/JTAG 后端 / ESP USB Serial/JTAG backend using the hardware FIFO directly.
ESP32CDCJtag(size_t rx_buffer_size=1024, size_t tx_buffer_size=512, uint32_t tx_queue_size=5, UART::Configuration config={115200, UART::Parity::NO_PARITY, 8, 1})
构造并初始化 USB Serial/JTAG 后端 / Construct the USB Serial/JTAG backend.
static void WriteFun(WritePort &port, bool in_isr)
通知处理已提交写入 / Notify released writes.
ErrorCode SetConfig(UART::Configuration config, bool in_isr=false) override
检查虚拟串口帧格式 / Check virtual UART framing.
通知 CDC-JTAG 恢复接收的读端口 / Read port that resumes CDC-JTAG RX.
ESP32CDCJtagReadPort(size_t size, ESP32CDCJtag &owner)
构造接收端口并关联后端 / Construct the RX port associated with its backend.
void OnReadQueueSpaceAvailable(bool in_isr) override
发布接收空间通知 / Publish RX space availability.
接收队列的短期写入接口 / Short-lived producer interface for the RX queue.
基于 SPSC 字节队列的读端口 / Read endpoint backed by an SPSC byte queue.
Definition read_port.hpp:30
事件合并与回调串行化服务 / Event-coalescing serialized-callback service.
通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART)
Definition uart.hpp:19
@ NO_PARITY
无校验 / No parity
已提交队头的出队接口 / Consumer interface for one released front.
基于 SPSC 字节队列的写端口 / Write endpoint backed by an SPSC byte queue.
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
UART 配置结构体 / UART configuration structure.
Definition uart.hpp:44