ELGIP-2 Adding in first generic IP to EL-GENERIC-IP library repository

This commit is contained in:
Simon Southwell 2018-09-26 11:44:55 +01:00
commit 430b455145
37 changed files with 15553 additions and 0 deletions

1
README.txt Normal file
View file

@ -0,0 +1 @@
As this repository will have links made into other repositories, no IP directories should be made at this level, as this level contains a .git, and the receiving repo, with the;link, will show GIT information, and indicate modifications. A check-in of the destination repo could inadvertantly check-in changes to this repository. All IP should be placed in the generic_ip folder (or lower), and this folder linked to the destination repository.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,678 @@
import sys
import os
import fileinput
import subprocess
import shutil
from distutils.dir_util import copy_tree
from os import listdir
from os.path import isfile, join, isdir
subst_array = dict([
('MM_interface', 'Mi' )
,('mm_interconnect', 'mi' )
,('agent_rsp_fifo', 'arf' )
,('avalon_slave', 'avas')
,('translator_avalon_universal_slave', 'taus')
,('translator_avalon_universal_master', 'taum')
])
batch = 0
def get_tool_root():
tmpPath = os.environ['QUARTUS_ROOTDIR']
newPath = tmpPath.replace('\\', '/')
return newPath
def get_dev_root():
tmpPath = os.getcwd()
tmpList = tmpPath.split("\\build")
intPath = tmpList[0]
tmpList = intPath.split("\\sim")
newPath = tmpList[0]
newPath = newPath.replace('\\', '/')
return newPath
def my_module():
firstArg = sys.argv[0]
splitList = firstArg.split(".")
return splitList[0]
def create_new_qsys():
readFileName = get_dev_root() + "/build/" + my_module() + "_system.qsys.tmp"
writeFileName = get_dev_root() + "/build/" + my_module() + "_system.qsys"
if os.path.isfile(readFileName):
os.remove(readFileName)
os.rename(writeFileName, readFileName)
readFile = open(readFileName , "r")
writeFile = open(writeFileName, "w")
for line in readFile:
newLine = line
if ("defaultValue" in line):
#newLine = newLine.replace(" elab", " elab_tb")
newLine = ''' defaultValue="101"''' + "\n"
writeFile.write(newLine)
readFile.close()
writeFile.close()
def conv2008(fileToSearch):
textToSearch = "vcom"
textToReplace = "vcom -2008"
tempFile = open( fileToSearch, 'r+' )
for line in fileinput.input( fileToSearch ):
tempFile.write( line.replace( textToSearch, textToReplace ) )
tempFile.close()
def generate_sim_files(searchPathList):
totalPath = "$"
for ip in searchPathList:
searchPath = ''.join(['../../', ip, '/src/'])
totalPath = ','.join([totalPath, searchPath])
searchPath = ''.join(['../../', ip, '/build/'])
totalPath = ','.join([totalPath, searchPath])
# Run Qsys 'generate IP'
myCmd = '''_TOOL_ROOT_/sopc_builder/bin/ip-generate --remove-qsys-generate-warning --project-directory=_DEV_ROOT_/build --output-directory=_DEV_ROOT_/build/_MODULE_/simulation --file-set=SIM_VHDL --report-file=html:_DEV_ROOT_/build/_MODULE_/_MODULE_.html --report-file=sopcinfo:_DEV_ROOT_/build/_MODULE_.sopcinfo --report-file=csv:_DEV_ROOT_/build/_MODULE_/_MODULE_.csv --report-file=spd:_DEV_ROOT_/build/_MODULE_/_MODULE_.spd --report-file=cmp:_DEV_ROOT_/build/_MODULE_/_MODULE_.cmp --report-file=sip:_DEV_ROOT_/build/_MODULE_/simulation/_MODULE_.sip --system-info=DEVICE_FAMILY=\"Cyclone V\" --system-info=DEVICE=5CSXFC6D6F31C8ES --system-info=DEVICE_SPEEDGRADE=8_H6 --component-file=_DEV_ROOT_/build/_MODULE_.qsys --search-path=_SEARCH_PATH_'''
myCmd = myCmd.replace('_TOOL_ROOT_', get_tool_root())
myCmd = myCmd.replace('_DEV_ROOT_', get_dev_root())
myCmd = myCmd.replace('_MODULE_', "".join([my_module() + "_system"]))
myCmd = myCmd.replace('_SEARCH_PATH_', totalPath)
print myCmd
myCmdArray = myCmd.split(" ")
subprocess.call(myCmdArray)
# Run Qsys 'generate scripts'
myCmd = '''_TOOL_ROOT_/sopc_builder/bin/sim-script-gen --spd=_DEV_ROOT_/build/_MODULE_/_MODULE_.spd --output-directory=_DEV_ROOT_/build/_MODULE_/simulation/ --use-relative-paths=true'''
myCmd = myCmd.replace('_TOOL_ROOT_', get_tool_root())
myCmd = myCmd.replace('_DEV_ROOT_', get_dev_root())
myCmd = myCmd.replace('_MODULE_', "".join([my_module() + "_system"]))
myCmd = myCmd.replace('_SEARCH_PATH_', totalPath)
print myCmd
myCmdArray = myCmd.split(" ")
subprocess.call(myCmdArray)
# Run Qsys 'generate bsf'
myCmd = '''_TOOL_ROOT_/sopc_builder/bin/ip-generate --project-directory=_DEV_ROOT_/build --output-directory=_DEV_ROOT_/build/_MODULE_ --report-file=bsf:_DEV_ROOT_/build/_MODULE_/stripe_transform_system.bsf --system-info=DEVICE_FAMILY="Cyclone V" --system-info=DEVICE=5CSXFC6D6F31C6 --system-info=DEVICE_SPEEDGRADE=6_H6 --component-file=_DEV_ROOT_/build/_MODULE_.qsys --remove-qsys-generate-warning'''
myCmd = myCmd.replace('_TOOL_ROOT_', get_tool_root())
myCmd = myCmd.replace('_DEV_ROOT_', get_dev_root())
myCmd = myCmd.replace('_MODULE_', "".join([my_module() + "_system"]))
myCmd = myCmd.replace('_SEARCH_PATH_', totalPath)
print myCmd
myCmdArray = myCmd.split(" ")
subprocess.call(myCmdArray)
myCmd2 = '''_DEV_ROOT_/build/_MODULE_/simulation/mentor/msim_setup.tcl'''
myCmd2 = myCmd2.replace('_DEV_ROOT_', get_dev_root())
myCmd2 = myCmd2.replace('_MODULE_', "".join([my_module() + "_system"]))
print myCmd2
conv2008(myCmd2)
def generate_synth_files(searchPathList):
totalPath = "$"
for ip in searchPathList:
searchPath = ''.join(['../../', ip, '/src/'])
totalPath = ','.join([totalPath, searchPath])
searchPath = ''.join(['../../', ip, '/build/'])
totalPath = ','.join([totalPath, searchPath])
searchPath = '../../**/*'
totalPath = ','.join([totalPath, searchPath])
# Run Qsys 'generate'
myCmd = '''_TOOL_ROOT_/sopc_builder/bin/ip-generate --project-directory=_DEV_ROOT_/build --output-directory=_DEV_ROOT_/build/_MODULE_ --report-file=bsf:_DEV_ROOT_/build/_MODULE_/_MODULE_.bsf --system-info=DEVICE_FAMILY="Cyclone V" --system-info=DEVICE=5CSXFC6D6F31C6 --system-info=DEVICE_SPEEDGRADE=6_H6 --component-file=_DEV_ROOT_/build/_MODULE_.qsys --remove-qsys-generate-warning --search-path=$,../../../../../**/*'''
myCmd = myCmd.replace('_TOOL_ROOT_', get_tool_root())
myCmd = myCmd.replace('_DEV_ROOT_', get_dev_root())
myCmd = myCmd.replace('_MODULE_', "".join([my_module() + "_system"]))
myCmd = myCmd.replace('_SEARCH_PATH_', totalPath)
print myCmd
myCmdArray = myCmd.split(" ")
subprocess.call(myCmdArray)
# Run Qsys 'generate'
myCmd = '''_TOOL_ROOT_/sopc_builder/bin/ip-generate --project-directory=_DEV_ROOT_/build --output-directory=_DEV_ROOT_/build/_MODULE_/synthesis --file-set=QUARTUS_SYNTH --report-file=html:_DEV_ROOT_/build/_MODULE_/_MODULE_.html --report-file=sopcinfo:_DEV_ROOT_/build/_MODULE_.sopcinfo --report-file=cmp:_DEV_ROOT_/build/_MODULE_/_MODULE_.cmp --report-file=qip:_DEV_ROOT_/build/_MODULE_/synthesis/_MODULE_.qip --report-file=svd:_DEV_ROOT_/build/_MODULE_/synthesis/_MODULE_.svd --report-file=regmap:_DEV_ROOT_/build/_MODULE_/synthesis/_MODULE_.regmap --report-file=xml:_DEV_ROOT_/build/_MODULE_/_MODULE_.xml --report-file=debuginfo:_DEV_ROOT_/build/_MODULE_/synthesis/_MODULE_.debuginfo --system-info=DEVICE_FAMILY="Cyclone V" --system-info=DEVICE=5CSXFC6D6F31C6 --system-info=DEVICE_SPEEDGRADE=6_H6 --component-file=_DEV_ROOT_/build/_MODULE_.qsys --remove-qsys-generate-warning --language=VHDL --search-path=$,../../../../../**/* --component-parameter=sysid_ver_num=_VER_NUM_'''
myCmd = myCmd.replace('_TOOL_ROOT_', get_tool_root())
myCmd = myCmd.replace('_DEV_ROOT_', get_dev_root())
myCmd = myCmd.replace('_MODULE_', "".join([my_module() + "_system"]))
myCmd = myCmd.replace('_SEARCH_PATH_', totalPath)
myCmd = myCmd.replace('_VER_NUM_', "8")
print myCmd
myCmdArray = myCmd.split(" ")
subprocess.call(myCmdArray)
# Perform Quartus synthesis
myCmd = '''_TOOL_ROOT_/bin64/quartus_sh --flow compile _MODULE_'''
myCmd = myCmd.replace('_TOOL_ROOT_', get_tool_root())
myCmd = myCmd.replace('_MODULE_', "".join([my_module() + "_system"]))
print myCmd
myCmdArray = myCmd.split(" ")
subprocess.call(myCmdArray)
def get_batch_mode():
for i in sys.argv:
if i == 'yesBatch':
print "yesBatch detected"
return 1
return 0
def get_qsys_build():
for i in sys.argv:
if i == 'yesQsys':
print "yesQsys detected"
return 1
return 0
def copy_files(system_name):
# Move, shorten, and then move back the generated files
curPath = os.getcwd()
srcPath = "".join(["..\\build\\" + system_name + "_system\simulation"])
print srcPath
dstPath = "c:\simulation"
# Create directories if they don't exist
if not os.path.exists(dstPath): os.makedirs(dstPath)
if not os.path.exists("".join([dstPath, "\submodules"])): os.makedirs("".join([dstPath, "\submodules"]))
if not os.path.exists("".join([dstPath, "\mentor"])): os.makedirs("".join([dstPath, "\mentor"]))
# Clear out what is currently in the temporary directory
os.chdir(dstPath)
filelist = [ f for f in os.listdir(".") if f.endswith(".vhd") ]
filelist = filelist + [ f for f in os.listdir(".") if f.endswith(".vho") ]
filelist = filelist + [ f for f in os.listdir(".") if f.endswith(".safe")]
filelist = filelist + [ f for f in os.listdir(".") if f.endswith(".sip") ]
filelist = filelist + [ f for f in os.listdir(".") if f.endswith("~") ]
for f in filelist: os.remove(f)
os.chdir("submodules")
filelist = [ f for f in os.listdir(".") if f.endswith(".vhd") ]
filelist = filelist + [ f for f in os.listdir(".") if f.endswith(".vho") ]
filelist = filelist + [ f for f in os.listdir(".") if f.endswith(".safe")]
filelist = filelist + [ f for f in os.listdir(".") if f.endswith("~") ]
for f in filelist: os.remove(f)
os.chdir(curPath)
# Perform the copy
#shutil.copyfile("\\".join([srcPath, "submodules\\print_control_system_head_1_Print_data.vhd"]),
# "\\".join([dstPath, "submodules\\print_control_system_head_1_Print_data.vhd"]))
subprocess.call(" ".join(["robocopy ", srcPath , dstPath]) , shell=True)
subprocess.call(" ".join(["robocopy ", "".join([srcPath, "\submodules"]), "".join([dstPath, "\submodules"])]), shell=True)
subprocess.call(" ".join(["robocopy ", "".join([srcPath, "\mentor"]) , "".join([dstPath, "\mentor"])]) , shell=True)
def return_files(system_name):
# Move, shorten, and then move back the generated files
srcPath = "c:/simulation"
dstPath = "".join(["..\\build\\" + system_name + "_system\simulation"])
myCmd = " ".join(["robocopy /E", srcPath, dstPath])
#print myCmd
subprocess.call(myCmd, shell=True)
def get_top_level():
searchfile = open('msim_setup.tcl', "r")
for line in searchfile:
if "set TOP_LEVEL_NAME" in line:
myList = line.split('''"''')
topLevel = myList[1]
#topLevel = "".join([myList[1], "_mm_interconnect"])
#print topLevel
searchfile.close()
return topLevel
def edit_msim_setup(longName, sub_array):
tbName = "".join([longName, "_tb -f args.txt"])
#sub_array[longerName] = "shrt"
sub_keys = sub_array.keys()
readFileName = 'msim_setup_old.tcl'
writeFileName = 'msim_setup.tcl'
if os.path.isfile(readFileName):
os.remove(readFileName)
os.rename(writeFileName, readFileName)
readFile = open('msim_setup_old.tcl', "r")
writeFile = open('msim_setup.tcl', "w")
copyNum = 0
elab_tb = 0
myAlias = ""
for line in readFile:
newLine = line
pcName = os.environ['USERDOMAIN']
# Swap in 'dev_com' edit
if ((" if " in line) and ("ModelSim" in line)):
if 'MULL' in pcName:
newLine = " if ![file isdirectory libraries/cyclonev/cyclonev_and1] {\n"
else:
newLine = " if [file isdirectory libraries/cyclonev/cyclonev_and1] {\n"
# Swap in shortened file names
for key in sub_keys:
if (elab_tb == 0): newLine = newLine.replace(key, sub_array[key])
# Check to see if we have already added the new 'elab_tb'
if ("alias elab_tb " in line):
elab_tb = 1
# Detect the 'elab' target and take a copy while creating the 'elab_tb'
if (("alias elab " in line) and (elab_tb == 0)):
copyNum = 5
elif copyNum > 0:
copyNum = copyNum - 1
if copyNum > 1:
myAlias = "".join([myAlias, newLine])
newLine = newLine.replace(" elab", " elab_tb")
newLine = newLine.replace('''$TOP_LEVEL_NAME''', tbName)
elif copyNum == 1:
writeFile.write(myAlias)
# Write back the original 'elab' target
writeFile.write(newLine)
readFile.close()
writeFile.close()
def rename_top_level(topLevel, longName, sub_array):
readFileName = "".join(["../", topLevel, "_old.vhd"])
writeFileName = "".join(["../", topLevel, ".vhd"])
sub_keys = sub_array.keys()
if os.path.isfile(readFileName):
os.remove(readFileName)
os.rename(writeFileName, readFileName)
readFile = open(readFileName, "r")
writeFile = open(writeFileName, "w")
myHeadAux = 0
entity = 1
for line in readFile:
newLine = line
# Replace all the long strings with shortened versions
for key in sub_keys:
newLine = newLine.replace(key, sub_array[key])
# Remove the std_logic_vector initialisation values as this upsets SystemC flow
if (": in " in newLine) and ("address " in newLine) and (entity == 1):
newLine = newLine.replace(":= '0'", "")
if (": in " in newLine) and (entity == 1):
newLine = newLine.replace(":= (others => '0')", "")
if ("end entity" in newLine):
entity = 0
# Correct the 1 bit address vector width issue
if ("address " in newLine) and (": in " in newLine) and (" std_logic " in newLine):
newLine = newLine.replace("std_logic", "std_logic_vector(0 downto 0)")
newLine = newLine.replace("'X'", "(others => 'X')")
newLine = newLine.replace("(0)", "")
writeFile.write(newLine)
readFile.close()
writeFile.close()
# Now fix the _rst_controller.vhd file
sub_keys = sub_array.keys()
os.chdir("..")
oldList = [ f for f in listdir("./") if isfile(join("./",f)) ]
newList = []
for f in oldList:
if isdir(f):
dummy = "me"
print "Removing: " + f
elif f.endswith("rst_controller.vhd"):
newList.append(f)
elif f.endswith("rst_controller_001.vhd"):
newList.append(f)
for f in newList:
readFileName = f + ".safe"
writeFileName = f
for key in sub_keys:
writeFileName = writeFileName.replace(key, sub_array[key])
print writeFileName
if os.path.isfile(readFileName):
os.remove(readFileName)
print '''Renaming "''' + f + '''" as "''' + readFileName
os.rename(f, readFileName)
#print "readFileName is:"+readFileName
#print "writeFileName is:"+writeFileName
readFile = open(readFileName, "r")
writeFile = open(writeFileName, "w")
for line in readFile:
newLine = line
for key in sub_keys:
newLine = newLine.replace(key, sub_array[key])
if ("address " in newLine) and (": in " in newLine) and (" std_logic " in newLine):
newLine = newLine.replace("std_logic", "std_logic_vector(0 downto 0)")
newLine = newLine.replace("'X'", "(others => 'X')")
if ("address " in newLine) and (": IN " in newLine) and (" STD_LOGIC;" in newLine):
newLine = newLine.replace("STD_LOGIC", "STD_LOGIC_VECTOR(0 DOWNTO 0)")
newLine = newLine.replace("'X'", "(others => 'X')")
if ("address\t" in newLine) and (":\tIN " in newLine) and (" STD_LOGIC;" in newLine):
newLine = newLine.replace("STD_LOGIC", "STD_LOGIC_VECTOR(0 DOWNTO 0)")
newLine = newLine.replace("'X'", "(others => 'X')")
if ("=>" in newLine):
newLine = newLine.replace("_address(0)", "_address")
if ("std_logic'" in newLine) and ("av_address" in newLine):
newLine = newLine.replace("(av_address)", "(av_address(0))")
newLine = newLine.replace("NOT av_address)", "NOT av_address(0))")
if ("av_address;" in newLine):
newLine = newLine.replace("av_address;", "av_address(0);")
if (" address " in newLine) and ("<=" in newLine) and not ("DOWNTO" in newLine):
newLine = newLine.replace(" address ", " address(0) ")
if (" address;" in newLine):
newLine = newLine.replace(" address;", " address(0);")
writeFile.write(newLine)
readFile.close()
writeFile.close()
os.chdir("mentor")
def rename_bridges(longName):
print longName
os.chdir("..")
oldList = [ f for f in listdir("./") if isfile(join("./",f)) ]
newList = []
for f in oldList:
if f.endswith("safe.safe"):
os.remove(f)
elif ("_bridge_" in f):
newList.append(f)
elif ("_translator" in f):
newList.append(f)
print newList
for f in newList:
readFileName = f + ".safe"
writeFileName = f
writeFileName = writeFileName.replace(longName, "shrt")
print writeFileName
if os.path.isfile(readFileName):
os.remove(readFileName)
print '''Renaming "''' + f + '''" as "''' + readFileName
os.rename(f, readFileName)
readFile = open(readFileName, "r")
writeFile = open(writeFileName, "w")
for line in readFile:
newLine = line
newLine = newLine.replace(longName, "shrt")
writeFile.write(newLine)
readFile.close()
writeFile.close()
os.chdir("mentor")
def rename_other_entities(longName, sub_array):
sub_keys = sub_array.keys()
os.chdir("../submodules")
oldList = [ f for f in listdir("./") if isfile(join("./",f)) ]
#oldList = ["lvds_slave_system_mm_interconnect_1_spi_0_spi_control_port_translator_avalon_universal_slave_0_agent_rsp_fifo.vho"]
#oldList = listdir(".")
#print oldList
newList = []
for f in oldList:
if isdir(f):
dummy = "me"
print "Removing: " + f
elif f.endswith("safe"):
if f.endswith("safe.safe"):
#print "Deleting: " + f
os.remove(f)
else:
dummy = "me"
#print "Not deleting: " + f
print "Removing: " + f
else:
#print "Not removing: " + f
newList.append(f)
print newList
for f in newList:
readFileName = f + ".safe"
writeFileName = f
for key in sub_keys:
writeFileName = writeFileName.replace(key, sub_array[key])
print writeFileName
if os.path.isfile(readFileName):
os.remove(readFileName)
print '''Renaming "''' + f + '''" as "''' + readFileName
os.rename(f, readFileName)
readFile = open(readFileName, "r")
writeFile = open(writeFileName, "w")
for line in readFile:
newLine = line
for key in sub_keys:
newLine = newLine.replace(key, sub_array[key])
if ("address " in newLine) and (": in " in newLine) and (" std_logic " in newLine):
newLine = newLine.replace("std_logic", "std_logic_vector(0 downto 0)")
newLine = newLine.replace("'X'", "(others => 'X')")
if ("address " in newLine) and (": IN " in newLine) and (" STD_LOGIC;" in newLine):
newLine = newLine.replace("STD_LOGIC", "STD_LOGIC_VECTOR(0 DOWNTO 0)")
newLine = newLine.replace("'X'", "(others => 'X')")
if ("address\t" in newLine) and (":\tIN " in newLine) and (" STD_LOGIC;" in newLine):
newLine = newLine.replace("STD_LOGIC", "STD_LOGIC_VECTOR(0 DOWNTO 0)")
newLine = newLine.replace("'X'", "(others => 'X')")
if ("=>" in newLine) and ("vhd" in readFileName):
newLine = newLine.replace("_address(0)", "_address")
if ("std_logic'" in newLine) and ("av_address" in newLine) and ("vhd" in readFileName):
newLine = newLine.replace("(av_address)", "(av_address(0))")
newLine = newLine.replace("NOT av_address)", "NOT av_address(0))")
if ("av_address;" in newLine) and ("vhd" in readFileName):
newLine = newLine.replace("av_address;", "av_address(0);")
if (" address " in newLine) and ("<=" in newLine) and not ("DOWNTO" in newLine) and ("vhd" in readFileName):
newLine = newLine.replace(" address ", " address(0) ")
if (" address;" in newLine) and ("vhd" in readFileName):
newLine = newLine.replace(" address;", " address(0);")
writeFile.write(newLine)
readFile.close()
writeFile.close()
def compile_test(longName):
origDir = os.getcwd()
compDir = longName.join(['../build/', '/simulation/mentor'])
os.chdir(compDir)
pcName = os.environ['USERDOMAIN']
if 'MULL' in pcName:
if ("supervisor" in longName):
subprocess.call(["C:\\modeltech_pe_10.1a\\win32pe\\vsim",
"-do", "../../../../../generic_ip/common/sim/supervisor_comp.do",
"-c", "-l", "compile.log"])
elif ("top" in longName):
subprocess.call(["C:\\modeltech_pe_10.1a\\win32pe\\vsim",
"-do", "../../../../../generic_ip/common/sim/top_comp.do",
"-c", "-l", "compile.log"])
else:
subprocess.call(["C:\\modeltech_pe_10.1a\\win32pe\\vsim",
"-do", "../../../../../generic_ip/common/sim/comp.do",
"-c", "-l", "compile.log"])
else:
vsimloc = os.environ['QUARTUS_ROOTDIR']+"\\..\\modelsim_ase\\win32aloem\\vsim"
print "about to call complie using vsim location of: {}".format(vsimloc)
subprocess.call([vsimloc,
"-do", "../../../../../generic_ip/common/sim/comp.do",
"-c", "-l", "compile.log"])
os.chdir(origDir)
def copy_artifacts(moduleName, testName):
# create directory in WORKSPACE called sim_results
tmpList = os.getcwd().split("\\firmware")
tgtDir = os.path.join(tmpList[0], "sim_results")
if not os.path.exists(tgtDir):
print "making directory at {}".format(tgtDir)
os.makedirs(tgtDir)
# create directory in there called moduleName_testName
newDirName = "_".join([moduleName,testName])
tgtDir = os.path.join(tgtDir,newDirName)
if not os.path.exists(tgtDir):
os.makedirs(tgtDir)
print "making directory at {}".format(tgtDir)
else:
for f in os.listdir(tgtDir):
fullPathF = os.path.join(tgtDir,f)
print "removing {}".format(fullPathF)
os.remove(fullPathF)
# from current location copy *.txt, *.log, *.tcl, *.vstf into the directory
localDir = os.getcwd()
print "copying relevant files from {} to {}".format(localDir,tgtDir)
extList = [".txt",".log",".tcl",".vstf"]
for f in os.listdir(localDir):
for ext in extList:
if f.endswith(ext):
fullPathF = os.path.join(localDir,f)
print "copying {}".format(fullPathF)
shutil.copy(fullPathF,tgtDir)
def run_program(moduleName, testArray):
paramNameArray = testArray.keys()
paramNameArray.remove('testName') # this is now an array of the names of the generics to be set
numParams = len(paramNameArray)
testNameArray = testArray['testName']
numTests = len(testNameArray)
print "run_program starting"
print "numParams: {} ".format(numParams)
print "testNameArray[0] {}".format(testNameArray[0])
print "numTests {}".format(numTests)
tmpStr = ""
for i in sys.argv:
tmpStr = "{},{}".format(tmpStr,i)
print "Argv items are {}".format(tmpStr)
namedTestPerformed = False
print "I running program-------------------------------------------------------"
origDir = os.getcwd()
simDir = moduleName.join(['../build/', '_system/simulation/mentor'])
os.chdir(simDir)
pcName = os.environ['USERDOMAIN']
for testName in testNameArray:
tmpStr = ""
for paramName in paramNameArray:
paramArray = testArray[paramName]
#print paramArray
#print paramArray[1]
paramValue = paramArray[testNameArray.index(testName)]
paramStr = "".join(["-G", paramName, "=", paramValue])
scParamStr = "".join(["-sc_arg \"", paramName, "=", paramValue, "\""])
if ("top" in moduleName) or ("supervisor" in moduleName):
tmpStr = " ".join([tmpStr, scParamStr])
else:
tmpStr = " ".join([tmpStr, paramStr])
print "set of parameters going to args.txt for test:{} is:{}".format(testName,tmpStr)
create_args_file(tmpStr)
logStr = "".join([testName, "_run.log"])
tbName = "".join([moduleName, "_system_tb"])
batchMode = get_batch_mode()
if 'MULL' in pcName:
if ("top" in moduleName) or ("supervisor" in moduleName):
print "Samba"
if batchMode==1:
callStr = " ".join(["C:/modeltech_pe_10.1a/win32pe/vsim", "-c",
"-do", "../../../../../generic_ip/common/sim/sc_run_batch.do", "-l", logStr])
else:
callStr = " ".join(["C:/modeltech_pe_10.1a/win32pe/vsim",
"-do", "../../../../../generic_ip/common/sim/sc_run.do", "-l", logStr])
else:
print "Not Samba"
if batchMode==1:
callStr = " ".join(["C:/modeltech_pe_10.1a/win32pe/vsim", "-c",
"-do", "../../../../../generic_ip/common/sim/run_batch.do", "-l", logStr])
else:
callStr = " ".join(["C:/modeltech_pe_10.1a/win32pe/vsim",
"-do", "../../../../../generic_ip/common/sim/run.do", "-l", logStr])
else:
if batchMode==1:
callStr = " ".join([os.environ['QUARTUS_ROOTDIR']+"\\..\\modelsim_ase\\win32aloem\\vsim", "-c",
"-do", "../../../../../generic_ip/common/sim/run_batch.do", "-l", logStr])
else:
callStr = " ".join([os.environ['QUARTUS_ROOTDIR']+"\\..\\modelsim_ase\\win32aloem\\vsim",
"-do", "../../../../../generic_ip/common/sim/run.do", "-l", logStr])
if ((sys.argv[-1]==testName) or (sys.argv[-1]=='all')):
print "current directory is {}".format(os.getcwd())
print "call String will be: {}".format(callStr)
subprocess.call(callStr, shell=True) # does the simulation
check_result(logStr)
namedTestPerformed = True
copy_artifacts(moduleName, testName)
if namedTestPerformed:
print "All requested tests performed per '{}'".format(sys.argv[-1])
else:
print "Oops!\n"
print "Test name '{}' was not found in array".format(sys.argv[-1])
os.chdir(origDir)
def create_args_file(argsString):
argsFileName = "args.txt"
argsFile = open(argsFileName, "w")
argsFile.write(argsString)
argsFile.close()
def check_result(logfile):
searchfile = open(logfile, "r")
for line in searchfile:
if "SUCCESS" in line:
print 'Test appears to have been successful, which is nice...'
return None
searchfile.close()
print 'Test appears to have NOT been successful, oops...'
sys.exit(1)
def main(myModule, testArray, ipArray):
origDir = os.getcwd()
create_new_qsys()
if (get_qsys_build()==1): generate_sim_files(ipArray)
copy_files(my_module())
os.chdir("c:/simulation/mentor")
topLevel = get_top_level()
#longName = "".join([topLevel, "_mm_interconnect"])
longName = topLevel
print "The top level is " + topLevel + " and the long name to be replaced is " + longName
edit_msim_setup(longName, subst_array)
rename_top_level(topLevel, longName, subst_array)
rename_bridges(longName)
rename_other_entities(longName, subst_array)
os.chdir(origDir)
return_files(my_module())
compile_test(longName)
run_program(myModule, testArray)

