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

Subversion Repositories usb_fpga_2_13

[/] [usb_fpga_2_13/] [trunk/] [default/] [usb-fpga-1.15y/] [Default.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   Default firmware and loader for ZTEX USB-FPGA Modules 1.15y
3
   Copyright (C) 2009-2014 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License version 3 as
8
   published by the Free Software Foundation.
9
 
10
   This program is distributed in the hope that it will be useful, but
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
   General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, see http://www.gnu.org/licenses/.
17
!*/
18
 
19
import java.io.*;
20
import java.util.*;
21
 
22
import ch.ntb.usb.*;
23
 
24
import ztex.*;
25
 
26
// *****************************************************************************
27
// ******* ParameterException **************************************************
28
// *****************************************************************************
29
// Exception the prints a help message
30
class ParameterException extends Exception {
31
    public final static String helpMsg = new String (
32
                "Parameters:\n"+
33
                "    -d <number>  Device Number (default: 0)\n" +
34
                "    -p           Print bus info\n" +
35
                "    -f           Force upload Firmware to RAM\n" +
36
                "    -v           Upload configuration data for USB-FPGA Modules 1.15y\n" +
37
                "    -c           Clear settings from configuration data\n" +
38
                "    -ue          Upload Firmware to EEPROM\n" +
39
                "    -re          Reset EEPROM Firmware\n" +
40
                "    -h           This help" );
41
 
42
    public ParameterException (String msg) {
43
        super( msg + "\n" + helpMsg );
44
    }
45
}
46
 
47
// *****************************************************************************
48
// ******* Default *************************************************************
49
// *****************************************************************************
50
class Default {
51
 
52
// ******* main ****************************************************************
53
    public static void main (String args[]) {
54
 
55
        int devNum = 0;
56
        boolean force = false;
57
        boolean clear = false;
58
        int variant = 0;
59
 
60
        try {
61
// init USB stuff
62
            LibusbJava.usb_init();
63
 
64
// scan the USB bus
65
            ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
66
            if ( bus.numberOfDevices() <= 0) {
67
                System.err.println("No devices found");
68
                System.exit(0);
69
            }
70
 
71
// scan the command line arguments
72
            for (int i=0; i<args.length; i++ ) {
73
                if ( args[i].equals("-d") ) {
74
                    i++;
75
                    try {
76
                        if (i>=args.length) throw new Exception();
77
                        devNum = Integer.parseInt( args[i] );
78
                    }
79
                    catch (Exception e) {
80
                        throw new ParameterException("Device number expected after -d");
81
                    }
82
                }
83
                else if ( args[i].equals("-p") ) {
84
                    bus.printBus(System.out);
85
                    System.exit(0);
86
                }
87
                else if ( args[i].equals("-f") ) {
88
                    force = true;
89
                }
90
                else if ( args[i].equals("-v") ) {
91
                    variant = 1;
92
                }
93
                else if ( args[i].equals("-c") ) {
94
                    clear = true;
95
                }
96
                else if ( args[i].equals("-h") ) {
97
                    System.err.println(ParameterException.helpMsg);
98
                    System.exit(0);
99
                }
100
                else if ( !args[i].equals("-re") && !args[i].equals("-ue") )
101
                    throw new ParameterException("Invalid Parameter: "+args[i]);
102
            }
103
 
104
// create the main class            
105
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
106
 
107
// upload the firmware if necessary
108
            if ( force || ! ztex.valid() || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_EEPROM) || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_MAC_EEPROM) ) {
109
                System.out.println("Firmware upload time: " + ztex.uploadFirmware( "default.ihx", force ) + " ms");
110
            }
111
 
112
            for (int i=0; i<args.length; i++ ) {
113
                if ( args[i].equals("-re") ) {
114
                    ztex.eepromDisable();
115
                }
116
                else if ( args[i].equals("-ue") ) {
117
                    System.out.println("Firmware to EEPROM upload time: " + ztex.eepromUpload( "default.ihx", force ) + " ms");
118
                }
119
            }
120
 
121
//          if ( ztex.config!=null ) System.out.println(ztex.config.getName());
122
 
123
// generate and upload config data
124
            if ( variant > 0 )
125
            {
126
                ConfigData config = new ConfigData();
127
                if ( ! clear  ) {
128
                    if ( config.connect(ztex) )
129
                        System.out.println("Reading configuration data.");
130
                    config.disconnect();
131
                }
132
 
133
//              System.out.println("ud[33]="+config.getUserData(33));
134
//              config.setUserData(33, (byte) (config.getUserData(33)+1) );
135
 
136
                config.setName("ZTEX USB-FPGA Module", 1, 15, "y");
137
                config.setFpga("Quad-XC6SLX150", "CSG484", "3NC");
138
 
139
                System.out.println("Writing configuration data.");
140
                ztex.config=null;
141
                ztex.macEepromWrite(0, config.data(), 128);
142
            }
143
 
144
 
145
        }
146
        catch (Exception e) {
147
            System.out.println("Error: "+e.getLocalizedMessage() );
148
        }
149
        catch (Error e) {
150
            System.out.println("Error: "+e.getLocalizedMessage() );
151
        }
152
    }
153
 
154
}

powered by: WebSVN 2.1.0

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