Example #1
0
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 
Example #2
0
def tscheck(dut):
    clkedge = RisingEdge(dut.clk)
    tsErrGen = genw.random_data(1, 9)    
    
    lastTsValid = False
    while True:
        if bool(dut.ts_valid_out.getvalue()) and not lastTsValid:
            if tsErrGen.next():            
                tsList.append(long(dut.ts_out.getvalue()))
            else:
                if not tsErrGen.next():
                    tsList.append(long(dut.ts_out.getvalue()) + 100)
                    
        lastTsValid = bool(dut.ts_valid_out.getvalue())
        yield clkedge
Example #3
0
def test_prio2(dut):
    global messages
    global cnt_plan

    ##### Test Global Parameters    
    messages = 20   
    cnt_plan = 8*messages 
    
    dut.log.setLevel(logging.INFO)
    
    #Setup Clocks
    cocotb.fork(Clock(dut.clk, clkref_period).start())
    cocotb.fork(Clock(dut.clk2, clksys_period).start())
    clkedge = RisingEdge(dut.clk)
    
    # Reset the DUT
    dut.log.debug("Resetting DUT")
    dut.reset_n     <= 0
    dut.reset_n2    <= 0
    dut.en_in       <= 0
    yield Timer(50*clksys_period)
    dut.log.debug("Out of reset")
    
    dut.reset_n     <= 1
    dut.reset_n2    <= 1
    yield Timer(50*clksys_period)
    
   #Timestamp capture routine. Save TSs to compare later against expected values    
    cocotb.fork(tscheck(dut))   
    
    #Data/Signal Generators for WB Slave
    replyWaitGen    = genw.random_data(1, 3)
    ackGen          = genw.random_data(0, 1)
    stallGen        = genb.bit_toggler(genw.random_data(0, 10), genw.random_data(1, 50))
    #Callback for WB SLave
    output = rec(dut)
    #instantiate WB Slave
    wbs  = WishboneSlave(entity=dut, name="wbm", clock=dut.clk, callback=output.receive, stallwaitgen=stallGen, replywaitgen=replyWaitGen)
    wbs.log.setLevel(logging.INFO)    
    
    #instantiate WB Master    
    wbm  = WishboneMaster(dut, "wbs", dut.clk, 500)
    wbm.log.setLevel(logging.INFO) 
    #Stimulus routine. Generate Cycles for WB Master 
    yield datagen(dut, wbm, messages)

    
    ##### TEST Evaluation ######
    
    #wait for all ops to finish
    cnt_timeout = cnt_plan*20
    while (cnt_timeout) and ((cnt_recv < cnt_plan) and (len(tsList) < len(tsExpList))):
        yield clkedge
        cnt_timeout -= 1
    
    #either timeout or all operations complete. Continue      
    yield Timer(50*clksys_period)
    print ""    
    print "%s%s" % (" "*117, "*"*40)
    print ""
    #check for timeout  
    if cnt_timeout <= 0:
        raise TestFailure("Timeout: Not all Operations made it through. Planned: %u Sent: %u Received: %u" % (cnt_plan, cnt_send, cnt_recv)) 
   
    #check if we got too many sent ops for some reason 
    if (cnt_send > cnt_plan):
        raise TestFailure("There were more replies than sent operations. Planned: %u Sent: %u Received: %u" % (cnt_plan, cnt_send, cnt_recv)) 
        
    #check if we got too replies many for some reason 
    if (cnt_recv > cnt_plan):
        raise TestFailure("There were more replies than sent operations. Planned: %u Sent: %u Received: %u" % (cnt_plan, cnt_send, cnt_recv)) 
    
    #check timestamps against expected values
    s = set(tsList)
    result = [x for x in tsExpList if x not in s]
    if len(result):
        raise TestFailure("Expected Timestamps missing from actual result: %s\n Expected: %s\n Got:      %s" % (result, tsExpList, tsList))                        
        
    #all okay, test passed
    print ("Expected Timestamps missing from actual result: %s\n Expected: %s\n Got:      %s" % (result, tsExpList, tsList))                        
        
    raise TestSuccess("All operations processed, all expected timestamps present.\nPlanned: %u Sent: %u Received: %u\nMessages: %u Timestamps: %u" % (cnt_plan, cnt_send, cnt_recv, output.cntcyc-1, messages - len(result)))
    print "*"*80

  #  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 *****"
Example #4
0
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 *****"