diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0be0f35 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*/wave +*/work diff --git a/README.md b/README.md index f8f44a3..2511c3c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This repository is the public part of the thesis work created by Adam Magnusson and Erik Örtenberg at Chalmers Univerity of Technology. The work contained wihtin this repo details how a network interface will work, mostly built in VHDL. # Tool instructions -TBW +Read the README.md in `./scripts` # Build instructions TBW diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 0000000..9d2b7ca --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,7 @@ +# Created by venv; see https://docs.python.org/3/library/venv.html +bin +include +lib +lib64 +pyvenv.cfg +__pycache__ diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..53a3716 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,6 @@ +# Installation +* Run `python -m venv .` +* Run `./bin/pip install -r requirements.txt` + +# Running +* `./bin/python gantry.py --help` documents how it works diff --git a/scripts/build_env.py b/scripts/build_env.py new file mode 100644 index 0000000..688041f --- /dev/null +++ b/scripts/build_env.py @@ -0,0 +1,67 @@ +import os +from re import split +import subprocess + +def ghdlEnvExists(relativePath="work"): + ## Check if work exists + try: + os.lstat(relativePath) + except: + return False + ## Check that work is writable + if not os.access(relativePath, os.W_OK): + print(f"{relativePath} is write-protected, please acquire correct permissions") + return False + cfFileExists = False + filesInWork = os.listdir(relativePath) + for file in filesInWork: + if ".cf" in file: + cfFileExists = True + if not cfFileExists: + return False + ## Nothing bad, continue + return True + +def createBuildEnv(): + if ghdlEnvExists(): + print("Build environment already exists, exiting...") + return -1 + ## Create build env + print("Initializing GHDL project in current directory...") + os.makedirs("work",exist_ok=True) + addAllVHDLFiles(init=True) + return 0 + +def addAllVHDLFiles(init=False): + ## Ensure everything is ready for adding files + ## (init exception to avoid one if-case in ghdlEnvExists) + if not ghdlEnvExists() and not init: + return -1 + vhdlFiles = [] + currentlyAdded = [] + ## Find already present files + if not init: + cfFileName = list(filter(lambda x: ".cf" in x, os.listdir("work")))[0] + cfFilePath = os.path.join(os.getcwd(),f"work/{cfFileName}") + currentlyAdded = getCurrentlyAddedFiles(cfFilePath) + ## Add files not added + for file in os.listdir(): + if ".vhd" in file and file not in currentlyAdded: + vhdlFiles.append(file) + if len(vhdlFiles) > 0: + print(f"Detected new files. Adding {vhdlFiles}") + command = ["ghdl", "-i", "--workdir=work"] + vhdlFiles + subprocess.run(command) + return 0 + +def getCurrentlyAddedFiles(cfFilePath:str): + f = open(cfFilePath,"r") + lines = f.readlines() + f.close() + fileLines = filter(lambda x: "file" in x, lines) + files = map(lambda x: split("\" \"",x)[1], fileLines) + return list(files) + + +if __name__ == "__main__": + getCurrentlyAddedFiles("work/work-obj93.cf") diff --git a/scripts/dependecies.md b/scripts/dependecies.md new file mode 100644 index 0000000..0feb6b1 --- /dev/null +++ b/scripts/dependecies.md @@ -0,0 +1,4 @@ +* GHDL = 4.1.0 +* Python >= 3.0.0 +* gtkwave >= v3.3.120 + diff --git a/scripts/elab.py b/scripts/elab.py new file mode 100644 index 0000000..db3d4f1 --- /dev/null +++ b/scripts/elab.py @@ -0,0 +1,31 @@ +import os +import subprocess +import build_env + +def elabDesign(topDef: str, arch: str, lib: str, std: str): + ## Add all source files present in pwd + if build_env.addAllVHDLFiles() == -1: + print("Adding files failed. GHDL Build environment may be broken...") + return -1 + command = [ + "ghdl", "-m", f"--workdir={lib}", f"--work={lib}", f"--std={std}", + "-o", f"{lib}/{topDef}-{arch}", f"{lib}.{topDef}", f"{arch}"] + subprocess.run(command) + +def runDesign(topDef: str, arch: str, lib: str, std: str): + ## elaborate first, then run + if elabDesign(topDef, arch, lib, std) == -1: + print("Elaboration failed...") + return -1 + os.makedirs("wave",exist_ok=True) + libPath = os.path.join(os.getcwd(), lib) + wavePath = os.path.join(os.getcwd(), "wave") + command = [ ## may add -v for verbose + "ghdl", "-r", f"{topDef}", f"{arch}", + f"--wave={os.path.join(libPath, topDef)}-{arch}.ghw" ##, "--read-wave-opt=