libxr  1.0
Want to be the best embedded framework
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_tx_double_buffer.hpp"
9#include "flag.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
17namespace LibXR
18{
19
20class ESP32CDCJtag;
21
29class ESP32CDCJtagReadPort : public ReadPort
30{
31 public:
38 explicit ESP32CDCJtagReadPort(size_t size, ESP32CDCJtag& owner)
39 : ReadPort(size), owner_(owner)
40 {
41 }
42
46 void OnRxDequeue(bool in_isr) override;
47
48 ESP32CDCJtagReadPort& operator=(ReadFun fun)
49 {
50 ReadPort::operator=(fun);
51 return *this;
52 }
53
54 private:
55 ESP32CDCJtag& owner_;
56};
57
58#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
59static_assert(false,
60 "ESP32CDCJtag conflicts with ESP-IDF primary USB Serial/JTAG console. "
61 "Set CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=n or disable this backend.");
62#endif
63
72class ESP32CDCJtag : public UART
73{
74 friend class ESP32CDCJtagReadPort;
75
76 public:
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,
90 1});
91
95 ErrorCode SetConfig(UART::Configuration config) override;
96
100 static ErrorCode WriteFun(WritePort& port, bool in_isr);
101
106 static ErrorCode ReadFun(ReadPort& port, bool in_isr);
107
108 private:
112 static void IsrEntry(void* arg);
113
118 ErrorCode InitHardware();
119
123 void HandleInterrupt();
124
129 void DrainRxToQueue(bool in_isr);
130
134 ErrorCode TryStartTx(bool in_isr);
135
139 bool LoadActiveTxFromQueue(bool in_isr);
140
144 bool LoadPendingTxFromQueue(bool in_isr);
145
150 bool StartPendingTxIfIdle(bool in_isr);
151
156 bool DequeueTxToSlot(uint8_t* slot, size_t& size, WriteInfoBlock& info, bool in_isr);
157
161 bool StartActiveTransfer(bool in_isr);
162
167 bool StartAndReportActive(bool in_isr);
168
172 void StopTxTransfer();
173
177 void OnTxTransferDone(bool in_isr, ErrorCode result);
178
182 bool PumpTx(bool in_isr);
183
187 void PushRxBytes(const uint8_t* data, size_t size, bool in_isr);
188
192 void ClearActiveTx();
193
197 void ClearPendingTx();
198
202 void ResetTxState(bool in_isr);
203
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_;
213
214 ESP32CDCJtagReadPort _read_port;
215 WritePort _write_port;
216};
217
218} // namespace LibXR
219
220#endif
LibXR 命名空间
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举
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.