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/] [java/] [ztex/] [ZtexDevice1.java] - Diff between revs 3 and 4

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 3 Rev 4
Line 1... Line 1...
/*!
/*!
   Java Driver API for the ZTEX Firmware Kit
   Java Driver API for the ZTEX Firmware Kit
   Copyright (C) 2008-2009 ZTEX e.K.
   Copyright (C) 2009-2010 ZTEX e.K.
   http://www.ztex.de
   http://www.ztex.de
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3 as
   it under the terms of the GNU General Public License version 3 as
   published by the Free Software Foundation.
   published by the Free Software Foundation.
Line 28... Line 28...
 
 
/**
/**
  * A class representing an EZ-USB device that supports the ZTEX descriptor 1 or an unconfigured EZ-USB device.<br>
  * A class representing an EZ-USB device that supports the ZTEX descriptor 1 or an unconfigured EZ-USB device.<br>
  * Instances of this class are usually created by {@link ZtexScanBus1}.
  * Instances of this class are usually created by {@link ZtexScanBus1}.
  * The following table describes the ZTEX descriptor 1.
  * The following table describes the ZTEX descriptor 1.
 
  * <a name="descriptor"></a>
  * <table bgcolor="#404040" cellspacing=1 cellpadding=4>
  * <table bgcolor="#404040" cellspacing=1 cellpadding=4>
  *   <tr>
  *   <tr>
  *     <td bgcolor="#d0d0d0" valign="top"><b>Field name</b></td>
  *     <td bgcolor="#d0d0d0" valign="top"><b>Field name</b></td>
  *     <td bgcolor="#d0d0d0" valign="top"><b>Offset</b></td>
  *     <td bgcolor="#d0d0d0" valign="top"><b>Offset</b></td>
  *     <td bgcolor="#d0d0d0" valign="top"><b>Size</b></td>
  *     <td bgcolor="#d0d0d0" valign="top"><b>Size</b></td>
Line 112... Line 113...
  * @see Ztex1v1
  * @see Ztex1v1
  * @see ZtexScanBus1
  * @see ZtexScanBus1
*/
*/
 
 
public class ZtexDevice1 {
public class ZtexDevice1 {
/** * The Cypress vendor ID 0x4b4. */
/** * Cypress vendor ID: 0x4b4 */
    public static final int cypressVendorId = 0x4b4;
    public static final int cypressVendorId = 0x4b4;
/** * The EZ-USB product ID 0x8613. */
/** * EZ-USB USB product ID: 0x8613 */
    public static final int cypressProductId = 0x8613;
    public static final int cypressProductId = 0x8613;
 
 
 
/** * ZTEX vendor ID: 0x221a */
 
    public static final int ztexVendorId = 0x221A;
 
/**
 
  * USB product ID for ZTEX devices that support ZTEX descriptor 1: 0x100.
 
  * This product ID is intended for general purpose use and can be shared by all devices that base on ZTEX modules.
 
  * Different products are identified by a second product ID, namely the PRODUCT_ID field of the <a href="#descriptor"> ZTEX descriptor 1</a>.
 
  * <p>
 
  * Please read the <a href="http://www.ztex.de/firmware-kit/usb_ids.e.html">informations about USB vendor and product ID's<a>.
 
  * @see #ztexProductIdMax
 
  */
 
    public static final int ztexProductId = 0x100;
 
/**
 
  * Largest USB product ID for ZTEX devices that support ZTEX descriptor 1: 0x1ff.
 
  * 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.
 
  * <p>
 
  * Please read the <a href="http://www.ztex.de/firmware-kit/usb_ids.e.html">informations about USB vendor and product ID's<a>.
 
  * @see #ztexProductId
 
  */
 
