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/] [ZtexIhxFile1.java] - Diff between revs 2 and 3

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

Rev 2 Rev 3
Line 22... Line 22...
package ztex;
package ztex;
 
 
import java.io.*;
import java.io.*;
import java.util.*;
import java.util.*;
 
 
 
/**
 
  * Represents a firmware image with ZTEX descriptor 1 loaded from an ihx (Intel Hex format) file. <br>
 
  * The ZTEX descriptor is usually located at the position 0x6x of the firmware image. <br>
 
  * A description of the ZTEX descriptor 1 can be found in {@link ZtexDevice1}.
 
  * @see ZtexDevice1
 
  * @see Ztex1
 
*/
public class ZtexIhxFile1 extends IhxFile {
public class ZtexIhxFile1 extends IhxFile {
    private static final int defaultZtexDescriptorOffs = 0x6c;
    private static final int defaultZtexDescriptorOffs = 0x6c;
 
 
    private int ztexDescriptorOffs = defaultZtexDescriptorOffs;
    private int ztexDescriptorOffs = defaultZtexDescriptorOffs;
 
 
    private byte productId[] = { 0,0,0,0 }; // product ID from the ZTEX descpriptor, not the USB product ID
    private byte productId[] = { 0,0,0,0 }; // product ID from the ZTEX descriptor, not the USB product ID
    private byte fwVersion = 0;
    private byte fwVersion = 0;
    private byte interfaceVersion = 0;
    private byte interfaceVersion = 0;
    private byte interfaceCapabilities[] = { 0,0,0,0, 0,0 };
    private byte interfaceCapabilities[] = { 0,0,0,0, 0,0 };
    private byte moduleReserved[] = { 0,0,0,0, 0,0,0,0, 0,0,0,0 };
    private byte moduleReserved[] = { 0,0,0,0, 0,0,0,0, 0,0,0,0 };
    private char snString[] = new char[10];
    private char snString[] = new char[10];
 
 
// ******* ZtexIhxFile1 ********************************************************
// ******* ZtexIhxFile1 ********************************************************
 
/**
 
  * Constructs an instance from a given file name and descriptor position.<br>
 
  * This method can also read system resources, e.g. files from the current jar archive.
 
  * @param fileName The file name.
 
  * @param pZtexDescriptorOffs The position of the descriptor in bytes. The default position is 0x6c.
 
  * @throws IOException If an read error occurred.
 
  * @throws IhxFileDamagedException If the ihx file is damaged.
 
  * @throws IncompatibleFirmwareException If the firmware image contains no valid ZTEX descriptor 1 at the specified position.
 
  */
    public ZtexIhxFile1( String fileName, int pZtexDescriptorOffs ) throws IOException, IhxFileDamagedException, IncompatibleFirmwareException {
    public ZtexIhxFile1( String fileName, int pZtexDescriptorOffs ) throws IOException, IhxFileDamagedException, IncompatibleFirmwareException {
        super( fileName );
        super( fileName );
 
 
        ztexDescriptorOffs = pZtexDescriptorOffs;
        ztexDescriptorOffs = pZtexDescriptorOffs;
 
 
Line 78... Line 94...
            else {
            else {
                throw new IncompatibleFirmwareException( "Invalid serial number string" );
                throw new IncompatibleFirmwareException( "Invalid serial number string" );
            }
            }
        }
        }
 
 
        // ensure word bounded upload data
        // ensure word aligned upload data
        for ( int i=0; i+1<ihxData.length; i+=2 )
        for ( int i=0; i+1<ihxData.length; i+=2 )
            if ( ihxData[i]<0 && ihxData[i+1]>=0 )
            if ( ihxData[i]<0 && ihxData[i+1]>=0 )
                ihxData[i] = 0;
                ihxData[i] = 0;
    }
    }
 
 
 
/**
 
  * Constructs an instance from a given file name.
 
  * The ZTEX descriptor 1 is expected to be at the position 0x6c of the firmware image.<br>
 
  * This method can also read system resources, e.g. files from the current jar archive.
 
  * @param fileName The file name.
 
  * @throws IOException If an read error occurred.
 
  * @throws IhxFileDamagedException If the ihx file is damaged.
 
  * @throws IncompatibleFirmwareException If the firmware image contains no valid ZTEX descriptor 1 at the specified position.
 
  */
    public ZtexIhxFile1( String fileName ) throws IOException, IhxFileDamagedException, IncompatibleFirmwareException {
    public ZtexIhxFile1( String fileName ) throws IOException, IhxFileDamagedException, IncompatibleFirmwareException {
        this( fileName, defaultZtexDescriptorOffs );
        this( fileName, defaultZtexDescriptorOffs );
    }
    }
 
 
// ******* productId ***********************************************************
// ******* productId ***********************************************************
 
