#! /usr/bin/env	python
# coding: utf8
# Copyright CERN, 2011
# Author: Ross Millar <ross.millar@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org

import sys
import rr
import random
import time
import spi
import csr
import i2c
import gn4124
import fmc_adc_test_suite	
from ptsexcept import *
import os

"""
EEPROM test - Runs python tool to generate binary input file from calibration data and input XML file
"""
    
def main (default_directory='.'):

    path_fpga_loader = '../firmwares/fpga_loader';
    path_firmware = '../firmwares/TestSuite.bin'; 	
    firmware_loader = os.path.join(default_directory, path_fpga_loader)
    bitstream = os.path.join(default_directory, path_firmware)
    os.system( firmware_loader + ' ' + bitstream)
    time.sleep(2);

    # Objects declaration
    spec = rr.Gennum() 
    fmc = fmc_adc_test_suite.CFmcAdc100ks(spec)     
     
    # Runs fmc_eeprom_gen.py - giving file containg calibration data as an argument
    os.system("python fmc_eeprom_gen.py -r calibration_data.txt")
    
    # Uses eeprom class to dump the output file from fmc_eeprom_gen, into eeprom
    fmc.fmc_eeprom_gen_wr("eeprom_formatted_data.txt")
    
    time.sleep(.1)

if __name__ == '__main__' :
	main()    
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
