jtag/drivers/cmsis_dap: speed up long transfers using DAP_TransferBlock
[openocd.git] / src / jtag / drivers / cmsis_dap.h
blob16885a51d420e1b1d7bbddfa28b9f0c5eca77bb6
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #ifndef OPENOCD_JTAG_DRIVERS_CMSIS_DAP_H
4 #define OPENOCD_JTAG_DRIVERS_CMSIS_DAP_H
6 #include <stdint.h>
8 struct cmsis_dap_backend;
9 struct cmsis_dap_backend_data;
11 struct pending_transfer_result {
12 uint8_t cmd;
13 uint32_t data;
14 void *buffer;
17 /* Up to MIN(packet_count, MAX_PENDING_REQUESTS) requests may be issued
18 * until the first response arrives */
19 #define MAX_PENDING_REQUESTS 4
21 struct pending_request_block {
22 struct pending_transfer_result *transfers;
23 unsigned int transfer_count;
24 uint8_t command;
27 struct cmsis_dap {
28 struct cmsis_dap_backend_data *bdata;
29 const struct cmsis_dap_backend *backend;
30 unsigned int packet_size;
31 unsigned int packet_usable_size;
32 unsigned int packet_buffer_size;
33 uint8_t *packet_buffer;
34 uint8_t *command;
35 uint8_t *response;
37 /* DP/AP register r/w operation counters used for checking the packet size
38 * that would result from the queue run */
39 unsigned int write_count;
40 unsigned int read_count;
42 /* We can use DAP_TransferBlock only if all SWD operations in the packet
43 * are either all writes or all reads and use the same DP/AP register.
44 * The following variables keep track of it */
45 uint8_t common_swd_cmd;
46 bool swd_cmds_differ;
48 /* Pending requests are organized as a FIFO - circular buffer */
49 struct pending_request_block pending_fifo[MAX_PENDING_REQUESTS];
50 unsigned int packet_count;
51 unsigned int pending_fifo_put_idx, pending_fifo_get_idx;
52 unsigned int pending_fifo_block_count;
54 uint16_t caps;
55 uint8_t mode;
56 uint32_t swo_buf_sz;
57 bool trace_enabled;
60 struct cmsis_dap_backend {
61 const char *name;
62 int (*open)(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], const char *serial);
63 void (*close)(struct cmsis_dap *dap);
64 int (*read)(struct cmsis_dap *dap, int timeout_ms);
65 int (*write)(struct cmsis_dap *dap, int len, int timeout_ms);
66 int (*packet_buffer_alloc)(struct cmsis_dap *dap, unsigned int pkt_sz);
69 extern const struct cmsis_dap_backend cmsis_dap_hid_backend;
70 extern const struct cmsis_dap_backend cmsis_dap_usb_backend;
71 extern const struct command_registration cmsis_dap_usb_subcommand_handlers[];
73 #define REPORT_ID_SIZE 1
75 #endif