-
Notifications
You must be signed in to change notification settings - Fork 178
Added gatemate vendor and Updated init file #1460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tarik-hamedovic
wants to merge
18
commits into
amaranth-lang:main
Choose a base branch
from
tarik-hamedovic:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fd61e4d
Added gatemate vendor and Updated init file
0580d1a
Update amaranth/vendor/_gatemate.py
tarik-hamedovic 95bea8a
Update
ceeca1f
Update
1eb3001
Update amaranth/vendor/_gatemate.py
tarik-hamedovic e3e65f8
Update
4a2b7da
Merge branch 'main' of https://github.com/TarikHamedovic/amaranth
ed3f252
Update
857d8e7
Update
c3b8f9c
fix whitespace errors
whitequark 231bbda
Update yosys command_template
59861aa
Update yosys command_template
9c0e84b
Added my Blinky example
3760be1
Deleted SDC file
0505ca5
Update README.md
tarik-hamedovic 9a82d53
Removed unnecessary lines
f639850
Removed unnecessary lines
006ca56
Changed yosys keep to appropriate form
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from abc import abstractmethod | ||
from amaranth import * | ||
from amaranth.build import * | ||
from amaranth.lib.cdc import ResetSynchronizer | ||
|
||
|
||
__all__ = ["GateMatePlatform"] | ||
|
||
whitequark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class GateMatePlatform(TemplatedPlatform): | ||
""" | ||
Required tools: | ||
* ``yosys`` | ||
* ``p_r`` | ||
|
||
The environment is populated by running the script specified in the environment variable | ||
``AMARANTH_ENV_GATEMATE``, if present. | ||
""" | ||
|
||
device = property(abstractmethod(lambda: None)) | ||
package = property(abstractmethod(lambda: None)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized that nothing in the platform file is using these variables. In that case they should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted those lines |
||
|
||
toolchain = "GateMate" | ||
|
||
required_tools = [ | ||
"yosys", | ||
"p_r", | ||
] | ||
|
||
file_templates = { | ||
**TemplatedPlatform.build_script_templates, | ||
"{{name}}.il": r""" | ||
# {{autogenerated}} | ||
{{emit_rtlil()}} | ||
""", | ||
"{{name}}.debug.v": r""" | ||
/* {{autogenerated}} */ | ||
{{emit_debug_verilog()}} | ||
""", | ||
"{{name}}.ys": r""" | ||
# {{autogenerated}} | ||
{% for file in platform.iter_files(".v") -%} | ||
read_verilog {{get_override("read_verilog_opts")|options}} {{file}} | ||
{% endfor %} | ||
{% for file in platform.iter_files(".sv") -%} | ||
read_verilog -sv {{get_override("read_verilog_opts")|options}} {{file}} | ||
{% endfor %} | ||
{% for file in platform.iter_files(".il") -%} | ||
read_ilang {{file}} | ||
{% endfor %} | ||
read_ilang {{name}}.il | ||
{{get_override("script_after_read")|default("# (script_after_read placeholder)")}} | ||
synth_gatemate {{get_override("synth_opts")|options}} -top {{name}} -vlog {{name}}_synth.v | ||
{{get_override("script_after_synth")|default("# (script_after_synth placeholder)")}} | ||
""", | ||
"{{name}}.ccf": r""" | ||
# {{autogenerated}} | ||
{% for port_name, pin_name, attrs in platform.iter_port_constraints_bits() -%} | ||
Net "{{port_name}}" Loc = "{{pin_name}}" | ||
{%- for constraint, value in attrs.items() -%} | ||
| {{constraint}}={{value}} | ||
{%- endfor -%}; | ||
{% endfor %} | ||
""", | ||
} | ||
|
||
command_templates = [ | ||
r""" | ||
{{invoke_tool("yosys")}} | ||
{{quiet("-q")}} | ||
{{get_override("yosys_opts")|options}} | ||
-l {{name}}.rpt | ||
{{name}}.ys | ||
""", | ||
r""" | ||
{{invoke_tool("p_r")}} | ||
{{verbose("-v")}} | ||
-i {{name}}_synth.v | ||
-o {{name}} | ||
-ccf {{name}}.ccf | ||
-cCP > {{name}}.tim | ||
""", | ||
] | ||
|
||
# Common logic | ||
|
||
def add_clock_constraint(self, clock, frequency): | ||
super().add_clock_constraint(clock, frequency) | ||
clock.attrs["keep"] = "TRUE" | ||
whitequark marked this conversation as resolved.
Show resolved
Hide resolved
whitequark marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from amaranth import * | ||
from amaranth.sim import * | ||
from amaranth.back import verilog | ||
|
||
import argparse | ||
import subprocess | ||
import importlib | ||
import os | ||
import shutil | ||
|
||
top_name = "Blinky" | ||
|
||
class Blinky(Elaboratable): | ||
|
||
def __init__(self, num_leds=1, clock_divider=21): | ||
self.num_leds = num_leds | ||
self.clock_divider = clock_divider | ||
self.leds = Signal(num_leds) | ||
|
||
def elaborate(self, platform): | ||
# Create a new Amaranth module | ||
m = Module() | ||
|
||
# This is a local signal, which will not be accessible from outside. | ||
count = Signal(self.clock_divider) | ||
|
||
# If the platform is not defined then it is simulation | ||
if platform is not None: | ||
|
||
# ULX3S | ||
#leds = [platform.request("led", i) for i in range(self.num_leds)] | ||
#m.d.comb += [led.o.eq(self.leds[i]) for i, led in enumerate(leds)] | ||
|
||
# Olimex GateMate | ||
led = platform.request("led", 0) | ||
m.d.comb += led.o.eq(self.leds) | ||
|
||
# In the sync domain all logic is clocked at the positive edge of | ||
# the implicit clk signal. | ||
m.d.sync += count.eq(count + 1) | ||
with m.If(count == (2**self.clock_divider - 1)): | ||
m.d.sync += [ | ||
self.leds.eq(~self.leds), | ||
count.eq(0) | ||
] | ||
|
||
return m | ||
|
||
|
||
def clean(): | ||
files_to_remove = [f"{top_name}.vcd", f"{top_name}.gtkw", f"{top_name}.v"] | ||
build_dir = "build" | ||
|
||
for file in files_to_remove: | ||
try: | ||
os.remove(file) | ||
print(f"Removed {file}") | ||
except FileNotFoundError: | ||
print(f"{file} not found, skipping") | ||
|
||
if os.path.isdir(build_dir): | ||
try: | ||
shutil.rmtree(build_dir) | ||
print(f"Removed {build_dir} directory") | ||
except OSError as e: | ||
print(f"Error removing {build_dir}: {e}") | ||
|
||
if __name__ == "__main__": | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-s", "--simulate", action="store_true", help="Simulate Blinky Example") | ||
parser.add_argument("-b", "--build", action="store_true", help="Build The Blinky Example") | ||
parser.add_argument("-v", "--verilog", action="store_true", help="Generate Verilog for Blinky Example") | ||
parser.add_argument("-p", "--platform", type=str, required=False, help="Platform module (e.g., amaranth_boards.ulx3s.ULX3S_85F_Platform)") | ||
parser.add_argument("-n", "--num-leds", type=int, default=1, help="Number of LEDs") | ||
parser.add_argument("-cd", "--clock-divider", type=int, default=21, help="Clock divider (bit width of the counter)") | ||
parser.add_argument("-cf", "--clock-frequency", type=float, default=1.0, help="Clock frequency in MHz") | ||
parser.add_argument("-rt", "--runtime", type=int, default=30000, help="Testbench runtime in clock cycles") | ||
parser.add_argument("-c", "--clean", action="store_true", help="Clean generated files and build directory") | ||
parser.add_argument("-dp", "--do-program", action="store_true", help="Program the device after building") | ||
parser.add_argument("-gw", "--gtkwave", action="store_true", help="Open GTKWave after simulation") | ||
|
||
args = parser.parse_args() | ||
|
||
if args.clean: | ||
clean() | ||
|
||
else: | ||
num_leds = args.num_leds if args.num_leds is not None else 1 | ||
clock_divider = args.clock_divider if args.clock_divider is not None else 21 | ||
clock_frequency = args.clock_frequency if args.clock_frequency is not None else 1.0 | ||
runtime = args.runtime if args.runtime is not None else 30000 | ||
do_program = args.do_program | ||
|
||
if args.simulate: | ||
|
||
def testbench(): | ||
for _ in range(runtime): | ||
yield Tick() | ||
|
||
# Instantiate the Blinky module | ||
dut = Blinky(num_leds, clock_divider) | ||
|
||
# Create a simulator | ||
sim = Simulator(dut) | ||
sim.add_clock(1e-6 / clock_frequency) | ||
sim.add_process(testbench) | ||
with sim.write_vcd(f"{top_name}.vcd", f"{top_name}.gtkw", traces=[dut.leds]): | ||
sim.run() | ||
|
||
# Open GTKWave with the generated VCD file if --gtkwave is set | ||
if args.gtkwave: | ||
subprocess.run(["gtkwave", f"{top_name}.vcd"]) | ||
|
||
elif args.build: | ||
if args.platform is None: | ||
raise ValueError("Platform must be specified for building") | ||
platform_module_name, platform_class_name = args.platform.rsplit(".", 1) | ||
platform_module = importlib.import_module(platform_module_name) | ||
platform_class = getattr(platform_module, platform_class_name) | ||
|
||
plat = platform_class() | ||
plat.build(Blinky(num_leds, clock_divider), do_program=do_program) | ||
|
||
elif args.verilog: | ||
dut = Blinky(num_leds, clock_divider) | ||
with open(f"{top_name}.v", "w") as f: | ||
f.write(verilog.convert(dut, ports=[dut.leds])) | ||
|
||
# TODO: Maybe write an additional file where all of the amaranth_boards with their vendors are specified so that you can type ulx3s -85F instead of amaranth_boards.ulx3s.ULX3S_85F_Platform |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.