summaryrefslogtreecommitdiff
path: root/hdl_lab/hdl
diff options
context:
space:
mode:
authorjjsuperpower <jjs29356@gmail.com>2022-06-28 23:59:02 -0500
committerjjsuperpower <jjs29356@gmail.com>2022-06-28 23:59:02 -0500
commit7947465eba567b1982e81e38771328d8d1303fce (patch)
tree04ca046242c31a3d21d73b62cc58a239c57b9e2c /hdl_lab/hdl
parent346307134958f5e4c0db141993d62b3b5c28996c (diff)
vcd file working for cosim
Diffstat (limited to 'hdl_lab/hdl')
-rw-r--r--hdl_lab/hdl/myhdl_wrap.py16
-rw-r--r--hdl_lab/hdl/reset_sync.py16
2 files changed, 25 insertions, 7 deletions
diff --git a/hdl_lab/hdl/myhdl_wrap.py b/hdl_lab/hdl/myhdl_wrap.py
index 2e8fe4e..56c8c5b 100644
--- a/hdl_lab/hdl/myhdl_wrap.py
+++ b/hdl_lab/hdl/myhdl_wrap.py
@@ -9,6 +9,22 @@ class Myhdl_Wrapper():
def _export(self, **kargs):
inst = getattr(self, self.class_name)(**kargs)
inst.convert(hdl='Verilog', path=GEN_VERILOG, name=f"{self.class_name}")
+
+ test_bench_file = GEN_VERILOG + 'tb_' +self.class_name + '.v'
+ test_bench_tmp_file = GEN_VERILOG + '~tb_' +self.class_name + '.v'
+
+ # this is needed to generate cosim vcd file
+ with open(test_bench_file) as f_old, open(test_bench_tmp_file, 'w') as f_new:
+ lines = f_old.readlines()
+ for line in lines:
+ f_new.write(line)
+ if 'initial begin' in line:
+ f_new.write('\n')
+ f_new.write(' // Needed to create vcd file\n')
+ f_new.write(f' $dumpfile ("{SIM_DIR + self.class_name}_cosim.vcd");\n')
+ f_new.write(f' $dumpvars(0, tb_{self.class_name});\n')
+ f_new.write('\n')
+ os.rename(test_bench_tmp_file, test_bench_file)
diff --git a/hdl_lab/hdl/reset_sync.py b/hdl_lab/hdl/reset_sync.py
index 3116b9e..04ccdeb 100644
--- a/hdl_lab/hdl/reset_sync.py
+++ b/hdl_lab/hdl/reset_sync.py
@@ -38,7 +38,7 @@ class ResetSync(Myhdl_Wrapper):
def tb(self, func: Callable):
async_reset = Signal(False)
sync_reset = Signal(False)
- clk = Signal(bool(0))
+ clk = Signal(False)
dut = func(clk=clk, async_reset=async_reset, sync_reset=sync_reset)
@@ -62,24 +62,26 @@ class ResetSync(Myhdl_Wrapper):
yield clk.posedge, async_reset.negedge
if async_reset == True:
- assert sync_reset.next == False, 'sync Reset did not wait for second clock positive edge'
+ yield delay(0)
+ assert sync_reset == False, 'sync Reset did not wait for second clock positive edge'
yield clk.posedge, async_reset.negedge
if async_reset == True:
- assert sync_reset.next == True, 'sync Reset did not set'
+ yield delay(0)
+ assert sync_reset == True, 'sync Reset did not set'
@instance
def stimulus():
for _ in range(500):
- yield delay(randint(1,20))
+ yield delay(randint(0,20))
if (now()+2) % 4 == 0: # do not create rising edge of reset and clk at the same time
yield(delay(1))
async_reset.next = True
- yield delay(randint(1, 20))
+ yield delay(randint(0, 20))
async_reset.next = False
raise StopSimulation
@@ -103,7 +105,7 @@ def test_reset_sync_sim():
def test_reset_sync_cosim():
hdl = ResetSync()
hdl.export()
- # hdl.cosim()
+ hdl.cosim()
-# test_reset_sync_sim()
+test_reset_sync_sim()
test_reset_sync_cosim()