URL
https://opencores.org/ocsvn/lateq/lateq/trunk
Subversion Repositories lateq
[/] [lateq/] [trunk/] [hdl_single_type/] [src/] [latreadgen.py] - Rev 3
Compare with Previous | Blame | View Log
#!/usr/bin/python3 # This file was written by Wojciech M. Zabolotny (wzab@ise.pw.edu.pl) # And is published under BSD license import os import sys import string import copy #The C_LATEQ_MRK_MAX must be set to the same value as in lateq_pkg.vhd! C_LATEQ_MRK_MAX = 1000000 """ Below we define the package template, which will be later filled with generated data """ PkgTemp=""" ------------------------------------------------------------------------------- -- Title : Function returning delay values for delay equalizers -- Project : ------------------------------------------------------------------------------- -- File : ${file_name} -- This file is automatically generated, please don't edit it manually -- Standard : VHDL'93/02 ------------------------------------------------------------------------------- -- Description: Function, which returns delays associated with particular -- identifier -- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use std.textio.all; library work; ${packages} package ${package_name} is function ${function_name} ( constant leq_id : in string; constant n : in integer) return integer; end package ${package_name}; package body ${package_name} is function ${function_name} ( constant leq_id : in string; constant n : in integer) return integer is begin -- function ${function_name} if leq_id = "" then return 0; ${generated_clauses} else return 0; end if; end function ${function_name}; end package body ${package_name}; """ # Function below compares two time markers, considering # their wrapping def del_cmp(v1, v2): res=v1-v2 if res > C_LATEQ_MRK_MAX/2: res -= C_LATEQ_MRK_MAX if res < -C_LATEQ_MRK_MAX/2: res += C_LATEQ_MRK_MAX return res class del_checker(object): def __init__(self): self.dels = {} self.new_dels = {} self.is_set = False def feed(self,t): #print(t) if t[1]=="end": #New data entered, verify them dmin = self.new_dels[0] for i in self.new_dels.values(): if i<0: #At least one input not initialized. Skip the line return if del_cmp(dmin,i) > 0: dmin = i #We have found the "minimal" (considering wrapping) value for k in self.new_dels.keys(): tmp =self.new_dels[k] - dmin if tmp < 0: #Wrap the value tmp += C_LATEQ_MRK_MAX self.new_dels[k] = tmp if self.is_set: #Verify, that delay has not changed if not (self.new_dels == self.dels): raise Exception("Error, delay has changed:" + t[0]+" :"+str(self.dels)+"<->"+str(self.new_dels)) else: self.dels = copy.copy(self.new_dels) # We MUST use deep copy here! self.is_set = True else: self.new_dels[int(t[1])]=int(t[2]) # Definition of function, which analyses the delay report # and generates the delay defining function def analyse_del_rep(fname): # Now read the delay report file (generated by simulation) # If it is the first run, the file may not exist yet # In this case we generate function which always returns # delay=0 try: with open(report_file,"r") as fin: # The delay report contains lines containing the leq_id, the input number and the delay value. # Each series of values is finished with line containing the leq_id and the "end" string. # We read lines from the file. For each new identifier found we create an object which # will accumulate delay data for that identifier. # Then we will feed that object with lines. After the line with "end" is received, we calculate # the delay difference. IT SHOULD NOT CHANGE DURING THE SIMULATION ids = {} for line in fin: t=line.strip().split(",") if len(t) < 2: break #leq_id is in t[0] if not t[0] in ids: #add the object ids[t[0]] = del_checker() #Feed the analyser with the received line ids[t[0]].feed(t) except IOError as e: #Delay report could not be read - don't adjust delays return("") #All lines read, now generate the results #Iterate over all identifiers res="" for ni in ids.keys(): res += " elsif leq_id=\""+ni+"\" then\n" res += " case n is\n" for k,v in ids[ni].dels.items(): res += " when "+str(k)+" => return "+str(v)+";\n" res += " when others => return -1;\n" res += " end case;\n" return res if len(sys.argv)<5: appname=sys.argv[0] print(string.Template(""" Correct calling syntax: ${appname} report_file output_file package_name function_name """).substitute(locals())) sys.exit(0) fout=open(sys.argv[2], "w") ndef={} report_file=sys.argv[1] ndef['file_name']=sys.argv[2] ndef['package_name']=sys.argv[3] ndef['function_name']=sys.argv[4] ndef['packages']=""" use work.lateq_pkg.all; """ ndef['generated_clauses']=analyse_del_rep(report_file) tout=string.Template(PkgTemp).substitute(ndef) fout.write(tout) fout.close()