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

Subversion Repositories usb_fpga_2_16

[/] [usb_fpga_2_16/] [trunk/] [java/] [FWLoader/] [FWLoader.java] - Diff between revs 2 and 3

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

Rev 2 Rev 3
/*!
/*!
   Firmware / Bitstream loader for the ZTEX EZ-USB FX2 SDK
   Firmware / Bitstream loader for ZTEX USB-FPGA Modules
   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/.
!*/
!*/
 
 
/*
/*
    Firmware Loader and FPGA Configurater
    Firmware Loader and FPGA Configurater
*/
*/
 
 
import java.io.*;
import java.io.*;
import java.util.*;
import java.util.*;
 
 
import ch.ntb.usb.*;
import ch.ntb.usb.*;
 
 
import ztex.*;
import ztex.*;
 
 
class FWLoader {
class FWLoader {
 
 
// ******* checkSnString *******************************************************
// ******* checkSnString *******************************************************
// make sure that snString is 10 chars long
// make sure that snString is 10 chars long
    private static String checkSnString ( String snString ) {
    private static String checkSnString ( String snString ) {
        if ( snString.length()>10 ) {
        if ( snString.length()>10 ) {
            snString = snString.substring(0,10);
            snString = snString.substring(0,10);
            System.err.println( "Serial number too long (max. 10 characters), truncated to `" + snString + "'" );
            System.err.println( "Serial number too long (max. 10 characters), truncated to `" + snString + "'" );
        }
        }
        while ( snString.length()<10 )
        while ( snString.length()<10 )
            snString = '0' + snString;
            snString = '0' + snString;
        return snString;
        return snString;
    }
    }
 
 
// ******* main ****************************************************************
// ******* main ****************************************************************
    public static void main (String args[]) {
    public static void main (String args[]) {
        LibusbJava.usb_init();
        LibusbJava.usb_init();
 
 
        final String helpMsg = new String (
        final String helpMsg = new String (
                        "Global parameters:\n"+
                        "Global parameters:\n"+
                        "    -c               Scan for Cypress EZ-USB devices without ZTEX firmware\n"+
                        "    -c               Scan for Cypress EZ-USB devices without ZTEX firmware\n"+
                        "    -v <VID> <PID>   Scan for devices with given Vendor ID and Product ID\n"+
                        "    -v <VID> <PID>   Scan for devices with given Vendor ID and Product ID\n"+
                        "    -vc              Equal to -v 0x4b4 0x8613\n"+
                        "    -vc              Equal to -v 0x4b4 0x8613\n"+
                        "    -s <sn string>   Only scan for devices with that serial number\n"+
                        "    -s <sn string>   Only scan for devices with that serial number\n"+
                        "    -d <number>      Device Number (default: 0, use -p to get a list)\n"+
                        "    -d <number>      Device Number (default: 0, use -p to get a list)\n"+
                        "    -f               Force uploads\n"+
                        "    -f               Force uploads\n"+
                        "    -p               Print a list of available devices\n"+
                        "    -p               Print a list of available devices\n"+
                        "    -w               Enable certain workarounds\n"+
                        "    -w               Enable certain workarounds\n"+
                        "    -h               This help \n\n"+
                        "    -h               This help \n\n"+
                        "Ordered parameters:\n"+
                        "Ordered parameters:\n"+
                        "    -i               Print device info\n"+
                        "    -i               Print device info\n"+
                        "    -ii              Print device info + capabilities\n"+
                        "    -ii              Print device info + capabilities\n"+
                        "    -if              Print FPGA state\n"+
                        "    -if              Print FPGA state\n"+
                        "    -ic              Print configuration data and flash info\n"+
                        "    -ic              Print configuration data and flash info\n"+
                        "    -ss <sn string>  Set the serial number, \n"+
                        "    -ss <sn string>  Set the serial number, \n"+
                        "                     used with -uu or -ue or if configuration data present\n"+
                        "                     used with -uu or -ue or if configuration data present\n"+
                        "    -ru              Reset EZ-USB Microcontroller\n"+
                        "    -ru              Reset EZ-USB Microcontroller\n"+
                        "    -uu <ihx file>   Upload EZ-USB Firmware\n"+
                        "    -uu <ihx file>   Upload EZ-USB Firmware\n"+
                        "    -bs 0|1|A        Bit swapping for bitstreams: 0: disable, 1: enable, A: automatic detection\n"+
                        "    -bs 0|1|A        Bit swapping for bitstreams: 0: disable, 1: enable, A: automatic detection\n"+
                        "    -rf              Reset FPGA\n"+
                        "    -rf              Reset FPGA\n"+
                        "    -uf <bitstream>  Upload bitstream to FPGA\n"+
                        "    -uf <bitstream>  Upload bitstream to FPGA\n"+
                        "    -sf <number>     Select FPGA (default: 0)\n"+
                        "    -sf <number>     Select FPGA (default: 0)\n"+
                        "    -re              Reset EEPROM Firmware\n"+
                        "    -re              Reset EEPROM Firmware\n"+
                        "    -ue <ihx file>   Upload Firmware to EEPROM\n"+
                        "    -ue <ihx file>   Upload Firmware to EEPROM\n"+
                        "    -rm              Reset bitstream in Flash\n"+
                        "    -rm              Reset bitstream in Flash\n"+
                        "    -um <bitstream>  Upload bitstream to Flash\n"+
                        "    -um <bitstream>  Upload bitstream to Flash\n"+
                        "    -uxf <ihx file>  Upload Firmware / data  to ATxmega Flash\n"+
                        "    -uxf <ihx file>  Upload Firmware / data  to ATxmega Flash\n"+
                        "    -uxe <ihx file>  Upload data to ATxmega EEPROM\n"+
                        "    -uxe <ihx file>  Upload data to ATxmega EEPROM\n"+
                        "    -rxf <index>     Read ATxmega Fuse\n" +
                        "    -rxf <index>     Read ATxmega Fuse\n" +
                        "    -wxf <index> <bitmask> <value>  Write ATxmega Fuse\n" +
                        "    -wxf <index> <bitmask> <value>  Write ATxmega Fuse\n" +
                        "Serial number strings (<sn string>) must be 10 chars long, if shorter filled with 0's." );
                        "Serial number strings (<sn string>) must be 10 chars long, if shorter filled with 0's." );
 
 
// process global parameters
// process global parameters
        try {
        try {
 
 
            int usbVendorId = ZtexDevice1.ztexVendorId;
            int usbVendorId = ZtexDevice1.ztexVendorId;
            int usbProductId = -1;
            int usbProductId = -1;
            boolean cypress = false;
            boolean cypress = false;
            int devNum = 0;
            int devNum = 0;
            boolean forceUpload = false;
            boolean forceUpload = false;
            boolean printBus = false;
            boolean printBus = false;
            boolean workarounds = false;
            boolean workarounds = false;
            String snString = null;
            String snString = null;
            int bs = -1;
            int bs = -1;
 
 
            if ( args.length == 0 ) {
            if ( args.length == 0 ) {
                    System.err.println(helpMsg);
                    System.err.println(helpMsg);
                    System.exit(1);
                    System.exit(1);
            }
            }
 
 
            for (int i=0; i<args.length; i++ ) {
            for (int i=0; i<args.length; i++ ) {
                if ( args[i].equals("-c") ) {
                if ( args[i].equals("-c") ) {
                    cypress = true;
                    cypress = true;
                }
                }
                else if ( args[i].equals("-v") ) {
                else if ( args[i].equals("-v") ) {
                    i++;
                    i++;
                    try {
                    try {
                        if (i>=args.length)
                        if (i>=args.length)
                            throw new Exception();
                            throw new Exception();
                        usbVendorId = Integer.decode( args[i] );
                        usbVendorId = Integer.decode( args[i] );
                    }
                    }
                    catch (Exception e) {
                    catch (Exception e) {
                        System.err.println("Error: Vendor ID expected after -v");
                        System.err.println("Error: Vendor ID expected after -v");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    i++;
                    i++;
                    try {
                    try {
                        if (i>=args.length)
                        if (i>=args.length)
                            throw new Exception();
                            throw new Exception();
                        usbProductId = Integer.decode( args[i] );
                        usbProductId = Integer.decode( args[i] );
                    }
                    }
                    catch (Exception e) {
                    catch (Exception e) {
                        System.err.println("Error: Product ID expected after -v <VID>");
                        System.err.println("Error: Product ID expected after -v <VID>");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                }
                }
                else if ( args[i].equals("-vc") ) {
                else if ( args[i].equals("-vc") ) {
                    usbVendorId = ZtexDevice1.cypressVendorId;
                    usbVendorId = ZtexDevice1.cypressVendorId;
                    usbProductId = ZtexDevice1.cypressProductId;
                    usbProductId = ZtexDevice1.cypressProductId;
                }
                }
                else if ( args[i].equals("-f") ) {
                else if ( args[i].equals("-f") ) {
                    forceUpload = true;
                    forceUpload = true;
                }
                }
                else if ( args[i].equals("-p") ) {
                else if ( args[i].equals("-p") ) {
                    printBus = true;
                    printBus = true;
                }
                }
                else if ( args[i].equals("-w") ) {
                else if ( args[i].equals("-w") ) {
                    workarounds = true;
                    workarounds = true;
                }
                }
                else if ( args[i].equals("-d") ) {
                else if ( args[i].equals("-d") ) {
                    i++;
                    i++;
                    try {
                    try {
                        if (i>=args.length)
                        if (i>=args.length)
                            throw new Exception();
                            throw new Exception();
                        devNum = Integer.parseInt( args[i] );
                        devNum = Integer.parseInt( args[i] );
                    }
                    }
                    catch (Exception e) {
                    catch (Exception e) {
                        System.err.println("Error: Device number expected after -d");
                        System.err.println("Error: Device number expected after -d");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                }
                }
                else if ( args[i].equals("-s") ) {
                else if ( args[i].equals("-s") ) {
                    i++;
                    i++;
                    if (i>=args.length) {
                    if (i>=args.length) {
                        System.err.println("Error: String expected after -s");
                        System.err.println("Error: String expected after -s");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    snString = checkSnString(args[i]);
                    snString = checkSnString(args[i]);
                }
                }
                else if ( args[i].equals("-h") ) {
                else if ( args[i].equals("-h") ) {
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(0);
                        System.exit(0);
                }
                }
                else if ( args[i].equals("-i") || args[i].equals("-ii") || args[i].equals("-if") || args[i].equals("-ic") || args[i].equals("-ru") || args[i].equals("-rf") || args[i].equals("-re") || args[i].equals("-rm") ) {
                else if ( args[i].equals("-i") || args[i].equals("-ii") || args[i].equals("-if") || args[i].equals("-ic") || args[i].equals("-ru") || args[i].equals("-rf") || args[i].equals("-re") || args[i].equals("-rm") ) {
                }
                }
                else if ( args[i].equals("-uu") || args[i].equals("-uf") || args[i].equals("-sf") || args[i].equals("-ue") || args[i].equals("-um") || args[i].equals("-bs") || args[i].equals("-uxf")  || args[i].equals("-uxe") || args[i].equals("-rxf") || args[i].equals("-ss")) {
                else if ( args[i].equals("-uu") || args[i].equals("-uf") || args[i].equals("-sf") || args[i].equals("-ue") || args[i].equals("-um") || args[i].equals("-bs") || args[i].equals("-uxf")  || args[i].equals("-uxe") || args[i].equals("-rxf") || args[i].equals("-ss")) {
                    i+=1;
                    i+=1;
                }
                }
                else if ( args[i].equals("-wxf")  ) {
                else if ( args[i].equals("-wxf")  ) {
                    i+=3;
                    i+=3;
                }
                }
                else {
                else {
                    System.err.println("Error: Invalid Parameter: "+args[i]);
                    System.err.println("Error: Invalid Parameter: "+args[i]);
                    System.err.println(helpMsg);
                    System.err.println(helpMsg);
                    System.exit(1);
                    System.exit(1);
                }
                }
            }
            }
 
 
// process ordered parameters
// process ordered parameters
            ZtexScanBus1 bus = new ZtexScanBus1( usbVendorId, usbProductId, cypress, false, 1, snString);
            ZtexScanBus1 bus = new ZtexScanBus1( usbVendorId, usbProductId, cypress, false, 1, snString);
            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);
            }
            }
            if ( printBus )
            if ( printBus )
                bus.printBus(System.out);
                bus.printBus(System.out);
 
 
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
            ztex.certainWorkarounds = workarounds;
            ztex.certainWorkarounds = workarounds;
 
 
            snString = null;
            snString = null;
            for (int i=0; i<args.length; i++ ) {
            for (int i=0; i<args.length; i++ ) {
                if ( args[i].equals("-i") ) {
                if ( args[i].equals("-i") ) {
                    System.out.println( ztex );
                    System.out.println( ztex );
                }
                }
                if ( args[i].equals("-ii") ) {
                if ( args[i].equals("-ii") ) {
                    System.out.println( ztex );
                    System.out.println( ztex );
                    String str = ztex.capabilityInfo("\n      ");
                    String str = ztex.capabilityInfo("\n      ");
                    if ( str.equals("") ) {
                    if ( str.equals("") ) {
                        System.out.println( "   No capabilities");
                        System.out.println( "   No capabilities");
                    }
                    }
                    else {
                    else {
                        System.out.println( "   Capabilities:\n      "+str);
                        System.out.println( "   Capabilities:\n      "+str);
                    }
                    }
                }
                }
                if ( args[i].equals("-if") ) {
                if ( args[i].equals("-if") ) {
                    ztex.printFpgaState();
                    ztex.printFpgaState();
                }
                }
                if ( args[i].equals("-ic") ) {
                if ( args[i].equals("-ic") ) {
                    if ( ztex.config != null ) {
                    if ( ztex.config != null ) {
                        System.out.println("ZTEX Product: " + ztex.config.getName());
                        System.out.println("ZTEX Product: " + ztex.config.getName());
                        System.out.println("FPGA: " + ztex.config.getFpga());
                        System.out.println("FPGA: " + ztex.config.getFpga());
                        if (ztex.config.getRamSize()>0)  System.out.println("RAM: " + (ztex.config.getRamSize() >> 20) + " MByte " + ztex.config.getRamType());
                        if (ztex.config.getRamSize()>0)  System.out.println("RAM: " + (ztex.config.getRamSize() >> 20) + " MByte " + ztex.config.getRamType());
                    }
                    }
                    else {
                    else {
                        System.out.println("(No configuration data found)");
                        System.out.println("(No configuration data found)");
                    }
                    }
                    String s = ztex.flashInfo(); if ( s.length()>0 ) System.out.println("Flash: " + s);
                    String s = ztex.flashInfo(); if ( s.length()>0 ) System.out.println("Flash: " + s);
                }
                }
                else if ( args[i].equals("-ss") ) {
                else if ( args[i].equals("-ss") ) {
                    i++;
                    i++;
                    if ( i >= args.length ) {
                    if ( i >= args.length ) {
                        System.err.println("Error: String expected after -ss");
                        System.err.println("Error: String expected after -ss");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    snString = checkSnString(args[i]);
                    snString = checkSnString(args[i]);
                    if ( ztex.config != null ) {
                    if ( ztex.config != null ) {
                        ztex.config.setSN(snString);
                        ztex.config.setSN(snString);
                    }
                    }
                }
                }
                else if ( args[i].equals("-ru") ) {
                else if ( args[i].equals("-ru") ) {
                    ztex.resetEzUsb();
                    ztex.resetEzUsb();
                }
                }
                else if ( args[i].equals("-uu") ) {
                else if ( args[i].equals("-uu") ) {
                    i++;
                    i++;
                    if ( i >= args.length ) {
                    if ( i >= args.length ) {
                        System.err.println("Error: Filename expected after -uu");
                        System.err.println("Error: Filename expected after -uu");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    ZtexIhxFile1 ihxFile = new ZtexIhxFile1( args[i] );
                    ZtexIhxFile1 ihxFile = new ZtexIhxFile1( args[i] );
                    if ( snString != null )
                    if ( snString != null )
                        ihxFile.setSnString( snString );
                        ihxFile.setSnString( snString );
                    System.out.println("Firmware upload time: " + ztex.uploadFirmware( ihxFile, forceUpload ) + " ms");
                    System.out.println("Firmware upload time: " + ztex.uploadFirmware( ihxFile, forceUpload ) + " ms");
                }
                }
                else if ( args[i].equals("-bs") ) {
                else if ( args[i].equals("-bs") ) {
                    i++;
                    i++;
                    if ( (i>=args.length) || !( args[i].equals("0") || args[i].equals("1") || args[i].equalsIgnoreCase("A") ) ) {
                    if ( (i>=args.length) || !( args[i].equals("0") || args[i].equals("1") || args[i].equalsIgnoreCase("A") ) ) {
                        System.err.println("Error: `0',`1' or `A' expected after -bs");
                        System.err.println("Error: `0',`1' or `A' expected after -bs");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    if ( args[i].equals("0") )
                    if ( args[i].equals("0") )
                        bs = 0;
                        bs = 0;
                    else if ( args[i].equals("1") )
                    else if ( args[i].equals("1") )
                        bs = 1;
                        bs = 1;
                    else bs = -1;
                    else bs = -1;
                }
                }
                else if ( args[i].equals("-rf") ) {
                else if ( args[i].equals("-rf") ) {
                    ztex.resetFpga();
                    ztex.resetFpga();
                }
                }
                else if ( args[i].equals("-uf") ) {
                else if ( args[i].equals("-uf") ) {
                    i++;
                    i++;
                    if ( i >= args.length ) {
                    if ( i >= args.length ) {
                        System.err.println("Error: Filename expected after -uf");
                        System.err.println("Error: Filename expected after -uf");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    System.out.println("FPGA configuration time: " + ztex.configureFpga( args[i], forceUpload, bs ) + " ms");
                    System.out.println("FPGA configuration time: " + ztex.configureFpga( args[i], forceUpload, bs ) + " ms");
                }
                }
                else if ( args[i].equals("-sf") ) {
                else if ( args[i].equals("-sf") ) {
                    i++;
                    i++;
                    int fn=-1;
                    int fn=-1;
                    try {
                    try {
                        if (i>=args.length)
                        if (i>=args.length)
                            throw new Exception();
                            throw new Exception();
                        fn = Integer.parseInt( args[i] );
                        fn = Integer.parseInt( args[i] );
                    }
                    }
                    catch (Exception e) {
                    catch (Exception e) {
                        System.err.println("Error: Number expected after -sf");
                        System.err.println("Error: Number expected after -sf");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    if ( fn >= 0 ) {
                    if ( fn >= 0 ) {
                        ztex.selectFpga(fn);
                        ztex.selectFpga(fn);
                    }
                    }
                }
                }
                else if ( args[i].equals("-re") ) {
                else if ( args[i].equals("-re") ) {
                    ztex.eepromDisable();
                    ztex.eepromDisable();
                }
                }
                else if ( args[i].equals("-ue") ) {
                else if ( args[i].equals("-ue") ) {
                    i++;
                    i++;
                    if ( i >= args.length ) {
                    if ( i >= args.length ) {
                        System.err.println("Error: Filename expected after -ue");
                        System.err.println("Error: Filename expected after -ue");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    ZtexIhxFile1 ihxFile = new ZtexIhxFile1( args[i] );
                    ZtexIhxFile1 ihxFile = new ZtexIhxFile1( args[i] );
                    if ( snString != null )
                    if ( snString != null )
                        ihxFile.setSnString(snString);
                        ihxFile.setSnString(snString);
                    System.out.println("Firmware to EEPROM upload time: " + ztex.eepromUpload( ihxFile, forceUpload ) + " ms");
                    System.out.println("Firmware to EEPROM upload time: " + ztex.eepromUpload( ihxFile, forceUpload ) + " ms");
                }
                }
                else if ( args[i].equals("-rm") ) {
                else if ( args[i].equals("-rm") ) {
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
                    ztex.flashResetBitstream();
                    ztex.flashResetBitstream();
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
                }
                }
                else if ( args[i].equals("-um") ) {
                else if ( args[i].equals("-um") ) {
                    i++;
                    i++;
                    if ( i >= args.length ) {
                    if ( i >= args.length ) {
                        System.err.println("Error: Filename expected after -um");
                        System.err.println("Error: Filename expected after -um");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
                    System.out.println("FPGA configuration time: " + ztex.flashUploadBitstream( args[i], bs ) + " ms");
                    System.out.println("FPGA configuration time: " + ztex.flashUploadBitstream( args[i], bs ) + " ms");
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
                }
                }
                else if ( args[i].equals("-uxf") ) {
                else if ( args[i].equals("-uxf") ) {
                    i++;
                    i++;
                    if ( i >= args.length ) {
                    if ( i >= args.length ) {
                        System.err.println("Error: Filename expected after -uxf");
                        System.err.println("Error: Filename expected after -uxf");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    System.out.println("Firmware to ATxmega Flash upload time: " + ztex.xmegaWriteFirmware( new IhxFile(args[i]) ) + " ms");
                    System.out.println("Firmware to ATxmega Flash upload time: " + ztex.xmegaWriteFirmware( new IhxFile(args[i]) ) + " ms");
                }
                }
                else if ( args[i].equals("-uxe") ) {
                else if ( args[i].equals("-uxe") ) {
                    i++;
                    i++;
                    if ( i >= args.length ) {
                    if ( i >= args.length ) {
                        System.err.println("Error: Filename expected after -uxe");
                        System.err.println("Error: Filename expected after -uxe");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    System.out.println("Firmware to ATxmega Flash upload time: " + ztex.xmegaWriteEeprom( new IhxFile(args[i]) ) + " ms");
                    System.out.println("Firmware to ATxmega Flash upload time: " + ztex.xmegaWriteEeprom( new IhxFile(args[i]) ) + " ms");
                }
                }
                else if ( args[i].equals("-rxf") ) {
                else if ( args[i].equals("-rxf") ) {
                    i++;
                    i++;
                    int j = 0;
                    int j = 0;
                    try {
                    try {
                        if (i>=args.length)
                        if (i>=args.length)
                            throw new Exception();
                            throw new Exception();
                        j = Integer.parseInt( args[i] );
                        j = Integer.parseInt( args[i] );
                    }
                    }
                    catch (Exception e) {
                    catch (Exception e) {
                        System.err.println("Error: Index number expected after -rxf");
                        System.err.println("Error: Index number expected after -rxf");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    System.out.println("Fuse " + j + ": 0b" + Integer.toBinaryString(256 | ztex.xmegaFuseRead ( j )).substring(1));
                    System.out.println("Fuse " + j + ": 0b" + Integer.toBinaryString(256 | ztex.xmegaFuseRead ( j )).substring(1));
                }
                }
                else if ( args[i].equals("-wxf") ) {
                else if ( args[i].equals("-wxf") ) {
                    i++;
                    i++;
                    int j=0, k=0, l=0;
                    int j=0, k=0, l=0;
                    try {
                    try {
                        if (i>=args.length)
                        if (i>=args.length)
                            throw new Exception();
                            throw new Exception();
                        j = Integer.parseInt( args[i] );
                        j = Integer.parseInt( args[i] );
                    }
                    }
                    catch (Exception e) {
                    catch (Exception e) {
                        System.err.println("Error: Index number expected after -wxf");
                        System.err.println("Error: Index number expected after -wxf");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    i++;
                    i++;
                    try {
                    try {
                        if (i>=args.length)
                        if (i>=args.length)
                            throw new Exception();
                            throw new Exception();
                        k = Integer.parseInt( args[i] );
                        k = Integer.parseInt( args[i] );
                    }
                    }
                    catch (Exception e) {
                    catch (Exception e) {
                        System.err.println("Error: Bitmask expected after -wxf <index>");
                        System.err.println("Error: Bitmask expected after -wxf <index>");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    i++;
                    i++;
                    try {
                    try {
                        if (i>=args.length)
                        if (i>=args.length)
                            throw new Exception();
                            throw new Exception();
                        l = Integer.parseInt( args[i] );
                        l = Integer.parseInt( args[i] );
                    }
                    }
                    catch (Exception e) {
                    catch (Exception e) {
                        System.err.println("Error: Value expected after -wxf <index> <bitmask>");
                        System.err.println("Error: Value expected after -wxf <index> <bitmask>");
                        System.err.println(helpMsg);
                        System.err.println(helpMsg);
                        System.exit(1);
                        System.exit(1);
                    }
                    }
                    ztex.xmegaFuseWrite( j, (ztex.xmegaFuseRead(j) & ~k) | l );
                    ztex.xmegaFuseWrite( j, (ztex.xmegaFuseRead(j) & ~k) | l );
                }
                }
            }
            }
        }
        }
        catch (Exception e) {
        catch (Exception 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.