OpenCores
URL https://opencores.org/ocsvn/usb_fpga_2_16/usb_fpga_2_16/trunk

Subversion Repositories usb_fpga_2_16

[/] [usb_fpga_2_16/] [trunk/] [default/] [usb-fpga-1.15/] [Default.java] - Blame information for rev 3

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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