Skip to content

Commit

Permalink
refactored pyuvm tb to decouple the result monitor from the driver
Browse files Browse the repository at this point in the history
  • Loading branch information
npatsiatzis committed Aug 26, 2023
1 parent a35baf6 commit eaa397b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
28 changes: 18 additions & 10 deletions pyuvm_sim/tb_async_fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,26 @@ def notify():
# at_least = value is superfluous, just shows how you can determine the amount of times that
# a bin must be hit to considered covered
# even if g_data_with is >8, do not exercize full range as it is extremelly comp. heavy
@CoverPoint("top.i_tx_data",xf = lambda x : x, bins = list(range(2**4,2**5)), at_least=1)
@CoverPoint("top.i_tx_data",xf = lambda x : x, bins = list(range(2**g_width)), at_least=1)
def number_cover(x):
pass

class crv_inputs(crv.Randomized):
def __init__(self,data):
def __init__(self,data,wren,ren):
crv.Randomized.__init__(self)
self.tx_data = data
self.wren = wren
self.ren = ren
self.add_rand("tx_data",list(range(2**g_width)))
self.add_rand("wren",[0,1])
self.add_rand("ren",[0,1])

# Sequence classes
class SeqItem(uvm_sequence_item):

def __init__(self, name,data):
def __init__(self, name,data,wren,ren):
super().__init__(name)
self.i_crv = crv_inputs(data)
self.i_crv = crv_inputs(data,wren,ren)

def randomize_operands(self):
self.i_crv.randomize()
Expand All @@ -53,7 +57,7 @@ class RandomSeq(uvm_sequence):
async def body(self):

while len(covered_values) != 2**g_width:
data_tr = SeqItem("data_tr", None)
data_tr = SeqItem("data_tr", None,None,None)
await self.start_item(data_tr)
data_tr.randomize_operands()
while(data_tr.i_crv.tx_data in covered_values):
Expand Down Expand Up @@ -86,13 +90,16 @@ async def run_phase(self):
await self.launch_tb()
while True:
data = await self.seq_item_port.get_next_item()

await self.bfm.send_data((1, 0,data.i_crv.tx_data))
await self.bfm.send_data((0, 0,data.i_crv.tx_data))
await RisingEdge(self.bfm.dut.f_wr_done)
await self.bfm.send_data((0, 0,data.i_crv.tx_data))
await RisingEdge(self.bfm.dut.i_clkW)


await self.bfm.send_data((0, 1,0))
result = await self.bfm.get_result()
self.ap.write(result)
data.result = result
await RisingEdge(self.bfm.dut.f_rd_done)

self.seq_item_port.item_done()
await self.bfm.send_data((0, 0,0))

Expand Down Expand Up @@ -187,14 +194,15 @@ def build_phase(self):
ConfigDB().set(None, "*", "SEQR", self.seqr)
self.driver = Driver.create("driver", self)
self.data_mon = Monitor("data_mon", self, "get_data")
self.res_mon = Monitor("res_mon", self, "get_result")
self.coverage = Coverage("coverage", self)
self.scoreboard = Scoreboard("scoreboard", self)

def connect_phase(self):
self.driver.seq_item_port.connect(self.seqr.seq_item_export)
self.data_mon.ap.connect(self.scoreboard.data_export)
self.data_mon.ap.connect(self.coverage.analysis_export)
self.driver.ap.connect(self.scoreboard.result_export)
self.res_mon.ap.connect(self.scoreboard.result_export)


@pyuvm.test()
Expand Down
16 changes: 10 additions & 6 deletions pyuvm_sim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@ async def driver_bfm(self):

async def data_mon_bfm(self):
while True:
await RisingEdge(self.dut.f_wr_done)
data = self.dut.i_dataW.value
self.data_mon_queue.put_nowait(data)
# await RisingEdge(self.dut.f_wr_done)
if(self.dut.i_wren.value == 1 and self.dut.o_full.value ==0):
data = self.dut.i_dataW.value
self.data_mon_queue.put_nowait(data)
await RisingEdge(self.dut.i_clkW)

async def result_mon_bfm(self):
while True:
await RisingEdge(self.dut.f_rd_done)
self.result_mon_queue.put_nowait(self.dut.o_dataR.value)

# await RisingEdge(self.dut.f_rd_done)
if(self.dut.i_ren.value == 1 and self.dut.o_empty.value ==0):
await RisingEdge(self.dut.i_clkR)
self.result_mon_queue.put_nowait(self.dut.o_dataR.value)
await RisingEdge(self.dut.i_clkR)

def start_bfm(self):
cocotb.start_soon(self.driver_bfm())
Expand Down

0 comments on commit eaa397b

Please sign in to comment.