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

Subversion Repositories usb_fpga_1_2

[/] [usb_fpga_1_2/] [trunk/] [java/] [ztex/] [ZtexIhxFile1.java] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   Java Driver API for the ZTEX Firmware Kit
3
   Copyright (C) 2008-2009 ZTEX e.K.
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
/*
20
    Reads an ihx file with ZTEX descriptor 1
21
*/
22
package ztex;
23
 
24
import java.io.*;
25
import java.util.*;
26
 
27
public class ZtexIhxFile1 extends IhxFile {
28
    private static final int defaultZtexDescriptorOffs = 0x6c;
29
 
30
    private int ztexDescriptorOffs = defaultZtexDescriptorOffs;
31
 
32
    private byte productId[] = { 0,0,0,0 }; // product ID from the ZTEX descpriptor, not the USB product ID
33
    private byte fwVersion = 0;
34
    private byte interfaceVersion = 0;
35
    private byte interfaceCapabilities[] = { 0,0,0,0, 0,0 };
36
    private byte moduleReserved[] = { 0,0,0,0, 0,0,0,0, 0,0,0,0 };
37
    private char snString[] = new char[10];
38
 
39
// ******* ZtexIhxFile1 ********************************************************
40
    public ZtexIhxFile1( String fileName, int pZtexDescriptorOffs ) throws IOException, IhxFileDamagedException, IncompatibleFirmwareException {
41
        super( fileName );
42
 
43
        ztexDescriptorOffs = pZtexDescriptorOffs;
44
 
45
        if ( ihxData[ztexDescriptorOffs]!=40 || ihxData[ztexDescriptorOffs+1]!=1 || ihxData[ztexDescriptorOffs+2]!='Z' || ihxData[ztexDescriptorOffs+3]!='T' || ihxData[ztexDescriptorOffs+4]!='E' || ihxData[ztexDescriptorOffs+5]!='X' )
46
            throw new IncompatibleFirmwareException( "Invalid ZTEX descriptor" );
47
 
48
        productId[0] = (byte) ihxData[ztexDescriptorOffs+6];
49
        productId[1] = (byte) ihxData[ztexDescriptorOffs+7];
50
        productId[2] = (byte) ihxData[ztexDescriptorOffs+8];
51
        productId[3] = (byte) ihxData[ztexDescriptorOffs+9];
52
        fwVersion = (byte) ihxData[ztexDescriptorOffs+10];
53
        interfaceVersion = (byte) ihxData[ztexDescriptorOffs+11];
54
        interfaceCapabilities[0] = (byte) ihxData[ztexDescriptorOffs+12];
55
        interfaceCapabilities[1] = (byte) ihxData[ztexDescriptorOffs+13];
56
        interfaceCapabilities[2] = (byte) ihxData[ztexDescriptorOffs+14];
57
        interfaceCapabilities[3] = (byte) ihxData[ztexDescriptorOffs+15];
58
        interfaceCapabilities[4] = (byte) ihxData[ztexDescriptorOffs+16];
59
        interfaceCapabilities[5] = (byte) ihxData[ztexDescriptorOffs+17];
60
        moduleReserved[0] = (byte) ihxData[ztexDescriptorOffs+18];
61
        moduleReserved[1] = (byte) ihxData[ztexDescriptorOffs+19];
62
        moduleReserved[2] = (byte) ihxData[ztexDescriptorOffs+20];
63
        moduleReserved[3] = (byte) ihxData[ztexDescriptorOffs+21];
64
        moduleReserved[4] = (byte) ihxData[ztexDescriptorOffs+22];
65
        moduleReserved[5] = (byte) ihxData[ztexDescriptorOffs+23];
66
        moduleReserved[6] = (byte) ihxData[ztexDescriptorOffs+24];
67
        moduleReserved[7] = (byte) ihxData[ztexDescriptorOffs+25];
68
        moduleReserved[8] = (byte) ihxData[ztexDescriptorOffs+26];
69
        moduleReserved[9] = (byte) ihxData[ztexDescriptorOffs+27];
70
        moduleReserved[10] = (byte) ihxData[ztexDescriptorOffs+28];
71
        moduleReserved[11] = (byte) ihxData[ztexDescriptorOffs+29];
72
 
73
        for (int i=0; i<10; i++ ) {
74
            int b = ihxData[ztexDescriptorOffs+30+i];
75
            if ( b>=0 && b<=255 ) {
76
                snString[i] = (char) b;
77
            }
78
            else {
79
                throw new IncompatibleFirmwareException( "Invalid serial number string" );
80
            }
81
        }
82
 
83
        // ensure word bounded upload data
84
        for ( int i=0; i+1<ihxData.length; i+=2 )
85
            if ( ihxData[i]<0 && ihxData[i+1]>=0 )
86
                ihxData[i] = 0;
87
    }
88
 
89
    public ZtexIhxFile1( String fileName ) throws IOException, IhxFileDamagedException, IncompatibleFirmwareException {
90
        this( fileName, defaultZtexDescriptorOffs );
91
    }
92
 
93
// ******* productId ***********************************************************
94
    public final byte[] productId() {
95
        return productId;
96
    }
97
 
98
    public int productId( int i ) {
99
        return productId[i] & 255;
100
    }
101
 
102
// ******* fwVersion ***********************************************************
103
    public final int fwVersion() {
104
        return fwVersion & 255;
105
    }
106
 
107
// ******* interfaceVersion *****************************************************
108
    public final int interfaceVersion() {
109
        return interfaceVersion & 255;
110
    }
111
 
112
// ******* interfaceCapabilities ************************************************
113
    public final byte[] interfaceCapabilities() {
114
        return interfaceCapabilities;
115
    }
116
 
117
    public final int interfaceCapabilities( int i ) {
118
        return interfaceCapabilities[i] & 255;
119
    }
120
 
121
// ******* moduleReserved ******************************************************
122
    public final byte[] moduleReserved() {
123
        return moduleReserved;
124
    }
125
 
126
    public final int moduleReserved( int i ) {
127
        return moduleReserved[i] & 255;
128
    }
129
// ******* snString ************************************************************
130
    public final String snString() {
131
        return new String( snString );
132
    }
133
 
134
// ******* setSnString **********************************************************
135
    public final void setSnString( String s ) throws IncompatibleFirmwareException {
136
        if ( s.length()>10 )
137
            throw new IncompatibleFirmwareException( "Serial number too long (max. 10 characters)" );
138
 
139
        int i=0;
140
        for (; i<s.length(); i++ ) {
141
            ihxData[ztexDescriptorOffs+26+i] = (byte) snString[i];
142
        }
143
        for (; i<10; i++ ) {
144
            ihxData[ztexDescriptorOffs+26+i] = 0;
145
        }
146
    }
147
 
148
// ******* toString ************************************************************
149
    public String toString () {
150
        return "productID=" + ZtexDevice1.byteArrayString(productId) + "  fwVer="+(fwVersion & 255) + "  ifVer="+(interfaceVersion & 255)+ "  snString=\"" + snString() + "\"";
151
    }
152
 
153
}

powered by: WebSVN 2.1.0

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