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.01/] [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.16
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.01a\n" +
37
                "    -vb          Upload configuration data for USB-FPGA Modules 2.01b\n" +
38
//              "    -vc          Upload configuration data for USB-FPGA Modules 2.01b\n" +
39
                "    -c           Clear settings from configuration data\n" +
40
                "    -ue          Upload Firmware to EEPROM\n" +
41
                "    -re          Reset EEPROM Firmware\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
        try {
65
// init USB stuff
66
            LibusbJava.usb_init();
67
 
68
// scan the USB bus
69
            ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
70
            if ( bus.numberOfDevices() <= 0) {
71
                System.err.println("No devices found");
72
                System.exit(0);
73
            }
74
 
75
// scan the command line arguments
76
            for (int i=0; i<args.length; i++ ) {
77
                if ( args[i].equals("-d") ) {
78
                    i++;
79
                    try {
80
                        if (i>=args.length) throw new Exception();
81
                        devNum = Integer.parseInt( args[i] );
82
                    }
83
                    catch (Exception e) {
84
                        throw new ParameterException("Device number expected after -d");
85
                    }
86
                }
87
                else if ( args[i].equals("-p") ) {
88
                    bus.printBus(System.out);
89
                    System.exit(0);
90
                }
91
                else if ( args[i].equals("-f") ) {
92
                    force = true;
93
                }
94
                else if ( args[i].equals("-va") ) {
95
                    variant = 1;
96
                }
97
                else if ( args[i].equals("-vb") ) {
98
                    variant = 2;
99
                }
100
                else if ( args[i].equals("-vc") ) {
101
                    variant = 3;
102
                }
103
                else if ( args[i].equals("-c") ) {
104
                    clear = true;
105
                }
106
                else if ( args[i].equals("-r") ) {
107
                    reset = true;
108
                }
109
                else if ( args[i].equals("-h") ) {
110
                    System.err.println(ParameterException.helpMsg);
111
                    System.exit(0);
112
                }
113
                else if ( !args[i].equals("-re") && !args[i].equals("-ue") )
114
                    throw new ParameterException("Invalid Parameter: "+args[i]);
115
            }
116
 
117
// create the main class            
118
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
119
 
120
// upload the firmware if necessary
121
            if ( force || ! ztex.valid() || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_EEPROM) || ! ztex.InterfaceCapabilities(ztex.CAPABILITY_MAC_EEPROM) ) {
122
                System.out.println("Firmware upload time: " + ztex.uploadFirmware( "default.ihx", force ) + " ms");
123
            }
124
 
125
            for (int i=0; i<args.length; i++ ) {
126
                if ( args[i].equals("-re") ) {
127
                    ztex.eepromDisable();
128
                }
129
                else if ( args[i].equals("-ue") ) {
130
                    System.out.println("Firmware to EEPROM upload time: " + ztex.eepromUpload( "default.ihx", force ) + " ms");
131
                }
132
            }
133
 
134
//          if ( ztex.config!=null ) System.out.println(ztex.config.getName());
135
 
136
// generate and upload config data
137
            if ( variant > 0 )
138
            {
139
                ConfigData config = new ConfigData();
140
                if ( ! clear  ) {
141
                    if ( config.connect(ztex) )
142
                        System.out.println("Reading configuration data.");
143
                    config.disconnect();
144
                }
145
 
146
                if ( variant == 1 ) {
147
                    config.setName("ZTEX USB-FPGA Module", 2, 01, "a");
148
                    config.setFpga("XC6SLX9", "FTG256", "2C");
149
                    config.setMaxBitstreamSize(110);
150
                }
151
                else if ( variant == 2 ) {
152
                    config.setName("ZTEX USB-FPGA Module", 2, 01, "b");
153
                    config.setFpga("XC6SLX16", "FTG256", "2C");
154
                    config.setMaxBitstreamSize(150);
155
                }
156
                else {
157
                    config.setName("ZTEX USB-FPGA Module", 2, 01, "c");
158
                    config.setFpga("XC6SLX25", "FTG256", "3C");
159
                    config.setMaxBitstreamSize(250);
160
                }
161
 
162
                System.out.println("Writing configuration data.");
163
                ztex.config=null;
164
                ztex.macEepromWrite(0, config.data(), 128);
165
            }
166
 
167
            if ( reset ) ztex.resetEzUsb();
168
 
169
 
170
        }
171
        catch (Exception e) {
172
            System.out.println("Error: "+e.getLocalizedMessage() );
173
        }
174
        catch (Error e) {
175
            System.out.println("Error: "+e.getLocalizedMessage() );
176
        }
177
    }
178
 
179
}

powered by: WebSVN 2.1.0

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