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.14/] [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.14
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.14a\n" +
38
                "    -vb          Upload configuration data for USB-FPGA Modules 2.14b\n" +
39
                "    -vc          Upload configuration data for USB-FPGA Modules 2.14c\n" +
40
                "    -vd          Upload configuration data for USB-FPGA Modules 2.14d\n" +
41
                "    -ve          Upload configuration data for USB-FPGA Modules 2.14e\n" +
42
                "    -c           Clear settings from configuration data\n" +
43
                "    -ue          Upload Firmware to Flash\n" +
44
                "    -re          Reset Firmware in Flash\n" +
45
                "    -r           Reset device after uploading\n" +
46
                "    -h           This help" );
47
 
48
    public ParameterException (String msg) {
49
        super( msg + "\n" + helpMsg );
50
    }
51
}
52
 
53
// *****************************************************************************
54
// ******* Default *************************************************************
55
// *****************************************************************************
56
class Default {
57
 
58
// ******* main ****************************************************************
59
    public static void main (String args[]) {
60
 
61
        int devNum = 0;
62
        boolean force = false;
63
        boolean clear = false;
64
        boolean reset = false;
65
        int variant = 0;
66
 
67
        if ( ! System.getProperty("os.name").equalsIgnoreCase("linux") ) {
68
            Runtime.getRuntime().addShutdownHook(new Thread() {
69
                public void run() {
70
                    Scanner s=new Scanner(System.in);
71
                    System.out.println("Press <enter> to continue ...");
72
                    s.nextLine();
73
                }
74
            });
75
        }
76
 
77
        try {
78
// Scan the USB. This also creates and initializes a new USB context.
79
            ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
80
            if ( bus.numberOfDevices() <= 0) {
81
                System.err.println("No devices found");
82
                System.exit(0);
83
            }
84
 
85
// scan the command line arguments
86
            for (int i=0; i<args.length; i++ ) {
87
                if ( args[i].equals("-d") ) {
88
                    i++;
89
                    try {
90
                        if (i>=args.length) throw new Exception();
91
                        devNum = Integer.parseInt( args[i] );
92
                    }
93
                    catch (Exception e) {
94
                        throw new ParameterException("Device number expected after -d");
95
                    }
96
                }
97
                else if ( args[i].equals("-p") ) {
98
                    bus.printBus(System.out);
99
                    System.exit(0);
100
                }
101
                else if ( args[i].equals("-f") ) {
102
                    force = true;
103
                }
104
                else if ( args[i].equals("-va") ) {
105
                    variant = 1;
106
                }
107
                else if ( args[i].equals("-vb") ) {
108
                    variant = 2;
109
                }
110
                else if ( args[i].equals("-vc") ) {
111
                    variant = 3;
112
                }
113
                else if ( args[i].equals("-vd") ) {
114
                    variant = 4;
115
                }
116
                else if ( args[i].equals("-ve") ) {
117
                    variant = 5;
118
                }
119
                else if ( args[i].equals("-c") ) {
120
                    clear = true;
121
                }
122
                else if ( args[i].equals("-r") ) {
123
                    reset = true;
124
                }
125
                else if ( args[i].equals("-h") ) {
126
                    System.err.println(ParameterException.helpMsg);
127
                    System.exit(0);
128
                }
129
                else if ( !args[i].equals("-re") && !args[i].equals("-ue") )
130
                    throw new ParameterException("Invalid Parameter: "+args[i]);
131
            }
132
 
133
// create the main class            
134
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
135
            bus.unref();
136
 
137
// upload the firmware if necessary
138
            if ( force || ! ztex.valid() || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_FX3) || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_FLASH) || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_MAC_EEPROM) ) {
139
                System.out.println("Firmware upload time: " + ztex.uploadFirmware( "default.img", force ) + " ms");
140
            }
141
 
142
            for (int i=0; i<args.length; i++ ) {
143
                if ( args[i].equals("-re") ) {
144
                    ztex.nvDisableFirmware();
145
                }
146
                else if ( args[i].equals("-ue") ) {
147
                    System.out.println("Firmware to NV memory upload time: " + ztex.nvUploadFirmware( "default.img", force ) + " ms");
148
                }
149
            }
150
 
151
            if ( ztex.config!=null ) System.out.println(ztex.config.getName());
152
 
153
// generate and upload config data
154
            if ( variant > 0 )
155
            {
156
                ConfigData config = new ConfigData();
157
                if ( ! clear  ) {
158
                    if ( config.connect(ztex) )
159
                        System.out.println("Reading configuration data.");
160
                    config.disconnect();
161
                }
162
 
163
//              System.out.println("ud[33]="+config.getUserData(33));
164
//              config.setUserData(33, (byte) (config.getUserData(33)+1) );
165
                config.setBitstreamStart(128);  // 512 kByte reserved for firmware
166
 
167
 
168
                if ( variant == 1 ) {
169
                    config.setName("ZTEX USB3-FPGA Module", 2, 14, "a");
170
                    config.setFpga("XC7A15T", "CSG324", "1C");
171
                    config.setRam(256,"DDR3-800 SDRAM");
172
                    config.setMaxBitstreamSize(610);
173
                } else if ( variant == 2 ) {
174
                    config.setName("ZTEX USB3-FPGA Module", 2, 14, "b");
175
                    config.setFpga("XC7A35T", "CSG324", "1C");
176
                    config.setRam(256,"DDR3-800 SDRAM");
177
                    config.setMaxBitstreamSize(610);
178
                } else if ( variant == 3 ) {
179
                    config.setName("ZTEX USB3-FPGA Module", 2, 14, "c");
180
                    config.setFpga("XC7A50T", "CSG324", "1C");
181
                    config.setRam(256,"DDR3-800 SDRAM");
182
                    config.setMaxBitstreamSize(640);
183
                } else if ( variant == 4 ) {
184
                    config.setName("ZTEX USB3-FPGA Module", 2, 14, "d");
185
                    config.setFpga("XC7A75T", "CSG324", "2C");
186
                    config.setRam(256,"DDR3-800 SDRAM");
187
                    config.setMaxBitstreamSize(1136);
188
                } else {
189
                    config.setName("ZTEX USB3-FPGA Module", 2, 14, "e");
190
                    config.setFpga("XC7A100T", "CSG324", "2C");
191
                    config.setRam(256,"DDR3-800 SDRAM");
192
                    config.setMaxBitstreamSize(1136);
193
                }
194
 
195
                System.out.println("Writing configuration data.");
196
                ztex.config=null;
197
                ztex.macEepromWrite(0, config.data(), 128);
198
            }
199
 
200
            if ( reset ) ztex.resetEzUsb();
201
 
202
            ztex.dispose();
203
        }
204
        catch (Exception e) {
205
            System.out.println("Error: "+e.getLocalizedMessage() );
206
        }
207
        catch (Error e) {
208
            System.out.println("Error: "+e.getLocalizedMessage() );
209
        }
210
    }
211
 
212
}

powered by: WebSVN 2.1.0

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