OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [java/] [src/] [edu/] [byu/] [cc/] [plieber/] [fpgaenet/] [icapif/] [IcapTools.java] - Blame information for rev 10

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

Line No. Rev Author Line
1 2 peteralieb
/**
2
 *
3
 */
4
package edu.byu.cc.plieber.fpgaenet.icapif;
5
 
6
import java.util.ArrayList;
7
import java.util.List;
8
 
9
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
10
import edu.byu.cc.plieber.util.StringUtil;
11
import edu.byu.ece.bitstreamTools.bitstream.BitstreamException;
12
import edu.byu.ece.bitstreamTools.bitstream.DummySyncData;
13
import edu.byu.ece.bitstreamTools.bitstream.Packet;
14
import edu.byu.ece.bitstreamTools.bitstream.PacketList;
15
import edu.byu.ece.bitstreamTools.bitstream.PacketOpcode;
16
import edu.byu.ece.bitstreamTools.bitstream.PacketType;
17
import edu.byu.ece.bitstreamTools.bitstream.PacketUtils;
18
import edu.byu.ece.bitstreamTools.bitstream.RegisterType;
19
import edu.byu.ece.bitstreamTools.configuration.Frame;
20
import edu.byu.ece.bitstreamTools.configuration.FrameData;
21
 
22
/**
23
 * @author plieber
24
 *
25
 */
