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
8 struct cmsis_dap_backend
;
9 struct cmsis_dap_backend_data
;
11 struct pending_transfer_result
{
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
;
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
;
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
;
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
;
55 bool quirk_mode
; /* enable expensive workarounds */
61 struct cmsis_dap_backend
{
63 int (*open
)(struct cmsis_dap
*dap
, uint16_t vids
[], uint16_t pids
[], const char *serial
);
64 void (*close
)(struct cmsis_dap
*dap
);
65 int (*read
)(struct cmsis_dap
*dap
, int transfer_timeout_ms
,
66 struct timeval
*wait_timeout
);
67 int (*write
)(struct cmsis_dap
*dap
, int len
, int timeout_ms
);
68 int (*packet_buffer_alloc
)(struct cmsis_dap
*dap
, unsigned int pkt_sz
);
69 void (*packet_buffer_free
)(struct cmsis_dap
*dap
);
70 void (*cancel_all
)(struct cmsis_dap
*dap
);
73 extern const struct cmsis_dap_backend cmsis_dap_hid_backend
;
74 extern const struct cmsis_dap_backend cmsis_dap_usb_backend
;
75 extern const struct command_registration cmsis_dap_usb_subcommand_handlers
[];
77 #define REPORT_ID_SIZE 1