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/] [examples/] [usb-fpga-1.2/] [nvmtest/] [NVMTest.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   nvmtest -- ATxmega non volatile memory test on ZTEX USB-FPGA Modules 1.2 plus Experimental Board 1.10
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
                "    -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
// ******* NVMTest *************************************************************
46
// *****************************************************************************
47
class NVMTest extends Ztex1v1 {
48
 
49
// ******* NVMTest *************************************************************
50
// constructor
51
    public NVMTest ( 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
            NVMTest ztex = new NVMTest ( bus.device(devNum) );
109
            ztex.certainWorkarounds = workarounds;
110
 
111
// upload the firmware if necessary
112
            if ( force || ! ztex.valid() || ! ztex.dev().productString().equals("nvmtest for EXP-1.10")  ) {
113
                System.out.println("Firmware upload time: " + ztex.uploadFirmware( "nvmtest.ihx", force ) + " ms");
114
            }
115
 
116
// check for Experimental Bord 1.10
117
            if ( ! ztex.xmegaEnabled() )
118
                throw new Exception("Experimental Board 1.10 required");
119
 
120
// print out some memory information
121
            System.out.println("Flash size: " + ztex.xmegaFlashPages()*ztex.xmegaFlashPageSize() + "   EEPROM size: " + ztex.xmegaEepromPages()*ztex.xmegaEepromPageSize() + "   Error code: " + ztex.xmegaEC );
122
 
123
// read out device ID from production signature row
124
            byte buf[] = new byte[ztex.xmegaFlashPageSize()];
125
 
126
            ztex.xmegaNvmRead ( 0x01000090, buf, 4 );
127
            System.out.println( "Device ID: " + Integer.toHexString(buf[0] & 255) + " " + Integer.toHexString(buf[1] & 255) + " " + Integer.toHexString(buf[2] & 255));
128
 
129
// test ATxmega Flash by reading / writing random data
130
            // generate + write date
131
            Random random = new Random();
132
            for (int i=0; i<ztex.xmegaFlashPageSize(); i++ )
133
                buf[i] = (byte) random.nextInt();
134
            ztex.xmegaFlashPageWrite ( ztex.xmegaFlashPages()*ztex.xmegaFlashPageSize()-1024, buf );
135
 
136
            // read + verify data
137
            byte buf2[] = new byte[ztex.xmegaFlashPageSize()];
138
            ztex.xmegaFlashRead ( ztex.xmegaFlashPages()*ztex.xmegaFlashPageSize()-1024, buf2, ztex.xmegaFlashPageSize());
139
            int j = 0;
140
            for (int i=0; i<ztex.xmegaFlashPageSize(); i++ ) {
141
                if ( buf[i] != buf2[i] ) {
142
                    if ( j<10 )
143
                        System.out.println("Error at " + i +": " + (buf[i] & 255) + " != " + (buf2[i] & 255));
144
                    j+=1;
145
                }
146
            }
147
            System.out.println(j + " Flash Errors");
148
 
149
// test ATxmega EEPROM by reading / writing random data
150
            // generate + write date
151
            random = new Random();
152
            for (int i=0; i<ztex.xmegaEepromPageSize(); i++ )
153
                buf[i] = (byte) random.nextInt();
154
            ztex.xmegaEepromPageWrite ( ztex.xmegaEepromPages()*ztex.xmegaEepromPageSize()-64, buf );
155
 
156
            // read + verify data
157
            ztex.xmegaEepromRead ( ztex.xmegaEepromPages()*ztex.xmegaEepromPageSize()-64, buf2, ztex.xmegaEepromPageSize());
158
            j = 0;
159
            for (int i=0; i<ztex.xmegaEepromPageSize(); i++ ) {
160
                if ( buf[i] != buf2[i] ) {
161
                    if ( j<10 )
162
                        System.out.println("Error at " + i +": " + (buf[i] & 255) + " != " + (buf2[i] & 255));
163
                    j+=1;
164
                }
165
            }
166
            System.out.println(j + " EEPROM Errors");
167
 
168
// test fuse by reading / writing JTAGUID
169
            // read old JTAGUID
170
            int i = ztex.xmegaFuseRead ( 0 );
171
            System.out.print( "JTAGUID: 0x" + Integer.toHexString(i & 255) );
172
            // write + read new JTAGUID
173
            ztex.xmegaFuseWrite ( 0, 0x56 );
174
            System.out.print( " -> 0x"  + Integer.toHexString(ztex.xmegaFuseRead ( 0 ) ) );
175
            // write + read old JTAGUID
176
            ztex.xmegaFuseWrite ( 0, i );
177
            System.out.println( " -> 0x"  + Integer.toHexString(ztex.xmegaFuseRead ( 0 ) ) );
178
 
179
        }
180
        catch (Exception e) {
181
            System.out.println("Error: "+e.getLocalizedMessage() );
182
        }
183
   }
184
 
185
}

powered by: WebSVN 2.1.0

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