1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
using System;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Tango.PMR.Stubs;
using Tango.Stubs;
const Int32 FPGA1 = 0x60000000;
const Int32 FPGA2 = 0x60000400;
const Int32 FPGA3 = 0x60000800;
const Int32 TEST_REG = 0x3f0;
StubFpgaReadRegResponse Fpga_Read_Reg(Int32 Fpga, Int32 Addr, Int32 Verbose)
{
var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" , Fpga + Addr);
response.Value = response.Value & 0xffff;
if (Verbose == 1) {
stubManager.Write("\n\nFPGA Reg. Read (FPGA Base, Addr, Data): (");
stubManager.WriteHex(Fpga,4);
stubManager.Write(", ");
stubManager.WriteHex(Addr,4);
stubManager.Write(", ");
stubManager.WriteHex(response.Value,4);
stubManager.Write(")");
}
return response;
}
int Fpga_Write_Reg(Int32 Fpga, Int32 Addr, Int32 Data, Int32 Verbose)
{
if (Verbose == 1) {
stubManager.Write("\n\nFPGA Reg. Write (FPGA Base, Addr, Data): (");
stubManager.WriteHex(Fpga,4);
stubManager.Write(", ");
stubManager.WriteHex(Addr,4);
stubManager.Write(", ");
stubManager.WriteHex(Data,4);
stubManager.Write(")");
}
var response = stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,Fpga + Addr, Data);
return 1;
}
Int32 GetBit(Int32 Fpga, Int32 Adr, Int32 BitNo)
{
Int32 BitMask;
var RetVal = Fpga_Read_Reg(Fpga, Adr, 0);
BitMask = 0x1 << BitNo;
if ( ( (Int32) RetVal.Value & BitMask) == BitMask )
{
return 1;
}
else
{
return 0;
}
}
Int32 SetBit (Int32 Fpga, Int32 Adr, Int32 BitNo, Int32 Bit)
{
Int32 BitMask;
var RetVal = Fpga_Read_Reg(Fpga, Adr, 0);
Int32 RV = (Int32) RetVal.Value;
if (Bit == 0x1)
{
BitMask = 0x1 << BitNo;
RV = RV | BitMask;
Fpga_Write_Reg(Fpga, Adr, RV , 0);
}
else if (Bit == 0x0)
{
BitMask = ~(0x1 << BitNo);
RV = RV & BitMask;
Fpga_Write_Reg(Fpga, Adr, RV , 0);
}
return 1;
}
|