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

Subversion Repositories usb_fpga_1_2

[/] [usb_fpga_1_2/] [trunk/] [include/] [ztex-descriptors.h] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   ZTEX Firmware Kit for EZ-USB Microcontrollers
3
   Copyright (C) 2008-2009 ZTEX e.K.
4
   http://www.ztex.de
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License version 3 as
8
   published by the Free Software Foundation.
9
 
10
   This program is distributed in the hope that it will be useful, but
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
   General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, see http://www.gnu.org/licenses/.
17
!*/
18
 
19
/*
20
   Defines the USB descriptors
21
*/
22
 
23
#ifndef[ZTEX_DESCRIPTORS_H]
24
#define[ZTEX_DESCRIPTORS_H]
25
 
26
#define[ZTEX_DESCRIPTOR_OFFS][0x06c]
27
#define[ZTEX_DESCRIPTOR_LEN][40]
28
 
29
xdata at ZTEX_DESCRIPTOR_OFFS BYTE ZTEX_DESCRIPTOR;
30
 
31
/* ZTEX descriptor version. Must be 1. */
32
xdata at ZTEX_DESCRIPTOR_OFFS+1 BYTE ZTEX_DESCRIPTOR_VERSION;
33
 
34
/* Must not be modified, ID="ZTEX" */
35
xdata at ZTEX_DESCRIPTOR_OFFS+2 BYTE ZTEXID[4];
36
 
37
/*
38
   Product ID and firmware compatibility information.
39
 
40
   A firmware can overwrite an installed one if
41
   if ( INSTALLED.PRODUCTID[0]==0 || PRODUCTID[0]==0 || INSTALLED.PRODUCTID[0]==PRODUCTID[0] ) &&
42
      ( INSTALLED.PRODUCTID[1]==0 || PRODUCTID[1]==0 || INSTALLED.PRODUCTID[1]==PRODUCTID[1] ) &&
43
      ( INSTALLED.PRODUCTID[2]==0 || PRODUCTID[2]==0 || INSTALLED.PRODUCTID[2]==PRODUCTID[2] ) &&
44
      ( INSTALLED.PRODUCTID[3]==0 || PRODUCTID[3]==0 || INSTALLED.PRODUCTID[3]==PRODUCTID[3] )
45
 
46
   Reserved Product ID's:
47
 
48
   0.0.0.0              // default Product ID (no product specified)
49
   1.*.*.*              // may be used for experimental purposes
50
   10.*.*.*             // used for ZTEX products
51
 
52
   Please contact me (http://www.ztex.de --> Impressum/Kontakt) if you want to register/reserve a Product ID (range).
53
*/
54
xdata at ZTEX_DESCRIPTOR_OFFS+6 BYTE PRODUCT_ID[4];
55
 
56
/* Firmware version, may be used to distinguish seveveral firmware versions */
57
xdata at ZTEX_DESCRIPTOR_OFFS+10 BYTE FW_VERSION;
58
 
59
/* Interface version. Must be 1. */
60
xdata at ZTEX_DESCRIPTOR_OFFS+11 BYTE INTERFACE_VERSION;
61
 
62
/*
63
    Standard interface capabilities:
64
        0.0  : EEPROM read/write, see ztex-eeprom.h
65
        0.1  : FPGA configuration, see ztex-fpga.h
66
*/
67
xdata at ZTEX_DESCRIPTOR_OFFS+12 BYTE INTERFACE_CAPABILITIES[6];
68
 
69
/* Space for settings which depends on PRODUCT_ID, e.g extra capabilities */
70
xdata at ZTEX_DESCRIPTOR_OFFS+18 BYTE MODULE_RESERVED[12];
71
 
72
/*
73
   Serial number string
74
   default: "0000000000"
75
   Should only be modified by the the firmware upload software
76
*/
77
xdata at ZTEX_DESCRIPTOR_OFFS+30 BYTE SN_STRING[10];
78
 
79
/* Are Vendor ID and Product ID defined? */
80
#ifndef[USB_VENDOR_ID]
81
#error[No USB Vendor ID defined (you may use the Cypress Vendor ID 0x04b4 (only !) for development purposes)]
82
#endif
83
 
84
#ifndef[USB_PRODUCT_ID]
85
#error[No USB Product ID defined (you may use the FX2 Product ID 0x8613 from Cypress (only !) during the development process)]
86
#endif
87
 
