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

Subversion Repositories usb_fpga_2_14

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

powered by: WebSVN 2.1.0

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