1 /***************************************************************************
\r
2 * Copyright (C) 2008 by Øyvind Harboe *
\r
3 * oyvind.harboe@zylin.com *
\r
5 * This program is free software; you can redistribute it and/or modify *
\r
6 * it under the terms of the GNU General Public License as published by *
\r
7 * the Free Software Foundation; either version 2 of the License, or *
\r
8 * (at your option) any later version. *
\r
10 * This program is distributed in the hope that it will be useful, *
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
13 * GNU General Public License for more details. *
\r
15 * You should have received a copy of the GNU General Public License *
\r
16 * along with this program; if not, write to the *
\r
17 * Free Software Foundation, Inc., *
\r
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
\r
19 ***************************************************************************/
\r
20 #ifdef HAVE_CONFIG_H
\r
24 #include "replacements.h"
\r
27 #include "bitbang.h"
\r
30 /* my private tap controller state, which tracks state for calling code */
\r
31 static tap_state_t dummy_state = TAP_RESET;
\r
33 static int dummy_clock; /* edge detector */
\r
35 static int clock_count; /* count clocks in any stable state, only stable states */
\r
38 static tap_state_t tap_state_transition(tap_state_t cur_state, int tms);
\r
40 static u32 dummy_data;
\r
43 int dummy_speed(int speed);
\r
44 int dummy_register_commands(struct command_context_s *cmd_ctx);
\r
45 int dummy_init(void);
\r
46 int dummy_quit(void);
\r
47 static int dummy_khz(int khz, int *jtag_speed);
\r
48 static int dummy_speed_div(int speed, int *khz);
\r
51 /* The dummy driver is used to easily check the code path
\r
52 * where the target is unresponsive.
\r
54 jtag_interface_t dummy_interface =
\r
58 .execute_queue = bitbang_execute_queue,
\r
60 .speed = dummy_speed,
\r
61 .register_commands = dummy_register_commands,
\r
63 .speed_div = dummy_speed_div,
\r
69 int dummy_read(void);
\r
70 void dummy_write(int tck, int tms, int tdi);
\r
71 void dummy_reset(int trst, int srst);
\r
72 void dummy_led(int on);
\r
74 bitbang_interface_t dummy_bitbang =
\r
77 .write = dummy_write,
\r
78 .reset = dummy_reset,
\r
82 int dummy_read(void)
\r
84 int data = 1 & dummy_data;
\r
85 dummy_data = (dummy_data >> 1) | (1<<31);
\r
90 void dummy_write(int tck, int tms, int tdi)
\r
92 /* TAP standard: "state transitions occur on rising edge of clock" */
\r
93 if( tck != dummy_clock )
\r
97 int old_state = dummy_state;
\r
98 dummy_state = tap_state_transition( old_state, tms );
\r
100 if( old_state != dummy_state )
\r
104 LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);
\r
108 LOG_DEBUG("dummy_tap: %s", jtag_state_name(dummy_state) );
\r
111 if(dummy_state == TAP_DRCAPTURE)
\r
112 dummy_data = 0x01255043;
\r
117 /* this is a stable state clock edge, no change of state here,
\r
118 * simply increment clock_count for subsequent logging
\r
127 void dummy_reset(int trst, int srst)
\r
131 if (trst || (srst && (jtag_reset_config & RESET_SRST_PULLS_TRST)))
\r
132 dummy_state = TAP_RESET;
\r
134 LOG_DEBUG("reset to: %s", jtag_state_name(dummy_state) );
\r
137 static int dummy_khz(int khz, int *jtag_speed)
\r
145 *jtag_speed=64000/khz;
\r
150 static int dummy_speed_div(int speed, int *khz)
\r
164 int dummy_speed(int speed)
\r
169 int dummy_register_commands(struct command_context_s *cmd_ctx)
\r
174 int dummy_init(void)
\r
176 bitbang_interface = &dummy_bitbang;
\r
181 int dummy_quit(void)
\r
186 void dummy_led(int on)
\r
192 * Function tap_state_transition
\r
193 * takes a current TAP state and returns the next state according to the tms value.
\r
195 * Even though there is code to duplicate this elsewhere, we do it here a little
\r
196 * differently just to get a second opinion, i.e. a verification, on state tracking
\r
197 * in that other logic. Plus array lookups without index checking are no favorite thing.
\r
198 * This is educational for developers new to TAP controllers.
\r
200 static tap_state_t tap_state_transition(tap_state_t cur_state, int tms)
\r
202 tap_state_t new_state;
\r
209 new_state = cur_state;
\r
214 new_state = TAP_DRSELECT;
\r
217 new_state = TAP_IRSELECT;
\r
219 case TAP_DRCAPTURE:
\r
221 new_state = TAP_DREXIT1;
\r
225 new_state = TAP_DRUPDATE;
\r
228 new_state = TAP_DREXIT2;
\r
231 new_state = TAP_RESET;
\r
233 case TAP_IRCAPTURE:
\r
235 new_state = TAP_IREXIT1;
\r
239 new_state = TAP_IRUPDATE;
\r
242 new_state = TAP_IREXIT2;
\r
245 LOG_ERROR( "fatal: invalid argument cur_state=%d", cur_state );
\r
258 new_state = TAP_IDLE;
\r
261 new_state = TAP_DRCAPTURE;
\r
263 case TAP_DRCAPTURE:
\r
266 new_state = TAP_DRSHIFT;
\r
270 new_state = TAP_DRPAUSE;
\r
273 new_state = TAP_IRCAPTURE;
\r
275 case TAP_IRCAPTURE:
\r
278 new_state = TAP_IRSHIFT;
\r
282 new_state = TAP_IRPAUSE;
\r
285 LOG_ERROR( "fatal: invalid argument cur_state=%d", cur_state );
\r