Commit 29542254 authored by Matthieu Cattin's avatar Matthieu Cattin

test05: Uses common modules, added exception handling.

parent 350b0a50
......@@ -4,15 +4,26 @@
# Author: Matthieu Cattin <matthieu.cattin@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
# Last modifications: 23/5/2012
# Import system modules
import sys
import rr
import time
import os
# Add common modules and libraries location to path
sys.path.append('../../../')
sys.path.append('../../../gnurabbit/python/')
sys.path.append('../../../common/')
# Import common modules
from ptsexcept import *
import rr
# Import specific modules
from fmc_adc_spec import *
from fmc_adc import *
import fmc_adc
"""
test05: Test LTC2174 ADC
......@@ -20,54 +31,78 @@ test05: Test LTC2174 ADC
Note: Requires test00.py to run first to load the firmware!
"""
TEST_PATTERN = 0x3FFF
NB_CHANNELS = 4
def main (default_directory='.'):
"""
path_fpga_loader = '../../../gnurabbit/user/fpga_loader';
path_firmware = '../firmwares/spec_fmcadc100m14b4cha.bin';
firmware_loader = os.path.join(default_directory, path_fpga_loader)
bitstream = os.path.join(default_directory, path_firmware)
print firmware_loader + ' ' + bitstream
os.system( firmware_loader + ' ' + bitstream )
time.sleep(2);
"""
# Objects declaration
spec = rr.Gennum() # bind to the SPEC board
fmc = fmc_adc.CFmcAdc100Ms(spec)
# Set and enable test pattern
fmc.testpat_en(TEST_PATTERN)
# Read and check test pattern
pattern = fmc.get_testpat()
if(TEST_PATTERN != pattern):
print('pattern:%.4X read:%.4X')%(TEST_PATTERN, pattern)
raise PtsError('Cannot access LTC2174 ADC through SPI')
# Print LTC2174 configuration
fmc.print_adc_regs()
# Check that SerDes are synchronised
if(0 == fmc.get_serdes_sync_stat()):
raise PtsError('SerDes are not synchronised')
# Read channels current data register
error=0
for i in range(1,NB_CHANNELS+1):
adc_value = fmc.get_current_adc_value(i)
print('ADC channel %d value:0x%.4X expected:0x%.4X') % (i, adc_value, (TEST_PATTERN<<2))
if((TEST_PATTERN<<2) != adc_value):
print('Error: value mismatch!')
error += 1
if(error != 0):
raise PtsError('Data read from LTC2174 ADC are wrong for one or more channels.')
# Constants declaration
TEST_NB = 5
EXPECTED_BITSTREAM_TYPE = 0x1
NB_CHANNELS = 4
TEST_PATTERN = 0x79A
start_test_time = time.time()
print "================================================================================"
print "Test%02d start\n" % TEST_NB
# SPEC object declaration
print "Loading hardware access library and opening device.\n"
spec = rr.Gennum()
# Carrier object declaration (SPEC board specific part)
# Used to check that the firmware is loaded.
try:
carrier = CFmcAdc100mSpec(spec, EXPECTED_BITSTREAM_TYPE)
except FmcAdc100mSpecOperationError as e:
raise PtsCritical("Carrier init failed, test stopped: %s" % e)
# Mezzanine object declaration (FmcAdc100m14b4cha board specific part)
try:
fmc = CFmcAdc100m(spec)
except FmcAdc100mOperationError as e:
raise PtsCritical("Mezzanine init failed, test stopped: %s" % e)
try:
# Set and enable test pattern
fmc.testpat_en(TEST_PATTERN)
# Read and check test pattern
pattern = fmc.get_testpat()
if(TEST_PATTERN != pattern):
print('pattern:%.4X read:%.4X')%(TEST_PATTERN, pattern)
raise PtsError('Cannot access LTC2174 ADC through SPI')
# Print LTC2174 configuration
fmc.print_adc_regs()
print ""
# Check that SerDes are synchronised
if(0 == fmc.get_serdes_sync_stat()):
raise PtsError('SerDes are not synchronised')
else:
print "SerDes are synchronised.\n"
# Read channels current data register
print "Check received data."
error=0
for i in range(1,NB_CHANNELS+1):
adc_value = fmc.get_current_adc_value(i)
print('ADC channel %d value:0x%.4X expected:0x%.4X') % (i, adc_value, (TEST_PATTERN<<2))
if((TEST_PATTERN<<2) != adc_value):
print('Error: value mismatch!')
error += 1
if(error != 0):
raise PtsError('Data read from LTC2174 ADC are wrong for one or more channels.')
except FmcAdc100mOperationError as e:
raise PtsError("Test failed: %s" % e)
print ""
print "==> End of test%02d" % TEST_NB
print "================================================================================"
end_test_time = time.time()
print "Test%02d elapsed time: %.2f seconds\n" % (TEST_NB, end_test_time-start_test_time)
if __name__ == '__main__' :
......
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