openocd: src: replace the GPL-2.0-or-later license tag
[fw/openocd] / src / transport / transport.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 /*
4  * Copyright (c) 2010 by David Brownell
5  * Copyright (C) 2011 Tomasz Boleslaw CEDRO (http://www.tomek.cedro.info)
6  */
7
8 #ifndef OPENOCD_TRANSPORT_TRANSPORT_H
9 #define OPENOCD_TRANSPORT_TRANSPORT_H
10
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14
15 #include "helper/command.h"
16
17 /**
18  * Wrapper for transport lifecycle operations.
19  *
20  * OpenOCD talks to targets through some kind of debugging
21  * or programming adapter, using some protocol that probably
22  * has target-specific aspects.
23  *
24  * A "transport" reflects electrical protocol to the target,
25  * e..g jtag, swd, spi, uart, ... NOT the messaging protocols
26  * layered over it (e.g. JTAG has eICE, CoreSight, Nexus, OnCE,
27  * and more).
28  *
29  * In addition to the lifecycle operations packaged by this
30  * structure, a transport also involves  an interface supported
31  * by debug adapters and used by components such as debug targets.
32  * For non-debug transports,  there may be interfaces used to
33  * write to flash chips.
34  */
35 struct transport {
36         /**
37          * Each transport has a unique name, used to select it
38          * from among the alternatives.  Examples might include
39          * "jtag", * "swd", "AVR_ISP" and more.
40          */
41         const char *name;
42
43         /**
44          * When a transport is selected, this method registers
45          * its commands and activates the transport (e.g. resets
46          * the link).
47          *
48          * After those commands are registered, they will often
49          * be used for further configuration of the debug link.
50          */
51         int (*select)(struct command_context *ctx);
52
53         /**
54          * server startup uses this method to validate transport
55          * configuration.  (For example, with JTAG this interrogates
56          * the scan chain against the list of expected TAPs.)
57          */
58         int (*init)(struct command_context *ctx);
59
60         /**
61          * Optional. If defined, allows transport to override target
62          * name prior to initialisation.
63          *
64          * @returns ERROR_OK on success, or an error code on failure.
65          */
66         int (*override_target)(const char **targetname);
67
68         /**
69          * Transports are stored in a singly linked list.
70          */
71         struct transport *next;
72 };
73
74 int transport_register(struct transport *new_transport);
75
76 struct transport *get_current_transport(void);
77
78 int transport_register_commands(struct command_context *ctx);
79
80 COMMAND_HELPER(transport_list_parse, char ***vector);
81
82 int allow_transports(struct command_context *ctx, const char * const *vector);
83
84 bool transport_is_jtag(void);
85 bool transport_is_swd(void);
86 bool transport_is_dapdirect_jtag(void);
87 bool transport_is_dapdirect_swd(void);
88 bool transport_is_swim(void);
89
90 #if BUILD_HLADAPTER
91 bool transport_is_hla(void);
92 #else
93 static inline bool transport_is_hla(void)
94 {
95         return false;
96 }
97 #endif
98
99 #endif /* OPENOCD_TRANSPORT_TRANSPORT_H */