#
# Script to exercise AIDA mini-TLU
#
# David Cussans, December 2012
# 
# Modified by Alvaro Dosil, January 2013
from PyChipsUser import *
import time

bAddrTab = AddressTable("./aida_mini_tlu_addr_map.txt")

# Assume DIP-switch controlled address. Switches at 1 
board = ChipsBusUdp(bAddrTab,"192.168.200.16",50001)

firmwareID=board.read("FirmwareId")
firmwareID=board.read("FirmwareId")

print "Firmware = " , hex(firmwareID)

board.write("TriggerMask", 0)
trigpatt = board.read("TriggerMask")
print "Trigger pattern set to ", trigpatt

pretrig = board.read("PreVetoTriggers")
print "Pre veto triggers = ", pretrig

fifofill = board.read("EventFifoFillLevel")
print "fifo fill level = ", fifofill

board.write("InternalTriggerInterval", 0x10000000)
trigint = board.read("InternalTriggerInterval")
print "Trigger interval set to " , trigint

time.sleep(1.0)
 
pretrig = board.read("PreVetoTriggers")
print "Pre veto triggers = ", pretrig

board.write("LogicRst",1)
print "reset counters"
pretrig = board.read("PreVetoTriggers")
print "Pre veto triggers = ", pretrig

print "Buffer Status = ", hex(board.read("EventFifoFillLevelFlags"))
board.write("EventFifoCSR",1)
print "reset FIFO"
print "Buffer Status = ", hex(board.read("EventFifoFillLevelFlags"))

posttrig = board.read("PostVetoTriggers")
print "Post veto triggers = ", posttrig

fifofill = board.read("EventFifoFillLevel")
print "fifo fill level = ", fifofill


