-
Notifications
You must be signed in to change notification settings - Fork 7k
/
usb_serial_jtag.h
87 lines (77 loc) · 2.68 KB
/
usb_serial_jtag.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Configuration structure for the usb-serial-jtag-driver. Can be expanded in the future
*
* @note tx_buffer_size and rx_buffer_size must be > 0
*/
typedef struct {
uint32_t tx_buffer_size; /* Size of the buffer (in bytes) for the TX direction */
uint32_t rx_buffer_size; /* Size of the buffer (in bytes) for the RX direction */
} usb_serial_jtag_driver_config_t;
#define USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT() (usb_serial_jtag_driver_config_t) {\
.tx_buffer_size = 256,\
.rx_buffer_size = 256,\
}
/**
* @brief Install USB-SERIAL-JTAG driver and set the USB-SERIAL-JTAG to the default configuration.
*
* USB-SERIAL-JTAG driver's ISR will be attached to the same CPU core that calls this function. Thus, users
* should ensure that the same core is used when calling `usb_serial_jtag_driver_uninstall()`.
*
* @note Blocking mode will result in usb_serial_jtag_write_bytes() blocking for a
* short period if the TX FIFO if full. It will not block again until the buffer
* has some space available again.
*
* @param usb_serial_jtag_driver_config_t Configuration for usb_serial_jtag driver.
*
* @return
* - ESP_OK Success
* - ESP_FAIL Failed for some reason.
*/
esp_err_t usb_serial_jtag_driver_install(usb_serial_jtag_driver_config_t *usb_serial_jtag_config);
/**
* @brief USB_SERIAL_JTAG read bytes from USB_SERIAL_JTAG buffer
*
* @param buf pointer to the buffer.
* @param length data length
* @param ticks_to_wait Timeout in RTOS ticks
*
* @return
* - The number of bytes read from USB_SERIAL FIFO
*/
int usb_serial_jtag_read_bytes(void* buf, uint32_t length, TickType_t ticks_to_wait);
/**
* @brief Send data to the USB-UART port from a given buffer and length,
*
* Please ensure the `tx_buffer_size is larger than 0`, if the 'tx_buffer_size' > 0, this function will return after copying all the data to tx ring buffer,
* USB_SERIAL_JTAG ISR will then move data from the ring buffer to TX FIFO gradually.
*
* @param src data buffer address
* @param size data length to send
* @param ticks_to_wait Maximum timeout in RTOS ticks
*
* @return
* - The number of bytes pushed to the TX FIFO
*/
int usb_serial_jtag_write_bytes(const void* src, size_t size, TickType_t ticks_to_wait);
/**
* @brief Uninstall USB-SERIAL-JTAG driver.
*
* @return
* - ESP_OK Success
*/
esp_err_t usb_serial_jtag_driver_uninstall(void);
#ifdef __cplusplus
}
#endif