Commit 243cc399 authored by Matthieu Cattin's avatar Matthieu Cattin

New program to test FMC EEPROM formating and writing.

parent d1c8010c
#! /usr/bin/env python
# coding: utf8
# Copyright CERN, 2011
# Author: Matthieu Cattin <matthieu.cattin@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
import sys
import rr
import time
import datetime
import os
import libxml2
import spec_fmc_adc
import fmc_adc
"""
test19_eeprom: Test eeprom data formatting
Note: Requires test00.py to run first to load the firmware!
"""
def main (default_directory = '.'):
# Objects declaration
spec = rr.Gennum() # bind to the SPEC board
spec_fmc = spec_fmc_adc.CSpecFmcAdc100Ms(spec)
fmc = fmc_adc.CFmcAdc100Ms(spec)
############################################################################
# Append serial number and mfg date to XML file
############################################################################
serial_filename = "../../../serial.txt"
f_serial = open(serial_filename, 'r+')
serial = f_serial.readline()
f_serial.close()
serial = serial[:-1] # remove EOL char
print "serial number: %s"%serial
serial = '+' + serial + '.0'
# Calculate number of minutes since 1/1/96
now_date = datetime.datetime.now()
ref_date = datetime.datetime(1996, 1, 1)
diff_date = now_date - ref_date
minutes = "%d"%int(diff_date.total_seconds()//60)
print "Mfg date/time: %s"%minutes
sys.exit()
xml_filename = "test19_eeprom_input.xml"
doc = libxml2.parseFile(xml_filename)
root = doc.getRootElement()
area = root.children
while area is not None:
if area.type == "element":
areaContent = area.children
while areaContent is not None:
if areaContent.type == "element":
if areaContent.prop('name') == "Board_serial_number":
areaContent.setProp('content', serial)
print "Board serial number %s written to XML file"%serial
if areaContent.prop('name') == "Mfg. Date/Time":
areaContent.setProp('content', minutes)
print "Mfg date/time %s written to XML file"%minutes
areaContent=areaContent.next
area=area.next
f = open(xml_filename, 'w')
doc.saveTo(f)
f.close
############################################################################
# Format FMC EEPROM data
############################################################################
print "Formatting FMC EEPROM data"
os.system("python fmc_eeprom_gen.py -i test19_eeprom_input.xml -o test19_formatted_data.txt -r test19_corr_data.txt")
############################################################################
# Write data to FMC EEPROM
############################################################################
in_filename = "test19_formatted_data.txt"
eeprom_content = []
eeprom_addr = []
f_in = open(in_filename,"r+")
for line in f_in:
addr,data=line.split()
eeprom_content.append(int(data,2))
eeprom_addr.append(int(addr,2))
if len(eeprom_content) == 0:
print "[ERROR] Formatted data file is empty"
else:
byte_to_write = len(eeprom_content)
addr = 0
while byte_to_write:
if byte_to_write > 32:
size = 32
else:
size = byte_to_write
fmc.sys_i2c_eeprom_write(addr,eeprom_content[addr:(addr+size)])
byte_to_write -= size
addr += size
time.sleep(0.01) # have to wait between writes otherwise the eeprom gives NACK on the i2c bus
print "Data written to FMC EEPROM"
f_in.close()
############################################################################
# Verify EEPROM data
############################################################################
time.sleep(0.1)
if len(eeprom_content) != 0:
eeprom_content_read = fmc.sys_i2c_eeprom_read(0,len(eeprom_content))
error = 0
for i in range(len(eeprom_content)):
if eeprom_content[i] != eeprom_content_read[i]:
print "[ERROR] eeprom data corruption @ addr:%d expect:0x%.2X read:0x%.2X"%(i, eeprom_content[i], eeprom_content_read[i])
error += 1
if error == 0:
print "Data verification OK!"
if __name__ == '__main__' :
main()
<?xml version="1.0" encoding="UTF-8"?>
<FMC_EPROMDATA memory_size = "2000">
<area number ="1" pos_of_len_field = "2">
<field name= "Board Area Format version" type="binary" content="00000001" description= "Indentifies language used" has_typelen = "no" />
<field name= "Language" type="binary" content= "00000001" description= "Indentifies language used" has_typelen = "no" />
<field name= "Mfg. Date/Time" type="binary" content="00000010 01010101" description="Num of mins from 00:00hrs 1/1/96 - little endian" has_typelen = "no" />
<field name= "Board_manufacturer" type="ascii" content="CERN" description="the manufacturer of the board" has_typelen = "yes" />
<field name= "Board product name" type="ascii" content="fmc-adc-100m14b4cha" description="name of the board" has_typelen = "yes" />
<field name= "Board_serial_number" type="binary" content="00000000" description="serial number for board" has_typelen = "yes" />
<field name= "Board_part_number" type="ascii" content="Desired input" description= "Part number for the board" has_typelen = "yes"/>
<field name= "FRU File ID" type="ascii" content="User dependant" description= "User desired - identification of EEPROM info source" has_typelen = "yes"/>
<field name= "Custom Mfg fields" type="ascii" content="Userdependant" description= "Delete if undesired" has_typelen = "yes"/>
<FMC_EPROMDATA memory_size="2000">
<area number="1" pos_of_len_field="2">
<field name="Board Area Format version" type="binary" content="00000001" description="Indentifies language used" has_typelen="no"/>
<field name="Language" type="binary" content="00000001" description="Indentifies language used" has_typelen="no"/>
<field name="Mfg. Date/Time" type="binary" content="00000010 01010101" description="Num of mins from 00:00hrs 1/1/96 - little endian" has_typelen="no"/>
<field name="Board_manufacturer" type="ascii" content="CERN" description="the manufacturer of the board" has_typelen="yes"/>
<field name="Board product name" type="ascii" content="fmc-adc-100m14b4cha" description="name of the board" has_typelen="yes"/>
<field name="Board_serial_number" type="signed_short" content="+16.0" description="serial number for board" has_typelen="yes"/>
<field name="Board_part_number" type="ascii" content="Desired input" description="Part number for the board" has_typelen="yes"/>
<field name="FRU File ID" type="ascii" content="User dependant" description="User desired - identification of EEPROM info source" has_typelen="yes"/>
<field name="Custom Mfg fields" type="ascii" content="Userdependant" description="Delete if undesired" has_typelen="yes"/>
</area>
<area number ="5" pos_of_len_field = "0">
<multirecord name= "DC_LOAD" multi_record_num = "1">
<field name= "DC Load number" type="binary" content= "00000001" description= "DC load multirecord number" has_typelen = "no" />
<field name= "Nominal Voltage" type="signed_short" content= "+2.50" description= "Nominal voltage for Vadj" has_typelen = "no" />
<field name="min_v" type="signed_short" content="+0.00" description="Spec'd min voltage for Vadj" has_typelen = "no" />
<field name="max_v" type="signed_short" content="+0.00" description="Spec'd max voltage for Vadj" has_typelen = "no" />
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for vadj" has_typelen = "no" />
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for Vadj" has_typelen = "no" />
<field name="max_current" type="signed_short" content="+0.00" description= "Spec'd min current load for Vadj" has_typelen = "no"/>
<area number="5" pos_of_len_field="0">
<multirecord name="DC_LOAD" multi_record_num="1">
<field name="DC Load number" type="binary" content="00000001" description="DC load multirecord number" has_typelen="no"/>
<field name="Nominal Voltage" type="signed_short" content="+2.50" description="Nominal voltage for Vadj" has_typelen="no"/>
<field name="min_v" type="signed_short" content="+0.00" description="Spec'd min voltage for Vadj" has_typelen="no"/>
<field name="max_v" type="signed_short" content="+0.00" description="Spec'd max voltage for Vadj" has_typelen="no"/>
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for vadj" has_typelen="no"/>
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for Vadj" has_typelen="no"/>
<field name="max_current" type="signed_short" content="+0.00" description="Spec'd min current load for Vadj" has_typelen="no"/>
</multirecord>
<multirecord name= "DC_LOAD" multi_record_num = "2" >
<field name= "DC load number" type="binary" content="00000010" description= "DC output multirecord number" has_typelen = "no" />
<field name= "Nominal Voltage" type="signed_short" content= "+3.30" description= "Nominal voltage for 3P3V" has_typelen = "no" />
<field name="min_v" type="signed_short" content="+0.00" description="Spec'd min voltage for 3P3V" has_typelen = "no" />
<field name="max_v" type="signed_short" content="+0.00" description="Spec'd max voltage for 3P3V" has_typelen = "no" />
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for 3P3V" has_typelen = "no" />
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for 3P3V" has_typelen = "no" />
<field name="max_current" type="signed_short" content="+0.00" description= "Spec'd min current load for 3P3V" has_typelen = "no" />
<multirecord name="DC_LOAD" multi_record_num="2">
<field name="DC load number" type="binary" content="00000010" description="DC output multirecord number" has_typelen="no"/>
<field name="Nominal Voltage" type="signed_short" content="+3.30" description="Nominal voltage for 3P3V" has_typelen="no"/>
<field name="min_v" type="signed_short" content="+0.00" description="Spec'd min voltage for 3P3V" has_typelen="no"/>
<field name="max_v" type="signed_short" content="+0.00" description="Spec'd max voltage for 3P3V" has_typelen="no"/>
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for 3P3V" has_typelen="no"/>
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for 3P3V" has_typelen="no"/>
<field name="max_current" type="signed_short" content="+0.00" description="Spec'd min current load for 3P3V" has_typelen="no"/>
</multirecord>
<multirecord name= "DC_LOAD" multi_record_num = "3" >
<field name= "DC load number" type="binary" content= "00000011" description= "DC output multirecord number" has_typelen = "no" />
<field name= "Nominal Voltage" type="signed_short" content= "+12.00" description= "Nominal voltage for 12P0V" has_typelen = "no" />
<field name="min_v" type="signed_short" content = "+0.00" description="Spec'd min voltage for 12P0V" has_typelen = "no" />
<field name="max_v" type="signed_short" content = "+0.00" description="Spec'd max voltage for 12P0V" has_typelen = "no" />
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for 12P0V" has_typelen = "no" />
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for 12P0V" has_typelen = "no" />
<field name="max_current" type="signed_short" content="+0.00" description= "Spec'd min current load for 12P0V" has_typelen = "no" />
<multirecord name="DC_LOAD" multi_record_num="3">
<field name="DC load number" type="binary" content="00000011" description="DC output multirecord number" has_typelen="no"/>
<field name="Nominal Voltage" type="signed_short" content="+12.00" description="Nominal voltage for 12P0V" has_typelen="no"/>
<field name="min_v" type="signed_short" content="+0.00" description="Spec'd min voltage for 12P0V" has_typelen="no"/>
<field name="max_v" type="signed_short" content="+0.00" description="Spec'd max voltage for 12P0V" has_typelen="no"/>
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for 12P0V" has_typelen="no"/>
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for 12P0V" has_typelen="no"/>
<field name="max_current" type="signed_short" content="+0.00" description="Spec'd min current load for 12P0V" has_typelen="no"/>
</multirecord>
<multirecord name= "DC_OUTPUT" multi_record_num = "1" >
<field name= "DC Output number" type="binary" content= "00000001" description= "DC output multirecord number" has_typelen = "no" />
<field name= "Nominal Voltage" type="signed_short" content= "+0.00" description= "Nominal voltage for VIO_B_M2C" has_typelen = "no" />
<field name="min_v" type="signed_short" content = "+0.00" description="Spec'd min voltage for VIO_B_M2C" has_typelen = "no" />
<field name="max_v" type="signed_short" content = "+0.00" description="Spec'd max voltage for VIO_B_M2C" has_typelen = "no" />
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for VIO_B_M2C" has_typelen = "no" />
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for VIO_B_M2C" has_typelen = "no" />
<field name="max_current" type="signed_short" content="+0.00" description= "Spec'd min current load for VIO_B_M2C" has_typelen = "no" />
<multirecord name="DC_OUTPUT" multi_record_num="1">
<field name="DC Output number" type="binary" content="00000001" description="DC output multirecord number" has_typelen="no"/>
<field name="Nominal Voltage" type="signed_short" content="+0.00" description="Nominal voltage for VIO_B_M2C" has_typelen="no"/>
<field name="min_v" type="signed_short" content="+0.00" description="Spec'd min voltage for VIO_B_M2C" has_typelen="no"/>
<field name="max_v" type="signed_short" content="+0.00" description="Spec'd max voltage for VIO_B_M2C" has_typelen="no"/>
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for VIO_B_M2C" has_typelen="no"/>
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for VIO_B_M2C" has_typelen="no"/>
<field name="max_current" type="signed_short" content="+0.00" description="Spec'd min current load for VIO_B_M2C" has_typelen="no"/>
</multirecord>
<multirecord name= "DC_OUTPUT" multi_record_num = "2" >
<field name= "DC Output number" type="binary" content= "00000010" description= "DC output multirecord number" has_typelen = "no" />
<field name= "Nominal Voltage" type="signed_short" content= "+0.00" description= "Nominal voltage for VREF_A_M2C" has_typelen = "no" />
<field name="min_v" type="signed_short" content = "+0.00" description="Spec'd min voltage for VREF_A_M2C" has_typelen = "no" />
<field name="max_v" type="signed_short" content = "+0.00" description="Spec'd max voltage for VREF_A_M2C" has_typelen = "no" />
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for VREF_A_M2C" has_typelen = "no" />
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for VREF_A_M2C" has_typelen = "no" />
<field name="max_current" type="signed_short" content="+0.00" description= "Spec'd min current load for VREF_A_M2C" has_typelen = "no" />
<multirecord name="DC_OUTPUT" multi_record_num="2">
<field name="DC Output number" type="binary" content="00000010" description="DC output multirecord number" has_typelen="no"/>
<field name="Nominal Voltage" type="signed_short" content="+0.00" description="Nominal voltage for VREF_A_M2C" has_typelen="no"/>
<field name="min_v" type="signed_short" content="+0.00" description="Spec'd min voltage for VREF_A_M2C" has_typelen="no"/>
<field name="max_v" type="signed_short" content="+0.00" description="Spec'd max voltage for VREF_A_M2C" has_typelen="no"/>
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for VREF_A_M2C" has_typelen="no"/>
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for VREF_A_M2C" has_typelen="no"/>
<field name="max_current" type="signed_short" content="+0.00" description="Spec'd min current load for VREF_A_M2C" has_typelen="no"/>
</multirecord>
<multirecord name= "DC_OUTPUT" multi_record_num = "3" >
<field name= "DC Output number" type="binary" content= "00000011" description= "DC output multirecord number" has_typelen = "no" />
<field name= "Nominal Voltage" type="signed_short" content= "+0.00" description= "Nominal voltage for VREF_A_M2C" has_typelen = "no" />
<field name="min_v" type="signed_short" content = "+0.00" description="Spec'd min voltage for VREF_B_M2C" has_typelen = "no" />
<field name="max_v" type="signed_short" content = "+0.00" description="Spec'd max voltage for VREF_B_M2C" has_typelen = "no" />
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for VREF_B_M2C" has_typelen = "no" />
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for VREF_B_M2C" has_typelen = "no" />
<field name="max_current" type="signed_short" content="+0.00" description= "Spec'd min current load for VREF_B_M2C" has_typelen = "no" />
<multirecord name="DC_OUTPUT" multi_record_num="3">
<field name="DC Output number" type="binary" content="00000011" description="DC output multirecord number" has_typelen="no"/>
<field name="Nominal Voltage" type="signed_short" content="+0.00" description="Nominal voltage for VREF_A_M2C" has_typelen="no"/>
<field name="min_v" type="signed_short" content="+0.00" description="Spec'd min voltage for VREF_B_M2C" has_typelen="no"/>
<field name="max_v" type="signed_short" content="+0.00" description="Spec'd max voltage for VREF_B_M2C" has_typelen="no"/>
<field name="ripple_pk_pk" type="signed_short" content="+0.00" description="Spec'd Ripple and noise pk - pk for VREF_B_M2C" has_typelen="no"/>
<field name="min_current" type="signed_short" content="+0.00" description="Spec'd min current load for VREF_B_M2C" has_typelen="no"/>
<field name="max_current" type="signed_short" content="+0.00" description="Spec'd min current load for VREF_B_M2C" has_typelen="no"/>
</multirecord>
<multirecord name= "OEM_record" multi_record_num = "1" >
<byteField name ="OEM Bytefield 1" >
<field name= "Subtype" type="binary" content= "0000" description= "0 for main definition type" has_typelen = "no" />
<field name= "Version" type="binary" content= "0000" description= "0 for current version" has_typelen = "no" />
<multirecord name="OEM_record" multi_record_num="1">
<byteField name="OEM Bytefield 1">
<field name="Subtype" type="binary" content="0000" description="0 for main definition type" has_typelen="no"/>
<field name="Version" type="binary" content="0000" description="0 for current version" has_typelen="no"/>
</byteField>
<byteField name ="OEM Bytefield 2" >
<field name= "Module Size" type="binary" content= "00" description= "Single width = 00, Double = 01" has_typelen = "no" />
<field name= "P1 Connector Size" type="binary" content= "01" description= "LPC connecter = 00 HPC connecter = 01" has_typelen = "no" />
<field name= "P2 Connector Size" type="binary" content= "11" description= "Same as above, or Not fitted =11" has_typelen = "no" />
<field name= "Clock Direction" type="binary" content= "1" description= "Mez to carrier = 0,Carrier to Mez =1" has_typelen = "no" />
<field name= "Reserved" type="binary" content= "0" description= "Reserved, by FMC standard" has_typelen = "no" />
<byteField name="OEM Bytefield 2">
<field name="Module Size" type="binary" content="00" description="Single width = 00, Double = 01" has_typelen="no"/>
<field name="P1 Connector Size" type="binary" content="01" description="LPC connecter = 00 HPC connecter = 01" has_typelen="no"/>
<field name="P2 Connector Size" type="binary" content="11" description="Same as above, or Not fitted =11" has_typelen="no"/>
<field name="Clock Direction" type="binary" content="1" description="Mez to carrier = 0,Carrier to Mez =1" has_typelen="no"/>
<field name="Reserved" type="binary" content="0" description="Reserved, by FMC standard" has_typelen="no"/>
</byteField>
<field name="P1 Bank A number of signals" type="binary" content="00011110" description= "Binary num of size byte" has_typelen = "no" />
<field name="P1 Bank B number of signals" type="binary" content="00000000" description= "Binary num of size byte" has_typelen = "no" />
<field name="P2 Bank A number of signals" type="binary" content="00000000" description= "Binary num of size byte" has_typelen = "no" />
<field name="P2 Bank B number of signals" type="binary" content="00000000" description= "Binary num of size byte" has_typelen = "no" />
<byteField name ="OEM Bytefield 3" >
<field name="P1 GBT Number Transsceivers" type="binary" content="0000" description= "Binary num of size 4 bits" has_typelen = "no" />
<field name="P2 GBT Number Transsceivers" type="binary" content="0000" description= "Binary num of size 4 bits" has_typelen = "no" />
<field name="P1 Bank A number of signals" type="binary" content="00011110" description="Binary num of size byte" has_typelen="no"/>
<field name="P1 Bank B number of signals" type="binary" content="00000000" description="Binary num of size byte" has_typelen="no"/>
<field name="P2 Bank A number of signals" type="binary" content="00000000" description="Binary num of size byte" has_typelen="no"/>
<field name="P2 Bank B number of signals" type="binary" content="00000000" description="Binary num of size byte" has_typelen="no"/>
<byteField name="OEM Bytefield 3">
<field name="P1 GBT Number Transsceivers" type="binary" content="0000" description="Binary num of size 4 bits" has_typelen="no"/>
<field name="P2 GBT Number Transsceivers" type="binary" content="0000" description="Binary num of size 4 bits" has_typelen="no"/>
</byteField>
<field name="Max clock for TCK" type="binary" content="00000000" description= "Binary num of size byte" has_typelen = "no" />
<field name="Max clock for TCK" type="binary" content="00000000" description="Binary num of size byte" has_typelen="no"/>
</multirecord>
</area>
</FMC_EPROMDATA>
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