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

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [java/] [ztex/] [ZtexDevice1.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*%
2
   Java host software API of ZTEX SDK
3
   Copyright (C) 2009-2017 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   This Source Code Form is subject to the terms of the Mozilla Public
7
   License, v. 2.0. If a copy of the MPL was not distributed with this file,
8
   You can obtain one at http://mozilla.org/MPL/2.0/.
9
 
10
   Alternatively, the contents of this file may be used under the terms
11
   of the GNU General Public License Version 3, as described below:
12
 
13
   This program is free software; you can redistribute it and/or modify
14
   it under the terms of the GNU General Public License version 3 as
15
   published by the Free Software Foundation.
16
 
17
   This program is distributed in the hope that it will be useful, but
18
   WITHOUT ANY WARRANTY; without even the implied warranty of
19
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
   General Public License for more details.
21
 
22
   You should have received a copy of the GNU General Public License
23
   along with this program; if not, see http://www.gnu.org/licenses/.
24
%*/
25
 
26
/*
27
    USB device with ZTEX descriptor 1 and/or Cypress EZ-USB FX2/3 device
28
*/
29
package ztex;
30
 
31
import java.io.*;
32
import java.util.*;
33
import java.nio.*;
34
 
35
import org.usb4java.*;
36
 
37
/**
38
  * A class representing an EZ-USB device that supports the ZTEX descriptor 1 or an unconfigured EZ-USB device.<br>
39
  * Instances of this class are usually created by {@link ZtexScanBus1}.
40
  * The following table describes the ZTEX descriptor 1.
41
  * <a name="descriptor"></a>
42
  * <table bgcolor="#404040" cellspacing=1 cellpadding=4>
43
  *   <tr>
44
  *     <td bgcolor="#d0d0d0" valign="top"><b>Field name</b></td>
45
  *     <td bgcolor="#d0d0d0" valign="top"><b>Offset</b></td>
46
  *     <td bgcolor="#d0d0d0" valign="top"><b>Size</b></td>
47
  *     <td bgcolor="#d0d0d0" valign="top"><b>Description</b></td>
48
  *   </tr>
49
  *   <tr>
50
  *     <td bgcolor="#ffffff" valign="top">ZTEX_DESCRIPTOR_SIZE</td>
51
  *     <td bgcolor="#ffffff" valign="top">0</td>
52
  *     <td bgcolor="#ffffff" valign="top">1</td>
53
  *     <td bgcolor="#ffffff" valign="top">Size of the descriptor in bytes; must be 40 for descriptor version 1</td>
54
  *   </tr>
55
  *   <tr>
56
  *     <td bgcolor="#ffffff" valign="top">ZTEX_DESCRIPTOR_VERSION</td>
57
  *     <td bgcolor="#ffffff" valign="top">1</td>
58
  *     <td bgcolor="#ffffff" valign="top">1</td>
59
  *     <td bgcolor="#ffffff" valign="top">Descriptor version; 1 for version 1</td>
60
  *   </tr>
61
  *   <tr>
62
  *     <td bgcolor="#ffffff" valign="top">ZTEXID</td>
63
  *     <td bgcolor="#ffffff" valign="top">2</td>
64
  *     <td bgcolor="#ffffff" valign="top">4</td>
65
  *     <td bgcolor="#ffffff" valign="top">ID; must be "ZTEX"</td>
66
  *   </tr>
67
  *   <tr>
68
  *     <td bgcolor="#ffffff" valign="top">PRODUCT_ID</td>
69
  *     <td bgcolor="#ffffff" valign="top">6</td>
70
  *     <td bgcolor="#ffffff" valign="top">4</td>
71
  *     <td bgcolor="#ffffff" valign="top">Four numbers (0..255) representing the product ID and firmware compatibility information.<br>
72
  *         A firmware can overwrite an installed one<br>
73
  *        <pre>if ( INSTALLED.PRODUCTID[0]==0 || PRODUCTID[0]==0 || INSTALLED.PRODUCTID[0]==PRODUCTID[0] ) &&
74
   ( INSTALLED.PRODUCTID[1]==0 || PRODUCTID[1]==0 || INSTALLED.PRODUCTID[1]==PRODUCTID[1] ) &&
75
   ( INSTALLED.PRODUCTID[2]==0 || PRODUCTID[2]==0 || INSTALLED.PRODUCTID[2]==PRODUCTID[2] ) &&
76
   ( INSTALLED.PRODUCTID[3]==0 || PRODUCTID[3]==0 || INSTALLED.PRODUCTID[3]==PRODUCTID[3] ) </pre>
77
  *       Here is a list of the preserved product ID's:
78
  *       <table><tr><td>&nbsp</td><td>
79
  *         <table>
80
  *          <tr><td>0.0.0.0</td> <td>default Product ID (no product specified)</td></tr>
81
  *           <tr><td>1.*.*.*</td> <td>may be used for experimental purposes</td></tr>
82
  *           <tr><td>10.*.*.*</td> <td>used for ZTEX products</td></tr>
83
  *           <tr><td>10.11.*.*</td> <td>ZTEX USB-FPGA-Module 1.2</td></tr>
84
  *           <tr><td>10.12.*.*</td> <td>ZTEX USB-FPGA-Module 1.11</td></tr>
85
  *           <tr><td>10.12.2.1..4</td> <td>NIT (http://www.niteurope.com/)</td></tr>
86
  *           <tr><td>10.13.*.*</td> <td>ZTEX USB-FPGA-Module 1.15 (not 1.15y)</td></tr>
87
  *           <tr><td>10.14.*.*</td> <td>ZTEX USB-FPGA-Module 1.15x</td></tr>
88
  *           <tr><td>10.15.*.*</td> <td>ZTEX USB-FPGA-Module 1.15y</td></tr>
89
  *           <tr><td>10.16.*.*</td> <td> ZTEX USB-FPGA-Module 2.16</td></tr>
90
  *           <tr><td>10.17.*.*</td> <td>ZTEX USB-FPGA-Module 2.13</td></tr>
91
  *           <tr><td>10.18.*.*</td> <td>ZTEX USB-FPGA-Module 2.01</td></tr>
92
  *           <tr><td>10.19.*.*</td> <td>ZTEX USB-FPGA-Module 2.04</td></tr>
93
  *           <tr><td>10.20.*.*</td> <td>ZTEX USB-Module 1.0</td></tr>
94
  *           <tr><td>10.30.*.*</td> <td>ZTEX USB-XMEGA-Module 1.0</td></tr>
95
  *           <tr><td>10.40.*.*</td> <td>ZTEX USB-FPGA-Module 2.02</td></tr>
96
  *           <tr><td>10.41.*.*</td> <td>ZTEX USB-FPGA-Module 2.14</td></tr>
97
  *           <tr><td>10.0.1.1</td> <td>ZTEX BTCMiner firmware</td></tr>
98
  *         </table></td></tr></table>
99
  *         Please contact us (<a href="http://www.ztex.de/contact.e.html">http://www.ztex.de/contact.e.html</a>) if you want to register or reserve a Product ID (range).
100
  *       </td>
101
  *   </tr>
102
  *   <tr>
103
  *     <td bgcolor="#ffffff" valign="top">FW_VERSION</td>
104
  *     <td bgcolor="#ffffff" valign="top">10</td>
105
  *     <td bgcolor="#ffffff" valign="top">1</td>
106
  *     <td bgcolor="#ffffff" valign="top">May be used to specify the firmware version.</td>
107
  *   </tr>
108
  *   <tr>
109
  *     <td bgcolor="#ffffff" valign="top">INTERFACE_VERSION</td>
110
  *     <td bgcolor="#ffffff" valign="top">11</td>
111
  *     <td bgcolor="#ffffff" valign="top">1</td>
112
  *     <td bgcolor="#ffffff" valign="top">The interface version. This number specifies the protocol that is used for interfacing the host software. A description of interface version 1 can be found in {@link Ztex1v1} </td>
113
  *   </tr>
114
  *   <tr>
115
  *     <td bgcolor="#ffffff" valign="top">INTERFACE_CAPABILITIES</td>
116
  *     <td bgcolor="#ffffff" valign="top">12</td>
117
  *     <td bgcolor="#ffffff" valign="top">6</td>
118
  *     <td bgcolor="#ffffff" valign="top">6 bytes, each bit represents a capability. If set, the capability is supported. A description of the capabilities of interface version 1 can be found in {@link Ztex1v1} </td>
119
  *   </tr>
120
  *   <tr>
121
  *     <td bgcolor="#ffffff" valign="top">MODULE_RESERVED</td>
122
  *     <td bgcolor="#ffffff" valign="top">18</td>
123
  *     <td bgcolor="#ffffff" valign="top">12</td>
124
  *     <td bgcolor="#ffffff" valign="top">12 bytes for application specific use, i.e. they depend from the PRODUCT_ID </td>
125
  *   </tr>
126
  *   <tr>
127
  *     <td bgcolor="#ffffff" valign="top">SN_STRING</td>
128
  *     <td bgcolor="#ffffff" valign="top">30</td>
129
  *     <td bgcolor="#ffffff" valign="top">10</td>
130
  *     <td bgcolor="#ffffff" valign="top">A serial number string of 10 characters. The default SN is "0000000000"</td> </td>
131
  *   </tr>
132
  * </table>
133
  * @see Ztex1
134
  * @see Ztex1v1
135
  * @see ZtexScanBus1
136
*/
137
 
138
public class ZtexDevice1 {
139
/** * Cypress vendor ID: 0x4b4 */
140
    public static final int cypressVendorId = 0x4b4;
141
/** * EZ-USB USB FX2 product ID: 0x8613 */
142
    public static final int cypressProductIdFx2 = 0x8613;
143
/** * EZ-USB USB FX3 product ID: 0x00f3 */
144
    public static final int cypressProductIdFx3 = 0x00f3;
145
//    public static final int cypressProductIdFx3 = 0x4720;
146
 
147
/** * Vendor ID of buggy FX3 devices (datecode 1149) */
148
    public static final int cypressVendorIdBuggy = 0x1480;
149
/** * Product ID of buggy FX3 devices (datecode 1149) */
150
    public static final int cypressProductIdBuggy = 0x0000;
151
 
152
/** * ZTEX vendor ID: 0x221a */
153
    public static final int ztexVendorId = 0x221A;
154
/**
155
  * USB product ID for ZTEX devices that support ZTEX descriptor 1: 0x100.
156
  * This product ID is intended for general purpose use and can be shared by all devices that base on ZTEX modules.
157
  * Different products are identified by a second product ID, namely the PRODUCT_ID field of the <a href="#descriptor"> ZTEX descriptor 1</a>.
158
  * <p>
159
  * Please read the <a href="http://www.ztex.de/firmware-kit/usb_ids.e.html">informations about USB vendor and product ID's</a>.
160
  * @see #ztexProductIdMax
161
  */
162
    public static final int ztexProductId = 0x100;
163
/**
164
  * Largest USB product ID for ZTEX devices that support ZTEX descriptor 1: 0x1ff.
165
  * USB product ID's from {@link #ztexProductId}+1 to ztexProductIdMax (0x101 to 0x1ff) are reserved for ZTEX devices and allow to identify products without reading the ZTEX descriptor.
166
  * <p>
167
  * Please read the <a href="http://www.ztex.de/firmware-kit/usb_ids.e.html">informations about USB vendor and product ID's</a>.
168
  * @see #ztexProductId
169
  */
170
    public static final int ztexProductIdMax = 0x1ff;
171
 
172
    private Device dev = null;
173
    private boolean valid = false;              // true if descriptor 1 is available
174
    private int usbVendorId = -1;
175
    private int usbProductId = -1;
176
    private String manufacturerString = null;
177
    private String productString = null;
178
    private String snString = null;
179
    private byte productId[] = { 0,0,0,0 }; // product ID from the ZTEX descriptor, not the USB product ID
180
    private byte fwVersion = 0;
181
    private byte interfaceVersion = 0;
182
    private byte interfaceCapabilities[] = { 0,0,0,0, 0,0 };
183
    private byte moduleReserved[] = { 0,0,0,0, 0,0,0,0, 0,0,0,0 };
184
    private boolean fx3 = false;
185
    private ZtexContext context = null;
186
    private int refCount = 0;
187
 
188
// ******* byteArrayString *****************************************************
189
/**
190
  * Produces a nice string representation of an array of bytes.
191
  * @param buf A byte array.
192
  * @return a nice string
193
  */
194
    public static String byteArrayString ( byte buf[] ) {
195
        String s = new String( "" );
196
        for ( int i = 0; i<buf.length; i++ ) {
197
            if ( i != 0 )
198
                s+=".";
199
            s+=buf[i] & 255;
200
        }
201
        return s;
202
    }
203
 
204
// ******* ZtexDevice1 *********************************************************
205
/**
206
  * Constructs an instance from a given USB device.<br>
207
  * If the given vendor and product id's match to the vendor and product id's of the given USB device,
208
  * the ZTEX descriptor 1 is attempted to read. If this fails, an {@link InvalidFirmwareException} is thrown.
209
  * To suppress this behavior (e.g. if the EZ-USB device is known to be unconfigured) the vendor and product id's
210
  * can be set to -1.
211
  * @param p_context The USB context.
212
  * @param p_dev The USB device.
213
  * @param pUsbVendorId The given vendor ID.
214
  * @param pUsbProductId The given product ID.
215
  * @param allowUnconfigured If true, unconfigured devices are allowed.
216
  * @throws UsbException if an USB communication error occurs.
217
  * @throws InvalidFirmwareException if no valid ZTEX descriptor 1 is found.
218
  * @throws DeviceNotSupported if the device has the wrong USB ID's.
219
  */
220
    public ZtexDevice1 (ZtexContext p_context, Device p_dev, int pUsbVendorId, int pUsbProductId, boolean allowUnconfigured) throws UsbException, InvalidFirmwareException, DeviceNotSupportedException  {
221
        context = p_context;
222
        dev = p_dev;
223
        refCount = 0;
224
 
225
        DeviceDescriptor dd = new DeviceDescriptor();
226
        int result = LibUsb.getDeviceDescriptor(dev, dd);
227
        if (result != LibUsb.SUCCESS) throw new UsbException(dev, "Unable to read device descriptor", result);
228
        usbVendorId = dd.idVendor() & 65535;
229
        usbProductId = dd.idProduct() & 65535;
230
 
231
        fx3 = (usbVendorId == cypressVendorId) && (usbProductId == cypressProductIdFx3) || (usbVendorId == cypressVendorIdBuggy) && (usbProductId == cypressProductIdBuggy);
232
        if ( ! ( (
233
                   (usbVendorId == pUsbVendorId) &&
234
                   (usbProductId == pUsbProductId || ( usbVendorId == ztexVendorId && pUsbProductId<0 && usbProductId>=ztexProductId && usbProductId<ztexProductIdMax ) )
235
                 ) ||
236
                 (
237
                   allowUnconfigured &&
238
                    ( (usbVendorId == cypressVendorId) && (usbProductId == cypressProductIdFx2) || fx3 )
239
                 ) )  )
240
            throw new DeviceNotSupportedException(p_dev);
241
 
242
        DeviceHandle handle = new DeviceHandle();
243
        result = LibUsb.open(dev, handle);
244
        if (result != LibUsb.SUCCESS) throw new UsbException(dev, "Unable to open USB device", result);
245
 
246
        if ( dd.iManufacturer() > 0 )
247
            manufacturerString = LibUsb.getStringDescriptor( handle, dd.iManufacturer() );
248
        if ( dd.iProduct() > 0 )
249
            productString = LibUsb.getStringDescriptor( handle, dd.iProduct() );
250
        if ( dd.iSerialNumber() > 0 )
251
            snString = LibUsb.getStringDescriptor( handle, dd.iSerialNumber() );
252
 
253
//          System.out.println("snString="+snString);
254
        if ( snString == null ) {
255
            LibUsb.close(handle);
256
            if ( allowUnconfigured ) {
257
                ref();
258
                return;
259
            }
260
            else {
261
                throw new InvalidFirmwareException( dev, "Not a ZTEX device" );  // ZTEX devices always have a SN. See also the next comment a few lines below
262
            }
263
        }
264
 
265
        ByteBuffer buf = BufferUtils.allocateByteBuffer(42);
266
        int i = LibUsb.controlTransfer(handle, (byte) (0xc0 & 255), (byte)0x22, (short)0,(short)0, buf, 500);     // Failing of this may cause problems under windows. Therefore we check for the SN above.
267
        if ( i < 0 ) {
268
            LibUsb.close(handle);
269
            if ( allowUnconfigured ) {
270
                ref();
271
                return;
272
            }
273
            else {
274
                throw new InvalidFirmwareException( dev, "Error reading ZTEX descriptor: " + LibUsb.strError(i) );
275
            }
276
        }
277
        else if ( i != 40 ) {
278
            LibUsb.close(handle);
279
            if ( allowUnconfigured ) {
280
                ref();
281
                return;
282
            }
283
            else {
284
                throw new InvalidFirmwareException( dev, "Error reading ZTEX descriptor: Invalid size: " + i );
285
            }
286
        }
287
 
288
        if ( buf.get()!=40 || buf.get()!=1 || buf.get()!='Z' || buf.get()!='T' || buf.get()!='E' || buf.get()!='X' ) {
289
            LibUsb.close(handle);
290
            if ( allowUnconfigured ) {
291
                ref();
292
                return;
293
            }
294
            else  {
295
                throw new InvalidFirmwareException( dev, "Invalid ZTEX descriptor" );
296
            }
297
        }
298
        buf.get(productId, 0, 4);              // 6
299
        fwVersion = buf.get();                 // 10
300
        interfaceVersion = buf.get();          // 11
301
        buf.get(interfaceCapabilities, 0, 6);  // 12
302
        buf.get(moduleReserved, 0, 12);         // 18
303
 
304
        fx3 = (interfaceCapabilities[1] & 4) != 0;
305
 
306
        valid = true;
307
        ref();
308
        LibUsb.close(handle);
309
    }
310
 
311
// ******* toString ************************************************************
312
/**
313
  * Returns a string representation if the device with a lot of useful information.
314
  * @return a string representation if the device with a lot of useful information.
315
  */
316
    public String toString () {
317
        return name() + "  ID=" + Integer.toHexString(usbVendorId) + ":" + Integer.toHexString(usbProductId) +"\n"  +
318
              ( manufacturerString == null ? "" : ("   Manufacturer=\""  + manufacturerString + "\"") ) +
319
              ( productString == null ? "" : ("  Product=\""  + productString + "\"") ) +
320
              ( snString == null ? "" : ("    SerialNumber=\""  + snString + "\"") ) +
321
              ( valid ? "\n   productID=" + byteArrayString(productId) + "  fwVer="+(fwVersion & 255) + "  ifVer="+(interfaceVersion & 255)  : "" );
322
    }
323
 
324
// ******* name ****************************************************************
325
/**
326
  * Returns a name that identifies a device.
327
  * @param p_dev the device.
328
  * @return a name that identifies a device.
329
  */
330
    public static String name ( Device p_dev ) {
331
        return "bus=" + LibUsb.getBusNumber(p_dev) + " device=" + LibUsb.getDeviceAddress(p_dev) + " port=" + LibUsb.getPortNumber(p_dev);
332
    }
333
 
334
// ******* name ****************************************************************
335
/**
336
  * Returns a name that identifies the device.
337
  * @return a name that identifies the device.
338
  */
339
    public String name () {
340
        return name(dev);
341
    }
342
 
343
// ******* compatible **********************************************************
344
/**
345
  * Checks whether the given product ID is compatible to the device.<br>
346
  * The given product ID is compatible
347
  * <pre>if ( this.productId(0)==0 || productId0<=0 || this.productId(0)==productId0 ) &&
348
   ( this.productId(0)==0 || productId1<=0 || this.productId(1)==productId1 ) &&
349
   ( this.productId(2)==0 || productId2<=0 || this.productId(2)==productId2 ) &&
350
   ( this.productId(3)==0 || productId3<=0 || this.productId(3)==productId3 ) </pre>
351
  * @param productId0 Byte 0 of the given product ID
352
  * @param productId1 Byte 1 of the given product ID
353
  * @param productId2 Byte 2 of the given product ID
354
  * @param productId3 Byte 3 of the given product ID
355
  * @return true if the given product ID is compatible
356
  */
357
    public final boolean compatible( int productId0, int productId1, int productId2, int productId3 ) {
358
        return ( productId[0]==0 || productId0<=0 || (productId[0] & 255) == productId0 ) &&
359
               ( productId[1]==0 || productId1<=0 || (productId[1] & 255) == productId1 ) &&
360
               ( productId[2]==0 || productId2<=0 || (productId[2] & 255) == productId2 ) &&
361
               ( productId[3]==0 || productId3<=0 || (productId[3] & 255) == productId3 );
362
    }
363
 
364
// ******* dev *****************************************************************
365
/**
366
  * Returns the USB device.
367
  * @return the USB device.
368
  */
369
    public final Device dev() {
370
        return dev;
371
    }
372
 
373
// ******* context *************************************************************
374
/**
375
  * Returns the USB context of the device.
376
  * @return the USB context of the device.
377
  */
378
    public final ZtexContext context() {
379
        return context;
380
    }
381
 
382
// ******* valid ***************************************************************
383
/**
384
  * Returns true if ZTEX descriptor 1 is available.
385
  * @return true if ZTEX descriptor 1 is available.
386
  */
387
    public final boolean valid() {
388
        return valid;
389
    }
390
 
391
// ******* usbVendorId *********************************************************
392
/**
393
  * Returns the USB vendor ID of the device.
394
  * @return the USB vendor ID of the device.
395
  */
396
    public final int usbVendorId() {
397
        return usbVendorId;
398
    }
399
 
400
// ******* usbProductId *********************************************************
401
/**
402
  * Returns the USB product ID of the device.
403
  * @return the USB product ID of the device.
404
  */
405
    public final int usbProductId() {
406
        return usbProductId;
407
    }
408
 
409
// ******* manufacturerString **************************************************
410
/**
411
  * Returns the manufacturer string of the device.
412
  * @return the manufacturer string of the device.
413
  */
414
    public final String manufacturerString() {
415
        return manufacturerString;
416
    }
417
 
418
// ******* productString *******************************************************
419
/**
420
  * Returns the product string of the device.
421
  * @return the product string of the device.
422
  */
423
    public final String productString() {
424
        return productString;
425
    }
426
 
427
// ******* snString ************************************************************
428
/**
429
  * Returns the serial number string of the device.
430
  * @return the serial number string of the device.
431
  */
432
    public final String snString() {
433
        return snString;
434
    }
435
 
436
// ******* productId ***********************************************************
437
/**
438
  * Returns the product ID (all 4 bytes).
439
  * @return PRODUCT_ID, see above.
440
  */
441
    public final byte[] productId() {
442
        return productId;
443
    }
444
 
445
/**
446
  * Returns byte i of the product ID.
447
  * @return PRODUCT_ID[i], see above.
448
  * @param i index
449
  */
450
    public int productId( int i ) {
451
        return productId[i] & 255;
452
    }
453
 
454
// ******* fwVersion ***********************************************************
455
/**
456
  * Returns the firmware version.
457
  * @return FW_VERSION, see above.
458
  */
459
    public final int fwVersion() {
460
        return fwVersion & 255;
461
    }
462
 
463
// ******* interfaceVersion *****************************************************
464
/**
465
  * Returns the interface version.
466
  * @return INTERFACE_VERSION, see above.
467
  */
468
    public final int interfaceVersion() {
469
        return interfaceVersion & 255;
470
    }
471
 
472
// ******* interfaceCapabilities ************************************************
473
/**
474
  * Returns the interface capabilities (all 6 bytes).
475
  * @return INTERFACE_CAPABILITIES, see above.
476
  */
477
    public final byte[] interfaceCapabilities() {
478
        return interfaceCapabilities;
479
    }
480
 
481
/**
482
  * Returns byte i of the interface capabilities.
483
  * @return INTERFACE_CAPABILITIES[i], see above.
484
  * @param i index
485
  */
486
    public final int interfaceCapabilities( int i ) {
487
        return interfaceCapabilities[i] & 255;
488
    }
489
 
490
/**
491
  * Returns byte i, bit j  of the interface capabilities.
492
  * @return INTERFACE_CAPABILITIES[i].j, see above.
493
  * @param i byte index
494
  * @param j bit index
495
  */
496
    public final boolean interfaceCapabilities( int i, int j ) {
497
        return  (i>=0) && (i<=5) && (j>=0) && (j<8) &&
498
                (((interfaceCapabilities[i] & 255) & (1 << j)) != 0);
499
    }
500
 
501
// ******* moduleReserved ******************************************************
502
/**
503
  * Returns the application specific information (all 12 bytes).
504
  * @return MODULE_RESERVED, see above.
505
  */
506
    public final byte[] moduleReserved() {
507
        return moduleReserved;
508
    }
509
 
510
/**
511
  * Returns byte i of the application specific information.
512
  * @return MODULE_RESERVED[i], see above.
513
  * @param i index
514
  */
515
    public final int moduleReserved( int i ) {
516
        return moduleReserved[i] & 255;
517
    }
518
 
519
// ******* fx3 *****************************************************************
520
/**
521
  * Returns true if device is an FX3
522
  * @return true if device is an FX3
523
  */
524
    public final boolean fx3 () {
525
        return fx3;
526
    }
527
 
528
// ******* ref *****************************************************************
529
/**
530
  * Increases reference counter.
531
  */
532
    public synchronized void ref() throws UsbException {
533
        refCount ++;
534
        if ( refCount == 1 ) {
535
            LibUsb.refDevice(dev);
536
            context.ref();
537
//          System.out.println("created ZtexDevice1: "+name());
538
        }
539
    }
540
 
541
// ******* unref ***************************************************************
542
/**
543
  * Decreases reference counter and rleases resources if 0 is reached.
544
  */
545
    public synchronized void unref() {
546
        refCount --;
547
        if ( refCount == 0 ) {
548
//          System.out.println("disposing ZtexDevice1: "+name());
549
            LibUsb.unrefDevice(dev);
550
            context.unref();
551
        }
552
    }
553
 
554
// ******* finalize ************************************************************
555
/**
556
  * Releases all resources.
557
  */
558
    protected void finalize() throws Throwable {
559
        if (refCount > 0) refCount=1;
560
        unref();
561
        super.finalize();
562
    }
563
 
564
}

powered by: WebSVN 2.1.0

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