vendor.lattice_{ecp5,machxo_2_3l}: remove -forceAll from Diamond scripts.
[nmigen.git] / examples / basic / pmux.py
1 from nmigen import *
2 from nmigen.cli import main
3
4
5 class ParMux(Elaboratable):
6 def __init__(self, width):
7 self.s = Signal(3)
8 self.a = Signal(width)
9 self.b = Signal(width)
10 self.c = Signal(width)
11 self.o = Signal(width)
12
13 def elaborate(self, platform):
14 m = Module()
15 with m.Switch(self.s):
16 with m.Case("--1"):
17 m.d.comb += self.o.eq(self.a)
18 with m.Case("-1-"):
19 m.d.comb += self.o.eq(self.b)
20 with m.Case("1--"):
21 m.d.comb += self.o.eq(self.c)
22 with m.Case():
23 m.d.comb += self.o.eq(0)
24 return m
25
26
27 if __name__ == "__main__":
28 pmux = ParMux(width=16)
29 main(pmux, ports=[pmux.s, pmux.a, pmux.b, pmux.c, pmux.o])