Commit fb1ed0aa authored by David Cussans's avatar David Cussans

Adding startTLU.py script

parent 40fd8194
#
# Script to setup AIDA TLU for TPix3 telescope <--> TORCH synchronization
#
# David Cussans, December 2012
#
# Nasty hack - use both PyChips and uHAL ( for block read ... )
from PyChipsUser import *
from FmcTluI2c import *
import uhal
import sys
import time
print "Setting up AIDA TLU for TPix3 telescope <--> TORCH synchronization\n"
writeTimestamps = False
listenForTelescopeShutter = True
TriggerInterval = 0 # Units = 160MHz clock ticks.
loopWait = 1.0 # polling interval ( seconds )
# Point to board in uHAL
manager = uhal.ConnectionManager("file://./connection.xml")
hw = manager.getDevice("minitlu")
device_id = hw.id()
fwVersion = hw.getNode("version").read()
hw.dispatch()
print "Version (uHAL)= " , hex(fwVersion)
# Point to TLU in Pychips
bAddrTab = AddressTable("./aida_mini_tlu_addr_map.txt")
# Assume DIP-switch controlled address. Switches at 2
board = ChipsBusUdp(bAddrTab,"192.168.200.32",50001)
# Check the bus for I2C devices
boardi2c = FmcTluI2c(board)
firmwareID=board.read("FirmwareId")
print "Firmware (from PyChips) = " , hex(firmwareID)
print "Scanning I2C bus:"
scanResults = boardi2c.i2c_scan()
print scanResults
boardId = boardi2c.get_serial_number()
print "FMC-TLU serial number = " , boardId
resetClocks = 0
resetSerdes = 0
# set DACs to -200mV
print "Setting all threshold DAC to -200mV "
boardi2c.set_threshold_voltage(7, -0.2)
clockStatus = board.read("LogicClocksCSR")
print "Clock status ( should be 3 if all clocks locked ) = " , hex(clockStatus)
if resetClocks:
print "Resetting clocks"
board.write("LogicRst", 1 )
clockStatus = board.read("LogicClocksCSR")
print "Clock status after reset = " , hex(clockStatus)
inputStatus = board.read("SerdesRstR")
print "Input status = " , hex(inputStatus)
if resetSerdes:
board.write("SerdesRstW", 0x00000003 )
inputStatus = board.read("SerdesRstR")
print "Input status during reset = " , hex(inputStatus)
board.write("SerdesRstW", 0x00000000 )
inputStatus = board.read("SerdesRstR")
print "Input status after reset = " , hex(inputStatus)
board.write("SerdesRstW", 0x00000004 )
inputStatus = board.read("SerdesRstR")
print "Input status during calibration = " , hex(inputStatus)
board.write("SerdesRstW", 0x00000000 )
inputStatus = board.read("SerdesRstR")
print "Input status after calibration = " , hex(inputStatus)
inputStatus = board.read("SerdesRstR")
print "Input status = " , hex(inputStatus)
count0 = board.read("ThrCount0R")
print " Count 0 = " , count0
count1 = board.read("ThrCount1R")
print " Count 1 = " , count1
count2 = board.read("ThrCount2R")
print " Count 2 = " , count2
count3 = board.read("ThrCount3R")
print " Count 3 = " , count3
board.write("InternalTriggerIntervalW",0)
print "Setting input trigger delay to 31 160MHz clock cycles"
board.write("PulseDelayW",31)
pulseDelay = board.read("PulseDelayR")
print "Pulse delay was set to ", pulseDelay
print "Enabling DUT 0 and 1"
board.write("DUTMaskW",3)
DUTMask = board.read("DUTMaskR")
print "DUTMaskR = " , DUTMask
if listenForTelescopeShutter:
print "Listen for veto from shutter"
board.write("IgnoreShutterVetoW",0)
else
print "Ignore veto from shutter"
board.write("IgnoreShutterVetoW",1)
IgnoreShutterVeto = board.read("IgnoreShutterVetoR")
print "IgnoreShutterVeto = " , IgnoreShutterVeto
print "Ignore veto on DUT 0"
board.write("IgnoreDUTBusyW",1)
IgnoreDUTBusy = board.read("IgnoreDUTBusyR")
print "IgnoreDUTBusyR = " , IgnoreDUTBusy
print "Turning off software trigger veto"
board.write("TriggerVetoW",0)
print "Reseting FIFO"
board.write("EventFifoCSR",0x2)
eventFifoFillLevel = board.read("EventFifoFillLevel")
print "FIFO fill level after resetting FIFO = " , eventFifoFillLevel
if writeTimestamps:
print "Enabling data recording"
board.write("Enable_Record_Data",1)
else
print "Disabling data recording"
board.write("Enable_Record_Data",0)
#print "Enabling handshake: No-handshake"
#board.write("HandshakeTypeW",1)
print "Setting internal trigger interval to " , TriggerInterval , " ( zero = no internal triggers)"
board.write("InternalTriggerIntervalW",TriggerInterval) #0->Internal pulse generator disabled. Any other value will generate pulses with a frequency of n*6.25ns
trigInterval = board.read("InternalTriggerIntervalR")
print "Trigger interval read back as ", trigInterval
oldEvtNumber = 0
oldPreVetotriggerCount = board.read("PreVetoTriggersR")
oldPostVetotriggerCount = board.read("PostVetoTriggersR")
print "Starting polling loop"
while True:
preVetotriggerCount = board.read("PreVetoTriggersR")
postVetotriggerCount = board.read("PostVetoTriggersR")
preVetoFreq = (preVetotriggerCount-oldPreVetotriggerCount)/loopWait
postVetoFreq = (postVetotriggerCount-oldPostVetotriggerCount)/loopWait
print "pre , post veto triggers = " , preVetotriggerCount , postVetotriggerCount
timestampHigh = board.read("CurrentTimestampHR")
timestampLow = board.read("CurrentTimestampLR")
print "Current timestamp High,Low (hex) = " , hex(timestampHigh) , hex(timestampLow)
eventFifoFillLevel = board.read("EventFifoFillLevel")
print "FIFO fill level = " , eventFifoFillLevel
#timestampData = board.blockRead("EventFifoData", eventFifoFillLevel)
nEvents = eventFifoFillLevel//4 # only read out whole events ( 4 x 32-bit words )
wordsToRead = nEvents*4
timestampData = hw.getNode("eventBuffer.EventFifoData").readBlock(eventFifoFillLevel)
hw.dispatch()
print "number of events in FIFO = ",nEvents
# print timestampData
for evt in range (0, nEvents-1 ):
lowWord = timestampData[evt*4 + 1] + 0x100000000* timestampData[ (evt*4) + 0] # timestamp
highWord = timestampData[evt*4 + 3] + 0x100000000* timestampData[ (evt*4) + 2] # evt number
evtNumber = timestampData[evt*4 + 3]
if evtNumber != ( oldEvtNumber + 1 ):
print "***WARNING *** Non sqeuential event numbers *** , evt,oldEvt = ", evtNumber , oldEvtNumber
oldEvtNumber = evtNumber
timeStamp = lowWord & 0xFFFFFFFFFFFF
evtType = timestampData[ (evt*4) + 0] >> 28
print "bufferPos, highWord , lowWord , event-number , timestamp , evtType = %x %016x %016x %08x %012x %01x" % ( evt , highWord , lowWord, evtNumber , timeStamp , evtType)
time.sleep( loopWait)
# Fixme - at the moment infiniate loop.
preVetotriggerCount = board.read("PreVetoTriggersR")
postVetotriggerCount = board.read("PostVetoTriggersR")
print "\n\nPre,post trigger count at end of run " , preVetotriggerCount , postVetotriggerCount
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