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