jtag/drivers: add support for Nu-Link (Nuvoton ICE) over usb
[fw/openocd] / src / jtag / hla / hla_layout.h
1 /***************************************************************************
2  *   Copyright (C) 2011 by Mathias Kuester                                 *
3  *   Mathias Kuester <kesmtp@freenet.de>                                   *
4  *                                                                         *
5  *   Copyright (C) 2012 by Spencer Oliver                                  *
6  *   spen@spen-soft.co.uk                                                  *
7  *                                                                         *
8  *   This program is free software; you can redistribute it and/or modify  *
9  *   it under the terms of the GNU General Public License as published by  *
10  *   the Free Software Foundation; either version 2 of the License, or     *
11  *   (at your option) any later version.                                   *
12  *                                                                         *
13  *   This program is distributed in the hope that it will be useful,       *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16  *   GNU General Public License for more details.                          *
17  *                                                                         *
18  *   You should have received a copy of the GNU General Public License     *
19  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
20  ***************************************************************************/
21
22 #ifndef OPENOCD_JTAG_HLA_HLA_LAYOUT_H
23 #define OPENOCD_JTAG_HLA_HLA_LAYOUT_H
24
25 #include <target/armv7m_trace.h>
26
27 /** */
28 struct hl_interface_s;
29 struct hl_interface_param_s;
30
31 /** */
32 extern struct hl_layout_api_s stlink_usb_layout_api;
33 extern struct hl_layout_api_s icdi_usb_layout_api;
34 extern struct hl_layout_api_s nulink_usb_layout_api;
35
36 /** */
37 struct hl_layout_api_s {
38         /** */
39         int (*open)(struct hl_interface_param_s *param, void **handle);
40         /** */
41         int (*close)(void *handle);
42         /** */
43         int (*reset)(void *handle);
44         /** */
45         int (*assert_srst)(void *handle, int srst);
46         /** */
47         int (*run)(void *handle);
48         /** */
49         int (*halt)(void *handle);
50         /** */
51         int (*step)(void *handle);
52         /** */
53         int (*read_regs)(void *handle);
54         /** */
55         int (*read_reg)(void *handle, int num, uint32_t *val);
56         /** */
57         int (*write_reg)(void *handle, int num, uint32_t val);
58         /** */
59         int (*read_mem)(void *handle, uint32_t addr, uint32_t size,
60                         uint32_t count, uint8_t *buffer);
61         /** */
62         int (*write_mem)(void *handle, uint32_t addr, uint32_t size,
63                         uint32_t count, const uint8_t *buffer);
64         /** */
65         int (*write_debug_reg)(void *handle, uint32_t addr, uint32_t val);
66         /**
67          * Read the idcode of the target connected to the adapter
68          *
69          * If the adapter doesn't support idcode retrieval, this callback should
70          * store 0 to indicate a wildcard match.
71          *
72          * @param handle A pointer to the device-specific handle
73          * @param idcode Storage for the detected idcode
74          * @returns ERROR_OK on success, or an error code on failure.
75          */
76         int (*idcode)(void *handle, uint32_t *idcode);
77         /** */
78         int (*override_target)(const char *targetname);
79         /** */
80         int (*custom_command)(void *handle, const char *command);
81         /** */
82         int (*speed)(void *handle, int khz, bool query);
83         /**
84          * Configure trace parameters for the adapter
85          *
86          * @param handle A handle to adapter
87          * @param enabled Whether to enable trace
88          * @param pin_protocol Configured pin protocol
89          * @param port_size Trace port width for sync mode
90          * @param trace_freq A pointer to the configured trace
91          * frequency; if it points to 0, the adapter driver must write
92          * its maximum supported rate there
93          * @returns ERROR_OK on success, an error code on failure.
94          */
95         int (*config_trace)(void *handle, bool enabled,
96                                 enum tpiu_pin_protocol pin_protocol, uint32_t port_size,
97                                 unsigned int *trace_freq, unsigned int traceclkin_freq,
98                                 uint16_t *prescaler);
99         /**
100          * Poll for new trace data
101          *
102          * @param handle A handle to adapter
103          * @param buf A pointer to buffer to store received data
104          * @param size A pointer to buffer size; must be filled with
105          * the actual amount of bytes written
106          *
107          * @returns ERROR_OK on success, an error code on failure.
108          */
109         int (*poll_trace)(void *handle, uint8_t *buf, size_t *size);
110         /** */
111         enum target_state (*state)(void *fd);
112 };
113
114 /** */
115 struct hl_layout {
116         /** */
117         char *name;
118         /** */
119         int (*open)(struct hl_interface_s *adapter);
120         /** */
121         int (*close)(struct hl_interface_s *adapter);
122         /** */
123         struct hl_layout_api_s *api;
124 };
125
126 /** */
127 const struct hl_layout *hl_layout_get_list(void);
128 /** */
129 int hl_layout_init(struct hl_interface_s *adapter);
130
131 #endif /* OPENOCD_JTAG_HLA_HLA_LAYOUT_H */