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

powered by: WebSVN 2.1.0

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