1 /***************************************************************************
2 * Copyright (C) 2007-2010 by Øyvind Harboe *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16 ***************************************************************************/
18 /* used to test manual mode */
19 #define TEST_MANUAL() 0
22 #if BUILD_ZY1000_MASTER
24 #define ZY1000_PEEK(a, b) do {b = *((volatile uint32_t *)(a)); } while (0)
25 #define ZY1000_POKE(a, b) do {*((volatile uint32_t *)(a)) = b; } while (0)
26 extern volatile void *zy1000_jtag_master;
27 #define ZY1000_JTAG_BASE ((unsigned long)zy1000_jtag_master)
31 /* redirect this to TCP/IP */
32 #define ZY1000_JTAG_BASE 0
33 extern void zy1000_tcpout(uint32_t address, uint32_t data);
34 extern uint32_t zy1000_tcpin(uint32_t address);
35 #define ZY1000_PEEK(a, b) b = zy1000_tcpin(a)
36 #define ZY1000_POKE(a, b) zy1000_tcpout(a, b)
40 #if BUILD_ZY1000_MASTER
42 static inline void waitIdle(void)
46 ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, empty);
47 } while ((empty & 0x100) == 0);
50 static inline void zy1000_flush_readqueue(void)
52 /* Not used w/hardware fifo */
54 static inline void zy1000_flush_callbackqueue(void)
56 /* Not used w/hardware fifo */
59 extern void waitIdle(void);
60 void zy1000_flush_readqueue(void);
61 void zy1000_flush_callbackqueue(void);
62 void zy1000_jtag_add_callback4(jtag_callback_t callback,
63 jtag_callback_data_t data0,
64 jtag_callback_data_t data1,
65 jtag_callback_data_t data2,
66 jtag_callback_data_t data3);
67 void zy1000_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t data0);
70 static inline void waitQueue(void)
75 static inline void sampleShiftRegister(void)
80 ZY1000_PEEK(ZY1000_JTAG_BASE + 0xc, dummy);
84 static inline void setCurrentState(enum tap_state state)
89 if (state == TAP_RESET) {
90 /* The FPGA nor we know the current state of the CPU TAP */
91 /* controller. This will move it to TAP for sure. */
93 /* 5 should be enough here, 7 is what OpenOCD uses */
97 sampleShiftRegister();
98 ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | a);
103 * Enter state and cause repeat transitions *out* of that state. So if the endState != state, then
104 * the transition from state to endState counts as a transition out of state.
106 static inline void shiftValueInner(const enum tap_state state,
107 const enum tap_state endState,
115 sampleShiftRegister();
116 ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value);
119 if ((state == TAP_DRSHIFT) && (endState != TAP_DRSHIFT)) {
121 setCurrentState(state);
122 for (i = 0; i < repeat; i++) {
125 if ((i == repeat-1) && (state != endState))
127 /* shift out value */
129 ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, (((value >> i)&1) << 1) | tms);
132 ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0);
134 /* ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRSHIFT); // set this state and things
135 * break => expected */
136 ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRPAUSE); /* set this and things will
137 * work => expected. Not
138 * setting this is not
139 * sufficient to make things
141 setCurrentState(endState);
143 ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b);
147 ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b);
150 /* maximum debug version */
151 if ((repeat > 0) && ((state == TAP_DRSHIFT) || (state == TAP_SI))) {
153 /* sample shift register for every bit. */
154 for (i = 0; i < repeat-1; i++) {
155 sampleShiftRegister();
156 ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> i);
157 ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 8) | (a << 4) | a);
159 sampleShiftRegister();
160 ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> (repeat-1));
161 ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 8) | (a << 4) | b);
163 sampleShiftRegister();
164 ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b);
166 sampleShiftRegister();
170 #if BUILD_ZY1000_MASTER
171 #define interface_jtag_add_callback(callback, in) callback(in)
172 #define interface_jtag_add_callback4(callback, in, data1, data2, \
173 data3) jtag_set_error(callback(in, data1, data2, data3))
175 #define interface_jtag_add_callback(callback, in) zy1000_jtag_add_callback(callback, in)
176 #define interface_jtag_add_callback4(callback, in, data1, data2, data3) zy1000_jtag_add_callback4( \