OpenOCD
cmsis_dap.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #ifndef OPENOCD_JTAG_DRIVERS_CMSIS_DAP_H
4 #define OPENOCD_JTAG_DRIVERS_CMSIS_DAP_H
5 
6 #include <stdint.h>
7 
8 struct cmsis_dap_backend;
10 
12  uint8_t cmd;
13  uint32_t data;
14  void *buffer;
15 };
16 
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
20 
23  unsigned int transfer_count;
24  uint8_t command;
25 };
26 
27 struct cmsis_dap {
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;
36 
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;
41 
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;
47 
48  /* Pending requests are organized as a FIFO - circular buffer */
50  unsigned int packet_count;
53 
54  uint16_t caps;
55  bool quirk_mode; /* enable expensive workarounds */
56 
57  uint32_t swo_buf_sz;
59 };
60 
62  const char *name;
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);
71 };
72 
73 extern const struct cmsis_dap_backend cmsis_dap_hid_backend;
74 extern const struct cmsis_dap_backend cmsis_dap_usb_backend;
76 
77 #define REPORT_ID_SIZE 1
78 
79 #endif
char * serial
Definition: adapter.c:43
#define MAX_PENDING_REQUESTS
Definition: cmsis_dap.h:19
const struct cmsis_dap_backend cmsis_dap_usb_backend
const struct command_registration cmsis_dap_usb_subcommand_handlers[]
const struct cmsis_dap_backend cmsis_dap_hid_backend
int(* read)(struct cmsis_dap *dap, int transfer_timeout_ms, struct timeval *wait_timeout)
Definition: cmsis_dap.h:65
void(* cancel_all)(struct cmsis_dap *dap)
Definition: cmsis_dap.h:70
const char * name
Definition: cmsis_dap.h:62
int(* packet_buffer_alloc)(struct cmsis_dap *dap, unsigned int pkt_sz)
Definition: cmsis_dap.h:68
void(* close)(struct cmsis_dap *dap)
Definition: cmsis_dap.h:64
void(* packet_buffer_free)(struct cmsis_dap *dap)
Definition: cmsis_dap.h:69
int(* open)(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], const char *serial)
Definition: cmsis_dap.h:63
int(* write)(struct cmsis_dap *dap, int len, int timeout_ms)
Definition: cmsis_dap.h:67
unsigned int packet_buffer_size
Definition: cmsis_dap.h:32
unsigned int packet_usable_size
Definition: cmsis_dap.h:31
struct pending_request_block pending_fifo[MAX_PENDING_REQUESTS]
Definition: cmsis_dap.h:49
unsigned int pending_fifo_put_idx
Definition: cmsis_dap.h:51
uint16_t caps
Definition: cmsis_dap.h:54
unsigned int packet_size
Definition: cmsis_dap.h:30
struct cmsis_dap_backend_data * bdata
Definition: cmsis_dap.h:28
unsigned int read_count
Definition: cmsis_dap.h:40
unsigned int pending_fifo_block_count
Definition: cmsis_dap.h:52
bool quirk_mode
Definition: cmsis_dap.h:55
bool trace_enabled
Definition: cmsis_dap.h:58
uint8_t * response
Definition: cmsis_dap.h:35
bool swd_cmds_differ
Definition: cmsis_dap.h:46
uint8_t common_swd_cmd
Definition: cmsis_dap.h:45
uint8_t * command
Definition: cmsis_dap.h:34
unsigned int packet_count
Definition: cmsis_dap.h:50
uint8_t * packet_buffer
Definition: cmsis_dap.h:33
unsigned int write_count
Definition: cmsis_dap.h:39
const struct cmsis_dap_backend * backend
Definition: cmsis_dap.h:29
unsigned int pending_fifo_get_idx
Definition: cmsis_dap.h:51
uint32_t swo_buf_sz
Definition: cmsis_dap.h:57
struct pending_transfer_result * transfers
Definition: cmsis_dap.h:22
unsigned int transfer_count
Definition: cmsis_dap.h:23