def __init__(self, name, parent, axi, addressWidth, clk, reset): Infrastructure.__init__(self, name, parent) self.axi = axi if hasattr(axi.arw.payload, "hid"): self.idWidth = len(axi.arw.payload.hid) self.addressWidth = addressWidth self.dataWidth = len(axi.w.payload.data) self.maxDataBytes = int(log2Up(self.dataWidth) / 8) self.ram = bytearray(b'\x00' * ((1 << addressWidth) * self.maxDataBytes)) self.doReadWriteCmdRand = BoolRandomizer() self.readWriteRand = BoolRandomizer() self.writeDataRand = BoolRandomizer() self.writeRspScoreboard = ScorboardOutOfOrder("writeRspScoreboard", self) self.readRspScoreboard = ScorboardOutOfOrder("readRspScoreboard", self) self.writeRspScoreboard.addListener(self.freeReservatedAddresses) self.readRspScoreboard.addListener(self.freeReservatedAddresses) self.cmdTasks = Queue() self.writeTasks = Queue() self.nonZeroReadRspCounter = 0 self.nonZeroReadRspCounterTarget = 1000 self.reservedAddresses = {} StreamDriverSlave(axi.r, clk, reset) StreamDriverSlave(axi.b, clk, reset) StreamDriverMaster(axi.arw, self.genReadWriteCmd, clk, reset) StreamDriverMaster(axi.w, self.genWriteData, clk, reset) StreamMonitor(axi.r, self.onReadRsp, clk, reset) StreamMonitor(axi.b, self.onWriteRsp, clk, reset) axi.w.payload.last <= 0 axi.r.payload.last <= 0
def createInfrastructure(self): StreamDriverMaster(self.axi.aw, self.genWriteCmd, self.dut.clk, self.dut.reset) StreamDriverMaster(self.axi.w, self.genWriteData, self.dut.clk, self.dut.reset) StreamDriverSlave(self.axi.b, self.dut.clk, self.dut.reset) return self
def __init__(self,name,parent,dut): Infrastructure.__init__(self,name,parent) StreamDriverMaster(Stream(dut,"io_rx_cmd"),self.genRxCmd(), dut.clk, dut.reset) StreamDriverMaster(Stream(dut, "io_rx_data"), self.genRxData(), dut.clk, dut.reset) StreamDriverSlave(Stream(dut, "io_tx_cmd"), dut.clk, dut.reset) StreamDriverSlave(Stream(dut, "io_tx_data"), dut.clk, dut.reset)
def __init__(self,name,parent,dut): Infrastructure.__init__(self,name,parent) StreamDriverMaster(Stream(dut,"io_cmdA"),self.genCmdA, dut.clk, dut.reset) StreamDriverMaster(Stream(dut, "io_cmdB"), self.genCmdB, dut.clk, dut.reset) StreamDriverSlave(Stream(dut, "io_rsp"), dut.clk, dut.reset) self.memInitDone = False
def createInfrastructure(self): StreamMonitor(self.axi.arw, self.onSharedCmd, self.dut.clk, self.dut.reset) StreamDriverSlave(self.axi.arw, self.dut.clk, self.dut.reset) StreamDriverMaster(self.axi.r, self.genReadRsp, self.dut.clk, self.dut.reset) StreamDriverSlave(self.axi.w, self.dut.clk, self.dut.reset) StreamMonitor(self.axi.w, self.onWriteData, self.dut.clk, self.dut.reset) StreamDriverMaster(self.axi.b, self.genWriteRsp, self.dut.clk, self.dut.reset) return self
def createInfrastructure(self): StreamDriverSlave(self.axi.ar, self.dut.clk, self.dut.reset) StreamMonitor(self.axi.ar, self.onReadCmd, self.dut.clk, self.dut.reset) StreamDriverMaster(self.axi.r, self.genReadRsp, self.dut.clk, self.dut.reset) return self
def __init__(self, axiLite, clk, reset): self.axiLite = axiLite self.clk = clk self.awQueue = Queue() self.arQueue = Queue() self.wQueue = Queue() self.awDriver = StreamDriverMaster( axiLite.aw, lambda: self.awQueue.get_nowait() if not self.awQueue.empty() else None, clk, reset) self.arDriver = StreamDriverMaster( axiLite.ar, lambda: self.arQueue.get_nowait() if not self.arQueue.empty() else None, clk, reset) self.wDriver = StreamDriverMaster( axiLite.w, lambda: self.wQueue.get_nowait() if not self.wQueue.empty() else None, clk, reset) StreamDriverSlave(axiLite.r, clk, reset) StreamDriverSlave(axiLite.b, clk, reset)
def __init__(self, name, parent, dut, sock, clkTocken): Infrastructure.__init__(self, name, parent) self.clkTocken = clkTocken self.rxCmdQueue = Queue() self.rxDataQueue = Queue() self.sock = sock StreamDriverMaster(Stream(dut, "io_rx_cmd"), self.genRxCmd, dut.clk, dut.reset) StreamDriverMaster(Stream(dut, "io_rx_data"), self.genRxData, dut.clk, dut.reset) StreamDriverSlave(Stream(dut, "io_tx_cmd"), dut.clk, dut.reset) StreamDriverSlave(Stream(dut, "io_tx_data"), dut.clk, dut.reset) try: thread.start_new_thread(self.rxThread, ()) except Exception as errtxt: print errtxt
def __init__(self, cmd, rsp, clk, reset, baudPeriod, softMaster): self.cmd = cmd self.rsp = rsp self.clk = clk self.baudPeriod = baudPeriod self.softMaster = softMaster self.cmdQueue = [] self.cmdDriver = StreamDriverMaster( cmd, lambda: self.cmdQueue.pop(0) if self.cmdQueue and (random.random() < (1.0 / 10.0)) else None, clk, reset)
def __init__(self, name, parent, cmd, rsp, clk, reset): Infrastructure.__init__(self, name, parent) StreamDriverMaster(cmd, self.genCmd, clk, reset) self.nonZeroRspCounter = 0 self.cmdRandomizer = BoolRandomizer() self.writeRandomizer = BoolRandomizer() self.burstRandomizer = BoolRandomizer() self.lastAddr = 0 self.closeIt = False self.ram = bytearray(b'\x00' * (1 << (9 + 2 + 2 + 1))) self.scorboard = ScorboardInOrder("scoreboard", self) StreamDriverSlave(rsp, clk, reset) # rsp.ready <= 1 StreamMonitor(rsp, self.scorboard.uutPush, clk, reset)
def initPort(self, bmbId, bmb, addressRange, lengthMin, lengthMaxAll, clk, reset): lengthMax = min(1 << len(bmb.cmd.payload.fragment_length), lengthMaxAll) doCmdRand = BoolRandomizer() doCmdRand.probLow = 0.1 doCmdRand.probHigh = 0.5 cmdTasks = Queue() rspTasks = Queue() bytePerBeat = len(bmb.cmd.payload.fragment_data) / 8 def genNewCmd(): length = random.randint(1, (lengthMax // lengthMin)) * lengthMin if self.doWriteInit: address = self.writeInitAddress self.writeInitAddress += length else: address = (random.randint( 0, addressRange // lengthMaxAll // len(self.bmbs) - 1) * len(self.bmbs) + bmbId) * lengthMaxAll write = random.random() < 0.5 or self.doWriteInit beatCount = (length + bytePerBeat - 1) // bytePerBeat context = randBits(len(bmb.cmd.payload.fragment_context)) print("* " + str(context) + " " + str(length) + " " + str(bytePerBeat) + " " + str(beatCount)) source = 0 if not write: cmd = Transaction() cmd.last = True cmd.fragment_source = source cmd.fragment_opcode = 0 cmd.fragment_address = address cmd.fragment_length = length - 1 cmd.fragment_data = randBits(len( bmb.cmd.payload.fragment_data)) cmd.fragment_mask = randBits(len( bmb.cmd.payload.fragment_mask)) cmd.fragment_context = context cmdTasks.put(cmd) # print("*** R" + str(bmbId) + " " + hex(cmd.fragment_context)) for beat in range(beatCount): rsp = Transaction() rsp.last = beat == beatCount - 1 rsp.fragment_source = source rsp.fragment_context = context rsp.fragment_opcode = 0 rsp.fragment_data = self.ram.read( address + beat * bytePerBeat, bytePerBeat) # print("*** " + str(bmbId) + " " + hex(rsp.fragment_context)) rspTasks.put(rsp) else: rsp = Transaction() rsp.last = True rsp.fragment_source = source rsp.fragment_context = context rsp.fragment_opcode = 0 rsp.fragment_data = None rspTasks.put(rsp) # print("*** " + str(bmbId) + " " + hex(rsp.fragment_context)) for beat in range(beatCount): cmd = Transaction() cmd.last = beat == beatCount - 1 cmd.fragment_opcode = 1 cmd.fragment_address = address cmd.fragment_length = length - 1 cmd.fragment_source = source cmd.fragment_context = context cmd.fragment_data = randBits( len(bmb.cmd.payload.fragment_data)) if self.doWriteInit: cmd.fragment_mask = ( 1 << len(bmb.cmd.payload.fragment_mask)) - 1 else: cmd.fragment_mask = randBits( len(bmb.cmd.payload.fragment_mask)) cmdTasks.put(cmd) # print("*** W " + str(bmbId) + " " + hex(cmd.fragment_context) + " " + str(length)) self.ram.write(address + beat * bytePerBeat, bytePerBeat, cmd.fragment_data, cmd.fragment_mask) if self.writeInitAddress >= addressRange: self.writeInitAddress = False def createCmd(): if doCmdRand.get(): while cmdTasks.empty(): if not self.run: return None genNewCmd() return cmdTasks.get() def checkRsp(trans): assert not rspTasks.empty() trans.assertEqualRef(rspTasks.get()) if trans.last: self.progress[bmbId] += 1 if self.progress[bmbId] == 10000: self.hold -= 1 if self.hold == 0: raise TestSuccess() StreamDriverMaster(bmb.cmd, createCmd, clk, reset) StreamMonitor(bmb.rsp, checkRsp, clk, reset) StreamDriverSlave(bmb.rsp, clk, reset).randomizer.probLow = 0.5
def test1(dut): dut.log.info("Cocotb test boot") random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(simulationSpeedPrinter(dut.clk)) axiMasters = [Axi4(dut, "axiMasters_" + str(i)) for i in range(3)] axiSlaves = [Axi4(dut, "axiSlaves_" + str(i)) for i in range(4)] masterHandles = [] idToWrites = [[] for i in range(16)] # Instanciate master side for idx, axiMaster in enumerate(axiMasters): masterHandle = MasterHandle(idx, idToWrites) masterHandles.append(masterHandle) # Read StreamDriverMaster(axiMaster.ar, masterHandle.genReadCmd, dut.clk, dut.reset) StreamDriverSlave(axiMaster.r, dut.clk, dut.reset) StreamMonitor(axiMaster.r, masterHandle.onReadRsp, dut.clk, dut.reset) # Write StreamDriverMaster(axiMaster.aw, masterHandle.genWriteCmd, dut.clk, dut.reset) StreamDriverMaster(axiMaster.w, masterHandle.genWriteData, dut.clk, dut.reset) StreamDriverSlave(axiMaster.b, dut.clk, dut.reset) StreamMonitor(axiMaster.b, masterHandle.onWriteRsp, dut.clk, dut.reset) # instanciate slave side for idx, axiSlave in enumerate(axiSlaves): axiSlave.r.payload.hid <= 0 axiSlave.b.payload.hid <= 0 slaveHandle = SlaveHandle(idx, idToWrites) # Read StreamDriverSlave(axiSlave.ar, dut.clk, dut.reset) StreamDriverMaster(axiSlave.r, slaveHandle.genReadRsp, dut.clk, dut.reset) StreamMonitor(axiSlave.ar, slaveHandle.onReadCmd, dut.clk, dut.reset) # Write StreamMonitor(axiSlave.aw, slaveHandle.onWriteCmd, dut.clk, dut.reset) StreamDriverSlave(axiSlave.aw, dut.clk, dut.reset) StreamMonitor(axiSlave.w, slaveHandle.onWriteData, dut.clk, dut.reset) StreamDriverSlave(axiSlave.w, dut.clk, dut.reset) StreamDriverMaster(axiSlave.b, slaveHandle.genWriteRsp, dut.clk, dut.reset) # Run until completion while True: yield RisingEdge(dut.clk) done = True for handle in masterHandles: if not handle.isCompleted(): done = False for l in idToWrites: if l: done = False if done: break yield Timer(1000 * 10) dut.log.info("Cocotb test done")