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-fpga1.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.0, 1.1 and 1.2
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 FPGA configuarion from Flash at startup
39
 
40
/* *********************************************************************
41
   ***** reset_fpga ****************************************************
42
   ********************************************************************* */
43
static void reset_fpga () {             // reset FPGA
44
    unsigned short k;
45
    IFCONFIG = bmBIT7;
46
    SYNCDELAY;
47
    PORTACFG = 0;
48
    PORTCCFG = 0;
49
 
50
    OEA = bmBIT1;
51
    IOA1 = 0;
52
    wait(10);
53
 
54
    OEB = 0xff;                         // setup IO's
55
    OEC = bmBIT2 | bmBIT3;
56
    IOC = bmBIT3;
57
 
58
    OED = bmBIT0;
59
    IOD0 = 0;
60
 
61
    IOA1 = 1;                           // ready for configuration
62
    IOD0 = 1;
63
    k=0;
64
    while (!IOC0 && k<65535)
65
        k++;
66
 
67
    fpga_init_b = IOC0 ? 200 : 100;
68
    fpga_bytes = 0;
69
    fpga_checksum = 0;
70
 
71
    IOC = 0;
72
}
73
 
74
#define[reset_fpga_flash][reset_fpga];
75
 
76
/* *********************************************************************
77
   ***** init_fpga_configuration ***************************************
78
   ********************************************************************* */
79
static void init_fpga_configuration () {
80
    {
81
        PRE_FPGA_RESET
82
    }
83
    reset_fpga();                       // reset FPGA
84
}
85
 
86
/* *********************************************************************
87
   ***** post_fpga_confog **********************************************
88
   ********************************************************************* */
89
static void post_fpga_config () {
90
    POST_FPGA_CONFIG
91
}
92
 
93
/* *********************************************************************
94
   ***** finish_fpga_configuration *************************************
95
   ********************************************************************* */
96
static void finish_fpga_configuration () {
97
    fpga_init_b += IOC0 ? 20 : 10;
98
    IOD0 = 0;  IOB = 0;  IOD0 = 1;
99
    IOD0 = 0;  IOD0 = 1;
100
    IOD0 = 0;  IOD0 = 1;
101
    IOD0 = 0;  IOD0 = 1;
102
    IOD0 = 0;  IOD0 = 1;
103
    IOD0 = 0;  IOD0 = 1;
104
    IOD0 = 0;  IOD0 = 1;
105
    IOD0 = 0;  IOD0 = 1;
106
    IOD0 = 0;  IOD0 = 1;
107
    IOD0 = 0;  IOD0 = 1;
108
    IOD0 = 0;  IOD0 = 1;
109
    OEB = 0;
110
    OEC = 0;
111
    OED = 0;
112
    OEA = 0;
113
    fpga_init_b += IOC0 ? 2 : 1;
114
    if ( IOA1 )  {
115
        IOA1 = 1;
116
        post_fpga_config();
117
    }
118
 
119
    IOA1 = 1;
120
    OEA |= bmBIT1;
121
}
122
 
123
 
124
/* *********************************************************************
125
   ***** EP0 vendor request 0x30 ***************************************
126
   ********************************************************************* */
127
ADD_EP0_VENDOR_REQUEST((0x30,,          // get FPGA state
128
    MEM_COPY1(fpga_checksum,EP0BUF+1,7);
129
    OEA &= ~bmBIT1;
130
    if ( IOA1 )  {
131
        EP0BUF[0] = 0;                    // FPGA configured 
132
        IOA1 = 1;
133
        OEA |= bmBIT1;
134
    }
135
    else {
136
        EP0BUF[0] = 1;                   // FPGA unconfigured 
137
        reset_fpga();                   // prepare FPGA for configuration
138
    }
139
    EP0BUF[8] = 0;                       // bit order for bitstream in FLASH: non swapped
140
 
141
    EP0BCH = 0;
142
    EP0BCL = 9;
143
,,));;
144
 
145
 
146
/* *********************************************************************
147
   ***** EP0 vendor command 0x31 ***************************************
148
   ********************************************************************* */
