Skip to content

Instantly share code, notes, and snippets.

@newhouseb
Last active March 18, 2021 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newhouseb/35099442566357395bbe0d684ea5fc02 to your computer and use it in GitHub Desktop.
Save newhouseb/35099442566357395bbe0d684ea5fc02 to your computer and use it in GitHub Desktop.
make_callable example for nmigen
class Doubler(Elaboratable):
def __init__(self):
self.input = Signal(8)
self.output = Signal(8)
self.sync_output = Signal(8)
def inputs(self):
return [self.input]
def outputs(self):
return [self.output, self.sync_output]
def elaborate(self, platform):
m = Module()
m.d.comb += self.output.eq(self.input << 1)
m.d.sync += self.sync_output.eq(self.input << 1)
return m
doubler = make_callable(Doubler())
assert doubler(1) == [2, 0]
assert doubler(2) == [4, 2]
assert doubler(2) == [4, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment