Last active
March 18, 2021 19:57
-
-
Save newhouseb/35099442566357395bbe0d684ea5fc02 to your computer and use it in GitHub Desktop.
make_callable example for nmigen
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
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