initial "transport" framework
[fw/openocd] / src / jtag / transport.h
1 /*
2  * Copyright (c) 2010 by David Brownell
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "helper/command.h"
20
21 /**
22  * Wrapper for transport lifecycle operations.
23  *
24  * OpenOCD talks to targets through some kind of debugging
25  * or programming adapter, using some protocol that probably
26  * has target-specific aspects.
27  *
28  * A "transport" reflects electrical protocol to the target,
29  * e..g jtag, swd, spi, uart, ... NOT the messaging protocols
30  * layered over it (e.g. JTAG has eICE, CoreSight, Nexus, OnCE,
31  * and more).
32  *
33  * In addition to the lifecycle operations packaged by this
34  * structure, a transport also involves  an interface supported
35  * by debug adapters and used by components such as debug targets.
36  * For non-debug transports,  there may be interfaces used to
37  * write to flash chips.
38  */
39 struct transport {
40         /**
41          * Each transport has a unique name, used to select it
42          * from among the alternatives.  Examples might include
43          * "jtag", * "swd", "AVR_ISP" and more.
44          */
45         const char *name;
46
47         /**
48          * When a transport is selected, this method registers
49          * its commands and activates the transport (e.g. resets
50          * the link).
51          *
52          * After those commands are registered, they will often
53          * be used for further configuration of the debug link.
54          */
55         int (*select)(struct command_context *ctx);
56
57         /**
58          * server startup uses this method to validate transport
59          * configuration.  (For example, with JTAG this interrogates
60          * the scan chain against the list of expected TAPs.)
61          */
62         int (*init)(struct command_context *ctx);
63
64         /**
65          * Transports are stored in a singly linked list.
66          */
67         struct transport *next;
68 };
69
70 int transport_register(struct transport *new_transport);
71
72 struct transport *get_current_transport(void);
73
74 int transport_register_commands(struct command_context *ctx);
75
76 COMMAND_HELPER(transport_list_parse, char ***vector);
77
78 int allow_transports(struct command_context *ctx, const char **vector);
79
80 bool transports_are_declared(void);