View file

@ -0,0 +1,78 @@
import sys
import os
from os import listdir
from os.path import isfile, join, isdir
# Defines which header file types we are trying to generate and support
class HeaderType:
CPP, VHDL = range(2)
# Maintains the 'Register Model' including name and address
class RegClass:
def __init__(self, vhdlLine):
lineList = vhdlLine.split()
self.regName = lineList[1]
addrList = lineList[-1].split("\"")
self.regAddr = addrList[1]
def getC(self):
myStr = "".join(["const int ", self.regName,
" = 0x", self.regAddr,";"])
print myStr
def getVhdl(self):
myStr = "".join(["constant ", self.regName,
" std_logic_vector(7 downto 0) := x\"",
self.regAddr,"\";"])
print myStr
def getRegs(self, header):
if header == HeaderType.CPP:
self.getC()
if header == HeaderType.VHDL:
self.getVhdl()
# Represents the 'IP Block' and contains instances of 'RegClass'
class IpClass:
def __init__(self, ip_name):
tmpPath = os.getcwd()
self.myPath = "".join([tmpPath, "/../../", ip_name, "/src"])
print self.myPath
self.file_list = [ f for f in os.listdir(self.myPath) if f.endswith(".vhd") ]
os.chdir(self.myPath)
readFileName = self.file_list[0]
readFile = open(readFileName, "r")
self.MyRegs = []
for line in readFile:
if (("constant" in line) and ("_ADDR" in line)):
self.MyRegs.append(RegClass(line))
def list_files(self):
print self.file_list
def getRegs(self, header):
for reg in self.MyRegs:
reg.getRegs(header)
# Represents the 'IP Library' and contains instances of 'IpClass'
class LibraryClass:
def __init__(self):
self.ip_list = [ f for f in os.listdir("../..") if f.find("generic")==0 ]
self.myIp = []
for ip in self.ip_list:
#print ip
self.myIp.append(IpClass(ip))
def getRegs(self, header):
print self.ip_list
for inst in self.myIp:
inst.getRegs(header)
# inst.list_files()
def main():
myLibrary = LibraryClass()
myLibrary.getRegs(HeaderType.VHDL)
main()

View file

@ -0,0 +1,56 @@
# Use vmap to copy modelsim.ini this directory so msim_setup.tcl doesn't
# override installation file.
vmap -c
# Load the Altera generated macros
do msim_setup.tcl
# Compile the technology specific libraries
dev_com
# Compile the constrained random related packages
vlib OSVVM
vcom -2008 -work OSVVM \
../../../../../generic_ip/common/src/test/OSVVM/RandomBasePkg.vhd \
../../../../../generic_ip/common/src/test/OSVVM/SortListPkg_int.vhd \
../../../../../generic_ip/common/src/test/OSVVM/RandomPkg.vhd \
../../../../../generic_ip/common/src/test/OSVVM/NamePkg.vhd \
../../../../../generic_ip/common/src/test/OSVVM/MessagePkg.vhd \
../../../../../generic_ip/common/src/test/OSVVM/CoveragePkg.vhd
#../../../../../generic_ip/common/src/test/OSVVM/OsvvmGlobalPkg.vhd \
#../../../../../generic_ip/common/src/test/OSVVM/OsvvmContext.vhd \
#../../../../../generic_ip/common/src/test/OSVVM/AlertLogPkg.vhd \
#../../../../../generic_ip/common/src/test/OSVVM/AlertLogPkg_body_BVUL.vhd \
# Compile the design files
com
vcom -2008 -work work ../../../../../generic_ip/common/src/test/txt_util.vhd
# Compile the VHDL packages that support bus protocols, memory mapped registers and functional procedures
vcom -2008 -work work ../../../../../generic_ip/common/src/test/avalon_verify_pkg.vhd
vcom -2008 -work work ../../../../../print_ctrl/src/test/pkg_types.vhd
vcom -2008 -work work ../../../../../top/src/test/hib_verify_pkg.vhd
vcom -2008 -work work ../../../../../top/src/test/func_verify_pkg.vhd
vcom -2008 -work work ../../../../../top/src/test/coverage_verify_pkg.vhd
vcom -2008 -work work ../../../../../soc_system/ip/hib_logic/src/pkg_functions.vhd
vcom -2008 -work work ../../../../../print_ctrl/src/test/asic_model.vhd
vcom -2008 -work work ../../../../../print_ctrl/src/test/actuator_die_model.vhd
vcom -2008 -work work ../../../../../print_ctrl/src/test/head_model.vhd
vcom -2008 -work work ../../../../../print_ctrl/src/test/memory_model2.vhd
# Compile the various printhead and circuit models
#vcom -work work ../../../../../lvds_slave/src/test/pmb_model.vhd
#vcom -work work ../../../../../print_data/src/test/data_model.vhd
#vcom -work work ../../../../../waveform_control/src/test/pzt_model.vhd
#vcom -work work ../../../../../waveform_control/src/test/waveform_circuit.vhd
#vcom -work work ../../../../../printhead/src/test/side_model.vhd
#vcom -work work ../../../../../printhead/src/test/head_model.vhd
# Compile the various block and sub-system VHDL testbenches
vcom -2008 -work work ../../../../../timing_ctrl/src/test/timing_ctrl_system_tb.vhd
vcom -2008 -work work ../../../../../image_expand/src/test/image_expand_system_tb.vhd
vcom -2008 -work work ../../../../../stripe_transform/src/test/stripe_transform_system_tb.vhd
vcom -2008 -work work ../../../../../print_ctrl/src/test/print_ctrl_system_tb.vhd
# Exit Modelsim once this is complete
quit -f

View file

@ -0,0 +1,5 @@
do msim_setup.tcl
elab_tb
when -label passed_end_of_simulation {passed == true} {echo "SUCCESS , Passed end of simulation"; stop ;}
when -label failed_end_of_simulation {failed == true} {echo "Failed end of simulation"; stop ;}
run -all

View file

@ -0,0 +1,5 @@
do msim_setup.tcl
elab_tb
when -label passed_end_of_simulation {passed == true} {echo "SUCCESS , Passed end of simulation"; quit -f -code 0 ;}
when -label failed_end_of_simulation {failed == true} {echo "Failed end of simulation"; quit -f -code 1 ;}
run -all

View file

@ -0,0 +1,5 @@
do msim_setup.tcl
elab_tb
#when -label passed_end_of_simulation {passed == true} {echo "Passed end of simulation"; quit -f -code 0 ;}
#when -label failed_end_of_simulation {failed == true} {echo "Failed end of simulation"; quit -f -code 1 ;}
#run -all

View file

@ -0,0 +1,5 @@
do msim_setup.tcl
elab_tb
#when -label passed_end_of_simulation {passed == true} {echo "Passed end of simulation"; quit -f -code 0 ;}
#when -label failed_end_of_simulation {failed == true} {echo "Failed end of simulation"; quit -f -code 1 ;}
run -all

View file

@ -0,0 +1,40 @@
# Load the Altera generated macros
do msim_setup.tcl
# Compile the technology specific libraries
dev_com
# Compile the constrained random related packages
vlib OSVVM
vcom -work OSVVM \
../../../../../../../../../Common/src/test/OSVVM/RandomBasePkg.vhd \
../../../../../../../../../Common/src/test/OSVVM/SortListPkg_int.vhd \
../../../../../../../../../Common/src/test/OSVVM/RandomPkg.vhd \
../../../../../../../../../Common/src/test/OSVVM/NamePkg.vhd \
../../../../../../../../../Common/src/test/OSVVM/MessagePkg.vhd \
../../../../../../../../../Common/src/test/OSVVM/CoveragePkg.vhd
# Compile the design files
com
# Compile the VHDL packages that support bus protocols, memory mapped registers and functional procedures
vcom -work work ../../../../../common/src/test/avalon_verify_pkg.vhd
vcom -work work ../../../../../common/src/test/hib_verify_pkg.vhd
vcom -work work ../../../../../common/src/test/func_verify_pkg.vhd
vcom -work work ../../../../../common/src/test/coverage_verify_pkg.vhd
# Compile the various printhead and circuit models
vcom -work work ../../../../../lvds_slave/src/test/pmb_model.vhd
vcom -work work ../../../../../print_data/src/test/data_model.vhd
vcom -work work ../../../../../waveform_control/src/test/pzt_model.vhd
vcom -work work ../../../../../waveform_control/src/test/waveform_circuit.vhd
vcom -work work ../../../../../printhead/src/test/side_model.vhd
vcom -work work ../../../../../printhead/src/test/head_model.vhd
# compile and link C source files
scgenmod supervisor_system > ../../../../../supervisor/src/test/supervisor_system.h
sccom -scv -g ../../../../../supervisor/src/test/supervisor_system_tb.cpp
sccom -scv -link
# Exit Modelsim once this is complete
quit -f

View file

@ -0,0 +1,47 @@
# Load the Altera generated macros
do msim_setup.tcl
# Compile the technology specific libraries
dev_com
# Compile the constrained random related packages
vlib OSVVM
vcom -work OSVVM \
../../../../../../../../../Common/src/test/OSVVM/RandomBasePkg.vhd \
../../../../../../../../../Common/src/test/OSVVM/SortListPkg_int.vhd \
../../../../../../../../../Common/src/test/OSVVM/RandomPkg.vhd \
../../../../../../../../../Common/src/test/OSVVM/NamePkg.vhd \
../../../../../../../../../Common/src/test/OSVVM/MessagePkg.vhd \
../../../../../../../../../Common/src/test/OSVVM/CoveragePkg.vhd
# Compile the design files
com
# Compile the VHDL packages that support bus protocols, memory mapped registers and functional procedures
vcom -work work ../../../../../common/src/test/avalon_verify_pkg.vhd
vcom -work work ../../../../../common/src/test/hib_verify_pkg.vhd
vcom -work work ../../../../../common/src/test/func_verify_pkg.vhd
vcom -work work ../../../../../common/src/test/coverage_verify_pkg.vhd
# Compile the various printhead and circuit models
vcom -work work ../../../../../lvds_slave/src/test/pmb_model.vhd
vcom -work work ../../../../../print_data/src/test/data_model.vhd
vcom -work work ../../../../../waveform_control/src/test/pzt_model.vhd
vcom -work work ../../../../../waveform_control/src/test/waveform_circuit.vhd
vcom -work work ../../../../../printhead/src/test/side_model.vhd
vcom -work work ../../../../../printhead/src/test/head_model.vhd
vcom -work work ../../../../../top/src/hib_fd_1200.vhd
# compile and link C source files
scgenmod top_system > ../../../../../top/src/test/top_system.h
scgenmod hib_fd_1200 > ../../../../../top/src/test/hib_fd_1200.h
sccom -g ../../../../../top/src/test/PrintheadMessage.cpp
sccom -g ../../../../../top/src/test/PrintheadMessageReceive.cpp
sccom -g ../../../../../top/src/test/PrintheadMessageSend.cpp
#sccom -g ../../../../../top/src/test/PrintheadExtenderBase.cpp
#sccom -g ../../../../../top/src/test/PrintheadEx.cpp
sccom -scv -g ../../../../../top/src/test/top_system_tb.cpp
sccom -scv -link
# Exit Modelsim once this is complete
quit -f

View file

@ -0,0 +1,40 @@
-------------------------------------------------------------------------------
-- Title : common_pkg
-- Project : Generic Components
-------------------------------------------------------------------------------
-- File : common_pkg.vhd
-- Author : GMG
-- Company : Global Inkjet Systems
-- Created : 2018-04-24
-- Last update: 2018-04-24
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Common Package
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package common_pkg is
-- compute ceil(log2(num)). E.g.: log2(255) = 8, log2(256) = 8, log2(257) = 9.
function log2(num : natural) return natural;
end common_pkg;
package body common_pkg is
-- compute ceil(log2(num)). E.g.: log2(255) = 8, log2(256) = 8, log2(257) = 9.
function log2(num : natural) return natural is
variable val : natural := 0;
begin
while 2**val < num loop
val := val+1;
end loop;
return val;
end function log2;
end package body common_pkg;

View file

