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/] [examples/] [RegisterInterface.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
/**
2
 *
3
 */
4
package edu.byu.cc.plieber.fpgaenet.examples;
5
 
6
import java.util.ArrayList;
7
 
8
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
9
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
10
 
11
/**
12
 * @author Peter Lieber
13
 *
14
 */
15
public class RegisterInterface {
16
 
17
        private FCPProtocol protocol;
18
        private int channel;
19
        /**
20
         *
21
         */
22
        public RegisterInterface(FCPProtocol p) {
23
                protocol = p;
24
                channel = 1;
25
        }
26
 
27
        public RegisterInterface(FCPProtocol p, int channel) {
28
                protocol = p;
29
                this.channel = channel;
30
        }
31
 
32
        public void setRegister(int value) {
33
                ArrayList<Byte> bytes = new ArrayList<Byte>();
34
                bytes.add(new Byte((byte) (value & 0xff)));
35
                bytes.add(new Byte((byte) ((value >> 8) & 0xff)));
36
                bytes.add(new Byte((byte) ((value >> 16) & 0xff)));
37
                bytes.add(new Byte((byte) ((value >> 24) & 0xff)));
38
                try {
39
                        protocol.sendData(channel, bytes);
40
                } catch (FCPException e) {
41
                        // TODO Auto-generated catch block
42
                        e.printStackTrace();
43
                }
44
        }
45
 
46
        public int getRegister() {
47
                try {
48
                        protocol.sendDataRequest(channel, 4);
49
                } catch (FCPException e) {
50
                        // TODO Auto-generated catch block
51
                        e.printStackTrace();
52
                }
53
                byte[] bytes = protocol.getDataResponse();
54
                int res = (((int)bytes[3] & 0xff) << 24) | (((int)bytes[2] & 0xff) << 16) | (((int)bytes[1] & 0xff) << 8) |  (((int)bytes[0] & 0xff));
55
                return res;
56
        }
57
 
58
}

powered by: WebSVN 2.1.0

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