1 |
2 |
ZTEX |
/*!
|
2 |
4 |
ZTEX |
lightshow -- lightshow on ZTEX USB-FPGA Module 1.15d plus Experimental Board 1.10
|
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 |
|
|
" -f Force uploads\n" +
|
35 |
|
|
" -p Print bus info\n" +
|
36 |
|
|
" -h This help" );
|
37 |
|
|
|
38 |
|
|
public ParameterException (String msg) {
|
39 |
|
|
super( msg + "\n" + helpMsg );
|
40 |
|
|
}
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
// *****************************************************************************
|
44 |
|
|
// ******* Test0 ***************************************************************
|
45 |
|
|
// *****************************************************************************
|
46 |
|
|
class Lightshow extends Ztex1v1 {
|
47 |
|
|
|
48 |
|
|
// ******* Lightshow ***********************************************************
|
49 |
|
|
// constructor
|
50 |
|
|
public Lightshow ( ZtexDevice1 pDev ) throws UsbException {
|
51 |
|
|
super ( pDev );
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
// ******* main ****************************************************************
|
55 |
|
|
public static void main (String args[]) {
|
56 |
|
|
|
57 |
|
|
int devNum = 0;
|
58 |
|
|
boolean force = false;
|
59 |
|
|
boolean workarounds = false;
|
60 |
|
|
|
61 |
|
|
try {
|
62 |
|
|
// init USB stuff
|
63 |
|
|
LibusbJava.usb_init();
|
64 |
|
|
|
65 |
|
|
// scan the USB bus
|
66 |
|
|
ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
|
67 |
|
|
if ( bus.numberOfDevices() <= 0) {
|
68 |
|
|
System.err.println("No devices found");
|
69 |
|
|
System.exit(0);
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
// scan the command line arguments
|
73 |
|
|
for (int i=0; i<args.length; i++ ) {
|
74 |
|
|
if ( args[i].equals("-d") ) {
|
75 |
|
|
i++;
|
76 |
|
|
try {
|
77 |
|
|
if (i>=args.length) throw new Exception();
|
78 |
|
|
devNum = Integer.parseInt( args[i] );
|
79 |
|
|
}
|
80 |
|
|
catch (Exception e) {
|
81 |
|
|
throw new ParameterException("Device number expected after -d");
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
else if ( args[i].equals("-f") ) {
|
85 |
|
|
force = true;
|
86 |
|
|
}
|
87 |
|
|
else if ( args[i].equals("-p") ) {
|
88 |
|
|
bus.printBus(System.out);
|
89 |
|
|
System.exit(0);
|
90 |
|
|
}
|
91 |
|
|
else if ( args[i].equals("-p") ) {
|
92 |
|
|
bus.printBus(System.out);
|
93 |
|
|
System.exit(0);
|
94 |
|
|
}
|
95 |
|
|
else if ( args[i].equals("-h") ) {
|
96 |
|
|
System.err.println(ParameterException.helpMsg);
|
97 |
|
|
System.exit(0);
|
98 |
|
|
}
|
99 |
|
|
else throw new ParameterException("Invalid Parameter: "+args[i]);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
// create the main class
|
104 |
|
|
Lightshow ztex = new Lightshow ( bus.device(devNum) );
|
105 |
|
|
|
106 |
|
|
// upload the firmware if necessary
|
107 |
|
|
if ( force || ! ztex.valid() || ! ztex.dev().productString().equals("lightshow for EXP-1.10") ) {
|
108 |
|
|
System.out.println("Firmware upload time: " + ztex.uploadFirmware( "lightshow.ihx", force ) + " ms");
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
// check for Experimental Bord 1.10
|
112 |
|
|
if ( ! ztex.xmegaEnabled() )
|
113 |
|
|
throw new Exception("Experimental Board 1.10 required");
|
114 |
|
|
|
115 |
|
|
// upload the bitstream if necessary
|
116 |
|
|
System.out.println("FPGA configuration time: " + ztex.configureFpga( "fpga/lightshow.bit" , true ) + " ms");
|
117 |
|
|
|
118 |
|
|
// bitstream if necessary
|
119 |
|
|
System.out.println("AVR Firmware upload time: " + ztex.xmegaWriteFirmware( new IhxFile("avr/lightshow.ihx" ) ) + " ms");
|
120 |
|
|
|
121 |
|
|
// program the ATxmega
|
122 |
|
|
System.out.println( ztex );
|
123 |
|
|
|
124 |
|
|
}
|
125 |
|
|
catch (Exception e) {
|
126 |
|
|
System.out.println("Error: "+e.getLocalizedMessage() );
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
}
|