@ -0,0 +1,149 @@
-------------------------------------------------------------------------------
-- Title : Markov Edges
-- Project :
-------------------------------------------------------------------------------
-- File : markov_edges.vhd
-- Author : <Damian@JERSEY>
-- Company : Global Inkjet Systems
-- Created : 2008-05-01
-- Last update: 2010-02-03
-- SVN ID : $Id: markov_edges.vhd 3267 2010-02-03 20:00:20Z damiansmith $
-- Standard : VHDL'93
-------------------------------------------------------------------------------
-- Description: Uses a Markov chain to detect rising and falling edges of a
-- signal. Generic allows configuration of length.
--
-- Counts up for '1' and down for '0' (saturating at 0 and chain_len)
-- when reaches limit, an edge has been detected and the value is held as the
-- filtered signal until the other limit is reached.
--
-- Note that this reduces the maximum encoder rate to RATE_clk / chain_len
-- assuming no noise and a 50% Mark Space ratio
--
-------------------------------------------------------------------------------
-- Copyright (c) 2008 Global Inkjet Systems
-------------------------------------------------------------------------------
-- Revisions :
-- Date Version Author Description
-- 2008-05-01 1.0 Damian Created
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.pkg_functions.all;
-------------------------------------------------------------------------------
entity markov_edges is
generic (
MAX_CHAIN_LEN : positive range 2 to 256 := 32;
DEFAULT_CHAIN_LEN : positive range 2 to 32 := 16
);
port (
clk : in std_logic;
arst_n : in std_logic := '1';
srst_n : in std_logic := '1';
ena : in std_logic := '1';
load_chain_len : in std_logic;
chain_len : in std_logic_vector(log2(MAX_CHAIN_LEN)-1 downto 0);
raw_signal : in std_logic;
filtered_signal : out std_logic;
edge_rising : out std_logic; -- strobe
edge_falling : out std_logic -- strobe
);
end entity markov_edges;
-------------------------------------------------------------------------------
architecture rtl of markov_edges is
signal filtered_signal_int : std_logic;
begin
markov : process (clk, arst_n) is
variable chain : unsigned(log2(MAX_CHAIN_LEN - 1)-1 downto 0);
variable raw_signal_d : std_logic_vector(1 downto 0);
variable chain_len_d : unsigned(chain_len'range);
begin -- process markov
if arst_n = '0' then
filtered_signal_int <= '0';
edge_falling <= '0';
edge_rising <= '0';
chain := (others => '0');
raw_signal_d := (others => '0');
chain_len_d := to_unsigned(DEFAULT_CHAIN_LEN,chain_len_d'length);
elsif rising_edge(clk) then
if srst_n = '0' then
filtered_signal_int <= '0';
edge_falling <= '0';
edge_rising <= '0';
chain := (others => '0');
raw_signal_d := (others => '0');
chain_len_d := to_unsigned(DEFAULT_CHAIN_LEN,chain_len_d'length);
elsif ena = '1' then
edge_rising <= '0';
edge_falling <= '0';
-----------------------------------------------------------------------
-- Detect Edges and Filter Output
-----------------------------------------------------------------------
if chain = chain_len_d and filtered_signal_int = '0' then
-- markov chain has reached '1'
edge_rising <= '1';
filtered_signal_int <= '1';
elsif chain = 0 and filtered_signal_int = '1' then
-- markov chain has reached '0'
edge_falling <= '1';
filtered_signal_int <= '0';
else
-- maintain filtered value
filtered_signal_int <= filtered_signal_int;
end if;
-----------------------------------------------------------------------
-- Move Markov Chain if necessary
-----------------------------------------------------------------------
if raw_signal_d(raw_signal_d'high) = '1' and chain /= chain_len_d then
chain := chain + 1;
elsif raw_signal_d(raw_signal_d'high) = '0' and chain /= 0 then
chain := chain - 1;
end if;
-----------------------------------------------------------------------
-- sr for metastability
-----------------------------------------------------------------------
raw_signal_d := raw_signal_d(raw_signal_d'high - 1 downto 0) & raw_signal;
-----------------------------------------------------------------------
-- Load new Chain Length - reset output values
-----------------------------------------------------------------------
if load_chain_len = '1' then
chain_len_d := unsigned(chain_len);
chain := (others => '0');
filtered_signal_int <= '0';
edge_falling <= '0';
edge_rising <= '0';
if unsigned(chain_len) < 1 then
chain_len_d := to_unsigned(1,chain_len_d'length);
elsif unsigned(chain_len) > MAX_CHAIN_LEN then
chain_len_d := to_unsigned(MAX_CHAIN_LEN, chain_len_d'length);
end if;
end if;
end if;
end if;
end process markov;
filtered_signal <= filtered_signal_int;
end architecture rtl;
-------------------------------------------------------------------------------

View file

@ -0,0 +1,370 @@
-------------------------------------------------------------------------------
-- Title : Package Functions
-- Project : Common
-------------------------------------------------------------------------------
-- File : pkg_functions.vhd
-- Author : <Damian@LANGERHANS>
-- Company : Global Inkjet Systems
-- Created : 2010-11-17
-- Last update: 2015-05-22
-- SVN ID : $Id$
-- Standard : VHDL'87
-------------------------------------------------------------------------------
-- Description: Various useful functions
-------------------------------------------------------------------------------
-- Copyright (c) 2010 Global Inkjet Systems
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_textio.all;
use std.textio.all;
package PKG_FUNCTIONS is
type fifo_80b_vector is array (natural range <>) of std_logic_vector(79 downto 0);
type fifo_64b_vector is array (natural range <>) of std_logic_vector(63 downto 0);
type fifo_32b_vector is array (natural range <>) of std_logic_vector(31 downto 0);
type fifo_20b_vector is array (natural range <>) of std_logic_vector(19 downto 0);
type fifo_18b_vector is array (natural range <>) of std_logic_vector(17 downto 0);
type fifo_19b_vector is array (natural range <>) of std_logic_vector(18 downto 0);
type dc_dout_t is array (16 downto 1) of std_logic_vector(15 downto 0);
type dout_t is array (16 downto 0) of std_logic_vector(15 downto 0);
type fifo_16b_vector is array (natural range <>) of std_logic_vector(15 downto 0);
type fifo_13b_vector is array (natural range <>) of std_logic_vector(12 downto 0);
type fifo_12b_vector is array (natural range <>) of std_logic_vector(11 downto 0);
type fifo_10b_vector is array (natural range <>) of std_logic_vector(9 downto 0);
type fifo_9b_vector is array (natural range <>) of std_logic_vector(8 downto 0);
type fifo_8b_vector is array (natural range <>) of std_logic_vector(7 downto 0);
type fifo_5b_vector is array (natural range <>) of std_logic_vector(4 downto 0);
type fifo_4b_vector is array (natural range <>) of std_logic_vector(3 downto 0);
type fifo_3b_vector is array (natural range <>) of std_logic_vector(2 downto 0);
type fifo_2b_vector is array (natural range <>) of std_logic_vector(1 downto 0);
-- TYPE fifo_3b_unsigned_vector IS ARRAY ( NATURAL RANGE <>) OF unsigned(2 downto 0);
-- Get the log to base 2 of an integer
function LOG2(N : integer) return integer;
function UNSIGNEDHIGH (N : natural) return integer;
function IS_POWER_OF_2 (N : integer) return boolean;
function WORDS(N : integer; M : integer) return integer;
function OR_BUS(DATA : std_logic_vector) return std_logic;
function CLIP (N : natural; MAX : natural) return natural;
function MAX_VAL (N : unsigned) return boolean;
function MAX_VAL (N : signed) return boolean;
function MAX_VAL (N : std_logic_vector) return boolean;
function STD2UINT (
n : std_logic_vector)
return natural;
function STD2INT (
n : std_logic_vector)
return integer;
-- useful for moving tristate signals up to a top level
type tristate_port_t is record
O : std_logic; -- output
I : std_logic; -- input
EN : std_logic; -- tristate enable - active high for 'Z'
end record;
function sel(Cond : boolean; If_True, If_False : integer) return integer;
-- pragma translate_off
-- Assemble a GBUS PKT
function GBUS_PKT (
ID : std_logic_vector(7 downto 0);
WLEN : natural;
RLEN : natural;
ADDR : natural;
WDATA : std_logic_vector := x"00")
return std_logic_vector;
function FIFO_WRAP (
CHAN : integer range 0 to 8;
PAYLOAD : std_logic_vector)
return std_logic_vector;
impure function print(
mytext : string;
emph : boolean := false;
display : boolean := true)
return boolean;
-- pragma translate_on
end PKG_FUNCTIONS;
package body PKG_FUNCTIONS is
-----------------------------------------------------------------------------
-- Get the log to base 2 of an integer
function LOG2(N : integer) return integer is
begin
if N = 1 then
return 1;
elsif N <= 0 then
--pragma translate_off
report "Invalid input for LOG function" severity error;
--pragma translate_on
return 0;
else
return 1 + LOG2(N/2);
end if;
end function LOG2;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-- purpose: Given a value N, this function returns the value for the HIGH end of an unsigned vector large enough to hold the value N
function UNSIGNEDHIGH (
N : natural)
return integer is
begin -- UNSIGNEDHIGH
if N <= 1 then
return 0;
else
return LOG2(N)-1;
end if;
end UNSIGNEDHIGH;
function IS_POWER_OF_2(N : integer) return boolean is
begin
if 2**(log2(N)-1) = N then
return true;
else
return false;
end if;
end function IS_POWER_OF_2;
-----------------------------------------------------------------------------
-- Return number of words of length M in N bits of data
function WORDS(N : integer; M : integer) return integer is
begin
if M = 0 then
--pragma translate_off
report "Invalid input for WORDS function" severity error;
--pragma translate_on
return 0;
elsif N = 0 then
return 0;
elsif N < M then
return 1;
else
return 1 + WORDS(N - M, M);
end if;
end function WORDS;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-- Logical or of all bits in a bus
function OR_BUS(DATA : std_logic_vector) return std_logic is
variable OR_ARRAY : std_logic_vector(2*DATA'length-2 downto 0);
begin
--Produces a tree of OR gates.
OR_ARRAY(DATA'length-1 downto 0) := DATA;
for n in 0 to DATA'length-2 loop
OR_ARRAY(DATA'length+n) := OR_ARRAY(2*n) or OR_ARRAY(2*n+1);
end loop; -- XOR_COUNT
return OR_ARRAY(OR_ARRAY'high);
end function OR_BUS;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
function CLIP (N : natural; MAX : natural) return natural is
begin
if N <= MAX then
return N;
else
return MAX;
end if;
end function CLIP;
function MAX_VAL (N : unsigned) return boolean is
begin
if (not(N)) = 0 then
return true;
end if;
return false;
end function MAX_VAL;
function MAX_VAL (N : signed) return boolean is
begin -- MAX_VAL
return max_val(unsigned(N));
end MAX_VAL;
function MAX_VAL (N : std_logic_vector) return boolean is
begin -- MAX_VAL
return max_val(unsigned(N));
end MAX_VAL;
function STD2UINT (n : std_logic_vector) return natural is
begin
return to_integer(unsigned(n));
end function STD2UINT;
function STD2INT (n : std_logic_vector) return integer is
begin
return to_integer(signed(n));
end function STD2INT;
----------------------------------------------------------------
-- Functions to select one or the other based on a boolean (or
-- std_ulogic or std_logic) input.
-- Analogous to the C statement x = Cond ? a : b
----------------------------------------------------------------
-- constant k: integer := sel(BOOLEAN_GENERIC, 5, 8);
-- or ...
-- constant k: integer := sel(Cond => BOOLEAN_GENERIC, If_True => 5, If_False => 8);
function sel(Cond : boolean; If_True, If_False : integer) return integer is
begin
if (Cond = true) then
return(If_True);
else
return(If_False);
end if;
end function sel;
-----------------------------------------------------------------------------
-- pragma translate_off
-----------------------------------------------------------------------------
function GBUS_PKT (
ID : std_logic_vector(7 downto 0);
WLEN : natural;
RLEN : natural;
ADDR : natural;
WDATA : std_logic_vector := x"00")
return std_logic_vector is
function ONE_IF_GT (
N : natural;
MAX : natural) return natural is
begin
if N > MAX then
return 1;
else
return 0;
end if;
end function ONE_IF_GT;
-- Byte 0 Entity ID (ignore locally) \
-- Byte 1(7) read#/write | stripped out and passed
-- Byte 1(6) single word reply | as individual control lines
-- Byte 1(5) no further data | to the entity of this block
-- Byte 1(4:0) Command Address /
-- Byte 2,3 Write Length (/words) (unless no further data)
-- Byte 4,5 Reply Length (/words) (unless write, or single word reply)
-- Next Bytes - Write Length words of data unless no further data
constant return_len : natural := 16*(1 + ONE_IF_GT(WLEN, 0) + ONE_IF_GT(RLEN, 1) + WLEN);
variable return_vec : std_logic_vector(return_len - 1 downto 0);
begin
if WLEN > 0 then
if RLEN > 1 then
-- long data, long reply
return_vec := ID&'0'&'0'&'0'&std_logic_vector(to_unsigned(ADDR, 5))&
std_logic_vector(to_unsigned(WLEN, 16)) &
std_logic_vector(to_unsigned(RLEN, 16)) &
WDATA;
elsif RLEN = 1 then
-- long data, short reply
return_vec := ID&'0'&'1'&'0'&std_logic_vector(to_unsigned(ADDR, 5))&
std_logic_vector(to_unsigned(WLEN, 16)) &
WDATA;
else
-- long data, no reply
return_vec := ID&'1'&'0'&'0'&std_logic_vector(to_unsigned(ADDR, 5))&
std_logic_vector(to_unsigned(WLEN, 16)) &
WDATA;
end if;
else
if RLEN > 1 then
-- no data, long reply
return_vec := ID&'0'&'0'&'1'&std_logic_vector(to_unsigned(ADDR, 5))&
std_logic_vector(to_unsigned(RLEN, 16));
elsif RLEN = 1 then
-- no data, short reply
return_vec := ID&'0'&'1'&'1'&std_logic_vector(to_unsigned(ADDR, 5));
else
-- no data, no reply
return_vec := ID&'1'&'0'&'1'&std_logic_vector(to_unsigned(ADDR, 5));
end if;
end if;
return return_vec;
end function GBUS_PKT;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
function FIFO_WRAP (
chan : integer range 0 to 8;
payload : std_logic_vector)
return std_logic_vector is
variable return_vec : std_logic_vector(WORDS(payload'length, 16)*16 + 31 downto 0);
begin
return_vec := (others => '0');
return_vec(return_vec'high downto return_vec'high - 31 - payload'length) := x"11" & std_logic_vector(to_unsigned(WORDS(payload'length, 16), 16)) & payload;
return return_vec;
end function FIFO_WRAP;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
impure function print(
mytext : string;
emph : boolean := false;
display : boolean := true)
return boolean is
variable my_input_line : line;
variable my_output_line : line;
begin
if display then
-- allows user to specify verbosity
if emph then
write(my_output_line, string'(" ******************************************************* "));
writeline(output, my_output_line);
end if;
write(my_output_line, NOW);
write(my_output_line, string'(" : "));
write(my_output_line, mytext);
writeline(output, my_output_line);
if emph then
write(my_output_line, string'(" ******************************************************* "));
writeline(output, my_output_line);
end if;
deallocate(my_input_line);
end if;
return true;
end function print;
-----------------------------------------------------------------------------
-- pragma translate_on
end PKG_FUNCTIONS;

View file

@ -0,0 +1,50 @@
-------------------------------------------------------------------------------
-- Title : sync_reset
-------------------------------------------------------------------------------
-- File : sync_reset.vhd
-- Author : Gianmarco Girau <ggianmarco.girau@gmail.com>
-- Company : On my own
-- Target : Generic (simulation), Generic (synthesis)
-- Dependency : none
-------------------------------------------------------------------------------
-- Description: Generate a active-low reset with async assertion and sync
-- de-assertion.
-------------------------------------------------------------------------------
-- Last update: 2015-08-16
-------------------------------------------------------------------------------
-- Revisions :
-- Date Version Author Description
-- 2010-08-06 1.0 gmg Created
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
entity sync_reset is
port(
async_rstN : in std_logic;
clk : in std_logic;
sync_rstN : out std_logic);
end sync_reset;
architecture RTL of sync_reset is
signal sync_rstN_i : std_logic;
begin
pSYNC : process(async_rstN, clk)
begin
if(async_rstN = '0') then
sync_rstN_i <= '0';
sync_rstN <= '0';
elsif(clk = '1' and clk'event) then
sync_rstN_i <= '1';
sync_rstN <= sync_rstN_i;
end if;
end process pSYNC;
end RTL;

View file

@ -0,0 +1,61 @@
-------------------------------------------------------------------------------
-- Title : sync_wire
-------------------------------------------------------------------------------
-- File : sync_wire.vhd
-- Author : Gianmarco Girau <ggianmarco.girau@gmail.com>
-- Company : On my own
-- Target : Generic (simulation), Generic (synthesis)
-- Dependency : none
-------------------------------------------------------------------------------
-- Description: synchronize a std_logic signal to a clock domain
-------------------------------------------------------------------------------
-- Last update: 2015-08-17
-------------------------------------------------------------------------------
-- Revisions :
-- Date Version Author Description
-- 2010-10-25 1.0 gmg Created
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
entity sync_wire is
generic(
rst_val : std_logic := '0';
sync_stages : positive := 2);
port(
rstN : in std_logic;
clk : in std_logic;
async_in : in std_logic;
sync_out : out std_logic);
end sync_wire;
architecture RTL of sync_wire is
signal sync_sig : std_logic_vector(sync_stages-1 downto 0);
begin
pSYNC : process(rstN, clk)
begin
if(rstN = '0') then
for n in 0 to sync_stages-1 loop
sync_sig(n) <= rst_val;
end loop; -- n
elsif(clk = '1' and clk'event) then
for n in 0 to sync_stages-1 loop
if(n = 0) then
sync_sig(0) <= async_in;
else
sync_sig(n) <= sync_sig(n-1);
end if;
end loop; -- n
end if;
end process pSYNC;
sync_out <= sync_sig(sync_stages-1);
end RTL;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,158 @@
--
-- File Name: MessagePkg.vhd
-- Design Unit Name: MessagePkg
-- Revision: STANDARD VERSION, revision 2014.01
--
-- Maintainer: Jim Lewis email: jim@synthworks.com
-- Contributor(s):
-- Jim Lewis SynthWorks
--
--
-- Package Defines
-- Data structure for multi-line name/message to be associated with a data structure.
--
-- Developed for:
-- SynthWorks Design Inc.
-- VHDL Training Classes
-- 11898 SW 128th Ave. Tigard, Or 97223
-- http://www.SynthWorks.com
--
-- Latest standard version available at:
-- http://www.SynthWorks.com/downloads
--
-- Revision History:
-- Date Version Description
-- 06/2010: 0.1 Initial revision
-- 07/2014: 2014.07 Moved specialization required by CoveragePkg to CoveragePkg
--
--
-- Copyright (c) 2010 - 2014 by SynthWorks Design Inc. All rights reserved.
--
-- Verbatim copies of this source file may be used and
-- distributed without restriction.
--
-- This source file is free software; you can redistribute it
-- and/or modify it under the terms of the ARTISTIC License
-- as published by The Perl Foundation; either version 2.0 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 Artistic License for details.
--
-- You should have received a copy of the license with this source.
-- If not download it from,
-- http://www.perlfoundation.org/artistic_license_2_0
--
library ieee ;
use ieee.std_logic_1164.all ;
use ieee.numeric_std.all ;
use ieee.math_real.all ;
use std.textio.all ;
package MessagePkg is
type MessagePType is protected
procedure Set (MessageIn : String) ;
impure function Get (ItemNumber : integer := 1) return string ;
impure function GetCount return integer ;
impure function IsSet return boolean ;
procedure Clear ; -- clear message
procedure Deallocate ; -- clear message
end protected MessagePType ;
end package MessagePkg ;
package body MessagePkg is
-- Local Data Structure Types
type LineArrayType is array (natural range <>) of line ;
type LineArrayPtrType is access LineArrayType ;
type MessagePType is protected body
variable MessageCount : integer := 0 ;
constant INITIAL_ITEM_COUNT : integer := 25 ;
variable MaxMessageCount : integer := INITIAL_ITEM_COUNT ;
variable MessagePtr : LineArrayPtrType := new LineArrayType(1 to INITIAL_ITEM_COUNT) ;
------------------------------------------------------------
procedure Set (MessageIn : String) is
------------------------------------------------------------
variable NamePtr : line ;
variable OldMaxMessageCount : integer ;
variable OldMessagePtr : LineArrayPtrType ;
begin
MessageCount := MessageCount + 1 ;
if MessageCount > MaxMessageCount then
OldMaxMessageCount := MaxMessageCount ;
MaxMessageCount := OldMaxMessageCount * 2 ;
OldMessagePtr := MessagePtr ;
MessagePtr := new LineArrayType(1 to MaxMessageCount) ;
for i in 1 to OldMaxMessageCount loop
MessagePtr(i) := OldMessagePtr(i) ;
end loop ;
Deallocate( OldMessagePtr ) ;
end if ;
MessagePtr(MessageCount) := new string'(MessageIn) ;
end procedure Set ;
------------------------------------------------------------
impure function Get (ItemNumber : integer := 1) return string is
------------------------------------------------------------
begin
if MessageCount > 0 then
if ItemNumber >= 1 and ItemNumber <= MessageCount then
return MessagePtr(ItemNumber).all ;
else
report LF & "%% MessagePkg:MessagePType.GetMessage input value out of range" severity failure ;
return "" ; -- error if this happens
end if ;
else
report LF & "%% MessagePkg:MessagePType.GetMessage message is not set" severity failure ;
return "" ; -- error if this happens
-- return NamePtr.all ;
end if ;
end function Get ;
------------------------------------------------------------
impure function GetCount return integer is
------------------------------------------------------------
begin
return MessageCount ;
end function GetCount ;
------------------------------------------------------------
impure function IsSet return boolean is
------------------------------------------------------------
begin
return MessageCount > 0 ;
end function IsSet ;
------------------------------------------------------------
procedure Deallocate is -- clear message
------------------------------------------------------------
variable CurPtr : LineArrayPtrType ;
begin
for i in 1 to MessageCount loop
deallocate( MessagePtr(i) ) ;
end loop ;
MessageCount := 0 ;
-- Do NOT Do this: deallocate( MessagePtr ) ;
end procedure Deallocate ;
------------------------------------------------------------
procedure Clear is -- clear
------------------------------------------------------------
begin
Deallocate ;
end procedure Clear ;
end protected body MessagePType ;
end package body MessagePkg ;

View file

@ -0,0 +1,109 @@
--
-- File Name: NamePkg.vhd
-- Design Unit Name: NamePkg
-- Revision: STANDARD VERSION, revision 2014.07
--
-- Maintainer: Jim Lewis email: jim@synthworks.com
-- Contributor(s):
-- Jim Lewis SynthWorks
--
--
-- Package Defines
-- Data structure for name.
--
-- Developed for:
-- SynthWorks Design Inc.
-- VHDL Training Classes
-- 11898 SW 128th Ave. Tigard, Or 97223
-- http://www.SynthWorks.com
--
-- Latest standard version available at:
-- http://www.SynthWorks.com/downloads
--
-- Revision History:
-- Date Version Description
-- 06/2010: 0.1 Initial revision
-- 07/2014: 2014.07 Moved specialization required by CoveragePkg to CoveragePkg
-- Separated name handling from message handling to simplify naming
--
--
-- Copyright (c) 2010 - 2014 by SynthWorks Design Inc. All rights reserved.
--
-- Verbatim copies of this source file may be used and
-- distributed without restriction.
--
-- This source file is free software; you can redistribute it
-- and/or modify it under the terms of the ARTISTIC License
-- as published by The Perl Foundation; either version 2.0 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 Artistic License for details.
--
-- You should have received a copy of the license with this source.
-- If not download it from,
-- http://www.perlfoundation.org/artistic_license_2_0
--
use std.textio.all ;
package NamePkg is
type NamePType is protected
procedure Set (NameIn : String) ;
impure function Get return string ;
impure function IsSet return boolean ;
procedure Clear ; -- clear name
procedure Deallocate ; -- effectively alias to clear name
end protected NamePType ;
end package NamePkg ;
package body NamePkg is
type NamePType is protected body
variable NamePtr : line := new string'("") ;
------------------------------------------------------------
procedure Set (NameIn : String) is
------------------------------------------------------------
begin
deallocate(NamePtr) ;
NamePtr := new string'(NameIn) ;
end procedure Set ;
------------------------------------------------------------
impure function Get return string is
------------------------------------------------------------
begin
return NamePtr.all ;
end function Get ;
------------------------------------------------------------
impure function IsSet return boolean is
------------------------------------------------------------
begin
return NamePtr.all /= "" ;
end function IsSet ;
------------------------------------------------------------
procedure Clear is -- clear name
------------------------------------------------------------
begin
deallocate(NamePtr) ;
NamePtr := new string'("") ;
end procedure Clear ;
------------------------------------------------------------
procedure Deallocate is -- clear name
------------------------------------------------------------
begin
Clear ;
end procedure Deallocate ;
end protected body NamePType ;
end package body NamePkg ;

View file

@ -0,0 +1,226 @@
--
-- File Name: RandomBasePkg.vhd
-- Design Unit Name: RandomBasePkg
-- Revision: STANDARD VERSION, revision 2013.05
--
-- Maintainer: Jim Lewis email: jim@synthworks.com
-- Contributor(s):
-- Jim Lewis jim@synthworks.com
--
--
-- Description:
-- Defines Base randomization, seed definition, seed generation,
-- and seed IO functionality for RandomPkg.vhd
-- Defines:
-- Procedure Uniform - baseline randomization
-- Type RandomSeedType - the seed as a single object
-- function GenRandSeed from integer_vector, integer, or string
-- IO function to_string, & procedures write, read
--
-- In revision 2.0 these types and functions are included by package reference.
-- Long term these will be passed as generics to RandomGenericPkg
--
--
-- Developed for:
-- SynthWorks Design Inc.
-- VHDL Training Classes
-- 11898 SW 128th Ave. Tigard, Or 97223
-- http://www.SynthWorks.com
--
-- Revision History:
-- Date Version Description
-- 01/2008: 0.1 Initial revision
-- Numerous revisions for VHDL Testbenches and Verification
-- 02/2009: 1.0 First Public Released Version
-- 02/25/2009 1.1 Replaced reference to std_2008 with a reference
-- to ieee_proposed.standard_additions.all ;
-- 03/01/2011 2.0 STANDARD VERSION
-- Fixed abstraction by moving RandomParmType to RandomPkg.vhd
-- 4/2013 2013.04 No Changes
-- 5/2013 2013.05 No Changes
--
--
-- Copyright (c) 2008 - 2013 by SynthWorks Design Inc. All rights reserved.
--
-- Verbatim copies of this source file may be used and
-- distributed without restriction.
--
-- This source file is free software; you can redistribute it
-- and/or modify it under the terms of the ARTISTIC License
-- as published by The Perl Foundation; either version 2.0 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 Artistic License for details.
--
-- You should have received a copy of the license with this source.
-- If not download it from,
-- http://www.perlfoundation.org/artistic_license_2_0
--
library ieee ;
use ieee.math_real.all ;
use std.textio.all ;
-- comment out following 2 lines with VHDL-2008. Leave in for VHDL-2002
-- library ieee_proposed ; -- remove with VHDL-2008
-- use ieee_proposed.standard_additions.all ; -- remove with VHDL-2008
package RandomBasePkg is
-- RandomSeedType and Uniform can be replaced by any procedure that
-- produces a uniform distribution with 0 <= Value < 1 or 0 < Value < 1
-- and maintains the same call interface
type RandomSeedType is array (1 to 2) of integer ;
procedure Uniform (Result : out real ; Seed : inout RandomSeedType) ;
-- Translate from integer_vector, integer, or string to RandomSeedType
-- Required by RandomPkg.InitSeed
-- GenRandSeed makes sure all values are in a valid range
function GenRandSeed(IV : integer_vector) return RandomSeedType ;
function GenRandSeed(I : integer) return RandomSeedType ;
function GenRandSeed(S : string) return RandomSeedType ;
-- IO for RandomSeedType. If use subtype, then create aliases here
-- in a similar fashion VHDL-2008 std_logic_textio.
-- Not required by RandomPkg
function to_string(A : RandomSeedType) return string ;
procedure write(variable L: inout line ; A : RandomSeedType ) ;
procedure read (variable L: inout line ; A : out RandomSeedType ; good : out boolean ) ;
procedure read (variable L: inout line ; A : out RandomSeedType ) ;
end RandomBasePkg ;
-----------------------------------------------------------------
-----------------------------------------------------------------
package body RandomBasePkg is
-----------------------------------------------------------------
-- Uniform
-- Generate a random number with a Uniform distribution
-- Required by RandomPkg. All randomization is derived from here.
-- Value produced must be either:
-- 0 <= Value < 1 or 0 < Value < 1
--
-- Current version uses ieee.math_real.Uniform
-- This abstraction allows higher precision version
-- of a uniform distribution to be used provided
--
procedure Uniform (
Result : out real ;
Seed : inout RandomSeedType
) is
begin
ieee.math_real.Uniform (Seed(Seed'left), Seed(Seed'right), Result) ;
end procedure Uniform ;
-----------------------------------------------------------------
-- GenRandSeed
-- Convert integer_vector to RandomSeedType
-- Uniform requires two seed values of the form:
-- 1 <= SEED1 <= 2147483562; 1 <= SEED2 <= 2147483398
--
-- if 2 seed values are passed to GenRandSeed and they are
-- in the above range, then they must remain unmodified.
--
function GenRandSeed(IV : integer_vector) return RandomSeedType is
alias iIV : integer_vector(1 to IV'length) is IV ;
variable Seed1 : integer ;
variable Seed2 : integer ;
constant SEED1_MAX : integer := 2147483562 ;
constant SEED2_MAX : integer := 2147483398 ;
begin
if iIV'Length <= 0 then -- no seed
report "%%FATAL: GenRandSeed received NULL integer_vector" severity failure ;
return (3, 17) ; -- if continue seed = (3, 17)
elsif iIV'Length = 1 then -- one seed value
-- inefficient handling, but condition is unlikely
return GenRandSeed(iIV(1)) ; -- generate a seed
else -- only use the left two values
-- 1 <= SEED1 <= 2147483562
-- mod returns 0 to MAX-1, the -1 adjusts legal values, +1 adjusts them back
Seed1 := ((iIV(1)-1) mod SEED1_MAX) + 1 ;
-- 1 <= SEED2 <= 2147483398
Seed2 := ((iIV(2)-1) mod SEED2_MAX) + 1 ;
return (Seed1, Seed2) ;
end if ;
end function GenRandSeed ;
-----------------------------------------------------------------
-- GenRandSeed
-- transform a single integer into the internal seed
--
function GenRandSeed(I : integer) return RandomSeedType is
variable result : integer_vector(1 to 2) ;
begin
result(1) := I ;
result(2) := I/3 + 1 ;
return GenRandSeed(result) ; -- make value ranges legal
end function GenRandSeed ;
-----------------------------------------------------------------
-- GenRandSeed
-- transform a string value into the internal seed
-- usage: RV.GenRandSeed(RV'instance_path));
--
function GenRandSeed(S : string) return RandomSeedType is
constant LEN : integer := S'length ;
constant HALF_LEN : integer := LEN/2 ;
alias revS : string(LEN downto 1) is S ;
variable result : integer_vector(1 to 2) ;
variable temp : integer := 0 ;
begin
for i in 1 to HALF_LEN loop
temp := (temp + character'pos(revS(i))) mod (integer'right - 2**8) ;
end loop ;
result(1) := temp ;
for i in HALF_LEN + 1 to LEN loop
temp := (temp + character'pos(revS(i))) mod (integer'right - 2**8) ;
end loop ;
result(2) := temp ;
return GenRandSeed(result) ; -- make value ranges legal
end function GenRandSeed ;
-----------------------------------------------------------------
function to_string(A : RandomSeedType) return string is
begin
return to_string(A(A'left)) & " " & to_string(A(A'right)) ;
end function to_string ;
-----------------------------------------------------------------
procedure write(variable L: inout line ; A : RandomSeedType ) is
begin
write(L, to_string(A)) ;
end procedure ;
-----------------------------------------------------------------
procedure read(variable L: inout line ; A : out RandomSeedType ; good : out boolean ) is
variable iGood : boolean ;
begin
for i in A'range loop
read(L, A(i), iGood) ;
exit when not iGood ;
end loop ;
good := iGood ;
end procedure read ;
-----------------------------------------------------------------
procedure read(variable L: inout line ; A : out RandomSeedType ) is
variable good : boolean ;
begin
read(L, A, good) ;
assert good report "read[line, RandomSeedType] failed" severity error ;
end procedure read ;
end RandomBasePkg ;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,409 @@
--
-- File Name: SortListPkg_int.vhd
-- Design Unit Name: SortListPkg_int
-- Revision: STANDARD VERSION, revision 2014.01
--
-- Maintainer: Jim Lewis email: jim@synthworks.com
-- Contributor(s):
-- Jim Lewis jim@synthworks.com
--
-- Description:
-- Sorting utility for array of scalars
-- Uses protected type so as to shrink and expand the data structure
--
-- Developed for:
-- SynthWorks Design Inc.
-- VHDL Training Classes
-- 11898 SW 128th Ave. Tigard, Or 97223
-- http://www.SynthWorks.com
--
-- Revision History:
-- Date Version Description
-- 06/2008: 0.1 Initial revision
-- Numerous revisions for VHDL Testbenches and Verification
-- 02/2009: 1.0 First Public Released Version
-- 02/25/2009 1.1 Replaced reference to std_2008 with a reference to
-- ieee_proposed.standard_additions.all ;
-- 06/16/2010 1.2 Added EraseList parameter to to_array
-- 3/2011 2.0 added inside as non protected type
-- 6/2011 2.1 added sort as non protected type
-- 4/2013 2013.04 No Changes
-- 5/2013 2013.05 No changes of substance.
-- Deleted extra variable declaration in procedure remove
-- 1/2014 2014.01 Added RevSort. Added AllowDuplicate paramter to Add procedure
--
--
--
-- Copyright (c) 2008 - 2014 by SynthWorks Design Inc. All rights reserved.
--
-- Verbatim copies of this source file may be used and
-- distributed without restriction.
--
-- This source file is free software; you can redistribute it
-- and/or modify it under the terms of the ARTISTIC License
-- as published by The Perl Foundation; either version 2.0 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 Artistic License for details.
--
-- You should have received a copy of the license with this source.
-- If not download it from,
-- http://www.perlfoundation.org/artistic_license_2_0
--
use std.textio.all ;
library ieee ;
use ieee.std_logic_1164.all ;
use ieee.numeric_std.all ;
use ieee.std_logic_textio.all ;
-- comment out following 2 lines with VHDL-2008. Leave in for VHDL-2002
-- library ieee_proposed ; -- remove with VHDL-2008
-- use ieee_proposed.standard_additions.all ; -- remove with VHDL-2008
package SortListPkg_int is
-- with VHDL-2008, convert package to generic package
-- convert subtypes ElementType and ArrayofElementType to generics
-- package SortListGenericPkg is
subtype ElementType is integer ;
subtype ArrayofElementType is integer_vector ;
function inside (constant E : ElementType; constant A : in ArrayofElementType) return boolean ;
impure function sort (constant A : in ArrayofElementType) return ArrayofElementType ;
impure function revsort (constant A : in ArrayofElementType) return ArrayofElementType ;
type SortListPType is protected
procedure add ( constant A : in ElementType ; constant AllowDuplicate : Boolean := FALSE ) ;
procedure add ( constant A : in ArrayofElementType ) ;
procedure add ( constant A : in ArrayofElementType ; Min, Max : integer ) ;
procedure add ( variable A : inout SortListPType ) ;
-- Count items in list
impure function count return integer ;
impure function find_index ( constant A : ElementType) return integer ;
impure function inside (constant A : ElementType) return boolean ;
procedure insert ( constant A : in ElementType; constant index : in integer := 1 ) ;
impure function get ( constant index : in integer := 1 ) return ElementType ;
procedure erase ;
impure function Empty return boolean ;
procedure print ;
procedure remove ( constant A : in ElementType ) ;
procedure remove ( constant A : in ArrayofElementType ) ;
procedure remove ( variable A : inout SortListPType ) ;
impure function to_array (constant EraseList : boolean := FALSE) return ArrayofElementType ;
impure function to_rev_array (constant EraseList : boolean := FALSE) return ArrayofElementType ;
end protected SortListPType ;
end SortListPkg_int ;
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
package body SortListPkg_int is
function inside (constant E : ElementType; constant A : in ArrayofElementType) return boolean is
begin
for i in A'range loop
if E = A(i) then
return TRUE ;
end if ;
end loop ;
return FALSE ;
end function inside ;
type SortListPType is protected body
type ListType ;
type ListPointerType is access ListType ;
type ListType is record
A : ElementType ;
-- item_num : integer ;
NextPtr : ListPointerType ;
-- PrevPtr : ListPointerType ;
end record ;
variable HeadPointer : ListPointerType := NULL ;
-- variable TailPointer : ListPointerType := NULL ;
procedure add ( constant A : in ElementType ; constant AllowDuplicate : Boolean := FALSE ) is
variable CurPtr, tempPtr : ListPointerType ;
begin
if HeadPointer = NULL then
HeadPointer := new ListType'(A, NULL) ;
elsif A = HeadPointer.A then -- ignore duplicates
if AllowDuplicate then
tempPtr := HeadPointer ;
HeadPointer := new ListType'(A, tempPtr) ;
end if ;
elsif A < HeadPointer.A then
tempPtr := HeadPointer ;
HeadPointer := new ListType'(A, tempPtr) ;
else
CurPtr := HeadPointer ;
AddLoop : loop
exit AddLoop when CurPtr.NextPtr = NULL ;
exit AddLoop when A < CurPtr.NextPtr.A ;
if A = CurPtr.NextPtr.A then
if AllowDuplicate then
exit AddLoop ; -- insert
else
return ; -- return without insert
end if;
end if ;
CurPtr := CurPtr.NextPtr ;
end loop AddLoop ;
tempPtr := CurPtr.NextPtr ;
CurPtr.NextPtr := new ListType'(A, tempPtr) ;
end if ;
end procedure add ;
procedure add ( constant A : in ArrayofElementType ) is
begin
for i in A'range loop
add(A(i)) ;
end loop ;
end procedure add ;
procedure add ( constant A : in ArrayofElementType ; Min, Max : integer ) is
begin
for i in A'range loop
if A(i) >= Min and A(i) <= Max then
add(A(i)) ;
end if ;
end loop ;
end procedure add ;
procedure add ( variable A : inout SortListPType ) is
begin
for i in 1 to A.Count loop
add(A.Get(i)) ;
end loop ;
end procedure add ;
-- Count items in list
impure function count return integer is
variable result : positive := 1 ;
variable CurPtr : ListPointerType ;
begin
if HeadPointer = NULL then
return 0 ;
else
CurPtr := HeadPointer ;
loop
exit when CurPtr.NextPtr = NULL ;
result := result + 1 ;
CurPtr := CurPtr.NextPtr ;
end loop ;
return result ;
end if ;
end function count ;
impure function find_index (constant A : ElementType) return integer is
variable result : positive := 2 ;
variable CurPtr : ListPointerType ;
begin
if HeadPointer = NULL then
return 0 ;
elsif A <= HeadPointer.A then
return 1 ;
else
CurPtr := HeadPointer ;
loop
exit when CurPtr.NextPtr = NULL ;
exit when A <= CurPtr.NextPtr.A ;
result := result + 1 ;
CurPtr := CurPtr.NextPtr ;
end loop ;
return result ;
end if ;
end function find_index ;
impure function inside (constant A : ElementType) return boolean is
variable CurPtr : ListPointerType ;
begin
if HeadPointer = NULL then
return FALSE ;
end if ;
if A = HeadPointer.A then
return TRUE ;
else
CurPtr := HeadPointer ;
loop
exit when CurPtr.NextPtr = NULL ;
exit when A < CurPtr.NextPtr.A ;
if A = CurPtr.NextPtr.A then
return TRUE ; -- exit
end if;
CurPtr := CurPtr.NextPtr ;
end loop ;
end if ;
return FALSE ;
end function inside ;
procedure insert( constant A : in ElementType; constant index : in integer := 1 ) is
variable CurPtr, tempPtr : ListPointerType ;
begin
if index <= 1 then
tempPtr := HeadPointer ;
HeadPointer := new ListType'(A, tempPtr) ;
else
CurPtr := HeadPointer ;
for i in 3 to index loop
exit when CurPtr.NextPtr = NULL ; -- end of list
CurPtr := CurPtr.NextPtr ;
end loop ;
tempPtr := CurPtr.NextPtr ;
CurPtr.NextPtr := new ListType'(A, tempPtr) ;
end if;
end procedure insert ;
impure function get ( constant index : in integer := 1 ) return ElementType is
variable CurPtr : ListPointerType ;
begin
if index > Count then
report "%%FAILURE: SortListPType index out of range" severity failure ;
return ElementType'left ;
elsif HeadPointer = NULL then
return ElementType'left ;
elsif index <= 1 then
return HeadPointer.A ;
else
CurPtr := HeadPointer ;
for i in 2 to index loop
CurPtr := CurPtr.NextPtr ;
end loop ;
return CurPtr.A ;
end if;
end function get ;
procedure erase (variable CurPtr : inout ListPointerType ) is
begin
if CurPtr.NextPtr /= NULL then
erase (CurPtr.NextPtr) ;
end if ;
deallocate (CurPtr) ;
end procedure erase ;
procedure erase is
begin
if HeadPointer /= NULL then
erase(HeadPointer) ;
-- deallocate (HeadPointer) ;
HeadPointer := NULL ;
end if;
end procedure erase ;
impure function Empty return boolean is
begin
return HeadPointer = NULL ;
end Empty ;
procedure print is
variable buf : line ;
variable CurPtr : ListPointerType ;
begin
if HeadPointer = NULL then
write (buf, string'("( )")) ;
else
CurPtr := HeadPointer ;
write (buf, string'("(")) ;
loop
write (buf, CurPtr.A) ;
exit when CurPtr.NextPtr = NULL ;
write (buf, string'(", ")) ;
CurPtr := CurPtr.NextPtr ;
end loop ;
write (buf, string'(")")) ;
end if ;
writeline(OUTPUT, buf) ;
end procedure print ;
procedure remove ( constant A : in ElementType ) is
variable CurPtr, tempPtr : ListPointerType ;
begin
if HeadPointer = NULL then
return ;
elsif A = HeadPointer.A then
tempPtr := HeadPointer ;
HeadPointer := HeadPointer.NextPtr ;
deallocate (tempPtr) ;
else
CurPtr := HeadPointer ;
loop
exit when CurPtr.NextPtr = NULL ;
if A = CurPtr.NextPtr.A then
tempPtr := CurPtr.NextPtr ;
CurPtr.NextPtr := CurPtr.NextPtr.NextPtr ;
deallocate (tempPtr) ;
exit ;
end if ;
exit when A < CurPtr.NextPtr.A ;
CurPtr := CurPtr.NextPtr ;
end loop ;
end if ;
end procedure remove ;
procedure remove ( constant A : in ArrayofElementType ) is
begin
for i in A'range loop
remove(A(i)) ;
end loop ;
end procedure remove ;
procedure remove ( variable A : inout SortListPType ) is
begin
for i in 1 to A.Count loop
remove(A.Get(i)) ;
end loop ;
end procedure remove ;
impure function to_array (constant EraseList : boolean := FALSE) return ArrayofElementType is
variable result : ArrayofElementType(1 to Count) ;
begin
for i in 1 to Count loop
result(i) := Get(i) ;
end loop ;
if EraseList then
erase ;
end if ;
return result ;
end function to_array ;
impure function to_rev_array (constant EraseList : boolean := FALSE) return ArrayofElementType is
variable result : ArrayofElementType(Count downto 1) ;
begin
for i in 1 to Count loop
result(i) := Get(i) ;
end loop ;
if EraseList then
erase ;
end if ;
return result ;
end function to_rev_array ;
end protected body SortListPType ;
impure function sort (constant A : in ArrayofElementType) return ArrayofElementType is
variable Result : SortListPType ;
begin
for i in A'range loop
Result.Add(A(i), TRUE) ;
end loop ;
return Result.to_array(EraseList => TRUE) ;
end function sort ;
impure function revsort (constant A : in ArrayofElementType) return ArrayofElementType is
variable Result : SortListPType ;
begin
for i in A'range loop
Result.Add(A(i), TRUE) ;
end loop ;
return Result.to_rev_array(EraseList => TRUE) ;
end function revsort ;
end SortListPkg_int ;

View file

@ -0,0 +1,14 @@
Compile the files into your osvvm library in the following order...
SortListPkg_int.vhd
RandomBasePkg.vhd
RandomPkg.vhd
MessagePkg.vhd
NamePkg.vhd
CoveragePkg.vhd
In your code, add the lines
library osvvm;
use osvvm.RandomPkg.all;
use osvvm.CoveragePkg.all;
useful guide at Doulos: https://www.doulos.com/knowhow/vhdl_designers_guide/OSVVM/

View file

@ -0,0 +1,685 @@
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_textio.all;
use std.textio.all;
library OSVVM ;
use OSVVM.RandomBasePkg.all ;
use OSVVM.RandomPkg.all ;
package AVALON_VERIFY_PKG is
shared variable RV : RandomPType;
-----------------------------------------------------------------------------
-- Bus duty cycle control
-----------------------------------------------------------------------------
signal int_mmBusPunctureAllowed : boolean := false;
signal int_mmBusPunctureMax : integer := 3;
signal int_stmBusPunctureAllowed : boolean := false;
signal int_stmBusPunctureMin : integer := 3;
signal int_stmBusPunctureMax : integer := 3;
-----------------------------------------------------------------------------
-- Clock and reset section
-----------------------------------------------------------------------------
signal clk_clk : std_logic := '0';
signal reset_reset_n : std_logic := '0';
-----------------------------------------------------------------------------
-- Avalon MM section
-----------------------------------------------------------------------------
type data_128b_vec_t is array (0 to 1023) of std_logic_vector(127 downto 0);
type data_96b_vec_t is array (0 to 1023) of std_logic_vector( 95 downto 0);
type data_64b_vec_t is array (0 to 1023) of std_logic_vector( 63 downto 0);
type data_32b_vec_t is array (0 to 1023) of std_logic_vector( 31 downto 0);
type data_16b_vec_t is array (0 to 1023) of std_logic_vector( 15 downto 0);
type data_8b_vec_t is array (0 to 1023) of std_logic_vector( 7 downto 0);
signal base_addr : std_logic_vector(31 downto 0) := (others => '0');
type mm_m_rec_t is
record
mm_burstcount : std_logic_vector(31 downto 0) ;
mm_burst : std_logic ;
mm_writedata : std_logic_vector(31 downto 0) ;
mm_address : std_logic_vector(31 downto 0) ;
mm_write : std_logic ;
mm_read : std_logic ;
mm_byteenable : std_logic_vector(3 downto 0) ;
mm_debugaccess : std_logic ;
end record;
type mm_s_rec_t is
record
mm_waitrequest : std_logic;
mm_readdata : std_logic_vector(31 downto 0);
mm_readdatavalid : std_logic;
use_readvalid : boolean;
end record;
type mm_128b_m_rec_t is
record
mm_burstcount : std_logic_vector( 31 downto 0);
mm_burst : std_logic ;
mm_writedata : std_logic_vector(127 downto 0);
mm_address : std_logic_vector( 31 downto 0);
mm_write : std_logic ;
mm_read : std_logic ;
mm_byteenable : std_logic_vector( 15 downto 0);
mm_debugaccess : std_logic ;
end record;
type mm_128b_s_rec_t is
record
mm_waitrequest : std_logic;
mm_readdata : std_logic_vector(127 downto 0);
mm_readdatavalid : std_logic;
end record;
procedure mm_m_init( signal mm_m_rec : out mm_m_rec_t );
procedure mm_s_init( signal mm_s_rec : out mm_s_rec_t );
procedure mm_128b_m_init( signal mm_m_rec : out mm_128b_m_rec_t );
procedure mm_128b_s_init( signal mm_s_rec : out mm_128b_s_rec_t );
procedure mm_128b_burst( addr : in std_logic_vector(31 downto 0);
size : in integer;
data : in data_128b_vec_t;
signal mm_s_rec : in mm_128b_s_rec_t;
signal mm_m_rec : out mm_128b_m_rec_t);
procedure mm_32b_burst( addr : in std_logic_vector(31 downto 0);
size : in integer;
data : in data_32b_vec_t;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
procedure mm_32b_write( addr : in std_logic_vector(31 downto 0);
data : in std_logic_vector(31 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
procedure mm_16b_write( addr : in std_logic_vector(31 downto 0);
data : in std_logic_vector(15 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
procedure mm_8b_write( addr : in std_logic_vector(31 downto 0);
data : in std_logic_vector( 7 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
procedure mm_32b_read( addr : in std_logic_vector(31 downto 0);
data : out std_logic_vector(31 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
procedure mm_16b_read( addr : in std_logic_vector(31 downto 0);
data : out std_logic_vector(15 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
procedure mm_8b_read( addr : in std_logic_vector(31 downto 0);
data : out std_logic_vector( 7 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
-----------------------------------------------------------------------------
-- Avalon Stream section
-----------------------------------------------------------------------------
type stm_m_rec_t is
record
stm_channel : std_logic_vector( 7 downto 0);
stm_data : std_logic_vector(31 downto 0);
stm_valid : std_logic;
stm_sop : std_logic;
stm_eop : std_logic;
end record;
type stm_s_rec_t is
record
stm_ready : std_logic;
stm_error : std_logic_vector( 7 downto 0);
end record;
procedure stm_m_init( signal stm_m_rec : out stm_m_rec_t );
procedure stm_s_init( signal stm_s_rec : out stm_s_rec_t );
procedure stm_puncture;
procedure stm_32b_write( len : in integer;
channel : in integer;
data_vec : in data_32b_vec_t;
signal stm_s_rec : in stm_s_rec_t;
signal stm_m_rec : out stm_m_rec_t);
procedure stm_16b_write( len : in integer;
channel : in integer;
data_vec : in data_16b_vec_t;
signal stm_s_rec : in stm_s_rec_t;
signal stm_m_rec : out stm_m_rec_t);
procedure stm_8b_write( len : in integer;
channel : in integer;
data_vec : in data_8b_vec_t;
signal stm_s_rec : in stm_s_rec_t;
signal stm_m_rec : out stm_m_rec_t);
procedure stm_8b_read( signal stm_m_rec : in stm_m_rec_t;
signal stm_s_rec : out stm_s_rec_t;
data_vec : out data_8b_vec_t;
channel : out integer;
len : out integer);
-----------------------------------------------------------------------------
-- LVDS section
-----------------------------------------------------------------------------
type lvds_m_rec_t is
record
lvds_1_rx_data : std_logic_vector(9 downto 0);
lvds_1_rx_nlock : std_logic;
lvds_1_rx_clk : std_logic;
lvds_2_rx_data : std_logic_vector(9 downto 0);
lvds_2_rx_nlock : std_logic;
lvds_2_rx_clk : std_logic;
end record;
type lvds_s_rec_t is
record
lvds_refclk : std_logic;
lvds_1_rx_npwrdn : std_logic;
lvds_1_rx_en : std_logic;
lvds_2_rx_npwrdn : std_logic;
lvds_2_rx_en : std_logic;
end record;
procedure lvds_m_init( signal lvds_m_rec : out lvds_m_rec_t );
procedure lvds_s_init( signal lvds_s_rec : out lvds_s_rec_t );
procedure lvds_write( len : in integer;
data_vec : in data_8b_vec_t;
signal lvds_s_rec : in lvds_s_rec_t;
signal lvds_m_rec : out lvds_m_rec_t);
end AVALON_VERIFY_PKG;
package body AVALON_VERIFY_PKG is
-----------------------------------------------------------------------------
-- Avalon MM section
-----------------------------------------------------------------------------
procedure mm_128b_m_init( signal mm_m_rec : out mm_128b_m_rec_t ) is
begin
mm_m_rec.mm_address <= (others => '0');
mm_m_rec.mm_byteenable <= (others => '0');
mm_m_rec.mm_writedata <= (others => '0');
mm_m_rec.mm_write <= '0';
mm_m_rec.mm_read <= '0';
mm_m_rec.mm_byteenable <= (others => '0');
mm_m_rec.mm_debugaccess <= '0';
mm_m_rec.mm_burstcount <= (others => '0');
end mm_128b_m_init;
procedure mm_128b_s_init( signal mm_s_rec : out mm_128b_s_rec_t ) is
begin
mm_s_rec.mm_waitrequest <= '0';
mm_s_rec.mm_readdata <= (others => '0');
mm_s_rec.mm_readdatavalid <= '0';
end mm_128b_s_init;
procedure mm_m_init( signal mm_m_rec : out mm_m_rec_t ) is
begin
mm_m_rec.mm_address <= (others => '0');
mm_m_rec.mm_byteenable <= (others => '0');
mm_m_rec.mm_writedata <= (others => '0');
mm_m_rec.mm_write <= '0';
mm_m_rec.mm_read <= '0';
mm_m_rec.mm_byteenable <= (others => '0');
mm_m_rec.mm_debugaccess <= '0';
mm_m_rec.mm_burstcount <= (others => '0');
end mm_m_init;
procedure mm_s_init( signal mm_s_rec : out mm_s_rec_t ) is
begin
mm_s_rec.mm_waitrequest <= '0';
mm_s_rec.mm_readdata <= (others => '0');
mm_s_rec.mm_readdatavalid <= '0';
end mm_s_init;
procedure mm_128b_burst( addr : in std_logic_vector(31 downto 0);
size : in integer;
data : in data_128b_vec_t;
signal mm_s_rec : in mm_128b_s_rec_t;
signal mm_m_rec : out mm_128b_m_rec_t) is
begin
wait until rising_edge(clk_clk);
if mm_s_rec.mm_waitrequest = '1' then
wait until falling_edge(mm_s_rec.mm_waitrequest);
end if;
for i in 0 to size-1 loop
if i = 0 then
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_byteenable <= x"1111";
mm_m_rec.mm_writedata <= data(i);
mm_m_rec.mm_write <= '1';
mm_m_rec.mm_burst <= '1';
mm_m_rec.mm_burstcount <= std_logic_vector(to_unsigned(size,32));
wait until rising_edge(clk_clk);
mm_m_rec.mm_byteenable <= x"0000";
mm_m_rec.mm_write <= '0';
mm_m_rec.mm_burst <= '0';
else
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_byteenable <= x"1111";
mm_m_rec.mm_writedata <= data(i);
mm_m_rec.mm_write <= '1';
wait until rising_edge(clk_clk);
mm_m_rec.mm_byteenable <= x"0000";
mm_m_rec.mm_write <= '0';
end if;
end loop; -- i
wait until rising_edge(clk_clk);
end mm_128b_burst;
procedure mm_32b_burst( addr : in std_logic_vector(31 downto 0);
size : in integer;
data : in data_32b_vec_t;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
begin
wait until rising_edge(clk_clk);
if mm_s_rec.mm_waitrequest = '1' then
wait until falling_edge(mm_s_rec.mm_waitrequest);
end if;
for i in 0 to size-1 loop
if i = 0 then
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_byteenable <= "1111";
mm_m_rec.mm_writedata <= data(i);
mm_m_rec.mm_write <= '1';
mm_m_rec.mm_burst <= '1';
mm_m_rec.mm_burstcount <= std_logic_vector(to_unsigned(size,32));
wait until rising_edge(clk_clk);
mm_m_rec.mm_byteenable <= "0000";
mm_m_rec.mm_write <= '0';
mm_m_rec.mm_burst <= '0';
else
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_byteenable <= "1111";
mm_m_rec.mm_writedata <= data(i);
mm_m_rec.mm_write <= '1';
wait until rising_edge(clk_clk);
mm_m_rec.mm_byteenable <= "0000";
mm_m_rec.mm_write <= '0';
end if;
end loop; -- i
wait until rising_edge(clk_clk);
end mm_32b_burst;
procedure mm_32b_write( addr : in std_logic_vector(31 downto 0);
data : in std_logic_vector(31 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
begin
wait until rising_edge(clk_clk);
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_byteenable <= "1111";
mm_m_rec.mm_writedata <= data;
mm_m_rec.mm_write <= '1';
wait until falling_edge(clk_clk);
while mm_s_rec.mm_waitrequest = '1' loop
wait until falling_edge(clk_clk);
end loop;
wait until rising_edge(clk_clk);
mm_m_rec.mm_byteenable <= "0000";
mm_m_rec.mm_write <= '0';
end mm_32b_write;
procedure mm_16b_write( addr : in std_logic_vector(31 downto 0);
data : in std_logic_vector(15 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
variable my_addr : std_logic_vector(31 downto 0) := (others=>'0');
begin
my_addr := addr;
if addr(1) = '1' then
my_addr := std_logic_vector(unsigned(my_addr)+2);
end if;
wait until rising_edge(clk_clk);
if mm_s_rec.mm_waitrequest = '1' then
wait until falling_edge(mm_s_rec.mm_waitrequest);
end if;
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_writedata <= data & data;
if addr(1) = '0' then
mm_m_rec.mm_byteenable <= "0011";
else
mm_m_rec.mm_byteenable <= "1100";
end if;
mm_m_rec.mm_write <= '1';
wait until rising_edge(clk_clk);
mm_m_rec.mm_byteenable <= "0000";
mm_m_rec.mm_write <= '0';
wait until rising_edge(clk_clk);
end mm_16b_write;
procedure mm_8b_write( addr : in std_logic_vector(31 downto 0);
data : in std_logic_vector( 7 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
begin
wait until rising_edge(clk_clk);
if mm_s_rec.mm_waitrequest = '1' then
wait until falling_edge(mm_s_rec.mm_waitrequest);
end if;
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_writedata <= data & data & data & data;
if addr(1 downto 0) = "00" then
mm_m_rec.mm_byteenable <= "0001";
elsif addr(1 downto 0) = "01" then
mm_m_rec.mm_byteenable <= "0010";
elsif addr(1 downto 0) = "10" then
mm_m_rec.mm_byteenable <= "0100";
else
mm_m_rec.mm_byteenable <= "1000";
end if;
mm_m_rec.mm_write <= '1';
wait until rising_edge(clk_clk);
mm_m_rec.mm_byteenable <= "0000";
mm_m_rec.mm_write <= '0';
wait until rising_edge(clk_clk);
end mm_8b_write;
procedure mm_32b_read( addr : in std_logic_vector(31 downto 0);
data : out std_logic_vector(31 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
begin
wait until rising_edge(clk_clk);
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_read <= '1';
wait until falling_edge(clk_clk);
while mm_s_rec.mm_waitrequest = '1' loop
wait until falling_edge(clk_clk);
end loop;
wait until rising_edge(clk_clk);
mm_m_rec.mm_read <= '0';
if(mm_s_rec.use_readvalid = true) then
if(mm_s_rec.mm_readdatavalid = '0') then
wait until mm_s_rec.mm_readdatavalid = '1';
end if;
end if;
wait until falling_edge(clk_clk);
data := mm_s_rec.mm_readdata;
end mm_32b_read;
procedure mm_16b_read( addr : in std_logic_vector(31 downto 0);
data : out std_logic_vector(15 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
begin
wait until rising_edge(clk_clk);
if mm_s_rec.mm_waitrequest = '1' then
wait until falling_edge(mm_s_rec.mm_waitrequest);
end if;
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_read <= '1';
wait until rising_edge(clk_clk);
mm_m_rec.mm_read <= '0';
wait until rising_edge(mm_s_rec.mm_readdatavalid);
data := mm_s_rec.mm_readdata(15 downto 0);
end mm_16b_read;
procedure mm_8b_read( addr : in std_logic_vector(31 downto 0);
data : out std_logic_vector( 7 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
begin
wait until rising_edge(clk_clk);
if mm_s_rec.mm_waitrequest = '1' then
wait until falling_edge(mm_s_rec.mm_waitrequest);
end if;
mm_m_rec.mm_address <= addr or base_addr;
mm_m_rec.mm_read <= '1';
wait until rising_edge(clk_clk);
mm_m_rec.mm_read <= '0';
wait until rising_edge(mm_s_rec.mm_readdatavalid);
data := mm_s_rec.mm_readdata( 7 downto 0);
end mm_8b_read;
-----------------------------------------------------------------------------
-- Avalon Stream section
-----------------------------------------------------------------------------
procedure stm_m_init( signal stm_m_rec : out stm_m_rec_t ) is
begin
stm_m_rec.stm_channel <= (others => '0');
stm_m_rec.stm_data <= (others => '0');
stm_m_rec.stm_valid <= '0';
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
end stm_m_init;
procedure stm_s_init( signal stm_s_rec : out stm_s_rec_t ) is
begin
stm_s_rec.stm_ready <= '0';
stm_s_rec.stm_error <= (others => '0');
end stm_s_init;
procedure stm_puncture is
variable loop_max : integer;
begin
loop_max := RV.RandInt(int_stmBusPunctureMin,int_stmBusPunctureMax);
if loop_max > 0 then
for i in 1 to loop_max loop
wait until rising_edge(clk_clk);
end loop; -- i
end if;
end stm_puncture;
procedure stm_32b_write( len : in integer;
channel : in integer;
data_vec : in data_32b_vec_t;
signal stm_s_rec : in stm_s_rec_t;
signal stm_m_rec : out stm_m_rec_t) is
variable loop_max : integer;
begin
wait until rising_edge(clk_clk);
if stm_s_rec.stm_ready = '0' then
wait until rising_edge(stm_s_rec.stm_ready);
end if;
wait until rising_edge(clk_clk);
for i in 1 to len loop
stm_m_rec.stm_channel <= std_logic_vector(to_unsigned(channel, 8));
stm_m_rec.stm_data <= data_vec(i-1);
stm_m_rec.stm_valid <= '1';
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
if i = 1 then
stm_m_rec.stm_sop <= '1';
end if;
if i = len then
stm_m_rec.stm_eop <= '1';
end if;
wait until rising_edge(clk_clk);
stm_m_rec.stm_valid <= '0';
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
stm_puncture;
end loop; -- i
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
stm_m_rec.stm_valid <= '0';
end stm_32b_write;
procedure stm_16b_write( len : in integer;
channel : in integer;
data_vec : in data_16b_vec_t;
signal stm_s_rec : in stm_s_rec_t;
signal stm_m_rec : out stm_m_rec_t) is
variable loop_max : integer;
begin
wait until rising_edge(clk_clk);
if stm_s_rec.stm_ready = '0' then
wait until rising_edge(stm_s_rec.stm_ready);
end if;
wait until rising_edge(clk_clk);
for i in 1 to len loop
stm_m_rec.stm_channel <= std_logic_vector(to_unsigned(channel, 8));
stm_m_rec.stm_data <= x"0000" & data_vec(i-1);
stm_m_rec.stm_valid <= '1';
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
if i = 1 then
stm_m_rec.stm_sop <= '1';
end if;
if i = len then
stm_m_rec.stm_eop <= '1';
end if;
wait until rising_edge(clk_clk);
stm_m_rec.stm_valid <= '0';
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
stm_puncture;
end loop; -- i
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
stm_m_rec.stm_valid <= '0';
end stm_16b_write;
procedure stm_8b_write( len : in integer;
channel : in integer;
data_vec : in data_8b_vec_t;
signal stm_s_rec : in stm_s_rec_t;
signal stm_m_rec : out stm_m_rec_t) is
variable loop_max : integer;
begin
wait until rising_edge(clk_clk);
if stm_s_rec.stm_ready = '0' then
wait until rising_edge(stm_s_rec.stm_ready);
end if;
wait until rising_edge(clk_clk);
for i in 1 to len loop
stm_m_rec.stm_channel <= std_logic_vector(to_unsigned(channel, 8));
stm_m_rec.stm_data <= x"000000" & data_vec(i-1);
stm_m_rec.stm_valid <= '1';
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
if i = 1 then
stm_m_rec.stm_sop <= '1';
end if;
if i = len then
stm_m_rec.stm_eop <= '1';
end if;
wait until rising_edge(clk_clk);
stm_m_rec.stm_valid <= '0';
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
stm_puncture;
end loop; -- i
stm_m_rec.stm_sop <= '0';
stm_m_rec.stm_eop <= '0';
stm_m_rec.stm_valid <= '0';
end stm_8b_write;
procedure stm_8b_read( signal stm_m_rec : in stm_m_rec_t;
signal stm_s_rec : out stm_s_rec_t;
data_vec : out data_8b_vec_t;
channel : out integer;
len : out integer) is
variable tmp_len : integer := 0;
begin
wait until rising_edge(clk_clk);
if stm_m_rec.stm_sop = '0' then
wait until rising_edge(stm_m_rec.stm_sop);
end if;
channel := to_integer(unsigned(stm_m_rec.stm_data));
while stm_m_rec.stm_eop = '0' loop
tmp_len := tmp_len + 1;
wait until rising_edge(clk_clk);
if stm_m_rec.stm_valid = '1' then
data_vec(tmp_len-1) := stm_m_rec.stm_data(7 downto 0);
end if;
end loop;
len := tmp_len;
end stm_8b_read;
-----------------------------------------------------------------------------
-- LVDS section
-----------------------------------------------------------------------------
procedure lvds_m_init( signal lvds_m_rec : out lvds_m_rec_t ) is
begin
lvds_m_rec.lvds_1_rx_data <= (others => '0');
lvds_m_rec.lvds_1_rx_nlock <= '0';
lvds_m_rec.lvds_1_rx_clk <= '0';
lvds_m_rec.lvds_2_rx_data <= (others => '0');
lvds_m_rec.lvds_2_rx_nlock <= '0';
lvds_m_rec.lvds_2_rx_clk <= '0';
end lvds_m_init;
procedure lvds_s_init( signal lvds_s_rec : out lvds_s_rec_t ) is
begin
lvds_s_rec.lvds_refclk <= '0';
lvds_s_rec.lvds_1_rx_npwrdn <= '0';
lvds_s_rec.lvds_1_rx_en <= '0';
lvds_s_rec.lvds_2_rx_npwrdn <= '0';
lvds_s_rec.lvds_2_rx_en <= '0';
end lvds_s_init;
procedure lvds_write( len : in integer;
data_vec : in data_8b_vec_t;
signal lvds_s_rec : in lvds_s_rec_t;
signal lvds_m_rec : out lvds_m_rec_t) is
variable tog : std_logic := '1';
variable lvds_crc : std_logic_vector(7 downto 0) := x"00";
variable lvds_tmp : std_logic_vector(7 downto 0) := x"00";
constant STX : std_logic_vector(7 downto 0) := x"02";
constant ETX : std_logic_vector(7 downto 0) := x"03";
begin
wait until rising_edge(lvds_s_rec.lvds_refclk);
lvds_m_rec.lvds_1_rx_data <= '1' & '0' & STX;
wait until rising_edge(lvds_s_rec.lvds_refclk);
lvds_m_rec.lvds_1_rx_data <= '0' & '0' & std_logic_vector(to_unsigned(len / 256,8));
wait until rising_edge(lvds_s_rec.lvds_refclk);
lvds_m_rec.lvds_1_rx_data <= '1' & '0' & std_logic_vector(to_unsigned(len mod 256,8));
wait until rising_edge(lvds_s_rec.lvds_refclk);
for i in 0 to len-1 loop
tog := not tog;
lvds_crc := lvds_crc xor data_vec(i);
lvds_m_rec.lvds_1_rx_data <= tog & '0' & data_vec(i);
wait until rising_edge(lvds_s_rec.lvds_refclk);
end loop; -- i
tog := not tog;
lvds_m_rec.lvds_1_rx_data <= tog & '0' & lvds_crc;
wait until rising_edge(lvds_s_rec.lvds_refclk);
tog := not tog;
lvds_m_rec.lvds_1_rx_data <= tog & '0' & ETX;
wait until rising_edge(lvds_s_rec.lvds_refclk);
if tog = '1' then
lvds_m_rec.lvds_1_rx_data <= (others => '0');
wait until rising_edge(lvds_s_rec.lvds_refclk);
end if;
end lvds_write;
end AVALON_VERIFY_PKG;

View file

@ -0,0 +1,273 @@
-------------------------------------------------------------------------------
-- Title : common_test_pkg
-- Project : project independent
-------------------------------------------------------------------------------
-- File : common_test_pkg.vhd
-- Author : GMG
-- Company : Global Inkjet Systems
-- Created : 2017-05-10
-- Last update: 2017-07-06
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Support package for testbenches
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
-------------------------------------------------------------------------------
-- Common Test Package
-------------------------------------------------------------------------------
package common_test_pkg is
-----------------------------------------------------------------------------
-- Protected Flag Type
-----------------------------------------------------------------------------
type prot_flag_t is protected
procedure set;
procedure reset;
impure function is_set return boolean;
impure function is_reset return boolean;
end protected prot_flag_t;
-----------------------------------------------------------------------------
-- Protected Integer Type
-----------------------------------------------------------------------------
type prot_int_t is protected
procedure set(val : in integer);
procedure reset;
procedure inc(val : in integer);
procedure dec(val : in integer);
impure function get return integer;
end protected prot_int_t;
-----------------------------------------------------------------------------
-- Linked List of Integers
-----------------------------------------------------------------------------
type int_linked_list_t is protected
-- return the length of the list
impure function len return integer;
-- clear the list
procedure clear;
-- Add an item to the end of the list
procedure append(val : in integer);
-- read the value of element at position idx in the list. Return -2^31
-- (2147483648) in case element idx does not exist
impure function get_value(idx : natural) return integer;
-- Insert an item at a given position. The first argument is the index
-- of the element before which to insert, so a.insert(0, x) inserts at
-- the front of the list, and a.insert(len(a), x)
procedure insert(idx : in natural; val : in integer);
-- Remove from the list the element a position idx and returns the value of
-- that element.
-- list.pop(0) => remove the first element added to the list (FIFO behaviour)
-- list.pop(list.len-1) => get the last element added to the list (LIFO behaviour)
impure function pop(idx : integer) return integer;
-- find the first occurrence of an item in the list. Return the
-- position of the item in the list if present, -1 if not present
impure function find(val : integer) return integer;
-- similar to find, but return the last occurrence of the item in the list
impure function rfind(val : integer) return integer;
end protected int_linked_list_t;
end package common_test_pkg;
-------------------------------------------------------------------------------
-- Common Test Package (Body)
-------------------------------------------------------------------------------
package body common_test_pkg is
-----------------------------------------------------------------------------
-- Protected Flag Type
-----------------------------------------------------------------------------
type prot_flag_t is protected body
variable flag : boolean := false;
procedure set is
begin flag := True; end procedure set;
procedure reset is
begin flag := False; end procedure reset;
impure function is_set return boolean is
begin return flag; end function is_set;
impure function is_reset return boolean is
begin return not flag; end function is_reset;
end protected body prot_flag_t;
-----------------------------------------------------------------------------
-- Protected Integer Type
-----------------------------------------------------------------------------
type prot_int_t is protected body
variable value : integer := 0;
procedure set(val : in integer) is
begin value := val; end procedure set;
procedure reset is
begin value := 0; end procedure reset;
procedure inc(val : in integer) is
begin value := value + val; end procedure inc;
procedure dec(val : in integer) is
begin value := value - val; end procedure dec;
impure function get return integer is
begin return value; end function get;
end protected body prot_int_t;
-----------------------------------------------------------------------------
-- Linked List of Integers
-----------------------------------------------------------------------------
type int_linked_list_t is protected body
-- define the cell element type
type value_cell;
type value_ptr is access value_cell;
type value_cell is record
value : integer;
next_cell : value_ptr;
end record value_cell;
-- list variable
variable list : value_ptr;
variable length : integer := 0;
-- return the length of the list
impure function len return integer is
begin return length; end function len;
-- clear the list
procedure clear is
begin list := NULL; length := 0; end procedure clear;
-- Add an item to the end of the list
procedure append(val : in integer) is
begin list := new value_cell'(val, list); length := length+1; end procedure append;
-- read the value of element at position idx in the list. Return -2^31
-- (2147483648) in case element idx does not exist
impure function get_value(idx : natural) return integer is
variable value : integer := -2147483648;
variable cell_ptr : value_ptr := list;
begin
if(idx < length) then
for i in 1 to length-idx-1 loop
cell_ptr := cell_ptr.next_cell;
end loop; -- i
if cell_ptr /= NULL then
value := cell_ptr.value;
end if;
end if;
return value;
end function get_value;
-- Insert an item at a given position. The first argument is the index
-- of the element before which to insert, so a.insert(0, x) inserts at
-- the front of the list, and a.insert(len(a), x)
procedure insert(idx : in natural; val : in integer) is
variable cell_ptr : value_ptr := list;
begin
if(idx = length) then
list := new value_cell'(val, list);
length := length+1;
elsif(idx < length) then
for i in 1 to length-idx-1 loop
cell_ptr := cell_ptr.next_cell;
end loop; -- i
cell_ptr.next_cell := new value_cell'(val, cell_ptr.next_cell);
length := length+1;
end if;
end procedure insert;
-- Remove from the list the element a position idx and returns the value of
-- that element.
-- list.pop(0) => remove the first element added to the list (FIFO behaviour)
-- list.pop(list.len-1) => get the last element added to the list (LIFO behaviour)
impure function pop(idx : integer) return integer is
variable val : integer := -2147483648;
variable cell_ptr : value_ptr := list;
variable to_delete : value_ptr := NULL;
variable cell_previous : value_ptr;
begin
if(idx = length-1) then
val := list.value;
to_delete := list;
list := list.next_cell;
length := length-1;
elsif(idx >= 0 and idx < length-1) then
for n in 1 to length-idx-1 loop
cell_previous := cell_ptr;
cell_ptr := cell_ptr.next_cell;
end loop; -- n
val := cell_ptr.value;
to_delete := cell_ptr;
cell_previous.next_cell := cell_ptr.next_cell;
length := length-1;
end if;
deallocate(to_delete);
return val;
end function pop;
-- find the first occurrence of an item in the list. Return the
-- position of the item in the list if present, -1 if not present
impure function find(val : integer) return integer is
variable idx : integer := -1;
variable cell_ptr : value_ptr := list;
begin
for n in length-1 downto 0 loop
if(cell_ptr.value = val) then
idx := n;
end if;
cell_ptr := cell_ptr.next_cell;
end loop; -- n
return idx;
end function find;
-- similar to find, but return the last occurrence of the item in the list
impure function rfind(val : integer) return integer is
variable idx : integer := -1;
variable curr_val : integer := -1;
variable cell_ptr : value_ptr := list;
begin
for n in length-1 downto 0 loop
curr_val := cell_ptr.value;
cell_ptr := cell_ptr.next_cell;
if(curr_val = val) then
idx := n;
exit;
end if;
end loop;
return idx;
end function rfind;
end protected body int_linked_list_t;
end package body common_test_pkg;

View file

@ -0,0 +1,205 @@
-------------------------------------------------------------------------------
-- Title : common_test_pkg
-- Project : project independent
-------------------------------------------------------------------------------
-- File : common_test_pkg.vhd
-- Author : GMG
-- Company : Global Inkjet Systems
-- Created : 2017-05-10
-- Last update: 2017-09-25
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Support package for testbenches
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_textio.all;
use std.textio.all;
use work.common_test_pkg.all;
-------------------------------------------------------------------------------
-- Log Package
-------------------------------------------------------------------------------
package log_pkg is
-- verbosity level
shared variable verb_level : prot_int_t;
-- verbosity levels
type verb_level_t is (V_NONE, V_LOW, V_MEDIUM, V_HIGH, V_FULL, V_DEBUG);
constant VNONE : verb_level_t := V_NONE;
constant VLOW : verb_level_t := V_LOW;
constant VMEDIUM : verb_level_t := V_MEDIUM;
constant VHIGH : verb_level_t := V_HIGH;
constant VFULL : verb_level_t := V_FULL;
constant VDEBUG : verb_level_t := V_DEBUG;
-- Defines whether to save log data to the transcript panel only or also to a
-- text file
-- in the simulator transcript.
shared variable log_to_file_en : prot_flag_t;
file log_file : text;
procedure set_log_verbosity(
level : in verb_level_t);
procedure log_to_file(
enable : in boolean;
file_name : in string);
procedure log_file_close;
procedure log_separator_line(
vlevel : in verb_level_t);
procedure log_header(
mytext : in string;
vlevel : in verb_level_t);
procedure log(
mytext : in string;
vlevel : in verb_level_t;
timetag : in boolean := true;
emph : in boolean := false);
end package log_pkg;
-------------------------------------------------------------------------------
-- Log Package (Body)
-------------------------------------------------------------------------------
package body log_pkg is
procedure set_log_verbosity(
level : in verb_level_t) is
begin
verb_level.set(verb_level_t'pos(level));
end procedure set_log_verbosity;
-- log_init : open the specified log file
procedure log_to_file(
enable : in boolean;
file_name : in string) is
variable status : file_open_status;
begin
if(enable = false) then
log_to_file_en.reset;
else
log_to_file_en.set;
file_open(status, log_file, file_name, write_mode);
if(status /= open_ok) then
--log_to_file_en.reset;
assert false report "Failed to open log file " & file_name & "." severity error;
end if;
end if;
end procedure log_to_file;
-- log_close: close the log file
procedure log_file_close is
begin
if(log_to_file_en.is_set) then
log_to_file_en.reset;
file_close(log_file);
end if;
end procedure log_file_close;
procedure log_separator_line(
vlevel : in verb_level_t) is
variable out_line : line;
begin
if(verb_level_t'pos(vlevel) <= verb_level.get) then
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(output, out_line);
if(log_to_file_en.is_set) then
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(log_file, out_line);
flush(log_file);
end if;
end if;
end procedure log_separator_line;
procedure log_header(
mytext : in string;
vlevel : in verb_level_t) is
variable out_line : line;
begin
if(verb_level_t'pos(vlevel) <= verb_level.get) then
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(output, out_line);
if(log_to_file_en.is_set) then
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(log_file, out_line);
flush(log_file);
end if;
write(out_line, mytext);
writeline(output, out_line);
if(log_to_file_en.is_set) then
write(out_line, mytext);
writeline(log_file, out_line);
flush(log_file);
end if;
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(output, out_line);
if(log_to_file_en.is_set) then
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(log_file, out_line);
flush(log_file);
end if;
end if;
end procedure log_header;
procedure log(
mytext : in string;
vlevel : in verb_level_t;
timetag : in boolean := true;
emph : in boolean := false) is
variable out_line : line;
begin
if(verb_level_t'pos(vlevel) <= verb_level.get) then
if(emph = true) then
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(output, out_line);
if(log_to_file_en.is_set) then
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(log_file, out_line);
flush(log_file);
end if;
end if;
if(timetag) then
write(out_line, now, UNIT => ns);
write(out_line, string'(" : ") & mytext);
else
write(out_line, mytext);
end if;
writeline(output, out_line);
if(log_to_file_en.is_set) then
if(timetag) then
write(out_line, now, UNIT => ns);
write(out_line, string'(" : ") & mytext);
else
write(out_line, mytext);
end if;
writeline(log_file, out_line);
flush(log_file);
end if;
if(emph = true) then
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(output, out_line);
if(log_to_file_en.is_set) then
write(out_line, string'("//////////////////////////////////////////////////////////////////"));
writeline(log_file, out_line);
flush(log_file);
end if;
end if;
end if;
end procedure log;
end package body log_pkg;

View file

@ -0,0 +1,621 @@
-- -------------------------------------------------------------------
-- Design:
--
-- Package for VHDL text output
--
-- Note:
-- -----
-- This package uses the VHDL 95 standard.
-- If VHDL 95 is not supported by your simulator
-- you need to comment out the file access functions.
--
-- The package provides a means to output text and
-- manipulate strings.
--
-- The basic usage is like this: >> print(s); <<
-- (where s is any string)
-- To print something which is not a string it has to be converted
-- into a string first. For this purpose the package contains
-- conversion functions called >> str(...) <<.
-- For example a std_logic_vector slv would be printed like this:
-- >> print(str(slv)); <<. To print several items on one line the
-- items have to concatenated as strings with the "&" operator eg:
-- >> print("The value of slv is "& str(slv)); <<
-- The string functions can also be used in assert statements as shown
-- in the example below:
-- >> assert DIN = "0101" <<
-- >> report "DIN = "& str(DIN)& " expected 0101 " <<
-- >> severity Error; <<
--
--
--
-- -------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
package txt_util is
-- prints a message to the screen
procedure print(text: string);
-- prints the message when active
-- useful for debug switches
procedure print(active: boolean; text: string);
-- converts std_logic into a character
function chr(sl: std_logic) return character;
-- converts std_logic into a string (1 to 1)
function str(sl: std_logic) return string;
-- converts std_logic_vector into a string (binary base)
function str(slv: std_logic_vector) return string;
-- converts boolean into a string
function str(b: boolean) return string;
-- converts an integer into a single character
-- (can also be used for hex conversion and other bases)
function chr(int: integer) return character;
-- converts integer into string using specified base
function str(int: integer; base: integer) return string;
-- converts integer to string, using base 10
function str(int: integer) return string;
-- convert std_logic_vector into a string in hex format
function hstr(slv: std_logic_vector) return string;
-- functions to manipulate strings
-----------------------------------
-- convert a character to upper case
function to_upper(c: character) return character;
-- convert a character to lower case
function to_lower(c: character) return character;
-- convert a string to upper case
function to_upper(s: string) return string;
-- convert a string to lower case
function to_lower(s: string) return string;
-- functions to convert strings into other formats
--------------------------------------------------
-- converts a character into std_logic
function to_std_logic(c: character) return std_logic;
-- converts a string into std_logic_vector
function to_std_logic_vector(s: string) return std_logic_vector;
-- file I/O
-----------
-- read variable length string from input file
procedure str_read(file in_file: TEXT;
res_string: out string);
-- print string to a file and start new line
procedure print(file out_file: TEXT;
new_string: in string);
-- print character to a file and start new line
procedure print(file out_file: TEXT;
char: in character);
end txt_util;
package body txt_util is
-- prints text to the screen
procedure print(text: string) is
variable msg_line: line;
begin
write(msg_line, text);
writeline(output, msg_line);
end print;
-- prints text to the screen when active
procedure print(active: boolean; text: string) is
begin
if active then
print(text);
end if;
end print;
-- converts std_logic into a character
function chr(sl: std_logic) return character is
variable c: character;
begin
case sl is
when 'U' => c:= 'U';
when 'X' => c:= 'X';
when '0' => c:= '0';
when '1' => c:= '1';
when 'Z' => c:= 'Z';
when 'W' => c:= 'W';
when 'L' => c:= 'L';
when 'H' => c:= 'H';
when '-' => c:= '-';
end case;
return c;
end chr;
-- converts std_logic into a string (1 to 1)
function str(sl: std_logic) return string is
variable s: string(1 to 1);
begin
s(1) := chr(sl);
return s;
end str;
-- converts std_logic_vector into a string (binary base)
-- (this also takes care of the fact that the range of
-- a string is natural while a std_logic_vector may
-- have an integer range)
function str(slv: std_logic_vector) return string is
variable result : string (1 to slv'length);
variable r : integer;
begin
r := 1;
for i in slv'range loop
result(r) := chr(slv(i));
r := r + 1;
end loop;
return result;
end str;
function str(b: boolean) return string is
begin
if b then
return "true";
else
return "false";
end if;
end str;
-- converts an integer into a character
-- for 0 to 9 the obvious mapping is used, higher
-- values are mapped to the characters A-Z
-- (this is usefull for systems with base > 10)
-- (adapted from Steve Vogwell's posting in comp.lang.vhdl)
function chr(int: integer) return character is
variable c: character;
begin
case int is
when 0 => c := '0';
when 1 => c := '1';
when 2 => c := '2';
when 3 => c := '3';
when 4 => c := '4';
when 5 => c := '5';
when 6 => c := '6';
when 7 => c := '7';
when 8 => c := '8';
when 9 => c := '9';
when 10 => c := 'A';
when 11 => c := 'B';
when 12 => c := 'C';
when 13 => c := 'D';
when 14 => c := 'E';
when 15 => c := 'F';
when 16 => c := 'G';
when 17 => c := 'H';
when 18 => c := 'I';
when 19 => c := 'J';
when 20 => c := 'K';
when 21 => c := 'L';
when 22 => c := 'M';
when 23 => c := 'N';
when 24 => c := 'O';
when 25 => c := 'P';
when 26 => c := 'Q';
when 27 => c := 'R';
when 28 => c := 'S';
when 29 => c := 'T';
when 30 => c := 'U';
when 31 => c := 'V';
when 32 => c := 'W';
when 33 => c := 'X';
when 34 => c := 'Y';
when 35 => c := 'Z';
when others => c := '?';
end case;
return c;
end chr;
-- convert integer to string using specified base
-- (adapted from Steve Vogwell's posting in comp.lang.vhdl)
function str(int: integer; base: integer) return string is
variable temp: string(1 to 10);
variable num: integer;
variable abs_int: integer;
variable len: integer := 1;
variable power: integer := 1;
begin
-- bug fix for negative numbers
abs_int := abs(int);
num := abs_int;
while num >= base loop -- Determine how many
len := len + 1; -- characters required
num := num / base; -- to represent the
end loop ; -- number.
for i in len downto 1 loop -- Convert the number to
temp(i) := chr(abs_int/power mod base); -- a string starting
power := power * base; -- with the right hand
end loop ; -- side.
-- return result and add sign if required
if int < 0 then
return '-'& temp(1 to len);
else
return temp(1 to len);
end if;
end str;
-- convert integer to string, using base 10
function str(int: integer) return string is
begin
return str(int, 10) ;
end str;
-- converts a std_logic_vector into a hex string.
function hstr(slv: std_logic_vector) return string is
variable hexlen: integer;
variable longslv : std_logic_vector(67 downto 0) := (others => '0');
variable hex : string(1 to 16);
variable fourbit : std_logic_vector(3 downto 0);
begin
hexlen := (slv'left+1)/4;
if (slv'left+1) mod 4 /= 0 then
hexlen := hexlen + 1;
end if;
longslv(slv'left downto 0) := slv;
for i in (hexlen -1) downto 0 loop
fourbit := longslv(((i*4)+3) downto (i*4));
case fourbit is
when "0000" => hex(hexlen -I) := '0';
when "0001" => hex(hexlen -I) := '1';
when "0010" => hex(hexlen -I) := '2';
when "0011" => hex(hexlen -I) := '3';
when "0100" => hex(hexlen -I) := '4';
when "0101" => hex(hexlen -I) := '5';
when "0110" => hex(hexlen -I) := '6';
when "0111" => hex(hexlen -I) := '7';
when "1000" => hex(hexlen -I) := '8';
when "1001" => hex(hexlen -I) := '9';
when "1010" => hex(hexlen -I) := 'A';
when "1011" => hex(hexlen -I) := 'B';
when "1100" => hex(hexlen -I) := 'C';
when "1101" => hex(hexlen -I) := 'D';
when "1110" => hex(hexlen -I) := 'E';
when "1111" => hex(hexlen -I) := 'F';
when "ZZZZ" => hex(hexlen -I) := 'z';
when "UUUU" => hex(hexlen -I) := 'u';
when "XXXX" => hex(hexlen -I) := 'x';
when others => hex(hexlen -I) := '?';
end case;
end loop;
return hex(1 to hexlen);
end hstr;
-- functions to manipulate strings
-----------------------------------
-- convert a character to upper case
function to_upper(c: character) return character is
variable u: character;
begin
case c is
when 'a' => u := 'A';
when 'b' => u := 'B';
when 'c' => u := 'C';
when 'd' => u := 'D';
when 'e' => u := 'E';
when 'f' => u := 'F';
when 'g' => u := 'G';
when 'h' => u := 'H';
when 'i' => u := 'I';
when 'j' => u := 'J';
when 'k' => u := 'K';
when 'l' => u := 'L';
when 'm' => u := 'M';
when 'n' => u := 'N';
when 'o' => u := 'O';
when 'p' => u := 'P';
when 'q' => u := 'Q';
when 'r' => u := 'R';
when 's' => u := 'S';
when 't' => u := 'T';
when 'u' => u := 'U';
when 'v' => u := 'V';
when 'w' => u := 'W';
when 'x' => u := 'X';
when 'y' => u := 'Y';
when 'z' => u := 'Z';
when others => u := c;
end case;
return u;
end to_upper;
-- convert a character to lower case
function to_lower(c: character) return character is
variable l: character;
begin
case c is
when 'A' => l := 'a';
when 'B' => l := 'b';
when 'C' => l := 'c';
when 'D' => l := 'd';
when 'E' => l := 'e';
when 'F' => l := 'f';
when 'G' => l := 'g';
when 'H' => l := 'h';
when 'I' => l := 'i';
when 'J' => l := 'j';
when 'K' => l := 'k';
when 'L' => l := 'l';
when 'M' => l := 'm';
when 'N' => l := 'n';
when 'O' => l := 'o';
when 'P' => l := 'p';
when 'Q' => l := 'q';
when 'R' => l := 'r';
when 'S' => l := 's';
when 'T' => l := 't';
when 'U' => l := 'u';
when 'V' => l := 'v';
when 'W' => l := 'w';
when 'X' => l := 'x';
when 'Y' => l := 'y';
when 'Z' => l := 'z';
when others => l := c;
end case;
return l;
end to_lower;
-- convert a string to upper case
function to_upper(s: string) return string is
variable uppercase: string (s'range);
begin
for i in s'range loop
uppercase(i):= to_upper(s(i));
end loop;
return uppercase;
end to_upper;
-- convert a string to lower case
function to_lower(s: string) return string is
variable lowercase: string (s'range);
begin
for i in s'range loop
lowercase(i):= to_lower(s(i));
end loop;
return lowercase;
end to_lower;
-- functions to convert strings into other types
-- converts a character into a std_logic
function to_std_logic(c: character) return std_logic is
variable sl: std_logic;
begin
case c is
when 'U' =>
sl := 'U';
when 'X' =>
sl := 'X';
when '0' =>
sl := '0';
when '1' =>
sl := '1';
when 'Z' =>
sl := 'Z';
when 'W' =>
sl := 'W';
when 'L' =>
sl := 'L';
when 'H' =>
sl := 'H';
when '-' =>
sl := '-';
when others =>
sl := 'X';
end case;
return sl;
end to_std_logic;
-- converts a string into std_logic_vector
function to_std_logic_vector(s: string) return std_logic_vector is
variable slv: std_logic_vector(s'high-s'low downto 0);
variable k: integer;
begin
k := s'high-s'low;
for i in s'range loop
slv(k) := to_std_logic(s(i));
k := k - 1;
end loop;
return slv;
end to_std_logic_vector;
----------------
-- file I/O --
----------------
-- read variable length string from input file
procedure str_read(file in_file: TEXT;
res_string: out string) is
variable l: line;
variable c: character;
variable is_string: boolean;
begin
readline(in_file, l);
-- clear the contents of the result string
for i in res_string'range loop
res_string(i) := ' ';
end loop;
-- read all characters of the line, up to the length
-- of the results string
for i in res_string'range loop
read(l, c, is_string);
res_string(i) := c;
if not is_string then -- found end of line
exit;
end if;
end loop;
end str_read;
-- print string to a file
procedure print(file out_file: TEXT;
new_string: in string) is
variable l: line;
begin
write(l, new_string);
writeline(out_file, l);
end print;
-- print character to a file and start new line
procedure print(file out_file: TEXT;
char: in character) is
variable l: line;
begin
write(l, char);
writeline(out_file, l);
end print;
-- appends contents of a string to a file until line feed occurs
-- (LF is considered to be the end of the string)
procedure str_write(file out_file: TEXT;
new_string: in string) is
begin
for i in new_string'range loop
print(out_file, new_string(i));
if new_string(i) = LF then -- end of string
exit;
end if;
end loop;
end str_write;
end txt_util;

View file

@ -0,0 +1,215 @@
[{
"ip_name" : "generic_sequencer",
"bus" : "csr",
"addr_width" : "4",
"description" : "Generic Sequencer core",
"registers" : {
"ip_id" : {
"address" : "0",
"width" : "32",
"description" : "Unique ID for this IP block",
"fields": {
"ip_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x01",
"description" : "IP identifier number"
},
"mfr_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0xFF",
"description" : "Manufacturer number"
},
"reserved" : {
"type" : "rsv",
"bit_len" : "16",
"description" : "Reserved bits"
}
}
},
"ip_ver" : {
"address" : "1",
"width" : "32",
"description" : "Bits[7:0] = Minor version number, Bits[15:8] = Major version number, etc.",
"fields": {
"minor_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x0F",
"description" : "Minor number"
},
"major_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x00",
"description" : "Major number"
},
"reserved" : {
"type" : "rsv",
"bit_len" : "16",
"description" : "Reserved bits"
}
}
},
"config" : {
"address" : "2",
"width" : "30",
"description" : "Configuration values for sequencer",
"fields": {
"seq_depth" : {
"type" : "r",
"bit_len" : "6",
"reset" : "0",
"description" : "LOG2 (+1?) of SEQ_DEPTH generic"
},
"pos_width" : {
"type" : "r",
"bit_len" : "6",
"reset" : "0",
"description" : "POS_WIDTH generic value"
},
"bus_width" : {
"type" : "r",
"bit_len" : "6",
"reset" : "0",
"description" : "BUS_WIDTH generic value"
},
"vector_width" : {
"type" : "r",
"bit_len" : "6",
"reset" : "0",
"description" : "VECTOR_WIDTH generic value"
},
"trigger_width" : {
"type" : "r",
"bit_len" : "6",
"reset" : "0",
"description" : "TRIGGER_WIDTH generic value"
}
}
},
"ctrl" : {
"address" : "3",
"width" : "5",
"description" : "Control register",
"fields": {
"seq_enable" : {
"type" : "w",
"bit_len" : "1",
"reset" : "0",
"description" : "Master enable for the sequencer"
},
"reserved" : {
"type" : "rsv",
"bit_len" : "1",
"description" : "Reserved bits"
},
"busy" : {
"type" : "wp",
"bit_len" : "1",
"reset" : "0",
"description" : "Busy status (writing has no effect---in this register for backwards compatibility)"
},
"debug_mode" : {
"type" : "w",
"bit_len" : "1",
"reset" : "0",
"description" : "Enter debug mode (only has effect if not busy)"
},
"rst_vector_out" : {
"type" : "w",
"bit_len" : "1",
"reset" : "0",
"description" : "Reset vector_out when start_req is asserted"
}
}
},
"pc" : {
"address" : "4",
"width" : "32",
"description" : "Configuration values for sequencer",
"fields": {
"ram_rd_addr" : {
"type" : "r",
"bit_len" : "16",
"reset" : "0",
"description" : "Current RAM read address"
},
"return_addr" : {
"type" : "r",
"bit_len" : "16",
"reset" : "0",
"description" : "Current return address"
}
}
},
"trigger" : {
"address" : "5",
"type" : "r",
"width" : "16",
"reset" : "0",
"description" : "Trigger input vector value"
},
"vector" : {
"address" : "6",
"type" : "wp",
"width" : "24",
"reset" : "0",
"description" : "Vector output override from CPU"
},
"r1" : {
"address" : "7",
"type" : "wp",
"width" : "12",
"reset" : "0",
"description" : "R1 register access. Writes only effective when idle."
},
"step" : {
"address" : "8",
"type" : "w0",
"width" : "1",
"reset" : "0",
"description" : "Step request from CPU"
},
"aux_config" : {
"address" : "9",
"width" : "5",
"description" : "Aux Configuration values for sequencer",
"fields": {
"ADD_VEC_PIPE" : {
"type" : "r",
"bit_len" : "1",
"reset" : "0",
"description" : "Add 1 level of pipeline on vector_out"
},
"VECT_RAMP_EN" : {
"type" : "r",
"bit_len" : "1",
"reset" : "0",
"description" : "Enable support for VEC_RAMP_UP/DN instructions"
},
"BUS_BURST_EN" : {
"type" : "r",
"bit_len" : "1",
"reset" : "0",
"description" : "Enable support for BUS_BURST instructions"
},
"POS_BUS_EN" : {
"type" : "r",
"bit_len" : "1",
"reset" : "0",
"description" : "Enable support for POS input bus"
},
"ALU_EN" : {
"type" : "r",
"bit_len" : "1",
"reset" : "0",
"description" : "Enable support for ALU instruction"
}
}
}
}
}]

View file

@ -0,0 +1,120 @@
##/////////////////////////////////////////////////////////////////////////////
## Title : Run Simulation script
##/////////////////////////////////////////////////////////////////////////////
## File : run_sim.py
## Author : Gianmarco Girau
## Company : GIS
## Target : Re-usable across multiple projects with minor customizations
## Dependency : none
##/////////////////////////////////////////////////////////////////////////////
## Description: Script for running in Jenkins custom ModelSim testbenches
##/////////////////////////////////////////////////////////////////////////////
## Last update: 2017-09-26
##/////////////////////////////////////////////////////////////////////////////
## Revisions :
## Date Version Author Description
## 2017-09-26 01.00.0a gmg Created
##/////////////////////////////////////////////////////////////////////////////
import os, sys, subprocess
##/////////////////////////////////////////////////////////////////////////////
## Check Simulation Results
##/////////////////////////////////////////////////////////////////////////////
def check_result(logfile):
searchfile = open(logfile, "r")
ok = 0
for line in searchfile:
if "SUCCESS" in line:
print("/////////////////////////////////////////////////////////////////////////////")
print('TEST SUCCESSFUL')
print("/////////////////////////////////////////////////////////////////////////////")
ok = 1
break
if "FAILURE" in line:
print("/////////////////////////////////////////////////////////////////////////////")
print('TEST FAILED')
print("/////////////////////////////////////////////////////////////////////////////")
break
searchfile.close()
if ok == 0:
sys.exit(1)
##/////////////////////////////////////////////////////////////////////////////
## Run Modelsim Simulation script
##/////////////////////////////////////////////////////////////////////////////
def run_msim_script(sim_job, cmd_line_mode = 1):
# create a copy of the do file, edit the copy as necessary
orig_do_file = "./{0}.do".format(sim_job)
print("/////////////////////////////////////////////////////////////////////////////")
print("Running {0} ...".format(orig_do_file))
print("/////////////////////////////////////////////////////////////////////////////")
if os.path.isfile(orig_do_file) == False:
print("ERROR: Cannot find do file " + orig_do_file)
sys.exit(1)
do_file = "./{0}_tmp.do".format(sim_job)
orig_do_file_cnt = open(orig_do_file , "r")
do_file_cnt = open(do_file, "w")
# Remove command ".main clear" in cmd line mode
for line in orig_do_file_cnt:
if cmd_line_mode == 1 and line.strip() == ".main clear":
do_file_cnt.write("#.main clear\n")
elif cmd_line_mode == 1 and line.find("do wave_") != -1:
do_file_cnt.write("#" + line)
else:
do_file_cnt.write(line)
# manually add commands to exit from modelsim at the end of simulation
if cmd_line_mode == 1:
do_file_cnt.write("\n")
do_file_cnt.write("quit -sim; quit -f\n")
orig_do_file_cnt.close()
do_file_cnt.close()
log_file = "./{0}.log".format(sim_job)
vsim_cmd = os.environ['QUARTUS_ROOTDIR']+"\\..\\modelsim_ase\\win32aloem\\vsim"
if cmd_line_mode == 1:
cmd_opt = "-c"
else:
cmd_opt = ""
sub_call = "{0} {1} -l {2} -do {3}".format(vsim_cmd, cmd_opt, log_file, do_file)
subprocess.call(sub_call)
'''
if cmd_line_mode == 1:
# Run in command line mode
subprocess.call([vsim_cmd, "-c", "-l", log_file, "-do", do_file])
else:
# Run in GUI mode
subprocess.call([os.environ['QUARTUS_ROOTDIR']+"\\..\\modelsim_ase\\win32aloem\\vsim",
"-do", do_file, "-l", log_file])
'''
# remove the local copy of the do file
os.remove(do_file)
check_result(log_file)
##/////////////////////////////////////////////////////////////////////////////
## Execute Simulation Scripts
##/////////////////////////////////////////////////////////////////////////////
if __name__ == "__main__":
print("Running Generic-Sequencer testbench ...")
run_msim_script("sim_gen_seq", cmd_line_mode=1)

View file

@ -0,0 +1,53 @@
# Simulation macro for print_ctrl
.main clear
set GEN_IP_PATH ../../
set COMMON_PATH $GEN_IP_PATH/common/0
set OSVVM_PATH $COMMON_PATH/src/test/OSVVM
set WORKLIB work
vlib ./work
vmap work ./work
# Compile the UUT
#vcom -2008 -work $WORKLIB $COMMON_PATH/src/pkg_functions.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/src/common_pkg.vhd
vcom -2008 -work $WORKLIB ../src/dpram_sclk.vhd
vcom -2008 -work $WORKLIB ../src/generic_seq_core.vhd
# Compile the constrained random related packages
vlib OSVVM
vcom -2008 -work OSVVM \
$OSVVM_PATH/RandomBasePkg.vhd \
$OSVVM_PATH/SortListPkg_int.vhd \
$OSVVM_PATH/RandomPkg.vhd \
$OSVVM_PATH/NamePkg.vhd \
$OSVVM_PATH/MessagePkg.vhd \
$OSVVM_PATH/CoveragePkg.vhd
# Compile support files
vcom -2008 -work $WORKLIB $COMMON_PATH/src/test/common_test_pkg.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/src/test/log_pkg.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/src/test/avalon_verify_pkg.vhd
# Compile the testbench
vcom -2008 -work $WORKLIB ./../src/test/generic_seq_core_tb.vhd
vsim -t ps work.generic_seq_core_tb
#add wave /generic_seq_core_tb/*
#add wave /generic_seq_core_tb/iUUT/*
# remove warnings from standard numeric/arithmetic packages (speed-up simulation)
set StdArithNoWarnings 1
set NumericStdNoWarnings 1
do wave_gen_seq.do
when -label end_of_simulation {test_completed == true} {echo "Simulation Completed"; stop ;}
run -all
#run 100 us;

View file

@ -0,0 +1,137 @@
onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate /generic_seq_core_tb/clk
add wave -noupdate /generic_seq_core_tb/reset_n
add wave -noupdate /generic_seq_core_tb/avs_csr_address
add wave -noupdate /generic_seq_core_tb/avs_csr_write
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/avs_csr_writedata
add wave -noupdate /generic_seq_core_tb/avs_csr_read
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/avs_csr_readdata
add wave -noupdate /generic_seq_core_tb/avs_seq_address
add wave -noupdate /generic_seq_core_tb/avs_seq_write
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/avs_seq_writedata
add wave -noupdate /generic_seq_core_tb/avs_seq_read
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/avs_seq_readdata
add wave -noupdate /generic_seq_core_tb/start_req
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/start_addr
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/trigger_in
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/pos_in
add wave -noupdate /generic_seq_core_tb/busy
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/vector_out
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/bus_data
add wave -noupdate /generic_seq_core_tb/bus_valid
add wave -noupdate /generic_seq_core_tb/bus_ack
add wave -noupdate /generic_seq_core_tb/setup
add wave -noupdate /generic_seq_core_tb/running
add wave -noupdate /generic_seq_core_tb/passed
add wave -noupdate /generic_seq_core_tb/failed
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/csr_mm_s_rec
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/csr_mm_m_rec
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/seq_mm_s_rec
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/seq_mm_m_rec
add wave -noupdate -divider UUT
add wave -noupdate /generic_seq_core_tb/iUUT/clk
add wave -noupdate /generic_seq_core_tb/iUUT/reset_n
add wave -noupdate -radix unsigned /generic_seq_core_tb/iUUT/avs_csr_address
add wave -noupdate /generic_seq_core_tb/iUUT/avs_csr_write
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/avs_csr_writedata
add wave -noupdate /generic_seq_core_tb/iUUT/avs_csr_read
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/avs_csr_readdata
add wave -noupdate -radix decimal /generic_seq_core_tb/iUUT/avs_seq_address
add wave -noupdate /generic_seq_core_tb/iUUT/avs_seq_write
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/avs_seq_writedata
add wave -noupdate /generic_seq_core_tb/iUUT/avs_seq_read
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/avs_seq_readdata
add wave -noupdate /generic_seq_core_tb/iUUT/start_req
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/start_addr
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/trigger_in
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/pos_in
add wave -noupdate /generic_seq_core_tb/iUUT/busy
add wave -noupdate /generic_seq_core_tb/iUUT/opcode
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/vector_out
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/bus_data
add wave -noupdate /generic_seq_core_tb/iUUT/bus_valid
add wave -noupdate /generic_seq_core_tb/iUUT/bus_ack
add wave -noupdate /generic_seq_core_tb/iUUT/seq_enable
add wave -noupdate /generic_seq_core_tb/iUUT/debug_mode
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/return_addr
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/ram_rd_addr
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/ram_rd_data
add wave -noupdate /generic_seq_core_tb/iUUT/fsm
add wave -noupdate /generic_seq_core_tb/iUUT/fsm_nxt
add wave -noupdate /generic_seq_core_tb/iUUT/fetch_enable
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/operand_1
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/operand_2
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/operand_comp
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/subcode
add wave -noupdate /generic_seq_core_tb/iUUT/inc_ram_addr
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/jump_addr_ext
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/jump_addr
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/pc_value
add wave -noupdate /generic_seq_core_tb/iUUT/ld_jmp_addr
add wave -noupdate /generic_seq_core_tb/iUUT/jump_abs
add wave -noupdate /generic_seq_core_tb/iUUT/jump_rel
add wave -noupdate /generic_seq_core_tb/iUUT/alu_upd
add wave -noupdate /generic_seq_core_tb/iUUT/jump_r1
add wave -noupdate /generic_seq_core_tb/iUUT/loop_active
add wave -noupdate /generic_seq_core_tb/iUUT/loop_upd
add wave -noupdate /generic_seq_core_tb/iUUT/loop_done
add wave -noupdate -radix unsigned /generic_seq_core_tb/iUUT/loop_cnt
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/r1
add wave -noupdate /generic_seq_core_tb/iUUT/flag
add wave -noupdate /generic_seq_core_tb/iUUT/ld_trig_mask
add wave -noupdate /generic_seq_core_tb/iUUT/ld_trig_sel
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/trig_mask
add wave -noupdate /generic_seq_core_tb/iUUT/trig_sel
add wave -noupdate /generic_seq_core_tb/iUUT/trig_int
add wave -noupdate /generic_seq_core_tb/iUUT/ld_vec
add wave -noupdate /generic_seq_core_tb/iUUT/clr_vec_i
add wave -noupdate /generic_seq_core_tb/iUUT/clr_vec
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/vector_out_i
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/vector_out
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/ramp_val
add wave -noupdate /generic_seq_core_tb/iUUT/ramp_up
add wave -noupdate /generic_seq_core_tb/iUUT/fetch_op
add wave -noupdate /generic_seq_core_tb/iUUT/clr_vec_ii
add wave -noupdate /generic_seq_core_tb/iUUT/op_cnt
add wave -noupdate /generic_seq_core_tb/iUUT/op_cnt_done
add wave -noupdate /generic_seq_core_tb/iUUT/inc_op_cnt
add wave -noupdate /generic_seq_core_tb/iUUT/bus_ack
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/bus_data
add wave -noupdate /generic_seq_core_tb/iUUT/bus_valid
add wave -noupdate /generic_seq_core_tb/iUUT/bus_valid_i
add wave -noupdate /generic_seq_core_tb/iUUT/bus_pause
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/pos_store
add wave -noupdate /generic_seq_core_tb/iUUT/loop_active
add wave -noupdate /generic_seq_core_tb/iUUT/vector_val_cpu
add wave -noupdate -radix hexadecimal /generic_seq_core_tb/iUUT/vector_cpu
add wave -noupdate /generic_seq_core_tb/iUUT/step_req
add wave -noupdate /generic_seq_core_tb/iUUT/rst_vector_out
add wave -noupdate /generic_seq_core_tb/iUUT/pos_target
add wave -noupdate /generic_seq_core_tb/iUUT/ld_ret_addr
add wave -noupdate /generic_seq_core_tb/iUUT/save_ret_addr
add wave -noupdate /generic_seq_core_tb/iUUT/r1_data
add wave -noupdate /generic_seq_core_tb/iUUT/r1_data_valid
add wave -noupdate /generic_seq_core_tb/iUUT/decode
add wave -noupdate /generic_seq_core_tb/iUUT/busy_i
add wave -noupdate /generic_seq_core_tb/iUUT/ld_start_addr
add wave -noupdate /generic_seq_core_tb/iUUT/ld_pos
add wave -noupdate /generic_seq_core_tb/iUUT/flag
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {25065000 ps} 0}
quietly wave cursor active 1
configure wave -namecolwidth 283
configure wave -valuecolwidth 194
configure wave -justifyvalue left
configure wave -signalnamewidth 0
configure wave -snapdistance 10
configure wave -datasetprefix 0
configure wave -rowmargin 4
configure wave -childrowmargin 2
configure wave -gridoffset 0
configure wave -gridperiod 1
configure wave -griddelta 40
configure wave -timeline 0
configure wave -timelineunits ps
update
WaveRestoreZoom {19215784 ps} {26657064 ps}

View file

@ -0,0 +1,74 @@
-------------------------------------------------------------------------------
-- Title : dpram_sclk
-- Project : Dual-Port, single clock RAM
-------------------------------------------------------------------------------
-- File : dpram_sclk.vhd
-- Author : GMG
-- Company : Global Inkjet Systems
-- Created : 2018-04-24
-- Last update: 2018-04-24
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- True Dual-Port, single clock RAM
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.common_pkg.all;
entity dpram_sclk_0 is
generic(
WIDTH : natural := 32;
DEPTH : natural := 256);
port(
clk : in std_logic;
-- Port-A
addr_a : in std_logic_vector(log2(DEPTH)-1 downto 0);
we_a : in std_logic := '1';
data_a : in std_logic_vector(WIDTH-1 downto 0);
q_a : out std_logic_vector(WIDTH-1 downto 0);
-- Port-B
addr_b : in std_logic_vector(log2(DEPTH)-1 downto 0);
we_b : in std_logic := '1';
data_b : in std_logic_vector(WIDTH-1 downto 0);
q_b : out std_logic_vector(WIDTH-1 downto 0));
end dpram_sclk_0;
architecture rtl of dpram_sclk_0 is
-- Build a 2-D array type for the RAM
subtype word_t is std_logic_vector(WIDTH-1 downto 0);
type memory_t is array(DEPTH-1 downto 0) of word_t;
-- Declare the RAM
shared variable ram : memory_t;
begin
-- Port A
pPORT_A : process(clk)
begin
if(clk = '1' and clk'event) then
if(we_a = '1') then
ram(to_integer(unsigned(addr_a))) := data_a;
end if;
q_a <= ram(to_integer(unsigned(addr_a)));
end if;
end process pPORT_A;
-- Port B
pPORT_B : process(clk)
begin
if(clk = '1' and clk'event) then
if(we_b = '1') then
ram(to_integer(unsigned(addr_b))) := data_b;
end if;
q_b <= ram(to_integer(unsigned(addr_b)));
end if;
end process pPORT_B;
end rtl;

View file

@ -0,0 +1,709 @@
-------------------------------------------------------------------------------
-- Title : generic_seq_core
-- Project : Generic Components
-------------------------------------------------------------------------------
-- File : generic_seq_core.vhd
-- Author : Robbie Temple (original)
-- Company : Global Inkjet Systems
-- Created : 2016-05-12
-- Last update: 2018-08-06
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Generic Sequencer core
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.common_pkg.all;
entity generic_seq_core_0 is
generic(
TRIGGER_WIDTH : natural range 1 to 16 := 16;
VECTOR_WIDTH : natural range 1 to 24 := 12;
BUS_WIDTH : natural range 1 to 32 := 12;
POS_WIDTH : natural range 1 to 24 := 12;
SEQ_DEPTH : natural range 256 to 4096 := 256;
ADD_VEC_PIPE : boolean := false; -- Add a pipeline register on vector_out
VECT_RAMP_EN : boolean := false;
BUS_BURST_EN : boolean := false;
POS_BUS_EN : boolean := false;
ALU_EN : boolean := false);
port(
--
clk : in std_logic;
reset_n : in std_logic;
--
avs_csr_address : in std_logic_vector(3 downto 0);
avs_csr_write : in std_logic;
avs_csr_writedata : in std_logic_vector(31 downto 0);
avs_csr_read : in std_logic;
avs_csr_readdata : out std_logic_vector(31 downto 0) := (others => '0');
--
avs_seq_address : in std_logic_vector(log2(SEQ_DEPTH)-1 downto 0);
avs_seq_write : in std_logic;
avs_seq_writedata : in std_logic_vector(31 downto 0);
avs_seq_read : in std_logic;
avs_seq_readdata : out std_logic_vector(31 downto 0) := (others => '0');
--
start_req : in std_logic;
start_addr : in std_logic_vector(log2(SEQ_DEPTH)-1 downto 0);
--
trigger_in : in std_logic_vector(TRIGGER_WIDTH-1 downto 0);
pos_in : in std_logic_vector(POS_WIDTH-1 downto 0);
--
busy : out std_logic;
--
vector_out : out std_logic_vector(VECTOR_WIDTH-1 downto 0);
--
bus_data : out std_logic_vector(BUS_WIDTH-1 downto 0);
bus_valid : out std_logic;
bus_ack : in std_logic);
end entity generic_seq_core_0;
architecture rtl of generic_seq_core_0 is
-----------------------------------------------------------------------------
-- Constant and types
-----------------------------------------------------------------------------
constant CSR_IP_ID : std_logic_vector(31 downto 0) := x"0000FF01";
constant CSR_IP_VER : std_logic_vector(31 downto 0) := x"0000000F";
constant CSR_IP_ID_ADDR : std_logic_vector(3 downto 0) := x"0";
constant CSR_IP_VER_ADDR : std_logic_vector(3 downto 0) := x"1";
constant CSR_CONFIG_ADDR : std_logic_vector(3 downto 0) := x"2";
constant CSR_CTRL_ADDR : std_logic_vector(3 downto 0) := x"3";
constant CSR_PC_ADDR : std_logic_vector(3 downto 0) := x"4";
constant CSR_TRIGGER_ADDR : std_logic_vector(3 downto 0) := x"5";
constant CSR_VECTOR_ADDR : std_logic_vector(3 downto 0) := x"6";
constant CSR_R1_ADDR : std_logic_vector(3 downto 0) := x"7"; -- write only works when sequencer idle
constant CSR_STEP_ADDR : std_logic_vector(3 downto 0) := x"8";
constant CSR_AUX_CONFIG_ADDR : std_logic_vector(3 downto 0) := x"9";
constant CMD_NOP : std_logic_vector(3 downto 0) := x"0";
constant CMD_TRIG_MASK : std_logic_vector(3 downto 0) := x"1";
constant CMD_TRIG_WAIT : std_logic_vector(3 downto 0) := x"2";
constant CMD_VEC_SET : std_logic_vector(3 downto 0) := x"3";
constant CMD_VEC_RAMP_UP : std_logic_vector(3 downto 0) := x"4";
constant CMD_VEC_RAMP_DN : std_logic_vector(3 downto 0) := x"5";
constant CMD_BUS_BURST : std_logic_vector(3 downto 0) := x"6";
constant CMD_POS_STORE : std_logic_vector(3 downto 0) := x"7";
constant CMD_POS_WAIT : std_logic_vector(3 downto 0) := x"8";
--
constant CMD_ALU : std_logic_vector(3 downto 0) := x"A";
--
constant CMD_LOOP : std_logic_vector(3 downto 0) := x"B";
constant CMD_JUMP : std_logic_vector(3 downto 0) := x"C";
constant CMD_BRANCH : std_logic_vector(3 downto 0) := x"D";
constant CMD_RETURN : std_logic_vector(3 downto 0) := x"E";
constant CMD_END : std_logic_vector(3 downto 0) := x"F";
type fsm_t is (s_idle, s_init, s_fetch, s_decode,
--
s_trig_mask, s_trig_wait,
s_vec_set, s_vec_ramp,
s_bus_burst, s_bus_data,
s_pos_store, s_pos_wait,
--
s_alu,
--
s_loop, s_jump, s_branch, s_return,
--
s_end);
-----------------------------------------------------------------------------
-- Signals
-----------------------------------------------------------------------------
signal fsm, fsm_nxt : fsm_t;
signal seq_cfg_aux : std_logic_vector(31 downto 0) := 32x"0";
signal seq_enable : std_logic;
signal rst_vector_out : std_logic;
signal debug_mode : std_logic;
signal ram_rd_addr : std_logic_vector(log2(SEQ_DEPTH)-1 downto 0);
signal ram_rd_data : std_logic_vector(31 downto 0);
signal operand_1 : std_logic_vector(11 downto 0);
signal operand_2 : std_logic_vector(11 downto 0);
signal operand_comp : std_logic_vector(23 downto 0);
signal opcode : std_logic_vector( 3 downto 0);
signal subcode : std_logic_vector( 3 downto 0);
signal jump_addr_ext : std_logic_vector(11 downto 0);
signal jump_addr : std_logic_vector(log2(SEQ_DEPTH)-1 downto 0);
signal pc_value : std_logic_vector(log2(SEQ_DEPTH)-1 downto 0);
signal pos_store : std_logic_vector(POS_WIDTH - 1 downto 0);
signal pos_target : std_logic_vector(POS_WIDTH - 1 downto 0);
signal trig_mask : std_logic_vector(TRIGGER_WIDTH - 1 downto 0);
signal trig_sel : std_logic_vector(3 downto 0);
signal trig_int : std_logic;
signal vector_out_i : std_logic_vector(VECTOR_WIDTH-1 downto 0);
signal ramp_val : std_logic_vector(VECTOR_WIDTH-1 downto 0);
signal op_cnt : std_logic_vector(11 downto 0);
signal loop_cnt : std_logic_vector(11 downto 0);
signal return_addr : std_logic_vector(log2(SEQ_DEPTH)-1 downto 0);
signal r1, r1_data : std_logic_vector(11 downto 0);
signal r1_data_valid : std_logic; -- strobe to cause R1 to be updated with R1_data value
signal decode, clr_vec, ld_vec : std_logic;
signal bus_valid_i, busy_i : std_logic;
signal ld_start_addr, inc_ram_addr : std_logic;
signal ld_trig_mask, ld_trig_sel : std_logic;
signal ld_pos : std_logic;
signal flag, alu_upd : std_logic;
signal clr_vec_i, clr_vec_ii : std_logic;
signal fetch_op, ramp_up : std_logic;
signal op_cnt_done, inc_op_cnt : std_logic;
signal bus_pause, ld_jmp_addr : std_logic;
signal jump_abs, jump_rel, jump_r1 : std_logic;
signal ld_ret_addr, save_ret_addr : std_logic;
signal loop_active, loop_upd : std_logic;
signal loop_done : std_logic;
signal start_req_d, start_req_i : std_logic;
signal vector_val_cpu : std_logic;
signal vector_cpu : std_logic_vector(VECTOR_WIDTH - 1 downto 0);
signal step_req : std_logic;
signal fetch_enable : std_logic;
begin
-----------------------------------------------------------------------------
-- Control & Status Registers
-----------------------------------------------------------------------------
--
-- The process manages the Control and Status registers
--
AVS_PROC : process(clk, reset_n) is
begin
if reset_n = '0' then
avs_csr_readdata <= (others => '0');
seq_enable <= '0';
rst_vector_out <= '0';
debug_mode <= '0';
vector_val_cpu <= '0';
vector_cpu <= (others => '0');
step_req <= '0';
elsif clk'event and clk = '1' then
--
avs_csr_readdata <= (others => '0');
vector_val_cpu <= '0';
step_req <= '0';
if(ALU_EN = true) then
if(busy_i = '0') then
r1_data_valid <= '0';
end if;
end if;
if avs_csr_write = '1' then
case avs_csr_address is
when CSR_CTRL_ADDR =>
seq_enable <= avs_csr_writedata(0);
rst_vector_out <= avs_csr_writedata(4);
if fsm = s_idle then
debug_mode <= avs_csr_writedata(3);
end if;
when CSR_VECTOR_ADDR =>
if fsm = s_idle then
vector_val_cpu <= '1';
vector_cpu <= avs_csr_writedata(VECTOR_WIDTH - 1 downto 0);
end if;
when CSR_STEP_ADDR =>
step_req <= '1';
when CSR_R1_ADDR =>
if(ALU_EN = true) then
r1_data <= avs_csr_writedata(R1_data'range);
r1_data_valid <= '1';
end if;
when others => null;
end case;
elsif avs_csr_read = '1' then
case avs_csr_address is
when CSR_IP_ID_ADDR =>
avs_csr_readdata <= CSR_IP_ID;
when CSR_IP_VER_ADDR =>
avs_csr_readdata <= CSR_IP_VER;
when CSR_CONFIG_ADDR =>
avs_csr_readdata <= "00" & std_logic_vector(to_unsigned(TRIGGER_WIDTH, 6)) & std_logic_vector(to_unsigned(VECTOR_WIDTH, 6)) & std_logic_vector(to_unsigned(BUS_WIDTH, 6)) & std_logic_vector(to_unsigned(POS_WIDTH, 6)) & std_logic_vector(to_unsigned(log2(SEQ_DEPTH), 6));
when CSR_CTRL_ADDR =>
avs_csr_readdata <= 27x"0" & rst_vector_out & debug_mode & busy & '0' & seq_enable;
when CSR_PC_ADDR =>
avs_csr_readdata(log2(SEQ_DEPTH)-1+ 16 downto 16) <= return_addr;
avs_csr_readdata(log2(SEQ_DEPTH)-1 downto 0) <= pc_value;
when CSR_TRIGGER_ADDR =>
avs_csr_readdata(TRIGGER_WIDTH - 1 downto 0) <= trigger_in;
when CSR_VECTOR_ADDR =>
avs_csr_readdata(VECTOR_WIDTH - 1 downto 0) <= vector_out;
when CSR_R1_ADDR =>
avs_csr_readdata(11 downto 0) <= r1;
when CSR_AUX_CONFIG_ADDR =>
avs_csr_readdata <= seq_cfg_aux;
when others => null;
end case;
end if;
end if;
end process AVS_PROC;
seq_cfg_aux(0) <= '1' when ADD_VEC_PIPE = true else '0';
seq_cfg_aux(1) <= '1' when VECT_RAMP_EN = true else '0';
seq_cfg_aux(2) <= '1' when BUS_BURST_EN = true else '0';
seq_cfg_aux(3) <= '1' when POS_BUS_EN = true else '0';
seq_cfg_aux(4) <= '1' when ALU_EN = true else '0';
trig_int <= trigger_in(to_integer(unsigned(trig_sel))) and trig_mask(to_integer(unsigned(trig_sel)));
-----------------------------------------------------------------------------
-- Dual-Port Memory buffer
-----------------------------------------------------------------------------
iRAM: entity work.dpram_sclk_0
generic map (
WIDTH => 32,
DEPTH => SEQ_DEPTH)
port map (
clk => clk,
addr_a => avs_seq_address,
we_a => avs_seq_write,
data_a => avs_seq_writedata,
q_a => avs_seq_readdata,
addr_b => ram_rd_addr,
we_b => '0',
data_b => (others => '0'),
q_b => ram_rd_data);
-----------------------------------------------------------------------------
-- Sequencer Logic
-----------------------------------------------------------------------------
opcode <= ram_rd_data(31 downto 28);
start_req_i <= start_req and not start_req_d;
-- FSM Status Register
pFSM_SR : process(reset_n, clk)
begin
if(reset_n = '0') then
fsm <= s_idle;
elsif(clk = '1' and clk'event) then
fsm <= fsm_nxt;
end if;
end process pFSM_SR;
-- FSM combinational logic
pFSM_CL : process(all)
begin
-- Default assignments
fsm_nxt <= fsm;
--
decode <= '0';
clr_vec_i <= '0';
ld_vec <= '0';
busy_i <= '1';
ld_start_addr <= '0';
inc_ram_addr <= '0';
fetch_op <= '0';
ld_trig_mask <= '0';
inc_op_cnt <= '0';
loop_upd <= '0';
if(BUS_BURST_EN = true) then
bus_valid_i <= '0';
end if;
if(ALU_EN = true) then
alu_upd <= '0';
end if;
if(POS_BUS_EN = true) then
ld_pos <= '0';
end if;
-- Determine next state
if(seq_enable = '0') then
busy_i <= '0';
if(rst_vector_out = '1') then
clr_vec_i <= '1';
end if;
fsm_nxt <= s_idle;
elsif(start_req_i = '1') then
busy_i <= '0';
ld_start_addr <= '1';
fsm_nxt <= s_init;
else
case fsm is
when s_idle =>
busy_i <= '0';
if seq_enable = '1' and start_req_i = '1' then
ld_start_addr <= '1';
fsm_nxt <= s_init;
end if;
when s_init =>
if(rst_vector_out = '1') then
clr_vec_i <= '1';
end if;
fsm_nxt <= s_fetch;
when s_fetch =>
if(fetch_enable = '1') then
inc_ram_addr <= '1';
fetch_op <= '1';
fsm_nxt <= s_decode;
end if;
when s_return =>
fsm_nxt <= s_fetch;
when s_decode =>
decode <= '1';
case opcode is
--
when CMD_NOP => fsm_nxt <= s_fetch;
--
when CMD_TRIG_MASK => fsm_nxt <= s_trig_mask;
when CMD_TRIG_WAIT => fsm_nxt <= s_trig_wait;
when CMD_VEC_SET => fsm_nxt <= s_vec_set;
when CMD_VEC_RAMP_UP => fsm_nxt <= s_vec_ramp;
when CMD_VEC_RAMP_DN => fsm_nxt <= s_vec_ramp;
when CMD_BUS_BURST => fsm_nxt <= s_bus_burst;
when CMD_POS_STORE => fsm_nxt <= s_pos_store;
when CMD_POS_WAIT => fsm_nxt <= s_pos_wait;
when CMD_ALU => fsm_nxt <= s_alu;
when CMD_LOOP => fsm_nxt <= s_loop;
when CMD_JUMP => fsm_nxt <= s_jump;
when CMD_BRANCH => fsm_nxt <= s_branch;
when CMD_RETURN => fsm_nxt <= s_return;
when CMD_END => fsm_nxt <= s_end;
when others => null;
end case;
when s_trig_mask =>
ld_trig_mask <= '1';
fsm_nxt <= s_fetch;
when s_trig_wait =>
if(trig_int = '1') then
inc_op_cnt <= '1';
end if;
if(op_cnt_done = '1') then
fsm_nxt <= s_fetch;
end if;
when s_vec_set =>
ld_vec <= '1';
fsm_nxt <= s_fetch;
when s_vec_ramp =>
if(VECT_RAMP_EN = false) then
fsm_nxt <= s_fetch;
else
if(trig_int = '1') then
inc_op_cnt <= '1';
if(op_cnt_done = '1') then
fsm_nxt <= s_fetch;
end if;
end if;
end if;
when s_bus_burst =>
if(BUS_BURST_EN = true) then
if(op_cnt_done = '1') then
fsm_nxt <= s_fetch;
elsif(bus_ack = '1' and bus_pause = '0') then
inc_ram_addr <= '1';
inc_op_cnt <= '1';
bus_valid_i <= '1';
end if;
else
fsm_nxt <= s_fetch;
end if;
when s_pos_store =>
if(POS_BUS_EN = true) then
ld_pos <= '1';
end if;
fsm_nxt <= s_fetch;
when s_pos_wait =>
if(pos_in = pos_target) then
fsm_nxt <= s_fetch;
end if;
when s_alu =>
if(ALU_EN = true) then
alu_upd <= '1';
end if;
fsm_nxt <= s_fetch;
when s_jump | s_branch =>
fsm_nxt <= s_fetch;
when s_loop =>
loop_upd <= '1';
fsm_nxt <= s_fetch;
when s_end =>
fsm_nxt <= s_idle;
when others => null;
end case;
end if;
end process pFSM_CL;
ld_trig_sel <= '1' when decode = '1' and opcode /= CMD_JUMP else '0';
--
pSEQ_REGs : process(reset_n, clk)
begin
if (reset_n = '0') then
vector_out_i <= (others => '0');
elsif(clk = '1' and clk'event) then
start_req_d <= start_req;
fetch_enable <= (not debug_mode) or (debug_mode and step_req);
if(fetch_op = '1') then
pc_value <= ram_rd_addr;
end if;
if(fetch_op = '1') then
operand_comp <= ram_rd_data(23 downto 0);
subcode <= ram_rd_data(27 downto 24);
end if;
busy <= busy_i;
if(ld_start_addr = '1') then
ram_rd_addr <= start_addr;
elsif(ld_jmp_addr = '1') then
ram_rd_addr <= jump_addr;
elsif(ld_ret_addr = '1') then
ram_rd_addr <= return_addr;
elsif(inc_ram_addr = '1') then
ram_rd_addr <= std_logic_vector(unsigned(ram_rd_addr)+1);
end if;
if(ld_trig_mask = '1') then
trig_mask <= operand_comp(TRIGGER_WIDTH - 1 downto 0);
end if;
if(ld_trig_sel = '1') then
trig_sel <= subcode;
end if;
if(ld_vec = '1' and subcode = "0001") then
clr_vec_ii <= '1';
else
clr_vec_ii <= '0';
end if;
if(clr_vec = '1') then
vector_out_i <= (others => '0');
elsif(ld_vec = '1') then
vector_out_i <= operand_comp(VECTOR_WIDTH-1 downto 0);
elsif(VECT_RAMP_EN = true and inc_op_cnt = '1') then
if ramp_up = '1' and ramp_val(ramp_val'high) = '0' and vector_out_i(vector_out_i'high) = '1' then
vector_out_i <= (others => '1');
elsif ramp_up = '0' and ramp_val(ramp_val'high) = '1' and vector_out_i(vector_out_i'high) = '0' then
vector_out_i <= (others => '0');
else
vector_out_i <= ramp_val;
end if;
elsif(vector_val_cpu = '1') then
vector_out_i <=vector_cpu;
end if;
if(save_ret_addr = '1') then
return_addr <= ram_rd_addr;
end if;
if(decode = '1') then
op_cnt <= (others => '0');
elsif(inc_op_cnt = '1') then
op_cnt <= std_logic_vector(unsigned(op_cnt)+1);
end if;
if(start_req_i = '1' or (loop_done = '1' and loop_upd = '1')) then
loop_active <= '0';
elsif(decode = '1' and opcode = CMD_LOOP) then
loop_active <= '1';
end if;
if(loop_active = '0' and opcode = CMD_LOOP) then
loop_cnt <= (others => '0');
elsif(loop_upd = '1') then
loop_cnt <= std_logic_vector(unsigned(loop_cnt)+1);
end if;
end if;
end process pSEQ_REGs;
loop_done <= '1' when unsigned(loop_cnt) = unsigned(operand_2) else '0';
operand_1 <= operand_comp(11 downto 0);
operand_2 <= operand_comp(23 downto 12);
clr_vec <= clr_vec_i or clr_vec_ii;
op_cnt_done <= '1' when op_cnt = operand_1 else '0';
jump_addr_ext <= operand_1 when jump_abs = '1' else
std_logic_vector(signed('0' & ram_rd_addr)+signed(operand_1)-1) when jump_rel = '1' else
r1;
jump_addr <= jump_addr_ext(jump_addr'range);
ld_jmp_addr <= '1' when decode = '1' and (jump_abs = '1' or jump_rel = '1' or jump_r1 = '1') else '0';
jump_abs <= '1' when opcode = CMD_JUMP and (subcode = X"0" or (subcode = X"1" and flag = '0') or (subcode = X"2" and flag = '1')) else '0';
jump_rel <= '1' when (opcode = CMD_BRANCH and (subcode = X"0" or (subcode = X"1" and flag = '0') or (subcode = X"2" and flag = '1'))) or (opcode = CMD_LOOP and loop_done = '0') else '0';
jump_r1 <= '1' when opcode = CMD_JUMP and subcode = X"F" else '0';
save_ret_addr <= ld_jmp_addr;
ld_ret_addr <= '1' when decode = '1' and (opcode = CMD_RETURN) else '0';
-----------------------------------------------------------------------------
-- Others - Generics dependent
-----------------------------------------------------------------------------
gVECT_NO_PIPE: if ADD_VEC_PIPE = false generate
vector_out <= vector_out_i;
end generate gVECT_NO_PIPE;
gVECT_PIPE: if ADD_VEC_PIPE = true generate
pVECT_PIPE : process(clk)
begin
if(clk = '1' and clk'event) then
vector_out <= vector_out_i;
end if;
end process pVECT_PIPE;
end generate gVECT_PIPE;
gRAMP_GEN: if VECT_RAMP_EN = true generate
ramp_val <= std_logic_vector(unsigned(vector_out_i) + unsigned(operand_2)) when ramp_up = '1' else
std_logic_vector(unsigned(vector_out_i) - unsigned(operand_2));
pRAMP_REGs : process(clk)
begin
if(clk = '1' and clk'event) then
if(decode = '1') then
if(opcode = CMD_VEC_RAMP_UP) then
ramp_up <= '1';
else
ramp_up <= '0';
end if;
end if;
end if;
end process pRAMP_REGs;
end generate gRAMP_GEN;
gRAMP_NOGEN: if VECT_RAMP_EN = false generate
ramp_val <= (others => '0');
end generate gRAMP_NOGEN;
gBUS_BURST_GEN: if BUS_BURST_EN = true generate
pBURST_REGs : process(clk)
begin
if(clk = '1' and clk'event) then
bus_valid <= bus_valid_i;
bus_pause <= bus_valid_i;
if(seq_enable = '0') then
bus_data <= (others => '0');
elsif(bus_valid_i = '1') then
bus_data <= ram_rd_data(BUS_WIDTH-1 downto 0);
end if;
end if;
end process pBURST_REGs;
end generate gBUS_BURST_GEN;
gBUS_BURST_NOGEN: if BUS_BURST_EN = false generate
bus_valid <= '0';
bus_pause <= '0';
bus_data <= (others => '0');
end generate gBUS_BURST_NOGEN;
gPOS_GEN: if POS_BUS_EN = true generate
pPOS_REGs : process(clk)
begin
if(clk = '1' and clk'event) then
if(ld_pos = '1') then
pos_store <= pos_in;
end if;
if(decode = '1') then
case subcode is
when X"0" =>
pos_target <= operand_comp(pos_in'range);
when X"1" =>
pos_target <= std_logic_vector(signed(pos_in) + signed(operand_comp(pos_in'range)));
when X"2" =>
pos_target <= pos_store;
when X"3" =>
pos_target <= std_logic_vector(signed(pos_store) + signed(operand_comp(pos_in'range)));
when others => null;
end case;
end if;
end if;
end process pPOS_REGs;
end generate gPOS_GEN;
gALU_GEN: if ALU_EN = true generate
pALU_REGs : process(clk)
begin
if(clk = '1' and clk'event) then
-- Update ALU register R1
if(busy_i = '0' and r1_data_valid = '1') then
r1 <= R1_data;
elsif(alu_upd = '1') then
case subcode is
when x"2" =>
r1 <= operand_1;
when x"3" =>
r1 <= std_logic_vector(signed(r1) + signed(operand_1));
when x"4" =>
r1 <= std_logic_vector(signed(r1) - signed(operand_1));
when others => null;
end case;
end if;
-- Update ALU flag
if(alu_upd = '1') then
case subcode is
when x"0" =>
if((trigger_in(TRIGGER_WIDTH-1 downto 0) and trig_mask(TRIGGER_WIDTH-1 downto 0)) = (operand_comp(TRIGGER_WIDTH-1 downto 0) and trig_mask(TRIGGER_WIDTH-1 downto 0))) then
flag <= '1';
else
flag <= '0';
end if;
when x"1" | x"3" | x"4" =>
if(r1 = operand_1) then
flag <= '1';
else
flag <= '0';
end if;
when x"2" =>
if(unsigned(operand_1) = 0) then
flag <= '1';
else
flag <= '0';
end if;
when others => null;
end case;
end if;
end if;
end process pALU_REGs;
end generate gALU_GEN;
gALU_NOGEN: if ALU_EN = false generate
r1 <= (others => '0');
flag <= '0';
end generate gALU_NOGEN;
end rtl;

File diff suppressed because it is too large Load diff