88
/* Prepare the Interfaces, i.e. check which interfaces are defined */
89
#define[CONFIGURE_INTERFACE(][);][
90
#define[CONFIG_INTERFACE$0]
91
#ifeq[EP1IN_INTERFACE][$0]
92
#elifeq[EP1OUT_INTERFACE][$0]
93
#elifeq[EP2_INTERFACE][$0]
94
#elifeq[EP4_INTERFACE][$0]
95
#elifeq[EP6_INTERFACE][$0]
96
#elifneq[EP8_INTERFACE][$0]
97
#udefine[CONFIG_INTERFACE$0]
98
#endif
99
#ifdef[CONFIG_INTERFACE$0]
100
//Interface $0: YES
101
#else
102
//Interface $0: NO
103
#endif]
104
 
105
CONFIGURE_INTERFACE(0);
106
CONFIGURE_INTERFACE(1);
107
CONFIGURE_INTERFACE(2);
108
CONFIGURE_INTERFACE(3);
109
 
110
/* define the ZTEX descriptor */
111
void abscode_identity() _naked
112
{
113
    _asm
114
    .area ABSCODE (ABS,CODE)
115
 
116
    .org ZTEX_DESCRIPTOR_OFFS
117
    .db ZTEX_DESCRIPTOR_LEN
118
 
119
    .org _ZTEX_DESCRIPTOR_VERSION
120
    .db 1
121
 
122
    .org _ZTEXID
123
    .ascii "ZTEX"
124
 
125
    .org _PRODUCT_ID
126
    .db PRODUCT_ID_0
127
    .db PRODUCT_ID_1
128
    .db PRODUCT_ID_2
129
    .db PRODUCT_ID_3
130
 
131
    .org _FW_VERSION
132
    .db FWVER
133
 
134
    .org _INTERFACE_VERSION
135
    .db 1
136
 
137
    .org _INTERFACE_CAPABILITIES
138
    .db 0
139
#ifdef[@CAPABILITY_EEPROM;]
140
#nolf
141
 + 1
142
#endif
143
#ifdef[@CAPABILITY_FPGA;]
144
#nolf
145
 + 2
146
#endif
147
    .db 0
148
    .db 0
149
    .db 0
150
    .db 0
151
    .db 0
152
 
153
    .org _MODULE_RESERVED
154
    .db MODULE_RESERVED_00
155
    .db MODULE_RESERVED_01
156
    .db MODULE_RESERVED_02
157
    .db MODULE_RESERVED_03
158
    .db MODULE_RESERVED_04
159
    .db MODULE_RESERVED_05
160
    .db MODULE_RESERVED_06
161
    .db MODULE_RESERVED_07
162
    .db MODULE_RESERVED_08
163
    .db MODULE_RESERVED_09
164
    .db MODULE_RESERVED_10
165
    .db MODULE_RESERVED_11
166
 
167
    .org _SN_STRING
168
    .ascii "0000000000"
169
 
170
    .area CSEG    (CODE)
171
    _endasm;
172
}
173
 
174
/* *********************************************************************
175
   ***** strings *******************************************************
176
   ********************************************************************* */
177
code char manufacturerString[] = MANUFACTURER_STRING;
178
code char productString[] = PRODUCT_STRING;
179
code char configurationString[] = CONFIGURATION_STRING;
180
 
181
 
182
/* *********************************************************************
183
   ***** descriptors ***************************************************
184
   ********************************************************************* */
185
#define[EP_DESCRIPTOR(][);][
186
                                // Endpoint $0 descriptor
187
        ,7                      // 0, Descriptor length
188
        ,5                      // 1, Descriptor type
189
#ifeq[$0][1IN]
190
        ,0x81                   // 2, direction=output, address=1
191
#elifeq[$0][1OUT]
192
        ,0x01                   // 2, direction=output, address=1
193
#elifeq[EP$0_DIR][IN]           
194
        ,0x80+$0                 // 2, direction=output, address=$0
195
#elifeq[EP$0_DIR][OUT]
196
        ,$0                      // 2, direction=input, address=$0
197
#else
198
#error[Invalid direction for endpoint $0 (`IN' or `ŇUT' expected)]
199
#endif
200
#ifeq[EP$0_TYPE][ISO]
201
        ,1                      // 3, ISO transferns
202
#elifeq[EP$0_TYPE][BULK]
203
        ,2                      // 3, BULK transferns
204
#elifeq[EP$0_TYPE][INT]
205
        ,3                      // 3, INT transferns
206
#else
207
#error[Invalid type for endpoint $0: `EP$0_TYPE' (`ISO', 'BULK' or `INT' expected)]
208
#endif 
209
#ifeq[EP$0_SIZE][64]            // to avoid stupid warnings
210
        ,64                     // 4, max. packet size (L) 
