libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
esp_cdc_jtag.hpp
1#pragma once
2
3#include "esp_def.hpp"
4
5#include <cstddef>
6#include <cstdint>
7
8#include "esp_intr_alloc.h"
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
20#if defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
21static_assert(false,
22 "ESP32CDCJtag conflicts with ESP-IDF primary USB Serial/JTAG console. "
23 "Set CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=n or disable this backend.");
24#endif
25
26class ESP32CDCJtag : public UART
27{
28 public:
29 explicit ESP32CDCJtag(
30 size_t rx_buffer_size = 1024, size_t tx_buffer_size = 512,
31 uint32_t tx_queue_size = 5,
32 UART::Configuration config = {115200, UART::Parity::NO_PARITY, 8, 1});
33
34
35 ErrorCode SetConfig(UART::Configuration config) override;
36
37 static ErrorCode WriteFun(WritePort& port, bool in_isr);
38
39 static ErrorCode ReadFun(ReadPort& port, bool in_isr);
40
41 private:
42 static void IsrEntry(void* arg);
43
44 ErrorCode InitHardware();
45
46
47 void HandleInterrupt();
48
49 ErrorCode TryStartTx(bool in_isr);
50 bool LoadActiveTxFromQueue(bool in_isr);
51 bool LoadPendingTxFromQueue(bool in_isr);
52 bool DequeueTxToSlot(uint8_t* slot, size_t& size, WriteInfoBlock& info, bool in_isr);
53 bool StartActiveTransfer(bool in_isr);
54 bool StartAndReportActive(bool in_isr);
55 void StopTxTransfer();
56 void OnTxTransferDone(bool in_isr, ErrorCode result);
57 bool PumpTx(bool in_isr);
58 void PushRxBytes(const uint8_t* data, size_t size, bool in_isr);
59 void ClearActiveTx();
60 void ClearPendingTx();
61 void ResetTxState(bool in_isr);
62
63 UART::Configuration config_;
64 uint8_t* tx_slot_storage_ = nullptr;
65 size_t tx_slot_size_ = 0;
66 uint8_t* tx_slot_a_ = nullptr;
67 uint8_t* tx_slot_b_ = nullptr;
68 intr_handle_t intr_handle_ = nullptr;
69 bool intr_installed_ = false;
70 bool hw_inited_ = false;
71 const uint8_t* tx_active_ptr_ = nullptr;
72 size_t tx_active_size_ = 0;
73 size_t tx_active_offset_ = 0;
74 WriteInfoBlock tx_active_info_ = {};
75 bool tx_active_valid_ = false;
76 const uint8_t* tx_pending_ptr_ = nullptr;
77 size_t tx_pending_size_ = 0;
78 bool tx_pending_valid_ = false;
79 WriteInfoBlock tx_pending_info_ = {};
80 Flag::Atomic tx_busy_{};
81 Flag::Plain in_tx_isr_;
82
83 ReadPort _read_port;
84 WritePort _write_port;
85};
86
87} // namespace LibXR
88
89#endif
LibXR 命名空间
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举
Definition libxr_def.hpp:64
ErrorCode(* ReadFun)(ReadPort &port, bool in_isr)
Function pointer type for read operations.
Definition libxr_rw.hpp:356
ErrorCode(* WriteFun)(WritePort &port, bool in_isr)
Function pointer type for write operations.
Definition libxr_rw.hpp:352