Commit 8e3f7866 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

software: Update Python scripts and their folder struct

The most major update is the fact that the login is not manual any more.
Instead, a common file `ei2cdefine.py' is used to define the ELMA crate
hostname, username and password. This module is used across all Python
scripts to connect to the ELMA crate.

Apart from that, some new modules have been added and the gp-py/ folder
was renamed to diag/
Signed-off-by: Theodor-Adrian Stana's avatarTheodor Stana <t.stana@cern.ch>
parent c379545f
Software for the CONV-TTL-BLO board
===================================
This folder contains various software that can communicate to the CONV-TTL-BLO
for diagnostics purposes, or to issue MultiBoot to a board. It contains the
following sub-folders:
catbstream/ -- a Python script for concatenating two bitstreams for writing a
golden and application bitstream to the Flash at once
diag/ -- Python scripts for diagnostics
ei2c/ -- common "library" files for the other programs used to test the
CONV-TTL-BLO
multiboot/ -- MultiBoot-related files
pulsetest/ -- Python script for running pulse tests
regtest/ -- Python script for running communication tests
For more information on the scripts in each folder, refer to the README.txt
file in the respective folder.
General purpose Python scripts
Python scripts for diagnostics
==============================
timetag/ -- Python scripts for working with the time-tagging logic
clrchxpcr.py -- Clears the channel pulse counter registers
gwvers.py -- Read gateware version from board CSR
mantrig.py -- Manually trigger a pulse on a selected channel
rdchxpcr.py -- Read the channel pulse counter registers
rdfifo.py -- Read samples of the tag FIFO while they exist
therm.py -- Get the unique ID and temperature from the
DS18B20 thermometer on-board the CONV-TTL-BLO
tsset.py -- set TAI time stamp value
DS18B20 thermometer on-board the CONV-TTL-BLO
import time
import sys
import time
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
if __name__ == "__main__":
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Clear channel counters and close
testelma.write(slot, 0x0c, 0)
testelma.write(slot, 0x10, 0)
testelma.write(slot, 0x14, 0)
testelma.write(slot, 0x18, 0)
testelma.write(slot, 0x1c, 0)
testelma.write(slot, 0x20, 0)
testelma.close()
import sys
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
if __name__ == "__main__":
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Get gateware version field and close
v = testelma.read(slot, 0x4)
maj = (v & 0xf0) >> 4
min = v & 0x0f
print("Gateware version: %d.%d" % (maj, min))
testelma.close()
import time
import sys
import time
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
if __name__ == "__main__":
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Send magic sequence
testelma.write(slot, 0x8, 0xde << 2)
testelma.write(slot, 0x8, 0xad << 2)
testelma.write(slot, 0x8, 0xbe << 2)
testelma.write(slot, 0x8, 0xef << 2)
# Ask for which channel to trigger on, trigger, close and exit
chan = input("chan (1..6): ")
testelma.write(slot, 0x8, chan << 2)
testelma.close()
import time
import sys
import time
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
if __name__ == "__main__":
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Print channel counter values, close and exit
print("CH1: %d" % testelma.read(slot, 0x0c))
print("CH2: %d" % testelma.read(slot, 0x10))
print("CH3: %d" % testelma.read(slot, 0x14))
print("CH4: %d" % testelma.read(slot, 0x18))
print("CH5: %d" % testelma.read(slot, 0x1c))
print("CH6: %d" % testelma.read(slot, 0x20))
testelma.close()
......@@ -6,6 +6,7 @@ import os
# Import common modules
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
##------------------------------------------------------------------------------
## OneWire class
......@@ -184,65 +185,56 @@ class CDS18B20:
## main
##------------------------------------------------------------------------------
if __name__ == "__main__":
FAMILY_CODE = 0x28
# Ask for username and password and retry init in case of error
while 1:
ip = raw_input("Crate IP or hostname: ")
user = raw_input("Username: ")
pwd = raw_input("Password: ")
try:
testelma = EI2C(ip, user, pwd)
testelma.open()
break
except BadHostnameError as e:
print(e.strerror)
except BadUsernameError as e:
print(e.strerror)
except BadPasswordError as e:
print(e.strerror)
# Wait for proper slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Create onewire and thermometer objects
onewire = COpenCoresOneWire(testelma, 1, 0x80, 99, 19)
ds18b20 = CDS18B20(onewire, 0)
# Reading of unique ID
unique_id = ds18b20.read_serial_number()
if(unique_id == -1):
msg = "ERROR: TempID IC20: Unable to read 1-wire thermometer"
print(msg)
else:
print("Unique ID: %.12X" % (unique_id))
# Reading of temperature
temp = ds18b20.read_temp(unique_id)
print("Current temperature: %3.3f" % temp)
# Cheking if received values are reasonable
if temp < 10.0 or temp > 50.0:
msg = "ERROR: TempID IC20: Temperature: %d out of range[10 .. 50oC]" % (temp)
print(msg)
if((unique_id & 0xFF) != FAMILY_CODE):
family_code = unique_id & 0xFF
msg = "ERROR: TempID IC20: Invalid family code: 0x%.8X" % (family_code)
print(msg)
testelma.close()
FAMILY_CODE = 0x28
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Create onewire and thermometer objects
onewire = COpenCoresOneWire(testelma, 1, 0x80, 99, 19)
ds18b20 = CDS18B20(onewire, 0)
# Reading of unique ID
unique_id = ds18b20.read_serial_number()
if(unique_id == -1):
msg = "ERROR: TempID IC20: Unable to read 1-wire thermometer"
print(msg)
else:
print("Unique ID: %.12X" % (unique_id))
# Reading of temperature
temp = ds18b20.read_temp(unique_id)
print("Current temperature: %3.3f" % temp)
# Cheking if received values are reasonable
if temp < 10.0 or temp > 50.0:
msg = "ERROR: TempID IC20: Temperature: %d out of range[10 .. 50oC]" % (temp)
print(msg)
if((unique_id & 0xFF) != FAMILY_CODE):
family_code = unique_id & 0xFF
msg = "ERROR: TempID IC20: Invalid family code: 0x%.8X" % (family_code)
print(msg)
testelma.close()
Scripts for the time-tagging logic
==================================
On the time-tagging side, the following scripts exist:
rdfifo.py -- Read samples of the tag FIFO while they exist
tsdiff.py -- Output the difference between two time-stamps from the FIFO
tsset.py -- set TAI time stamp value, clearing the cycles counter in the
process
While the last script is pretty straightforward, the first two need some
further notes on their functioning.
rdfifo.py
---------
First, the rdfifo.py script can be used to read the FIFO and output its
contents. The output can be the prompt (stdout), or a file if the user selects
it. When the script is started, it asks for the slot number (as usual), then
whether it should output to a file, and the filename if it should:
%> python rdfifo.py
Slot no.: 1
Output samples to file? (y/n) y
File name (with extension): myfile.txt
The last part of the output is -- no matter whether you selected to output to
a file or not -- the number of pulses stored to the FIFO on each channel,
calculated based on the number of times the channel mask was containing a '1'
for a particular channel.
The output file can be used by the tsdiff.py script to print the difference
between two timestamps on stdout. The format of the FIFO output is the
following:
(<USEDW>) <channel mask> : <TAI value>.<seconds value>
where
<USEDW> -- the TFCSR.USED field
<channel mask> -- the TFMR.CHAN field
<TAI value> -- TAI value obtained by concatenating the bit fields of the
TFTLR and TFTHR registers
<seconds value> -- TFCYR * 8
tsdiff.py
---------
This script can be used to calculated the difference between consecutive
timestamps in the FIFO. It requires an output file from the rdfifo.py script
and then retrieves the TAI and seconds value from the script's output,
printing the difference between one timestamp and the previous.
Additionally, the script calculates when the timestamp difference is less than
6 us (the pulse rejection period on the CONV-TTL-BLO) and prints an extra
warning to the sample.
The output -- based on that of the rdfifo.py output -- is:
(<channel mask>) <TAI difference>.<seconds difference>
Note that the first sample in the output is always the first timestamp value.
To run (considering the output file in the rdfifo.py section):
%> python tsdiff.py
Input file name (with extension): myfile.txt
import sys
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
import math
if __name__ == "__main__":
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Output to file?
while 1:
try:
inp = raw_input("Output samples to file? (y/n) ").lower()
if (inp == 'y'):
fname = raw_input("File name (with extension): ");
f = open(fname, 'w')
break
elif (inp == 'n'):
break
except KeyboardInterrupt:
print("Exiting on user request")
sys.exit();
except:
print("Error: " + sys.exc_info()[0]);
# Read while FIFO is not empty
csr = testelma.read(slot, 0x3c)
empty = csr & (1 << 17)
used = csr & 0x7f
chcnt = [0, 0, 0, 0, 0, 0]
while not empty:
# Get channel mask from meta register and convert it to channel number
ch = testelma.read(slot, 0x2c) & 0x3f
# Increment channel counters if channel bit is set in FIFO
i = 0
if (ch & (1 << i)):
chcnt[i] += 1
i += 1
if (ch & (1 << i)):
chcnt[i] += 1
i += 1
if (ch & (1 << i)):
chcnt[i] += 1
i += 1
if (ch & (1 << i)):
chcnt[i] += 1
i += 1
if (ch & (1 << i)):
chcnt[i] += 1
i += 1
if (ch & (1 << i)):
chcnt[i] += 1
#ch = 1 + int(math.log(ch)/math.log(2))
# Read cycles and seconds counters
cyc = testelma.read(slot, 0x30)
sl = testelma.read(slot, 0x34)
sh = testelma.read(slot, 0x38)
# The seconds counter indicates actual seconds; the cycles counter
# indicates 8-ns cycles, so convert to ns
s = (sh << 32) | sl
ns = cyc*8
# And print
csr = testelma.read(slot, 0x3c)
empty = csr & (1 << 17)
used = csr & 0x7f
sample = "(%3d) %s : %d.%09d sec" % (used, "{0:#08b}".format(ch)[2:], s, ns)
if 'f' in locals():
f.write(sample + '\n');
else:
print(sample)
# Number of pulses are always printed to console
print("Number of pulses:")
i = 0
print("CH%d: %d" % (i+1, chcnt[i]))
i += 1
print("CH%d: %d" % (i+1, chcnt[i]))
i += 1
print("CH%d: %d" % (i+1, chcnt[i]))
i += 1
print("CH%d: %d" % (i+1, chcnt[i]))
i += 1
print("CH%d: %d" % (i+1, chcnt[i]))
i += 1
print("CH%d: %d" % (i+1, chcnt[i]))
i += 1
if 'f' in locals():
f.close()
if __name__ == "__main__":
# seconds, nanoseconds
s = 0
ns = 0
# previous seconds and nanoseconds
prs = 0
prns = 0
# FIFO sample number
n = 0
# Get file name
fname = raw_input("Input file name (with extension): ");
# And start getting the samples and calculating the difference values
with open(fname, 'r') as f:
for l in f:
t = l.split()[3]
ch = l.split()[1][2:]
if t == ':':
t = l.split()[4]
ch = l.split()[2]
#if t == ':':
# t = l.split()[5]
# if t == ':':
# t = l.split()[6]
ch = int(ch, 2)
# Get seconds and nanoseconds
s = int(t.split('.')[0])
ns = int(t.split('.')[1])
# Calc seconds difference, adjust in case of overflow
sd = s - prs
nsd = ns - prns
if sd < 0:
sd = -sd
if nsd < 0:
nsd = -nsd
# Print
p = "(%s) %d.%09d" % ("{0:#08b}".format(ch)[2:], sd, nsd)
if (sd == 0) and (nsd < 6000) and (ch & prch):
p += " [!!!]"
print(p)
prch = ch
prs = s
prns = ns
n += 1
import sys
sys.path.append("../ei2c")
import time
from ei2c import *
import ei2cdefine
if __name__ == "__main__":
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Set time stamp, close and exit
s = int(raw_input("Number of seconds: "))
testelma.write(slot, 0x24, s & 0xffffffff)
if s > 2**32-1:
testelma.write(slot, 0x28, s >> 32)
testelma.close()
EI2C files
==========
Common files for the Python scripts using the I2C protocol defined in the VME
crates from ELMA.
ei2c.py -- defines the EI2C class and methods for accessing a board within
the VME crate
ei2cexcept.py -- exception classes for all the errors an ELMA crate can return
when communicating over I2C
ei2cdefine.py -- constants used across the other Python scripts
-- dump constant that is used within the ei2c.py module to see
whether a dump file should be created when running a Python
script; this dump file contains the messages returned by the
ELMA crate when communicating over I2C
......@@ -37,6 +37,7 @@
import socket
from ei2cexcept import *
import ei2cdefine
class EI2C:
......@@ -58,7 +59,8 @@ class EI2C:
self.write_cnt = 0
self.read_cnt = 0
self.f = open("dump.txt", 'w')
if (ei2cdefine.DUMP):
self.f = open("dump.txt", 'w')
def open(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
......@@ -77,7 +79,8 @@ class EI2C:
def close(self):
self.handle.close()
self.f.close()
if (ei2cdefine.DUMP):
self.f.close()
def writemregs(self, slot, addr, val):
self.write_cnt += 1
......@@ -86,62 +89,65 @@ class EI2C:
cmd = "writemregs %d %x %s\r\n" % (slot, addr, ' '.join(format(b,'x') for b in val))
#print cmd
self.handle.send(cmd)
_strip_resp(self.handle.recv(30),self.f)
self._strip_resp(self.handle.recv(30))
def readmregs(self, slot, addr, nrregs):
self.read_cnt += 1
#reg = addr/4 + 1
cmd = "readmregs %d %x %d\r\n" % (slot, addr, nrregs)
self.handle.send(cmd)
resp = _strip_resp(self.handle.recv(30),self.f)
resp = self._strip_resp(self.handle.recv(30))
return resp
def write(self, slot, addr, val):
self.write_cnt += 1
#reg = addr/4 + 1
cmd = "writereg %d %x %x\r\n" % (slot, addr, val)
self.f.write(cmd);
if (ei2cdefine.DUMP):
self.f.write(cmd);
self.handle.send(cmd)
_strip_resp(self.handle.recv(30),self.f)
self._strip_resp(self.handle.recv(30))
def read(self, slot, addr):
self.read_cnt += 1
#reg = addr/4 + 1
cmd = "readreg %d %x\r\n" % (slot, addr)
self.f.write(cmd);
if (ei2cdefine.DUMP):
self.f.write(cmd);
self.handle.send(cmd)
resp = _strip_resp(self.handle.recv(30),self.f)
resp = self._strip_resp(self.handle.recv(30))
return resp
def _strip_resp(msg,f):
def _strip_resp(self, msg):
"""Strip useful message from SysMon response.
"""Strip useful message from SysMon response.
The response string from the SysMon is stripped of unnecessary characters
and a "useful" string is returned. In case one of the error messages appear,
the function raises one of the EI2C exceptions."""
The response string from the SysMon is stripped of unnecessary characters
and a "useful" string is returned. In case one of the error messages appear,
the function raises one of the EI2C exceptions."""
#print msg.splitlines()
msg = msg.splitlines()[1]
f.write(msg + "\n")
#print msg.splitlines()
msg = msg.splitlines()[1]
if (ei2cdefine.DUMP):
self.f.write(msg + "\n")
if "Not Ack" in msg:
raise NAckError
if "Not Ack" in msg:
raise NAckError
if "Invalid register number!" in msg:
raise RegNumberError
if "Invalid register number!" in msg:
raise RegNumberError
if "Bad command!" in msg:
raise InvalidCmdError
if "Bad command!" in msg:
raise InvalidCmdError
if "I2C Timer expired" in msg:
raise TimerExpiredError
if "I2C Timer expired" in msg:
raise TimerExpiredError
if "Invalid slot number!" in msg:
raise SlotError
if "Invalid slot number!" in msg:
raise SlotError
if "Read Data:" in msg:
msg = msg.split(" ")[3]
msg = int(msg,16)
if "Read Data:" in msg:
msg = msg.split(" ")[3]
msg = int(msg,16)
return msg
return msg
#===============================================================================
# CERN (BE-CO-HT)
# EI2C global definitions file
#===============================================================================
# author: Theodor Stana (t.stana@cern.ch)
#
# date of creation: 2014-03-05
#
# version: 1.0
#
# description:
#
# This module defines some global constants that are used by other scripts in
# the software suite. The constants and their definitions are in the code
# below.
#
#===============================================================================
# GNU LESSER GENERAL PUBLIC LICENSE
#===============================================================================
# This source file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version. This source is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with this
# source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
#===============================================================================
# last changes:
# 2014-03-05 Theodor Stana File created
#===============================================================================
# TODO: -
#===============================================================================
# Hostname, username and password
HNAME = ""
USER = ""
PWD = ""
# Boolean to tell the ei2c.py module whether to create a dump file for the ELMA
# command replies
DUMP = False
import time
import sys
import time
sys.path.append("../ei2c")
from ei2c import *
if __name__ == "__main__":
# Ask for username and password and retry init in case of error
while 1:
ip = raw_input("Crate IP or hostname: ")
user = raw_input("Username: ")
pwd = raw_input("Password: ")
try:
testelma = EI2C(ip, user, pwd)
testelma.open()
break
except BadHostnameError as e:
print(e.strerror)
except BadUsernameError as e:
print(e.strerror)
except BadPasswordError as e:
print(e.strerror)
# Wait for proper slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Clear channel counters and close
testelma.write(slot, 0x0c, 0)
testelma.write(slot, 0x10, 0)
testelma.write(slot, 0x14, 0)
testelma.write(slot, 0x18, 0)
testelma.write(slot, 0x1c, 0)
testelma.write(slot, 0x20, 0)
testelma.close()
import sys
sys.path.append("../ei2c")
from ei2c import *
if __name__ == "__main__":
# Ask for username and password and retry init in case of error
while 1:
ip = raw_input("Crate IP or hostname: ")
user = raw_input("Username: ")
pwd = raw_input("Password: ")
try:
testelma = EI2C(ip, user, pwd)
testelma.open()
break
except BadHostnameError as e:
print(e.strerror)
except BadUsernameError as e:
print(e.strerror)
except BadPasswordError as e:
print(e.strerror)
# Wait for proper slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Get gateware version field and close
v = testelma.read(slot, 0x4)
maj = (v & 0xf0) >> 4
min = v & 0x0f
print("Gateware version: %d.%d" % (maj, min))
testelma.close()
import time
import sys
import time
sys.path.append("../ei2c")
from ei2c import *
if __name__ == "__main__":
# Ask for username and password and retry init in case of error
while 1:
ip = raw_input("Crate IP or hostname: ")
user = raw_input("Username: ")
pwd = raw_input("Password: ")
try:
testelma = EI2C(ip, user, pwd)
testelma.open()
break
except BadHostnameError as e:
print(e.strerror)
except BadUsernameError as e:
print(e.strerror)
except BadPasswordError as e:
print(e.strerror)
# Wait for proper slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Send magic sequence
testelma.write(slot, 0x8, 0xde << 2)
testelma.write(slot, 0x8, 0xad << 2)
testelma.write(slot, 0x8, 0xbe << 2)
testelma.write(slot, 0x8, 0xef << 2)
# Ask for which channel to trigger on, trigger, close and exit
chan = input("chan (1..6): ")
testelma.write(slot, 0x8, chan << 2)
testelma.close()
import time
import sys
import time
sys.path.append("../ei2c")
from ei2c import *
if __name__ == "__main__":
# Ask for username and password and retry init in case of error
while 1:
ip = raw_input("Crate IP or hostname: ")
user = raw_input("Username: ")
pwd = raw_input("Password: ")
try:
testelma = EI2C(ip, user, pwd)
testelma.open()
break
except BadHostnameError as e:
print(e.strerror)
except BadUsernameError as e:
print(e.strerror)
except BadPasswordError as e:
print(e.strerror)
# Wait for proper slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Print channel counter values, close and exit
print("CH1: %d" % testelma.read(slot, 0x0c))
print("CH2: %d" % testelma.read(slot, 0x10))
print("CH3: %d" % testelma.read(slot, 0x14))
print("CH4: %d" % testelma.read(slot, 0x18))
print("CH5: %d" % testelma.read(slot, 0x1c))
print("CH6: %d" % testelma.read(slot, 0x20))
testelma.close()
import sys
sys.path.append("../ei2c")
from ei2c import *
import math
if __name__ == "__main__":
# Ask for username and password and retry init in case of error
while 1:
ip = raw_input("Crate IP or hostname: ")
user = raw_input("Username: ")
pwd = raw_input("Password: ")
try:
testelma = EI2C(ip, user, pwd)
testelma.open()
break
except BadHostnameError as e:
print(e.strerror)
except BadUsernameError as e:
print(e.strerror)
except BadPasswordError as e:
print(e.strerror)
# Wait for proper slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Read while FIFO is not empty
csr = testelma.read(slot, 0x3c)
empty = csr & (1 << 17)
used = csr & 0x7f
while not empty:
# Get channel mask from meta register and convert it to channel number
ch = testelma.read(slot, 0x2c) & 0x3f
ch = 1 + int(math.log(ch)/math.log(2))
# Read cycles and seconds counters
cyc = testelma.read(slot, 0x30)
sl = testelma.read(slot, 0x34)
sh = testelma.read(slot, 0x38)
# The seconds counter indicates actual seconds; the cycles counter
# indicates 8-ns cycles, so convert to ns
s = (sh << 32) | sl
ns = cyc*8
# And print
csr = testelma.read(slot, 0x3c)
empty = csr & (1 << 17)
used = csr & 0x7f
print("(%3d) ch %d: %d.%09d sec" % (used, ch, s, ns))
import sys
sys.path.append("../ei2c")
import time
from ei2c import *
if __name__ == "__main__":
# Ask for username and password and retry init in case of error
while 1:
ip = raw_input("Crate IP or hostname: ")
user = raw_input("Username: ")
pwd = raw_input("Password: ")
try:
testelma = EI2C(ip, user, pwd)
testelma.open()
break
except BadHostnameError as e:
print(e.strerror)
except BadUsernameError as e:
print(e.strerror)
except BadPasswordError as e:
print(e.strerror)
# Wait for proper slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Set time stamp, close and exit
s = int(raw_input("Number of seconds: "))
testelma.write(slot, 0x24, s & 0xffffffff)
if s > 2**32-1:
testelma.write(slot, 0x28, s >> 32)
testelma.close()
......@@ -50,6 +50,7 @@ import sys
import time
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
from ei2cexcept import *
from functools import partial
......@@ -321,38 +322,28 @@ def _rdcfgreg():
# MAIN "FUNCTION"
if __name__ == "__main__":
# Ask for username and password and retry init in case of error
while 1:
ip = raw_input("Crate IP or hostname: ")
user = raw_input("Username: ")
pwd = raw_input("Password: ")
try:
testelma = EI2C(ip, user, pwd)
testelma.open()
break
except BadHostnameError as e:
print e.strerror
except BadUsernameError as e:
print e.strerror
except BadPasswordError as e:
print e.strerror
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Wait for proper slot number
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print "Please input a decimal slot number."
print("Please input a decimal slot number.")
except SlotError as e:
print e.strerror
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print "Unexpected error: ", sys.exc_info()[0]
print("Unexpected error: ", sys.exc_info()[0])
# The PULSETEST bitstream has the MultiBoot module starting at address 0x300
if (testelma.read(slot, 0x04) & 0xFF == 0xff):
......
import sys
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
MB_BASE = 0x40
MB_CR_OFS = 0x00
......@@ -51,24 +52,14 @@ def flash_read(addr, nrbytes):
if __name__ == "__main__":
# Ask for username and password and retry init in case of error
while 1:
ip = raw_input("Crate IP or hostname: ")
user = raw_input("Username: ")
pwd = raw_input("Password: ")
try:
testelma = EI2C(ip, user, pwd)
testelma.open()
break
except BadHostnameError as e:
print(e.strerror)
except BadUsernameError as e:
print(e.strerror)
except BadPasswordError as e:
print(e.strerror)
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Wait for proper slot number
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
......
pulsetest.py
============
This script runs the pulse test, by writing to the pulsetest FPGA gateware
the frequency of pulse generation to the channels the user wants to generate
pulses on.
To run, you first need a CONV-TTL-BLO with a pulsetest gateware. Then:
%> python pulsetest.py
Slot no.: <give the slot number of the pulsetest CONV-TTL-BLO>
Enable channel 1? (y/n) y
freq (Hz): 1
Enable channel 2? (y/n) n
Enable channel 3? (y/n) n
Enable channel 4? (y/n) y
freq (Hz): 2
Enable channel 5? (y/n) n
Enable channel 6? (y/n) y
freq (Hz): 4
How long would you like to run the test?
hrs: <give the number of hours>
mins: <give the number of minutes>
secs: <give the number of seconds>
For each channel you want to enable, it writes the frequency value to the
appropriate register in the pulsetest gateware, then sets the appropriate bits
in the control register to enable pulse generation. For more information on
the pulsetest gateware and the registers the script is writing, see:
http://www.ohwr.org/projects/conv-ttl-blo-gw/wiki/pulsetest
Note that the output frequency is limited to 166 kHz _in software_, to avoid
damage to the output transformers.
When the script finishes execution, it will store the output to a file it
specifies at the end. The name of this file is based on the date and time
the script started execution.
......@@ -3,6 +3,7 @@ import sys
import time
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
IDREG = 0x00
FWVREG = 0x04
......@@ -43,28 +44,27 @@ CTB_CLK_PER = 50*(10**(-9))
#CTB_CLK_PER = 8*(10**(-9))
if __name__ == "__main__":
ip = raw_input("Crate IP or hostname? ")
user = raw_input("Username? ")
pwd = raw_input("Password? ")
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Wait for proper slot number
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.? ")
slot = raw_input("Slot no.: ")
slot = int(slot)
testelma = EI2C(ip, user, pwd)
break
except TypeError as e:
print "Please input a decimal slot number."
print("Please input a decimal slot number.")
except SlotError as e:
print e.strerror
print(e.strerror)
except KeyboardInterrupt:
sys.exit()
sys.exit();
except:
print "Unexpected error: ", sys.exc_info()[0]
# Open I2C connection
testelma.open()
print("Unexpected error: ", sys.exc_info()[0])
bloid = testelma.read(slot, 0x00)
fwvers = testelma.read(slot, 0x04) & 0xFF
......
regtest.py
==========
This script runs the communication test, accessing the RAM in the regtest
gateware to read and write values to various RAM addresses.
To run:
%> python regtest.py
Slot no.: <give slot number>
How long would you like to run the test?
hrs: <give number of hours>
mins: <give number of minutes>
secs: <give number of seconds>
The script will then start writing and reading the RAM until the time you
selected elapses. To see exactly which addresses are being written, check the
code in the script file itself. The comments at the top of the file should
hopefully provide some help.
When the script finishes execution, it will store the output to a file it
specifies at the end. The name of this file is based on the date and time
the script started execution.
......@@ -10,9 +10,16 @@
#
# description:
#
# dependencies:
# This module runs the communication test by reading and writing to addresses
# in a RAM on the CONV-TTL-BLO regtest gateware for the FPGA.
#
# Without too much modification, it can be used in two modes:
# - read and write address 0
# - read and write the whole RAM
#
# To select between one of two modes, you need to comment or uncomment the
# proper code, as marked below.
#
# references:
#===============================================================================
# GNU LESSER GENERAL PUBLIC LICENSE
#===============================================================================
......@@ -27,7 +34,8 @@
# source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
#===============================================================================
# last changes:
# 2013-08-13 Theodor Stana t.stana@cern.ch File created
# 2013-08-13 Theodor Stana File created
# 2014-03-06 Theodor Stana Added description above
#===============================================================================
# TODO: -
#===============================================================================
......@@ -37,26 +45,35 @@ import sys
import time
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
RAMSTART = 0x000
RAMEND = 0xFFF
if __name__ == "__main__":
ip = raw_input("Crate IP or hostname? ")
user = raw_input("Username? ")
pwd = raw_input("Password? ")
# Wait for proper slot number
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Ask for slot number
while 1:
try:
nrslots = raw_input("Number of slots: ")
nrslots = int(nrslots)
testelma = EI2C(ip, user, pwd)
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit()
sys.exit();
except:
print "Unexpected error: ", sys.exc_info()[0]
print("Unexpected error: ", sys.exc_info()[0])
# Ask how long to run the test
print "How long would you like to run the test?"
......@@ -128,6 +145,9 @@ if __name__ == "__main__":
# Run test loop for the specified time
while time.time() < end_time:
#--------------------------------------------------------------------------
# Comment/uncomment here for accessing address 0
#--------------------------------------------------------------------------
if br:
break
......@@ -160,6 +180,9 @@ if __name__ == "__main__":
f.write("rex %i / %s / %s\r\n" % (i, time.strftime("%Y-%m-%d-%Hh%Mm%Ss",time.localtime()), e.strerror))
rexcep_cnt += 1
#--------------------------------------------------------------------------
# Comment/uncomment here for accessing the whole RAM
#--------------------------------------------------------------------------
# for i in range(1, nrslots+1):
# if br:
# break
......
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