forked from svn2github/ixo-usb-jtag
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathhw_saxo_l.c
256 lines (218 loc) · 5.74 KB
/
hw_saxo_l.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*-----------------------------------------------------------------------------
* Hardware-dependent code for usb_jtag
*-----------------------------------------------------------------------------
* Copyright (C) 2007 Kolja Waschk, ixo.de
*-----------------------------------------------------------------------------
* This code is part of usbjtag. usbjtag is free software; you can redistribute
* it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version. usbjtag is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. You should have received a
* copy of the GNU General Public License along with this program in the file
* COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin
* St, Fifth Floor, Boston, MA 02110-1301 USA
*-----------------------------------------------------------------------------
*/
#include <fx2regs.h>
#include "hardware.h"
#include "delay.h"
//-----------------------------------------------------------------------------
/* JTAG TCK, AS/PS DCLK */
sbit at 0xB3 TCK;
#define bmTCKOE bmBIT3
#define SetTCK(x) do{TCK=(x);}while(0)
/* JTAG TDI, AS ASDI, PS DATA0 */
sbit at 0xB0 TDI;
#define bmTDIOE bmBIT0
#define SetTDI(x) do{TDI=(x);}while(0)
/* JTAG TMS, AS/PS nCONFIG */
sbit at 0xB2 TMS;
#define bmTMSOE bmBIT2
#define SetTMS(x) do{TMS=(x);}while(0)
/* JTAG TDO, AS/PS CONF_DONE */
sbit at 0xB1 TDO;
#define bmTDOOE bmBIT1
#define GetTDO(x) TDO
//-----------------------------------------------------------------------------
#define bmPROGOUTOE (bmTCKOE|bmTDIOE|bmTMSOE)
#define bmPROGINOE (bmTDOOE)
//-----------------------------------------------------------------------------
void ProgIO_Poll(void) {}
// These aren't called anywhere in usbjtag.c, but I plan to do so...
void ProgIO_Enable(void) {}
void ProgIO_Disable(void) {}
void ProgIO_Deinit(void) {}
void ProgIO_Init(void)
{
/* The following code depends on your actual circuit design.
Make required changes _before_ you try the code! */
// set the CPU clock to 48MHz, enable clock output to FPGA
CPUCS = bmCLKOE | bmCLKSPD1;
// Use external clock, use "Slave FIFO" mode for all pins
IFCONFIG = bmIFCFG1 | bmIFCFG0;
// TDO input, others output
OED=(OED&~bmPROGINOE) | bmPROGOUTOE;
}
void ProgIO_Set_State(unsigned char d)
{
/* Set state of output pins:
*
* d.0 => TCK
* d.1 => TMS
* d.2 => nCE (only #ifdef HAVE_AS_MODE)
* d.3 => nCS (only #ifdef HAVE_AS_MODE)
* d.4 => TDI
* d.6 => LED / Output Enable
*/
SetTCK((d & bmBIT0) ? 1 : 0);
SetTMS((d & bmBIT1) ? 1 : 0);
SetTDI((d & bmBIT4) ? 1 : 0);
}
unsigned char ProgIO_Set_Get_State(unsigned char d)
{
/* Set state of output pins (s.a.)
* then read state of input pins:
*
* TDO => d.0
* DATAOUT => d.1 (only #ifdef HAVE_AS_MODE)
*/
ProgIO_Set_State(d);
return 2|GetTDO(); /* DATAOUT assumed high, no AS mode */
}
//-----------------------------------------------------------------------------
void ProgIO_ShiftOut(unsigned char c)
{
/* Shift out byte C:
*
* 8x {
* Output least significant bit on TDI
* Raise TCK
* Shift c right
* Lower TCK
* }
*/
(void)c; /* argument passed in DPL */
_asm
MOV A,DPL
;; Bit0
RRC A
MOV _TDI,C
SETB _TCK
;; Bit1
RRC A
CLR _TCK
MOV _TDI,C
SETB _TCK
;; Bit2
RRC A
CLR _TCK
MOV _TDI,C
SETB _TCK
;; Bit3
RRC A
CLR _TCK
MOV _TDI,C
SETB _TCK
;; Bit4
RRC A
CLR _TCK
MOV _TDI,C
SETB _TCK
;; Bit5
RRC A
CLR _TCK
MOV _TDI,C
SETB _TCK
;; Bit6
RRC A
CLR _TCK
MOV _TDI,C
SETB _TCK
;; Bit7
RRC A
CLR _TCK
MOV _TDI,C
SETB _TCK
NOP
CLR _TCK
ret
_endasm;
}
/*
;; For ShiftInOut, the timing is a little more
;; critical because we have to read _TDO/shift/set _TDI
;; when _TCK is low. But 20% duty cycle at 48/4/5 MHz
;; is just like 50% at 6 Mhz, and that's still acceptable
*/
unsigned char ProgIO_ShiftInOut(unsigned char c)
{
/* Shift out byte C, shift in from TDO:
*
* 8x {
* Read carry from TDO
* Output least significant bit on TDI
* Raise TCK
* Shift c right, append carry (TDO) at left
* Lower TCK
* }
* Return c.
*/
(void)c; /* argument passed in DPL */
_asm
MOV A,DPL
;; Bit0
MOV C,_TDO
RRC A
MOV _TDI,C
SETB _TCK
CLR _TCK
;; Bit1
MOV C,_TDO
RRC A
MOV _TDI,C
SETB _TCK
CLR _TCK
;; Bit2
MOV C,_TDO
RRC A
MOV _TDI,C
SETB _TCK
CLR _TCK
;; Bit3
MOV C,_TDO
RRC A
MOV _TDI,C
SETB _TCK
CLR _TCK
;; Bit4
MOV C,_TDO
RRC A
MOV _TDI,C
SETB _TCK
CLR _TCK
;; Bit5
MOV C,_TDO
RRC A
MOV _TDI,C
SETB _TCK
CLR _TCK
;; Bit6
MOV C,_TDO
RRC A
MOV _TDI,C
SETB _TCK
CLR _TCK
;; Bit7
MOV C,_TDO
RRC A
MOV _TDI,C
SETB _TCK
CLR _TCK
MOV DPL,A
ret
_endasm;
/* return value in DPL */
return c;
}