211
        ,0                       // 5, max. packet size (H) 
212
#else
213
#ifdef[HIGH_SPEED]
214
        ,EP$0_SIZE & 0xff        // 4, max. packet size (L) 
215
        ,EP$0_SIZE >> 8  // 5, max. packet size (H) 
216
#else
217
        ,64                     // 4, max. packet size (L) 
218
        ,0                       // 5, max. packet size (H) 
219
#endif  
220
#endif
221
#ifeq[EP$0_TYPE][ISO]
222
        ,1                      // 6, Polling interval
223
#else
224
        ,0                       // 6, Polling interval
225
#endif  
226
]
227
 
228
#define[INTERFACE_DESCRIPTOR(][);][
229
                // Interface $0 descriptor
230
        ,9      // 0, Descriptor length
231
        ,0x04   // 1, Descriptor type
232
        ,0       // 2, Zero-based index of this interface
233
#ifneq[$0][0]
234
#ifdef[CONFIG_INTERFACE0]
235
          +1
236
#endif
237
#ifneq[$0][1]
238
#ifdef[CONFIG_INTERFACE1]
239
          +1
240
#endif
241
#ifneq[$0][2]
242
#ifdef[CONFIG_INTERFACE2]
243
          +1
244
#endif
245
#endif
246
#endif
247
#endif
248
        ,0       // 3, Alternate setting 
249
        ,0       // 4, Number of end points 
250
#ifeq[EP1IN_INTERFACE][$0]
251
          +1
252
#endif    
253
#ifeq[EP1OUT_INTERFACE][$0]
254
          +1
255
#endif    
256
#ifeq[EP2_INTERFACE][$0]
257
          +1
258
#endif    
259
#ifeq[EP4_INTERFACE][$0]
260
          +1
261
#endif    
262
#ifeq[EP6_INTERFACE][$0]
263
          +1
264
#endif    
265
#ifeq[EP8_INTERFACE][$0]
266
          +1
267
#endif    
268
        ,0xff   // 5, Interface class
269
        ,0xff   // 6, Interface sub class
270
        ,0xff   // 7, Interface protocol
271
        ,0       // 8, Index of interface string descriptor
272
#ifeq[EP1IN_INTERFACE][$0]
273
         EP_DESCRIPTOR(1IN);
274
#endif    
275
#ifeq[EP1OUT_INTERFACE][$0]
276
         EP_DESCRIPTOR(1OUT);
277
#endif    
278
#ifeq[EP2_INTERFACE][$0]
279
         EP_DESCRIPTOR(2);
280
#endif    
281
#ifeq[EP4_INTERFACE][$0]
282
         EP_DESCRIPTOR(4);
283
#endif    
284
#ifeq[EP6_INTERFACE][$0]
285
         EP_DESCRIPTOR(6);
286
#endif    
287
#ifeq[EP8_INTERFACE][$0]
288
         EP_DESCRIPTOR(8);
289
#endif
290
]
291
 
292
#define[APPEND_PADBYTE(][);][code BYTE $0_PadByte[2-(sizeof($0) & 1)] = { 0 };]
293
 
294
#ifdef[PAD_BYTE]                // to ensure word alignment of the descriptors; PAD_BYTE is defined automatically by bmpsdcc script
295
code BYTE PadByte = 0;
296
#endif
297
 
298
code BYTE DeviceDescriptor[] =
299
    {
300
        18,     // 0, Descriptor length
301
        0x01,   // 1, Descriptor type
302
        0x00,   // 2, Specification Version (L)
303
        0x02,   // 3, Specification Version (H)
304
        0xff,   // 4, Device class
305
        0xff,   // 5, Device sub-class
306
        0xff,   // 6, Device protocol
307
        64,     // 7, Maximum packet size for EP0
308
        (USB_VENDOR_ID) & 255,  // 8, VENDOR_ID (L)
309
        (USB_VENDOR_ID) >> 8,   // 9, VENDOR_ID (H)
310
        (USB_PRODUCT_ID) & 255, // 10, PRODUCT_ID (L)
311
        (USB_PRODUCT_ID) >> 8,  // 11, PRODUCT_ID (H)
312
        0x00,   // 12, device release number (BCD, L)
313
        0x00,   // 13, device release number (BCD, H)
314
        1,      // 14, Manufacturer string index
315
        2,      // 15, Product string index
316
        3,      // 16, Serial number string index
317
        1       // 17, Number of configurations
318
    };
