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/] [SimpleInterface.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 SimpleInterface {
16
 
17
        private FCPProtocol protocol;
18
        /**
19
         *
20
         */
21
        public SimpleInterface(FCPProtocol p) {
22
                protocol = p;
23
        }
24
 
25
        public void setLED(byte value) {
26
                try {
27
                        protocol.sendData(1, value);
28
                } catch (FCPException e) {
29
                        // TODO Auto-generated catch block
30
                        e.printStackTrace();
31
                }
32
        }
33
 
34
        public byte getDIP() {
35
                try {
36
                        protocol.sendDataRequest(1, 1);
37
                } catch (FCPException e) {
38
                        // TODO Auto-generated catch block
39
                        e.printStackTrace();
40
                }
41
                byte[] res = protocol.getDataResponse();
42
                return res[0];
43
        }
44
 
45
        public void setRegister(int value) {
46
                ArrayList<Byte> bytes = new ArrayList<Byte>();
47
                bytes.add(new Byte((byte) (value & 0xff)));
48
                bytes.add(new Byte((byte) ((value >> 8) & 0xff)));
49
                bytes.add(new Byte((byte) ((value >> 16) & 0xff)));
50
                bytes.add(new Byte((byte) ((value >> 24) & 0xff)));
51
                try {
52
                        protocol.sendData(2, bytes);
53
                } catch (FCPException e) {
54
                        // TODO Auto-generated catch block
55
                        e.printStackTrace();
56
                }
57
        }
58
 
59
        public int getRegister() {
60
                try {
61
                        protocol.sendDataRequest(2, 4);
62
                } catch (FCPException e) {
63
                        // TODO Auto-generated catch block
64
                        e.printStackTrace();
65
                }
66
                byte[] bytes = protocol.getDataResponse();
67
                int res = (((int)bytes[3] & 0xff) << 24) | (((int)bytes[2] & 0xff) << 16) | (((int)bytes[1] & 0xff) << 8) |  (((int)bytes[0] & 0xff));
68
                return res;
69
        }
70
 
71
}

powered by: WebSVN 2.1.0

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