-
Notifications
You must be signed in to change notification settings - Fork 188
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
examples.boilerplate: modify to use port groups #663
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,66 @@ | ||
import logging | ||
import asyncio | ||
from amaranth import * | ||
from amaranth.lib import io, stream, wiring | ||
|
||
from ... import * | ||
|
||
|
||
class BoilerplateSubtarget(Elaboratable): | ||
def __init__(self, pads, in_fifo, out_fifo): | ||
self.pads = pads | ||
class BoilerplateModule(wiring.Component): | ||
data: In(8) | ||
enable: Out(1) | ||
|
||
in_stream: In(stream.Signature(signed(8))) | ||
out_stream: Out(stream.Signature(signed(8))) | ||
def elaborate(self, platform): | ||
m = Module() | ||
|
||
return m | ||
|
||
class BoilerplateSubtarget(wiring.Component): | ||
def __init__(self, ports, in_fifo, out_fifo): | ||
self.ports = ports | ||
self.in_fifo = in_fifo | ||
self.out_fifo = out_fifo | ||
|
||
def elaborate(self, platform): | ||
m = Module() | ||
|
||
# ┌───────┐ ┌─────────────────┐ | ||
# │in_fifo◄───in_stream───┤ │ | ||
# └───────┘ │ │ | ||
# │BoilerplateModule│ | ||
# ┌────────┐ │ │ | ||
# │out_fifo├───out_stream──► │ | ||
# └────────┘ └─────▲───────┬───┘ | ||
# │ │ | ||
# data enable | ||
# │ │ | ||
# ┌───┴───────▼──┐ | ||
# │ Ports │ | ||
# └──────────────┘ | ||
|
||
|
||
m.submodules.boilerplate = boilerplate = BoilerplateModule() | ||
|
||
## Instantiate IO buffers for pins/ports | ||
m.submodules.data_buffer = data_buffer = io.Buffer("i", args.port_data) | ||
m.submodules.enable_buffer = enable_buffer = io.Buffer("o", args.port_enable) | ||
|
||
## Connect IO buffers to corresponding ports of BoilerplateModule | ||
wiring.connect(m, boilerplate.data, data_buffer.i) | ||
wiring.connect(m, boilerplate.enable, enable_buffer.o) | ||
|
||
## Connect BoilerplateModule.in_stream to BoilerplateSubtarget.out_fifo | ||
boilerplate.in_stream.payload.eq(self.out_fifo.r_data), | ||
boilerplate.in_stream.valid.eq(self.out_fifo.r_rdy), | ||
self.out_fifo.r_en.eq(boilerplate.in_stream.ready), | ||
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 think you should be able to do these via 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. In my latest version, I used the "interface adaptation" pattern between the in/out fifo signals to a stream.Signature. But I see now that amaranth.lib.fifo implements streams, so 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. yep! |
||
|
||
## Connect BoilerplateSubtarget.in_fifo to BoilerplateModule.out_stream | ||
self.in_fifo.w_data.eq(boilerplate.out_stream.payload), | ||
self.in_fifo.w_en.eq(boilerplate.out_stream.valid), | ||
boilerplate.out_stream.ready.eq(self.in_fifo.w_rdy), | ||
|
||
return m | ||
|
||
|
||
|
@@ -32,19 +80,20 @@ class BoilerplateApplet(GlasgowApplet): | |
nothing. Similarly, there is no requirement to use IN or OUT FIFOs, or any pins at all. | ||
""" | ||
|
||
__pins = () | ||
|
||
@classmethod | ||
def add_build_arguments(cls, parser, access): | ||
super().add_build_arguments(parser, access) | ||
|
||
for pin in cls.__pins: | ||
access.add_pin_argument(parser, pin, default=True) | ||
access.add_pin_argument(parser, "enable", default=True) | ||
access.add_pin_set_argument(parser, "data", width=8, default=True) | ||
|
||
def build(self, target, args): | ||
self.mux_interface = iface = target.multiplexer.claim_interface(self, args) | ||
iface.add_subtarget(BoilerplateSubtarget( | ||
pads=iface.get_deprecated_pads(args, pins=self.__pins), | ||
ports=iface.get_port_group( | ||
enable = args.pin_enable, | ||
data = args.pin_set_data | ||
), | ||
in_fifo=iface.get_in_fifo(), | ||
out_fifo=iface.get_out_fifo(), | ||
)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually these should live in the
BoilerplateModule
which I'd probably callBoilerplateCore
. So the core would do the port manipulation and the subtarget would set up the transfers and stuff like that, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That separation of functions makes sense to me. A more verbose option would be to create a
BoilerplateOutput
module to handle the ports, and then leaveBoilerplateCore
empty as a placeholder for "core" logic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems excessive for the sample applet. This all will change some time not too far away anyway.