/**
 
  * Returns the product ID (all 4 bytes).
 
  * @return PRODUCT_ID, see {@link ZtexDevice1}.
 
  */
    public final byte[] productId() {
    public final byte[] productId() {
        return productId;
        return productId;
    }
    }
 
 
 
/**
 
  * Returns byte i of the product ID.
 
  * @return PRODUCT_ID[i], see {@link ZtexDevice1}.
 
  * @param i index
 
  */
    public int productId( int i ) {
    public int productId( int i ) {
        return productId[i] & 255;
        return productId[i] & 255;
    }
    }
 
 
// ******* fwVersion ***********************************************************
// ******* fwVersion ***********************************************************
 
/**
 
  * Returns the firmware version.
 
  * @return FW_VERSION, see {@link ZtexDevice1}.
 
  */
    public final int fwVersion() {
    public final int fwVersion() {
        return fwVersion & 255;
        return fwVersion & 255;
    }
    }
 
 
// ******* interfaceVersion *****************************************************
// ******* interfaceVersion *****************************************************
 
/**
 
  * Returns the interface version.
 
  * @return INTERFACE_VERSION, see {@link ZtexDevice1}.
 
  */
    public final int interfaceVersion() {
    public final int interfaceVersion() {
        return interfaceVersion & 255;
        return interfaceVersion & 255;
    }
    }
 
 
// ******* interfaceCapabilities ************************************************
// ******* interfaceCapabilities ************************************************
 
/**
 
  * Returns the interface capabilities (all 6 bytes).
 
  * @return INTERFACE_CAPABILITIES, see {@link ZtexDevice1}.
 
  */
    public final byte[] interfaceCapabilities() {
    public final byte[] interfaceCapabilities() {
        return interfaceCapabilities;
        return interfaceCapabilities;
    }
    }
 
 
 
/**
 
  * Returns byte i of the interface capabilities.
 
  * @return INTERFACE_CAPABILITIES[i], see {@link ZtexDevice1}.
 
  * @param i index
 
  */
    public final int interfaceCapabilities( int i ) {
    public final int interfaceCapabilities( int i ) {
        return interfaceCapabilities[i] & 255;
        return interfaceCapabilities[i] & 255;
    }
    }
 
 
// ******* moduleReserved ******************************************************
// ******* moduleReserved ******************************************************
 
/**
 
  * Returns the application specific information (all 12 bytes).
 
  * @return MODULE_RESERVED, see {@link ZtexDevice1}.
 
  */
    public final byte[] moduleReserved() {
    public final byte[] moduleReserved() {
        return moduleReserved;
        return moduleReserved;
    }
    }
 
 
 
/**
 
  * Returns byte i of the application specific information.
 
  * @return MODULE_RESERVED[i], see {@link ZtexDevice1}.
 
  * @param i index
 
  */
    public final int moduleReserved( int i ) {
    public final int moduleReserved( int i ) {
        return moduleReserved[i] & 255;
        return moduleReserved[i] & 255;
    }
    }
 
 
// ******* snString ************************************************************
// ******* snString ************************************************************
 
/**
 
  * Returns the serial number string.
 
  * @return SN_STRING, see {@link ZtexDevice1}.
 
  */
    public final String snString() {
    public final String snString() {
        return new String( snString );
        return new String( snString );
    }
    }
 
 
// ******* setSnString **********************************************************
// ******* setSnString **********************************************************
 
/**
 
  * Modifies the serial number string.
 
  * @param s The new serial number string which must not be longer then 10 characters.
 
  */
    public final void setSnString( String s ) throws IncompatibleFirmwareException {
    public final void setSnString( String s ) throws IncompatibleFirmwareException {
        if ( s.length()>10 )
        if ( s.length()>10 )
            throw new IncompatibleFirmwareException( "Serial number too long (max. 10 characters)" );
            throw new IncompatibleFirmwareException( "Serial number too long (max. 10 characters)" );
 
 
        int i=0;
        int i=0;
Line 144... Line 213...
            ihxData[ztexDescriptorOffs+26+i] = 0;
            ihxData[ztexDescriptorOffs+26+i] = 0;
        }
        }
    }
    }
 
 
// ******* toString ************************************************************
// ******* toString ************************************************************
 
/**
 
  * Returns a string representation if the instance.
 
  * @return a string representation if the instance.
 
  */
    public String toString () {
    public String toString () {
        return "productID=" + ZtexDevice1.byteArrayString(productId) + "  fwVer="+(fwVersion & 255) + "  ifVer="+(interfaceVersion & 255)+ "  snString=\"" + snString() + "\"";
        return "productID=" + ZtexDevice1.byteArrayString(productId) + "  fwVer="+(fwVersion & 255) + "  ifVer="+(interfaceVersion & 255)+ "  snString=\"" + snString() + "\"";
    }
    }
 
 
}
}

powered by: WebSVN 2.1.0

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