diff --git a/ecppll.py b/ecppll.py new file mode 100644 index 0000000..cbf5ca9 --- /dev/null +++ b/ecppll.py @@ -0,0 +1,27 @@ +#!/usr/bin/python +from fusesoc.capi2.generator import Generator +import subprocess +import os + +class EcppllGenerator(Generator): + def run(self): + name = self.config.get('name', 'pll') + fin = self.config.get('freq_in', 12) + fout = self.config.get('freq_out', 60) + filename = self.config.get('filename', 'pll.v') + use_container = self.config.get('use_container', False) + + args = [] + if use_container: + args += ['docker', 'run', '--rm', '-v', os.getcwd() + ':/src', '-w', '/src', 'hdlc/prjtrellis'] + args += ['ecppll', '-f', filename, '-n', name, '-i', str(fin), '-o', str(fout)] + + rc = subprocess.run(args) + + if rc.returncode: + exit(1) + self.add_files([{filename : {'file_type' : 'verilogSource'}}]) + +g = EcppllGenerator() +g.run() +g.write() diff --git a/generators.core b/generators.core index 962849a..a94d107 100644 --- a/generators.core +++ b/generators.core @@ -47,7 +47,7 @@ generators: it detects that there are local modifications in the repository icepll: - interpreter: python + interpreter: python3 command: icepll.py description: Generate a parameterized verilog wrapper for an iCE40 PLL usage: | @@ -62,6 +62,22 @@ generators: and the icepll generator will create a list of parameters that can be included in the parameter list of the user-instantiated component (default: false) + use_container (bool): Run icepll tool from a container without installing it + locally. Requires Docker (default: false). + ecppll: + interpreter: python3 + command: ecppll.py + description: Generate a parameterized verilog wrapper for an ECP5 PLL + usage: | + The ecppll generator is a simple wrapper around the ecppll command + + Parameters: + name (str): PLL module name (default: pll) + freq_in (int): PLL Input Frequency (default: 12 MHz) + freq_out (int) PLL Output Frequency (default: 60 MHz) + filename (str): Output filename (default: pll.v) + use_container (bool): Run icepll tool from a container without installing it + locally. Requires Docker (default: false). template: interpreter: python diff --git a/icepll.py b/icepll.py index 26b76d0..f334249 100644 --- a/icepll.py +++ b/icepll.py @@ -1,6 +1,7 @@ #!/usr/bin/python from fusesoc.capi2.generator import Generator import subprocess +import os class IcepllGenerator(Generator): def run(self): @@ -8,12 +9,18 @@ def run(self): fout = self.config.get('freq_out', 60) module = self.config.get('module', False) filename = self.config.get('filename', 'pll.v' if module else 'pll.vh') + use_container = self.config.get('use_container', False) - args = ['icepll', '-f', filename, '-i', str(fin), '-o', str(fout)] + args = [] + if use_container: + args += ['docker', 'run', '--rm', '-v', os.getcwd() + ':/src', '-w', '/src', 'hdlc/icestorm'] + args += ['icepll', '-f', filename, '-i', str(fin), '-o', str(fout)] if module: - args.append('-m') - rc = subprocess.call(args) - if rc: + args += ['-m'] + + rc = subprocess.run(args) + + if rc.returncode: exit(1) self.add_files([{filename : {'file_type' : 'verilogSource', 'is_include_file' : not module}}])