]> git.sur5r.net Git - openocd/blob - src/jtag/dummy.c
49161a607c80b0dd6dd198348ecb1b75f4aac35f
[openocd] / src / jtag / dummy.c
1 /***************************************************************************\r
2  *   Copyright (C) 2008 by Ã˜yvind Harboe                                   *\r
3  *   oyvind.harboe@zylin.com                                               *\r
4  *                                                                         *\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
9  *                                                                         *\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
14  *                                                                         *\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
21 #include "config.h"\r
22 #endif\r
23 \r
24 #include "replacements.h"\r
25 \r
26 #include "jtag.h"\r
27 #include "bitbang.h"\r
28 \r
29 \r
30 /* my private tap controller state, which tracks state for calling code */\r
31 static tap_state_t dummy_state = TAP_RESET;\r
32 \r
33 static int dummy_clock;         /* edge detector */\r
34 \r
35 static int clock_count;         /* count clocks in any stable state, only stable states */\r
36 \r
37 static u32 dummy_data;\r
38 \r
39 \r
40 static int dummy_speed(int speed);\r
41 static int dummy_register_commands(struct command_context_s *cmd_ctx);\r
42 static int dummy_init(void);\r
43 static int dummy_quit(void);\r
44 static int dummy_khz(int khz, int *jtag_speed);\r
45 static int dummy_speed_div(int speed, int *khz);\r
46 \r
47 \r
48 /* The dummy driver is used to easily check the code path\r
49  * where the target is unresponsive.\r
50  */\r
51 jtag_interface_t dummy_interface =\r
52 {\r
53         .name = "dummy",\r
54 \r
55         .execute_queue = bitbang_execute_queue,\r
56 \r
57         .speed = dummy_speed,\r
58         .register_commands = dummy_register_commands,\r
59         .khz = dummy_khz,\r
60         .speed_div = dummy_speed_div,\r
61 \r
62         .init = dummy_init,\r
63         .quit = dummy_quit,\r
64 };\r
65 \r
66 static int dummy_read(void);\r
67 static void dummy_write(int tck, int tms, int tdi);\r
68 static void dummy_reset(int trst, int srst);\r
69 static void dummy_led(int on);\r
70 \r
71 static bitbang_interface_t dummy_bitbang =\r
72 {\r
73         .read = dummy_read,\r
74         .write = dummy_write,\r
75         .reset = dummy_reset,\r
76         .blink = dummy_led\r
77 };\r
78 \r
79 static int dummy_read(void)\r
80 {\r
81         int data = 1 & dummy_data;\r
82         dummy_data = (dummy_data >> 1) | (1<<31);\r
83         return data;\r
84 }\r
85 \r
86 \r
87 static void dummy_write(int tck, int tms, int tdi)\r
88 {\r
89         /* TAP standard: "state transitions occur on rising edge of clock" */\r
90         if( tck != dummy_clock )\r
91         {\r
92                 if( tck )\r
93                 {\r
94                         tap_state_t old_state = dummy_state;\r
95                         dummy_state = tap_state_transition( old_state, tms );\r
96 \r
97                         if( old_state != dummy_state )\r
98                         {\r
99                                 if( clock_count )\r
100                                 {\r
101                                         LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);\r
102                                         clock_count = 0;\r
103                                 }\r
104 \r
105                                 LOG_DEBUG("dummy_tap: %s", tap_state_name(dummy_state) );\r
106 \r
107 #if defined(DEBUG)\r
108                                 if(dummy_state == TAP_DRCAPTURE)\r
109                                         dummy_data = 0x01255043;\r
110 #endif\r
111                         }\r
112                         else\r
113                         {\r
114                                 /* this is a stable state clock edge, no change of state here,\r
115                                  * simply increment clock_count for subsequent logging\r
116                                  */\r
117                                 ++clock_count;\r
118                         }\r
119                 }\r
120                 dummy_clock = tck;\r
121         }\r
122 }\r
123 \r
124 static void dummy_reset(int trst, int srst)\r
125 {\r
126         dummy_clock = 0;\r
127 \r
128         if (trst || (srst && (jtag_reset_config & RESET_SRST_PULLS_TRST)))\r
129                 dummy_state = TAP_RESET;\r
130 \r
131         LOG_DEBUG("reset to: %s", tap_state_name(dummy_state) );\r
132 }\r
133 \r
134 static int dummy_khz(int khz, int *jtag_speed)\r
135 {\r
136         if (khz==0)\r
137         {\r
138                 *jtag_speed=0;\r
139         }\r
140         else\r
141         {\r
142                 *jtag_speed=64000/khz;\r
143         }\r
144         return ERROR_OK;\r
145 }\r
146 \r
147 static int dummy_speed_div(int speed, int *khz)\r
148 {\r
149         if (speed==0)\r
150         {\r
151                 *khz = 0;\r
152         }\r
153         else\r
154         {\r
155                 *khz=64000/speed;\r
156         }\r
157 \r
158         return ERROR_OK;\r
159 }\r
160 \r
161 static int dummy_speed(int speed)\r
162 {\r
163         return ERROR_OK;\r
164 }\r
165 \r
166 static int dummy_register_commands(struct command_context_s *cmd_ctx)\r
167 {\r
168         return ERROR_OK;\r
169 }\r
170 \r
171 static int dummy_init(void)\r
172 {\r
173         bitbang_interface = &dummy_bitbang;\r
174 \r
175         return ERROR_OK;\r
176 }\r
177 \r
178 static int dummy_quit(void)\r
179 {\r
180         return ERROR_OK;\r
181 }\r
182 \r
183 static void dummy_led(int on)\r
184 {\r
185 }\r
186 \r