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

powered by: WebSVN 2.1.0

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