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-2.13/] [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.13
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
                "    -va          Upload configuration data for USB-FPGA Modules 2.13a\n" +
37
                "    -vb          Upload configuration data for USB-FPGA Modules 2.13b\n" +
38
                "    -vc          Upload configuration data for USB-FPGA Modules 2.13c\n" +
39
                "    -vd          Upload configuration data for USB-FPGA Modules 2.13d\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
        try {
66
// init USB stuff
67
            LibusbJava.usb_init();
68
 
69
// scan the USB bus
70
            ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
71
            if ( bus.numberOfDevices() <= 0) {
72
                System.err.println("No devices found");
73
                System.exit(0);
74
            }
75
 
76
// scan the command line arguments
77
            for (int i=0; i<args.length; i++ ) {
78
                if ( args[i].equals("-d") ) {
79
                    i++;
80
                    try {
81
                        if (i>=args.length) throw new Exception();
82
                        devNum = Integer.parseInt( args[i] );
83
                    }
84
                    catch (Exception e) {
85
                        throw new ParameterException("Device number expected after -d");
86
                    }
87
                }
88
                else if ( args[i].equals("-p") ) {
89
                    bus.printBus(System.out);
90
                    System.exit(0);
91
                }
92
                else if ( args[i].equals("-f") ) {
93
                    force = true;
94
                }
95
                else if ( args[i].equals("-va") ) {
96
                    variant = 1;
97
                }
98
                else if ( args[i].equals("-vb") ) {
99
                    variant = 2;
100
                }
101
                else if ( args[i].equals("-vc") ) {
102
                    variant = 3;
103
                }
104
                else if ( args[i].equals("-vd") ) {
105
                    variant = 4;
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
 
124
// upload the firmware if necessary
125
            if ( force || ! ztex.valid() || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_EEPROM) || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_MAC_EEPROM) ) {
126
                System.out.println("Firmware upload time: " + ztex.uploadFirmware( "default.ihx", force ) + " ms");
127
            }
128
 
129
            for (int i=0; i<args.length; i++ ) {
130
                if ( args[i].equals("-re") ) {
131
                    ztex.eepromDisable();
132
                }
133
                else if ( args[i].equals("-ue") ) {
134
                    System.out.println("Firmware to EEPROM upload time: " + ztex.eepromUpload( "default.ihx", force ) + " ms");
135
                }
136
            }
137
 
138
//          if ( ztex.config!=null ) System.out.println(ztex.config.getName());
139
 
140
// generate and upload config data
141
            if ( variant > 0 )
142
            {
143
                ConfigData config = new ConfigData();
144
                if ( ! clear  ) {
145
                    if ( config.connect(ztex) )
146
                        System.out.println("Reading configuration data.");
147
                    config.disconnect();
148
                }
149
 
150
//              System.out.println("ud[33]="+config.getUserData(33));
151
//              config.setUserData(33, (byte) (config.getUserData(33)+1) );
152
 
153
                if ( variant == 1 ) {
154
                    config.setName("ZTEX USB-FPGA Module", 2, 13, "a");
155
                    config.setFpga("XC7A35T", "CSG324", "1C");
156
                    config.setRam(256,"DDR3-800 SDRAM");
157
                    config.setMaxBitstreamSize(610);
158
                } else if ( variant == 2 ) {
159
                    config.setName("ZTEX USB-FPGA Module", 2, 13, "b");
160
                    config.setFpga("XC7A50T", "CSG324", "1C");
161
                    config.setRam(256,"DDR3-800 SDRAM");
162
                    config.setMaxBitstreamSize(640);
163
                } else if ( variant == 3 ) {
164
                    config.setName("ZTEX USB-FPGA Module", 2, 13, "c");
165
                    config.setFpga("XC7A75T", "CSG324", "2C");
166
                    config.setRam(256,"DDR3-800 SDRAM");
167
                    config.setMaxBitstreamSize(1130);
168
                } else {
169
                    config.setName("ZTEX USB-FPGA Module", 2, 13, "d");
170
                    config.setFpga("XC7A100T", "CSG324", "2C");
171
                    config.setRam(256,"DDR3-800 SDRAM");
172
                    config.setMaxBitstreamSize(1130);
173
                }
174
 
175
                System.out.println("Writing configuration data.");
176
                ztex.config=null;
177
                ztex.macEepromWrite(0, config.data(), 128);
178
            }
179
 
180
            if ( reset ) ztex.resetEzUsb();
181
 
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.