OpenOCD
dummy.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2008 by Øyvind Harboe *
5  * oyvind.harboe@zylin.com *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include <jtag/interface.h>
13 #include "bitbang.h"
14 #include "hello.h"
15 
16 /* my private tap controller state, which tracks state for calling code */
18 
19 static int dummy_clock; /* edge detector */
20 
21 static int clock_count; /* count clocks in any stable state, only stable states */
22 
23 static uint32_t dummy_data;
24 
25 static bb_value_t dummy_read(void)
26 {
27  int data = 1 & dummy_data;
28  dummy_data = (dummy_data >> 1) | (1 << 31);
29  return data ? BB_HIGH : BB_LOW;
30 }
31 
32 static int dummy_write(int tck, int tms, int tdi)
33 {
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);
39 
40  if (old_state != dummy_state) {
41  if (clock_count) {
42  LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);
43  clock_count = 0;
44  }
45 
46  LOG_DEBUG("dummy_tap: %s", tap_state_name(dummy_state));
47 
48 #if defined(DEBUG)
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
55  */
56  ++clock_count;
57  }
58  }
59  dummy_clock = tck;
60  }
61  return ERROR_OK;
62 }
63 
64 static int dummy_reset(int trst, int srst)
65 {
66  dummy_clock = 0;
67 
68  if (trst || (srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
70 
71  LOG_DEBUG("reset to: %s", tap_state_name(dummy_state));
72  return ERROR_OK;
73 }
74 
75 static int dummy_led(bool on)
76 {
77  return ERROR_OK;
78 }
79 
80 static struct bitbang_interface dummy_bitbang = {
81  .read = &dummy_read,
82  .write = &dummy_write,
83  .blink = &dummy_led,
84  };
85 
86 static int dummy_khz(int khz, int *jtag_speed)
87 {
88  if (khz == 0)
89  *jtag_speed = 0;
90  else
91  *jtag_speed = 64000/khz;
92  return ERROR_OK;
93 }
94 
95 static int dummy_speed_div(int speed, int *khz)
96 {
97  if (speed == 0)
98  *khz = 0;
99  else
100  *khz = 64000/speed;
101 
102  return ERROR_OK;
103 }
104 
105 static int dummy_speed(int speed)
106 {
107  return ERROR_OK;
108 }
109 
110 static int dummy_init(void)
111 {
113 
114  return ERROR_OK;
115 }
116 
117 static int dummy_quit(void)
118 {
119  return ERROR_OK;
120 }
121 
122 static const struct command_registration dummy_command_handlers[] = {
123  {
124  .name = "dummy",
125  .mode = COMMAND_ANY,
126  .help = "dummy interface driver commands",
127  .chain = hello_command_handlers,
128  .usage = "",
129  },
131 };
132 
133 /* The dummy driver is used to easily check the code path
134  * where the target is unresponsive.
135  */
136 static struct jtag_interface dummy_interface = {
138  .execute_queue = &bitbang_execute_queue,
139 };
140 
142  .name = "dummy",
143  .transports = jtag_only,
144  .commands = dummy_command_handlers,
145 
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,
152 
153  .jtag_ops = &dummy_interface,
154 };
const char *const jtag_only[]
Definition: adapter.c:27
int bitbang_execute_queue(struct jtag_command *cmd_queue)
Definition: bitbang.c:293
bb_value_t
Definition: bitbang.h:17
@ BB_LOW
Definition: bitbang.h:18
@ BB_HIGH
Definition: bitbang.h:19
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
static struct jtag_interface dummy_interface
Definition: dummy.c:136
static int clock_count
Definition: dummy.c:21
static int dummy_clock
Definition: dummy.c:19
static int dummy_write(int tck, int tms, int tdi)
Definition: dummy.c:32
struct adapter_driver dummy_adapter_driver
Definition: dummy.c:141
static bb_value_t dummy_read(void)
Definition: dummy.c:25
static int dummy_init(void)
Definition: dummy.c:110
static int dummy_led(bool on)
Definition: dummy.c:75
static tap_state_t dummy_state
Definition: dummy.c:17
static uint32_t dummy_data
Definition: dummy.c:23
static int dummy_speed_div(int speed, int *khz)
Definition: dummy.c:95
static struct bitbang_interface dummy_bitbang
Definition: dummy.c:80
static int dummy_speed(int speed)
Definition: dummy.c:105
static const struct command_registration dummy_command_handlers[]
Definition: dummy.c:122
static int dummy_reset(int trst, int srst)
Definition: dummy.c:64
static int dummy_quit(void)
Definition: dummy.c:117
static int dummy_khz(int khz, int *jtag_speed)
Definition: dummy.c:86
const struct command_registration hello_command_handlers[]
Export the registration for the hello command group, so it can be embedded in example drivers.
Definition: hello.c:86
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
Definition: interface.c:223
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
Definition: interface.c:344
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:187
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1734
@ TAP_RESET
Definition: jtag.h:56
@ TAP_DRCAPTURE
Definition: jtag.h:47
@ RESET_SRST_PULLS_TRST
Definition: jtag.h:221
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
Represents a driver for a debugging interface.
Definition: interface.h:207
const char *const name
The name of the interface driver.
Definition: interface.h:209
Low level callbacks (for bitbang).
Definition: bitbang.h:30
bb_value_t(* read)(void)
Sample TDO and return the value.
Definition: bitbang.h:32
const char * name
Definition: command.h:235
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241
Represents a driver for a debugging interface.
Definition: interface.h:182
unsigned int supported
Bit vector listing capabilities exposed by this driver.
Definition: interface.h:186