amaranth/examples/basic/pmux.py

30 lines
795 B
Python
Raw Normal View History

2021-12-09 22:39:50 -07:00
from amaranth import *
from amaranth.cli import main
2018-12-11 13:50:56 -07:00
class ParMux(Elaboratable):
2018-12-11 13:50:56 -07:00
def __init__(self, width):
self.s = Signal(3)
self.a = Signal(width)
self.b = Signal(width)
self.c = Signal(width)
self.o = Signal(width)
def elaborate(self, platform):
m = Module()
with m.Switch(self.s):
with m.Case("--1"):
m.d.comb += self.o.eq(self.a)
with m.Case("-1-"):
m.d.comb += self.o.eq(self.b)
with m.Case("1--"):
m.d.comb += self.o.eq(self.c)
2024-01-16 05:09:16 -07:00
with m.Default():
m.d.comb += self.o.eq(0)
return m
2018-12-11 13:50:56 -07:00
if __name__ == "__main__":
pmux = ParMux(width=16)
main(pmux, ports=[pmux.s, pmux.a, pmux.b, pmux.c, pmux.o])