- Cable driver helper API courtesy of Dick Hollenbeck <dick@softplc.com>
[openocd.git] / src / jtag / dummy.c
1 /***************************************************************************
2 * Copyright (C) 2008 by Øyvind Harboe *
3 * oyvind.harboe@zylin.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "replacements.h"
25
26 #include "jtag.h"
27 #include "bitbang.h"
28
29
30 /* my private tap controller state, which tracks state for calling code */
31 static tap_state_t dummy_state = TAP_RESET;
32
33 static int dummy_clock; /* edge detector */
34
35 static int clock_count; /* count clocks in any stable state, only stable states */
36
37 static u32 dummy_data;
38
39
40 int dummy_speed(int speed);
41 int dummy_register_commands(struct command_context_s *cmd_ctx);
42 int dummy_init(void);
43 int dummy_quit(void);
44 static int dummy_khz(int khz, int *jtag_speed);
45 static int dummy_speed_div(int speed, int *khz);
46
47
48 /* The dummy driver is used to easily check the code path
49 * where the target is unresponsive.
50 */
51 jtag_interface_t dummy_interface =
52 {
53 .name = "dummy",
54
55 .execute_queue = bitbang_execute_queue,
56
57 .speed = dummy_speed,
58 .register_commands = dummy_register_commands,
59 .khz = dummy_khz,
60 .speed_div = dummy_speed_div,
61
62 .init = dummy_init,
63 .quit = dummy_quit,
64 };
65
66 int dummy_read(void);
67 void dummy_write(int tck, int tms, int tdi);
68 void dummy_reset(int trst, int srst);
69 void dummy_led(int on);
70
71 bitbang_interface_t dummy_bitbang =
72 {
73 .read = dummy_read,
74 .write = dummy_write,
75 .reset = dummy_reset,
76 .blink = dummy_led
77 };
78
79 int dummy_read(void)
80 {
81 int data = 1 & dummy_data;
82 dummy_data = (dummy_data >> 1) | (1<<31);
83 return data;
84 }
85
86
87 void dummy_write(int tck, int tms, int tdi)
88 {
89 /* TAP standard: "state transitions occur on rising edge of clock" */
90 if( tck != dummy_clock )
91 {
92 if( tck )
93 {
94 int old_state = dummy_state;
95 dummy_state = tap_state_transition( old_state, tms );
96
97 if( old_state != dummy_state )
98 {
99 if( clock_count )
100 {
101 LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);
102 clock_count = 0;
103 }
104
105 LOG_DEBUG("dummy_tap: %s", tap_state_name(dummy_state) );
106
107 #if defined(DEBUG)
108 if(dummy_state == TAP_DRCAPTURE)
109 dummy_data = 0x01255043;
110 #endif
111 }
112 else
113 {
114 /* this is a stable state clock edge, no change of state here,
115 * simply increment clock_count for subsequent logging
116 */
117 ++clock_count;
118 }
119 }
120 dummy_clock = tck;
121 }
122 }
123
124 void dummy_reset(int trst, int srst)
125 {
126 dummy_clock = 0;
127
128 if (trst || (srst && (jtag_reset_config & RESET_SRST_PULLS_TRST)))
129 dummy_state = TAP_RESET;
130
131 LOG_DEBUG("reset to: %s", tap_state_name(dummy_state) );
132 }
133
134 static int dummy_khz(int khz, int *jtag_speed)
135 {
136 if (khz==0)
137 {
138 *jtag_speed=0;
139 }
140 else
141 {
142 *jtag_speed=64000/khz;
143 }
144 return ERROR_OK;
145 }
146
147 static int dummy_speed_div(int speed, int *khz)
148 {
149 if (speed==0)
150 {
151 *khz = 0;
152 }
153 else
154 {
155 *khz=64000/speed;
156 }
157
158 return ERROR_OK;
159 }
160
161 int dummy_speed(int speed)
162 {
163 return ERROR_OK;
164 }
165
166 int dummy_register_commands(struct command_context_s *cmd_ctx)
167 {
168 return ERROR_OK;
169 }
170
171 int dummy_init(void)
172 {
173 bitbang_interface = &dummy_bitbang;
174
175 return ERROR_OK;
176 }
177
178 int dummy_quit(void)
179 {
180 return ERROR_OK;
181 }
182
183 void dummy_led(int on)
184 {
185 }
186

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)