openocd: src/jtag: replace the GPL-2.0-or-later license tag
[openocd.git] / src / jtag / drivers / dummy.c
blobde216e35ad7adfbe9ec666283fccc80607b133b6
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Copyright (C) 2008 by Øyvind Harboe *
5 * oyvind.harboe@zylin.com *
6 ***************************************************************************/
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
12 #include <jtag/interface.h>
13 #include "bitbang.h"
14 #include "hello.h"
16 /* my private tap controller state, which tracks state for calling code */
17 static tap_state_t dummy_state = TAP_RESET;
19 static int dummy_clock; /* edge detector */
21 static int clock_count; /* count clocks in any stable state, only stable states */
23 static uint32_t dummy_data;
25 static bb_value_t dummy_read(void)
27 int data = 1 & dummy_data;
28 dummy_data = (dummy_data >> 1) | (1 << 31);
29 return data ? BB_HIGH : BB_LOW;
32 static int dummy_write(int tck, int tms, int tdi)
34 /* TAP standard: "state transitions occur on rising edge of clock" */
35 if (tck != dummy_clock) {
36 if (tck) {
37 tap_state_t old_state = dummy_state;
38 dummy_state = tap_state_transition(old_state, tms);
40 if (old_state != dummy_state) {
41 if (clock_count) {
42 LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);
43 clock_count = 0;
46 LOG_DEBUG("dummy_tap: %s", tap_state_name(dummy_state));
48 #if defined(DEBUG)
49 if (dummy_state == TAP_DRCAPTURE)
50 dummy_data = 0x01255043;
51 #endif
52 } else {
53 /* this is a stable state clock edge, no change of state here,
54 * simply increment clock_count for subsequent logging
56 ++clock_count;
59 dummy_clock = tck;
61 return ERROR_OK;
64 static int dummy_reset(int trst, int srst)
66 dummy_clock = 0;
68 if (trst || (srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
69 dummy_state = TAP_RESET;
71 LOG_DEBUG("reset to: %s", tap_state_name(dummy_state));
72 return ERROR_OK;
75 static int dummy_led(int on)
77 return ERROR_OK;
80 static struct bitbang_interface dummy_bitbang = {
81 .read = &dummy_read,
82 .write = &dummy_write,
83 .blink = &dummy_led,
86 static int dummy_khz(int khz, int *jtag_speed)
88 if (khz == 0)
89 *jtag_speed = 0;
90 else
91 *jtag_speed = 64000/khz;
92 return ERROR_OK;
95 static int dummy_speed_div(int speed, int *khz)
97 if (speed == 0)
98 *khz = 0;
99 else
100 *khz = 64000/speed;
102 return ERROR_OK;
105 static int dummy_speed(int speed)
107 return ERROR_OK;
110 static int dummy_init(void)
112 bitbang_interface = &dummy_bitbang;
114 return ERROR_OK;
117 static int dummy_quit(void)
119 return ERROR_OK;
122 static const struct command_registration dummy_command_handlers[] = {
124 .name = "dummy",
125 .mode = COMMAND_ANY,
126 .help = "dummy interface driver commands",
127 .chain = hello_command_handlers,
128 .usage = "",
130 COMMAND_REGISTRATION_DONE,
133 /* The dummy driver is used to easily check the code path
134 * where the target is unresponsive.
136 static struct jtag_interface dummy_interface = {
137 .supported = DEBUG_CAP_TMS_SEQ,
138 .execute_queue = &bitbang_execute_queue,
141 struct adapter_driver dummy_adapter_driver = {
142 .name = "dummy",
143 .transports = jtag_only,
144 .commands = dummy_command_handlers,
146 .init = &dummy_init,
147 .quit = &dummy_quit,
148 .reset = &dummy_reset,
149 .speed = &dummy_speed,
150 .khz = &dummy_khz,
151 .speed_div = &dummy_speed_div,
153 .jtag_ops = &dummy_interface,