OpenCores
URL https://opencores.org/ocsvn/usb_fpga_2_13/usb_fpga_2_13/trunk

Subversion Repositories usb_fpga_2_13

[/] [usb_fpga_2_13/] [trunk/] [include/] [ztex-fpga2.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
3
   Copyright (C) 2009-2014 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License version 3 as
8
   published by the Free Software Foundation.
9
 
10
   This program is distributed in the hope that it will be useful, but
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
   General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, see http://www.gnu.org/licenses/.
17
!*/
18
 
19
/*
20
    FPGA support for ZTEX USB FPGA Modules 1.10
21
*/
22
 
23
#ifndef[ZTEX_FPGA_H]
24
#define[ZTEX_FPGA_H]
25
 
26
#define[@CAPABILITY_FPGA;]
27
 
28
__xdata BYTE fpga_checksum;         // checksum
29
__xdata DWORD fpga_bytes;           // transfered bytes
30
__xdata BYTE fpga_init_b;           // init_b state (should be 222 after configuration)
31
__xdata BYTE fpga_flash_result;     // result of automatic fpga configuarion from Flash
32
 
33
/* *********************************************************************
34
   ***** reset_fpga ****************************************************
35
   ********************************************************************* */
36
static void reset_fpga_int (BYTE mode) {                // reset FPGA
37
    unsigned short k;
38
    IFCONFIG = bmBIT7;
39
    SYNCDELAY;
40
    PORTACFG = 0;
41
    PORTCCFG = 0;
42
 
43
    OEA = (OEA & 0xe0) | bmBIT1 | bmBIT3 | bmBIT4;
44
    IOA = (IOA & 0xe0) | bmBIT4;
45
    wait(10);
46
 
47
    OEC = bmBIT4 | bmBIT6 | bmBIT7;
48
    IOC = mode;
49
 
50
    IOA = (IOA & 0xe0) | bmBIT1;                                // ready for configuration
51
    k=0;
52
    while (!IOA0 && k<65535)
53
        k++;
54
 
55
    fpga_init_b = IOA0 ? 200 : 100;
56
    fpga_bytes = 0;
57
    fpga_checksum = 0;
58
}
59
 
60
static void reset_fpga () {
61
    reset_fpga_int(bmBIT4);
62
}
63
 
64
static void reset_fpga_flash () {
65
    reset_fpga_int(bmBIT4 | bmBIT6);
66
}
67
 
68
/* *********************************************************************
69
   ***** init_fpga_configuration ***************************************
70
   ********************************************************************* */
71
static void init_fpga_configuration () {
72
    {
73
        PRE_FPGA_RESET
74
    }
75
    reset_fpga();                       // reset FPGA
76
}
77
 
78
/* *********************************************************************
79
   ***** post_fpga_confog **********************************************
80
   ********************************************************************* */
81
static void post_fpga_config () {
82
    POST_FPGA_CONFIG
83
}
84
 
85
/* *********************************************************************
86
   ***** finish_fpga_configuration *************************************
87
   ********************************************************************* */
88
static void finish_fpga_configuration () {
89
    WORD w;
90
    fpga_init_b += IOA0 ? 20 : 10;
91
 
92
    for ( w=0; w<65535; w++ ) {
93
        IOA3 = 1; IOA3 = 0;
94
    }
95
 
96
    IOA3 = 1; IOA3 = 0;
97
    IOA3 = 1; IOA3 = 0;
98
    IOA3 = 1; IOA3 = 0;
99
    IOA3 = 1; IOA3 = 0;
100
    IOA4 = 1;
101
    IOA3 = 1; IOA3 = 0;
102
    OEC = 0;
103
    IOA3 = 1; IOA3 = 0;
104
    IOA3 = 1; IOA3 = 0;
105
    IOA3 = 1; IOA3 = 0;
106
 
107
    OEA = OEA & 0xe0;
108
    fpga_init_b += IOA0 ? 2 : 1;
109
    if ( IOA1 )  {
110
        IOA1 = 1;
111
        post_fpga_config();
112
    }
113
 
114
    IOA1 = 1;
115
    OEA |= bmBIT1;
116
}
117
 
118
 
119
/* *********************************************************************
120
   ***** EP0 vendor request 0x30 ***************************************
121
   ********************************************************************* */
122
ADD_EP0_VENDOR_REQUEST((0x30,,          // get FPGA state
123
    MEM_COPY1(fpga_checksum,EP0BUF+1,7);
124
    OEA &= ~bmBIT1;
125
    if ( IOA1 )  {
126
        EP0BUF[0] = 0;                    // FPGA configured 
127
        IOA1 = 1;
128
        OEA |= bmBIT1;
129
    }
130
    else {
131
        EP0BUF[0] = 1;                   // FPGA unconfigured 
132
        reset_fpga();                   // prepare FPGA for configuration
133
    }
134
    EP0BUF[8] = 1;                      // bit order for bitstream in Flash memory: swapped
135
 
136
    EP0BCH = 0;
137
    EP0BCL = 9;
138
,,));;
139
 
140
 
141
/* *********************************************************************
142
   ***** EP0 vendor command 0x31 ***************************************
143
   ********************************************************************* */
144
ADD_EP0_VENDOR_COMMAND((0x31,,init_fpga_configuration();,,));;  // reset FPGA
145
 
146
 
147
/* *********************************************************************
148
   ***** EP0 vendor command 0x32 ***************************************
149
   ********************************************************************* */
150
void fpga_send_ep0() {
151
    BYTE oOED;
152
    oOED = OED;
153
    OED = 255;
154
    fpga_bytes += ep0_payload_transfer;
155
    __asm
156
        mov     dptr,#_EP0BCL
157
        movx    a,@dptr
158
        jz      010000$
159
        mov     r2,a
160
        mov     _AUTOPTRL1,#(_EP0BUF)
161
        mov     _AUTOPTRH1,#(_EP0BUF >> 8)
162
        mov     _AUTOPTRSETUP,#0x07
163
        mov     dptr,#_fpga_checksum
164
        movx    a,@dptr
165
        mov     r1,a
166
        mov     dptr,#_XAUTODAT1
167
010001$:
168
        movx    a,@dptr
169
        mov     _IOD,a
170
        setb    _IOA3
171
        add     a,r1
172
        mov     r1,a
173
        clr     _IOA3
174
        djnz    r2, 010001$
175
 
176
        mov     dptr,#_fpga_checksum
177
        mov     a,r1
178
        movx    @dptr,a
179
 
180
010000$:
181
        __endasm;
182
    OED = oOED;
183
    if ( EP0BCL<64 ) {
184
        finish_fpga_configuration();
185
    }
186
}
187
 
188
ADD_EP0_VENDOR_COMMAND((0x32,,          // send FPGA configuration data
189
,,
190
    fpga_send_ep0();
191
));;
192
 
193
 
194
#ifeq[FLASH_BITSTREAM_ENABLED][1]
195
#ifeq[FLASH_ENABLED][1]
196
 
197
/* *********************************************************************
198
   ***** fpga_send_bitstream_from_flash ********************************
199
   ********************************************************************* */
200
void fpga_send_bitstream_from_flash (WORD size) {
201
        size;                   // this avoids stupid warnings
202
__asm
203
        push    _OED
204
        mov     _OED,#0
205
 
206
        mov     r5,dpl          // = size
207
        mov     r6,dph
208
 
209
        // fpga_bytes+=size
210
        mov     dptr,#_fpga_bytes
211
        movx    a,@dptr
212
        mov     r1,a
213
        inc     dptr
214
        movx    a,@dptr
215
        mov     r2,a
216
        inc     dptr
217
        movx    a,@dptr
218
        mov     r3,a
219
        inc     dptr
220
        movx    a,@dptr
221
        mov     r4,a
222
 
223
        mov     dptr,#_fpga_bytes
224
        mov     a,r5
225
        add     a,r1
226
        movx    @dptr,a
227
        mov     a,r6
228
        addc    a,r2
229
        inc     dptr
230
        movx    @dptr,a
231
        mov     a,#0
232
        addc    a,r3
233
        inc     dptr
234
        movx    @dptr,a
235
        mov     a,#0
236
        addc    a,r4
237
        inc     dptr
238
        movx    @dptr,a
239
 
240
010003$:
241
        cjne    r5,#0x00,010002$
242
        cjne    r6,#0x00,010002$
243
        pop     _OED
244
        ret
245
010002$:
246
        mov     _IOA,#(bmBIT1 | bmBIT6 | bmBIT3 | bmBIT7)
247
        mov     _IOA,#(bmBIT1 | bmBIT6)
248
        mov     _IOA,#(bmBIT1 | bmBIT6 | bmBIT3 | bmBIT7)
249
        mov     _IOA,#(bmBIT1 | bmBIT6)
250
        mov     _IOA,#(bmBIT1 | bmBIT6 | bmBIT3 | bmBIT7)
251
        mov     _IOA,#(bmBIT1 | bmBIT6)
252
        mov     _IOA,#(bmBIT1 | bmBIT6 | bmBIT3 | bmBIT7)
253
        mov     _IOA,#(bmBIT1 | bmBIT6)
254
        mov     _IOA,#(bmBIT1 | bmBIT6 | bmBIT3 | bmBIT7)
255
        mov     _IOA,#(bmBIT1 | bmBIT6)
256
        mov     _IOA,#(bmBIT1 | bmBIT6 | bmBIT3 | bmBIT7)
257
        mov     _IOA,#(bmBIT1 | bmBIT6)
258
        mov     _IOA,#(bmBIT1 | bmBIT6 | bmBIT3 | bmBIT7)
259
        mov     _IOA,#(bmBIT1 | bmBIT6)
260
        mov     _IOA,#(bmBIT1 | bmBIT6 | bmBIT3 | bmBIT7)
261
        mov     _IOA,#(bmBIT1 | bmBIT6)
262
 
263
        dec     r5
264
        cjne    r5,#0xff,010003$
265
        dec     r6
266
        sjmp    010003$
267
__endasm;
268
}
269
 
270
#include[ztex-fpga-flash1.h]
271
 
272
#else
273
#warning[Flash interface is not enabled but required for FPGA configuration using a bitstream from Flash meomory]
274
#define[FLASH_BITSTREAM_ENABLED][0]
275
#endif
276
#endif
277
 
278
#endif  /*ZTEX_FPGA_H*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.