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/] [default/] [usb-fpga-2.04/] [default.tmp.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
#line 1 "default.c"
2
/*!
3
   Default firmware and loader for ZTEX USB-FPGA Modules 2.16
4
   Copyright (C) 2009-2014 ZTEX GmbH.
5
   http://www.ztex.de
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License version 3 as
9
   published by the Free Software Foundation.
10
 
11
   This program is distributed in the hope that it will be useful, but
12
   WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
   General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, see http://www.gnu.org/licenses/.
18
!*/
19
 
20
#line 1 "../../include/ztex-conf.h"
21
/*!
22
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
23
   Copyright (C) 2009-2014 ZTEX GmbH.
24
   http://www.ztex.de
25
 
26
   This program is free software; you can redistribute it and/or modify
27
   it under the terms of the GNU General Public License version 3 as
28
   published by the Free Software Foundation.
29
 
30
   This program is distributed in the hope that it will be useful, but
31
   WITHOUT ANY WARRANTY; without even the implied warranty of
32
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33
   General Public License for more details.
34
 
35
   You should have received a copy of the GNU General Public License
36
   along with this program; if not, see http://www.gnu.org/licenses/.
37
!*/
38
 
39
/*
40
   Configuration macros
41
*/
42
 
43
#line 25 "../../include/ztex-conf.h"
44
 
45
/*
46
   Don't expand macros in comments
47
*/
48
#line 35 "../../include/ztex-conf.h"
49
 
50
/*
51
   This macro defines the USB Vendor ID and USB Product ID  (not the product ID
52
   from the ZTEX descriptor). The Vendor ID must be purchased from the USB-IF
53
   (http://www.usb.org).
54
 
55
   The default vendor ID is the ZTEX vendor ID 0x221A, default product ID is
56
   0x100 which is assigned to ZTEX modules. These ID's can be shared by many
57
   different products which are identified by the product ID of the ZTEX
58
   descriptor. According to the USB-IF rules these ID's must not be used by
59
   hardware which is not manufactured by ZTEX. (Of course, this ID's can be
60
   used during the development process or for internal purposes.)
61
 
62
   Please read the http://www.ztex.de/firmware-kit/usb_ids.e.html for more
63
   informations about this topic.
64
 
65
   Usage:
66
        SET_VPID(<Vendor ID>,<Product ID>);
67
*/
68
#line 57 "../../include/ztex-conf.h"
69
 
70
/*
71
   This macro is called before FPGA Firmware is reset, e.g. to save some
72
   settings. After this macro is called the I/O ports are set to default
73
   states in order to avoid damage during / after the FPGA configuration.
74
   To append something to this macro use the following definition:
75
#define[PRE_FPGA_RESET][PRE_FPGA_RESET
76
...]
77
*/
78
#line 67 "../../include/ztex-conf.h"
79
 
80
 
81
/*
82
   This macro is called after FPGA Firmware has been configured. This is
83
   usually used to configure the I/O ports.
84
   To append something to this macro use the following definition:
85
#define[POST_FW_LOAD][POST_FW_LOAD
86
...]
87
*/
88
#line 77 "../../include/ztex-conf.h"
89
 
90
/*
91
   On multi FPGA boards this macro is called betwen deselection and
92
   selection of a FPGA. This can be used to store / resore I/O contents.
93
   To append something to this macro use the following definition:
94
#define[PRE_FPGA_SELECT][PRE_FPGA_SELECT
95
...]
96
*/
97
#line 86 "../../include/ztex-conf.h"
98
 
99
 
100
/*
101
  Add a vedor request for endpoint 0,
102
 
103
   Usage:
104
     ADD_EP0_VENDOR_REQUEST((<request number>,,<code executed after setup package received>,,<code executed after data package received>''));
105
   Example:
106
     ADD_EP0_VENDOR_REQUEST((0x33,,initHSFPGAConfiguration();,,));;
107
...]
108
*/
109
#line 109 "../../include/ztex-conf.h"
110
 
111
 
112
/*
113
   Add a vedor command for endpoint 0,
114
 
115
   Usage:
116
     ADD_EP0_VENDOR_COMMAND((<request number>,,<code executed after setup package received>,,<code executed after data package received>''));
117
   Example:
118
     ADD_EP0_VENDOR_COMMAND((0x33,,initHSFPGAConfiguration();,,));;
119
...]
120
*/
121
#line 132 "../../include/ztex-conf.h"
122
 
123
/*
124
  This macro generates a EP0 stall and aborts the current loop. Stalls are usually used to indicate errors.
125
*/
126
#line 141 "../../include/ztex-conf.h"
127
 
128
 
129
/*
130
   Endoint 1,2,4,5,8 configuration:
131
 
132
   EP_CONFIG(<EP number>,<interface>,<type>,<direction>,<size>,<buffers>)
133
        <EP number> = 1IN | 1OUT | 2 | 4 | 6 | 8        Endpoint number
134
        <INTERFACE> = 0 | 1 | 2 | 3                     To which interface this endpoint belongs
135
        <type>      = BULK  | ISO | INT
136
        <dir>       = IN | OUT
137
        <size>      = 512 | 1024
138
        <buffers>   = 1 | 2 | 3 | 4
139
   Example: EP_CONFIG(2,0,ISO,OUT,1024,4);
140
   Important note: No spaces next to the commas
141
 
142
 
143
   Endpoint 1 configuration:
144
 
145
   These Endpoints are defined by default as bulk endpoints and are assigned to interface 0.
146
   Endpoint size is always 64 bytes, but reported Endpoint size will be 512 bytes for USB 2.0 compliance.
147
 
148
   These Endpoints can be redefined using EP_CONFIG or using:
149
 
150
   EP1IN_CONFIG(<interface>);
151
           <INTERFACE> = 0 | 1 | 2 | 3          Interface to which EP1IN belongs; default: 0
152
   EP1OUT_CONFIG(<interface>);
153
           <INTERFACE> = 0 | 1 | 2 | 3          Interface to which EP1OUT belongs; default: 0
154
   EP1_CONFIG(<interface>);
155
           <INTERFACE> = 0 | 1 | 2 | 3          Interface to which EP1IN and EP1OUT belongs; default: 0
156
 
157
   The following (maximum) configurations are possible:
158
   EP2          EP4     EP6     EP8
159
   2x512        2x512   2x512   2x512
160
   2x512        2x512   4x512
161
   2x512        2x512   2x1024
162
   4x512                2x512   2x512
163
   4x512                4x512
164
   4x512                2x1024
165
   2x1024               2x512   2x512
166
   2x1024               4x512
167
   2x1024               2x1024
168
   3x512                3x512   2x512
169
   3x1024                       2x512
170
   4x1024
171
*/
172
#line 225 "../../include/ztex-conf.h"
173
 
174
#line 230 "../../include/ztex-conf.h"
175
 
176
#line 186 "../../include/ztex-conf.h"
177
 
178
#line 186 "../../include/ztex-conf.h"
179
 
180
#line 233 "../../include/ztex-conf.h"
181
 
182
/*
183
   ISO and INT Transactions per microframe:
184
 
185
   Default value is 1 for all endpoints.
186
 
187
   EP_PPMF(<EP number>,<transactions per microframe>)
188
        <EP number>                  = 1IN | 1OUT | 2 | 4 | 6 | 8       Endpoint
189
        <transactions per microframe> = 1 | 2 | 3                       Transactions per microframe
190
 
191
   Example: EP_PPMF(2,3);
192
   Important note: No spaces next to the commas
193
*/
194
#line 261 "../../include/ztex-conf.h"
195
 
196
#line 246 "../../include/ztex-conf.h"
197
 
198
#line 246 "../../include/ztex-conf.h"
199
 
200
#line 246 "../../include/ztex-conf.h"
201
 
202
#line 246 "../../include/ztex-conf.h"
203
 
204
#line 246 "../../include/ztex-conf.h"
205
 
206
#line 246 "../../include/ztex-conf.h"
207
 
208
#line 268 "../../include/ztex-conf.h"
209
 
210
/*
211
   Polling interval in microframes for INT transactions:
212
 
213
   Default value is 1 for all endpoints.
214
 
215
   EP_POLL(<EP number>,<polling interval>)
216
        <EP number>        = 1IN | 1OUT | 2 | 4 | 6 | 8         Endpoint
217
        <polling interval> = 1 | 2 | 3                          Polling interval
218
 
219
   Example: EP_POLL(2,1);
220
   Important note: No spaces next to the commas
221
*/
222
#line 291 "../../include/ztex-conf.h"
223
 
224
#line 281 "../../include/ztex-conf.h"
225
 
226
#line 281 "../../include/ztex-conf.h"
227
 
228
#line 281 "../../include/ztex-conf.h"
229
 
230
#line 281 "../../include/ztex-conf.h"
231
 
232
#line 281 "../../include/ztex-conf.h"
233
 
234
#line 281 "../../include/ztex-conf.h"
235
 
236
#line 298 "../../include/ztex-conf.h"
237
 
238
 
239
 
240
/*
241
   Settings which depends PRODUCT_ID, e.g extra capabilities.
242
   Overwrite this macros as desired.
243
*/
244
#line 317 "../../include/ztex-conf.h"
245
 
246
#line 319 "../../include/ztex-conf.h"
247
 
248
#line 324 "../../include/ztex-conf.h"
249
 
250
 
251
/*
252
   Identify as ZTEX USB FPGA Module 1.0
253
   Usage: IDENTITY_UFM_1_0(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
254
*/
255
#line 337 "../../include/ztex-conf.h"
256
 
257
 
258
/*
259
   Identify as ZTEX USB FPGA Module 1.1
260
   Usage: IDENTITY_UFM_1_1(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
261
*/
262
#line 350 "../../include/ztex-conf.h"
263
 
264
 
265
/*
266
   Identify as ZTEX USB FPGA Module 1.2
267
   Usage: IDENTITY_UFM_1_2(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
268
*/
269
#line 363 "../../include/ztex-conf.h"
270
 
271
/*
272
   Identify as ZTEX USB FPGA Module 1.10
273
   Usage: IDENTITY_UFM_1_10(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
274
*/
275
#line 375 "../../include/ztex-conf.h"
276
 
277
/*
278
   Identify as ZTEX USB FPGA Module 1.11
279
   Usage: IDENTITY_UFM_1_11(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
280
*/
281
#line 387 "../../include/ztex-conf.h"
282
 
283
/*
284
   Identify as ZTEX USB FPGA Module 1.15
285
   Usage: IDENTITY_UFM_1_15(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
286
*/
287
#line 400 "../../include/ztex-conf.h"
288
 
289
/*
290
   Identify as ZTEX USB FPGA Module 1.15y
291
   Usage: IDENTITY_UFM_1_15Y(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
292
*/
293
#line 413 "../../include/ztex-conf.h"
294
 
295
/*
296
   Identify as ZTEX USB FPGA Module 2.16
297
   Usage: IDENTITY_UFM_2_16(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
298
*/
299
#line 426 "../../include/ztex-conf.h"
300
 
301
/*
302
   Identify as ZTEX USB FPGA Module 2.13
303
   Usage: IDENTITY_UFM_2_13(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
304
*/
305
#line 439 "../../include/ztex-conf.h"
306
 
307
/*
308
   Identify as ZTEX USB FPGA Module 2.01
309
   Usage: IDENTITY_UFM_2_13(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
310
*/
311
#line 452 "../../include/ztex-conf.h"
312
 
313
/*
314
   Identify as ZTEX USB FPGA Module 2.04
315
   Usage: IDENTITY_UFM_2_13(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
316
*/
317
#line 465 "../../include/ztex-conf.h"
318
 
319
/*
320
   Identify as ZTEX USB Module 1.0
321
   Usage: IDENTITY_UM_1_0(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
322
*/
323
#line 477 "../../include/ztex-conf.h"
324
 
325
 
326
/*
327
   Identify as ZTEX USB XMEGA Module 1.0
328
   Usage: IDENTITY_UM_1_0(<PRODUCT_ID_0>.<PRODUCT_ID_1><PRODUCT_ID_2>.<PRODUCT_ID_3>,<FW_VERSION>);
329
*/
330
#line 490 "../../include/ztex-conf.h"
331
 
332
 
333
/*
334
   This macro defines the Manufacturer string. Limited to 31 characters.
335
*/
336
#line 496 "../../include/ztex-conf.h"
337
 
338
 
339
/*
340
   This macro defines the Product string. Limited to 31 characters.
341
*/
342
#line 502 "../../include/ztex-conf.h"
343
 
344
/*
345
   This macro enables defines the Configuration string. Limited to 31 characters.
346
*/
347
#line 507 "../../include/ztex-conf.h"
348
 
349
 
350
/*
351
   This macro disables EEPROM interface, I2C helper functions and all other I2C devices (enabled by default)
352
   Usage: DISABLE_EEPROM;
353
*/
354
#line 514 "../../include/ztex-conf.h"
355
 
356
 
357
/*
358
   This macro enables the Flash interface, if available
359
   Usage: ENABLE_FLASH;
360
*/
361
#line 521 "../../include/ztex-conf.h"
362
 
363
/*
364
   This macro enables the FPGA configuration using a bitstream from the Flash memory
365
   Usage: ENABLE_FLASH_BITSTREAM;
366
*/
367
#line 527 "../../include/ztex-conf.h"
368
 
369
/*
370
   Define this macro to use 4k sectors instead of 64k sectors of SPI Flash, if possible
371
   This is usually much slower and only recommended if you do not use the Flash for storing the Bitstream.
372
   Usage: USE_4KSECTORS;
373
*/
374
#line 534 "../../include/ztex-conf.h"
375
 
376
/*
377
   This enables the debug helper. The debug helper consists in a stack of messages which can be read out from host software.
378
   See ../examples/all/debug/Readme.
379
   Usage: ENABLE_DEBUG(<stack size>,<message_size>);
380
        <stack size>    number of messages in stack
381
        <message size>  message size in bytes
382
*/
383
#line 545 "../../include/ztex-conf.h"
384
 
385
/*
386
   This macro disables XMEGA support, if available
387
   Usage: XMEGA_DISABLE;
388
*/
389
#line 551 "../../include/ztex-conf.h"
390
 
391
/*
392
   Enables support for ZTEX Experimantal Board 1.10
393
   Usage: EXTENSION_EXP_1_10;
394
*/
395
#line 557 "../../include/ztex-conf.h"
396
 
397
/*
398
   Enables high speed FPGA configuration for ZTEX USB-FPGA Module 1.15 and 1.15y
399
   Usage: ENABLE_HS_FPGA_CONF(<ENDPOINT>);
400
        <endpoint>      endpoint which shall be used (any bulk output can be used)
401
*/
402
#line 571 "../../include/ztex-conf.h"
403
 
404
/*
405
   This macro disables MAC EEPROM support, if available
406
   Usage: MAC_EEPROM_DISABLE;
407
*/
408
#line 577 "../../include/ztex-conf.h"
409
 
410
/*
411
   Enables detection of USB-FPGA Modules 1.15x. This avoids some warnings and makes the variable is_ufm_1_15x available.
412
   Usage: ENABLE_UFM_1_15X_DETECTION;
413
*/
414
#line 583 "../../include/ztex-conf.h"
415
 
416
/*
417
   This macro disables temperature sensor support
418
   Usage: TEMP_SENSOR_DISABLE;
419
*/
420
#line 589 "../../include/ztex-conf.h"
421
 
422
        // Loads the configuration macros, see ztex-conf.h for the available macros
423
#line 1 "../../include/ztex-utils.h"
424
/*!
425
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
426
   Copyright (C) 2009-2014 ZTEX GmbH.
427
   http://www.ztex.de
428
 
429
   This program is free software; you can redistribute it and/or modify
430
   it under the terms of the GNU General Public License version 3 as
431
   published by the Free Software Foundation.
432
 
433
   This program is distributed in the hope that it will be useful, but
434
   WITHOUT ANY WARRANTY; without even the implied warranty of
435
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
436
   General Public License for more details.
437
 
438
   You should have received a copy of the GNU General Public License
439
   along with this program; if not, see http://www.gnu.org/licenses/.
440
!*/
441
 
442
/*
443
   Various utility routines
444
*/
445
 
446
#line 25 "../../include/ztex-utils.h"
447
 
448
#line 34 "../../include/ztex-utils.h"
449
 
450
#line 39 "../../include/ztex-utils.h"
451
 
452
#line 44 "../../include/ztex-utils.h"
453
 
454
typedef unsigned char BYTE;
455
typedef unsigned short WORD;
456
typedef unsigned long DWORD;
457
 
458
#line 1 "../../include/ezregs.h"
459
/*!
460
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
461
   Copyright (C) 2009-2014 ZTEX GmbH.
462
   http://www.ztex.de
463
 
464
   This program is free software; you can redistribute it and/or modify
465
   it under the terms of the GNU General Public License version 3 as
466
   published by the Free Software Foundation.
467
 
468
   This program is distributed in the hope that it will be useful, but
469
   WITHOUT ANY WARRANTY; without even the implied warranty of
470
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
471
   General Public License for more details.
472
 
473
   You should have received a copy of the GNU General Public License
474
   along with this program; if not, see http://www.gnu.org/licenses/.
475
!*/
476
 
477
/*
478
   EZ-USB registers
479
*/
480
 
481
#line 25 "../../include/ezregs.h"
482
 
483
#line 1 "../../include/ztex-utils.h"
484
/*!
485
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
486
   Copyright (C) 2009-2014 ZTEX GmbH.
487
   http://www.ztex.de
488
 
489
   This program is free software; you can redistribute it and/or modify
490
   it under the terms of the GNU General Public License version 3 as
491
   published by the Free Software Foundation.
492
 
493
   This program is distributed in the hope that it will be useful, but
494
   WITHOUT ANY WARRANTY; without even the implied warranty of
495
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
496
   General Public License for more details.
497
 
498
   You should have received a copy of the GNU General Public License
499
   along with this program; if not, see http://www.gnu.org/licenses/.
500
!*/
501
 
502
/*
503
   Various utility routines
504
*/
505
 
506
#line 26 "../../include/ezregs.h"
507
 
508
 
509
/* This syncronization delay is valid if <CPU Clock> <= 5/3*<Interface Clock>,
510
   i.e. if the Interface Clock is equal or greater than 28.8 MHz
511
 
512
   The formula for the synchonization delay is:
513
 
514
                        /    <CPU Clock>        \
515
   <syncdelay> >= 1.5 * | ----------------- + 1 |
516
                        \ <Interface Clock>     /
517
 
518
   Overwrite this macro if this formula is not satisfied
519
*/
520
 
521
#line 49 "../../include/ezregs.h"
522
 
523
// GPIF Waveform Memories
524
__xdata __at 0xE400 volatile BYTE GPIF_WAVE_DATA[128];  // GPIF Waveform Descriptor 0, 1, 2 3, data
525
__xdata __at 0xE400 volatile BYTE GPIF_WAVE0_DATA[32];  // GPIF Waveform Descriptor 0 data
526
__xdata __at 0xE420 volatile BYTE GPIF_WAVE1_DATA[32];  // GPIF Waveform Descriptor 1 data
527
__xdata __at 0xE440 volatile BYTE GPIF_WAVE2_DATA[32];  // GPIF Waveform Descriptor 2 data
528
__xdata __at 0xE460 volatile BYTE GPIF_WAVE3_DATA[32];  // GPIF Waveform Descriptor 3 data
529
#line 56 "../../include/ezregs.h"
530
 
531
// General Configuration
532
__xdata __at 0xE50D volatile BYTE GPCR2;                        // General Purpose Configuration Register 2
533
__xdata __at 0xE600 volatile BYTE CPUCS;                        // Control & Status
534
__xdata __at 0xE601 volatile BYTE IFCONFIG;                     // Interface Configuration
535
__xdata __at 0xE602 volatile BYTE PINFLAGSAB;           // FIFO FLAGA and FLAGB Assignments
536
__xdata __at 0xE603 volatile BYTE PINFLAGSCD;           // FIFO FLAGC and FLAGD Assignments
537
__xdata __at 0xE604 volatile BYTE FIFORESET;            // Restore FIFOS to default state
538
__xdata __at 0xE605 volatile BYTE BREAKPT;                      // Breakpoint
539
__xdata __at 0xE606 volatile BYTE BPADDRH;                      // Breakpoint Address H
540
__xdata __at 0xE607 volatile BYTE BPADDRL;                      // Breakpoint Address L
541
__xdata __at 0xE608 volatile BYTE UART230;                      // 230 Kbaud clock for T0,T1,T2
542
__xdata __at 0xE609 volatile BYTE FIFOPINPOLAR;         // FIFO polarities
543
__xdata __at 0xE60A volatile BYTE REVID;                        // Chip Revision
544
__xdata __at 0xE60B volatile BYTE REVCTL;                       // Chip Revision Control
545
#line 71 "../../include/ezregs.h"
546
 
547
// UDMA
548
__xdata __at 0xE60C volatile BYTE GPIFHOLDAMOUNT;               // MSTB Hold Time (for UDMA)
549
#line 74 "../../include/ezregs.h"
550
 
551
// Endpoint Configuration
552
__xdata __at 0xE610 volatile BYTE EP1OUTCFG;            // Endpoint 1-OUT Configuration
553
__xdata __at 0xE611 volatile BYTE EP1INCFG;                     // Endpoint 1-IN Configuration
554
__xdata __at 0xE612 volatile BYTE EP2CFG;                       // Endpoint 2 Configuration
555
__xdata __at 0xE613 volatile BYTE EP4CFG;                       // Endpoint 4 Configuration
556
__xdata __at 0xE614 volatile BYTE EP6CFG;                       // Endpoint 6 Configuration
557
__xdata __at 0xE615 volatile BYTE EP8CFG;                       // Endpoint 8 Configuration
558
__xdata __at 0xE618 volatile BYTE EP2FIFOCFG;           // Endpoint 2 FIFO configuration
559
__xdata __at 0xE619 volatile BYTE EP4FIFOCFG;           // Endpoint 4 FIFO configuration
560
__xdata __at 0xE61A volatile BYTE EP6FIFOCFG;           // Endpoint 6 FIFO configuration
561
__xdata __at 0xE61B volatile BYTE EP8FIFOCFG;           // Endpoint 8 FIFO configuration
562
__xdata __at 0xE620 volatile BYTE EP2AUTOINLENH;                // Endpoint 2 Packet Length H (IN only)
563
__xdata __at 0xE621 volatile BYTE EP2AUTOINLENL;                // Endpoint 2 Packet Length L (IN only)
564
__xdata __at 0xE622 volatile BYTE EP4AUTOINLENH;                // Endpoint 4 Packet Length H (IN only)
565
__xdata __at 0xE623 volatile BYTE EP4AUTOINLENL;                // Endpoint 4 Packet Length L (IN only)
566
__xdata __at 0xE624 volatile BYTE EP6AUTOINLENH;                // Endpoint 6 Packet Length H (IN only)
567
__xdata __at 0xE625 volatile BYTE EP6AUTOINLENL;                // Endpoint 6 Packet Length L (IN only)
568
__xdata __at 0xE626 volatile BYTE EP8AUTOINLENH;                // Endpoint 8 Packet Length H (IN only)
569
__xdata __at 0xE627 volatile BYTE EP8AUTOINLENL;                // Endpoint 8 Packet Length L (IN only)
570
__xdata __at 0xE628 volatile BYTE ECCCFG;                       // ECC Configuration
571
__xdata __at 0xE629 volatile BYTE ECCRESET;                     // ECC Reset
572
__xdata __at 0xE62A volatile BYTE ECC1B0;                       // ECC1 Byte 0 Address
573
__xdata __at 0xE62B volatile BYTE ECC1B1;                       // ECC1 Byte 1 Address
574
__xdata __at 0xE62C volatile BYTE ECC1B2;                       // ECC1 Byte 2 Address
575
__xdata __at 0xE62D volatile BYTE ECC2B0;                       // ECC2 Byte 0 Address
576
__xdata __at 0xE62E volatile BYTE ECC2B1;                       // ECC2 Byte 1 Address
577
__xdata __at 0xE62F volatile BYTE ECC2B2;                       // ECC2 Byte 2 Address
578
__xdata __at 0xE630 volatile BYTE EP2FIFOPFH;           // EP2 Programmable Flag trigger H
579
__xdata __at 0xE631 volatile BYTE EP2FIFOPFL;           // EP2 Programmable Flag trigger L
580
__xdata __at 0xE632 volatile BYTE EP4FIFOPFH;           // EP4 Programmable Flag trigger H
581
__xdata __at 0xE633 volatile BYTE EP4FIFOPFL;           // EP4 Programmable Flag trigger L
582
__xdata __at 0xE634 volatile BYTE EP6FIFOPFH;           // EP6 Programmable Flag trigger H
583
__xdata __at 0xE635 volatile BYTE EP6FIFOPFL;           // EP6 Programmable Flag trigger L
584
__xdata __at 0xE636 volatile BYTE EP8FIFOPFH;           // EP8 Programmable Flag trigger H
585
__xdata __at 0xE637 volatile BYTE EP8FIFOPFL;           // EP8 Programmable Flag trigger L
586
__xdata __at 0xE640 volatile BYTE EP2ISOINPKTS;         // EP2 (if ISO) IN Packets per frame (1-3)
587
__xdata __at 0xE641 volatile BYTE EP4ISOINPKTS;         // EP4 (if ISO) IN Packets per frame (1-3)
588
__xdata __at 0xE642 volatile BYTE EP6ISOINPKTS;         // EP6 (if ISO) IN Packets per frame (1-3)
589
__xdata __at 0xE643 volatile BYTE EP8ISOINPKTS;         // EP8 (if ISO) IN Packets per frame (1-3)
590
__xdata __at 0xE648 volatile BYTE INPKTEND;                     // Force IN Packet End
591
__xdata __at 0xE649 volatile BYTE OUTPKTEND;            // Force OUT Packet End
592
#line 116 "../../include/ezregs.h"
593
 
594
// Interrupts
595
__xdata __at 0xE650 volatile BYTE EP2FIFOIE;            // Endpoint 2 Flag Interrupt Enable
596
__xdata __at 0xE651 volatile BYTE EP2FIFOIRQ;           // Endpoint 2 Flag Interrupt Request
597
__xdata __at 0xE652 volatile BYTE EP4FIFOIE;            // Endpoint 4 Flag Interrupt Enable
598
__xdata __at 0xE653 volatile BYTE EP4FIFOIRQ;           // Endpoint 4 Flag Interrupt Request
599
__xdata __at 0xE654 volatile BYTE EP6FIFOIE;            // Endpoint 6 Flag Interrupt Enable
600
__xdata __at 0xE655 volatile BYTE EP6FIFOIRQ;           // Endpoint 6 Flag Interrupt Request
601
__xdata __at 0xE656 volatile BYTE EP8FIFOIE;            // Endpoint 8 Flag Interrupt Enable
602
__xdata __at 0xE657 volatile BYTE EP8FIFOIRQ;           // Endpoint 8 Flag Interrupt Request
603
__xdata __at 0xE658 volatile BYTE IBNIE;                        // IN-BULK-NAK Interrupt Enable
604
__xdata __at 0xE659 volatile BYTE IBNIRQ;                       // IN-BULK-NAK interrupt Request
605
__xdata __at 0xE65A volatile BYTE NAKIE;                        // Endpoint Ping NAK interrupt Enable
606
__xdata __at 0xE65B volatile BYTE NAKIRQ;                       // Endpoint Ping NAK interrupt Request
607
__xdata __at 0xE65C volatile BYTE USBIE;                        // USB Int Enables
608
__xdata __at 0xE65D volatile BYTE USBIRQ;                       // USB Interrupt Requests
609
__xdata __at 0xE65E volatile BYTE EPIE;                 // Endpoint Interrupt Enables
610
__xdata __at 0xE65F volatile BYTE EPIRQ;                        // Endpoint Interrupt Requests
611
__xdata __at 0xE660 volatile BYTE GPIFIE;                       // GPIF Interrupt Enable
612
__xdata __at 0xE661 volatile BYTE GPIFIRQ;                      // GPIF Interrupt Request
613
__xdata __at 0xE662 volatile BYTE USBERRIE;                     // USB Error Interrupt Enables
614
__xdata __at 0xE663 volatile BYTE USBERRIRQ;            // USB Error Interrupt Requests
615
__xdata __at 0xE664 volatile BYTE ERRCNTLIM;            // USB Error counter and limit
616
__xdata __at 0xE665 volatile BYTE CLRERRCNT;            // Clear Error Counter EC[3..0]
617
__xdata __at 0xE666 volatile BYTE INT2IVEC;                     // Interupt 2 (USB) Autovector
618
__xdata __at 0xE667 volatile BYTE INT4IVEC;                     // Interupt 4 (FIFOS & GPIF) Autovector
619
__xdata __at 0xE668 volatile BYTE INTSETUP;                     // Interrupt 2&4 Setup
620
#line 143 "../../include/ezregs.h"
621
 
622
// Input/Output
623
__xdata __at 0xE670 volatile BYTE PORTACFG;                     // I/O PORTA Alternate Configuration
624
__xdata __at 0xE671 volatile BYTE PORTCCFG;                     // I/O PORTC Alternate Configuration
625
__xdata __at 0xE672 volatile BYTE PORTECFG;                     // I/O PORTE Alternate Configuration
626
__xdata __at 0xE678 volatile BYTE I2CS;                 // Control & Status
627
__xdata __at 0xE679 volatile BYTE I2DAT;                        // Data
628
__xdata __at 0xE67A volatile BYTE I2CTL;                        // I2C Control
629
__xdata __at 0xE67B volatile BYTE XAUTODAT1;            // Autoptr1 MOVX access
630
__xdata __at 0xE67B volatile BYTE EXTAUTODAT1;          // Autoptr1 MOVX access
631
__xdata __at 0xE67C volatile BYTE XAUTODAT2;            // Autoptr2 MOVX access
632
__xdata __at 0xE67C volatile BYTE EXTAUTODAT2;          // Autoptr2 MOVX access
633
#line 155 "../../include/ezregs.h"
634
 
635
// UDMA CRC
636
__xdata __at 0xE67D volatile BYTE UDMACRCH;                     // UDMA CRC MSB
637
__xdata __at 0xE67E volatile BYTE UDMACRCL;                     // UDMA CRC LSB
638
__xdata __at 0xE67F volatile BYTE UDMACRCQUALIFIER;             // UDMA CRC Qualifier
639
#line 160 "../../include/ezregs.h"
640
 
641
// USB Control
642
__xdata __at 0xE680 volatile BYTE USBCS;                        // USB Control & Status
643
__xdata __at 0xE681 volatile BYTE SUSPEND;                      // Put chip into suspend
644
__xdata __at 0xE682 volatile BYTE WAKEUPCS;                     // Wakeup source and polarity
645
__xdata __at 0xE683 volatile BYTE TOGCTL;                       // Toggle Control
646
__xdata __at 0xE684 volatile BYTE USBFRAMEH;            // USB Frame count H
647
__xdata __at 0xE685 volatile BYTE USBFRAMEL;            // USB Frame count L
648
__xdata __at 0xE686 volatile BYTE MICROFRAME;           // Microframe count, 0-7
649
__xdata __at 0xE687 volatile BYTE FNADDR;                       // USB Function address
650
#line 170 "../../include/ezregs.h"
651
 
652
// Endpoints
653
__xdata __at 0xE68A volatile BYTE EP0BCH;                       // Endpoint 0 Byte Count H
654
__xdata __at 0xE68B volatile BYTE EP0BCL;                       // Endpoint 0 Byte Count L
655
__xdata __at 0xE68D volatile BYTE EP1OUTBC;                     // Endpoint 1 OUT Byte Count
656
__xdata __at 0xE68F volatile BYTE EP1INBC;                      // Endpoint 1 IN Byte Count
657
__xdata __at 0xE690 volatile BYTE EP2BCH;                       // Endpoint 2 Byte Count H
658
__xdata __at 0xE691 volatile BYTE EP2BCL;                       // Endpoint 2 Byte Count L
659
__xdata __at 0xE694 volatile BYTE EP4BCH;                       // Endpoint 4 Byte Count H
660
__xdata __at 0xE695 volatile BYTE EP4BCL;                       // Endpoint 4 Byte Count L
661
__xdata __at 0xE698 volatile BYTE EP6BCH;                       // Endpoint 6 Byte Count H
662
__xdata __at 0xE699 volatile BYTE EP6BCL;                       // Endpoint 6 Byte Count L
663
__xdata __at 0xE69C volatile BYTE EP8BCH;                       // Endpoint 8 Byte Count H
664
__xdata __at 0xE69D volatile BYTE EP8BCL;                       // Endpoint 8 Byte Count L
665
__xdata __at 0xE6A0 volatile BYTE EP0CS;                        // Endpoint Control and Status
666
__xdata __at 0xE6A1 volatile BYTE EP1OUTCS;                     // Endpoint 1 OUT Control and Status
667
__xdata __at 0xE6A2 volatile BYTE EP1INCS;                      // Endpoint 1 IN Control and Status
668
__xdata __at 0xE6A3 volatile BYTE EPXCS[4];                     // Endpoint 2-8 Control and Status
669
__xdata __at 0xE6A3 volatile BYTE EP2CS;                        // Endpoint 2 Control and Status
670
__xdata __at 0xE6A4 volatile BYTE EP4CS;                        // Endpoint 4 Control and Status
671
__xdata __at 0xE6A5 volatile BYTE EP6CS;                        // Endpoint 6 Control and Status
672
__xdata __at 0xE6A6 volatile BYTE EP8CS;                        // Endpoint 8 Control and Status
673
__xdata __at 0xE6A7 volatile BYTE EP2FIFOFLGS;          // Endpoint 2 Flags
674
__xdata __at 0xE6A8 volatile BYTE EP4FIFOFLGS;          // Endpoint 4 Flags
675
__xdata __at 0xE6A9 volatile BYTE EP6FIFOFLGS;          // Endpoint 6 Flags
676
__xdata __at 0xE6AA volatile BYTE EP8FIFOFLGS;          // Endpoint 8 Flags
677
__xdata __at 0xE6AB volatile BYTE EP2FIFOBCH;           // EP2 FIFO total byte count H
678
__xdata __at 0xE6AC volatile BYTE EP2FIFOBCL;           // EP2 FIFO total byte count L
679
__xdata __at 0xE6AD volatile BYTE EP4FIFOBCH;           // EP4 FIFO total byte count H
680
__xdata __at 0xE6AE volatile BYTE EP4FIFOBCL;           // EP4 FIFO total byte count L
681
__xdata __at 0xE6AF volatile BYTE EP6FIFOBCH;           // EP6 FIFO total byte count H
682
__xdata __at 0xE6B0 volatile BYTE EP6FIFOBCL;           // EP6 FIFO total byte count L
683
__xdata __at 0xE6B1 volatile BYTE EP8FIFOBCH;           // EP8 FIFO total byte count H
684
__xdata __at 0xE6B2 volatile BYTE EP8FIFOBCL;           // EP8 FIFO total byte count L
685
__xdata __at 0xE6B3 volatile BYTE SUDPTRH;                      // Setup Data Pointer high address byte
686
__xdata __at 0xE6B4 volatile BYTE SUDPTRL;                      // Setup Data Pointer low address byte
687
__xdata __at 0xE6B5 volatile BYTE SUDPTRCTL;            // Setup Data Pointer Auto Mode
688
__xdata __at 0xE6B8 volatile BYTE SETUPDAT[8];          // 8 bytes of SETUP data
689
__xdata __at 0xE6B8 volatile BYTE bmRequestType;                // Request Type, Direction, and Recipient
690
__xdata __at 0xE6B9 volatile BYTE bRequest;                     // The actual request
691
#line 210 "../../include/ezregs.h"
692
__xdata __at 0xE6BA volatile BYTE wValueL;
693
__xdata __at 0xE6BB volatile BYTE wValueH;
694
__xdata __at 0xE6BC volatile BYTE wIndexL;
695
__xdata __at 0xE6BD volatile BYTE wIndexH;
696
__xdata __at 0xE6BE volatile BYTE wLengthL;                     // Number of bytes to transfer if there is a data phase
697
#line 215 "../../include/ezregs.h"
698
__xdata __at 0xE6BF volatile BYTE wLengthH;
699
 
700
// GPIF
701
__xdata __at 0xE6C0 volatile BYTE GPIFWFSELECT;         // Waveform Selector
702
__xdata __at 0xE6C1 volatile BYTE GPIFIDLECS;           // GPIF Done, GPIF IDLE drive mode
703
__xdata __at 0xE6C2 volatile BYTE GPIFIDLECTL;          // Inactive Bus, CTL states
704
__xdata __at 0xE6C3 volatile BYTE GPIFCTLCFG;           // CTL OUT pin drive
705
__xdata __at 0xE6C4 volatile BYTE GPIFADRH;                     // GPIF Address H
706
__xdata __at 0xE6C5 volatile BYTE GPIFADRL;                     // GPIF Address L
707
#line 224 "../../include/ezregs.h"
708
 
709
// FLOWSTATE 
710
__xdata __at 0xE6C6 volatile BYTE FLOWSTATE;            // Flowstate Enable and Selector
711
__xdata __at 0xE6C7 volatile BYTE FLOWLOGIC;            // Flowstate Logic
712
__xdata __at 0xE6C8 volatile BYTE FLOWEQ0CTL;           // CTL-Pin States in Flowstate (when Logic = 0)
713
__xdata __at 0xE6C9 volatile BYTE FLOWEQ1CTL;           // CTL-Pin States in Flowstate (when Logic = 1)
714
__xdata __at 0xE6CA volatile BYTE FLOWHOLDOFF;          // Holdoff Configuration
715
__xdata __at 0xE6CB volatile BYTE FLOWSTB;                      // Flowstate Strobe Configuration
716
__xdata __at 0xE6CC volatile BYTE FLOWSTBEDGE;          // Flowstate Rising/Falling Edge Configuration
717
__xdata __at 0xE6CD volatile BYTE FLOWSTBHPERIOD;               // Master-Strobe Half-Period
718
__xdata __at 0xE6CE volatile BYTE GPIFTCB3;                     // GPIF Transaction Count Byte 3
719
__xdata __at 0xE6CF volatile BYTE GPIFTCB2;                     // GPIF Transaction Count Byte 2
720
__xdata __at 0xE6D0 volatile BYTE GPIFTCB1;                     // GPIF Transaction Count Byte 1
721
__xdata __at 0xE6D1 volatile BYTE GPIFTCB0;                     // GPIF Transaction Count Byte 0
722
__xdata __at 0xE6D2 volatile BYTE EP2GPIFFLGSEL;                // EP2 GPIF Flag select
723
__xdata __at 0xE6D3 volatile BYTE EP2GPIFPFSTOP;                // Stop GPIF EP2 transaction on prog. flag
724
__xdata __at 0xE6D4 volatile BYTE EP2GPIFTRIG;          // EP2 FIFO Trigger
725
__xdata __at 0xE6DA volatile BYTE EP4GPIFFLGSEL;                // EP4 GPIF Flag select
726
__xdata __at 0xE6DB volatile BYTE EP4GPIFPFSTOP;                // Stop GPIF EP4 transaction on prog. flag
727
__xdata __at 0xE6DC volatile BYTE EP4GPIFTRIG;          // EP4 FIFO Trigger
728
__xdata __at 0xE6E2 volatile BYTE EP6GPIFFLGSEL;                // EP6 GPIF Flag select
729
__xdata __at 0xE6E3 volatile BYTE EP6GPIFPFSTOP;                // Stop GPIF EP6 transaction on prog. flag
730
__xdata __at 0xE6E4 volatile BYTE EP6GPIFTRIG;          // EP6 FIFO Trigger
731
__xdata __at 0xE6EA volatile BYTE EP8GPIFFLGSEL;                // EP8 GPIF Flag select
732
__xdata __at 0xE6EB volatile BYTE EP8GPIFPFSTOP;                // Stop GPIF EP8 transaction on prog. flag
733
__xdata __at 0xE6EC volatile BYTE EP8GPIFTRIG;          // EP8 FIFO Trigger
734
__xdata __at 0xE6F0 volatile BYTE XGPIFSGLDATH;         // GPIF Data H (16-bit mode only)
735
__xdata __at 0xE6F1 volatile BYTE XGPIFSGLDATLX;                // Read/Write GPIF Data L & trigger transac
736
__xdata __at 0xE6F2 volatile BYTE XGPIFSGLDATLNOX;              // Read GPIF Data L, no transac trigger
737
__xdata __at 0xE6F3 volatile BYTE GPIFREADYCFG;         // Internal RDY,Sync/Async, RDY5CFG
738
__xdata __at 0xE6F4 volatile BYTE GPIFREADYSTAT;                // RDY pin states
739
__xdata __at 0xE6F5 volatile BYTE GPIFABORT;            // Abort GPIF cycles
740
#line 256 "../../include/ezregs.h"
741
 
742
// Endpoint Buffers
743
__xdata __at 0xE740 volatile BYTE EP0BUF[64];           // EP0 IN-OUT buffer
744
__xdata __at 0xE780 volatile BYTE EP1OUTBUF[64];                // EP1-OUT buffer
745
__xdata __at 0xE7C0 volatile BYTE EP1INBUF[64];         // EP1-IN buffer
746
__xdata __at 0xF000 volatile BYTE EP2FIFOBUF[1024];             // 512/1024-byte EP2 buffer (IN or OUT)
747
__xdata __at 0xF400 volatile BYTE EP4FIFOBUF[1024];             // 512 byte EP4 buffer (IN or OUT)
748
__xdata __at 0xF800 volatile BYTE EP6FIFOBUF[1024];             // 512/1024-byte EP6 buffer (IN or OUT)
749
__xdata __at 0xFC00 volatile BYTE EP8FIFOBUF[1024];             // 512 byte EP8 buffer (IN or OUT)
750
#line 265 "../../include/ezregs.h"
751
 
752
 
753
// Special Function Registers (__sfrs)
754
__sfr __at 0x80 IOA;                                    // Port A
755
__sbit __at 0x80+0 IOA0;                                 // Port A bit 0
756
__sbit __at 0x80+1 IOA1;                                        // Port A bit 1
757
__sbit __at 0x80+2 IOA2;                                        // Port A bit 2
758
__sbit __at 0x80+3 IOA3;                                        // Port A bit 3
759
__sbit __at 0x80+4 IOA4;                                        // Port A bit 4
760
__sbit __at 0x80+5 IOA5;                                        // Port A bit 5
761
__sbit __at 0x80+6 IOA6;                                        // Port A bit 6
762
__sbit __at 0x80+7 IOA7;                                        // Port A bit 7
763
__sfr __at 0x81 SP;                                             // Stack Pointer
764
__sfr __at 0x82 DPL0;                                   // Data Pointer 0 L
765
__sfr __at 0x83 DPH0;                                   // Data Pointer 0 H
766
__sfr __at 0x84 DPL1;                                   // Data Pointer 1 L
767
__sfr __at 0x85 DPH1;                                   // Data Pointer 0 H
768
__sfr __at 0x86 DPS;                                    // Data Pointer 0/1 select
769
__sfr __at 0x87 PCON;                                   // Power Control
770
__sfr __at 0x88 TCON;                                   // Timer/Counter Control
771
__sbit __at 0x88+0 IT0;                                  // Interrupt 0 Type select
772
__sbit __at 0x88+1 IE0;                                 // Interrupt 0 Edge detect
773
__sbit __at 0x88+2 IT1;                                 // Interrupt 1 Type select
774
__sbit __at 0x88+3 IE1;                                 // Interrupt 1 Edge detect
775
__sbit __at 0x88+4 TR0;                                 // Timer 0 Run Control
776
__sbit __at 0x88+5 TF0;                                 // Timer 0 Overflow Flag
777
__sbit __at 0x88+6 TR1;                                 // Timer 1 Run Control
778
__sbit __at 0x88+7 TF1;                                 // Timer 1 Overflow Flag
779
__sfr __at 0x89 TMOD;                                   // Timer/Counter Mode Control
780
__sfr __at 0x8A TL0;                                    // Timer 0 reload L
781
__sfr __at 0x8B TL1;                                    // Timer 1 reload L
782
__sfr __at 0x8C TH0;                                    // Timer 0 reload H
783
__sfr __at 0x8D TH1;                                    // Timer 1 reload H
784
__sfr __at 0x8E CKCON;                                  // Clock Control
785
__sfr __at 0x90 IOB;                                    // Port B
786
__sbit __at 0x90+0 IOB0;                                 // Port B bit 0
787
__sbit __at 0x90+1 IOB1;                                        // Port B bit 1
788
__sbit __at 0x90+2 IOB2;                                        // Port B bit 2
789
__sbit __at 0x90+3 IOB3;                                        // Port B bit 3
790
__sbit __at 0x90+4 IOB4;                                        // Port B bit 4
791
__sbit __at 0x90+5 IOB5;                                        // Port B bit 5
792
__sbit __at 0x90+6 IOB6;                                        // Port B bit 6
793
__sbit __at 0x90+7 IOB7;                                        // Port B bit 7
794
__sfr __at 0x91 EXIF;                                   // External Interrupt Flag(s)
795
__sfr __at 0x92 MPAGE;                                  // Upper Addr Byte of MOVX using @R0 / @R1
796
#line 310 "../../include/ezregs.h"
797
__sfr __at (0x92) _XPAGE;
798
__sfr __at 0x98 SCON0;                                  // Serial Port 0 Control
799
__sbit __at 0x98+0 RI_0;                                 // Recive Interrupt Flag
800
__sbit __at 0x98+1 TI_0;                                        // Transmit Interrupt Flag
801
__sbit __at 0x98+2 RB8_0;                                       // State of the 9th bit / Stop Bit received
802
__sbit __at 0x98+3 TB8_0;                                       // State of the 9th bit transmitted
803
__sbit __at 0x98+4 REN_0;                                       // Receive enable
804
__sbit __at 0x98+5 SM2_0;                                       // Multiprocessor communication enable
805
__sbit __at 0x98+6 SM1_0;                                       // Serial Port 0 mode bit 1
806
__sbit __at 0x98+7 SM0_0;                                       // Serial Port 0 mode bit 0
807
__sfr __at 0x99 SBUF0;                                  // Serial Port 0 Data Buffer
808
__sfr __at 0x9A AUTOPTRH1;                                      // Autopointer 1 Address H
809
__sfr __at 0x9B AUTOPTRL1;                                      // Autopointer 1 Address L
810
__sfr __at 0x9D AUTOPTRH2;                                      // Autopointer 2 Address H
811
__sfr __at 0x9E AUTOPTRL2;                                      // Autopointer 2 Address L
812
__sfr __at 0xA0 IOC;                                    // Port C
813
__sbit __at 0xA0+0 IOC0;                                 // Port C bit 0
814
__sbit __at 0xA0+1 IOC1;                                        // Port C bit 1
815
__sbit __at 0xA0+2 IOC2;                                        // Port C bit 2
816
__sbit __at 0xA0+3 IOC3;                                        // Port C bit 3
817
__sbit __at 0xA0+4 IOC4;                                        // Port C bit 4
818
__sbit __at 0xA0+5 IOC5;                                        // Port C bit 5
819
__sbit __at 0xA0+6 IOC6;                                        // Port C bit 6
820
__sbit __at 0xA0+7 IOC7;                                        // Port C bit 7
821
__sfr __at 0xA1 INT2CLR;                                        // Interrupt 2 clear
822
__sfr __at 0xA2 INT4CLR;                                        // Interrupt 4clear
823
__sfr __at 0xA8 IE;                                             // Interrupt Enable
824
__sbit __at 0xA8+0 EX0;                                  // Enable external interrupt 0
825
__sbit __at 0xA8+1 ET0;                                 // Enable Timer 0 interrupt
826
__sbit __at 0xA8+2 EX1;                                 // Enable external interrupt 1
827
__sbit __at 0xA8+3 ET1;                                 // Enable Timer 1 interrupt
828
__sbit __at 0xA8+4 ES0;                                 // Enable Serial Port 0 interrupt
829
__sbit __at 0xA8+5 ET2;                                 // Enable Timer 2 interrupt
830
__sbit __at 0xA8+6 ES1;                                 // Enable Serial Port 1 interrupt
831
__sbit __at 0xA8+7 EA;                                  // Global interrupt enable
832
__sfr __at 0xAA EP2468STAT;                                     // Endpoint 2,4,6,8 status flags
833
__sfr __at 0xAB EP24FIFOFLGS;                           // Endpoint 2,4 slave FIFO flags
834
__sfr __at 0xAC EP68FIFOFLGS;                           // Endpoint 6,8 slave FIFO flags
835
__sfr __at 0xAF AUTOPTRSETUP;                           // Autopointer 1&2 set-up
836
__sfr __at 0xB0 IOD;                                    // Port D
837
__sbit __at 0xB0+0 IOD0;                                 // Port D bit 0
838
__sbit __at 0xB0+1 IOD1;                                        // Port D bit 1
839
__sbit __at 0xB0+2 IOD2;                                        // Port D bit 2
840
__sbit __at 0xB0+3 IOD3;                                        // Port D bit 3
841
__sbit __at 0xB0+4 IOD4;                                        // Port D bit 4
842
__sbit __at 0xB0+5 IOD5;                                        // Port D bit 5
843
__sbit __at 0xB0+6 IOD6;                                        // Port D bit 6
844
__sbit __at 0xB0+7 IOD7;                                        // Port D bit 7
845
__sfr __at 0xB1 IOE;                                    // Port E
846
__sfr __at 0xB2 OEA;                                    // Port A Output Enable
847
__sfr __at 0xB3 OEB;                                    // Port B Output Enable
848
__sfr __at 0xB4 OEC;                                    // Port C Output Enable
849
__sfr __at 0xB5 OED;                                    // Port D Output Enable
850
__sfr __at 0xB6 OEE;                                    // Port E Output Enable
851
__sfr __at 0xB8 IP;                                             // Interrupt priority
852
__sbit __at 0xB8+0 PX0;                                  // External interrupt 0 priority control
853
__sbit __at 0xB8+1 PT0;                                 // Timer 0 interrupt priority control
854
__sbit __at 0xB8+2 PX1;                                 // External interrupt 1 priority control
855
__sbit __at 0xB8+3 PT1;                                 // Timer 1 interrupt priority control
856
__sbit __at 0xB8+4 PS0;                                 // Serial Port 0 interrupt priority control
857
__sbit __at 0xB8+5 PT2;                                 // Timer 2 interrupt priority control
858
__sbit __at 0xB8+6 PS1;                                 // Serial Port 1 interrupt priority control
859
__sfr __at 0xBA EP01STAT;                                       // Endpoint 0&1 Status
860
__sfr __at 0xBB GPIFTRIG;                                       // Endpoint 2,4,6,8 GPIF slafe FIFO Trigger
861
__sfr __at 0xBD GPIFSGLDATH;                            // GPIF Data H (16-bit mode only)
862
__sfr __at 0xBE GPIFSGLDATLX;                           // GPIF Data L w/ Trigger
863
__sfr __at 0xBF GPIFSGLDATLNOX;                         // GPIF Data L w/ No Trigger
864
__sfr __at 0xC0 SCON1;                                  // Serial Port 1 Control
865
__sbit __at 0xC0+0 RI_1;                                 // Recive Interrupt Flag
866
__sbit __at 0xC0+1 TI_1;                                        // Transmit Interrupt Flag
867
__sbit __at 0xC0+2 RB8_1;                                       // State of the 9th bit / Stop Bit received
868
__sbit __at 0xC0+3 TB8_1;                                       // State of the 9th bit transmitted
869
__sbit __at 0xC0+4 REN_1;                                       // Receive enable
870
__sbit __at 0xC0+5 SM2_1;                                       // Multiprocessor communication enable
871
__sbit __at 0xC0+6 SM1_1;                                       // Serial Port 1 mode bit 1
872
__sbit __at 0xC0+7 SM0_1;                                       // Serial Port 1 mode bit 0
873
__sfr __at 0xC1 SBUF1;                                  // Serial Port 1 Data Buffer
874
__sfr __at 0xC8 T2CON;                                  // Timer/Counter 2 Control
875
__sbit __at 0xC8+0 CPRL2;                                        // Capture/reload flag
876
__sbit __at 0xC8+1 CT2;                                 // Counter/Timer select
877
__sbit __at 0xC8+2 TR2;                                 // Timer 2 run control flag
878
__sbit __at 0xC8+3 EXEN2;                                       // Timer 2 external enable
879
__sbit __at 0xC8+4 TCLK;                                        // Transmit clock flag
880
__sbit __at 0xC8+5 RCLK;                                        // Receive clock flag
881
__sbit __at 0xC8+6 EXF2;                                        // Timer 2 external flag
882
__sbit __at 0xC8+7 TF2;                                 // Timer 2 overflow flag
883
__sfr __at 0xCA RCAP2L;                                 // Capture for Timer 2, auto-reload, up-counter L
884
__sfr __at 0xCB RCAP2H;                                 // Capture for Timer 2, auto-reload, up-counter H
885
__sfr __at 0xCC TL2;                                    // Timer 2 reload L
886
__sfr __at 0xCD TH2;                                    // Timer 2 reload H
887
__sfr __at 0xD0 PSW;                                    // Program Status Word
888
__sbit __at 0xD0+0 PF;                                   // Parity flag
889
__sbit __at 0xD0+1 F1;                                  // User flag 1
890
__sbit __at 0xD0+2 OV;                                  // Overflow flag
891
__sbit __at 0xD0+3 RS0;                                 // Register bank select bit 0
892
__sbit __at 0xD0+4 RS1;                                 // Register bank select bit 1
893
__sbit __at 0xD0+5 F0;                                  // User flag 0
894
__sbit __at 0xD0+6 AC;                                  // Auxiliary carry flag
895
__sbit __at 0xD0+7 CY;                                  // Carry flag
896
__sfr __at 0xD8 EICON;                                  // External Interrupt Control
897
__sbit __at 0xD8+3 INT6;                                        // External interrupt 6
898
__sbit __at 0xD8+4 RESI;                                        // Wakeup interrupt flag
899
__sbit __at 0xD8+5 ERESI;                                       // Enable Resume interrupt
900
__sbit __at 0xD8+7 SMOD1;                                       // Serial Port 1 baud rate doubler enable
901
__sfr __at 0xE0 ACC;                                    // Accumulator
902
__sbit __at 0xE0+0 ACC0;                                 // Accumulator bit 0
903
__sbit __at 0xE0+1 ACC1;                                        // Accumulator bit 1
904
__sbit __at 0xE0+2 ACC2;                                        // Accumulator bit 2
905
__sbit __at 0xE0+3 ACC3;                                        // Accumulator bit 3
906
__sbit __at 0xE0+4 ACC4;                                        // Accumulator bit 4
907
__sbit __at 0xE0+5 ACC5;                                        // Accumulator bit 5
908
__sbit __at 0xE0+6 ACC6;                                        // Accumulator bit 6
909
__sbit __at 0xE0+7 ACC7;                                        // Accumulator bit 7
910
__sfr __at 0xE8 EIE;                                    // External Interrupt Enable(s)
911
__sbit __at 0xE8+0 EUSB;                                 // Enable USB interrupt (USBINT)
912
__sbit __at 0xE8+1 EI2C;                                        // Enable I2C bus interrupt (I2CINT)
913
__sbit __at 0xE8+2 EIEX4;                                       // Enable external interrupt 4
914
__sbit __at 0xE8+3 EIEX5;                                       // Enable external interrupt 5
915
__sbit __at 0xE8+4 EIEX6;                                       // Enable external interrupt 6
916
__sfr __at 0xF0 BREG;                                   // B Register
917
__sbit __at 0xF0+0 BREG0;                                        // B Register bit 0
918
__sbit __at 0xF0+1 BREG1;                                       // B Register bit 1
919
__sbit __at 0xF0+2 BREG2;                                       // B Register bit 2
920
__sbit __at 0xF0+3 BREG3;                                       // B Register bit 3
921
__sbit __at 0xF0+4 BREG4;                                       // B Register bit 4
922
__sbit __at 0xF0+5 BREG5;                                       // B Register bit 5
923
__sbit __at 0xF0+6 BREG6;                                       // B Register bit 6
924
__sbit __at 0xF0+7 BREG7;                                       // B Register bit 7
925
__sfr __at 0xF8 EIP;                                    // External Interrupt Priority Control
926
__sbit __at 0xF8+0 PUSB;                                 // USBINT priority control
927
__sbit __at 0xF8+1 PI2C;                                        // I2CINT priority control
928
__sbit __at 0xF8+2 EIPX4;                                       // External interrupt 4 priority control
929
__sbit __at 0xF8+3 EIPX5;                                       // External interrupt 5 priority control
930
__sbit __at 0xF8+4 EIPX6;                                       // External interrupt 6 priority control
931
#line 444 "../../include/ezregs.h"
932
 
933
#line 49 "../../include/ztex-utils.h"
934
 
935
#line 1 "../../include/ezintavecs.h"
936
/*!
937
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
938
   Copyright (C) 2009-2014 ZTEX GmbH.
939
   http://www.ztex.de
940
 
941
   This program is free software; you can redistribute it and/or modify
942
   it under the terms of the GNU General Public License version 3 as
943
   published by the Free Software Foundation.
944
 
945
   This program is distributed in the hope that it will be useful, but
946
   WITHOUT ANY WARRANTY; without even the implied warranty of
947
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
948
   General Public License for more details.
949
 
950
   You should have received a copy of the GNU General Public License
951
   along with this program; if not, see http://www.gnu.org/licenses/.
952
!*/
953
 
954
/*
955
   EZ-USB Autovectors
956
*/
957
 
958
#line 25 "../../include/ezintavecs.h"
959
 
960
#line 1 "../../include/ztex-utils.h"
961
/*!
962
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
963
   Copyright (C) 2009-2014 ZTEX GmbH.
964
   http://www.ztex.de
965
 
966
   This program is free software; you can redistribute it and/or modify
967
   it under the terms of the GNU General Public License version 3 as
968
   published by the Free Software Foundation.
969
 
970
   This program is distributed in the hope that it will be useful, but
971
   WITHOUT ANY WARRANTY; without even the implied warranty of
972
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
973
   General Public License for more details.
974
 
975
   You should have received a copy of the GNU General Public License
976
   along with this program; if not, see http://www.gnu.org/licenses/.
977
!*/
978
 
979
/*
980
   Various utility routines
981
*/
982
 
983
#line 26 "../../include/ezintavecs.h"
984
 
985
 
986
struct INTVEC {
987
    BYTE op;
988
    BYTE addrH;
989
    BYTE addrL;
990
};
991
 
992
#line 87 "../../include/ezintavecs.h"
993
 
994
#line 34 "../../include/ezintavecs.h"
995
__xdata __at 0x0003 struct INTVEC INT0VEC_IE0;
996
__xdata __at 0x000b struct INTVEC INT1VEC_T0;
997
__xdata __at 0x0013 struct INTVEC INT2VEC_IE1;
998
__xdata __at 0x001b struct INTVEC INT3VEC_T1;
999
__xdata __at 0x0023 struct INTVEC INT4VEC_USART0;
1000
__xdata __at 0x002b struct INTVEC INT5VEC_T2;
1001
__xdata __at 0x0033 struct INTVEC INT6VEC_RESUME;
1002
__xdata __at 0x003b struct INTVEC INT7VEC_USART1;
1003
__xdata __at 0x0043 struct INTVEC INT8VEC_USB;
1004
__xdata __at 0x004b struct INTVEC INT9VEC_I2C;
1005
__xdata __at 0x0053 struct INTVEC INT10VEC_GPIF;
1006
__xdata __at 0x005b struct INTVEC INT11VEC_IE5;
1007
__xdata __at 0x0063 struct INTVEC INT12VEC_IE6;
1008
__xdata __at 0x0100 struct INTVEC INTVEC_SUDAV;
1009
__xdata __at 0x0104 struct INTVEC INTVEC_SOF;
1010
__xdata __at 0x0108 struct INTVEC INTVEC_SUTOK;
1011
__xdata __at 0x010C struct INTVEC INTVEC_SUSPEND;
1012
__xdata __at 0x0110 struct INTVEC INTVEC_USBRESET;
1013
__xdata __at 0x0114 struct INTVEC INTVEC_HISPEED;
1014
__xdata __at 0x0118 struct INTVEC INTVEC_EP0ACK;
1015
__xdata __at 0x0120 struct INTVEC INTVEC_EP0IN;
1016
__xdata __at 0x0124 struct INTVEC INTVEC_EP0OUT;
1017
__xdata __at 0x0128 struct INTVEC INTVEC_EP1IN;
1018
__xdata __at 0x012C struct INTVEC INTVEC_EP1OUT;
1019
__xdata __at 0x0130 struct INTVEC INTVEC_EP2;
1020
__xdata __at 0x0134 struct INTVEC INTVEC_EP4;
1021
__xdata __at 0x0138 struct INTVEC INTVEC_EP6;
1022
__xdata __at 0x013C struct INTVEC INTVEC_EP8;
1023
__xdata __at 0x0140 struct INTVEC INTVEC_IBN;
1024
__xdata __at 0x0148 struct INTVEC INTVEC_EP0PING;
1025
__xdata __at 0x014C struct INTVEC INTVEC_EP1PING;
1026
__xdata __at 0x0150 struct INTVEC INTVEC_EP2PING;
1027
__xdata __at 0x0154 struct INTVEC INTVEC_EP4PING;
1028
__xdata __at 0x0158 struct INTVEC INTVEC_EP6PING;
1029
__xdata __at 0x015C struct INTVEC INTVEC_EP8PING;
1030
__xdata __at 0x0160 struct INTVEC INTVEC_ERRLIMIT;
1031
__xdata __at 0x0170 struct INTVEC INTVEC_EP2ISOERR;
1032
__xdata __at 0x0174 struct INTVEC INTVEC_EP4ISOERR;
1033
__xdata __at 0x0178 struct INTVEC INTVEC_EP6ISOERR;
1034
__xdata __at 0x017C struct INTVEC INTVEC_EP8ISOERR;
1035
__xdata __at 0x0180 struct INTVEC INTVEC_EP2PF;
1036
__xdata __at 0x0184 struct INTVEC INTVEC_EP4PF;
1037
__xdata __at 0x0188 struct INTVEC INTVEC_EP6PF;
1038
__xdata __at 0x018C struct INTVEC INTVEC_EP8PF;
1039
__xdata __at 0x0190 struct INTVEC INTVEC_EP2EF;
1040
__xdata __at 0x0194 struct INTVEC INTVEC_EP4EF;
1041
__xdata __at 0x0198 struct INTVEC INTVEC_EP6EF;
1042
__xdata __at 0x019C struct INTVEC INTVEC_EP8EF;
1043
__xdata __at 0x01A0 struct INTVEC INTVEC_EP2FF;
1044
__xdata __at 0x01A8 struct INTVEC INTVEC_EP6FF;
1045
__xdata __at 0x01AC struct INTVEC INTVEC_EP8FF;
1046
__xdata __at 0x01B0 struct INTVEC INTVEC_GPIFDONE;
1047
#line 89 "../../include/ezintavecs.h"
1048
__xdata __at 0x01B4 struct INTVEC INTVEC_GPIFWF;
1049
#line 91 "../../include/ezintavecs.h"
1050
 
1051
void abscode_intvec()// _naked
1052
#line 93 "../../include/ezintavecs.h"
1053
{
1054
#line 96 "../../include/ezintavecs.h"
1055
    __asm
1056
    .area ABSCODE (ABS,CODE)
1057
    .org 0x0000
1058
ENTRY:
1059
        ljmp #0x0200
1060
#line 94 "../../include/ezintavecs.h"
1061
    .org 0x0003
1062
#line 34 "../../include/ezintavecs.h"
1063
        reti
1064
#line 94 "../../include/ezintavecs.h"
1065
    .org 0x000b
1066
#line 35 "../../include/ezintavecs.h"
1067
        reti
1068
#line 94 "../../include/ezintavecs.h"
1069
    .org 0x0013
1070
#line 36 "../../include/ezintavecs.h"
1071
        reti
1072
#line 94 "../../include/ezintavecs.h"
1073
    .org 0x001b
1074
#line 37 "../../include/ezintavecs.h"
1075
        reti
1076
#line 94 "../../include/ezintavecs.h"
1077
    .org 0x0023
1078
#line 38 "../../include/ezintavecs.h"
1079
        reti
1080
#line 94 "../../include/ezintavecs.h"
1081
    .org 0x002b
1082
#line 39 "../../include/ezintavecs.h"
1083
        reti
1084
#line 94 "../../include/ezintavecs.h"
1085
    .org 0x0033
1086
#line 40 "../../include/ezintavecs.h"
1087
        reti
1088
#line 94 "../../include/ezintavecs.h"
1089
    .org 0x003b
1090
#line 41 "../../include/ezintavecs.h"
1091
        reti
1092
#line 94 "../../include/ezintavecs.h"
1093
    .org 0x0043
1094
#line 42 "../../include/ezintavecs.h"
1095
        reti
1096
#line 94 "../../include/ezintavecs.h"
1097
    .org 0x004b
1098
#line 43 "../../include/ezintavecs.h"
1099
        reti
1100
#line 94 "../../include/ezintavecs.h"
1101
    .org 0x0053
1102
#line 44 "../../include/ezintavecs.h"
1103
        reti
1104
#line 94 "../../include/ezintavecs.h"
1105
    .org 0x005b
1106
#line 45 "../../include/ezintavecs.h"
1107
        reti
1108
#line 94 "../../include/ezintavecs.h"
1109
    .org 0x0063
1110
#line 46 "../../include/ezintavecs.h"
1111
        reti
1112
#line 94 "../../include/ezintavecs.h"
1113
    .org 0x0100
1114
#line 47 "../../include/ezintavecs.h"
1115
        reti
1116
#line 94 "../../include/ezintavecs.h"
1117
    .org 0x0104
1118
#line 48 "../../include/ezintavecs.h"
1119
        reti
1120
#line 94 "../../include/ezintavecs.h"
1121
    .org 0x0108
1122
#line 49 "../../include/ezintavecs.h"
1123
        reti
1124
#line 94 "../../include/ezintavecs.h"
1125
    .org 0x010C
1126
#line 50 "../../include/ezintavecs.h"
1127
        reti
1128
#line 94 "../../include/ezintavecs.h"
1129
    .org 0x0110
1130
#line 51 "../../include/ezintavecs.h"
1131
        reti
1132
#line 94 "../../include/ezintavecs.h"
1133
    .org 0x0114
1134
#line 52 "../../include/ezintavecs.h"
1135
        reti
1136
#line 94 "../../include/ezintavecs.h"
1137
    .org 0x0118
1138
#line 53 "../../include/ezintavecs.h"
1139
        reti
1140
#line 94 "../../include/ezintavecs.h"
1141
    .org 0x0120
1142
#line 54 "../../include/ezintavecs.h"
1143
        reti
1144
#line 94 "../../include/ezintavecs.h"
1145
    .org 0x0124
1146
#line 55 "../../include/ezintavecs.h"
1147
        reti
1148
#line 94 "../../include/ezintavecs.h"
1149
    .org 0x0128
1150
#line 56 "../../include/ezintavecs.h"
1151
        reti
1152
#line 94 "../../include/ezintavecs.h"
1153
    .org 0x012C
1154
#line 57 "../../include/ezintavecs.h"
1155
        reti
1156
#line 94 "../../include/ezintavecs.h"
1157
    .org 0x0130
1158
#line 58 "../../include/ezintavecs.h"
1159
        reti
1160
#line 94 "../../include/ezintavecs.h"
1161
    .org 0x0134
1162
#line 59 "../../include/ezintavecs.h"
1163
        reti
1164
#line 94 "../../include/ezintavecs.h"
1165
    .org 0x0138
1166
#line 60 "../../include/ezintavecs.h"
1167
        reti
1168
#line 94 "../../include/ezintavecs.h"
1169
    .org 0x013C
1170
#line 61 "../../include/ezintavecs.h"
1171
        reti
1172
#line 94 "../../include/ezintavecs.h"
1173
    .org 0x0140
1174
#line 62 "../../include/ezintavecs.h"
1175
        reti
1176
#line 94 "../../include/ezintavecs.h"
1177
    .org 0x0148
1178
#line 63 "../../include/ezintavecs.h"
1179
        reti
1180
#line 94 "../../include/ezintavecs.h"
1181
    .org 0x014C
1182
#line 64 "../../include/ezintavecs.h"
1183
        reti
1184
#line 94 "../../include/ezintavecs.h"
1185
    .org 0x0150
1186
#line 65 "../../include/ezintavecs.h"
1187
        reti
1188
#line 94 "../../include/ezintavecs.h"
1189
    .org 0x0154
1190
#line 66 "../../include/ezintavecs.h"
1191
        reti
1192
#line 94 "../../include/ezintavecs.h"
1193
    .org 0x0158
1194
#line 67 "../../include/ezintavecs.h"
1195
        reti
1196
#line 94 "../../include/ezintavecs.h"
1197
    .org 0x015C
1198
#line 68 "../../include/ezintavecs.h"
1199
        reti
1200
#line 94 "../../include/ezintavecs.h"
1201
    .org 0x0160
1202
#line 69 "../../include/ezintavecs.h"
1203
        reti
1204
#line 94 "../../include/ezintavecs.h"
1205
    .org 0x0170
1206
#line 70 "../../include/ezintavecs.h"
1207
        reti
1208
#line 94 "../../include/ezintavecs.h"
1209
    .org 0x0174
1210
#line 71 "../../include/ezintavecs.h"
1211
        reti
1212
#line 94 "../../include/ezintavecs.h"
1213
    .org 0x0178
1214
#line 72 "../../include/ezintavecs.h"
1215
        reti
1216
#line 94 "../../include/ezintavecs.h"
1217
    .org 0x017C
1218
#line 73 "../../include/ezintavecs.h"
1219
        reti
1220
#line 94 "../../include/ezintavecs.h"
1221
    .org 0x0180
1222
#line 74 "../../include/ezintavecs.h"
1223
        reti
1224
#line 94 "../../include/ezintavecs.h"
1225
    .org 0x0184
1226
#line 75 "../../include/ezintavecs.h"
1227
        reti
1228
#line 94 "../../include/ezintavecs.h"
1229
    .org 0x0188
1230
#line 76 "../../include/ezintavecs.h"
1231
        reti
1232
#line 94 "../../include/ezintavecs.h"
1233
    .org 0x018C
1234
#line 77 "../../include/ezintavecs.h"
1235
        reti
1236
#line 94 "../../include/ezintavecs.h"
1237
    .org 0x0190
1238
#line 78 "../../include/ezintavecs.h"
1239
        reti
1240
#line 94 "../../include/ezintavecs.h"
1241
    .org 0x0194
1242
#line 79 "../../include/ezintavecs.h"
1243
        reti
1244
#line 94 "../../include/ezintavecs.h"
1245
    .org 0x0198
1246
#line 80 "../../include/ezintavecs.h"
1247
        reti
1248
#line 94 "../../include/ezintavecs.h"
1249
    .org 0x019C
1250
#line 81 "../../include/ezintavecs.h"
1251
        reti
1252
#line 94 "../../include/ezintavecs.h"
1253
    .org 0x01A0
1254
#line 82 "../../include/ezintavecs.h"
1255
        reti
1256
#line 94 "../../include/ezintavecs.h"
1257
    .org 0x01A8
1258
#line 83 "../../include/ezintavecs.h"
1259
        reti
1260
#line 94 "../../include/ezintavecs.h"
1261
    .org 0x01AC
1262
#line 84 "../../include/ezintavecs.h"
1263
        reti
1264
#line 94 "../../include/ezintavecs.h"
1265
    .org 0x01B0
1266
#line 85 "../../include/ezintavecs.h"
1267
        reti
1268
#line 94 "../../include/ezintavecs.h"
1269
    .org 0x01B4
1270
#line 101 "../../include/ezintavecs.h"
1271
        reti
1272
    .org 0x01b8
1273
INTVEC_DUMMY:
1274
        reti
1275
    .area CSEG    (CODE)
1276
    __endasm;
1277
}
1278
 
1279
#line 111 "../../include/ezintavecs.h"
1280
 
1281
 
1282
/* Init an interrupt vector */
1283
#line 119 "../../include/ezintavecs.h"
1284
 
1285
 
1286
/* Enable USB autovectors */
1287
#line 128 "../../include/ezintavecs.h"
1288
 
1289
 
1290
/* Disable USB autovectors */
1291
#line 132 "../../include/ezintavecs.h"
1292
 
1293
 
1294
/* Enable GPIF autovectors */
1295
#line 141 "../../include/ezintavecs.h"
1296
 
1297
 
1298
/* Disable GPIF autovectors */
1299
#line 145 "../../include/ezintavecs.h"
1300
 
1301
 
1302
#line 50 "../../include/ztex-utils.h"
1303
 
1304
/* *********************************************************************
1305
   ***** global variables **********************************************
1306
   ********************************************************************* */
1307
/*
1308
    The following two variables are used to control HSNAK bit.
1309
 
1310
    ep0_payload_remaining is set to the length field of of the Setup Data
1311
    structure (in SUDAV_ISR). At the begin of each payload data transfer (in
1312
    SUDAV_ISR, EP0IN_ISR and EP0OUT_ISR) the amount of payload of the current
1313
    transfer s calculated (<=64 bytes) and subtracted from
1314
    ep0_payload_remaining. For Vendor Commands HSNAK bit is cleared
1315
    automatically (at the end of EP0OUT_ISR) ifep0_payload_remaining == 0.
1316
    For Vendor Requests HSNAK bit is always cleared at the end of SUDAV_ISR.
1317
*/
1318
 
1319
__xdata WORD ep0_payload_remaining = 0;          // remaining amount of ep0 payload data (excluding the data of the current transfer)
1320
__xdata BYTE ep0_payload_transfer = 0;           // transfer
1321
#line 68 "../../include/ztex-utils.h"
1322
 
1323
/* *********************************************************************
1324
   *********************************************************************
1325
   ***** basic functions ***********************************************
1326
   *********************************************************************
1327
   ********************************************************************* */
1328
 
1329
/* *********************************************************************
1330
   ***** wait **********************************************************
1331
   ********************************************************************* */
1332
void wait(WORD short ms) {        // wait in ms 
1333
#line 79 "../../include/ztex-utils.h"
1334
    WORD i,j;
1335
    for (j=0; j<ms; j++)
1336
        for (i=0; i<1200; i++);
1337
}
1338
 
1339
 
1340
/* *********************************************************************
1341
   ***** uwait *********************************************************
1342
   ********************************************************************* */
1343
void uwait(WORD short us) {       // wait in 10µs steps
1344
#line 89 "../../include/ztex-utils.h"
1345
    WORD i,j;
1346
    for (j=0; j<us; j++)
1347
        for (i=0; i<10; i++);
1348
}
1349
 
1350
 
1351
/* *********************************************************************
1352
   ***** MEM_COPY ******************************************************
1353
   ********************************************************************* */
1354
// copies 1..256 bytes 
1355
void MEM_COPY1_int() // __naked 
1356
#line 100 "../../include/ztex-utils.h"
1357
{
1358
        __asm
1359
020001$:
1360
            mov         _AUTOPTRSETUP,#0x07
1361
            mov         dptr,#_XAUTODAT1
1362
            movx        a,@dptr
1363
            mov         dptr,#_XAUTODAT2
1364
            movx        @dptr,a
1365
            djnz        r2, 020001$
1366
            ret
1367
        __endasm;
1368
}
1369
 
1370
/*
1371
    ! no spaces before/after commas allowed !
1372
 
1373
    This will work too:
1374
        MEM_COPY1(fpga_checksum,EP0BUF+1,6);
1375
*/
1376
 
1377
#line 132 "../../include/ztex-utils.h"
1378
 
1379
 
1380
        // include basic functions and variables
1381
#line 21 "default.c"
1382
 
1383
// select ZTEX USB FPGA Module 2.16 as target  (required for FPGA configuration)
1384
#line 24 "default.c"
1385
 
1386
// enable Flash support
1387
#line 28 "default.c"
1388
 
1389
// this product string is also used for identification by the host software
1390
#line 31 "default.c"
1391
 
1392
// include the main part of the firmware kit, define the descriptors, ...
1393
#line 1 "../../include/ztex.h"
1394
/*!
1395
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
1396
   Copyright (C) 2009-2014 ZTEX GmbH.
1397
   http://www.ztex.de
1398
 
1399
   This program is free software; you can redistribute it and/or modify
1400
   it under the terms of the GNU General Public License version 3 as
1401
   published by the Free Software Foundation.
1402
 
1403
   This program is distributed in the hope that it will be useful, but
1404
   WITHOUT ANY WARRANTY; without even the implied warranty of
1405
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1406
   General Public License for more details.
1407
 
1408
   You should have received a copy of the GNU General Public License
1409
   along with this program; if not, see http://www.gnu.org/licenses/.
1410
!*/
1411
 
1412
/*
1413
   Puts everything together.
1414
*/
1415
 
1416
#line 25 "../../include/ztex.h"
1417
 
1418
#line 27 "../../include/ztex.h"
1419
 
1420
#line 31 "../../include/ztex.h"
1421
 
1422
#line 35 "../../include/ztex.h"
1423
 
1424
/* *********************************************************************
1425
   ***** include the basic functions ***********************************
1426
   ********************************************************************* */
1427
#line 1 "../../include/ztex-utils.h"
1428
/*!
1429
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
1430
   Copyright (C) 2009-2014 ZTEX GmbH.
1431
   http://www.ztex.de
1432
 
1433
   This program is free software; you can redistribute it and/or modify
1434
   it under the terms of the GNU General Public License version 3 as
1435
   published by the Free Software Foundation.
1436
 
1437
   This program is distributed in the hope that it will be useful, but
1438
   WITHOUT ANY WARRANTY; without even the implied warranty of
1439
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1440
   General Public License for more details.
1441
 
1442
   You should have received a copy of the GNU General Public License
1443
   along with this program; if not, see http://www.gnu.org/licenses/.
1444
!*/
1445
 
1446
/*
1447
   Various utility routines
1448
*/
1449
 
1450
#line 39 "../../include/ztex.h"
1451
 
1452
 
1453
/* *********************************************************************
1454
   ***** I2C helper functions, EEPROM and MAC EEPROM support ***********
1455
   ********************************************************************* */
1456
#line 45 "../../include/ztex.h"
1457
 
1458
#line 66 "../../include/ztex.h"
1459
 
1460
#line 1 "../../include/ztex-eeprom.h"
1461
/*!
1462
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
1463
   Copyright (C) 2009-2014 ZTEX GmbH.
1464
   http://www.ztex.de
1465
 
1466
   This program is free software; you can redistribute it and/or modify
1467
   it under the terms of the GNU General Public License version 3 as
1468
   published by the Free Software Foundation.
1469
 
1470
   This program is distributed in the hope that it will be useful, but
1471
   WITHOUT ANY WARRANTY; without even the implied warranty of
1472
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1473
   General Public License for more details.
1474
 
1475
   You should have received a copy of the GNU General Public License
1476
   along with this program; if not, see http://www.gnu.org/licenses/.
1477
!*/
1478
 
1479
/*
1480
    EEPROM support an some I2C helper routines
1481
*/
1482
 
1483
#line 25 "../../include/ztex-eeprom.h"
1484
 
1485
#line 28 "../../include/ztex-eeprom.h"
1486
 
1487
/* *********************************************************************
1488
   ***** global variables **********************************************
1489
   ********************************************************************* */
1490
__xdata WORD eeprom_addr;
1491
__xdata WORD eeprom_write_bytes;
1492
__xdata BYTE eeprom_write_checksum;
1493
 
1494
 
1495
/* *********************************************************************
1496
   ***** i2c_waitWrite *************************************************
1497
   ********************************************************************* */
1498
/* Do the necessary steps after writing I2DAT register. Returns 1 on error. */
1499
BYTE i2c_waitWrite()
1500
{
1501
    unsigned char i2csbuf,toc;
1502
    for ( toc=0; toc<255 && !(I2CS & 1); toc++ );
1503
    i2csbuf = I2CS;
1504
    if ( (i2csbuf & 4) || (!(i2csbuf & 2)) ) {
1505
        I2CS |= 64;
1506
        return 1;
1507
    }
1508
    return 0;
1509
}
1510
 
1511
/* *********************************************************************
1512
   ***** i2c_waitRead **************************************************
1513
   ********************************************************************* */
1514
/* Do the necessary steps after reading I2DAT register. Returns 1 on error. */
1515
BYTE i2c_waitRead(void)
1516
{
1517
    unsigned char i2csbuf, toc;
1518
    for ( toc=0; toc<255 && !(I2CS & 1); toc++ );
1519
    i2csbuf = I2CS;
1520
    if (i2csbuf & 4) {
1521
        I2CS |= 64;
1522
        return 1;
1523
    }
1524
    return 0;
1525
}
1526
 
1527
/* *********************************************************************
1528
   ***** i2c_waitStart *************************************************
1529
   ********************************************************************* */
1530
/* Do the necessary steps after start bit. Returns 1 on error. */
1531
BYTE i2c_waitStart()
1532
{
1533
    BYTE toc;
1534
    for ( toc=0; toc<255; toc++ ) {
1535
        if ( ! (I2CS & 4) )
1536
            return 0;
1537
    }
1538
    return 1;
1539
}
1540
 
1541
/* *********************************************************************
1542
   ***** i2c_waitStop **************************************************
1543
   ********************************************************************* */
1544
/* Do the necessary steps after stop bit. Returns 1 on error. */
1545
BYTE i2c_waitStop()
1546
{
1547
    BYTE toc;
1548
    for ( toc=0; toc<255; toc++ ) {
1549
        if ( ! (I2CS & 64) )
1550
            return 0;
1551
    }
1552
    return 1;
1553
}
1554
 
1555
/* *********************************************************************
1556
   ***** eeprom_select *************************************************
1557
   ********************************************************************* */
1558
/* Select the EEPROM device, i.e. send the control Byte.
1559
   <to> specifies the time to wait in 0.1ms steps if the EEPROM is busy (during a write cycle).
1560
   if <stop>=0 no sop bit is sent. Returns 1 on error or if EEPROM is busy. */
1561
BYTE eeprom_select (BYTE addr, BYTE to, BYTE stop ) {
1562
    BYTE toc = 0;
1563
eeprom_select_start:
1564
    I2CS |= 128;                // start bit
1565
#line 107 "../../include/ztex-eeprom.h"
1566
    i2c_waitStart();
1567
    I2DAT = addr;               // select device for writing
1568
#line 109 "../../include/ztex-eeprom.h"
1569
    if ( ! i2c_waitWrite() ) {
1570
        if ( stop ) {
1571
            I2CS |= 64;
1572
            i2c_waitStop();
1573
        }
1574
        return 0;
1575
    }
1576
    else if (toc<to) {
1577
        uwait(10);
1578
        goto eeprom_select_start;
1579
    }
1580
    if ( stop ) {
1581
        I2CS |= 64;
1582
    }
1583
    return 1;
1584
}
1585
 
1586
/* *********************************************************************
1587
   ***** eeprom_read ***************************************************
1588
   ********************************************************************* */
1589
/* Reads <length> bytes from EEPROM address <addr> and write them to buf.
1590
   Returns the number of bytes read. */
1591
BYTE eeprom_read ( __xdata BYTE *buf, WORD addr, BYTE length ) {
1592
    BYTE bytes = 0,i;
1593
 
1594
    if ( length == 0 )
1595
        return 0;
1596
 
1597
    if ( eeprom_select(0xA2, 100,0) )
1598
        goto eeprom_read_end;
1599
 
1600
    I2DAT = ((BYTE)((((unsigned short)(addr)) >> 8) & 0xff)) ;          // write address
1601
#line 141 "../../include/ztex-eeprom.h"
1602
    if ( i2c_waitWrite() ) goto eeprom_read_end;
1603
    I2DAT = ((BYTE)(addr));             // write address
1604
#line 143 "../../include/ztex-eeprom.h"
1605
    if ( i2c_waitWrite() ) goto eeprom_read_end;
1606
    I2CS |= 64;
1607
    i2c_waitStop();
1608
 
1609
    I2CS |= 128;                // start bit
1610
#line 148 "../../include/ztex-eeprom.h"
1611
    i2c_waitStart();
1612
    I2DAT = 0xA2 | 1;   // select device for reading
1613
#line 150 "../../include/ztex-eeprom.h"
1614
    if ( i2c_waitWrite() ) goto eeprom_read_end;
1615
 
1616
    *buf = I2DAT;               // dummy read
1617
#line 153 "../../include/ztex-eeprom.h"
1618
    if ( i2c_waitRead()) goto eeprom_read_end;
1619
    for (; bytes<length; bytes++ ) {
1620
        *buf = I2DAT;           // read data
1621
#line 156 "../../include/ztex-eeprom.h"
1622
        buf++;
1623
        if ( i2c_waitRead()) goto eeprom_read_end;
1624
    }
1625
 
1626
    I2CS |= 32;         // no ACK
1627
    i = I2DAT;                  // dummy read
1628
#line 162 "../../include/ztex-eeprom.h"
1629
    if ( i2c_waitRead()) goto eeprom_read_end;
1630
 
1631
    I2CS |= 64;         // stop bit
1632
    i = I2DAT;                  // dummy read
1633
#line 166 "../../include/ztex-eeprom.h"
1634
    i2c_waitStop();
1635
 
1636
eeprom_read_end:
1637
    return bytes;
1638
}
1639
 
1640
/* *********************************************************************
1641
   ***** eeprom_write **************************************************
1642
   ********************************************************************* */
1643
/* Writes <length> bytes from buf to EEPROM address <addr>.
1644
   <length> must be smaller or equal than 8. Returns the number of bytes
1645
   read. */
1646
BYTE eeprom_write ( __xdata BYTE *buf, WORD addr, BYTE length ) {
1647
    BYTE bytes = 0;
1648
 
1649
    if ( length == 0 )
1650
        return 0;
1651
 
1652
    if ( eeprom_select(0xA2, 100,0) )
1653
        goto eeprom_write_end;
1654
 
1655
    I2DAT = ((BYTE)((((unsigned short)(addr)) >> 8) & 0xff)) ;                  // write address
1656
#line 188 "../../include/ztex-eeprom.h"
1657
    if ( i2c_waitWrite() ) goto eeprom_write_end;
1658
    I2DAT = ((BYTE)(addr));             // write address
1659
#line 190 "../../include/ztex-eeprom.h"
1660
    if ( i2c_waitWrite() ) goto eeprom_write_end;
1661
 
1662
    for (; bytes<length; bytes++ ) {
1663
        I2DAT = *buf;           // write data 
1664
#line 194 "../../include/ztex-eeprom.h"
1665
        eeprom_write_checksum += *buf;
1666
        buf++;
1667
        eeprom_write_bytes+=1;
1668
        if ( i2c_waitWrite() ) goto eeprom_write_end;
1669
    }
1670
    I2CS |= 64;         // stop bit
1671
#line 200 "../../include/ztex-eeprom.h"
1672
    i2c_waitStop();
1673
 
1674
eeprom_write_end:
1675
    return bytes;
1676
}
1677
 
1678
/* *********************************************************************
1679
   ***** EP0 vendor request 0x38 ***************************************
1680
   ********************************************************************* */
1681
BYTE eeprom_read_ep0 () {
1682
    BYTE i, b;
1683
    b = ep0_payload_transfer;
1684
    i = eeprom_read(EP0BUF, eeprom_addr, b);
1685
    eeprom_addr += b;
1686
    return i;
1687
}
1688
 
1689
#line 225 "../../include/ztex-eeprom.h"
1690
 
1691
 
1692
/* *********************************************************************
1693
   ***** EP0 vendor command 0x39 ***************************************
1694
   ********************************************************************* */
1695
void eeprom_write_ep0 ( BYTE length ) {
1696
    eeprom_write(EP0BUF, eeprom_addr, length);
1697
    eeprom_addr += length;
1698
}
1699
 
1700
#line 242 "../../include/ztex-eeprom.h"
1701
 
1702
/* *********************************************************************
1703
   ***** EP0 vendor request 0x3A ***************************************
1704
   ********************************************************************* */
1705
#line 254 "../../include/ztex-eeprom.h"
1706
 
1707
 
1708
#line 259 "../../include/ztex-eeprom.h"
1709
 
1710
__xdata BYTE mac_eeprom_addr;
1711
 
1712
// details about the configuration data structure can be found at 
1713
// http://www.ztex.de/firmware-kit/docs/java/ztex/ConfigData.html
1714
#line 264 "../../include/ztex-eeprom.h"
1715
 
1716
__xdata BYTE config_data_valid;
1717
 
1718
/* *********************************************************************
1719
   ***** mac_eeprom_read ***********************************************
1720
   ********************************************************************* */
1721
/* Reads <length> bytes from EEPROM address <addr> and write them to buf.
1722
   Returns the number of bytes read. */
1723
BYTE mac_eeprom_read ( __xdata BYTE *buf, BYTE addr, BYTE length ) {
1724
    BYTE bytes = 0,i;
1725
 
1726
    if ( length == 0 )
1727
        return 0;
1728
 
1729
    if ( eeprom_select(0xA6, 100,0) )
1730
        goto mac_eeprom_read_end;
1731
 
1732
    I2DAT = addr;               // write address
1733
#line 282 "../../include/ztex-eeprom.h"
1734
    if ( i2c_waitWrite() ) goto mac_eeprom_read_end;
1735
    I2CS |= 64;
1736
    i2c_waitStop();
1737
 
1738
    I2CS |= 128;                // start bit
1739
#line 287 "../../include/ztex-eeprom.h"
1740
    i2c_waitStart();
1741
    I2DAT = 0xA6 | 1;  // select device for reading
1742
#line 289 "../../include/ztex-eeprom.h"
1743
    if ( i2c_waitWrite() ) goto mac_eeprom_read_end;
1744
 
1745
    *buf = I2DAT;               // dummy read
1746
#line 292 "../../include/ztex-eeprom.h"
1747
    if ( i2c_waitRead()) goto mac_eeprom_read_end;
1748
    for (; bytes<length; bytes++ ) {
1749
        *buf = I2DAT;           // read data
1750
#line 295 "../../include/ztex-eeprom.h"
1751
        buf++;
1752
        if ( i2c_waitRead()) goto mac_eeprom_read_end;
1753
    }
1754
 
1755
    I2CS |= 32;         // no ACK
1756
    i = I2DAT;                  // dummy read
1757
#line 301 "../../include/ztex-eeprom.h"
1758
    if ( i2c_waitRead()) goto mac_eeprom_read_end;
1759
 
1760
    I2CS |= 64;         // stop bit
1761
    i = I2DAT;                  // dummy read
1762
#line 305 "../../include/ztex-eeprom.h"
1763
    i2c_waitStop();
1764
 
1765
mac_eeprom_read_end:
1766
    return bytes;
1767
}
1768
 
1769
/* *********************************************************************
1770
   ***** mac_eeprom_write **********************************************
1771
   ********************************************************************* */
1772
/* Writes <length> bytes from buf to and write them EEPROM address <addr>.
1773
   <length> must be smaller or equal than 8. Returns the number of bytes
1774
   written. */
1775
BYTE mac_eeprom_write ( __xdata BYTE *buf, BYTE addr, BYTE length ) {
1776
    BYTE bytes = 0;
1777
 
1778
    if ( length == 0 )
1779
        return 0;
1780
 
1781
    if ( eeprom_select(0xA6, 100,0) )
1782
        goto mac_eeprom_write_end;
1783
 
1784
    I2DAT = addr;               // write address
1785
#line 327 "../../include/ztex-eeprom.h"
1786
    if ( i2c_waitWrite() ) goto mac_eeprom_write_end;
1787
 
1788
    while ( bytes<length ) {
1789
        I2DAT = *buf;           // write data 
1790
#line 331 "../../include/ztex-eeprom.h"
1791
        buf++;
1792
        if ( i2c_waitWrite() ) goto mac_eeprom_write_end;
1793
 
1794
        addr++;
1795
        bytes++;
1796
        if ( ( (addr & 8) == 0 ) && ( bytes<length ) ) {
1797
            I2CS |= 64;         // stop bit
1798
#line 338 "../../include/ztex-eeprom.h"
1799
            i2c_waitStop();
1800
 
1801
            if ( eeprom_select(0xA6, 100,0) )
1802
                goto mac_eeprom_write_end;
1803
 
1804
            I2DAT = addr;               // write address
1805
#line 344 "../../include/ztex-eeprom.h"
1806
            if ( i2c_waitWrite() ) goto mac_eeprom_write_end;
1807
        }
1808
    }
1809
    I2CS |= 64;         // stop bit
1810
#line 348 "../../include/ztex-eeprom.h"
1811
    i2c_waitStop();
1812
 
1813
mac_eeprom_write_end:
1814
    mac_eeprom_addr = addr;
1815
    return bytes;
1816
}
1817
 
1818
/* *********************************************************************
1819
   ***** EP0 vendor request 0x3B ***************************************
1820
   ********************************************************************* */
1821
BYTE mac_eeprom_read_ep0 () {
1822
    BYTE i, b;
1823
    b = ep0_payload_transfer;
1824
    i = mac_eeprom_read(EP0BUF, mac_eeprom_addr, b);
1825
    mac_eeprom_addr += b;
1826
    return i;
1827
}
1828
 
1829
#line 374 "../../include/ztex-eeprom.h"
1830
 
1831
 
1832
/* *********************************************************************
1833
   ***** EP0 vendor command 0x3C ***************************************
1834
   ********************************************************************* */
1835
#line 384 "../../include/ztex-eeprom.h"
1836
 
1837
/* *********************************************************************
1838
   ***** EP0 vendor request 0x3D ***************************************
1839
   ********************************************************************* */
1840
#line 393 "../../include/ztex-eeprom.h"
1841
 
1842
 
1843
#line 396 "../../include/ztex-eeprom.h"
1844
 
1845
#line 67 "../../include/ztex.h"
1846
 
1847
 
1848
#line 70 "../../include/ztex.h"
1849
 
1850
 
1851
/* *********************************************************************
1852
   ***** Flash memory support ******************************************
1853
   ********************************************************************* */
1854
#line 76 "../../include/ztex.h"
1855
 
1856
#line 1 "../../include/ztex-flash2.h"
1857
/*!
1858
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
1859
   Copyright (C) 2009-2014 ZTEX GmbH.
1860
   http://www.ztex.de
1861
 
1862
   This program is free software; you can redistribute it and/or modify
1863
   it under the terms of the GNU General Public License version 3 as
1864
   published by the Free Software Foundation.
1865
 
1866
   This program is distributed in the hope that it will be useful, but
1867
   WITHOUT ANY WARRANTY; without even the implied warranty of
1868
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1869
   General Public License for more details.
1870
 
1871
   You should have received a copy of the GNU General Public License
1872
   along with this program; if not, see http://www.gnu.org/licenses/.
1873
!*/
1874
 
1875
/*
1876
    Support for standard SPI flash.
1877
*/
1878
 
1879
#line 29 "../../include/ztex-flash2.h"
1880
 
1881
#line 32 "../../include/ztex-flash2.h"
1882
 
1883
#line 34 "../../include/ztex-flash2.h"
1884
 
1885
#line 38 "../../include/ztex-flash2.h"
1886
 
1887
#line 42 "../../include/ztex-flash2.h"
1888
 
1889
#line 46 "../../include/ztex-flash2.h"
1890
 
1891
#line 50 "../../include/ztex-flash2.h"
1892
 
1893
#line 54 "../../include/ztex-flash2.h"
1894
 
1895
#line 58 "../../include/ztex-flash2.h"
1896
 
1897
#line 61 "../../include/ztex-flash2.h"
1898
 
1899
#line 66 "../../include/ztex-flash2.h"
1900
 
1901
// may be redefined if the first sectors are reserved (e.g. for a FPGA bitstream)
1902
#line 69 "../../include/ztex-flash2.h"
1903
 
1904
__xdata BYTE flash_enabled;     // 0    1: enabled, 0:disabled
1905
__xdata WORD flash_sector_size; // 1    sector size <sector size> = MSB==0 : flash_sector_size and 0x7fff ? 1<<(flash_sector_size and 0x7fff)
1906
__xdata DWORD flash_sectors;    // 3    number of sectors
1907
__xdata BYTE flash_ec;          // 7    error code
1908
#line 74 "../../include/ztex-flash2.h"
1909
 
1910
__xdata BYTE spi_vendor;        // 0
1911
__xdata BYTE spi_device;        // 1
1912
__xdata BYTE spi_memtype;       // 2
1913
__xdata BYTE spi_erase_cmd;     // 3
1914
__xdata BYTE spi_last_cmd;      // 4
1915
__xdata BYTE spi_buffer[4];     // 5
1916
#line 81 "../../include/ztex-flash2.h"
1917
 
1918
__xdata WORD spi_write_addr_hi;
1919
__xdata BYTE spi_write_addr_lo;
1920
__xdata BYTE spi_need_pp;
1921
__xdata WORD spi_write_sector;
1922
__xdata BYTE ep0_read_mode;
1923
__xdata BYTE ep0_write_mode;
1924
 
1925
#line 93 "../../include/ztex-flash2.h"
1926
 
1927
/* *********************************************************************
1928
   ***** spi_clocks ****************************************************
1929
   ********************************************************************* */
1930
// perform c (256 if c=0) clocks
1931
#line 98 "../../include/ztex-flash2.h"
1932
void spi_clocks (BYTE c) {
1933
        c;                                      // this avoids stupid warnings
1934
#line 100 "../../include/ztex-flash2.h"
1935
__asm
1936
        mov     r2,dpl
1937
010014$:
1938
        setb    _IOA0   // 1
1939
        nop                     // 1
1940
        nop                     // 1
1941
        nop                     // 1
1942
        clr     _IOA0   // 1
1943
        djnz    r2,010014$      // 3
1944
#line 109 "../../include/ztex-flash2.h"
1945
__endasm;
1946
}
1947
 
1948
 
1949
/* *********************************************************************
1950
   ***** flash_read_byte ***********************************************
1951
   ********************************************************************* */
1952
// read a single byte from the flash
1953
BYTE flash_read_byte() { // uses r2,r3,r4
1954
#line 118 "../../include/ztex-flash2.h"
1955
__asm
1956
        // 8*7 + 6 = 62 clocks 
1957
        mov     c,_IOC0 // 7
1958
#line 121 "../../include/ztex-flash2.h"
1959
        setb    _IOA0
1960
        rlc     a
1961
        clr     _IOA0
1962
 
1963
        mov     c,_IOC0 // 6
1964
#line 126 "../../include/ztex-flash2.h"
1965
        setb    _IOA0
1966
        rlc     a
1967
        clr     _IOA0
1968
 
1969
        mov     c,_IOC0 // 5
1970
#line 131 "../../include/ztex-flash2.h"
1971
        setb    _IOA0
1972
        rlc     a
1973
        clr     _IOA0
1974
 
1975
        mov     c,_IOC0 // 4
1976
#line 136 "../../include/ztex-flash2.h"
1977
        setb    _IOA0
1978
        rlc     a
1979
        clr     _IOA0
1980
 
1981
        mov     c,_IOC0 // 3
1982
#line 141 "../../include/ztex-flash2.h"
1983
        setb    _IOA0
1984
        rlc     a
1985
        clr     _IOA0
1986
 
1987
        mov     c,_IOC0 // 2
1988
#line 146 "../../include/ztex-flash2.h"
1989
        setb    _IOA0
1990
        rlc     a
1991
        clr     _IOA0
1992
 
1993
        mov     c,_IOC0 // 1
1994
#line 151 "../../include/ztex-flash2.h"
1995
        setb    _IOA0
1996
        rlc     a
1997
        clr     _IOA0
1998
 
1999
        mov     c,_IOC0 // 0
2000
#line 156 "../../include/ztex-flash2.h"
2001
        setb    _IOA0
2002
        rlc     a
2003
        clr     _IOA0
2004
        mov     dpl,a
2005
        ret
2006
__endasm;
2007
        return 0;                // never ever called (just to avoid warnings)
2008
#line 163 "../../include/ztex-flash2.h"
2009
}
2010
 
2011
/* *********************************************************************
2012
   ***** flash_read ****************************************************
2013
   ********************************************************************* */
2014
// read len (256 if len=0) bytes from the flash to the buffer
2015
#line 169 "../../include/ztex-flash2.h"
2016
void flash_read(__xdata BYTE *buf, BYTE len) {
2017
        *buf;                                   // this avoids stupid warnings
2018
        len;                                    // this too
2019
__asm                                           // *buf is in dptr, len is in _flash_read_PARM_2
2020
#line 173 "../../include/ztex-flash2.h"
2021
        mov     r2,_flash_read_PARM_2
2022
010012$:
2023
        // 2 + len*(8*7 + 9) + 4 = 6 + len*65 clocks
2024
        mov     c,_IOC0 // 7
2025
#line 177 "../../include/ztex-flash2.h"
2026
        setb    _IOA0
2027
        rlc     a
2028
        clr     _IOA0
2029
 
2030
        mov     c,_IOC0 // 6
2031
#line 182 "../../include/ztex-flash2.h"
2032
        setb    _IOA0
2033
        rlc     a
2034
        clr     _IOA0
2035
 
2036
        mov     c,_IOC0 // 5
2037
#line 187 "../../include/ztex-flash2.h"
2038
        setb    _IOA0
2039
        rlc     a
2040
        clr     _IOA0
2041
 
2042
        mov     c,_IOC0 // 4
2043
#line 192 "../../include/ztex-flash2.h"
2044
        setb    _IOA0
2045
        rlc     a
2046
        clr     _IOA0
2047
 
2048
        mov     c,_IOC0 // 3
2049
#line 197 "../../include/ztex-flash2.h"
2050
        setb    _IOA0
2051
        rlc     a
2052
        clr     _IOA0
2053
 
2054
        mov     c,_IOC0 // 2
2055
#line 202 "../../include/ztex-flash2.h"
2056
        setb    _IOA0
2057
        rlc     a
2058
        clr     _IOA0
2059
 
2060
        mov     c,_IOC0 // 1
2061
#line 207 "../../include/ztex-flash2.h"
2062
        setb    _IOA0
2063
        rlc     a
2064
        clr     _IOA0
2065
 
2066
        mov     c,_IOC0 // 0
2067
#line 212 "../../include/ztex-flash2.h"
2068
        setb    _IOA0
2069
        rlc     a
2070
        clr     _IOA0
2071
 
2072
        movx    @dptr,a
2073
        inc     dptr
2074
        djnz    r2,010012$
2075
__endasm;
2076
}
2077
 
2078
/* *********************************************************************
2079
   ***** spi_write_byte ************************************************
2080
   ********************************************************************* */
2081
// send one bytes from buffer buf to the card
2082
void spi_write_byte (BYTE b) {  // b is in dpl
2083
        b;                              // this avoids stupid warnings
2084
#line 228 "../../include/ztex-flash2.h"
2085
__asm
2086
        // 3 + 8*7 + 4 = 63 clocks 
2087
#line 230 "../../include/ztex-flash2.h"
2088
        mov     a,dpl
2089
        rlc     a               // 7
2090
#line 232 "../../include/ztex-flash2.h"
2091
 
2092
        mov     _IOA1,c
2093
        setb    _IOA0
2094
        rlc     a               // 6
2095
#line 236 "../../include/ztex-flash2.h"
2096
        clr     _IOA0
2097
 
2098
        mov     _IOA1,c
2099
        setb    _IOA0
2100
        rlc     a               // 5
2101
#line 241 "../../include/ztex-flash2.h"
2102
        clr     _IOA0
2103
 
2104
        mov     _IOA1,c
2105
        setb    _IOA0
2106
        rlc     a               // 4
2107
#line 246 "../../include/ztex-flash2.h"
2108
        clr     _IOA0
2109
 
2110
        mov     _IOA1,c
2111
        setb    _IOA0
2112
        rlc     a               // 3
2113
#line 251 "../../include/ztex-flash2.h"
2114
        clr     _IOA0
2115
 
2116
        mov     _IOA1,c
2117
        setb    _IOA0
2118
        rlc     a               // 2
2119
#line 256 "../../include/ztex-flash2.h"
2120
        clr     _IOA0
2121
 
2122
        mov     _IOA1,c
2123
        setb    _IOA0
2124
        rlc     a               // 1
2125
#line 261 "../../include/ztex-flash2.h"
2126
        clr     _IOA0
2127
 
2128
        mov     _IOA1,c
2129
        setb    _IOA0
2130
        rlc     a               // 0
2131
#line 266 "../../include/ztex-flash2.h"
2132
        clr     _IOA0
2133
 
2134
        mov     _IOA1,c
2135
        setb    _IOA0
2136
        nop
2137
        clr     _IOA0
2138
__endasm;
2139
}
2140
 
2141
/* *********************************************************************
2142
   ***** spi_write *****************************************************
2143
   ********************************************************************* */
2144
// write len (256 if len=0) bytes from the buffer to the flash
2145
#line 279 "../../include/ztex-flash2.h"
2146
void spi_write(__xdata BYTE *buf, BYTE len) {
2147
        *buf;                                   // this avoids stupid warnings
2148
        len;                                    // this too
2149
__asm                                           // *buf is in dptr, len is in _flash_read_PARM_2
2150
#line 283 "../../include/ztex-flash2.h"
2151
        mov     r2,_flash_read_PARM_2
2152
010013$:
2153
        // 2 + len*(3 + 8*7 - 1 + 7 ) + 4 = 6 + len*65 clocks
2154
#line 286 "../../include/ztex-flash2.h"
2155
        movx    a,@dptr
2156
        rlc     a               // 7
2157
#line 288 "../../include/ztex-flash2.h"
2158
 
2159
        mov     _IOA1,c
2160
        setb    _IOA0
2161
        rlc     a               // 6
2162
#line 292 "../../include/ztex-flash2.h"
2163
        clr     _IOA0
2164
 
2165
        mov     _IOA1,c
2166
        setb    _IOA0
2167
        rlc     a               // 5
2168
#line 297 "../../include/ztex-flash2.h"
2169
        clr     _IOA0
2170
 
2171
        mov     _IOA1,c
2172
        setb    _IOA0
2173
        rlc     a               // 4
2174
#line 302 "../../include/ztex-flash2.h"
2175
        clr     _IOA0
2176
 
2177
        mov     _IOA1,c
2178
        setb    _IOA0
2179
        rlc     a               // 3
2180
#line 307 "../../include/ztex-flash2.h"
2181
        clr     _IOA0
2182
 
2183
        mov     _IOA1,c
2184
        setb    _IOA0
2185
        rlc     a               // 2
2186
#line 312 "../../include/ztex-flash2.h"
2187
        clr     _IOA0
2188
 
2189
        mov     _IOA1,c
2190
        setb    _IOA0
2191
        rlc     a               // 1
2192
#line 317 "../../include/ztex-flash2.h"
2193
        clr     _IOA0
2194
 
2195
        mov     _IOA1,c
2196
        setb    _IOA0
2197
        rlc     a               // 0
2198
#line 322 "../../include/ztex-flash2.h"
2199
        clr     _IOA0
2200
 
2201
        mov     _IOA1,c
2202
        setb    _IOA0
2203
        inc     dptr
2204
        clr     _IOA0
2205
 
2206
        djnz    r2,010013$
2207
__endasm;
2208
}
2209
 
2210
/* *********************************************************************
2211
   ***** spi_select ****************************************************
2212
   ********************************************************************* */
2213
/*
2214
   select the flash (CS)
2215
*/
2216
void spi_select() {
2217
    IOA3 = 1;                                   // CS = 1;
2218
    spi_clocks(8);                              // 8 dummy clocks to finish a previous command
2219
#line 342 "../../include/ztex-flash2.h"
2220
    IOA3 = 0;
2221
}
2222
 
2223
/* *********************************************************************
2224
   ***** spi_deselect **************************************************
2225
   ********************************************************************* */
2226
// de-select the flash (CS)
2227
#line 349 "../../include/ztex-flash2.h"
2228
void spi_deselect() {
2229
    IOA3 = 1;                                   // CS = 1;
2230
    spi_clocks(8);                              // 8 dummy clocks to finish a previous command
2231
#line 352 "../../include/ztex-flash2.h"
2232
}
2233
 
2234
/* *********************************************************************
2235
   ***** spi_start_cmd *************************************************
2236
   ********************************************************************* */
2237
// send a command   
2238
#line 363 "../../include/ztex-flash2.h"
2239
 
2240
/* *********************************************************************
2241
   ***** spi_wait ******************************************************
2242
   ********************************************************************* */
2243
/*
2244
   wait if prvious read/write command is still prcessed
2245
   result is flash_ec (FLASH_EC_TIMEOUT or 0)
2246
*/
2247
BYTE spi_wait() {
2248
    WORD i;
2249
    // wait up to 11s
2250
    {                   // send a command, argument=0
2251
#line 359 "../../include/ztex-flash2.h"
2252
    spi_last_cmd = 0x05;
2253
    spi_select();                               // select
2254
    spi_write_byte(0x05);                               // CMD 90h
2255
#line 374 "../../include/ztex-flash2.h"
2256
}
2257
    for (i=0; (flash_read_byte() & 1) && i<65535; i++ ) {
2258
        spi_clocks(0);                           // 256 dummy clocks
2259
//      uwait(20);
2260
#line 378 "../../include/ztex-flash2.h"
2261
    }
2262
    flash_ec = flash_read_byte() & 1 ? 2 : 0;
2263
    spi_deselect();
2264
    return flash_ec;
2265
}
2266
 
2267
/* *********************************************************************
2268
   ***** flash_read_init ***********************************************
2269
   ********************************************************************* */
2270
/*
2271
   Start the initialization sequence for reading sector s.
2272
   returns an error code (FLASH_EC_*). 0 means no error.
2273
*/
2274
BYTE flash_read_init(WORD s) {
2275
    if ( (IOA3) == 0 ) {
2276
        flash_ec = 4;
2277
        return 4;               // we interrupted a pending Flash operation
2278
#line 395 "../../include/ztex-flash2.h"
2279
    }
2280
    OEC &= ~1;
2281
    OEA |= 8 | 2 | 1;
2282
    if ( spi_wait() ) {
2283
        return flash_ec;
2284
    }
2285
 
2286
    s = s << ((BYTE)flash_sector_size - 8);
2287
    {                   // send a command, argument=0
2288
#line 359 "../../include/ztex-flash2.h"
2289
    spi_last_cmd = 0x0b;
2290
    spi_select();                               // select
2291
    spi_write_byte(0x0b);                               // CMD 90h
2292
}                       // read command
2293
    spi_write_byte(s >> 8);                     // 24 byte address
2294
#line 405 "../../include/ztex-flash2.h"
2295
    spi_write_byte(s & 255);
2296
    spi_write_byte(0);
2297
    spi_clocks(8);                              // 8 dummy clocks
2298
#line 408 "../../include/ztex-flash2.h"
2299
    return 0;
2300
}
2301
 
2302
/* *********************************************************************
2303
   ***** flash_read_next ***********************************************
2304
   ********************************************************************* */
2305
/*
2306
   dummy function for compatibilty
2307
*/
2308
BYTE flash_read_next() {
2309
    return 0;
2310
}
2311
 
2312
 
2313
/* *********************************************************************
2314
   ***** flash_read_finish *********************************************
2315
   ********************************************************************* */
2316
/*
2317
    Runs the finalization sequence for the read operation.
2318
*/
2319
void flash_read_finish(WORD n) {
2320
   n;                                   // avoids warnings
2321
#line 430 "../../include/ztex-flash2.h"
2322
   spi_deselect();
2323
}
2324
 
2325
 
2326
/* *********************************************************************
2327
   ***** spi_pp ********************************************************
2328
   ********************************************************************* */
2329
BYTE spi_pp () {
2330
    spi_deselect();                             // finish previous write cmd
2331
#line 439 "../../include/ztex-flash2.h"
2332
 
2333
    spi_need_pp = 0;
2334
 
2335
    if ( spi_wait() ) {
2336
        return flash_ec;
2337
    }
2338
    {                   // send a command, argument=0
2339
#line 359 "../../include/ztex-flash2.h"
2340
    spi_last_cmd = 0x06;
2341
    spi_select();                               // select
2342
    spi_write_byte(0x06);                               // CMD 90h
2343
}                       // write enable command
2344
#line 446 "../../include/ztex-flash2.h"
2345
    spi_deselect();
2346
 
2347
    {                   // send a command, argument=0
2348
#line 359 "../../include/ztex-flash2.h"
2349
    spi_last_cmd = 0x02;
2350
    spi_select();                               // select
2351
    spi_write_byte(0x02);                               // CMD 90h
2352
}                       // page write
2353
    spi_write_byte(spi_write_addr_hi >> 8);     // 24 byte address
2354
#line 450 "../../include/ztex-flash2.h"
2355
    spi_write_byte(spi_write_addr_hi & 255);
2356
    spi_write_byte(0);
2357
    return 0;
2358
}
2359
 
2360
 
2361
/* *********************************************************************
2362
   ***** flash_write_byte **********************************************
2363
   ********************************************************************* */
2364
BYTE flash_write_byte (BYTE b) {
2365
    if ( spi_need_pp && spi_pp() ) return flash_ec;
2366
    spi_write_byte(b);
2367
    spi_write_addr_lo++;
2368
    if ( spi_write_addr_lo == 0 ) {
2369
        spi_write_addr_hi++;
2370
        spi_deselect();                         // finish write cmd
2371
#line 466 "../../include/ztex-flash2.h"
2372
        spi_need_pp = 1;
2373
    }
2374
    return 0;
2375
}
2376
 
2377
 
2378
/* *********************************************************************
2379
   ***** flash_write ***************************************************
2380
   ********************************************************************* */
2381
// write len (256 if len=0) bytes from the buffer to the flash
2382
#line 476 "../../include/ztex-flash2.h"
2383
BYTE flash_write(__xdata BYTE *buf, BYTE len) {
2384
    BYTE b;
2385
    if ( spi_need_pp && spi_pp() ) return flash_ec;
2386
 
2387
    if ( spi_write_addr_lo == 0 ) {
2388
        spi_write(buf,len);
2389
    }
2390
    else {
2391
        b = (~spi_write_addr_lo) + 1;
2392
        if ( len==0 || len>b ) {
2393
            spi_write(buf,b);
2394
            len-=b;
2395
            spi_write_addr_hi++;
2396
            spi_write_addr_lo=0;
2397
            buf+=b;
2398
            if ( spi_pp() ) return flash_ec;
2399
        }
2400
        spi_write(buf,len);
2401
    }
2402
 
2403
    spi_write_addr_lo+=len;
2404
 
2405
    if ( spi_write_addr_lo == 0 ) {
2406
        spi_write_addr_hi++;
2407
        spi_deselect();                         // finish write cmd
2408
#line 501 "../../include/ztex-flash2.h"
2409
        spi_need_pp = 1;
2410
    }
2411
 
2412
    return 0;
2413
}
2414
 
2415
 
2416
/* *********************************************************************
2417
   ***** flash_write_init **********************************************
2418
   ********************************************************************* */
2419
/*
2420
   Start the initialization sequence for writing sector s
2421
   The whole sector will be modified
2422
   returns an error code (FLASH_EC_*). 0 means no error.
2423
*/
2424
BYTE flash_write_init(WORD s) {
2425
    if ( !IOA3 ) {
2426
        flash_ec = 4;
2427
        return 4;               // we interrupted a pending Flash operation
2428
#line 520 "../../include/ztex-flash2.h"
2429
    }
2430
    OEC &= ~1;
2431
    OEA |= 8 | 2 | 1;
2432
    if ( spi_wait() ) {
2433
        return flash_ec;
2434
    }
2435
    spi_write_sector = s;
2436
    s = s << ((BYTE)flash_sector_size - 8);
2437
    spi_write_addr_hi = s;
2438
    spi_write_addr_lo = 0;
2439
 
2440
    {                   // send a command, argument=0
2441
#line 359 "../../include/ztex-flash2.h"
2442
    spi_last_cmd = 0x06;
2443
    spi_select();                               // select
2444
    spi_write_byte(0x06);                               // CMD 90h
2445
}                       // write enable command
2446
#line 532 "../../include/ztex-flash2.h"
2447
    spi_deselect();
2448
 
2449
    {                   // send a command, argument=0
2450
#line 359 "../../include/ztex-flash2.h"
2451
    spi_last_cmd = spi_erase_cmd;
2452
    spi_select();                               // select
2453
    spi_write_byte(spi_erase_cmd);                              // CMD 90h
2454
}               // erase command
2455
    spi_write_byte(s >> 8);                     // 24 byte address
2456
#line 536 "../../include/ztex-flash2.h"
2457
    spi_write_byte(s & 255);
2458
    spi_write_byte(0);
2459
    spi_deselect();
2460
 
2461
    spi_need_pp = 1;
2462
    return 0;
2463
}
2464
 
2465
 
2466
/* *********************************************************************
2467
   ***** flash_write_finish_sector *************************************
2468
   ********************************************************************* */
2469
/*
2470
   Dummy function for compatibilty.
2471
*/
2472
BYTE flash_write_finish_sector (WORD n) {
2473
    n;
2474
    spi_deselect();
2475
    return 0;
2476
}
2477
 
2478
 
2479
/* *********************************************************************
2480
   ***** flash_write_finish ********************************************
2481
   ********************************************************************* */
2482
/*
2483
   Dummy function for compatibilty.
2484
*/
2485
void flash_write_finish () {
2486
    spi_deselect();
2487
}
2488
 
2489
 
2490
/* *********************************************************************
2491
   ***** flash_write_next **********************************************
2492
   ********************************************************************* */
2493
/*
2494
   Prepare the next sector for writing, see flash_write_finish1.
2495
*/
2496
BYTE flash_write_next () {
2497
    spi_deselect();
2498
    return flash_write_init(spi_write_sector+1);
2499
}
2500
 
2501
 
2502
/* *********************************************************************
2503
   ***** flash_init ****************************************************
2504
   ********************************************************************* */
2505
// init the flash
2506
#line 585 "../../include/ztex-flash2.h"
2507
void flash_init() {
2508
    BYTE i;
2509
 
2510
    PORTCCFG = 0;
2511
 
2512
    flash_enabled = 1;
2513
    flash_ec = 0;
2514
    flash_sector_size = 0x8010;  // 64 KByte
2515
#line 593 "../../include/ztex-flash2.h"
2516
    spi_erase_cmd = 0xd8;
2517
 
2518
    OEC &= ~1;
2519
    OEA |= 8 | 2 | 1;
2520
    IOA3 = 1;
2521
    spi_clocks(0);                               // 256 clocks
2522
#line 599 "../../include/ztex-flash2.h"
2523
 
2524
    {                   // send a command, argument=0
2525
#line 359 "../../include/ztex-flash2.h"
2526
    spi_last_cmd = 0x90;
2527
    spi_select();                               // select
2528
    spi_write_byte(0x90);                               // CMD 90h
2529
}                       // CMD 90h, not supported by all chips
2530
    spi_clocks(24);                             // ADDR=0
2531
#line 602 "../../include/ztex-flash2.h"
2532
    spi_device = flash_read_byte();
2533
    spi_deselect();                             // deselect
2534
#line 604 "../../include/ztex-flash2.h"
2535
 
2536
    {                   // send a command, argument=0
2537
#line 359 "../../include/ztex-flash2.h"
2538
    spi_last_cmd = 0x9F;
2539
    spi_select();                               // select
2540
    spi_write_byte(0x9F);                               // CMD 90h
2541
}                       // CMD 9Fh
2542
    flash_read(spi_buffer,3);                   // read data
2543
    spi_deselect();                             // deselect
2544
#line 608 "../../include/ztex-flash2.h"
2545
    if ( spi_buffer[2]<16 || spi_buffer[2]>24 ) {
2546
        goto  disable;
2547
    }
2548
    spi_vendor = spi_buffer[0];
2549
    spi_memtype = spi_buffer[1];
2550
 
2551
#line 628 "../../include/ztex-flash2.h"
2552
    i=spi_buffer[2]-16;
2553
#line 630 "../../include/ztex-flash2.h"
2554
    flash_sectors = 1 << i;
2555
 
2556
    return;
2557
 
2558
disable:
2559
    flash_enabled = 0;
2560
    flash_ec = 7;
2561
    OEA &= ~( 8 | 2 | 1 );
2562
}
2563
 
2564
 
2565
/* *********************************************************************
2566
   ***** EP0 vendor request 0x40 ***************************************
2567
   ********************************************************************* */
2568
// send flash information structure (card size, error status,  ...) to the host
2569
#line 654 "../../include/ztex-flash2.h"
2570
 
2571
/* *********************************************************************
2572
   ***** EP0 vendor request 0x41 ***************************************
2573
   ********************************************************************* */
2574
/* read modes (ep0_read_mode)
2575
        0: start read
2576
        1: continue read
2577
        2: finish read
2578
*/
2579
void spi_read_ep0 () {
2580
    flash_read(EP0BUF, ep0_payload_transfer);
2581
    if ( ep0_read_mode==2 && ep0_payload_remaining==0 ) {
2582
        spi_deselect();
2583
    }
2584
}
2585
 
2586
#line 686 "../../include/ztex-flash2.h"
2587
 
2588
/* *********************************************************************
2589
   ***** EP0 vendor command 0x42 ***************************************
2590
   ********************************************************************* */
2591
void spi_send_ep0 () {
2592
    flash_write(EP0BUF, ep0_payload_transfer);
2593
    if ( ep0_write_mode==2 && ep0_payload_remaining==0 ) {
2594
        spi_deselect();
2595
    }
2596
}
2597
 
2598
#line 712 "../../include/ztex-flash2.h"
2599
 
2600
/* *********************************************************************
2601
   ***** EP0 vendor request 0x43 ***************************************
2602
   ********************************************************************* */
2603
// send detailed SPI status plus debug information
2604
#line 723 "../../include/ztex-flash2.h"
2605
 
2606
#line 168 "../../include/ztex.h"
2607
 
2608
#line 174 "../../include/ztex.h"
2609
 
2610
/* *********************************************************************
2611
   ***** FPGA configuration support ************************************
2612
   ********************************************************************* */
2613
#line 1 "../../include/ztex-fpga7.h"
2614
/*!
2615
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
2616
   Copyright (C) 2009-2014 ZTEX GmbH.
2617
   http://www.ztex.de
2618
 
2619
   This program is free software; you can redistribute it and/or modify
2620
   it under the terms of the GNU General Public License version 3 as
2621
   published by the Free Software Foundation.
2622
 
2623
   This program is distributed in the hope that it will be useful, but
2624
   WITHOUT ANY WARRANTY; without even the implied warranty of
2625
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2626
   General Public License for more details.
2627
 
2628
   You should have received a copy of the GNU General Public License
2629
   along with this program; if not, see http://www.gnu.org/licenses/.
2630
!*/
2631
 
2632
/*
2633
    FPGA support for ZTEX USB FPGA Modules 2.01 and 2.04
2634
*/
2635
 
2636
#line 25 "../../include/ztex-fpga7.h"
2637
 
2638
#line 27 "../../include/ztex-fpga7.h"
2639
 
2640
__xdata BYTE fpga_checksum;         // checksum
2641
__xdata DWORD fpga_bytes;           // transfered bytes
2642
__xdata BYTE fpga_init_b;           // init_b state (should be 222 after configuration)
2643
__xdata BYTE fpga_flash_result;     // result of automatic fpga configuarion from Flash
2644
#line 32 "../../include/ztex-fpga7.h"
2645
 
2646
__xdata BYTE fpga_conf_initialized; // 123 if initialized
2647
#line 34 "../../include/ztex-fpga7.h"
2648
__xdata BYTE OOEA;
2649
 
2650
/* *********************************************************************
2651
   ***** reset_fpga ****************************************************
2652
   ********************************************************************* */
2653
static void reset_fpga () {
2654
    OEE = (OEE & ~64) | 128;
2655
    IOE = IOE & ~128;
2656
    wait(1);
2657
    IOE = IOE | 128;
2658
    fpga_conf_initialized = 0;
2659
}
2660
 
2661
/* *********************************************************************
2662
   ***** init_fpga *****************************************************
2663
   ********************************************************************* */
2664
static void init_fpga () {
2665
    IOE = IOE | 128;
2666
    OEE = (OEE & ~64) | 128;
2667
    if ( ! (IOE & 64) ) {
2668
        // ensure that FPGA is in a proper configuration mode
2669
        IOE = IOE & ~128;                       // PROG_B = 0
2670
#line 56 "../../include/ztex-fpga7.h"
2671
        OEA = (OEA & 4 ) | 16 | 32 | 64;
2672
        IOA = (IOA & 4 ) | 32;
2673
        wait(1);
2674
        IOE = IOE | 128;                        // PROG_B = 1
2675
#line 60 "../../include/ztex-fpga7.h"
2676
 
2677
    }
2678
    fpga_conf_initialized = 0;
2679
}
2680
 
2681
/* *********************************************************************
2682
   ***** init_fpga_configuration ***************************************
2683
   ********************************************************************* */
2684
static void init_fpga_configuration () {
2685
    unsigned short k;
2686
 
2687
    {
2688
 
2689
    }
2690
 
2691
    IFCONFIG = 128;
2692
#line 41 "../../include/ezregs.h"
2693
    __asm
2694
        nop
2695
        nop
2696
        nop
2697
        nop
2698
    __endasm;
2699
#line 76 "../../include/ztex-fpga7.h"
2700
 
2701
    PORTACFG = 0;
2702
    PORTCCFG = 0;
2703
 
2704
    OOEA = OEA;
2705
    fpga_conf_initialized = 123;
2706
 
2707
    OEA &= 4;                   // only unsed PA bit
2708
#line 84 "../../include/ztex-fpga7.h"
2709
 
2710
    OEE = (OEE & ~64) | 128;
2711
    IOE = IOE & ~128;           // PROG_B = 0
2712
#line 87 "../../include/ztex-fpga7.h"
2713
 
2714
    //     CSI      M0       M1       RDWR
2715
#line 89 "../../include/ztex-fpga7.h"
2716
    OEA |= 2 | 16 | 32 | 64;
2717
    IOA = ( IOA & 4 ) | 2 | 32;
2718
    wait(5);
2719
 
2720
    IOE = IOE | 128;                    // PROG_B = 1
2721
    IOA1 = 0;                            // CS = 0
2722
#line 95 "../../include/ztex-fpga7.h"
2723
 
2724
    k=0;
2725
    while (!IOA7 && k<65535)
2726
        k++;
2727
 
2728
    //     CCLK 
2729
    OEA |= 1;                   // ready for configuration
2730
#line 102 "../../include/ztex-fpga7.h"
2731
 
2732
    fpga_init_b = IOA7 ? 200 : 100;
2733
    fpga_bytes = 0;
2734
    fpga_checksum = 0;
2735
}
2736
 
2737
/* *********************************************************************
2738
   ***** post_fpga_confog **********************************************
2739
   ********************************************************************* */
2740
static void post_fpga_config () {
2741
 
2742
}
2743
 
2744
/* *********************************************************************
2745
   ***** finish_fpga_configuration *************************************
2746
   ********************************************************************* */
2747
static void finish_fpga_configuration () {
2748
    BYTE w;
2749
    fpga_init_b += IOA7 ? 22 : 11;
2750
 
2751
    for ( w=0; w<64; w++ ) {
2752
        IOA0 = 1; IOA0 = 0;
2753
    }
2754
    IOA1 = 1;
2755
    IOA0 = 1; IOA0 = 0;
2756
    IOA0 = 1; IOA0 = 0;
2757
    IOA0 = 1; IOA0 = 0;
2758
    IOA0 = 1; IOA0 = 0;
2759
 
2760
    OEA = OOEA;
2761
    if ( IOE & 64 )  {
2762
        post_fpga_config();
2763
    }
2764
}
2765
 
2766
 
2767
/* *********************************************************************
2768
   ***** EP0 vendor request 0x30 ***************************************
2769
   ********************************************************************* */
2770
#line 158 "../../include/ztex-fpga7.h"
2771
 
2772
 
2773
/* *********************************************************************
2774
   ***** EP0 vendor command 0x31 ***************************************
2775
   ********************************************************************* */
2776
#line 164 "../../include/ztex-fpga7.h"
2777
 
2778
 
2779
/* *********************************************************************
2780
   ***** EP0 vendor command 0x32 ***************************************
2781
   ********************************************************************* */
2782
void fpga_send_ep0() {
2783
    BYTE oOEC;
2784
    oOEC = OEC;
2785
    OEC = 255;
2786
    fpga_bytes += ep0_payload_transfer;
2787
    __asm
2788
        mov     dptr,#_EP0BCL
2789
        movx    a,@dptr
2790
        jz      010000$
2791
        mov     r2,a
2792
        mov     _AUTOPTRL1,#(_EP0BUF)
2793
        mov     _AUTOPTRH1,#(_EP0BUF >> 8)
2794
        mov     _AUTOPTRSETUP,#0x07
2795
        mov     dptr,#_fpga_checksum
2796
        movx    a,@dptr
2797
        mov     r1,a
2798
        mov     dptr,#_XAUTODAT1
2799
010001$:
2800
        movx    a,@dptr                 // 2
2801
        mov     _IOC,a                  // 2
2802
        setb    _IOA0                   // 2
2803
        add     a,r1                    // 1
2804
        mov     r1,a                    // 1
2805
        clr     _IOA0                   // 2
2806
        djnz    r2, 010001$             // 4
2807
#line 194 "../../include/ztex-fpga7.h"
2808
 
2809
        mov     dptr,#_fpga_checksum
2810
        mov     a,r1
2811
        movx    @dptr,a
2812
 
2813
010000$:
2814
        __endasm;
2815
    OEC = oOEC;
2816
    if ( EP0BCL<64 ) {
2817
        finish_fpga_configuration();
2818
    }
2819
}
2820
 
2821
#line 213 "../../include/ztex-fpga7.h"
2822
 
2823
 
2824
#line 216 "../../include/ztex-fpga7.h"
2825
/* *********************************************************************
2826
   ***** fpga_configure_from_flash *************************************
2827
   ********************************************************************* */
2828
/*
2829
    Configure the FPGA using a bitstream from flash.
2830
    If force == 0 a already configured FPGA is not re-configured.
2831
    Return values:
2832
 
2833
        1 : FPGA already configured
2834
        4 : Configuration error
2835
*/
2836
BYTE fpga_configure_from_flash( BYTE force ) {
2837
//    BYTE c,d;
2838
#line 229 "../../include/ztex-fpga7.h"
2839
    WORD i;
2840
 
2841
    if ( ( force == 0 ) && ( IOE & 64 ) ) {
2842
        fpga_flash_result = 1;
2843
        return 1;
2844
    }
2845
 
2846
    fpga_flash_result = 0;
2847
 
2848
    IFCONFIG = 128;
2849
#line 41 "../../include/ezregs.h"
2850
    __asm
2851
        nop
2852
        nop
2853
        nop
2854
        nop
2855
    __endasm;
2856
#line 239 "../../include/ztex-fpga7.h"
2857
 
2858
    PORTACFG = 0;
2859
    PORTCCFG = 0;
2860
 
2861
//    c = OEA;
2862
    OEA &= 4;                   // only unsed PA bit
2863
#line 245 "../../include/ztex-fpga7.h"
2864
 
2865
//    d = OEC;
2866
#line 247 "../../include/ztex-fpga7.h"
2867
    OEC &= ~1;
2868
 
2869
    OEE = (OEE & ~64) | 128;
2870
    IOE = IOE & ~128;           // PROG_B = 0
2871
#line 251 "../../include/ztex-fpga7.h"
2872
 
2873
    //     M0       M1
2874
#line 253 "../../include/ztex-fpga7.h"
2875
    OEA |= 16 | 32;
2876
    IOA = ( IOA & 4 ) | 16;
2877
    wait(1);
2878
 
2879
    IOE = IOE | 128;                    // PROG_B = 1
2880
#line 258 "../../include/ztex-fpga7.h"
2881
 
2882
// wait up to 4s for CS going high
2883
#line 260 "../../include/ztex-fpga7.h"
2884
    wait(20);
2885
    for (i=0; IOA7 && (!IOA1) && i<4000; i++ ) {
2886
        wait(1);
2887
    }
2888
 
2889
    wait(1);
2890
 
2891
    if ( IOE & 64 )  {
2892
//      IOA = ( IOA & bmBIT2 ) | bmBIT3;
2893
#line 269 "../../include/ztex-fpga7.h"
2894
        post_fpga_config();
2895
//      OEC = d;
2896
//      OEA = c;
2897
#line 272 "../../include/ztex-fpga7.h"
2898
    }
2899
    else {
2900
        init_fpga();
2901
        fpga_flash_result = 4;
2902
    }
2903
 
2904
    return fpga_flash_result;
2905
}
2906
 
2907
#line 1 "../../include/ztex-fpga-flash2.h"
2908
/*!
2909
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
2910
   Copyright (C) 2009-2014 ZTEX GmbH.
2911
   http://www.ztex.de
2912
 
2913
   This program is free software; you can redistribute it and/or modify
2914
   it under the terms of the GNU General Public License version 3 as
2915
   published by the Free Software Foundation.
2916
 
2917
   This program is distributed in the hope that it will be useful, but
2918
   WITHOUT ANY WARRANTY; without even the implied warranty of
2919
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2920
   General Public License for more details.
2921
 
2922
   You should have received a copy of the GNU General Public License
2923
   along with this program; if not, see http://www.gnu.org/licenses/.
2924
!*/
2925
 
2926
/*
2927
    Common functions for FPGA configuration from SPI flash
2928
*/
2929
 
2930
__code BYTE fpga_flash_boot_id[] = {'Z','T','E', 'X', 'B', 'S', '\1', '\1'};
2931
 
2932
/* *********************************************************************
2933
   ***** fpga_first_free_sector ****************************************
2934
   ********************************************************************* */
2935
// First free sector. Returns 0 if no boot sector exeists.   
2936
// Use the macro FLASH_FIRST_FREE_SECTOR instead of this function.
2937
#line 31 "../../include/ztex-fpga-flash2.h"
2938
WORD fpga_first_free_sector() {
2939
    BYTE i,j;
2940
#line 34 "../../include/ztex-fpga-flash2.h"
2941
    __xdata WORD buf[2];
2942
 
2943
    if ( config_data_valid ) {
2944
        mac_eeprom_read ( (__xdata BYTE*) buf, 26, 4 );         // read actual and max bitstream size 
2945
#line 38 "../../include/ztex-fpga-flash2.h"
2946
        if ( buf[1] != 0 ) {
2947
            return ( ( ( buf[1] > buf[0] ? buf[1] : buf[0] ) - 1 ) >> ((flash_sector_size & 255) - 12) ) + 1;
2948
        }
2949
    }
2950
    flash_read_init( 0 );                                // prepare reading sector 0
2951
#line 44 "../../include/ztex-fpga-flash2.h"
2952
    for ( i=0; i<8 && flash_read_byte()==fpga_flash_boot_id[i]; i++ );
2953
    if ( i != 8 ) {
2954
        flash_read_finish(flash_sector_size - i);       // dummy-read the rest of the sector + finish read opration
2955
#line 47 "../../include/ztex-fpga-flash2.h"
2956
        return 0;
2957
    }
2958
    i=flash_read_byte();
2959
    j=flash_read_byte();
2960
    flash_read_finish(flash_sector_size - 10);          // dummy-read the rest of the sector + finish read opration
2961
#line 52 "../../include/ztex-fpga-flash2.h"
2962
 
2963
    return (i | (j<<8))+1;
2964
}
2965
 
2966
/* *********************************************************************
2967
   ***** fpga_configure_from_flash_init ********************************
2968
   ********************************************************************* */
2969
// this function is called by init_USB;
2970
#line 60 "../../include/ztex-fpga-flash2.h"
2971
BYTE fpga_configure_from_flash_init() {
2972
    BYTE i;
2973
 
2974
#line 64 "../../include/ztex-fpga-flash2.h"
2975
    __xdata WORD buf[2];
2976
 
2977
    if ( config_data_valid ) {
2978
        mac_eeprom_read ( (__xdata BYTE*) buf, 26, 4 );         // read actual and max bitstream size 
2979
#line 68 "../../include/ztex-fpga-flash2.h"
2980
        if ( buf[1] != 0 ) {
2981
            if ( buf[0] == 0 ) {
2982
                return fpga_flash_result = 3;
2983
            }
2984
//          return 10;
2985
#line 73 "../../include/ztex-fpga-flash2.h"
2986
            goto flash_config;
2987
        }
2988
//          return 15;
2989
#line 76 "../../include/ztex-fpga-flash2.h"
2990
    }
2991
#line 78 "../../include/ztex-fpga-flash2.h"
2992
 
2993
    // read the boot sector
2994
    if ( flash_read_init( 0 ) )          // prepare reading sector 0
2995
#line 81 "../../include/ztex-fpga-flash2.h"
2996
        return fpga_flash_result = 2;
2997
    for ( i=0; i<8 && flash_read_byte()==fpga_flash_boot_id[i]; i++ );
2998
    if ( i != 8 ) {
2999
        flash_read_finish(flash_sector_size - i);       // dummy-read the rest of the sector + finish read opration
3000
#line 85 "../../include/ztex-fpga-flash2.h"
3001
        return fpga_flash_result = 3;
3002
    }
3003
    i = flash_read_byte();
3004
    i |= flash_read_byte();
3005
    flash_read_finish(flash_sector_size - 10);          // dummy-read the rest of the sector + finish read opration
3006
#line 90 "../../include/ztex-fpga-flash2.h"
3007
    if ( i==0 )
3008
        return fpga_flash_result = 3;
3009
 
3010
flash_config:
3011
    fpga_flash_result = fpga_configure_from_flash(0);
3012
    if ( fpga_flash_result == 1 ) {
3013
        post_fpga_config();
3014
    }
3015
    else if ( fpga_flash_result == 4 ) {
3016
        fpga_flash_result = fpga_configure_from_flash(0);        // up to two tries
3017
#line 100 "../../include/ztex-fpga-flash2.h"
3018
    }
3019
    return fpga_flash_result;
3020
}
3021
 
3022
#line 282 "../../include/ztex-fpga7.h"
3023
 
3024
#line 284 "../../include/ztex-fpga7.h"
3025
 
3026
#line 199 "../../include/ztex.h"
3027
 
3028
#line 201 "../../include/ztex.h"
3029
 
3030
 
3031
/* *********************************************************************
3032
   ***** DEBUG helper functions ****************************************
3033
   ********************************************************************* */
3034
#line 209 "../../include/ztex.h"
3035
 
3036
 
3037
/* *********************************************************************
3038
   ***** XMEGA support *************************************************
3039
   ********************************************************************* */
3040
#line 215 "../../include/ztex.h"
3041
 
3042
#line 222 "../../include/ztex.h"
3043
 
3044
#line 237 "../../include/ztex.h"
3045
 
3046
#line 239 "../../include/ztex.h"
3047
 
3048
/* *********************************************************************
3049
   ***** define the descriptors ****************************************
3050
   ********************************************************************* */
3051
#line 1 "../../include/ztex-descriptors.h"
3052
/*!
3053
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
3054
   Copyright (C) 2009-2014 ZTEX GmbH.
3055
   http://www.ztex.de
3056
 
3057
   This program is free software; you can redistribute it and/or modify
3058
   it under the terms of the GNU General Public License version 3 as
3059
   published by the Free Software Foundation.
3060
 
3061
   This program is distributed in the hope that it will be useful, but
3062
   WITHOUT ANY WARRANTY; without even the implied warranty of
3063
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3064
   General Public License for more details.
3065
 
3066
   You should have received a copy of the GNU General Public License
3067
   along with this program; if not, see http://www.gnu.org/licenses/.
3068
!*/
3069
 
3070
/*
3071
   Defines the USB descriptors
3072
*/
3073
 
3074
#line 25 "../../include/ztex-descriptors.h"
3075
 
3076
#line 28 "../../include/ztex-descriptors.h"
3077
 
3078
__xdata __at 0x06c BYTE ZTEX_DESCRIPTOR;
3079
 
3080
/* ZTEX descriptor version. Must be 1. */
3081
__xdata __at 0x06c+1 BYTE ZTEX_DESCRIPTOR_VERSION;
3082
 
3083
/* Must not be modified, ID="ZTEX" */
3084
__xdata __at 0x06c+2 BYTE ZTEXID[4];
3085
 
3086
/*
3087
   Product ID and firmware compatibility information.
3088
 
3089
   A firmware can overwrite an installed one if
3090
   if ( INSTALLED.PRODUCTID[0]==0 || PRODUCTID[0]==0 || INSTALLED.PRODUCTID[0]==PRODUCTID[0] ) &&
3091
      ( INSTALLED.PRODUCTID[1]==0 || PRODUCTID[1]==0 || INSTALLED.PRODUCTID[1]==PRODUCTID[1] ) &&
3092
      ( INSTALLED.PRODUCTID[2]==0 || PRODUCTID[2]==0 || INSTALLED.PRODUCTID[2]==PRODUCTID[2] ) &&
3093
      ( INSTALLED.PRODUCTID[3]==0 || PRODUCTID[3]==0 || INSTALLED.PRODUCTID[3]==PRODUCTID[3] )
3094
 
3095
   Reserved Product ID's:
3096
 
3097
   0.0.0.0              // default Product ID (no product specified)
3098
   1.*.*.*              // may be used for experimental purposes
3099
   10.*.*.*             // used for ZTEX products
3100
   10.11.*.*            // ZTEX USB-FPGA-Module 1.2
3101
   10.12.*.*            // ZTEX USB-FPGA-Module 1.11
3102
   10.12.2.1..4         // NIT (http://www.niteurope.com/)
3103
   10.13.*.*            // ZTEX USB-FPGA-Module 1.15 (not 1.15y)
3104
   10.14.*.*            // ZTEX USB-FPGA-Module 1.15x
3105
   10.15.*.*            // ZTEX USB-FPGA-Module 1.15y
3106
   10.16.*.*            // ZTEX USB-FPGA-Module 2.16
3107
   10.17.*.*            // ZTEX USB-FPGA-Module 2.13
3108
   10.18.*.*            // ZTEX USB-FPGA-Module 2.01
3109
   10.19.*.*            // ZTEX USB-FPGA-Module 2.04
3110
   10.20.*.*            // ZTEX USB-Module 1.0
3111
   10.30.*.*            // ZTEX USB-XMEGA-Module 1.0
3112
   10.0.1.1             // ZTEX bitminer firmware
3113
 
3114
   Please contact us (http://www.ztex.de/contact.e.html) if you want to register/reserve a Product ID (range).
3115
*/
3116
__xdata __at 0x06c+6 BYTE PRODUCT_ID[4];
3117
 
3118
/* Firmware version, may be used to distinguish seveveral firmware versions */
3119
__xdata __at 0x06c+10 BYTE FW_VERSION;
3120
 
3121
/* Interface version. Must be 1. */
3122
__xdata __at 0x06c+11 BYTE INTERFACE_VERSION;
3123
 
3124
/*
3125
    Standard interface capabilities:
3126
        0.0  : EEPROM read/write, see ztex-eeprom.h
3127
        0.1  : FPGA configuration, see ztex-fpga.h
3128
        0.2  : Flash memory support, see ztex-flash1.h
3129
        0.3  : Debug helper, see ztex-debug.h
3130
        0.4  : AVR XMEGA support, see ztex-xmega.h
3131
        0.5  : High speed FPGA configuration support
3132
        0.6  : MAC EEPROM support
3133
        0.7  : Multi-FPGA support
3134
        1.0  : Temperature sensor support
3135
*/
3136
__xdata __at 0x06c+12 BYTE INTERFACE_CAPABILITIES[6];
3137
 
3138
/* Space for settings which depends on PRODUCT_ID, e.g extra capabilities */
3139
__xdata __at 0x06c+18 BYTE MODULE_RESERVED[12];
3140
 
3141
/*
3142
   Serial number string
3143
   default: "0000000000"
3144
   Should only be modified by the the firmware upload software
3145
*/
3146
__xdata __at 0x06c+30 BYTE SN_STRING[10];
3147
 
3148
/* Are Vendor ID and Product ID defined? */
3149
#line 103 "../../include/ztex-descriptors.h"
3150
 
3151
#line 107 "../../include/ztex-descriptors.h"
3152
 
3153
/* Prepare the Interfaces, i.e. check which interfaces are defined */
3154
#line 124 "../../include/ztex-descriptors.h"
3155
 
3156
#line 109 "../../include/ztex-descriptors.h"
3157
 
3158
//Interface 0: YES
3159
#line 109 "../../include/ztex-descriptors.h"
3160
 
3161
//Interface 1: NO
3162
#line 109 "../../include/ztex-descriptors.h"
3163
 
3164
//Interface 2: NO
3165
#line 109 "../../include/ztex-descriptors.h"
3166
 
3167
//Interface 3: NO
3168
#line 129 "../../include/ztex-descriptors.h"
3169
 
3170
/* define the ZTEX descriptor */
3171
void abscode_identity()// _naked
3172
#line 132 "../../include/ztex-descriptors.h"
3173
{
3174
    __asm
3175
    .area ABSCODE (ABS,CODE)
3176
 
3177
    .org 0x06c
3178
    .db 40
3179
 
3180
    .org _ZTEX_DESCRIPTOR_VERSION
3181
    .db 1
3182
 
3183
    .org _ZTEXID
3184
    .ascii "ZTEX"
3185
 
3186
    .org _PRODUCT_ID
3187
    .db 10
3188
    .db 19
3189
    .db 0
3190
    .db 0
3191
 
3192
    .org _FW_VERSION
3193
    .db 0
3194
 
3195
    .org _INTERFACE_VERSION
3196
    .db 1
3197
 
3198
    .org _INTERFACE_CAPABILITIES
3199
#line 185 "../../include/ztex-descriptors.h"
3200
    .db 0 + 1 + 2 + 4 + 64
3201
#line 191 "../../include/ztex-descriptors.h"
3202
    .db 0
3203
    .db 0
3204
    .db 0
3205
    .db 0
3206
    .db 0
3207
 
3208
    .org _MODULE_RESERVED
3209
    .db 0
3210
    .db 0
3211
    .db 0
3212
    .db 0
3213
    .db 0
3214
    .db 0
3215
    .db 0
3216
    .db 0
3217
    .db 0
3218
    .db 0
3219
    .db 0
3220
    .db 0
3221
 
3222
    .org _SN_STRING
3223
    .ascii "0000000000"
3224
 
3225
    .area CSEG    (CODE)
3226
    __endasm;
3227
}
3228
 
3229
/* *********************************************************************
3230
   ***** strings *******************************************************
3231
   ********************************************************************* */
3232
__code char manufacturerString[] = "ZTEX";
3233
__code char productString[] = "USB-FPGA Module 2.01  (default)";
3234
__code char configurationString[] = "default";
3235
 
3236
 
3237
/* *********************************************************************
3238
   ***** descriptors ***************************************************
3239
   ********************************************************************* */
3240
#line 271 "../../include/ztex-descriptors.h"
3241
 
3242
#line 335 "../../include/ztex-descriptors.h"
3243
 
3244
#line 337 "../../include/ztex-descriptors.h"
3245
 
3246
#line 341 "../../include/ztex-descriptors.h"
3247
 
3248
__code BYTE DeviceDescriptor[] =
3249
    {
3250
        18,     // 0, Descriptor length
3251
        0x01,   // 1, Descriptor type
3252
        0x00,   // 2, Specification Version (L)
3253
        0x02,   // 3, Specification Version (H)
3254
        0xff,   // 4, Device class
3255
        0xff,   // 5, Device sub-class
3256
        0xff,   // 6, Device protocol
3257
        64,     // 7, Maximum packet size for EP0
3258
        (0x221a) & 255, // 8, VENDOR_ID (L)
3259
        (0x221a) >> 8,  // 9, VENDOR_ID (H)
3260
        (0x100) & 255,  // 10, PRODUCT_ID (L)
3261
        (0x100) >> 8,   // 11, PRODUCT_ID (H)
3262
        0x00,   // 12, device release number (BCD, L)
3263
        0x00,   // 13, device release number (BCD, H)
3264
        1,      // 14, Manufacturer string index
3265
        2,      // 15, Product string index
3266
        3,      // 16, Serial number string index
3267
        1       // 17, Number of configurations
3268
#line 362 "../../include/ztex-descriptors.h"
3269
    };
3270
 
3271
__code BYTE DeviceQualifierDescriptor[] =
3272
    {
3273
        10,     // 0, Descriptor length
3274
        0x06,   // 1, Decriptor type
3275
        0x00,   // 2, Specification Version (L)
3276
        0x02,   // 3, Specification Version (H)
3277
        0xff,   // 4, Device class
3278
        0xff,   // 5, Device sub-class
3279
        0xff,   // 6, Device protocol
3280
        64,     // 7, Maximum packet size (EP0?)
3281
        1,      // 8, Number of configurations
3282
        0,       // 9, Reserved, must be zero
3283
#line 376 "../../include/ztex-descriptors.h"
3284
    };
3285
 
3286
__code BYTE HighSpeedConfigDescriptor[] =
3287
    {
3288
        9       // 0, Descriptor length
3289
        ,0x02   // 1, Decriptor type
3290
        ,sizeof(HighSpeedConfigDescriptor) & 0xff       // 2, Total length (LSB)
3291
//      ,sizeof(HighSpeedConfigDescriptor) >> 8         // 3, Total length (MB)
3292
        ,0                                               // 3, To avoid warnings, descriptor length will never exceed 255 bytes
3293
        ,0       // 4, Number of Interfaces
3294
#line 388 "../../include/ztex-descriptors.h"
3295
          +1
3296
#line 399 "../../include/ztex-descriptors.h"
3297
 
3298
        ,1      // 5, Configuration number
3299
        ,4      // 6, Configuration string
3300
        ,0xc0   // 7, Attributes: bus and self powered
3301
        ,50     // Maximum bus power 100 mA
3302
#line 272 "../../include/ztex-descriptors.h"
3303
 
3304
                // Interface 0 descriptor
3305
        ,9      // 0, Descriptor length
3306
        ,0x04   // 1, Descriptor type
3307
        ,0       // 2, Zero-based index of this interface
3308
        ,0       // 3, Alternate setting 0
3309
        ,0       // 4, Number of end points 
3310
#line 295 "../../include/ztex-descriptors.h"
3311
          +1
3312
#line 298 "../../include/ztex-descriptors.h"
3313
          +1
3314
        ,0xff   // 5, Interface class
3315
        ,0xff   // 6, Interface sub class
3316
        ,0xff   // 7, Interface protocol
3317
        ,0       // 8, Index of interface string descriptor
3318
#line 229 "../../include/ztex-descriptors.h"
3319
 
3320
                                // Endpoint 1IN descriptor
3321
        ,7                      // 0, Descriptor length
3322
        ,5                      // 1, Descriptor type
3323
        ,0x81                   // 2, direction=output, address=1
3324
        ,2                      // 3, BULK transferns
3325
        ,512 & 0xff     // 4, max. packet size (L) 
3326
        ,512 >> 8       // 5, max. packet size (H) 
3327
        ,0                       // 6, Polling interval
3328
#line 317 "../../include/ztex-descriptors.h"
3329
 
3330
#line 229 "../../include/ztex-descriptors.h"
3331
 
3332
                                // Endpoint 1OUT descriptor
3333
        ,7                      // 0, Descriptor length
3334
        ,5                      // 1, Descriptor type
3335
        ,0x01                   // 2, direction=output, address=1
3336
        ,2                      // 3, BULK transferns
3337
        ,512 & 0xff     // 4, max. packet size (L) 
3338
        ,512 >> 8       // 5, max. packet size (H) 
3339
        ,0                       // 6, Polling interval
3340
#line 320 "../../include/ztex-descriptors.h"
3341
 
3342
#line 405 "../../include/ztex-descriptors.h"
3343
 
3344
#line 417 "../../include/ztex-descriptors.h"
3345
    };
3346
__code BYTE HighSpeedConfigDescriptor_PadByte[2-(sizeof(HighSpeedConfigDescriptor) & 1)] = { 0 };
3347
 
3348
__code BYTE FullSpeedConfigDescriptor[] =
3349
    {
3350
        9       // 0, Descriptor length
3351
        ,0x02   // 1, Decriptor type
3352
        ,sizeof(FullSpeedConfigDescriptor) & 0xff       // 2, Total length (LSB)
3353
//      ,sizeof(FullSpeedConfigDescriptor) >> 8         // 3, Total length (MSB)
3354
        ,0                                               // 3, To avoid warnings, descriptor length will never exceed 255 bytes
3355
        ,0       // 4, Number of Interfaces
3356
#line 429 "../../include/ztex-descriptors.h"
3357
          +1
3358
#line 440 "../../include/ztex-descriptors.h"
3359
 
3360
        ,1      // 5, Configuration number
3361
        ,4      // 6, Configuration string
3362
        ,0xc0   // 7, Attributes: bus and self powered
3363
        ,50     // Maximum bus power 100 mA
3364
#line 272 "../../include/ztex-descriptors.h"
3365
 
3366
                // Interface 0 descriptor
3367
        ,9      // 0, Descriptor length
3368
        ,0x04   // 1, Descriptor type
3369
        ,0       // 2, Zero-based index of this interface
3370
        ,0       // 3, Alternate setting 0
3371
        ,0       // 4, Number of end points 
3372
#line 295 "../../include/ztex-descriptors.h"
3373
          +1
3374
#line 298 "../../include/ztex-descriptors.h"
3375
          +1
3376
        ,0xff   // 5, Interface class
3377
        ,0xff   // 6, Interface sub class
3378
        ,0xff   // 7, Interface protocol
3379
        ,0       // 8, Index of interface string descriptor
3380
#line 229 "../../include/ztex-descriptors.h"
3381
 
3382
                                // Endpoint 1IN descriptor
3383
        ,7                      // 0, Descriptor length
3384
        ,5                      // 1, Descriptor type
3385
        ,0x81                   // 2, direction=output, address=1
3386
        ,2                      // 3, BULK transferns
3387
        ,64                     // 4, max. packet size (L) 
3388
        ,0                       // 5, max. packet size (H) 
3389
        ,0                       // 6, Polling interval
3390
#line 317 "../../include/ztex-descriptors.h"
3391
 
3392
#line 229 "../../include/ztex-descriptors.h"
3393
 
3394
                                // Endpoint 1OUT descriptor
3395
        ,7                      // 0, Descriptor length
3396
        ,5                      // 1, Descriptor type
3397
        ,0x01                   // 2, direction=output, address=1
3398
        ,2                      // 3, BULK transferns
3399
        ,64                     // 4, max. packet size (L) 
3400
        ,0                       // 5, max. packet size (H) 
3401
        ,0                       // 6, Polling interval
3402
#line 320 "../../include/ztex-descriptors.h"
3403
 
3404
#line 446 "../../include/ztex-descriptors.h"
3405
 
3406
#line 457 "../../include/ztex-descriptors.h"
3407
    };
3408
__code BYTE FullSpeedConfigDescriptor_PadByte[2-(sizeof(FullSpeedConfigDescriptor) & 1)] = { 0 };
3409
 
3410
__code BYTE EmptyStringDescriptor[] =
3411
    {
3412
        sizeof(EmptyStringDescriptor),          // Length
3413
        0x03,                                   // Descriptor type
3414
#line 464 "../../include/ztex-descriptors.h"
3415
        0, 0
3416
    };
3417
 
3418
#line 243 "../../include/ztex.h"
3419
 
3420
 
3421
 
3422
/* *********************************************************************
3423
   ***** Temperature sensor support ************************************
3424
   ********************************************************************* */
3425
#line 254 "../../include/ztex.h"
3426
 
3427
#line 257 "../../include/ztex.h"
3428
 
3429
 
3430
/* *********************************************************************
3431
   ***** interrupt routines ********************************************
3432
   ********************************************************************* */
3433
#line 1 "../../include/ztex-isr.h"
3434
/*!
3435
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
3436
   Copyright (C) 2009-2014 ZTEX GmbH.
3437
   http://www.ztex.de
3438
 
3439
   This program is free software; you can redistribute it and/or modify
3440
   it under the terms of the GNU General Public License version 3 as
3441
   published by the Free Software Foundation.
3442
 
3443
   This program is distributed in the hope that it will be useful, but
3444
   WITHOUT ANY WARRANTY; without even the implied warranty of
3445
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3446
   General Public License for more details.
3447
 
3448
   You should have received a copy of the GNU General Public License
3449
   along with this program; if not, see http://www.gnu.org/licenses/.
3450
!*/
3451
 
3452
/*
3453
   Interrupt routines
3454
*/
3455
 
3456
#line 25 "../../include/ztex-isr.h"
3457
 
3458
__xdata BYTE ep0_prev_setup_request = 0xff;
3459
__xdata BYTE ep0_vendor_cmd_setup = 0;
3460
 
3461
__xdata WORD ISOFRAME_COUNTER[4] = {0, 0, 0, 0};    // counters for iso frames automatically reset by sync frame request
3462
#line 30 "../../include/ztex-isr.h"
3463
 
3464
/* *********************************************************************
3465
   ***** toggleData ****************************************************
3466
   ********************************************************************* */
3467
static void resetToggleData () {
3468
#line 44 "../../include/ztex-isr.h"
3469
 
3470
    TOGCTL = 0;                          // EP0 out
3471
#line 46 "../../include/ztex-isr.h"
3472
    TOGCTL = 0 | 32;
3473
    TOGCTL = 0x10;                      // EP0 in
3474
#line 48 "../../include/ztex-isr.h"
3475
    TOGCTL = 0x10 | 32;
3476
    TOGCTL = 1;                         // EP1 out
3477
#line 51 "../../include/ztex-isr.h"
3478
    TOGCTL = 1 | 32;
3479
    TOGCTL = 0x11;                      // EP1 in
3480
#line 55 "../../include/ztex-isr.h"
3481
    TOGCTL = 0x11 | 32;
3482
#line 35 "../../include/ztex-isr.h"
3483
 
3484
#line 35 "../../include/ztex-isr.h"
3485
 
3486
#line 35 "../../include/ztex-isr.h"
3487
 
3488
#line 35 "../../include/ztex-isr.h"
3489
 
3490
#line 61 "../../include/ztex-isr.h"
3491
}
3492
 
3493
/* *********************************************************************
3494
   ***** getStringDescriptor *******************************************
3495
   ********************************************************************* */
3496
#line 67 "../../include/ztex-isr.h"
3497
 
3498
static void sendStringDescriptor (BYTE loAddr, BYTE hiAddr, BYTE size)
3499
{
3500
    BYTE i;
3501
    if ( size > 31) size = 31;
3502
    if (SETUPDAT[7] == 0 && SETUPDAT[6]<size ) size = SETUPDAT[6];
3503
    AUTOPTRSETUP = 7;
3504
    AUTOPTRL1 = loAddr;
3505
    AUTOPTRH1 = hiAddr;
3506
    AUTOPTRL2 = (BYTE)(((unsigned short)(&EP0BUF))+1);
3507
    AUTOPTRH2 = (BYTE)((((unsigned short)(&EP0BUF))+1) >> 8);
3508
    XAUTODAT2 = 3;
3509
    for (i=0; i<size; i++) {
3510
        XAUTODAT2 = XAUTODAT1;
3511
        XAUTODAT2 = 0;
3512
    }
3513
    i = (size+1) << 1;
3514
    EP0BUF[0] = i;
3515
    EP0BUF[1] = 3;
3516
    EP0BCH = 0;
3517
    EP0BCL = i;
3518
}
3519
 
3520
/* *********************************************************************
3521
   ***** ep0_payload_update ********************************************
3522
   ********************************************************************* */
3523
static void ep0_payload_update() {
3524
    ep0_payload_transfer = ( ep0_payload_remaining > 64 ) ? 64 : ep0_payload_remaining;
3525
    ep0_payload_remaining -= ep0_payload_transfer;
3526
}
3527
 
3528
 
3529
/* *********************************************************************
3530
   ***** ep0_vendor_cmd_su **********************************************
3531
   ********************************************************************* */
3532
static void ep0_vendor_cmd_su() {
3533
    switch ( ep0_prev_setup_request ) {
3534
#line 122 "../../include/ztex-conf.h"
3535
 
3536
case 0x39:
3537
                                // write to EEPROM
3538
#line 236 "../../include/ztex-eeprom.h"
3539
    eeprom_write_checksum = 0;
3540
    eeprom_write_bytes = 0;
3541
    eeprom_addr =  ( SETUPDAT[3] << 8) | SETUPDAT[2];   // Address
3542
#line 124 "../../include/ztex-conf.h"
3543
 
3544
    break;
3545
#line 122 "../../include/ztex-conf.h"
3546
 
3547
case 0x3C:
3548
                                // write to EEPROM
3549
    mac_eeprom_addr =  SETUPDAT[2];                     // address
3550
#line 124 "../../include/ztex-conf.h"
3551
 
3552
    break;
3553
#line 122 "../../include/ztex-conf.h"
3554
 
3555
case 0x42:
3556
                        // write integer number of sectors
3557
#line 698 "../../include/ztex-flash2.h"
3558
    ep0_write_mode = SETUPDAT[5];
3559
    if ( (ep0_write_mode == 0) && flash_write_init((SETUPDAT[3] << 8) | SETUPDAT[2]) ) {
3560
#line 136 "../../include/ztex-conf.h"
3561
        {
3562
    EP0CS |= 0x01;      // set stall
3563
#line 138 "../../include/ztex-conf.h"
3564
    ep0_payload_remaining = 0;
3565
    break;
3566
#line 700 "../../include/ztex-flash2.h"
3567
}
3568
    }
3569
#line 124 "../../include/ztex-conf.h"
3570
 
3571
    break;
3572
#line 122 "../../include/ztex-conf.h"
3573
 
3574
case 0x31:
3575
    reset_fpga();
3576
    break;
3577
#line 122 "../../include/ztex-conf.h"
3578
 
3579
case 0x32:
3580
                // send FPGA configuration data
3581
#line 208 "../../include/ztex-fpga7.h"
3582
    if ( fpga_conf_initialized != 123 )
3583
        init_fpga_configuration();
3584
#line 124 "../../include/ztex-conf.h"
3585
 
3586
    break;
3587
#line 104 "../../include/ztex-isr.h"
3588
 
3589
        default:
3590
            EP0CS |= 0x01;                      // set stall, unknown request
3591
#line 107 "../../include/ztex-isr.h"
3592
    }
3593
}
3594
 
3595
/* *********************************************************************
3596
   ***** SUDAV_ISR *****************************************************
3597
   ********************************************************************* */
3598
static void SUDAV_ISR () __interrupt
3599
{
3600
    BYTE a;
3601
    ep0_prev_setup_request = bRequest;
3602
    SUDPTRCTL = 1;
3603
 
3604
    // standard USB requests
3605
#line 120 "../../include/ztex-isr.h"
3606
    switch ( bRequest ) {
3607
        case 0x00:      // get status 
3608
#line 122 "../../include/ztex-isr.h"
3609
            switch(SETUPDAT[0]) {
3610
                case 0x80:              // self powered and remote 
3611
                    EP0BUF[0] = 0;        // not self-powered, no remote wakeup
3612
#line 125 "../../include/ztex-isr.h"
3613
                    EP0BUF[1] = 0;
3614
                    EP0BCH = 0;
3615
                    EP0BCL = 2;
3616
                    break;
3617
                case 0x81:              // interface (reserved)
3618
                    EP0BUF[0] = 0;        // always return zeros
3619
#line 131 "../../include/ztex-isr.h"
3620
                    EP0BUF[1] = 0;
3621
                    EP0BCH = 0;
3622
                    EP0BCL = 2;
3623
                    break;
3624
                case 0x82:
3625
                    switch ( SETUPDAT[4] ) {
3626
                        case 0x00 :
3627
                        case 0x80 :
3628
                            EP0BUF[0] = EP0CS & 1;
3629
                            break;
3630
                        case 0x01 :
3631
                            EP0BUF[0] = EP1OUTCS & 1;
3632
                            break;
3633
                        case 0x81 :
3634
                            EP0BUF[0] = EP1INCS & 1;
3635
                            break;
3636
                        default:
3637
                            EP0BUF[0] = EPXCS[ ((SETUPDAT[4] >> 1)-1) & 3 ] & 1;
3638
                            break;
3639
                        }
3640
                    EP0BUF[1] = 0;
3641
                    EP0BCH = 0;
3642
                    EP0BCL = 2;
3643
                    break;
3644
            }
3645
            break;
3646
        case 0x01:      // disable feature, e.g. remote wake, stall bit
3647
#line 158 "../../include/ztex-isr.h"
3648
            if ( SETUPDAT[0] == 2 && SETUPDAT[2] == 0 ) {
3649
                switch ( SETUPDAT[4] ) {
3650
                    case 0x00 :
3651
                    case 0x80 :
3652
                        EP0CS &= ~1;
3653
                        break;
3654
                    case 0x01 :
3655
                        EP1OUTCS &= ~1;
3656
                        break;
3657
                    case 0x81 :
3658
                         EP1INCS &= ~1;
3659
                        break;
3660
                    default:
3661
                         EPXCS[ ((SETUPDAT[4] >> 1)-1) & 3 ] &= ~1;
3662
                        break;
3663
                }
3664
            }
3665
            break;
3666
        case 0x03:      // enable feature, e.g. remote wake, test mode, stall bit
3667
#line 177 "../../include/ztex-isr.h"
3668
            if ( SETUPDAT[0] == 2 && SETUPDAT[2] == 0 ) {
3669
                switch ( SETUPDAT[4] ) {
3670
                    case 0x00 :
3671
                    case 0x80 :
3672
                        EP0CS |= 1;
3673
                        break;
3674
                    case 0x01 :
3675
                        EP1OUTCS |= 1;
3676
                        break;
3677
                    case 0x81 :
3678
                         EP1INCS |= 1;
3679
                        break;
3680
                    default:
3681
                         EPXCS[ ((SETUPDAT[4] >> 1)-1) & 3 ] |= ~1;
3682
                        break;
3683
                }
3684
                a = ( (SETUPDAT[4] & 0x80) >> 3 ) | (SETUPDAT[4] & 0x0f);
3685
                TOGCTL = a;
3686
                TOGCTL = a | 32;
3687
            }
3688
            break;
3689
        case 0x06:                      // get descriptor
3690
#line 199 "../../include/ztex-isr.h"
3691
            switch(SETUPDAT[3]) {
3692
                case 0x01:              // device
3693
#line 201 "../../include/ztex-isr.h"
3694
                    SUDPTRH = ((BYTE)((((unsigned short)(&DeviceDescriptor)) >> 8) & 0xff)) ;
3695
                    SUDPTRL = ((BYTE)(&DeviceDescriptor));
3696
                    break;
3697
                case 0x02:              // configuration
3698
#line 205 "../../include/ztex-isr.h"
3699
                    if (USBCS & 128) {
3700
                        SUDPTRH = ((BYTE)((((unsigned short)(&HighSpeedConfigDescriptor)) >> 8) & 0xff)) ;
3701
                        SUDPTRL = ((BYTE)(&HighSpeedConfigDescriptor));
3702
                    }
3703
                    else {
3704
                        SUDPTRH = ((BYTE)((((unsigned short)(&FullSpeedConfigDescriptor)) >> 8) & 0xff)) ;
3705
                        SUDPTRL = ((BYTE)(&FullSpeedConfigDescriptor));
3706
                    }
3707
                    break;
3708
                case 0x03:              // strings
3709
#line 215 "../../include/ztex-isr.h"
3710
                    switch (SETUPDAT[2]) {
3711
                        case 1:
3712
                            sendStringDescriptor(((BYTE)(manufacturerString)), ((BYTE)((((unsigned short)(manufacturerString)) >> 8) & 0xff)) , sizeof(manufacturerString) );
3713
                            break;
3714
                        case 2:
3715
                            sendStringDescriptor(((BYTE)(productString)), ((BYTE)((((unsigned short)(productString)) >> 8) & 0xff)) , sizeof(productString) );
3716
                            break;
3717
                        case 3:
3718
                            sendStringDescriptor(((BYTE)(SN_STRING)), ((BYTE)((((unsigned short)(SN_STRING)) >> 8) & 0xff)) , sizeof(SN_STRING) );
3719
                            break;
3720
                        case 4:
3721
                            sendStringDescriptor(((BYTE)(configurationString)), ((BYTE)((((unsigned short)(configurationString)) >> 8) & 0xff)) , sizeof(configurationString) );
3722
                            break;
3723
                        default:
3724
                            SUDPTRH = ((BYTE)((((unsigned short)(&EmptyStringDescriptor)) >> 8) & 0xff)) ;
3725
                            SUDPTRL = ((BYTE)(&EmptyStringDescriptor));
3726
                            break;
3727
                        }
3728
                    break;
3729
                case 0x06:              // device qualifier
3730
#line 235 "../../include/ztex-isr.h"
3731
                    SUDPTRH = ((BYTE)((((unsigned short)(&DeviceQualifierDescriptor)) >> 8) & 0xff)) ;
3732
                    SUDPTRL = ((BYTE)(&DeviceQualifierDescriptor));
3733
                    break;
3734
                case 0x07:              // other speed configuration
3735
#line 239 "../../include/ztex-isr.h"
3736
                    if (USBCS & 128) {
3737
                        SUDPTRH = ((BYTE)((((unsigned short)(&FullSpeedConfigDescriptor)) >> 8) & 0xff)) ;
3738
                        SUDPTRL = ((BYTE)(&FullSpeedConfigDescriptor));
3739
                    }
3740
                    else {
3741
                        SUDPTRH = ((BYTE)((((unsigned short)(&HighSpeedConfigDescriptor)) >> 8) & 0xff)) ;
3742
                        SUDPTRL = ((BYTE)(&HighSpeedConfigDescriptor));
3743
                    }
3744
                    break;
3745
                default:
3746
                    EP0CS |= 0x01;      // set stall, unknown descriptor
3747
#line 250 "../../include/ztex-isr.h"
3748
            }
3749
            break;
3750
        case 0x07:                      // set descriptor
3751
#line 253 "../../include/ztex-isr.h"
3752
            break;
3753
        case 0x08:                      // get configuration
3754
            EP0BUF[0] = 0;                // only one configuration
3755
#line 256 "../../include/ztex-isr.h"
3756
            EP0BCH = 0;
3757
            EP0BCL = 1;
3758
            break;
3759
        case 0x09:                      // set configuration
3760
#line 260 "../../include/ztex-isr.h"
3761
            resetToggleData();
3762
            break;                      // do nothing since we have only one configuration
3763
        case 0x0a:                      // get alternate setting for an interface
3764
            EP0BUF[0] = 0;                // only one alternate setting
3765
#line 264 "../../include/ztex-isr.h"
3766
            EP0BCH = 0;
3767
            EP0BCL = 1;
3768
            break;
3769
        case 0x0b:                      // set alternate setting for an interface
3770
#line 268 "../../include/ztex-isr.h"
3771
            resetToggleData();
3772
            break;                      // do nothing since we have only on alternate setting
3773
        case 0x0c:                      // sync frame
3774
#line 271 "../../include/ztex-isr.h"
3775
            if ( SETUPDAT[0] == 0x82 ) {
3776
                ISOFRAME_COUNTER[ ((SETUPDAT[4] >> 1)-1) & 3 ] = 0;
3777
                EP0BUF[0] = USBFRAMEL;   // use current frame as sync frame, i hope that works
3778
#line 274 "../../include/ztex-isr.h"
3779
                EP0BUF[1] = USBFRAMEH;
3780
                EP0BCH = 0;
3781
                EP0BCL = 2;
3782
            }
3783
            break;                      // do nothing since we have only on alternate setting
3784
#line 279 "../../include/ztex-isr.h"
3785
 
3786
    }
3787
 
3788
    // vendor request and commands
3789
#line 283 "../../include/ztex-isr.h"
3790
    switch ( bmRequestType ) {
3791
        case 0xc0:                                      // vendor request 
3792
#line 285 "../../include/ztex-isr.h"
3793
            ep0_payload_remaining = (SETUPDAT[7] << 8) | SETUPDAT[6];
3794
            ep0_payload_update();
3795
 
3796
            switch ( bRequest ) {
3797
                case 0x22:                              // get ZTEX descriptor
3798
#line 290 "../../include/ztex-isr.h"
3799
                    SUDPTRCTL = 0;
3800
                    EP0BCH = 0;
3801
                    EP0BCL = 40;
3802
                    SUDPTRH = ((BYTE)((((unsigned short)(0x06c)) >> 8) & 0xff)) ;
3803
                    SUDPTRL = ((BYTE)(0x06c));
3804
                    break;
3805
#line 99 "../../include/ztex-conf.h"
3806
 
3807
case 0x38:
3808
                                // read from EEPROM
3809
    eeprom_addr =  (SETUPDAT[3] << 8) | SETUPDAT[2];    // Address
3810
#line 219 "../../include/ztex-eeprom.h"
3811
    EP0BCH = 0;
3812
    EP0BCL = eeprom_read_ep0();
3813
#line 101 "../../include/ztex-conf.h"
3814
 
3815
    break;
3816
#line 99 "../../include/ztex-conf.h"
3817
 
3818
case 0x3A:
3819
                                // EEPROM state
3820
#line 247 "../../include/ztex-eeprom.h"
3821
    EP0BUF[0] = ((BYTE)(eeprom_write_bytes));
3822
    EP0BUF[1] = ((BYTE)((((unsigned short)(eeprom_write_bytes)) >> 8) & 0xff)) ;
3823
    EP0BUF[2] = eeprom_write_checksum;
3824
    EP0BUF[3] = eeprom_select(0xA2,0,1);         // 1 means busy or error
3825
#line 251 "../../include/ztex-eeprom.h"
3826
    EP0BCH = 0;
3827
    EP0BCL = 4;
3828
#line 101 "../../include/ztex-conf.h"
3829
 
3830
    break;
3831
#line 99 "../../include/ztex-conf.h"
3832
 
3833
case 0x3B:
3834
                                // read from EEPROM
3835
    mac_eeprom_addr =  SETUPDAT[2];                     // Address
3836
#line 368 "../../include/ztex-eeprom.h"
3837
    EP0BCH = 0;
3838
    EP0BCL = mac_eeprom_read_ep0();
3839
#line 101 "../../include/ztex-conf.h"
3840
 
3841
    break;
3842
#line 99 "../../include/ztex-conf.h"
3843
 
3844
case 0x3D:
3845
                                // EEPROM state
3846
    EP0BUF[0] = eeprom_select(0xA6,0,1);  // 1 means busy or error
3847
#line 390 "../../include/ztex-eeprom.h"
3848
    EP0BCH = 0;
3849
    EP0BCL = 1;
3850
#line 101 "../../include/ztex-conf.h"
3851
 
3852
    break;
3853
#line 99 "../../include/ztex-conf.h"
3854
 
3855
case 0x40:
3856
#line 645 "../../include/ztex-flash2.h"
3857
 
3858
    if ( flash_ec == 0 && IOA3 == 0 ) {
3859
        flash_ec = 4;
3860
    }
3861
#line 120 "../../include/ztex-utils.h"
3862
    {
3863
        AUTOPTRL1=((BYTE)(&(flash_enabled)));
3864
        AUTOPTRH1=((BYTE)((((unsigned short)(&(flash_enabled)) >> 8) & 0xff)) );
3865
        AUTOPTRL2=((BYTE)(&(EP0BUF)));
3866
        AUTOPTRH2=((BYTE)((((unsigned short)(&(EP0BUF)) >> 8) & 0xff)) );
3867
        __asm
3868
                push    ar2
3869
                mov     r2,#(8);
3870
                lcall   _MEM_COPY1_int
3871
                pop     ar2
3872
        __endasm;
3873
#line 649 "../../include/ztex-flash2.h"
3874
}
3875
    EP0BCH = 0;
3876
    EP0BCL = 8;
3877
#line 101 "../../include/ztex-conf.h"
3878
 
3879
    break;
3880
#line 99 "../../include/ztex-conf.h"
3881
 
3882
case 0x41:
3883
                        // read data
3884
#line 671 "../../include/ztex-flash2.h"
3885
    ep0_read_mode = SETUPDAT[5];
3886
    if ( (ep0_read_mode==0) && flash_read_init((SETUPDAT[3] << 8) | SETUPDAT[2]) ) {
3887
#line 136 "../../include/ztex-conf.h"
3888
        {
3889
    EP0CS |= 0x01;      // set stall
3890
#line 138 "../../include/ztex-conf.h"
3891
    ep0_payload_remaining = 0;
3892
    break;
3893
#line 673 "../../include/ztex-flash2.h"
3894
}
3895
    }
3896
    spi_read_ep0();
3897
    EP0BCH = 0;
3898
    EP0BCL = ep0_payload_transfer;
3899
#line 101 "../../include/ztex-conf.h"
3900
 
3901
    break;
3902
#line 99 "../../include/ztex-conf.h"
3903
 
3904
case 0x43:
3905
#line 717 "../../include/ztex-flash2.h"
3906
 
3907
#line 120 "../../include/ztex-utils.h"
3908
    {
3909
        AUTOPTRL1=((BYTE)(&(flash_ec)));
3910
        AUTOPTRH1=((BYTE)((((unsigned short)(&(flash_ec)) >> 8) & 0xff)) );
3911
        AUTOPTRL2=((BYTE)(&(EP0BUF)));
3912
        AUTOPTRH2=((BYTE)((((unsigned short)(&(EP0BUF)) >> 8) & 0xff)) );
3913
        __asm
3914
                push    ar2
3915
                mov     r2,#(10);
3916
                lcall   _MEM_COPY1_int
3917
                pop     ar2
3918
        __endasm;
3919
#line 718 "../../include/ztex-flash2.h"
3920
}
3921
    EP0BCH = 0;
3922
    EP0BCL = 10;
3923
#line 101 "../../include/ztex-conf.h"
3924
 
3925
    break;
3926
#line 99 "../../include/ztex-conf.h"
3927
 
3928
case 0x30:
3929
                // get FPGA state
3930
#line 120 "../../include/ztex-utils.h"
3931
    {
3932
        AUTOPTRL1=((BYTE)(&(fpga_checksum)));
3933
        AUTOPTRH1=((BYTE)((((unsigned short)(&(fpga_checksum)) >> 8) & 0xff)) );
3934
        AUTOPTRL2=((BYTE)(&(EP0BUF+1)));
3935
        AUTOPTRH2=((BYTE)((((unsigned short)(&(EP0BUF+1)) >> 8) & 0xff)) );
3936
        __asm
3937
                push    ar2
3938
                mov     r2,#(7);
3939
                lcall   _MEM_COPY1_int
3940
                pop     ar2
3941
        __endasm;
3942
#line 142 "../../include/ztex-fpga7.h"
3943
}
3944
 
3945
    OEE = (OEE & ~64) | 128;
3946
    if ( IOE & 64 )  {
3947
        EP0BUF[0] = 0;                    // FPGA configured 
3948
#line 147 "../../include/ztex-fpga7.h"
3949
    }
3950
    else {
3951
        EP0BUF[0] = 1;                   // FPGA unconfigured 
3952
        reset_fpga();                   // prepare FPGA for configuration
3953
#line 151 "../../include/ztex-fpga7.h"
3954
     }
3955
//    EP0BUF[8] = 0;                    // bit order for bitstream in Flash memory: non-swapped
3956
    EP0BUF[8] = 1;                      // bit order for bitstream in Flash memory: swapped
3957
#line 154 "../../include/ztex-fpga7.h"
3958
 
3959
    EP0BCH = 0;
3960
    EP0BCL = 9;
3961
#line 101 "../../include/ztex-conf.h"
3962
 
3963
    break;
3964
#line 296 "../../include/ztex-isr.h"
3965
 
3966
                default:
3967
                    EP0CS |= 0x01;                      // set stall, unknown request
3968
#line 299 "../../include/ztex-isr.h"
3969
            }
3970
            break;
3971
        case 0x40:                                      // vendor command
3972
#line 302 "../../include/ztex-isr.h"
3973
            /* vendor commands may overlap if they are send without pause. To avoid
3974
               synchronization problems the setup sequences are executed in EP0OUT_ISR, i.e.
3975
               after the first packet of payload data received. */
3976
            if ( SETUPDAT[7]!=0 || SETUPDAT[6]!=0 ) {
3977
                ep0_vendor_cmd_setup = 1;
3978
                EP0BCL = 0;
3979
                EXIF &= ~16;                    // clear main USB interrupt flag
3980
                USBIRQ = 1;                     // clear SUADV IRQ
3981
                return;                                 // don't clear HSNAK bit. This is done after the command has completed
3982
#line 311 "../../include/ztex-isr.h"
3983
            }
3984
            ep0_vendor_cmd_su();                        // setup sequences of vendor command with no payload ara executed immediately
3985
#line 313 "../../include/ztex-isr.h"
3986
            EP0BCL = 0;
3987
            break;
3988
    }
3989
 
3990
    EXIF &= ~16;                                        // clear main USB interrupt flag
3991
    USBIRQ = 1;                                 // clear SUADV IRQ
3992
    EP0CS |= 0x80;                                      // clear the HSNAK bit
3993
#line 320 "../../include/ztex-isr.h"
3994
}
3995
 
3996
/* *********************************************************************
3997
   ***** SOF_ISR *******************************************************
3998
   ********************************************************************* */
3999
void SOF_ISR() __interrupt
4000
{
4001
        EXIF &= ~16;
4002
        USBIRQ = 2;
4003
}
4004
 
4005
/* *********************************************************************
4006
   ***** SUTOK_ISR *****************************************************
4007
   ********************************************************************* */
4008
void SUTOK_ISR() __interrupt
4009
{
4010
        EXIF &= ~16;
4011
        USBIRQ = 4;
4012
}
4013
 
4014
/* *********************************************************************
4015
   ***** SUSP_ISR ******************************************************
4016
   ********************************************************************* */
4017
void SUSP_ISR() __interrupt
4018
{
4019
        EXIF &= ~16;
4020
        USBIRQ = 8;
4021
}
4022
 
4023
/* *********************************************************************
4024
   ***** URES_ISR ******************************************************
4025
   ********************************************************************* */
4026
void URES_ISR() __interrupt
4027
{
4028
        EXIF &= ~16;
4029
        USBIRQ = 16;
4030
}
4031
 
4032
/* *********************************************************************
4033
   ***** HSGRANT_ISR ***************************************************
4034
   ********************************************************************* */
4035
void HSGRANT_ISR() __interrupt
4036
{
4037
        EXIF &= ~16;
4038
//        while ( USBIRQ & bmBIT5 )
4039
#line 365 "../../include/ztex-isr.h"
4040
            USBIRQ = 32;
4041
}
4042
 
4043
/* *********************************************************************
4044
   ***** EP0ACK_ISR ****************************************************
4045
   ********************************************************************* */
4046
void EP0ACK_ISR() __interrupt
4047
{
4048
        EXIF &= ~16;    // clear USB interrupt flag
4049
        USBIRQ = 64;    // clear EP0ACK IRQ
4050
#line 375 "../../include/ztex-isr.h"
4051
}
4052
 
4053
/* *********************************************************************
4054
   ***** EP0IN_ISR *****************************************************
4055
   ********************************************************************* */
4056
static void EP0IN_ISR () __interrupt
4057
{
4058
    EUSB = 0;                    // block all USB interrupts
4059
#line 383 "../../include/ztex-isr.h"
4060
    ep0_payload_update();
4061
    switch ( ep0_prev_setup_request ) {
4062
#line 104 "../../include/ztex-conf.h"
4063
 
4064
case 0x38:
4065
#line 221 "../../include/ztex-eeprom.h"
4066
 
4067
    EP0BCH = 0;
4068
    EP0BCL = eeprom_read_ep0();
4069
#line 106 "../../include/ztex-conf.h"
4070
 
4071
    break;
4072
#line 104 "../../include/ztex-conf.h"
4073
 
4074
case 0x3A:
4075
 
4076
    break;
4077
#line 104 "../../include/ztex-conf.h"
4078
 
4079
case 0x3B:
4080
#line 370 "../../include/ztex-eeprom.h"
4081
 
4082
    EP0BCH = 0;
4083
    EP0BCL = mac_eeprom_read_ep0();
4084
#line 106 "../../include/ztex-conf.h"
4085
 
4086
    break;
4087
#line 104 "../../include/ztex-conf.h"
4088
 
4089
case 0x3D:
4090
 
4091
    break;
4092
#line 104 "../../include/ztex-conf.h"
4093
 
4094
case 0x40:
4095
#line 652 "../../include/ztex-flash2.h"
4096
 
4097
#line 106 "../../include/ztex-conf.h"
4098
 
4099
    break;
4100
#line 104 "../../include/ztex-conf.h"
4101
 
4102
case 0x41:
4103
#line 678 "../../include/ztex-flash2.h"
4104
 
4105
    if ( ep0_payload_transfer != 0 ) {
4106
        flash_ec = 0;
4107
        spi_read_ep0();
4108
    }
4109
    EP0BCH = 0;
4110
    EP0BCL = ep0_payload_transfer;
4111
#line 106 "../../include/ztex-conf.h"
4112
 
4113
    break;
4114
#line 104 "../../include/ztex-conf.h"
4115
 
4116
case 0x43:
4117
#line 721 "../../include/ztex-flash2.h"
4118
 
4119
#line 106 "../../include/ztex-conf.h"
4120
 
4121
    break;
4122
#line 104 "../../include/ztex-conf.h"
4123
 
4124
case 0x30:
4125
 
4126
    break;
4127
#line 385 "../../include/ztex-isr.h"
4128
 
4129
        default:
4130
            EP0BCH = 0;
4131
            EP0BCL = 0;
4132
    }
4133
    EXIF &= ~16;                // clear USB interrupt flag
4134
    EPIRQ = 1;          // clear EP0IN IRQ
4135
#line 392 "../../include/ztex-isr.h"
4136
    EUSB = 1;
4137
}
4138
 
4139
/* *********************************************************************
4140
   ***** EP0OUT_ISR ****************************************************
4141
   ********************************************************************* */
4142
static void EP0OUT_ISR () __interrupt
4143
{
4144
    EUSB = 0;                    // block all USB interrupts
4145
#line 401 "../../include/ztex-isr.h"
4146
    if ( ep0_vendor_cmd_setup ) {
4147
        ep0_vendor_cmd_setup = 0;
4148
        ep0_payload_remaining = (SETUPDAT[7] << 8) | SETUPDAT[6];
4149
        ep0_vendor_cmd_su();
4150
    }
4151
 
4152
    ep0_payload_update();
4153
 
4154
    switch ( ep0_prev_setup_request ) {
4155
#line 127 "../../include/ztex-conf.h"
4156
 
4157
case 0x39:
4158
#line 239 "../../include/ztex-eeprom.h"
4159
 
4160
    eeprom_write_ep0(EP0BCL);
4161
#line 129 "../../include/ztex-conf.h"
4162
 
4163
    break;
4164
#line 127 "../../include/ztex-conf.h"
4165
 
4166
case 0x3C:
4167
#line 381 "../../include/ztex-eeprom.h"
4168
 
4169
    mac_eeprom_write(EP0BUF, mac_eeprom_addr, EP0BCL);
4170
#line 129 "../../include/ztex-conf.h"
4171
 
4172
    break;
4173
#line 127 "../../include/ztex-conf.h"
4174
 
4175
case 0x42:
4176
#line 702 "../../include/ztex-flash2.h"
4177
 
4178
    if ( ep0_payload_transfer != 0 ) {
4179
        flash_ec = 0;
4180
        spi_send_ep0();
4181
        if ( flash_ec != 0 ) {
4182
            spi_deselect();
4183
#line 136 "../../include/ztex-conf.h"
4184
            {
4185
    EP0CS |= 0x01;      // set stall
4186
#line 138 "../../include/ztex-conf.h"
4187
    ep0_payload_remaining = 0;
4188
    break;
4189
#line 708 "../../include/ztex-flash2.h"
4190
}
4191
        }
4192
    }
4193
#line 129 "../../include/ztex-conf.h"
4194
 
4195
    break;
4196
#line 127 "../../include/ztex-conf.h"
4197
 
4198
case 0x31:
4199
 
4200
    break;
4201
#line 127 "../../include/ztex-conf.h"
4202
 
4203
case 0x32:
4204
#line 210 "../../include/ztex-fpga7.h"
4205
 
4206
    fpga_send_ep0();
4207
#line 129 "../../include/ztex-conf.h"
4208
 
4209
    break;
4210
#line 410 "../../include/ztex-isr.h"
4211
 
4212
    }
4213
 
4214
    EP0BCL = 0;
4215
 
4216
    EXIF &= ~16;                // clear main USB interrupt flag
4217
    EPIRQ = 2;          // clear EP0OUT IRQ
4218
#line 417 "../../include/ztex-isr.h"
4219
    if ( ep0_payload_remaining == 0 ) {
4220
        EP0CS |= 0x80;          // clear the HSNAK bit
4221
#line 419 "../../include/ztex-isr.h"
4222
    }
4223
    EUSB = 1;
4224
}
4225
 
4226
 
4227
/* *********************************************************************
4228
   ***** EP1IN_ISR *****************************************************
4229
   ********************************************************************* */
4230
void EP1IN_ISR() __interrupt
4231
{
4232
    EXIF &= ~16;
4233
    EPIRQ = 4;
4234
 
4235
}
4236
 
4237
/* *********************************************************************
4238
   ***** EP1OUT_ISR ****************************************************
4239
   ********************************************************************* */
4240
void EP1OUT_ISR() __interrupt
4241
{
4242
    EXIF &= ~16;
4243
    EPIRQ = 8;
4244
}
4245
 
4246
/* *********************************************************************
4247
   ***** EP2_ISR *******************************************************
4248
   ********************************************************************* */
4249
void EP2_ISR() __interrupt
4250
{
4251
    EXIF &= ~16;
4252
    EPIRQ = 16;
4253
}
4254
 
4255
/* *********************************************************************
4256
   ***** EP4_ISR *******************************************************
4257
   ********************************************************************* */
4258
void EP4_ISR() __interrupt
4259
{
4260
    EXIF &= ~16;
4261
    EPIRQ = 32;
4262
}
4263
 
4264
/* *********************************************************************
4265
   ***** EP6_ISR *******************************************************
4266
   ********************************************************************* */
4267
void EP6_ISR() __interrupt
4268
{
4269
    EXIF &= ~16;
4270
    EPIRQ = 64;
4271
}
4272
 
4273
/* *********************************************************************
4274
   ***** EP8_ISR *******************************************************
4275
   ********************************************************************* */
4276
void EP8_ISR() __interrupt
4277
{
4278
    EXIF &= ~16;
4279
    EPIRQ = 128;
4280
}
4281
 
4282
#line 262 "../../include/ztex.h"
4283
 
4284
 
4285
 
4286
/* *********************************************************************
4287
   ***** mac_eeprom_init ***********************************************
4288
   ********************************************************************* */
4289
#line 269 "../../include/ztex.h"
4290
void mac_eeprom_init ( ) {
4291
    BYTE b,c,d;
4292
    __xdata BYTE buf[5];
4293
    __code char hexdigits[] = "0123456789ABCDEF";
4294
 
4295
    mac_eeprom_read ( buf, 0, 3 );       // read signature
4296
#line 275 "../../include/ztex.h"
4297
    if ( buf[0]==67 && buf[1]==68 && buf[2]==48 ) {
4298
        config_data_valid = 1;
4299
        mac_eeprom_read ( SN_STRING, 16, 10 );  // copy serial number
4300
#line 278 "../../include/ztex.h"
4301
    }
4302
    else {
4303
        config_data_valid = 0;
4304
    }
4305
 
4306
    for (b=0; b<10; b++) {       // abort if SN != "0000000000"
4307
#line 284 "../../include/ztex.h"
4308
        if ( SN_STRING[b] != 48 )
4309
            return;
4310
    }
4311
 
4312
    mac_eeprom_read ( buf, 0xfb, 5 );   // read the last 5 MAC digits
4313
#line 289 "../../include/ztex.h"
4314
 
4315
    c=0;
4316
    for (b=0; b<5; b++) {        // convert to MAC to SN string
4317
#line 292 "../../include/ztex.h"
4318
        d = buf[b];
4319
        SN_STRING[c] = hexdigits[d>>4];
4320
        c++;
4321
        SN_STRING[c] = hexdigits[d & 15];
4322
        c++;
4323
    }
4324
}
4325
#line 300 "../../include/ztex.h"
4326
 
4327
 
4328
/* *********************************************************************
4329
   ***** init_USB ******************************************************
4330
   ********************************************************************* */
4331
#line 331 "../../include/ztex.h"
4332
 
4333
#line 343 "../../include/ztex.h"
4334
 
4335
 
4336
void init_USB ()
4337
{
4338
    USBCS |= 8;
4339
 
4340
    CPUCS = 16 | 2;
4341
    wait(2);
4342
    CKCON &= ~7;
4343
 
4344
#line 380 "../../include/ztex.h"
4345
    init_fpga();
4346
#line 382 "../../include/ztex.h"
4347
 
4348
#line 104 "../../include/ztex-fpga-flash2.h"
4349
 
4350
fpga_flash_result= 255;
4351
#line 383 "../../include/ztex.h"
4352
 
4353
 
4354
    EA = 0;
4355
    EUSB = 0;
4356
 
4357
#line 122 "../../include/ezintavecs.h"
4358
    {
4359
    INT8VEC_USB.op=0x02;
4360
    INT8VEC_USB.addrH = 0x01;
4361
    INT8VEC_USB.addrL = 0xb8;
4362
    INTSETUP |= 8;
4363
#line 388 "../../include/ztex.h"
4364
}
4365
 
4366
#line 114 "../../include/ezintavecs.h"
4367
    {
4368
    INTVEC_SUDAV.op=0x02;
4369
    INTVEC_SUDAV.addrH=((unsigned short)(& SUDAV_ISR)) >> 8;
4370
    INTVEC_SUDAV.addrL=(unsigned short)(& SUDAV_ISR);
4371
#line 390 "../../include/ztex.h"
4372
}
4373
#line 114 "../../include/ezintavecs.h"
4374
    {
4375
    INTVEC_SOF.op=0x02;
4376
    INTVEC_SOF.addrH=((unsigned short)(& SOF_ISR)) >> 8;
4377
    INTVEC_SOF.addrL=(unsigned short)(& SOF_ISR);
4378
#line 391 "../../include/ztex.h"
4379
}
4380
#line 114 "../../include/ezintavecs.h"
4381
    {
4382
    INTVEC_SUTOK.op=0x02;
4383
    INTVEC_SUTOK.addrH=((unsigned short)(& SUTOK_ISR)) >> 8;
4384
    INTVEC_SUTOK.addrL=(unsigned short)(& SUTOK_ISR);
4385
#line 392 "../../include/ztex.h"
4386
}
4387
#line 114 "../../include/ezintavecs.h"
4388
    {
4389
    INTVEC_SUSPEND.op=0x02;
4390
    INTVEC_SUSPEND.addrH=((unsigned short)(& SUSP_ISR)) >> 8;
4391
    INTVEC_SUSPEND.addrL=(unsigned short)(& SUSP_ISR);
4392
#line 393 "../../include/ztex.h"
4393
}
4394
#line 114 "../../include/ezintavecs.h"
4395
    {
4396
    INTVEC_USBRESET.op=0x02;
4397
    INTVEC_USBRESET.addrH=((unsigned short)(& URES_ISR)) >> 8;
4398
    INTVEC_USBRESET.addrL=(unsigned short)(& URES_ISR);
4399
#line 394 "../../include/ztex.h"
4400
}
4401
#line 114 "../../include/ezintavecs.h"
4402
    {
4403
    INTVEC_HISPEED.op=0x02;
4404
    INTVEC_HISPEED.addrH=((unsigned short)(& HSGRANT_ISR)) >> 8;
4405
    INTVEC_HISPEED.addrL=(unsigned short)(& HSGRANT_ISR);
4406
#line 395 "../../include/ztex.h"
4407
}
4408
#line 114 "../../include/ezintavecs.h"
4409
    {
4410
    INTVEC_EP0ACK.op=0x02;
4411
    INTVEC_EP0ACK.addrH=((unsigned short)(& EP0ACK_ISR)) >> 8;
4412
    INTVEC_EP0ACK.addrL=(unsigned short)(& EP0ACK_ISR);
4413
#line 396 "../../include/ztex.h"
4414
}
4415
 
4416
#line 114 "../../include/ezintavecs.h"
4417
    {
4418
    INTVEC_EP0IN.op=0x02;
4419
    INTVEC_EP0IN.addrH=((unsigned short)(& EP0IN_ISR)) >> 8;
4420
    INTVEC_EP0IN.addrL=(unsigned short)(& EP0IN_ISR);
4421
#line 398 "../../include/ztex.h"
4422
}
4423
#line 114 "../../include/ezintavecs.h"
4424
    {
4425
    INTVEC_EP0OUT.op=0x02;
4426
    INTVEC_EP0OUT.addrH=((unsigned short)(& EP0OUT_ISR)) >> 8;
4427
    INTVEC_EP0OUT.addrL=(unsigned short)(& EP0OUT_ISR);
4428
#line 399 "../../include/ztex.h"
4429
}
4430
#line 114 "../../include/ezintavecs.h"
4431
    {
4432
    INTVEC_EP1IN.op=0x02;
4433
    INTVEC_EP1IN.addrH=((unsigned short)(& EP1IN_ISR)) >> 8;
4434
    INTVEC_EP1IN.addrL=(unsigned short)(& EP1IN_ISR);
4435
#line 400 "../../include/ztex.h"
4436
}
4437
#line 114 "../../include/ezintavecs.h"
4438
    {
4439
    INTVEC_EP1OUT.op=0x02;
4440
    INTVEC_EP1OUT.addrH=((unsigned short)(& EP1OUT_ISR)) >> 8;
4441
    INTVEC_EP1OUT.addrL=(unsigned short)(& EP1OUT_ISR);
4442
#line 401 "../../include/ztex.h"
4443
}
4444
#line 114 "../../include/ezintavecs.h"
4445
    {
4446
    INTVEC_EP2.op=0x02;
4447
    INTVEC_EP2.addrH=((unsigned short)(& EP2_ISR)) >> 8;
4448
    INTVEC_EP2.addrL=(unsigned short)(& EP2_ISR);
4449
#line 402 "../../include/ztex.h"
4450
}
4451
#line 114 "../../include/ezintavecs.h"
4452
    {
4453
    INTVEC_EP4.op=0x02;
4454
    INTVEC_EP4.addrH=((unsigned short)(& EP4_ISR)) >> 8;
4455
    INTVEC_EP4.addrL=(unsigned short)(& EP4_ISR);
4456
#line 403 "../../include/ztex.h"
4457
}
4458
#line 114 "../../include/ezintavecs.h"
4459
    {
4460
    INTVEC_EP6.op=0x02;
4461
    INTVEC_EP6.addrH=((unsigned short)(& EP6_ISR)) >> 8;
4462
    INTVEC_EP6.addrL=(unsigned short)(& EP6_ISR);
4463
#line 404 "../../include/ztex.h"
4464
}
4465
#line 114 "../../include/ezintavecs.h"
4466
    {
4467
    INTVEC_EP8.op=0x02;
4468
    INTVEC_EP8.addrH=((unsigned short)(& EP8_ISR)) >> 8;
4469
    INTVEC_EP8.addrL=(unsigned short)(& EP8_ISR);
4470
#line 405 "../../include/ztex.h"
4471
}
4472
 
4473
    EXIF &= ~16;
4474
    USBIRQ = 0x7f;
4475
    USBIE |= 0x7f;
4476
    EPIRQ = 0xff;
4477
    EPIE = 0xff;
4478
 
4479
    EUSB = 1;
4480
    EA = 1;
4481
 
4482
#line 333 "../../include/ztex.h"
4483
        EP1INCFG = 128 | 32;
4484
#line 41 "../../include/ezregs.h"
4485
        __asm
4486
        nop
4487
        nop
4488
        nop
4489
        nop
4490
    __endasm;
4491
#line 341 "../../include/ztex.h"
4492
 
4493
#line 416 "../../include/ztex.h"
4494
 
4495
#line 333 "../../include/ztex.h"
4496
        EP1OUTCFG = 128 | 32;
4497
#line 41 "../../include/ezregs.h"
4498
        __asm
4499
        nop
4500
        nop
4501
        nop
4502
        nop
4503
    __endasm;
4504
#line 341 "../../include/ztex.h"
4505
 
4506
#line 417 "../../include/ztex.h"
4507
 
4508
#line 305 "../../include/ztex.h"
4509
        EP2CFG =
4510
#line 311 "../../include/ztex.h"
4511
 
4512
#line 328 "../../include/ztex.h"
4513
        ;
4514
#line 41 "../../include/ezregs.h"
4515
        __asm
4516
        nop
4517
        nop
4518
        nop
4519
        nop
4520
    __endasm;
4521
#line 329 "../../include/ztex.h"
4522
 
4523
#line 418 "../../include/ztex.h"
4524
 
4525
#line 305 "../../include/ztex.h"
4526
        EP4CFG =
4527
#line 311 "../../include/ztex.h"
4528
 
4529
#line 328 "../../include/ztex.h"
4530
        ;
4531
#line 41 "../../include/ezregs.h"
4532
        __asm
4533
        nop
4534
        nop
4535
        nop
4536
        nop
4537
    __endasm;
4538
#line 329 "../../include/ztex.h"
4539
 
4540
#line 419 "../../include/ztex.h"
4541
 
4542
#line 305 "../../include/ztex.h"
4543
        EP6CFG =
4544
#line 311 "../../include/ztex.h"
4545
 
4546
#line 328 "../../include/ztex.h"
4547
        ;
4548
#line 41 "../../include/ezregs.h"
4549
        __asm
4550
        nop
4551
        nop
4552
        nop
4553
        nop
4554
    __endasm;
4555
#line 329 "../../include/ztex.h"
4556
 
4557
#line 420 "../../include/ztex.h"
4558
 
4559
#line 305 "../../include/ztex.h"
4560
        EP8CFG =
4561
#line 311 "../../include/ztex.h"
4562
 
4563
#line 328 "../../include/ztex.h"
4564
        ;
4565
#line 41 "../../include/ezregs.h"
4566
        __asm
4567
        nop
4568
        nop
4569
        nop
4570
        nop
4571
    __endasm;
4572
#line 329 "../../include/ztex.h"
4573
 
4574
#line 421 "../../include/ztex.h"
4575
 
4576
 
4577
#line 432 "../../include/ztex.h"
4578
 
4579
#line 434 "../../include/ztex.h"
4580
    flash_init();
4581
    if ( !flash_enabled ) {
4582
        wait(250);
4583
        flash_init();
4584
    }
4585
#line 447 "../../include/ztex.h"
4586
    mac_eeprom_init();
4587
#line 453 "../../include/ztex.h"
4588
    fpga_configure_from_flash_init();
4589
#line 455 "../../include/ztex.h"
4590
 
4591
    USBCS |= 128 | 2;
4592
    wait(10);
4593
//    wait(250);
4594
#line 459 "../../include/ztex.h"
4595
    USBCS &= ~8;
4596
}
4597
 
4598
 
4599
#line 33 "default.c"
4600
 
4601
 
4602
void main(void)
4603
{
4604
    init_USB();
4605
 
4606
    if ( config_data_valid ) {
4607
        mac_eeprom_read ( (__xdata BYTE*) (productString+20), 6, 1 );
4608
    }
4609
 
4610
    while (1) { }                                       //  twiddle thumbs
4611
#line 44 "default.c"
4612
}
4613
 

powered by: WebSVN 2.1.0

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