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

Subversion Repositories usb_fpga_1_15

[/] [usb_fpga_1_15/] [trunk/] [default/] [usb-fpga-1.15/] [Default.java] - Diff between revs 3 and 4

Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 4
/*!
/*!
   flashdemo -- demo for Flash memory access from firmware and host software for ZTEX USB-FPGA Module 1.15
   Default firmware and loader for ZTEX USB-FPGA Modules 1.15
   Copyright (C) 2009-2011 ZTEX GmbH.
   Copyright (C) 2009-2014 ZTEX GmbH.
   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.
 
 
   This program is distributed in the hope that it will be useful, but
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.
   General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, see http://www.gnu.org/licenses/.
   along with this program; if not, see http://www.gnu.org/licenses/.
!*/
!*/
 
 
import java.io.*;
import java.io.*;
import java.util.*;
import java.util.*;
 
 
import ch.ntb.usb.*;
import ch.ntb.usb.*;
 
 
import ztex.*;
import ztex.*;
 
 
// *****************************************************************************
// *****************************************************************************
// ******* ParameterException **************************************************
// ******* ParameterException **************************************************
// *****************************************************************************
// *****************************************************************************
// Exception the prints a help message
// Exception the prints a help message
class ParameterException extends Exception {
class ParameterException extends Exception {
    public final static String helpMsg = new String (
    public final static String helpMsg = new String (
                "Parameters:\n"+
                "Parameters:\n"+
                "    -d <number>  Device Number (default: 0)\n" +
                "    -d <number>  Device Number (default: 0)\n" +
                "    -p           Print bus info\n" +
                "    -p           Print bus info\n" +
                "    -f           Force upload Firmware to RAM\n" +
                "    -f           Force upload Firmware to RAM\n" +
                "    -va          Upload configuration data for USB-FPGA Modules 1.15a\n" +
                "    -va          Upload configuration data for USB-FPGA Modules 1.15a\n" +
                "    -vb          Upload configuration data for USB-FPGA Modules 1.15b\n" +
                "    -vb          Upload configuration data for USB-FPGA Modules 1.15b\n" +
//              "    -vc          Upload configuration data for USB-FPGA Modules 1.15c\n" +
//              "    -vc          Upload configuration data for USB-FPGA Modules 1.15c\n" +
                "    -vd          Upload configuration data for USB-FPGA Modules 1.14d\n" +
                "    -vd          Upload configuration data for USB-FPGA Modules 1.14d\n" +
                "    -c           Clear settings from configuration data\n" +
                "    -c           Clear settings from configuration data\n" +
                "    -ue          Upload Firmware to EEPROM\n" +
                "    -ue          Upload Firmware to EEPROM\n" +
                "    -re          Reset EEPROM Firmware\n" +
                "    -re          Reset EEPROM Firmware\n" +
                "    -h           This help" );
                "    -h           This help" );
 
 
    public ParameterException (String msg) {
    public ParameterException (String msg) {
        super( msg + "\n" + helpMsg );
        super( msg + "\n" + helpMsg );
    }
    }
}
}
 
 
// *****************************************************************************
// *****************************************************************************
// ******* Default *************************************************************
// ******* Default *************************************************************
// *****************************************************************************
// *****************************************************************************
class Default {
class Default {
 
 
// ******* main ****************************************************************
// ******* main ****************************************************************
    public static void main (String args[]) {
    public static void main (String args[]) {
 
 
        int devNum = 0;
        int devNum = 0;
        boolean force = false;
        boolean force = false;
        boolean clear = false;
        boolean clear = false;
        int variant = 0;
        int variant = 0;
 
 
        try {
        try {
// init USB stuff
// init USB stuff
            LibusbJava.usb_init();
            LibusbJava.usb_init();
 
 
// scan the USB bus
// scan the USB bus
            ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
            ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
            if ( bus.numberOfDevices() <= 0) {
            if ( bus.numberOfDevices() <= 0) {
                System.err.println("No devices found");
                System.err.println("No devices found");
                System.exit(0);
                System.exit(0);
            }
            }
 
 
// scan the command line arguments
// scan the command line arguments
            for (int i=0; i<args.length; i++ ) {
            for (int i=0; i<args.length; i++ ) {
                if ( args[i].equals("-d") ) {
                if ( args[i].equals("-d") ) {
                    i++;
                    i++;
                    try {
                    try {
                        if (i>=args.length) throw new Exception();
                        if (i>=args.length) throw new Exception();
                        devNum = Integer.parseInt( args[i] );
                        devNum = Integer.parseInt( args[i] );
                    }
                    }
                    catch (Exception e) {
                    catch (Exception e) {
                        throw new ParameterException("Device number expected after -d");
                        throw new ParameterException("Device number expected after -d");
                    }
                    }
                }
                }
                else if ( args[i].equals("-p") ) {
                else if ( args[i].equals("-p") ) {
                    bus.printBus(System.out);
                    bus.printBus(System.out);
                    System.exit(0);
                    System.exit(0);
                }
                }
                else if ( args[i].equals("-f") ) {
                else if ( args[i].equals("-f") ) {
                    force = true;
                    force = true;
                }
                }
                else if ( args[i].equals("-va") ) {
                else if ( args[i].equals("-va") ) {
                    variant = 1;
                    variant = 1;
                }
                }
                else if ( args[i].equals("-vb") ) {
                else if ( args[i].equals("-vb") ) {
                    variant = 2;
                    variant = 2;
                }
                }
                else if ( args[i].equals("-vc") ) {
                else if ( args[i].equals("-vc") ) {
                    variant = 3;
                    variant = 3;
                }
                }
                else if ( args[i].equals("-vd") ) {
                else if ( args[i].equals("-vd") ) {
                    variant = 4;
                    variant = 4;
                }
                }
                else if ( args[i].equals("-c") ) {
                else if ( args[i].equals("-c") ) {
                    clear = true;
                    clear = true;
                }
                }
                else if ( args[i].equals("-h") ) {
                else if ( args[i].equals("-h") ) {
                    System.err.println(ParameterException.helpMsg);
                    System.err.println(ParameterException.helpMsg);
                    System.exit(0);
                    System.exit(0);
                }
                }
                else if ( !args[i].equals("-re") && !args[i].equals("-ue") )
                else if ( !args[i].equals("-re") && !args[i].equals("-ue") )
                    throw new ParameterException("Invalid Parameter: "+args[i]);
                    throw new ParameterException("Invalid Parameter: "+args[i]);
            }
            }
 
 
// create the main class            
// create the main class            
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
 
 
// upload the firmware if necessary
// upload the firmware if necessary
            if ( force || ! ztex.valid() || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_EEPROM) || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_MAC_EEPROM) ) {
            if ( force || ! ztex.valid() || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_EEPROM) || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_MAC_EEPROM) ) {
                System.out.println("Firmware upload time: " + ztex.uploadFirmware( "default.ihx", force ) + " ms");
                System.out.println("Firmware upload time: " + ztex.uploadFirmware( "default.ihx", force ) + " ms");
            }
            }
 
 
            for (int i=0; i<args.length; i++ ) {
            for (int i=0; i<args.length; i++ ) {
                if ( args[i].equals("-re") ) {
                if ( args[i].equals("-re") ) {
                    ztex.eepromDisable();
                    ztex.eepromDisable();
                }
                }
                else if ( args[i].equals("-ue") ) {
                else if ( args[i].equals("-ue") ) {
                    System.out.println("Firmware to EEPROM upload time: " + ztex.eepromUpload( "default.ihx", force ) + " ms");
                    System.out.println("Firmware to EEPROM upload time: " + ztex.eepromUpload( "default.ihx", force ) + " ms");
                }
                }
            }
            }
 
 
//          if ( ztex.config!=null ) System.out.println(ztex.config.getName());
//          if ( ztex.config!=null ) System.out.println(ztex.config.getName());
 
 
// generate and upload config data
// generate and upload config data
            if ( variant > 0 )
            if ( variant > 0 )
            {
            {
                ConfigData config = new ConfigData();
                ConfigData config = new ConfigData();
                if ( ! clear  ) {
                if ( ! clear  ) {
                    if ( config.connect(ztex) )
                    if ( config.connect(ztex) )
                        System.out.println("Reading configuration data.");
                        System.out.println("Reading configuration data.");
                    config.disconnect();
                    config.disconnect();
                }
                }
 
 
//              System.out.println("ud[33]="+config.getUserData(33));
//              System.out.println("ud[33]="+config.getUserData(33));
//              config.setUserData(33, (byte) (config.getUserData(33)+1) );
//              config.setUserData(33, (byte) (config.getUserData(33)+1) );
 
 
                if ( variant == 1 ) {
                if ( variant == 1 ) {
                    config.setName("ZTEX USB-FPGA Module", 1, 15, "a");
                    config.setName("ZTEX USB-FPGA Module", 1, 15, "a");
                    config.setFpga("XC6SLX45", "CSG484", "2C");
                    config.setFpga("XC6SLX45", "CSG484", "2C");
                    config.setRam(128,"DDR2-667 SDRAM");
                    config.setRam(128,"DDR2-667 SDRAM");
                }
                }
                else if ( variant == 2 ) {
                else if ( variant == 2 ) {
                    config.setName("ZTEX USB-FPGA Module", 1, 15, "b");
                    config.setName("ZTEX USB-FPGA Module", 1, 15, "b");
                    config.setFpga("XC6SLX75", "CSG484", "3C");
                    config.setFpga("XC6SLX75", "CSG484", "3C");
                    config.setRam(128,"DDR2-800 SDRAM");
                    config.setRam(128,"DDR2-800 SDRAM");
                }
                }
                else if ( variant == 3 ) {
                else if ( variant == 3 ) {
                    config.setName("ZTEX USB-FPGA Module", 1, 15, "c");
                    config.setName("ZTEX USB-FPGA Module", 1, 15, "c");
                    config.setFpga("XC6SLX100", "CSG484", "3C");
                    config.setFpga("XC6SLX100", "CSG484", "3C");
                    config.setRam(128,"DDR2-800 SDRAM");
                    config.setRam(128,"DDR2-800 SDRAM");
                }
                }
                else {
                else {
                    config.setName("ZTEX USB-FPGA Module", 1, 15, "d");
                    config.setName("ZTEX USB-FPGA Module", 1, 15, "d");
                    config.setFpga("XC6SLX150", "CSG484", "3C");
                    config.setFpga("XC6SLX150", "CSG484", "3C");
                    config.setRam(128,"DDR2-800 SDRAM");
                    config.setRam(128,"DDR2-800 SDRAM");
                }
                }
 
 
                System.out.println("Writing configuration data.");
                System.out.println("Writing configuration data.");
                ztex.config=null;
                ztex.config=null;
                ztex.macEepromWrite(0, config.data(), 128);
                ztex.macEepromWrite(0, config.data(), 128);
            }
            }
 
 
 
 
        }
        }
        catch (Exception e) {
        catch (Exception e) {
            System.out.println("Error: "+e.getLocalizedMessage() );
            System.out.println("Error: "+e.getLocalizedMessage() );
        }
        }
        catch (Error e) {
        catch (Error e) {
            System.out.println("Error: "+e.getLocalizedMessage() );
            System.out.println("Error: "+e.getLocalizedMessage() );
        }
        }
    }
    }
 
 
}
}
 
 

powered by: WebSVN 2.1.0

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