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; using Tango.Stubs; const Int32 FPGA1 = 0x60000000; const Int32 FPGA2 = 0x60000400; const Int32 FPGA3 = 0x60000800; const Int32 VER1_REG = 0x000; const Int32 VER2_REG = 0x010; const Int32 TEST_REG = 0x3f0; StubFpgaReadRegResponse Fpga_Read_Reg(Int32 Fpga, Int32 Addr, Int32 Verbose) { var response = stubManager.Run("StubFpgaReadRegRequest" , Fpga + Addr); response.Value = response.Value & 0xffff; if (Verbose == 1) { stubManager.Write("FPGA 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("FPGA 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("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; }