summaryrefslogtreecommitdiff
path: root/hdl/testing/shift_reg.py
diff options
context:
space:
mode:
authorjjsuperpower <jjs29356@gmail.com>2022-08-10 22:16:20 -0500
committerjjsuperpower <jjs29356@gmail.com>2022-08-10 22:16:20 -0500
commitc3fbef6e64506057e832334e1dfa26efde67777e (patch)
tree3e0ef3cdfd3f6830832cc53102b38df5be95cb12 /hdl/testing/shift_reg.py
parent965821b9bcf018173e0a60f49382568724a5b589 (diff)
added make file
Diffstat (limited to 'hdl/testing/shift_reg.py')
-rw-r--r--hdl/testing/shift_reg.py100
1 files changed, 0 insertions, 100 deletions
diff --git a/hdl/testing/shift_reg.py b/hdl/testing/shift_reg.py
deleted file mode 100644
index b7c2290..0000000
--- a/hdl/testing/shift_reg.py
+++ /dev/null
@@ -1,100 +0,0 @@
-import sys
-from amaranth import *
-from amaranth.back import verilog, cxxrtl
-from amaranth.cli import main
-from amaranth.sim import Simulator, Settle, Delay
-
-BASENAME = "shift_reg"
-
-class ShiftReg(Elaboratable):
- def __init__(self, width):
- self.load_val = Signal(width, reset=0, reset_less=True)
- self.load = Signal()
- self.reg = Signal(width)
- self.en = Signal()
- self.right_left = Signal()
-
- self.ports = [self.load_val, self.en, self.right_left, self.reg]
-
- def elaborate(self, platform):
- m = Module()
-
- with m.If(self.load):
- m.d.sync += self.reg.eq(self.load_val)
- with m.Else():
- with m.If(self.en):
- with m.If(self.right_left):
- m.d.sync += self.reg.eq(self.reg << 1)
- with m.Else():
- m.d.sync += self.reg.eq(self.reg >> 1)
-
- return m
-
-
-def step():
- yield
- yield Settle()
-
-def test_shift_reg():
- dut = ShiftReg(8)
-
- def proc1():
- val = 0xAB
-
- yield dut.load_val.eq(val)
- yield dut.en.eq(0)
- yield dut.load.eq(1)
- yield
- yield Settle()
- yield dut.load.eq(0)
- yield dut.en.eq(1)
-
- for _ in range(9):
- reg_val = yield dut.reg
- assert reg_val == val, f"Incorrect shift ---EXPECTED: {hex(val)} ---GOT: {hex(reg_val)}"
- val = val >> 1
- yield
- yield Settle()
-
- val = 0xBD
- yield dut.load_val.eq(val)
- yield dut.load.eq(1)
- yield dut.right_left.eq(1)
- yield
- yield Settle()
- yield dut.load.eq(0)
-
- for _ in range(9):
- reg_val = yield dut.reg
- assert reg_val == val, f"Incorrect shift ---EXPECTED: {hex(val)} ---GOT: {hex(reg_val)}"
- val = (val << 1) & 0xff
- yield
- yield Settle()
-
-
-
- sim = Simulator(dut)
- sim.add_clock(1e-6)
- sim.add_sync_process(proc1)
-
- with sim.write_vcd(BASENAME + '.vcd'):
- sim.run()
-
-
-if __name__ == '__main__':
-
- if sys.argv[1] == "sim":
- test_shift_reg()
- exit()
-
- m = ShiftReg(8)
-
- if sys.argv[1] == "v":
- out = verilog.convert(m, ports=m.ports)
- with open(BASENAME + '.v','w') as f:
- f.write(out)
-
- elif sys.argv[1] == "cc":
- out = cxxrtl.convert(m, ports=m.ports)
- with open(BASENAME + '.cc','w') as f:
- f.write(out)