Commit b4495e8a authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

software/python: library based on SPEC driver

parent e9ab8ca8
......@@ -74,12 +74,7 @@ if __name__ == "__main__":
print("Sorry, I must be run as root...");
sys.exit(-1)
fd = os.open("/dev/rawrabbit", os.O_SYNC)
if(fd < 0):
print("Can't open the rawrabbit device. Is the rawrabbit driver installed?")
sys.exit(-1)
card = FineDelay(fd)
card = FineDelay()
app = QApplication(sys.argv)
......
......@@ -22,33 +22,43 @@ class fd_timestamp(Structure):
return "%d:%d" % (self.utc, self.nsecs())
class FineDelay:
BASE_ADDR = 0x80000
FREE_RUNNING = 0x10
WR_OFFLINE = 0x8
WR_READY = 0x1
WR_SYNCING = 0x2
WR_SYNCED = 0x4
SYNC_LOCAL = 0x1
SYNC_WR = 0x2
def __init__(self, bus = -1):
self.fdelay = CDLL('../lib/libfinedelay.so')
# load the firmware for the SPEC:
self.card = self.fdelay.spec_open(c_int(bus), c_int(-1));
if(self.card == 0):
print ("SPEC enumeration failed");
sys.exit(-1)
if ~os.path.isfile("spec_top_fd.bin"):
print ("No firmware file found. Attempting to download one from OHWR")
import urllib
urllib.urlretrieve ("http://www.ohwr.org/attachments/download/1350/spec_top.bin", "spec_top_fd.bin")
cwd = os.getcwd();
def __init__(self, fd):
cwd = os.path.dirname(__file__)
self.fdelay = CDLL(cwd+'/../lib/libfinedelay.so')
self.handle = c_voidp(self.fdelay.fdelay_create_rawrabbit(c_int(fd), c_ulong(self.BASE_ADDR)));
if(self.fdelay.spec_load_bitstream(c_voidp(self.card), c_char_p(cwd + "/spec_top_fd.bin")) < 0):
print ("Firmware loader failure");
sys.exit(-1)
self.fdelay.spec_close(c_voidp(self.card))
if(c_int(self.fdelay.fdelay_load_firmware("../spec_top_wr.bin")) < 0):
print ("Firmware loader failed...");
self.handle = pointer(create_string_buffer('\000' * 16384)) #allocate some memory for the fdelay_device_t
if(self.fdelay.spec_fdelay_create_bd(self.handle, c_int(bus), c_int(-1), c_ulong(self.BASE_ADDR)) < 0):
print ("FD enumeration failed")
sys.exit(-1)
print "Initialising Fine Delay board..."
print "Initializing Fine Delay board..."
if(self.fdelay.fdelay_init(self.handle) < 0):
print ("Init failed..");
sys.exit(-1)
def conf_trigger(self, enable, termination):
self.fdelay.fdelay_configure_trigger(self.handle, c_int(enable), c_int(termination))
......@@ -77,14 +87,7 @@ class FineDelay:
return t
def get_sync_status(self):
htab = { self.FREE_RUNNING : "oscillator free-running",
self.WR_OFFLINE : "WR core offline",
self.WR_READY : "WR core ready",
self.WR_SYNCING : "Syncing local clock with WR",
self.WR_SYNCED : "Synced with WR" }
# status = c_int(self.fdelay.fdelay_get_sync_status(self.handle));
# print("GetSyncStatus %x" % status.value);
return "none"; #htab[status.value]
return "none"; #fixme: new WR state machine
def read_ts(self):
buf = (fd_timestamp * 256)();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment