remove unused includes, files and reference
This commit is contained in:
parent
8e3b541d26
commit
24aa3bed7f
components
DAP/cmsis-dap
USBIP
dap_proxy
elaphureLink
main
|
@ -1,597 +0,0 @@
|
|||
/**
|
||||
* @brief Made some simple modifications to the official UART
|
||||
*
|
||||
*/
|
||||
|
||||
// Copyright 2018-2025 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
#ifndef _DRIVER_UART_H_
|
||||
#define _DRIVER_UART_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
// SWO modify
|
||||
extern volatile uint32_t kSWO_read_index;
|
||||
extern volatile uint32_t kSWO_read_num;
|
||||
extern volatile uint8_t kSWO_uart_notify_enable;
|
||||
extern SemaphoreHandle_t kSWO_read_mux;
|
||||
|
||||
#define UART_FIFO_LEN (128) /*!< Length of the hardware FIFO buffers */
|
||||
#define UART_INTR_MASK 0x1ff /*!< Mask of all UART interrupts */
|
||||
#define UART_LINE_INV_MASK (0x3f << 19) /*!< TBD */
|
||||
|
||||
#define UART_INVERSE_DISABLE (0x0) /*!< Disable UART signal inverse*/
|
||||
#define UART_INVERSE_RXD (BIT(19)) /*!< UART RXD input inverse*/
|
||||
#define UART_INVERSE_CTS (BIT(20)) /*!< UART CTS input inverse*/
|
||||
#define UART_INVERSE_TXD (BIT(22)) /*!< UART TXD output inverse*/
|
||||
#define UART_INVERSE_RTS (BIT(23)) /*!< UART RTS output inverse*/
|
||||
|
||||
/**
|
||||
* @brief UART mode selection
|
||||
*/
|
||||
typedef enum {
|
||||
UART_MODE_UART = 0x00, /*!< mode: regular UART mode*/
|
||||
} uart_mode_t;
|
||||
|
||||
/**
|
||||
* @brief UART word length constants
|
||||
*/
|
||||
typedef enum {
|
||||
UART_DATA_5_BITS = 0x0, /*!< word length: 5bits*/
|
||||
UART_DATA_6_BITS = 0x1, /*!< word length: 6bits*/
|
||||
UART_DATA_7_BITS = 0x2, /*!< word length: 7bits*/
|
||||
UART_DATA_8_BITS = 0x3, /*!< word length: 8bits*/
|
||||
UART_DATA_BITS_MAX = 0x4,
|
||||
} uart_word_length_t;
|
||||
|
||||
/**
|
||||
* @brief UART stop bits number
|
||||
*/
|
||||
typedef enum {
|
||||
UART_STOP_BITS_1 = 0x1, /*!< stop bit: 1bit*/
|
||||
UART_STOP_BITS_1_5 = 0x2, /*!< stop bit: 1.5bits*/
|
||||
UART_STOP_BITS_2 = 0x3, /*!< stop bit: 2bits*/
|
||||
UART_STOP_BITS_MAX = 0x4,
|
||||
} uart_stop_bits_t;
|
||||
|
||||
/**
|
||||
* @brief UART peripheral number
|
||||
*/
|
||||
typedef enum {
|
||||
UART_NUM_0 = 0x0,
|
||||
UART_NUM_1 = 0x1,
|
||||
UART_NUM_MAX,
|
||||
} uart_port_t;
|
||||
|
||||
/**
|
||||
* @brief UART parity constants
|
||||
*/
|
||||
typedef enum {
|
||||
UART_PARITY_DISABLE = 0x0, /*!< Disable UART parity*/
|
||||
UART_PARITY_EVEN = 0x2, /*!< Enable UART even parity*/
|
||||
UART_PARITY_ODD = 0x3 /*!< Enable UART odd parity*/
|
||||
} uart_parity_t;
|
||||
|
||||
/**
|
||||
* @brief UART hardware flow control modes
|
||||
*/
|
||||
typedef enum {
|
||||
UART_HW_FLOWCTRL_DISABLE = 0x0, /*!< disable hardware flow control*/
|
||||
UART_HW_FLOWCTRL_RTS = 0x1, /*!< enable RX hardware flow control (rts)*/
|
||||
UART_HW_FLOWCTRL_CTS = 0x2, /*!< enable TX hardware flow control (cts)*/
|
||||
UART_HW_FLOWCTRL_CTS_RTS = 0x3, /*!< enable hardware flow control*/
|
||||
UART_HW_FLOWCTRL_MAX = 0x4,
|
||||
} uart_hw_flowcontrol_t;
|
||||
|
||||
/**
|
||||
* @brief UART configuration parameters for my_uart_param_config function
|
||||
*/
|
||||
typedef struct {
|
||||
int baud_rate; /*!< UART baud rate*/
|
||||
uart_word_length_t data_bits; /*!< UART byte size*/
|
||||
uart_parity_t parity; /*!< UART parity mode*/
|
||||
uart_stop_bits_t stop_bits; /*!< UART stop bits*/
|
||||
uart_hw_flowcontrol_t flow_ctrl; /*!< UART HW flow control mode (cts/rts)*/
|
||||
uint8_t rx_flow_ctrl_thresh; /*!< UART HW RTS threshold*/
|
||||
} uart_config_t;
|
||||
|
||||
/**
|
||||
* @brief UART interrupt configuration parameters for my_uart_intr_config function
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t intr_enable_mask; /*!< UART interrupt enable mask, choose from UART_XXXX_INT_ENA_M under UART_INT_ENA_REG(i), connect with bit-or operator*/
|
||||
uint8_t rx_timeout_thresh; /*!< UART timeout interrupt threshold (unit: time of sending one byte)*/
|
||||
uint8_t txfifo_empty_intr_thresh; /*!< UART TX empty interrupt threshold.*/
|
||||
uint8_t rxfifo_full_thresh; /*!< UART RX full interrupt threshold.*/
|
||||
} uart_intr_config_t;
|
||||
|
||||
/**
|
||||
* @brief UART event types used in the ring buffer
|
||||
*/
|
||||
typedef enum {
|
||||
UART_DATA, /*!< UART data event*/
|
||||
UART_BUFFER_FULL, /*!< UART RX buffer full event*/
|
||||
UART_FIFO_OVF, /*!< UART FIFO overflow event*/
|
||||
UART_FRAME_ERR, /*!< UART RX frame error event*/
|
||||
UART_PARITY_ERR, /*!< UART RX parity event*/
|
||||
UART_EVENT_MAX, /*!< UART event max index*/
|
||||
} uart_event_type_t;
|
||||
|
||||
/**
|
||||
* @brief Event structure used in UART event queue
|
||||
*/
|
||||
typedef struct {
|
||||
uart_event_type_t type; /*!< UART event type */
|
||||
size_t size; /*!< UART data size for UART_DATA event*/
|
||||
} uart_event_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set UART data bits.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param data_bit Uart data bits.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_bit);
|
||||
|
||||
/**
|
||||
* @brief Get UART data bits.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param data_bit Pointer to accept value of UART data bits.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_get_word_length(uart_port_t uart_num, uart_word_length_t *data_bit);
|
||||
|
||||
/**
|
||||
* @brief Set UART stop bits.
|
||||
*
|
||||
* @param uart_num Uart port number
|
||||
* @param stop_bits Uart stop bits
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bits);
|
||||
|
||||
/**
|
||||
* @brief Get UART stop bits.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param stop_bits Pointer to accept value of UART stop bits.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t *stop_bits);
|
||||
|
||||
/**
|
||||
* @brief Set UART parity mode.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param parity_mode The enum of uart parity configuration.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_set_parity(uart_port_t uart_num, uart_parity_t parity_mode);
|
||||
|
||||
/**
|
||||
* @brief Get UART parity mode.
|
||||
*
|
||||
* @param uart_num Uart port number
|
||||
* @param parity_mode Pointer to accept value of UART parity mode.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_get_parity(uart_port_t uart_num, uart_parity_t *parity_mode);
|
||||
|
||||
/**
|
||||
* @brief Set UART baud rate.
|
||||
*
|
||||
* @param uart_num Uart port number
|
||||
* @param baudrate UART baud rate.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_set_baudrate(uart_port_t uart_num, uint32_t baudrate);
|
||||
|
||||
/**
|
||||
* @brief Get UART baud rate.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param baudrate Pointer to accept value of Uart baud rate.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_get_baudrate(uart_port_t uart_num, uint32_t *baudrate);
|
||||
|
||||
/**
|
||||
* @brief Set UART line inverse mode
|
||||
*
|
||||
* @param uart_num UART_NUM_0
|
||||
* @param inverse_mask Choose the wires that need to be inverted.
|
||||
* Inverse_mask should be chosen from
|
||||
* UART_INVERSE_RXD / UART_INVERSE_TXD / UART_INVERSE_RTS / UART_INVERSE_CTS,
|
||||
* combined with OR operation.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask);
|
||||
|
||||
/**
|
||||
* @brief Configure Hardware flow control.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param flow_ctrl Hardware flow control mode.
|
||||
* @param rx_thresh Threshold of Hardware flow control.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh);
|
||||
|
||||
/**
|
||||
* @brief Get hardware flow control mode
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param flow_ctrl Option for different flow control mode.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success, result will be put in (*flow_ctrl)
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_get_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t *flow_ctrl);
|
||||
|
||||
/**
|
||||
* @brief UART0 swap.
|
||||
* Use MTCK as UART0 RX, MTDO as UART0 TX, so ROM log will not output from
|
||||
* this new UART0. We also need to use MTDO (U0RTS) and MTCK (U0CTS) as UART0 in hardware.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t my_uart_enable_swap(void);
|
||||
|
||||
/**
|
||||
* @brief Disable UART0 swap.
|
||||
* Use the original UART0, not MTCK and MTDO.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t my_uart_disable_swap(void);
|
||||
|
||||
/**
|
||||
* @brief Clear uart interrupts status.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param mask Uart interrupt bits mask.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_clear_intr_status(uart_port_t uart_num, uint32_t mask);
|
||||
|
||||
/**
|
||||
* @brief Set UART interrupt enable
|
||||
*
|
||||
* @param uart_num Uart port number
|
||||
* @param enable_mask Bit mask of the enable bits.
|
||||
* The bit mask should be composed from the fields of register UART_INT_ENA_REG.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_enable_intr_mask(uart_port_t uart_num, uint32_t enable_mask);
|
||||
|
||||
/**
|
||||
* @brief Clear UART interrupt enable bits
|
||||
*
|
||||
* @param uart_num Uart port number
|
||||
* @param disable_mask Bit mask of the disable bits.
|
||||
* The bit mask should be composed from the fields of register UART_INT_ENA_REG.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_disable_intr_mask(uart_port_t uart_num, uint32_t disable_mask);
|
||||
|
||||
/**
|
||||
* @brief Enable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT)
|
||||
*
|
||||
* @param uart_num UART_NUM_0
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_enable_rx_intr(uart_port_t uart_num);
|
||||
|
||||
/**
|
||||
* @brief Disable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT)
|
||||
*
|
||||
* @param uart_num UART_NUM_0
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_disable_rx_intr(uart_port_t uart_num);
|
||||
|
||||
/**
|
||||
* @brief Disable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT)
|
||||
*
|
||||
* @param uart_num UART_NUM_0
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_disable_tx_intr(uart_port_t uart_num);
|
||||
|
||||
/**
|
||||
* @brief Enable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT)
|
||||
*
|
||||
* @param uart_num UART_NUM_0
|
||||
* @param enable 1: enable; 0: disable
|
||||
* @param thresh Threshold of TX interrupt, 0 ~ UART_FIFO_LEN
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_enable_tx_intr(uart_port_t uart_num, int enable, int thresh);
|
||||
|
||||
/**
|
||||
* @brief Register UART interrupt handler (ISR).
|
||||
*
|
||||
* @param uart_num UART_NUM_0
|
||||
* @param fn Interrupt handler function.
|
||||
* @param arg parameter for handler function
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_isr_register(uart_port_t uart_num, void (*fn)(void *), void *arg);
|
||||
|
||||
/**
|
||||
* @brief Config Common parameters of serial ports.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param uart_conf Uart config parameters.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_param_config(uart_port_t uart_num, uart_config_t *uart_conf);
|
||||
|
||||
/**
|
||||
* @brief Config types of uarts.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param uart_intr_conf Uart interrupt config parameters.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_intr_config(uart_port_t uart_num, uart_intr_config_t *uart_intr_conf);
|
||||
|
||||
/**
|
||||
* @brief Install UART driver.
|
||||
*
|
||||
* @note Rx_buffer_size should be greater than UART_FIFO_LEN. Tx_buffer_size should be either zero or greater than UART_FIFO_LEN.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param rx_buffer_size UART RX ring buffer size.
|
||||
* @param tx_buffer_size UART TX ring buffer size.
|
||||
* If set to zero, driver will not use TX buffer, TX function will block task until all data have been sent out.
|
||||
* @param queue_size UART event queue size/depth.
|
||||
* @param uart_queue UART event queue handle (out param). On success, a new queue handle is written here to provide
|
||||
* access to UART events. If set to NULL, driver will not use an event queue.
|
||||
* @param no_use Invalid parameters, just to fit some modules.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_driver_install(uart_port_t uart_num, int rx_buffer_size, int tx_buffer_size, int queue_size, QueueHandle_t *uart_queue, int no_use);
|
||||
|
||||
/**
|
||||
* @brief Uninstall UART driver.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_driver_delete(uart_port_t uart_num);
|
||||
|
||||
/**
|
||||
* @brief Waiting for the last byte of data to be sent
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param ticks_to_wait Timeout, count in RTOS ticks
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait);
|
||||
|
||||
/**
|
||||
* @brief Send data to the UART port from a given buffer and length.
|
||||
*
|
||||
* This function will not wait for enough space in TX FIFO. It will just fill the available TX FIFO and return when the FIFO is full.
|
||||
* @note This function should only be used when UART TX buffer is not enabled.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param buffer data buffer address
|
||||
* @param len data length to send
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
* - OTHERS (>=0) The number of bytes pushed to the TX FIFO
|
||||
*/
|
||||
int my_uart_tx_chars(uart_port_t uart_num, const char *buffer, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief Send data to the UART port from a given buffer and length,
|
||||
*
|
||||
* If the UART driver's parameter 'tx_buffer_size' is set to zero:
|
||||
* This function will not return until all the data have been sent out, or at least pushed into TX FIFO.
|
||||
*
|
||||
* Otherwise, if the 'tx_buffer_size' > 0, this function will return after copying all the data to tx ring buffer,
|
||||
* UART ISR will then move data from the ring buffer to TX FIFO gradually.
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param src data buffer address
|
||||
* @param size data length to send
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
* - OTHERS (>=0) The number of bytes pushed to the TX FIFO
|
||||
*/
|
||||
int my_uart_write_bytes(uart_port_t uart_num, const char *src, size_t size);
|
||||
|
||||
/**
|
||||
* @brief UART read bytes from UART buffer
|
||||
*
|
||||
* @param uart_num Uart port number.
|
||||
* @param buf pointer to the buffer.
|
||||
* @param length data length
|
||||
* @param ticks_to_wait sTimeout, count in RTOS ticks
|
||||
*
|
||||
* @return
|
||||
* - (-1) Error
|
||||
* - OTHERS (>=0) The number of bytes read from UART FIFO
|
||||
*/
|
||||
int my_uart_read_bytes(uart_port_t uart_num, uint8_t *buf, uint32_t length, TickType_t ticks_to_wait);
|
||||
|
||||
/**
|
||||
* @brief Alias of my_uart_flush_input.
|
||||
* UART ring buffer flush. This will discard all data in the UART RX buffer.
|
||||
* @note Instead of waiting the data sent out, this function will clear UART rx buffer.
|
||||
* In order to send all the data in tx FIFO, we can use my_uart_wait_tx_done function.
|
||||
* @param uart_num UART port number.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_flush(uart_port_t uart_num);
|
||||
|
||||
/**
|
||||
* @brief Clear input buffer, discard all the data is in the ring-buffer.
|
||||
* @note In order to send all the data in tx FIFO, we can use my_uart_wait_tx_done function.
|
||||
* @param uart_num UART port number.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_flush_input(uart_port_t uart_num);
|
||||
|
||||
/**
|
||||
* @brief UART get RX ring buffer cached data length
|
||||
*
|
||||
* @param uart_num UART port number.
|
||||
* @param size Pointer of size_t to accept cached data length
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_get_buffered_data_len(uart_port_t uart_num, size_t *size);
|
||||
|
||||
/**
|
||||
* @brief UART set threshold timeout for TOUT feature
|
||||
*
|
||||
* @param uart_num Uart number to configure
|
||||
* @param tout_thresh This parameter defines timeout threshold in uart symbol periods. The maximum value of threshold is 126.
|
||||
* tout_thresh = 1, defines TOUT interrupt timeout equal to transmission time of one symbol (~11 bit) on current baudrate.
|
||||
* If the time is expired the UART_RXFIFO_TOUT_INT interrupt is triggered. If tout_thresh == 0,
|
||||
* the TOUT feature is disabled.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t my_uart_set_rx_timeout(uart_port_t uart_num, const uint8_t tout_thresh);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Asynchronously read bytes to swo buffer
|
||||
* @note This function only serves as a notification,
|
||||
* and will initiate a callback when the buffer reaches the length since we modify the uart
|
||||
* @param index buffer index to read
|
||||
* @param length data length
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL There are still unfinished requests
|
||||
*/
|
||||
esp_err_t my_uart_read_bytes_async_swo(uint32_t index, uint32_t length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief UART get RX ring buffer cached data length
|
||||
* @note This function is basically equivalent to \ref my_uart_get_buffered_data_len
|
||||
* @param uart_num UART port number.
|
||||
*
|
||||
* @return data length
|
||||
*/
|
||||
int my_uart_get_rx_buffered_data_len(uart_port_t uart_num);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _DRIVER_UART_H_
|
|
@ -25,7 +25,6 @@
|
|||
*
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DAP_config.h"
|
||||
#include "cmsis-dap/include/DAP.h"
|
||||
|
||||
//**************************************************************************************************
|
||||
|
|
|
@ -1,16 +1,3 @@
|
|||
/**
|
||||
* @file SWO.c
|
||||
* @author windowsair
|
||||
* @brief SWO support
|
||||
* @change: 2021-02-17: Add basic functions
|
||||
* @version 0.2
|
||||
*
|
||||
* @date 2021-02-17
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013-2017 ARM Limited. All rights reserved.
|
||||
*
|
||||
|
@ -39,14 +26,8 @@
|
|||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DAP_config.h"
|
||||
#include "cmsis-dap/include/DAP.h"
|
||||
#include "cmsis-dap/include/uart_modify.h"
|
||||
#include "cmsis-dap/include/swo.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
|
||||
|
||||
EventGroupHandle_t kSwoThreadEventGroup;
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,7 +10,6 @@
|
|||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
#include "components/USBIP/usb_defs.h"
|
||||
|
|
|
@ -11,16 +11,11 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "usbip_server.h"
|
||||
#include "main/wifi_configuration.h"
|
||||
|
||||
#include "components/USBIP/usb_handle.h"
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
#include "components/USBIP/MSOS20_descriptor.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
|
||||
const char *strings_list[] = {
|
||||
|
@ -43,28 +38,28 @@ void handleUSBControlRequest(usbip_stage2_header *header)
|
|||
switch (header->u.cmd_submit.request.bRequest)
|
||||
{
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
os_printf("* CLEAR FEATURE\r\n");
|
||||
printf("* CLEAR FEATURE\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_SET_FEATURE:
|
||||
os_printf("* SET FEATURE\r\n");
|
||||
printf("* SET FEATURE\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_SET_ADDRESS:
|
||||
os_printf("* SET ADDRESS\r\n");
|
||||
printf("* SET ADDRESS\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_SET_DESCRIPTOR:
|
||||
os_printf("* SET DESCRIPTOR\r\n");
|
||||
printf("* SET DESCRIPTOR\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_SET_CONFIGURATION:
|
||||
os_printf("* SET CONFIGURATION\r\n");
|
||||
printf("* SET CONFIGURATION\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
default:
|
||||
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -72,21 +67,21 @@ void handleUSBControlRequest(usbip_stage2_header *header)
|
|||
switch (header->u.cmd_submit.request.bRequest)
|
||||
{
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
os_printf("* CLEAR FEATURE\r\n");
|
||||
printf("* CLEAR FEATURE\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_SET_FEATURE:
|
||||
os_printf("* SET FEATURE\r\n");
|
||||
printf("* SET FEATURE\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
os_printf("* SET INTERFACE\r\n");
|
||||
printf("* SET INTERFACE\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -94,17 +89,17 @@ void handleUSBControlRequest(usbip_stage2_header *header)
|
|||
switch (header->u.cmd_submit.request.bRequest)
|
||||
{
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
os_printf("* CLEAR FEATURE\r\n");
|
||||
printf("* CLEAR FEATURE\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_SET_FEATURE:
|
||||
os_printf("* SET INTERFACE\r\n");
|
||||
printf("* SET INTERFACE\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -117,19 +112,19 @@ void handleUSBControlRequest(usbip_stage2_header *header)
|
|||
switch (header->u.cmd_submit.request.bRequest)
|
||||
{
|
||||
case USB_REQ_GET_CONFIGURATION:
|
||||
os_printf("* GET CONIFGTRATION\r\n");
|
||||
printf("* GET CONIFGTRATION\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
handleGetDescriptor(header); ////TODO: device_qualifier
|
||||
break;
|
||||
case USB_REQ_GET_STATUS:
|
||||
os_printf("* GET STATUS\r\n");
|
||||
printf("* GET STATUS\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
default:
|
||||
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -139,21 +134,21 @@ void handleUSBControlRequest(usbip_stage2_header *header)
|
|||
switch (header->u.cmd_submit.request.bRequest)
|
||||
{
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
os_printf("* GET INTERFACE\r\n");
|
||||
printf("* GET INTERFACE\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_SET_SYNCH_FRAME:
|
||||
os_printf("* SET SYNCH FRAME\r\n");
|
||||
printf("* SET SYNCH FRAME\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
case USB_REQ_GET_STATUS:
|
||||
os_printf("* GET STATUS\r\n");
|
||||
printf("* GET STATUS\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -162,13 +157,13 @@ void handleUSBControlRequest(usbip_stage2_header *header)
|
|||
switch (header->u.cmd_submit.request.bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
os_printf("* GET STATUS\r\n");
|
||||
printf("* GET STATUS\r\n");
|
||||
send_stage2_submit_data(header, 0, 0, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -178,18 +173,18 @@ void handleUSBControlRequest(usbip_stage2_header *header)
|
|||
switch (wIndex)
|
||||
{
|
||||
case MS_OS_20_DESCRIPTOR_INDEX:
|
||||
os_printf("* GET MSOS 2.0 vendor-specific descriptor\r\n");
|
||||
printf("* GET MSOS 2.0 vendor-specific descriptor\r\n");
|
||||
send_stage2_submit_data(header, 0, msOs20DescriptorSetHeader, sizeof(msOs20DescriptorSetHeader));
|
||||
break;
|
||||
case MS_OS_20_SET_ALT_ENUMERATION:
|
||||
// set alternate enumeration command
|
||||
// bAltEnumCode set to 0
|
||||
os_printf("Set alternate enumeration.This should not happen.\r\n");
|
||||
printf("Set alternate enumeration.This should not happen.\r\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d,wIndex:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest, wIndex);
|
||||
printf("USB unknown request, bmRequestType:%d,bRequest:%d,wIndex:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest, wIndex);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -198,19 +193,19 @@ void handleUSBControlRequest(usbip_stage2_header *header)
|
|||
switch (header->u.cmd_submit.request.bRequest)
|
||||
{
|
||||
case USB_REQ_SET_IDLE:
|
||||
os_printf("* SET IDLE\r\n");
|
||||
printf("* SET IDLE\r\n");
|
||||
send_stage2_submit(header, 0, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
|
||||
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -221,23 +216,23 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
switch (header->u.cmd_submit.request.wValue.u8hi)
|
||||
{
|
||||
case USB_DT_DEVICE: // get device descriptor
|
||||
os_printf("* GET 0x01 DEVICE DESCRIPTOR\r\n");
|
||||
printf("* GET 0x01 DEVICE DESCRIPTOR\r\n");
|
||||
send_stage2_submit_data(header, 0, &kUSBd0DeviceDescriptor[0], sizeof(kUSBd0DeviceDescriptor));
|
||||
break;
|
||||
|
||||
case USB_DT_CONFIGURATION: // get configuration descriptor
|
||||
os_printf("* GET 0x02 CONFIGURATION DESCRIPTOR\r\n");
|
||||
printf("* GET 0x02 CONFIGURATION DESCRIPTOR\r\n");
|
||||
////TODO: ?
|
||||
if (header->u.cmd_submit.data_length == USB_DT_CONFIGURATION_SIZE)
|
||||
{
|
||||
os_printf("Sending only first part of CONFIG\r\n");
|
||||
printf("Sending only first part of CONFIG\r\n");
|
||||
|
||||
send_stage2_submit(header, 0, header->u.cmd_submit.data_length);
|
||||
usbip_network_send(kSock, kUSBd0ConfigDescriptor, sizeof(kUSBd0ConfigDescriptor), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
os_printf("Sending ALL CONFIG\r\n");
|
||||
printf("Sending ALL CONFIG\r\n");
|
||||
send_stage2_submit(header, 0, sizeof(kUSBd0ConfigDescriptor) + sizeof(kUSBd0InterfaceDescriptor));
|
||||
usbip_network_send(kSock, kUSBd0ConfigDescriptor, sizeof(kUSBd0ConfigDescriptor), 0);
|
||||
usbip_network_send(kSock, kUSBd0InterfaceDescriptor, sizeof(kUSBd0InterfaceDescriptor), 0);
|
||||
|
@ -249,7 +244,7 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
|
||||
if (header->u.cmd_submit.request.wValue.u8lo == 0)
|
||||
{
|
||||
os_printf("** REQUESTED list of supported languages\r\n");
|
||||
printf("** REQUESTED list of supported languages\r\n");
|
||||
send_stage2_submit_data(header, 0, kLangDescriptor, sizeof(kLangDescriptor));
|
||||
}
|
||||
else if (header->u.cmd_submit.request.wValue.u8lo != 0xee)
|
||||
|
@ -272,27 +267,27 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
}
|
||||
else
|
||||
{
|
||||
os_printf("low bit : %d\r\n", (int)header->u.cmd_submit.request.wValue.u8lo);
|
||||
os_printf("high bit : %d\r\n", (int)header->u.cmd_submit.request.wValue.u8hi);
|
||||
os_printf("***Unsupported String descriptor***\r\n");
|
||||
printf("low bit : %d\r\n", (int) header->u.cmd_submit.request.wValue.u8lo);
|
||||
printf("high bit : %d\r\n", (int) header->u.cmd_submit.request.wValue.u8hi);
|
||||
printf("***Unsupported String descriptor***\r\n");
|
||||
send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_DT_INTERFACE:
|
||||
os_printf("* GET 0x04 INTERFACE DESCRIPTOR (UNIMPLEMENTED)\r\n");
|
||||
printf("* GET 0x04 INTERFACE DESCRIPTOR (UNIMPLEMENTED)\r\n");
|
||||
////TODO:UNIMPLEMENTED
|
||||
send_stage2_submit(header, 0, 0);
|
||||
break;
|
||||
|
||||
case USB_DT_ENDPOINT:
|
||||
os_printf("* GET 0x05 ENDPOINT DESCRIPTOR (UNIMPLEMENTED)\r\n");
|
||||
printf("* GET 0x05 ENDPOINT DESCRIPTOR (UNIMPLEMENTED)\r\n");
|
||||
////TODO:UNIMPLEMENTED
|
||||
send_stage2_submit(header, 0, 0);
|
||||
break;
|
||||
|
||||
case USB_DT_DEVICE_QUALIFIER:
|
||||
os_printf("* GET 0x06 DEVICE QUALIFIER DESCRIPTOR\r\n");
|
||||
printf("* GET 0x06 DEVICE QUALIFIER DESCRIPTOR\r\n");
|
||||
|
||||
usb_device_qualifier_descriptor desc;
|
||||
|
||||
|
@ -302,19 +297,19 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
break;
|
||||
|
||||
case USB_DT_OTHER_SPEED_CONFIGURATION:
|
||||
os_printf("GET 0x07 [UNIMPLEMENTED] USB_DT_OTHER_SPEED_CONFIGURATION\r\n");
|
||||
printf("GET 0x07 [UNIMPLEMENTED] USB_DT_OTHER_SPEED_CONFIGURATION\r\n");
|
||||
////TODO:UNIMPLEMENTED
|
||||
send_stage2_submit(header, 0, 0);
|
||||
break;
|
||||
|
||||
case USB_DT_INTERFACE_POWER:
|
||||
os_printf("GET 0x08 [UNIMPLEMENTED] USB_DT_INTERFACE_POWER\r\n");
|
||||
printf("GET 0x08 [UNIMPLEMENTED] USB_DT_INTERFACE_POWER\r\n");
|
||||
////TODO:UNIMPLEMENTED
|
||||
send_stage2_submit(header, 0, 0);
|
||||
break;
|
||||
#if (USE_WINUSB == 1)
|
||||
case USB_DT_BOS:
|
||||
os_printf("* GET 0x0F BOS DESCRIPTOR\r\n");
|
||||
printf("* GET 0x0F BOS DESCRIPTOR\r\n");
|
||||
uint32_t bos_len = header->u.cmd_submit.request.wLength.u8lo | ((uint32_t) header->u.cmd_submit.request.wLength.u8hi << 8);
|
||||
bos_len = (sizeof(bosDescriptor) < bos_len) ? sizeof(bosDescriptor) : bos_len;
|
||||
send_stage2_submit_data(header, 0, bosDescriptor, bos_len);
|
||||
|
@ -327,9 +322,9 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
#endif
|
||||
default:
|
||||
//// TODO: ms os 1.0 descriptor
|
||||
os_printf("USB unknown Get Descriptor requested:%d\r\n", header->u.cmd_submit.request.wValue.u8lo);
|
||||
os_printf("low bit :%d\r\n",header->u.cmd_submit.request.wValue.u8lo);
|
||||
os_printf("high bit :%d\r\n",header->u.cmd_submit.request.wValue.u8hi);
|
||||
printf("USB unknown Get Descriptor requested:%d\r\n", header->u.cmd_submit.request.wValue.u8lo);
|
||||
printf("low bit :%d\r\n", header->u.cmd_submit.request.wValue.u8lo);
|
||||
printf("high bit :%d\r\n", header->u.cmd_submit.request.wValue.u8hi);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,7 @@
|
|||
#include "usbip_server.h"
|
||||
#include "DAP_handle.h"
|
||||
#include "main/dap_configuration.h"
|
||||
#include "main/wifi_configuration.h"
|
||||
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
#include "cmsis-dap/include/DAP.h"
|
||||
#include "cmsis-dap/include/swo.h"
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
@ -30,14 +26,8 @@
|
|||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#if ((USE_MDNS == 1) || (USE_OTA == 1))
|
||||
#define DAP_BUFFER_NUM 10
|
||||
#else
|
||||
#define DAP_BUFFER_NUM 20
|
||||
#endif
|
||||
#define DAP_BUFFER_NUM 10
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
typedef struct
|
||||
|
@ -55,9 +45,6 @@ typedef struct
|
|||
#define DAP_HANDLE_SIZE (sizeof(DapPacket_t))
|
||||
|
||||
|
||||
extern int kSock;
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
|
||||
int kRestartDAPHandle = NO_SIGNAL;
|
||||
|
||||
|
||||
|
@ -116,13 +103,11 @@ void handle_dap_data_request(usbip_stage2_header *header, uint32_t length)
|
|||
// always send constant size buf -> cuz we don't care about the IN packet size
|
||||
// and to unify the style, we set aside the length of the section
|
||||
xRingbufferSend(dap_dataIN_handle, data_in - sizeof(uint32_t), DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#else
|
||||
send_stage2_submit(header, 0, 0);
|
||||
|
||||
xRingbufferSend(dap_dataIN_handle, data_in, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -188,7 +173,7 @@ void DAP_Thread(void *argument)
|
|||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL ||
|
||||
data_response_mux == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
for (;;)
|
||||
|
@ -204,7 +189,7 @@ void DAP_Thread(void *argument)
|
|||
malloc_dap_ringbuf();
|
||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +215,8 @@ void DAP_Thread(void *argument)
|
|||
|
||||
else if (packetSize < DAP_HANDLE_SIZE)
|
||||
{
|
||||
os_printf("Wrong data in packet size:%d , data in remain: %d\r\n", packetSize, (int)xRingbufferGetMaxItemSize(dap_dataIN_handle));
|
||||
printf("Wrong data in packet size:%d , data in remain: %d\r\n", packetSize,
|
||||
(int) xRingbufferGetMaxItemSize(dap_dataIN_handle));
|
||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item);
|
||||
break;
|
||||
// This may not happen because there is a semaphore acquisition
|
||||
|
@ -294,7 +280,7 @@ int fast_reply(uint8_t *buf, uint32_t length)
|
|||
}
|
||||
else if (packetSize > 0)
|
||||
{
|
||||
os_printf("Wrong data out packet size:%d!\r\n", packetSize);
|
||||
printf("Wrong data out packet size:%d!\r\n", packetSize);
|
||||
}
|
||||
////TODO: fast reply
|
||||
}
|
||||
|
|
|
@ -17,12 +17,10 @@
|
|||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
extern int kRestartDAPHandle;
|
||||
|
||||
uint8_t kState = ACCEPTING;
|
||||
|
@ -60,10 +58,10 @@ void tcp_server_task(void *pvParameters)
|
|||
int listen_sock = socket(addr_family, SOCK_STREAM, ip_protocol);
|
||||
if (listen_sock < 0)
|
||||
{
|
||||
os_printf("Unable to create socket: errno %d\r\n", errno);
|
||||
printf("Unable to create socket: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket created\r\n");
|
||||
printf("Socket created\r\n");
|
||||
|
||||
setsockopt(listen_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(listen_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
|
@ -71,18 +69,18 @@ void tcp_server_task(void *pvParameters)
|
|||
int err = bind(listen_sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Socket unable to bind: errno %d\r\n", errno);
|
||||
printf("Socket unable to bind: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket binded\r\n");
|
||||
printf("Socket binded\r\n");
|
||||
|
||||
err = listen(listen_sock, 1);
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Error occured during listen: errno %d\r\n", errno);
|
||||
printf("Error occured during listen: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket listening\r\n");
|
||||
printf("Socket listening\r\n");
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
struct sockaddr_in6 sourceAddr; // Large enough for both IPv4 or IPv6
|
||||
|
@ -95,12 +93,12 @@ void tcp_server_task(void *pvParameters)
|
|||
kSock = accept(listen_sock, (struct sockaddr *)&sourceAddr, &addrLen);
|
||||
if (kSock < 0)
|
||||
{
|
||||
os_printf("Unable to accept connection: errno %d\r\n", errno);
|
||||
printf("Unable to accept connection: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
setsockopt(kSock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(kSock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
os_printf("Socket accepted\r\n");
|
||||
printf("Socket accepted\r\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -108,13 +106,13 @@ void tcp_server_task(void *pvParameters)
|
|||
// Error occured during receiving
|
||||
if (len < 0)
|
||||
{
|
||||
os_printf("recv failed: errno %d\r\n", errno);
|
||||
printf("recv failed: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
// Connection closed
|
||||
else if (len == 0)
|
||||
{
|
||||
os_printf("Connection closed\r\n");
|
||||
printf("Connection closed\r\n");
|
||||
break;
|
||||
}
|
||||
// Data received
|
||||
|
@ -159,14 +157,14 @@ void tcp_server_task(void *pvParameters)
|
|||
el_dap_data_process(tcp_rx_buffer, len);
|
||||
break;
|
||||
default:
|
||||
os_printf("unkonw kstate!\r\n");
|
||||
printf("unkonw kstate!\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
// kState = ACCEPTING;
|
||||
if (kSock != -1)
|
||||
{
|
||||
os_printf("Shutting down socket and restarting...\r\n");
|
||||
printf("Shutting down socket and restarting...\r\n");
|
||||
//shutdown(kSock, 0);
|
||||
close(kSock);
|
||||
if (kState == EMULATING || kState == EL_DATA_PHASE)
|
||||
|
@ -176,8 +174,6 @@ void tcp_server_task(void *pvParameters)
|
|||
el_process_buffer_free();
|
||||
|
||||
kRestartDAPHandle = RESET_HANDLE;
|
||||
if (kDAPTaskHandle)
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
//shutdown(listen_sock, 0);
|
||||
//close(listen_sock);
|
||||
|
|
|
@ -3,15 +3,12 @@
|
|||
|
||||
#include "usbip_server.h"
|
||||
#include "DAP_handle.h"
|
||||
#include "main/wifi_configuration.h"
|
||||
|
||||
#include "components/USBIP/usb_handle.h"
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
|
||||
// attach helper function
|
||||
|
@ -56,7 +53,7 @@ int attach(uint8_t *buffer, uint32_t length)
|
|||
break;
|
||||
|
||||
default:
|
||||
os_printf("attach Unknown command: %d\r\n", command);
|
||||
printf("attach Unknown command: %d\r\n", command);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -74,19 +71,19 @@ static int read_stage1_command(uint8_t *buffer, uint32_t length)
|
|||
|
||||
static void handle_device_list(uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
os_printf("Handling dev list request...\r\n");
|
||||
printf("Handling dev list request...\r\n");
|
||||
send_stage1_header(USBIP_STAGE1_CMD_DEVICE_LIST, 0);
|
||||
send_device_list();
|
||||
}
|
||||
|
||||
static void handle_device_attach(uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
os_printf("Handling dev attach request...\r\n");
|
||||
printf("Handling dev attach request...\r\n");
|
||||
|
||||
//char bus[USBIP_BUSID_SIZE];
|
||||
if (length < sizeof(USBIP_BUSID_SIZE))
|
||||
{
|
||||
os_printf("handle device attach failed!\r\n");
|
||||
printf("handle device attach failed!\r\n");
|
||||
return;
|
||||
}
|
||||
//client.readBytes((uint8_t *)bus, USBIP_BUSID_SIZE);
|
||||
|
@ -100,7 +97,7 @@ static void handle_device_attach(uint8_t *buffer, uint32_t length)
|
|||
|
||||
static void send_stage1_header(uint16_t command, uint32_t status)
|
||||
{
|
||||
os_printf("Sending header...\r\n");
|
||||
printf("Sending header...\r\n");
|
||||
usbip_stage1_header header;
|
||||
header.version = htons(273); ////TODO: 273???
|
||||
// may be : https://github.com/Oxalin/usbip_windows/issues/4
|
||||
|
@ -113,10 +110,10 @@ static void send_stage1_header(uint16_t command, uint32_t status)
|
|||
|
||||
static void send_device_list()
|
||||
{
|
||||
os_printf("Sending device list...\r\n");
|
||||
printf("Sending device list...\r\n");
|
||||
|
||||
// send device list size:
|
||||
os_printf("Sending device list size...\r\n");
|
||||
printf("Sending device list size...\r\n");
|
||||
usbip_stage1_response_devlist response_devlist;
|
||||
|
||||
// we have only 1 device, so:
|
||||
|
@ -136,7 +133,7 @@ static void send_device_list()
|
|||
|
||||
static void send_device_info()
|
||||
{
|
||||
os_printf("Sending device info...\r\n");
|
||||
printf("Sending device info...\r\n");
|
||||
usbip_stage1_usb_device device;
|
||||
|
||||
strcpy(device.path, "/sys/devices/pci0000:00/0000:00:01.2/usb1/1-1");
|
||||
|
@ -163,7 +160,7 @@ static void send_device_info()
|
|||
|
||||
static void send_interface_info()
|
||||
{
|
||||
os_printf("Sending interface info...\r\n");
|
||||
printf("Sending interface info...\r\n");
|
||||
usbip_stage1_usb_interface interface;
|
||||
interface.bInterfaceClass = USBD_CUSTOM_CLASS0_IF0_CLASS;
|
||||
interface.bInterfaceSubClass = USBD_CUSTOM_CLASS0_IF0_SUBCLASS;
|
||||
|
@ -207,7 +204,7 @@ int emulate(uint8_t *buffer, uint32_t length)
|
|||
break;
|
||||
|
||||
default:
|
||||
os_printf("emulate unknown command:%d\r\n", command);
|
||||
printf("emulate unknown command:%d\r\n", command);
|
||||
//handle_submit((usbip_stage2_header *)buffer, length);
|
||||
return -1;
|
||||
}
|
||||
|
@ -317,16 +314,16 @@ static int handle_submit(usbip_stage2_header *header, uint32_t length)
|
|||
case 0x81:
|
||||
if (header->base.direction == 0)
|
||||
{
|
||||
os_printf("*** WARN! EP 81 DATA TX");
|
||||
printf("*** WARN! EP 81 DATA TX");
|
||||
}
|
||||
else
|
||||
{
|
||||
os_printf("*** WARN! EP 81 DATA RX");
|
||||
printf("*** WARN! EP 81 DATA RX");
|
||||
}
|
||||
return -1;
|
||||
|
||||
default:
|
||||
os_printf("*** WARN ! UNKNOWN ENDPOINT: %d\r\n", (int)header->base.ep);
|
||||
printf("*** WARN ! UNKNOWN ENDPOINT: %d\r\n", (int) header->base.ep);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -377,7 +374,7 @@ void send_stage2_submit_data_fast(usbip_stage2_header *req_header, const void *c
|
|||
|
||||
static void handle_unlink(usbip_stage2_header *header)
|
||||
{
|
||||
os_printf("s2 handling cmd unlink...\r\n");
|
||||
printf("s2 handling cmd unlink...\r\n");
|
||||
handle_dap_unlink();
|
||||
send_stage2_unlink(header);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
#include "components/elaphureLink/elaphureLink_protocol.h"
|
||||
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
extern int kSock;
|
||||
extern int usbip_network_send(int s, const void *dataptr, size_t size, int flags);
|
||||
|
|
22
main/main.c
22
main/main.c
|
@ -1,14 +1,5 @@
|
|||
/* BSD Socket API Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "tcp_server.h"
|
||||
#include "main/wifi_configuration.h"
|
||||
|
@ -18,23 +9,12 @@
|
|||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#include "mdns.h"
|
||||
|
||||
|
||||
TaskHandle_t kDAPTaskHandle = NULL;
|
||||
|
||||
static const char *MDNS_TAG = "server_common";
|
||||
|
||||
void mdns_setup() {
|
||||
|
@ -76,5 +56,5 @@ void app_main() {
|
|||
xTaskCreate(tcp_server_task, "tcp_server", 4096, NULL, 14, NULL);
|
||||
|
||||
// DAP handle task
|
||||
xTaskCreate(DAP_Thread, "DAP_Task", 2048, NULL, 10, &kDAPTaskHandle);
|
||||
xTaskCreate(DAP_Thread, "DAP_Task", 2048, NULL, 10, NULL);
|
||||
}
|
||||
|
|
|
@ -34,29 +34,11 @@ static struct {
|
|||
#define DAP_IP_ADDRESS 192, 168, 137, 123
|
||||
#define DAP_IP_GATEWAY 192, 168, 137, 1
|
||||
#define DAP_IP_NETMASK 255, 255, 255, 0
|
||||
//
|
||||
|
||||
#define USE_OTA 0
|
||||
|
||||
#define USE_UART_BRIDGE 0
|
||||
#define UART_BRIDGE_PORT 1234
|
||||
#define UART_BRIDGE_BAUDRATE 74880
|
||||
//
|
||||
|
||||
// DO NOT CHANGE
|
||||
#define USE_TCP_NETCONN 0
|
||||
|
||||
#define PORT 3240
|
||||
#define CONFIG_EXAMPLE_IPV4 1
|
||||
#define USE_KCP 0
|
||||
#define MTU_SIZE 1500
|
||||
//
|
||||
|
||||
|
||||
|
||||
extern int printf(const char *, ...);
|
||||
inline int os_printf(const char *__restrict __fmt, ...) {
|
||||
return printf(__fmt, __builtin_va_arg_pack());
|
||||
}
|
||||
|
||||
#endif
|
|
@ -57,13 +57,13 @@ static void event_handler(void *handler_arg __attribute__((unused)),
|
|||
ip_event_got_ip_t *event = event_data;
|
||||
// GPIO_SET_LEVEL_HIGH(PIN_LED_WIFI_STATUS);
|
||||
xEventGroupSetBits(wifi_event_group, IPV4_GOTIP_BIT);
|
||||
os_printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa((const ip4_addr_t *) &event->ip_info.ip));
|
||||
printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa((const ip4_addr_t *) &event->ip_info.ip));
|
||||
break;
|
||||
}
|
||||
case WIFI_EVENT_STA_DISCONNECTED: {
|
||||
wifi_event_sta_disconnected_t *event = event_data;
|
||||
// GPIO_SET_LEVEL_LOW(PIN_LED_WIFI_STATUS);
|
||||
os_printf("Disconnect reason : %d\r\n", event->reason);
|
||||
printf("Disconnect reason : %d\r\n", event->reason);
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) {
|
||||
|
@ -78,9 +78,6 @@ static void event_handler(void *handler_arg __attribute__((unused)),
|
|||
xEventGroupClearBits(wifi_event_group, IPV6_GOTIP_BIT);
|
||||
#endif
|
||||
|
||||
#if (USE_UART_BRIDGE == 1)
|
||||
uart_bridge_close();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case IP_EVENT_GOT_IP6: {
|
||||
|
@ -123,9 +120,9 @@ static void wait_for_ip() {
|
|||
uint32_t bits = IPV4_GOTIP_BIT;
|
||||
#endif
|
||||
|
||||
os_printf("Waiting for AP connection...\r\n");
|
||||
printf("Waiting for AP connection...\r\n");
|
||||
xEventGroupWaitBits(wifi_event_group, bits, false, true, portMAX_DELAY);
|
||||
os_printf("Connected to AP\r\n");
|
||||
printf("Connected to AP\r\n");
|
||||
}
|
||||
|
||||
void wifi_init(void) {
|
||||
|
|
Loading…
Reference in New Issue