lpc3180_nand_controller: use register_commands()
[fw/openocd] / 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 "interface.h"
25 #include "bitbang.h"
26
27
28 /* my private tap controller state, which tracks state for calling code */
29 static tap_state_t dummy_state = TAP_RESET;
30
31 static int dummy_clock;         /* edge detector */
32
33 static int clock_count;         /* count clocks in any stable state, only stable states */
34
35 static uint32_t dummy_data;
36
37
38 static int dummy_read(void)
39 {
40         int data = 1 & dummy_data;
41         dummy_data = (dummy_data >> 1) | (1 << 31);
42         return data;
43 }
44
45
46 static void dummy_write(int tck, int tms, int tdi)
47 {
48         /* TAP standard: "state transitions occur on rising edge of clock" */
49         if (tck != dummy_clock)
50         {
51                 if (tck)
52                 {
53                         tap_state_t old_state = dummy_state;
54                         dummy_state = tap_state_transition(old_state, tms);
55
56                         if (old_state != dummy_state)
57                         {
58                                 if (clock_count)
59                                 {
60                                         LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);
61                                         clock_count = 0;
62                                 }
63
64                                 LOG_DEBUG("dummy_tap: %s", tap_state_name(dummy_state));
65
66 #if defined(DEBUG)
67                                 if (dummy_state == TAP_DRCAPTURE)
68                                         dummy_data = 0x01255043;
69 #endif
70                         }
71                         else
72                         {
73                                 /* this is a stable state clock edge, no change of state here,
74                                  * simply increment clock_count for subsequent logging
75                                  */
76                                 ++clock_count;
77                         }
78                 }
79                 dummy_clock = tck;
80         }
81 }
82
83 static void dummy_reset(int trst, int srst)
84 {
85         dummy_clock = 0;
86
87         if (trst || (srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
88                 dummy_state = TAP_RESET;
89
90         LOG_DEBUG("reset to: %s", tap_state_name(dummy_state));
91 }
92
93 static void dummy_led(int on)
94 {
95 }
96
97 static struct bitbang_interface dummy_bitbang = {
98                 .read = &dummy_read,
99                 .write = &dummy_write,
100                 .reset = &dummy_reset,
101                 .blink = &dummy_led,
102         };
103
104
105 static int dummy_khz(int khz, int *jtag_speed)
106 {
107         if (khz == 0)
108         {
109                 *jtag_speed = 0;
110         }
111         else
112         {
113                 *jtag_speed = 64000/khz;
114         }
115         return ERROR_OK;
116 }
117
118 static int dummy_speed_div(int speed, int *khz)
119 {
120         if (speed == 0)
121         {
122                 *khz = 0;
123         }
124         else
125         {
126                 *khz = 64000/speed;
127         }
128
129         return ERROR_OK;
130 }
131
132 static int dummy_speed(int speed)
133 {
134         return ERROR_OK;
135 }
136
137 static int dummy_init(void)
138 {
139         bitbang_interface = &dummy_bitbang;
140
141         return ERROR_OK;
142 }
143
144 static int dummy_quit(void)
145 {
146         return ERROR_OK;
147 }
148
149 /* The dummy driver is used to easily check the code path
150  * where the target is unresponsive.
151  */
152 struct jtag_interface dummy_interface = {
153                 .name = "dummy",
154
155                 .execute_queue = &bitbang_execute_queue,
156
157                 .speed = &dummy_speed,
158                 .khz = &dummy_khz,
159                 .speed_div = &dummy_speed_div,
160
161                 .init = &dummy_init,
162                 .quit = &dummy_quit,
163         };