319
 
320
code BYTE DeviceQualifierDescriptor[] =
321
    {
322
        10,     // 0, Descriptor length
323
        0x06,   // 1, Decriptor type
324
        0x00,   // 2, Specification Version (L)
325
        0x02,   // 3, Specification Version (H)
326
        0xff,   // 4, Device class
327
        0xff,   // 5, Device sub-class
328
        0xff,   // 6, Device protocol
329
        64,     // 7, Maximum packet size (EP0?)
330
        1,      // 8, Number of configurations
331
        0,       // 9, Reserved, must be zero
332
    };
333
 
334
code BYTE HighSpeedConfigDescriptor[] =
335
    {
336
#define[HIGH_SPEED]
337
        9       // 0, Descriptor length
338
        ,0x02   // 1, Decriptor type
339
        ,sizeof(HighSpeedConfigDescriptor) & 0xff       // 2, Total length (LSB)
340
//      ,sizeof(HighSpeedConfigDescriptor) >> 8         // 3, Total length (MB)
341
        ,0                                               // 3, To avoid warnings, descriptor length will never exceed 255 bytes
342
        ,0       // 4, Number of Interfaces
343
#ifdef[CONFIG_INTERFACE0]
344
          +1
345
#endif
346
#ifdef[CONFIG_INTERFACE1]
347
          +1
348
#endif
349
#ifdef[CONFIG_INTERFACE2]
350
          +1
351
#endif
352
#ifdef[CONFIG_INTERFACE3]
353
          +1
354
#endif
355
 
356
        ,1      // 5, Configuration number
357
        ,4      // 6, Configuration string
358
        ,0xc0   // 7, Attributes: bus and self powered
359
        ,50     // Maximum bus power 100 mA
360
#ifdef[CONFIG_INTERFACE0]
361
        INTERFACE_DESCRIPTOR(0);
362
#endif
363
#ifdef[CONFIG_INTERFACE1]
364
        INTERFACE_DESCRIPTOR(1);
365
#endif
366
#ifdef[CONFIG_INTERFACE2]
367
        INTERFACE_DESCRIPTOR(2);
368
#endif
369
#ifdef[CONFIG_INTERFACE3]
370
        INTERFACE_DESCRIPTOR(3);
371
#endif
372
#udefine[HIGH_SPEED]
373
    };
374
APPEND_PADBYTE(HighSpeedConfigDescriptor);
375
 
376
code BYTE FullSpeedConfigDescriptor[] =
377
    {
378
        9       // 0, Descriptor length
379
        ,0x02   // 1, Decriptor type
380
        ,sizeof(HighSpeedConfigDescriptor) & 0xff       // 2, Total length (LSB)
381
//      ,sizeof(HighSpeedConfigDescriptor) >> 8         // 3, Total length (MSB)
382
        ,0                                               // 3, To avoid warnings, descriptor length will never exceed 255 bytes
383
        ,0       // 4, Number of Interfaces
384
#ifdef[CONFIG_INTERFACE0]
385
          +1
386
#endif
387
#ifdef[CONFIG_INTERFACE1]
388
          +1
389
#endif
390
#ifdef[CONFIG_INTERFACE2]
391
          +1
392
#endif
393
#ifdef[CONFIG_INTERFACE3]
394
          +1
395
#endif
396
 
397
        ,1      // 5, Configuration number
398
        ,4      // 6, Configuration string
399
        ,0xc0   // 7, Attributes: bus and self powered
400
        ,50     // Maximum bus power 100 mA
401
#ifdef[CONFIG_INTERFACE0]
402
        INTERFACE_DESCRIPTOR(0);
403
#endif
404
#ifdef[CONFIG_INTERFACE1]
405
        INTERFACE_DESCRIPTOR(1);
406
#endif
407
#ifdef[CONFIG_INTERFACE2]
408
        INTERFACE_DESCRIPTOR(2);
409
#endif
410
#ifdef[CONFIG_INTERFACE3]
411
        INTERFACE_DESCRIPTOR(3);
412
#endif
413
    };
414
APPEND_PADBYTE(FullSpeedConfigDescriptor);
415
 
416
code BYTE EmptyStringDescriptor[] =
417
    {
418
        sizeof(EmptyStringDescriptor),          // Length
419
        0x03,                                   // Descriptor type
420
        0, 0
421
    };
422
 
423
#endif  /*ZTEX_DESCRIPTORS_H*/

powered by: WebSVN 2.1.0

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