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

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [default/] [usb-fpga-2.04/] [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 2.04
3
   Copyright (C) 2009-2017 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   Licensed under the Apache License, Version 2.0 (the "License");
7
   you may not use this file except in compliance with the License.
8
   You may obtain a copy of the License at
9
 
10
       http://www.apache.org/licenses/LICENSE-2.0
11
 
12
   Unless required by applicable law or agreed to in writing, software
13
   distributed under the License is distributed on an "AS IS" BASIS,
14
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
   See the License for the specific language governing permissions and
16
   limitations under the License.
17
%*/
18
 
19
import java.io.*;
20
import java.util.*;
21
import java.nio.*;
22
 
23
import org.usb4java.*;
24
 
25
import ztex.*;
26
 
27
// *****************************************************************************
28
// ******* ParameterException **************************************************
29
// *****************************************************************************
30
// Exception the prints a help message
31
class ParameterException extends Exception {
32
    public final static String helpMsg = new String (
33
                "Parameters:\n"+
34
                "    -d <number>  Device Number (default: 0)\n" +
35
                "    -p           Print bus info\n" +
36
                "    -f           Force upload Firmware to RAM\n" +
37
//              "    -va          Upload configuration data for USB-FPGA Modules 2.04a\n" +
38
                "    -vb          Upload configuration data for USB-FPGA Modules 2.04b\n" +
39
//              "    -vc          Upload configuration data for USB-FPGA Modules 2.04b\n" +
40
                "    -c           Clear settings from configuration data\n" +
41
                "    -ue          Upload Firmware to EEPROM\n" +
42
                "    -re          Reset EEPROM Firmware\n" +
43
                "    -r           Reset device after uploading\n" +
44
                "    -h           This help" );
45
 
46
    public ParameterException (String msg) {
47
        super( msg + "\n" + helpMsg );
48
    }
49
}
50
 
51
// *****************************************************************************
52
// ******* Default *************************************************************
53
// *****************************************************************************
54
class Default {
55
 
56
// ******* main ****************************************************************
57
    public static void main (String args[]) {
58
 
59
        int devNum = 0;
60
        boolean force = false;
61
        boolean clear = false;
62
        boolean reset = false;
63
        int variant = 0;
64
 
65
        if ( ! System.getProperty("os.name").equalsIgnoreCase("linux") ) {
66
            Runtime.getRuntime().addShutdownHook(new Thread() {
67
                public void run() {
68
                    Scanner s=new Scanner(System.in);
69
                    System.out.println("Press <enter> to continue ...");
70
                    s.nextLine();
71
                }
72
            });
73
        }
74
 
75
        try {
76
// Scan the USB. This also creates and initializes a new USB context.
77
            ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
78
            if ( bus.numberOfDevices() <= 0) {
79
                System.err.println("No devices found");
80
                System.exit(0);
81
            }
82
 
83
// scan the command line arguments
84
            for (int i=0; i<args.length; i++ ) {
85
                if ( args[i].equals("-d") ) {
86
                    i++;
87
                    try {
88
                        if (i>=args.length) throw new Exception();
89
                        devNum = Integer.parseInt( args[i] );
90
                    }
91
                    catch (Exception e) {
92
                        throw new ParameterException("Device number expected after -d");
93
                    }
94
                }
95
                else if ( args[i].equals("-p") ) {
96
                    bus.printBus(System.out);
97
                    System.exit(0);
98
                }
99
                else if ( args[i].equals("-f") ) {
100
                    force = true;
101
                }
102
                else if ( args[i].equals("-va") ) {
103
                    variant = 1;
104
                }
105
                else if ( args[i].equals("-vb") ) {
106
                    variant = 2;
107
                }
108
                else if ( args[i].equals("-vc") ) {
109
                    variant = 3;
110
                }
111
                else if ( args[i].equals("-c") ) {
112
                    clear = true;
113
                }
114
                else if ( args[i].equals("-r") ) {
115
                    reset = true;
116
                }
117
                else if ( args[i].equals("-h") ) {
118
                    System.err.println(ParameterException.helpMsg);
119
                    System.exit(0);
120
                }
121
                else if ( !args[i].equals("-re") && !args[i].equals("-ue") )
122
                    throw new ParameterException("Invalid Parameter: "+args[i]);
123
            }
124
 
125
// create the main class            
126
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
127
            bus.unref();
128
 
129
// upload the firmware if necessary
130
            if ( force || ! ztex.valid() || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_EEPROM) || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_MAC_EEPROM) ) {
131
                System.out.println("Firmware upload time: " + ztex.uploadFirmware( "default.ihx", force ) + " ms");
132
            }
133
 
134
            for (int i=0; i<args.length; i++ ) {
135
                if ( args[i].equals("-re") ) {
136
                    ztex.nvDisableFirmware();
137
                }
138
                else if ( args[i].equals("-ue") ) {
139
                    System.out.println("Firmware to EEPROM upload time: " + ztex.nvUploadFirmware( "default.ihx", force ) + " ms");
140
                }
141
            }
142
 
143
//          if ( ztex.config!=null ) System.out.println(ztex.config.getName());
144
 
145
// generate and upload config data
146
            if ( variant > 0 )
147
            {
148
                ConfigData config = new ConfigData();
149
                if ( ! clear  ) {
150
                    if ( config.connect(ztex) )
151
                        System.out.println("Reading configuration data.");
152
                    config.disconnect();
153
                }
154
 
155
                if ( variant == 1 ) {
156
                    config.setName("ZTEX USB-FPGA Module", 2, 04, "a");
157
                    config.setFpga("XC6SLX9", "FTG256", "2C");
158
                    config.setMaxBitstreamSize(112);
159
                    config.setRam(64,"DDR-400 SDRAM");
160
                }
161
                else if ( variant == 2 ) {
162
                    config.setName("ZTEX USB-FPGA Module", 2, 04, "b");
163
                    config.setFpga("XC6SLX16", "FTG256", "2C");
164
                    config.setMaxBitstreamSize(160);
165
                    config.setRam(64,"DDR-400 SDRAM");
166
                }
167
                else {
168
                    config.setName("ZTEX USB-FPGA Module", 2, 04, "c");
169
                    config.setFpga("XC6SLX25", "FTG256", "3C");
170
                    config.setMaxBitstreamSize(256);
171
                    config.setRam(64,"DDR-400 SDRAM");
172
                }
173
 
174
                System.out.println("Writing configuration data.");
175
                ztex.config=null;
176
                ztex.macEepromWrite(0, config.data(), 128);
177
            }
178
 
179
            if ( reset ) ztex.resetEzUsb();
180
 
181
            ztex.dispose();  // this also releases clamied interfaces
182
 
183
        }
184
        catch (Exception e) {
185
            System.out.println("Error: "+e.getLocalizedMessage() );
186
        }
187
        catch (Error e) {
188
            System.out.println("Error: "+e.getLocalizedMessage() );
189
        }
190
    }
191
 
192
}

powered by: WebSVN 2.1.0

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