7516c24a612a471d08a2501c2ae9aeadba740833
[fw/openocd] / src / jtag / drivers / bitbang.h
1 /***************************************************************************
2  *   Copyright (C) 2005 by Dominic Rath                                    *
3  *   Dominic.Rath@gmx.de                                                   *
4  *                                                                         *
5  *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                 *
6  *   oyvind.harboe@zylin.com                                               *
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_DRIVERS_BITBANG_H
23 #define OPENOCD_JTAG_DRIVERS_BITBANG_H
24
25 #include <jtag/swd.h>
26
27 typedef enum {
28         BB_LOW,
29         BB_HIGH,
30         BB_ERROR
31 } bb_value_t;
32
33 /** Low level callbacks (for bitbang).
34  *
35  * Either read(), or sample() and read_sample() must be implemented.
36  *
37  * The sample functions allow an interface to batch a number of writes and
38  * sample requests together. Not waiting for a value to come back can greatly
39  * increase throughput. */
40 struct bitbang_interface {
41         /** Sample TDO and return the value. */
42         bb_value_t (*read)(void);
43
44         /** The number of TDO samples that can be buffered up before the caller has
45          * to call read_sample. */
46         size_t buf_size;
47
48         /** Sample TDO and put the result in a buffer. */
49         int (*sample)(void);
50
51         /** Return the next unread value from the buffer. */
52         bb_value_t (*read_sample)(void);
53
54         /** Set TCK, TMS, and TDI to the given values. */
55         int (*write)(int tck, int tms, int tdi);
56
57         /** Blink led (optional). */
58         int (*blink)(int on);
59
60         /** Sample SWDIO and return the value. */
61         int (*swdio_read)(void);
62
63         /** Set direction of SWDIO. */
64         void (*swdio_drive)(bool on);
65 };
66
67 extern const struct swd_driver bitbang_swd;
68
69 extern bool swd_mode;
70
71 int bitbang_execute_queue(void);
72
73 extern struct bitbang_interface *bitbang_interface;
74 void bitbang_switch_to_swd(void);
75 int bitbang_swd_switch_seq(enum swd_special_seq seq);
76
77 #endif /* OPENOCD_JTAG_DRIVERS_BITBANG_H */