    public static final int ztexProductIdMax = 0x1ff;
 
 
    private Usb_Device dev = null;
    private Usb_Device dev = null;
    private boolean isCypress = false;          // true if Cypress device
    private boolean isCypress = false;          // true if Cypress device
    private boolean valid = false;              // true if descriptor 1 is available
    private boolean valid = false;              // true if descriptor 1 is available
    private int usbVendorId = -1;
    private int usbVendorId = -1;
    private int usbProductId = -1;
    private int usbProductId = -1;
Line 173... Line 194...
            isCypress = true;
            isCypress = true;
        }
        }
 
 
        int handle = LibusbJava.usb_open(dev);
        int handle = LibusbJava.usb_open(dev);
 
 
        if ( handle > 0 ) {
//      if ( handle > 0 ) {
            if ( dd.getIManufacturer() > 0 )
            if ( dd.getIManufacturer() > 0 )
                manufacturerString = LibusbJava.usb_get_string_simple( handle, dd.getIManufacturer() );
                manufacturerString = LibusbJava.usb_get_string_simple( handle, dd.getIManufacturer() );
            if ( dd.getIProduct() > 0 )
            if ( dd.getIProduct() > 0 )
                productString = LibusbJava.usb_get_string_simple( handle, dd.getIProduct() );
                productString = LibusbJava.usb_get_string_simple( handle, dd.getIProduct() );
            if ( dd.getISerialNumber() > 0 )
            if ( dd.getISerialNumber() > 0 )
                snString = LibusbJava.usb_get_string_simple( handle, dd.getISerialNumber() );
                snString = LibusbJava.usb_get_string_simple( handle, dd.getISerialNumber() );
 
 
            if ( usbVendorId == pUsbVendorId  &&  usbProductId == pUsbProductId ) {
            if ( usbVendorId == pUsbVendorId && (usbProductId == pUsbProductId || ( usbVendorId == ztexVendorId && pUsbProductId<0 && usbProductId>=ztexProductId && usbProductId<ztexProductIdMax ) ) ) {
                if ( snString == null ) {
                if ( snString == null ) {
                    LibusbJava.usb_close(handle);
                    LibusbJava.usb_close(handle);
                    throw new InvalidFirmwareException( dev, "Not a ZTEX device" );  // ZTEX devices always have a SN. See also the next comment a few lines below
                    throw new InvalidFirmwareException( dev, "Not a ZTEX device" );  // ZTEX devices always have a SN. See also the next comment a few lines below
                }
                }
 
 
Line 228... Line 249...
                moduleReserved[10] = buf[28];
                moduleReserved[10] = buf[28];
                moduleReserved[11] = buf[29];
                moduleReserved[11] = buf[29];
 
 
                valid = true;
                valid = true;
            }
            }
        }
//      }
        else {
//      else {
            throw new UsbException( dev, "Error opening device: " + LibusbJava.usb_strerror() );
//          throw new UsbException( dev, "Error opening device: " + LibusbJava.usb_strerror() );
        }
//      }
 
 
        LibusbJava.usb_close(handle);
        LibusbJava.usb_close(handle);
    }
    }
 
 
// ******* toString ************************************************************
// ******* toString ************************************************************
/**
/**
  * Returns a string representation if the device with a lot of useful information.
  * Returns a string representation if the device with a lot of useful information.
  * @return a string representation if the device with a lot of useful information.
  * @return a string representation if the device with a lot of useful information.
  */
  */
    public String toString () {
    public String toString () {
        return "bus=" + dev().getBus().getDirname() + "  device=" + dev().getFilename() +
        return "bus=" + dev().getBus().getDirname() + "  device=" + dev().getFilename() + "  ID=" + Integer.toHexString(usbVendorId) + ":" + Integer.toHexString(usbProductId) +
            "\n   " + ( isCypress ? "Cypress" : "" ) +
            "\n   " + ( isCypress ? "Cypress" : "" ) +
              ( manufacturerString == null ? "" : ("    Manufacturer=\""  + manufacturerString + "\"") ) +
              ( manufacturerString == null ? "" : ("    Manufacturer=\""  + manufacturerString + "\"") ) +
              ( productString == null ? "" : ("  Product=\""  + productString + "\"") ) +
              ( productString == null ? "" : ("  Product=\""  + productString + "\"") ) +
              ( snString == null ? "" : ("    SerialNumber=\""  + snString + "\"") ) +
              ( snString == null ? "" : ("    SerialNumber=\""  + snString + "\"") ) +
            ( valid ? "\n   productID=" + byteArrayString(productId) + "  fwVer="+(fwVersion & 255) + "  ifVer="+(interfaceVersion & 255)  : "" );
            ( valid ? "\n   productID=" + byteArrayString(productId) + "  fwVer="+(fwVersion & 255) + "  ifVer="+(interfaceVersion & 255)  : "" );

powered by: WebSVN 2.1.0

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