149
ADD_EP0_VENDOR_COMMAND((0x31,,init_fpga_configuration();,,));;  // reset FPGA
150
 
151
 
152
/* *********************************************************************
153
   ***** EP0 vendor command 0x32 ***************************************
154
   ********************************************************************* */
155
void fpga_send_ep0() {
156
    fpga_bytes += ep0_payload_transfer;
157
    __asm
158
        mov     dptr,#_EP0BCL
159
        movx    a,@dptr
160
        jz      010000$
161
        mov     r2,a
162
        mov     _AUTOPTRL1,#(_EP0BUF)
163
        mov     _AUTOPTRH1,#(_EP0BUF >> 8)
164
        mov     _AUTOPTRSETUP,#0x07
165
        mov     dptr,#_fpga_checksum
166
        movx    a,@dptr
167
        mov     r1,a
168
        mov     dptr,#_XAUTODAT1
169
010001$:
170
        clr     _IOD0
171
        movx    a,@dptr
172
        mov     _IOB,a
173
        add     a,r1
174
        mov     r1,a
175
        setb    _IOD0
176
        djnz    r2, 010001$
177
 
178
        mov     dptr,#_fpga_checksum
179
        mov     a,r1
180
        movx    @dptr,a
181
 
182
010000$:
183
        __endasm;
184
    if ( EP0BCL<64 ) {
185
        finish_fpga_configuration();
186
    }
187
}
188
 
189
ADD_EP0_VENDOR_COMMAND((0x32,,          // send FPGA configuration data
190
,,
191
    fpga_send_ep0();
192
));;
193
 
194
 
195
#ifeq[FLASH_BITSTREAM_ENABLED][1]
196
#ifeq[FLASH_ENABLED][1]
197
 
198
/* *********************************************************************
199
   ***** fpga__send_bitstream_from_flash *******************************
200
   ********************************************************************* */
201
void fpga_send_bitstream_from_flash (WORD size) {
202
        size;                   // this avoids stupid warnings
203
__asm
204
        mov     r5,dpl          // = size
205
        mov     r6,dph
206
 
207
        // fpga_bytes+=size
208
        mov     dptr,#_fpga_bytes
209
        movx    a,@dptr
210
        mov     r1,a
211
        inc     dptr
212
        movx    a,@dptr
213
        mov     r2,a
214
        inc     dptr
215
        movx    a,@dptr
216
        mov     r3,a
217
        inc     dptr
218
        movx    a,@dptr
219
        mov     r4,a
220
 
221
        mov     dptr,#_fpga_bytes
222
        mov     a,r5
223
        add     a,r1
224
        movx    @dptr,a
225
        mov     a,r6
226
        addc    a,r2
227
        inc     dptr
228
        movx    @dptr,a
229
        mov     a,#0
230
        addc    a,r3
231
        inc     dptr
232
        movx    @dptr,a
233
        mov     a,#0
234
        addc    a,r4
235
        inc     dptr
236
        movx    @dptr,a
237
 
238
        mov     dptr,#_fpga_checksum
239
        movx    a,@dptr
240
        mov     r7,a
241
 
242
010003$:
243
        cjne    r5,#0x00,010002$
244
        cjne    r6,#0x00,010002$
245
        mov     dptr,#_fpga_checksum
246
        mov     a,r7
247
        movx    @dptr,a
248
        ret
249
010002$:
250
        clr     _IOD0
251
        lcall   _flash_read_byte
252
        mov     a,dpl
253
        mov     _IOB,a
254
        add     a,r7
255
        mov     r7,a
256
        setb    _IOD0
257
        dec     r5
258
        cjne    r5,#0xff,010003$
259
        dec     r6
260
        sjmp    010003$
261
__endasm;
262
}
263
 
264
#include[ztex-fpga-flash1.h]
265
 
266
#else
267
#warning[Flash interface is not enabled but required for FPGA configuration using a bitstream from Flash meomory]
268
#define[FLASH_BITSTREAM_ENABLED][0]
269
#endif
270
#endif
271
 
272
#endif  /*ZTEX_FPGA_H*/

powered by: WebSVN 2.1.0

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