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

Subversion Repositories usb_fpga_1_11

[/] [usb_fpga_1_11/] [trunk/] [examples/] [all/] [debug/] [Debug.java] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 ZTEX
/*!
2
   debug -- debug helper example
3 5 ZTEX
   Copyright (C) 2009-2011 ZTEX GmbH.
4 3 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
                "    -w                Enable certain workarounds\n"+
37
                "    -h                This help" );
38
 
39
    public ParameterException (String msg) {
40
        super( msg + "\n" + helpMsg );
41
    }
42
}
43
 
44
// *****************************************************************************
45
// ******* Test0 ***************************************************************
46
// *****************************************************************************
47
class Debug extends Ztex1v1 {
48
 
49
// ******* Debug ***************************************************************
50
// constructor
51
    public Debug ( ZtexDevice1 pDev ) throws UsbException {
52
        super ( pDev );
53
    }
54
 
55
// ******* main ****************************************************************
56
    public static void main (String args[]) {
57
 
58
        int devNum = 0;
59
        boolean force = false;
60
        boolean workarounds = false;
61
 
62
        try {
63
// init USB stuff
64
            LibusbJava.usb_init();
65
 
66
// scan the USB bus
67
            ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
68
            if ( bus.numberOfDevices() <= 0) {
69
                System.err.println("No devices found");
70
                System.exit(0);
71
            }
72
 
73
// scan the command line arguments
74
            for (int i=0; i<args.length; i++ ) {
75
                if ( args[i].equals("-d") ) {
76
                    i++;
77
                    try {
78
                        if (i>=args.length) throw new Exception();
79
                        devNum = Integer.parseInt( args[i] );
80
                    }
81
                    catch (Exception e) {
82
                        throw new ParameterException("Device number expected after -d");
83
                    }
84
                }
85
                else if ( args[i].equals("-f") ) {
86
                    force = true;
87
                }
88
                else if ( args[i].equals("-p") ) {
89
                    bus.printBus(System.out);
90
                    System.exit(0);
91
                }
92
                else if ( args[i].equals("-p") ) {
93
                    bus.printBus(System.out);
94
                    System.exit(0);
95
                }
96
                else if ( args[i].equals("-w") ) {
97
                    workarounds = true;
98
                }
99
                else if ( args[i].equals("-h") ) {
100
                        System.err.println(ParameterException.helpMsg);
101
                        System.exit(0);
102
                }
103
                else throw new ParameterException("Invalid Parameter: "+args[i]);
104
            }
105
 
106
 
107
// create the main class            
108
            Debug ztex = new Debug ( bus.device(devNum) );
109
            ztex.certainWorkarounds = workarounds;
110
 
111
// upload the firmware if necessary
112
            if ( force || ! ztex.valid() || ! ztex.dev().productString().equals("debug for EZ-USB devices")  ) {
113
                System.out.println("Firmware upload time: " + ztex.uploadFirmware( "debug.ihx", force ) + " ms");
114
            }
115
 
116
// claim interface 0
117
            ztex.trySetConfiguration ( 1 );
118
            ztex.claimInterface ( 0 );
119
 
120
// read string from stdin and write it to USB device
121
            byte[] buf = new byte[30];
122
            BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
123
            for (int i=0; i<20; i++ ) {
124
                try {
125
                    Thread.sleep( 2345 );
126
                }
127
                catch ( InterruptedException e) {
128
                }
129
                int j = ztex.debugReadMessages(false,buf);
130
                System.out.print(ztex.debugNewMessages + " new messages: ");
131
                for (int k=0; k<j; k++ ) {
132
                    if (k > 0 ) System.out.print("                ");
133
                    System.out.println( ((buf[k*3] & 255) | ((buf[k*3+1] & 255)<<8)) + (buf[k*3+2] & 255)*0.01 );
134
                }
135
            }
136
 
137
// release interface 0
138
            ztex.releaseInterface(0);
139
 
140
        }
141
        catch (Exception e) {
142
            System.out.println("Error: "+e.getLocalizedMessage() );
143
        }
144
   }
145
 
146
}

powered by: WebSVN 2.1.0

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