26
public class IcapTools {
27
 
28
        protected IcapInterface icapif;
29
 
30
        /**
31
         * Creates a new IcapTools object attached to given IcapInterface instance.
32
         * @param icapif IcapInterface instance to use
33
         */
34
        public IcapTools(IcapInterface icapif) {
35
                this.icapif = icapif;
36
        }
37
 
38
        /**
39
         * Writes a packet to the ICAP
40
         * @param packet
41 7 peteralieb
         * @throws FCPException
42 2 peteralieb
         */
43 7 peteralieb
        public void write(edu.byu.ece.bitstreamTools.bitstream.Packet packet) throws FCPException {
44 2 peteralieb
                this.icapif.sendIcapData(packet.toByteArray());
45
        }
46
 
47
        /**
48
         * Writes a packet list to the ICAP
49
         * @param packet
50 7 peteralieb
         * @throws FCPException
51 2 peteralieb
         */
52 7 peteralieb
        public void write(edu.byu.ece.bitstreamTools.bitstream.PacketList packetList) throws FCPException {
53 2 peteralieb
                this.icapif.sendIcapData(packetList.toByteArray());
54
        }
55
 
56
        /**
57
         * Writes dummy/synch data from a DummySyncData object.
58
         * @param synchData
59 7 peteralieb
         * @throws FCPException
60 2 peteralieb
         */
61 7 peteralieb
        public void write(edu.byu.ece.bitstreamTools.bitstream.DummySyncData synchData) throws FCPException {
62 2 peteralieb
                this.icapif.sendIcapData(synchData.getData());
63
        }
64
 
65 7 peteralieb
        public void write(edu.byu.ece.bitstreamTools.configuration.Frame frame) throws BitstreamException, FCPException {
66 2 peteralieb
                PacketList packets = new PacketList();
67
                packets.addAll(PacketUtils.NOP_PACKETS(2));
68
                packets.add(PacketUtils.RCRC_CMD_PACKET);
69
                packets.addAll(PacketUtils.NOP_PACKETS(2));
70
                packets.add(PacketUtils.COR_PACKET(0x100531E5));
71
                packets.addAll(PacketUtils.NOP_PACKETS(2));
72
                packets.add(PacketUtils.IDCODE_PACKET(0x2AD6093));
73
                packets.addAll(PacketUtils.NOP_PACKETS(2));
74
                packets.add(PacketUtils.FAR_WRITE_PACKET(frame.getFrameAddress()));
75
                packets.addAll(PacketUtils.NOP_PACKETS(2));
76
                packets.add(PacketUtils.WCFG_CMD_PACKET);
77
                packets.addAll(PacketUtils.NOP_PACKETS(3));
78
 
79
 
80
                ArrayList<Integer> Data = new ArrayList<Integer>();
81
                Data.addAll(frame.getData().getAllFrameWords());
82
                Data.addAll(frame.getData().getAllFrameWords());
83
                packets.add(PacketUtils.TYPE_ONE_WRITE_PACKET(RegisterType.FDRI,  Data));
84
 
85
                //packets.addAll(PacketUtils.FDRI_WRITE_PACKETS(frame.getData().getAllFrameWords()));
86
                //packets.addAll(PacketUtils.FDRI_WRITE_PACKETS(frame.getData().getAllFrameWords()));
87
                packets.addAll(PacketUtils.NOP_PACKETS(3));
88
                this.write(packets);
89
        }
90
 
91 7 peteralieb
        public void write(edu.byu.ece.bitstreamTools.bitstream.RegisterType regtype, int value) throws BitstreamException, FCPException {
92 2 peteralieb
                PacketList packets = new PacketList();
93
                //packets.addAll(PacketUtils.NOP_PACKETS(1));
94
                //packets.add(PacketUtils.IDCODE_PACKET(0x2AD6093));
95
                //packets.addAll(PacketUtils.NOP_PACKETS(1));
96
                ArrayList<Integer> valuelist = new ArrayList<Integer>();
97
                valuelist.add(value);
98
                //ArrayList<Integer> valuelist2 = new ArrayList<Integer>();
99
                //valuelist2.add(0x7);
100
                packets.addAll(PacketUtils.NOP_PACKETS(1));
101
                packets.addAll(PacketUtils.NOP_PACKETS(1));
102
                packets.add(PacketUtils.TYPE_ONE_WRITE_PACKET(regtype, valuelist));
103
                //packets.addAll(PacketUtils.NOP_PACKETS(100));
104
 
105
                //packets.add(PacketUtils.COR_PACKET(0x100531E5));
106
                //packets.addAll(PacketUtils.NOP_PACKETS(1));
107
                //packets.addAll(PacketUtils.NOP_PACKETS(1));
108
                //ArrayList<Integer> valuelist = new ArrayList<Integer>();
109
                //valuelist.add(value);
110
                //packets.add(PacketUtils.TYPE_ONE_WRITE_PACKET(regtype, valuelist));
111
                //packets.addAll(PacketUtils.NOP_PACKETS(1));
112
                //packets.add(PacketUtils.RCRC_CMD_PACKET);
113
                //packets.addAll(PacketUtils.NOP_PACKETS(1));
114
                //packets.add(PacketUtils.TYPE_ONE_WRITE_PACKET(regtype, valuelist2));
115
                //packets.addAll(PacketUtils.NOP_PACKETS(20));
116
                this.write(packets);
117
        }
118
 
119 7 peteralieb
        public void synchIcap() throws FCPException {
120 2 peteralieb
                //write(DummySyncData.V5_V6_ICAP_DUMMY_SYNC_DATA);
121
                write(DummySyncData.V5_V6_STANDARD_DUMMY_SYNC_DATA);
122
        }
123
 
124
        public void deviceIdCheck(int deviceId) {
125
 
126
        }
127
 
128
        public void clearCRC(int deviceId) {
129
 
130
        }
131
 
132
        /**
133
         * Reads a frame from the ICAP. This methods stores the frame data into the frame instance given as a paramter.
134
         * @param frame The Frame in which to store the read frame data.
135
         * @return A reference to the Frame where the data was stored.
136
         * @throws FCPException
137
         */
138
        public edu.byu.ece.bitstreamTools.configuration.Frame readFrame(edu.byu.ece.bitstreamTools.configuration.Frame frame) throws FCPException {
139
                PacketList packets = new PacketList();
140
                packets.addAll(PacketUtils.NOP_PACKETS(2));
141
                //packets.add(PacketUtils.GCAPTURE_CMD_PACKET);
142
                packets.addAll(PacketUtils.NOP_PACKETS(2));
143
                packets.add(PacketUtils.NULL_CMD_PACKET);
144
                packets.addAll(PacketUtils.NOP_PACKETS(2));
145
                packets.add(PacketUtils.FAR_WRITE_PACKET(frame.getFrameAddress()));
146
                packets.add(PacketUtils.RCFG_CMD_PACKET);
147
                packets.addAll(PacketUtils.NOP_PACKETS(3));
148
                packets.addAll(PacketUtils.FDRO_READ_PACKETS(1));
149
                packets.addAll(PacketUtils.NOP_PACKETS(2));
150
                this.icapif.sendIcapData(packets.toByteArray());
151
                this.icapif.requestIcapData(332);
152
                ArrayList<Byte> bytes = this.icapif.receiveIcapData();
153
                frame.configure(new FrameData(bytes.subList(168, bytes.size())));
154
                return frame;
155
        }
156
 
157
        public int readRegister(RegisterType T) throws FCPException, BitstreamException{
158
 
159
                PacketList packets = new PacketList();
160
                packets.addAll(PacketUtils.NOP_PACKETS(2));
161
                List<Integer> data = new ArrayList<Integer>();
162
                packets.add(new Packet(Packet.getHeader(PacketType.ONE, PacketOpcode.READ, T, 0) | 1, data));
163
                packets.addAll(PacketUtils.NOP_PACKETS(2));
164
                System.out.println(packets.toString());
165
                this.icapif.sendIcapData(packets.toByteArray());
166
                this.icapif.requestIcapData(4);
167
                ArrayList<Byte> bytes = this.icapif.receiveIcapData();
168
            int value=0;
169
                for(int i = 0; i < bytes.size(); i++){
170
                        System.out.println(Integer.toHexString(bytes.get(i)));
171
                        value = value | bytes.get(i) << ( i * 8);
172
                }
173
                return value;
174
        }
175
        /**
176
         * Read a frame from the ICAP. A new Frame is created and returned.
177
         * @param frameAddress The frame address to read
178
         * @return
179
         * @throws FCPException
180
         */
181
        public edu.byu.ece.bitstreamTools.configuration.Frame readFrame(int frameAddress) throws FCPException {
182
                Frame frame = new Frame(41, frameAddress);
183
                return this.readFrame(frame);
184
        }
185
}

powered by: WebSVN 2.1.0

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