jamexp.y: rewrite grammar using precedences
[urjtag.git] / urjtag / src / tap / tap.c
blobebdf5e475b6ff58593475a7a8ab083d096ad2b38
1 /*
2 * $Id$
4 * Copyright (C) 2002 ETC s.r.o.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
21 * Written by Marcel Telka <marcel@telka.sk>, 2002.
25 #include <sysdep.h>
27 #include <stdio.h>
29 #include <urjtag/log.h>
30 #include <urjtag/cable.h>
31 #include <urjtag/part.h>
32 #include <urjtag/tap_register.h>
33 #include <urjtag/tap.h>
34 #include <urjtag/tap_state.h>
35 #include <urjtag/chain.h>
37 void
38 urj_tap_reset (urj_chain_t *chain)
40 urj_tap_state_reset (chain);
42 urj_tap_chain_clock (chain, 1, 0, 5); /* Test-Logic-Reset */
43 urj_tap_chain_clock (chain, 0, 0, 1); /* Run-Test/Idle */
46 void
47 urj_tap_trst_reset (urj_chain_t *chain)
49 urj_tap_chain_set_trst (chain, 0);
50 urj_tap_chain_set_trst (chain, 1);
52 urj_tap_reset (chain);
55 int
56 urj_tap_reset_bypass (urj_chain_t *chain)
58 urj_tap_reset (chain);
60 /* set all parts in the chain to BYPASS instruction if the total
61 instruction register length of the chain is already known */
62 if (chain->total_instr_len > 0)
64 urj_tap_register_t *ir = urj_tap_register_fill (
65 urj_tap_register_alloc (chain->total_instr_len), 1);
66 if (!ir)
67 return URJ_STATUS_FAIL;
69 urj_tap_capture_ir (chain);
70 urj_tap_shift_register (chain, ir, NULL, URJ_CHAIN_EXITMODE_IDLE);
71 urj_tap_register_free (ir);
73 urj_part_parts_set_instruction (chain->parts, "BYPASS");
76 return URJ_STATUS_OK;
79 void
80 urj_tap_defer_shift_register (urj_chain_t *chain,
81 const urj_tap_register_t *in,
82 urj_tap_register_t *out, int tap_exit)
84 int i;
86 if (!(urj_tap_state (chain) & URJ_TAP_STATE_SHIFT))
87 urj_log (URJ_LOG_LEVEL_NORMAL, _("%s: Invalid state: %2X\n"), __func__,
88 urj_tap_state (chain));
90 /* Capture-DR, Capture-IR, Shift-DR, Shift-IR, Exit2-DR or Exit2-IR state */
91 if (urj_tap_state (chain) & URJ_TAP_STATE_CAPTURE)
92 urj_tap_chain_defer_clock (chain, 0, 0, 1); /* save last TDO bit :-) */
94 i = in->len;
95 if (tap_exit)
96 i--;
97 if (out && out->len < i)
98 i = out->len;
100 if (out)
101 urj_tap_cable_defer_transfer (chain->cable, i, in->data, out->data);
102 else
103 urj_tap_cable_defer_transfer (chain->cable, i, in->data, NULL);
105 for (; i < in->len; i++)
107 if (out != NULL && (i < out->len))
108 out->data[i] = urj_tap_cable_defer_get_tdo (chain->cable);
109 urj_tap_chain_defer_clock (chain, (tap_exit != URJ_CHAIN_EXITMODE_SHIFT && ((i + 1) == in->len)) ? 1 : 0, in->data[i], 1); /* Shift (& Exit1) */
112 /* Shift-DR, Shift-IR, Exit1-DR or Exit1-IR state */
113 if (tap_exit == URJ_CHAIN_EXITMODE_IDLE)
115 urj_tap_chain_defer_clock (chain, 1, 0, 1); /* Update-DR or Update-IR */
116 urj_tap_chain_defer_clock (chain, 0, 0, 1); /* Run-Test/Idle */
117 urj_tap_chain_wait_ready (chain);
119 else if (tap_exit == URJ_CHAIN_EXITMODE_UPDATE)
120 urj_tap_chain_defer_clock (chain, 1, 0, 1); /* Update-DR or Update-IR */
123 void
124 urj_tap_shift_register_output (urj_chain_t *chain,
125 const urj_tap_register_t *in,
126 urj_tap_register_t *out, int tap_exit)
128 if (out != NULL)
130 int j;
132 j = in->len;
133 if (tap_exit)
134 j--;
135 if (out && out->len < j)
136 j = out->len;
138 /* Asking for the result of the cable transfer
139 * actually flushes the queue */
141 (void) urj_tap_cable_transfer_late (chain->cable, out->data);
142 for (; j < in->len && j < out->len; j++)
143 out->data[j] = urj_tap_cable_get_tdo_late (chain->cable);
147 void
148 urj_tap_shift_register (urj_chain_t *chain, const urj_tap_register_t *in,
149 urj_tap_register_t *out, int tap_exit)
151 urj_tap_defer_shift_register (chain, in, out, tap_exit);
152 urj_tap_shift_register_output (chain, in, out, tap_exit);
155 void
156 urj_tap_capture_dr (urj_chain_t *chain)
158 if ((urj_tap_state (chain) & (URJ_TAP_STATE_RESET | URJ_TAP_STATE_IDLE))
159 != URJ_TAP_STATE_IDLE)
160 urj_log (URJ_LOG_LEVEL_NORMAL, _("%s: Invalid state: %2X\n"), __func__,
161 urj_tap_state (chain));
163 /* Run-Test/Idle or Update-DR or Update-IR state */
164 urj_tap_chain_defer_clock (chain, 1, 0, 1); /* Select-DR-Scan */
165 urj_tap_chain_defer_clock (chain, 0, 0, 1); /* Capture-DR */
168 void
169 urj_tap_capture_ir (urj_chain_t *chain)
171 if ((urj_tap_state (chain) & (URJ_TAP_STATE_RESET | URJ_TAP_STATE_IDLE))
172 != URJ_TAP_STATE_IDLE)
173 urj_log (URJ_LOG_LEVEL_NORMAL, _("%s: Invalid state: %2X\n"), __func__,
174 urj_tap_state (chain));
176 /* Run-Test/Idle or Update-DR or Update-IR state */
177 urj_tap_chain_defer_clock (chain, 1, 0, 2); /* Select-DR-Scan, then Select-IR-Scan */
178 urj_tap_chain_defer_clock (chain, 0, 0, 1); /* Capture-IR */