def datagen(dut, wbm, messages): reslist = [] idleGenWord = genw.random_data(0, 5) idleGenCyc = genw.random_data(1, 10) idleGenBlock = genw.random_data(1, 10) cntGenX1000 = genw.incrementing_data(0x1000, 0x1000) cntGen = genw.incrementing_data(1, 1) adrGen = genw.incrementing_data() #tsGen = genw.random_data(0, 50, 64) tsGen = genw.incrementing_data(1) clkedge = RisingEdge(dut.clk) global cnt_send for i in range(0, messages): opQ = Queue.Queue(8) ts = tsGen.next() tsExpList.append(ts) opQ.put(WBO(adrGen.next(), ts >> 32, idleGenWord.next())) opQ.put(WBO(adrGen.next(), ts & 0xffffffff, idleGenWord.next())) n = cntGenX1000.next() opQ.put(WBO(adrGen.next(), n + cntGen.next(), idleGenWord.next())) opQ.put(WBO(adrGen.next(), n + cntGen.next(), idleGenWord.next())) opQ.put(WBO(adrGen.next(), n + cntGen.next(), idleGenWord.next())) opQ.put(WBO(adrGen.next(), n + cntGen.next(), idleGenWord.next())) opQ.put(WBO(adrGen.next(), n + cntGen.next(), idleGenWord.next())) opQ.put(WBO(adrGen.next(), n + cntGen.next(), idleGenWord.next())) while not opQ.empty(): dowords = random.randint(1, 8) cycle = [] for i in range(dowords): if not opQ.empty(): cycle.append(opQ.get_nowait()) cnt_send += 1 tmp = yield wbm.send_cycle(cycle) reslist.append(tmp) #wait a couple of clockcycle before next wb cycle for i in range(idleGenCyc.next()): yield clkedge #wait a couple of clockcycle before next block for i in range(idleGenBlock.next()): yield clkedge
def test_wb_looback(dut): clkref_period = 8 clksys_period = 16 # """Example of a test using TUN/TAP over WB.""" cocotb.fork(Clock(dut.clk, clkref_period).start()) cocotb.fork(Clock(dut.clk2, clksys_period).start()) # Reset the DUT dut.log.debug("Resetting DUT") dut.reset_n <= 0 dut.reset_n2 <= 0 yield Timer(50*clksys_period) dut.log.debug("Out of reset") dut.log.setLevel(logging.INFO) tsGen = genw.random_data(0, 1000, 64) idleGenWord = genw.random_data(0, 5) replyWaitGen = genw.random_data(1, 10) idleGenBlock = genw.random_data(0, 50) stallGen = genb.bit_toggler(genw.random_data(1, 10), genw.random_data(1, 10)) cntGenX1000 = genw.incrementing_data(0x1000) cntGen = genw.incrementing_data(1) stdExp = WBR(True, None, 6, 5, 5) datGen = genw.incrementing_data(1) errGen = genb.bit_toggler(genw.random_data(0, 1), genw.random_data(1, 10)) adrGen = genw.random_data(0, 50) datwrGen = genw.random_data() wordRepeatGen = genw.random_data(1, 50) weGen = genw.random_data(0, 1) output = rec(dut) wbm = WishboneMaster(dut, "wbm", dut.clk) wbm.log.setLevel(logging.INFO) wbs = WishboneSlave(entity=dut, name="wbmo", clock=dut.clk, callback=output.receive, errgen=None, datgen=datGen, stallwaitgen=stallGen, replywaitgen=replyWaitGen) wbs.log.setLevel(logging.INFO) oplist = [] explist = [] reslist = [] #oplist.append([WBO(0x0, 0xDEADBEEF, 123)]) # for i in range(1, 3): # tmpOplist = [] # tmpExplist = [] # ts = tsGen.next() # # tmpOplist.append(WBO(0x0, ts >> 32, idleGenWord.next())) # tmpExplist.append(stdExp) # tmpOplist.append(WBO(0x0, ts & 0xffffffff, idleGenWord.next())) # tmpOplist.append(WBO(0x0, None, idleGenWord.next())) # tmpExplist.append(stdExp) # n = cntGenX1000.next() # tmpOplist.append(WBO(0x0, n + cntGen.next(), idleGenWord.next())) # tmpExplist.append(stdExp) # tmpOplist.append(WBO(0x0, n + cntGen.next(), idleGenWord.next())) # tmpExplist.append(stdExp) # tmpOplist.append(WBO(0x0, n + cntGen.next(), idleGenWord.next())) # tmpExplist.append(stdExp) # tmpOplist.append(WBO(0x0, n + cntGen.next(), idleGenWord.next())) # tmpExplist.append(stdExp) # tmpOplist.append(WBO(0x0, n + cntGen.next(), idleGenWord.next())) # tmpExplist.append(stdExp) # tmpOplist.append(WBO(0x0, None, idleGenBlock.next())) # # tmpExplist.append(stdExp) # oplist += [tmpOplist] # explist.append(tmpExplist) for i in range(0, 10): tmpOplist = [] words = wordRepeatGen.next() for i in range(0, words): dat = None if weGen.next(): dat = datwrGen.next() tmpOplist.append(WBO(adrGen.next()*4, dat, idleGenWord.next())) oplist += [tmpOplist] for cycle in oplist: tmp = yield wbm.send_cycle(cycle) reslist.append(tmp) dut.log.info("***** Master - Received Replies:") cyccnt = 0 for cycle in reslist: dut.log.info("WBM Cycle #%3u, %3u Ops" % (cyccnt,len(cycle))) cyccnt += 1 cnt = 0 for res in cycle: dat = " None" if res.dat is not None: dat = "0x%08x" % res.dat ackerr = "ERR" if res.ack: ackerr = "ACK" dut.log.debug("#%3u ACK/ERR: %s RD: %s IDLW: %3u STLW: %3u ACKW: %3u" % (cnt, ackerr, dat, res.waitidle, res.waitstall, res.waitack)) cnt += 1 # yield RisingEdge(dut.clk) #cocotb.fork(lifesign(dut, 5000000)) # L = [] # thread.start_new_thread(input_thread, (L,)) # print "Press Any key to close" # while True: # if L: # print L # break # yield RisingEdge(dut.clk2) print "DONE *****"