def pinsecClockGen(dut): cocotb.fork(ClockDomainAsyncReset(dut.io_axiClk, dut.io_asyncReset, 7500)) cocotb.fork(ClockDomainAsyncReset(dut.io_vgaClk, None, 40000)) # cocotb.fork(axiClkLogger(dut.uut)) core = dut.uut.axi_core.core logger = PinsecLogger() StreamMonitor(Stream(core, "dCmd"), logger.logDCmd, dut.io_axiClk, dut.io_asyncReset) StreamMonitor(Stream(core, "dRsp"), logger.logDRsp, dut.io_axiClk, dut.io_asyncReset)
def test1(dut): cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset,1000)) cocotb.fork(simulationSpeedPrinter(dut.clk)) cocotb.fork(SimulationTimeout(1000*20e3)) apb = Apb3(dut, "io_apb", dut.clk) apb.idle() spi = SpiSlave(dut, "io_spi") spiCtrl = SpiSlaveMaster(spi) yield Timer(5000) yield RisingEdge(dut.clk) yield testIt(apb,dut.io_interrupt, spiCtrl, 0, 0) yield restart(dut) yield testIt(apb,dut.io_interrupt, spiCtrl, 0, 1) yield restart(dut) yield testIt(apb,dut.io_interrupt, spiCtrl, 1, 0) yield restart(dut) yield testIt(apb,dut.io_interrupt, spiCtrl, 1, 1)
def test1(dut): cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset, 100000)) cocotb.fork(simulationSpeedPrinter(dut.clk)) baudPeriod = 2500000 sclInterconnect = OpenDrainInterconnect() sclInterconnect.addHardDriver(dut.io_i2c_scl_write) sclInterconnect.addHardReader(dut.io_i2c_scl_read) sdaInterconnect = OpenDrainInterconnect() sdaInterconnect.addHardDriver(dut.io_i2c_sda_write) sdaInterconnect.addHardReader(dut.io_i2c_sda_read) dut.io_config_samplingClockDivider <= 3 dut.io_config_timerClockDivider <= 24 softMaster = I2cSoftMaster(sclInterconnect.newSoftConnection(), sdaInterconnect.newSoftConnection(), baudPeriod, dut.clk) slaveThread = fork( SlaveThread(sclInterconnect.newSoftConnection(), sdaInterconnect.newSoftConnection(), dut.clk, baudPeriod)) masterThread = fork( MasterThread(Stream(dut, "io_cmd"), Flow(dut, "io_rsp"), dut.clk, dut.reset, baudPeriod, softMaster).run()) yield masterThread.join()
def jtagTest(dut): dut.log.info("Cocotb test boot") random.seed(0) cocotb.fork(simulationSpeedPrinter(dut.io_axiClk)) yield loadIHex(dut,"e:/vm/share/pinsec_test.hex",dut.io_axiClk,dut.io_asyncReset) cocotb.fork(ClockDomainAsyncReset(dut.io_axiClk, dut.io_asyncReset)) jtag = JtagMaster(Bundle(dut,"io_jtag"),4000,4) yield Timer(1000*50) yield jtag.goToIdle() yield Timer(1000*8) # Check rom write/read via jtag yield jtagBridgeWrite(jtag,0x3000,0x11223344,4) yield jtagBridgeWrite(jtag,0x3002,0x00550000,1) yield jtagBridgeReadAssert(jtag,0x3000,4,0x11553344) yield jtagBridgeReadAssert(jtag,0x3002,2,0x1155) # Check RISCV APB debug module via jtag yield jtagBridgeWrite(jtag,0xF00F0200,1 << 17,4) #halt CPU yield jtagBridgeReadAssert(jtag,0xF00F0200,4,(1 << 1),0x0F) yield jtagBridgeWrite(jtag,0xF00F0008,0x99887766,4) #write R2 yield jtagBridgeReadAssert(jtag,0xF00F0008,4,0x99887766) yield Timer(1000*500) dut.log.info("Cocotb test done")
def test1(dut): dut.log.info("Cocotb test boot") random.seed(0) from cocotblib.misc import cocotbXHack cocotbXHack() cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) threads = [] threads.append(cocotb.fork(Fifo(dut).run())) threads.append(cocotb.fork(Fork(dut).run())) threads.append(cocotb.fork(DispatcherInOrder(dut).run())) threads.append(cocotb.fork(StreamFlowArbiter(dut).run())) threads.append(cocotb.fork(ArbiterInOrder(dut).run())) threads.append(cocotb.fork(ArbiterLowIdPortFirst(dut).run())) threads.append(cocotb.fork(ArbiterRoundRobin(dut).run())) threads.append(cocotb.fork(ArbiterLowIdPortNoLockFirst(dut).run())) threads.append(cocotb.fork(ArbiterLowIdPortFragmentLockFirst(dut).run())) for thread in threads: yield thread.join() # # # yield fork dut.log.info("Cocotb test done")
def test1(dut): dut.log.info("Cocotb test boot") random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, None)) for i in range(0,1000): randSignal(dut.io_conds_0) randSignal(dut.io_conds_1) randSignal(dut.io_conds_2) randSignal(dut.io_conds_3) randSignal(dut.io_conds_4) randSignal(dut.io_conds_5) randSignal(dut.io_conds_6) randSignal(dut.io_conds_7) randSignal(dut.io_data_0 ) randSignal(dut.io_data_1 ) randSignal(dut.io_data_2 ) randSignal(dut.io_data_3 ) randSignal(dut.io_data_4 ) randSignal(dut.io_data_5 ) randSignal(dut.io_data_6 ) randSignal(dut.io_data_7 ) randSignal(dut.io_data_8 ) randSignal(dut.io_data_9 ) randSignal(dut.io_data_10) randSignal(dut.io_data_11) yield RisingEdge(dut.clk) ref = Ref(dut) assertEquals(ref.io_outDefault,dut.io_outDefault,"io_outDefault") assertEquals(ref.io_outComplex, dut.io_outComplex, "io_outComplex") yield Timer(1) assertEquals(ref.io_outComplex, dut.io_outRegComplex, "io_outRegComplex") dut.log.info("Cocotb test done")
def test1(dut): cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset, 1000)) cocotb.fork(simulationSpeedPrinter(dut.clk)) # cocotb.fork(SimulationTimeout(1000 * 20e3)) cocotb.fork(debugFilter(dut)) dut.io_parallelIn <= 0x10 for i in xrange(200): yield RisingEdge(dut.clk) dut.io_parallelIn <= 0x70 for i in xrange(1000): yield RisingEdge(dut.clk) dut.io_parallelIn <= 0x80 for i in xrange(1000): yield RisingEdge(dut.clk) dut.io_parallelIn <= 0x90 for i in xrange(1000): yield RisingEdge(dut.clk) dut.io_parallelIn <= 0xF0 for i in xrange(200): yield RisingEdge(dut.clk)
def test1(dut): cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset, 1000)) cocotb.fork(simulationSpeedPrinter(dut.clk)) # cocotb.fork(SimulationTimeout(1000 * 20e3)) dut.io_step <= 1 for i in xrange(8000): yield RisingEdge(dut.clk)
def test1(dut): dut.log.info("Cocotb test boot") random.seed(0) cocotb.fork(simulationSpeedPrinter(dut.io_axiClk)) yield loadIHex(dut, "../hex/timer.hex", dut.io_axiClk, dut.io_asyncReset) cocotb.fork(ClockDomainAsyncReset(dut.io_axiClk, dut.io_asyncReset)) yield assertions(dut) yield Timer(1000 * 10) dut.log.info("Cocotb test done")
def test1(dut): cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset, 1000)) cocotb.fork(simulationSpeedPrinter(dut.clk)) dut.io_en <= False for i in xrange(20): yield RisingEdge(dut.clk) dut.io_en <= True dut.io_step <= 40 for i in xrange(8000): yield RisingEdge(dut.clk)
def test1(dut): random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(simulationSpeedPrinter(dut.clk)) cocotb.fork(SimulationTimeout(1000*16000)) yield driveAndCheck(dut, "setValueA",0x11,8,dut.io_valueA) yield driveAndCheck(dut, "setValueB", 0x22334455, 32, dut.io_valueB) yield driveAndCheck(dut, "setValueC", 0x66778899AABB, 48, dut.io_valueC) yield driveAndCheck(dut, "setValueB", 0xCAFEF00D, 32, dut.io_valueB) yield Timer(1000*20)
def test1(dut): dut.log.info("Cocotb test boot") #random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) ref = Ref(dut) for i in range(0, 1000): randSignal(dut.enable) yield RisingEdge(dut.clk) assertEquals(ref.getGray(), dut.gray, "gray") dut.log.info("Cocotb test done")
def test1(dut): random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(simulationSpeedPrinter(dut.clk)) cocotb.fork(SimulationTimeout(1000 * 2000)) phaseManager = PhaseManager() phaseManager.setWaitTasksEndTime(1000 * 200) DriverAgent("driver", phaseManager, dut) MonitorAgent("monitor", phaseManager, dut) yield phaseManager.run()
def test1(dut): dut.log.info("Cocotb test boot") cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) outA_ref = 0 outB_ref = 0 for i in range(0,1000): randSignal(dut.io_inA) randSignal(dut.io_inB) yield RisingEdge(dut.clk) assertEquals(outA_ref,dut.io_outA,"io_outA") assertEquals(outB_ref, dut.io_outB, "io_outB") outA_ref = truncUInt(outA_ref + int(dut.io_inA), dut.io_outA) outB_ref = truncUInt(outB_ref + int(dut.io_inB), dut.io_outB) dut.log.info("Cocotb test done")
def test1(dut): dut.log.info("Cocotb test boot") from cocotblib.misc import cocotbXHack cocotbXHack() #random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, None)) for i in range(0, 1000): randSignal(dut.io_inSIntA) randSignal(dut.io_inSIntB) yield Timer(1000) ref = Ref(dut) assertEquals(dut.io_outSInt, dut.io_outSIntRef, "io_outSInt") dut.log.info("Cocotb test done")
def test1(dut): dut.log.info("Cocotb test boot") from cocotblib.misc import cocotbXHack cocotbXHack() random.seed(0) cocotb.fork(simulationSpeedPrinter(dut.clk)) # elements = [a for a in dut.AhbRam if a._name.startswith("")] # for e in elements: # print(str(e._name)) # while True: # dut.AhbRam.ram_port1_enable <= 1 # dut.AhbRam.ram_port1_mask <= 0xF # dut.AhbRam.ram_port1_address <= 0X90 # dut.AhbRam.ram_port1_data <= 0xCAFEF00D # # dut.AhbRam.reset <= 1 # dut.AhbRam.ram_port1_enable <= 1 # yield Timer(1000) # dut.AhbRam.ram_port1_enable <= 1 # dut.AhbRam.clk <= 0 # yield Timer(1000) # dut.AhbRam.ram_port1_enable <= 1 # dut.AhbRam.clk <= 1 # yield Timer(1000) # dut.AhbRam.ram_port1_enable <= 0 # yield Timer(1000) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) readQueue = Queue() ahb = Bundle(dut, "ahb") driver = AhbLite3MasterDriver( ahb, AhbLite3TraficGeneratorWithMemory(10, 32, readQueue), dut.clk, dut.reset) checker = AhbLite3MasterReadChecker(ahb, readQueue, dut.clk, dut.reset) terminaison = AhbLite3Terminaison(ahb, dut.clk, dut.reset) while True: yield RisingEdge(dut.clk) if checker.counter > 4000: break dut.log.info("Cocotb test done")
def test1(dut): dut.log.info("Cocotb test boot") from cocotblib.misc import cocotbXHack cocotbXHack() queueTx = Queue() queueRx = Queue() cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(sendRandomPackets(dut, queueTx, queueRx)) cocotb.fork(checkTx(dut, queueTx)) cocotb.fork(txToRxBypass(dut)) cocotb.fork(simulationSpeedPrinter(dut.clk)) yield checkCtrlReadedBytes(dut, queueRx) dut.log.info("Cocotb test done")
def test1(dut): dut.log.info("Cocotb test boot") random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) uutModel = UutModel(dut) for i in range(0, 5000): randSignal(dut.io_bus_aw_valid) randSignal(dut.io_bus_aw_payload_addr) randSignal(dut.io_bus_w_valid) randSignal(dut.io_bus_w_payload_data) randSignal(dut.io_bus_ar_valid) randSignal(dut.io_bus_ar_payload_addr) randSignal(dut.io_bus_b_ready) randSignal(dut.io_bus_r_ready) yield RisingEdge(dut.clk) dut.log.info("Cocotb test done")
def test1(dut): dut.log.info("Cocotb test boot") from cocotblib.misc import cocotbXHack cocotbXHack() #random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) while True: yield RisingEdge(dut.clk) if int(dut.io_internalClkCounter) == 2: break counter = 3 for i in range(0,1000): yield RisingEdge(dut.clk) yield RisingEdge(dut.clk) assertEquals(counter, dut.io_internalClkCounter, "io_internalClkCounter") counter = truncUInt(counter + 1, dut.io_internalClkCounter) dut.log.info("Cocotb test done")
def test1(dut): random.seed(0) from cocotblib.misc import cocotbXHack cocotbXHack() cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(simulationSpeedPrinter(dut.clk)) phaseManager = PhaseManager() phaseManager.setWaitTasksEndTime(1000 * 200) StreamFifoTester("fifoA", phaseManager, Stream(dut, "fifoAPush"), Stream(dut, "fifoAPop"), bundleAGen, 3000, dut.clk, dut.reset).createInfrastructure() StreamFifoTester("fifoB", phaseManager, Stream(dut, "fifoBPush"), Stream(dut, "fifoBPop"), bundleAGen, 3000, dut.clk, dut.reset).createInfrastructure() yield phaseManager.run()
def test1(dut): cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset, 1000)) cocotb.fork(simulationSpeedPrinter(dut.clk)) cocotb.fork(SimulationTimeout(1000 * 20e3)) apb = Apb3(dut, "io_apb", dut.clk) apb.idle() spi = SpiMaster(dut, "io_spi") slaveQueue = Queue() yield Timer(5000) yield RisingEdge(dut.clk) apbThread = fork(apbAgent(apb, slaveQueue)) spiThread = fork(spiSlaveAgent(spi, slaveQueue, dut.clk)) yield apbThread.join()
def test1(dut): random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(simulationSpeedPrinter(dut.clk)) cocotb.fork(SimulationTimeout(1000 * 8000)) axiLite = AxiLite4(dut, "io_axiLite") master = AxiLite4Master(axiLite, dut.clk, dut.reset) yield RisingEdge(dut.clk) yield master.readAssert( 0x00, 0, 1, "wavePlayer.phase.run was read as True, but should be False") yield master.readAssert( 0x10, 1, 1, "wavePlayer.filter.bypass was read as False, but should be True") yield master.write(4, 0x80) yield master.write(0, 1) yield master.readAssert( 0x00, 1, 1, "wavePlayer.phase.run was read as False, but should be True") phaseValue = 0 for i in range(4): newValue = [0] yield master.read(0x8, newValue) assert newValue[ 0] > phaseValue, "wavePlayer.phase.value doesn't seem to increment" phaseValue = newValue[0] yield RisingEdge(dut.clk) yield analyseFreq(dut, 0x200) yield Timer(1000 * 2000) yield master.write(0x14, 0x10) yield master.write(0x10, 0) yield master.readAssert( 0x10, 0, 1, "wavePlayer.filter.bypass was read as True, but should be False") yield Timer(1000 * 2000) yield analyseFreq(dut, 0x200) yield Timer(1000 * 2000)
def do(self, iHexPath): loadIHex(iHexPath, self.rom) cocotb.fork(simulationSpeedPrinter(self.dut.clk)) cocotb.fork(ClockDomainAsyncReset(self.dut.clk, self.dut.reset)) cocotb.fork(self.driveMisc()) cocotb.fork(self.driveIRsp()) cocotb.fork(self.driveDRsp()) while True: yield RisingEdge(self.dut.clk) if int(self.dut.io_d_cmd_valid) == 1 and int( self.dut.io_d_cmd_payload_address) == 0xFFFFFFFC: if int(self.dut.io_d_cmd_payload_data) != 0x00000001: print("ERROR") raise TestFailure( "RISCV test %s fail with %d" % (iHexPath, int(self.dut.io_d_cmd_payload_data))) else: raise TestSuccess( "RISCV test %s pass with %d" % (iHexPath, int(self.dut.io_d_cmd_payload_data)))
def test1(dut): dut.log.info("Cocotb test boot") from cocotblib.misc import cocotbXHack cocotbXHack() random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(simulationSpeedPrinter(dut.clk)) phaseManager = PhaseManager() phaseManager.setWaitTasksEndTime(1000 * 200) checker = Axi4SharedMemoryChecker("checker", phaseManager, Axi4Shared(dut, "io_axi"), 12, dut.clk, dut.reset) checker.idWidth = 2 checker.nonZeroReadRspCounterTarget = 2000 yield phaseManager.run() dut.log.info("Cocotb test done")
def test1(dut): dut.log.info("Cocotb test boot") random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(simulationSpeedPrinter(dut.clk)) drivers = [] checkers = [] for i in range(3): readQueue = Queue() ahb = Bundle(dut, "ahbMasters_" + str(i)) drivers.append( AhbLite3MasterDriver( ahb, AhbLite3TraficGeneratorWithMemory(12, 32, readQueue, i), dut.clk, dut.reset)) checkers.append( AhbLite3MasterReadChecker(ahb, readQueue, dut.clk, dut.reset)) # AhbLite3MasterIdle(Bundle(dut, "ahbMasters_1")) # AhbLite3MasterIdle(Bundle(dut, "ahbMasters_2")) AhbLite3SlaveMemory(Bundle(dut, "ahbSlaves_0"), 0x000, 0x400, dut.clk, dut.reset) AhbLite3SlaveMemory(Bundle(dut, "ahbSlaves_1"), 0x400, 0x400, dut.clk, dut.reset) AhbLite3SlaveMemory(Bundle(dut, "ahbSlaves_2"), 0x800, 0x400, dut.clk, dut.reset) AhbLite3SlaveMemory(Bundle(dut, "ahbSlaves_3"), 0xC00, 0x400, dut.clk, dut.reset) while True: yield RisingEdge(dut.clk) done = True for checker in checkers: if checker.counter < 1000: done = False if done: break dut.log.info("Cocotb test done")
def test1(dut): random.seed(0) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(simulationSpeedPrinter(dut.clk)) cocotb.fork(SimulationTimeout(1000 * 8000)) phaseManager = PhaseManager() phaseManager.setWaitTasksEndTime(1000 * 200) driver = DriverAgent("driver", phaseManager, dut) monitor = MonitorAgent("monitor", phaseManager, dut) for i in range(1 << 8): dut.io_memWrite_valid <= 1 dut.io_memWrite_payload_address <= i dut.io_memWrite_payload_data <= randBits(32) yield RisingEdge(dut.clk) dut.io_memWrite_valid <= 0 driver.memInitDone = True yield phaseManager.run()
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")
def test1(dut): # random.seed(13) cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset,100000)) cocotb.fork(simulationSpeedPrinter(dut.clk)) sclInterconnect = OpenDrainInterconnect() sclInterconnect.addHardDriver(dut.io_i2c_scl_write) sclInterconnect.addHardReader(dut.io_i2c_scl_read) sdaInterconnect = OpenDrainInterconnect() sdaInterconnect.addHardDriver(dut.io_i2c_sda_write) sdaInterconnect.addHardReader(dut.io_i2c_sda_read) dut.io_config_samplingClockDivider <= 3 dut.io_config_timeout <= 25*10-1 dut.io_config_tsuDat <= 4 softMaster = I2cSoftMaster(sclInterconnect.newSoftConnection(), sdaInterconnect.newSoftConnection(), 2500000,dut.clk) masterCmds = [] slaveCmds = [] slaveRsps = [] masterRsps = [] masterCmds.append(10) for frameId in range(50): masterCmds.append("start") slaveCmds.append("start") while True: for bitId in range(randInt(1,10)): masterValue = random.uniform(0,1) > 0.5 slaveValue = random.uniform(0,1) > 0.5 slaveEnable = random.uniform(0,1) > 0.5 value = masterValue and (slaveValue or not slaveEnable) masterCmds.append(masterValue) slaveRsps.append(slaveValue if slaveEnable else "Z") slaveCmds.append("drive") slaveCmds.append(value) masterRsps.append(value) if random.uniform(0,1) < 0.1: slaveCmds.append("drive") slaveRsps.append(random.uniform(0,1) > 0.5) masterCmds.append(20) masterCmds.append("drop") masterCmds.append(randInt(1,10)) slaveCmds.append("drop") break slaveRsps.append("Z") if random.uniform(0,1) < 0.5: masterCmds.append("stop") slaveCmds.append("drive") slaveCmds.append(False) slaveCmds.append("stop") masterCmds.append(randInt(1,10)) break masterCmds.append("restart") slaveCmds.append("drive") slaveCmds.append(True) slaveCmds.append("restart") masterThread = fork(i2cMasterThread(softMaster, masterCmds,masterRsps)) slaveThread = fork(i2cSlaveThread(Bundle(dut,"io_bus_cmd"), Bundle(dut,"io_bus_rsp"),slaveCmds,slaveRsps, dut.clk)) yield masterThread.join() cocotb.fork(SimulationTimeout(100 * 2500000)) while True: if not slaveCmds and not slaveRsps and not masterRsps: break yield Timer(10000)
def pixelSolverTester(dut): dut.log.info("Cocotb test boot") speedBench = True # Create Agents cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset)) cocotb.fork(simulationSpeedPrinter(dut.clk)) cycleCounter = [0] cocotb.fork(cycleCounterAgent(dut, cycleCounter)) cmdThread = cocotb.fork(cmdAgent(dut, 1.0 if speedBench else 0.5)) resultArray = [[0 for x in xrange(resX)] for y in xrange(resY)] rspThread = cocotb.fork( rspAgent(dut, resultArray, 1.0 if speedBench else 0.5)) # Wait everybody finish its job yield cmdThread.join() yield rspThread.join() # Flush the mandelbrot into a text file uutString = reduce(lambda a, b: a + "\n" + b, [str(e) for e in resultArray]) uutFile = open('mandelbrot.uut', 'w') uutFile.write(uutString) uutFile.flush() uutFile.close() # Count how many iteration were done iterationCount = 0 for y in xrange(resY): for x in xrange(resX): iterationCount += resultArray[y][x] + 1 print("Done in %d cycles => %f iteration/cycle" % (cycleCounter[0], 1.0 * iterationCount / cycleCounter[0])) # Display the mandelbrot picture in a GUI from Tkinter import Tk, Canvas, PhotoImage zoomFactor = 4 pictureWidth, pictureHeight = resX * zoomFactor, resY * zoomFactor window = Tk() canvas = Canvas(window, width=pictureWidth, height=pictureHeight, bg="#000000") canvas.pack() img = PhotoImage(width=pictureWidth, height=pictureHeight) canvas.create_image((pictureWidth / 2, pictureHeight / 2), image=img, state="normal") for y in xrange(resY): for x in xrange(resX): r, g, b = 0, 0, 0 r = resultArray[y][x] << 4 for zy in xrange(zoomFactor): for zx in xrange(zoomFactor): img.put("#%02x%02x%02x" % (r, g, b), (x * zoomFactor + zx, y * zoomFactor + zy)) window.mainloop() # Check differences with the reference image refFile = open('mandelbrot.ref', 'r') refString = refFile.read() if refString != uutString: raise TestFailure( "FAIL because of picture missmatch, see mandelbrot.ref vs mandelbrot.uut" )
def test1(dut): cocotb.fork(ClockDomainAsyncReset(dut.clk, dut.reset,100000)) cocotb.fork(simulationSpeedPrinter(dut.clk)) cocotb.fork(SimulationTimeout(2000 * 2.5e6)) sclInterconnect = OpenDrainInterconnect() sclInterconnect.addHardDriver(dut.io_i2c_scl_write) sclInterconnect.addHardReader(dut.io_i2c_scl_read) sdaInterconnect = OpenDrainInterconnect() sdaInterconnect.addHardDriver(dut.io_i2c_sda_write) sdaInterconnect.addHardReader(dut.io_i2c_sda_read) softMaster = I2cSoftMaster(sclInterconnect.newSoftConnection(), sdaInterconnect.newSoftConnection(), 2500000,dut.clk) apb = Apb3(dut, "io_apb", dut.clk) apb.idle() @coroutine def txData(valid = False, enable = False, value = 0xFF, repeat = False, disableOnConflict = False): yield apb.write(0, (valid << 8) | (enable << 9) | (value << 0) | (repeat << 10) | (disableOnConflict << 11)) @coroutine def txAck(valid=False, enable=False, value=0x1, repeat=False, disableOnConflict=False): yield apb.write(4, (valid << 8) | (enable << 9) | (value << 0) | (repeat << 10) | (disableOnConflict << 11)) @coroutine def rxDataConfig(listen = False): yield apb.write(8, listen << 9) @coroutine def rxAckConfig(listen = False): yield apb.write(12, listen << 9) @coroutine def rxDataValue(expected): yield apb.readAssertMasked(8, 0x100 | expected, 0x1FF) @coroutine def rxAckValue(expected): yield apb.readAssertMasked(12, 0x100 | expected, 0x101) @coroutine def rxDataNotValid(): yield apb.readAssertMasked(8, 0, 0x100) @coroutine def rxAckNotValid(): yield apb.readAssertMasked(12, 0, 0x100) @coroutine def addressFilter(index, enable = False, is10Bits = False, value = 0): yield apb.write(136+index*4, (enable << 15) | (is10Bits << 14) | (value << 0)) @coroutine def addressFilterHits(value): yield apb.readAssertMasked(128, value, 0xFFFFFFFF) @coroutine def idle(): yield txData(valid = True, repeat = True) yield txAck(valid=True, repeat=True) yield rxDataConfig(listen=False) yield rxAckConfig(listen=False) buffer = [0] yield apb.write(40, 3) #samplingClockDivider yield apb.write(44, 25*20-1) #timeout yield apb.write(48, 4) #tsuDat #Check idle controller yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0xAA, 0xAA) yield softMaster.sendBitCheck(False, False) yield softMaster.sendByteCheck(0x55, 0x55) yield softMaster.sendBitCheck(True, True) yield softMaster.sendStop() yield softMaster.wait(5) # Check simple txData yield idle() yield txData(valid = True, enable = True, value = 0x0F) yield rxDataConfig(listen=True) yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0xAA, 0x0A) yield softMaster.sendBitCheck(True, True) yield softMaster.sendStop() yield rxDataValue(0x0A) yield rxDataNotValid(); yield softMaster.wait(5) # Check simple txAck yield idle() yield txAck(valid=True, enable=True, value=False) yield rxAckConfig(listen=True) yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0xFF, 0xFF) yield softMaster.sendBitCheck(True, False) yield rxAckValue(False) yield txAck(valid=True, enable=True, value=True) yield softMaster.sendByteCheck(0x00, 0x00) yield softMaster.sendBitCheck(True, True) yield softMaster.sendStop() yield rxAckValue(True) yield softMaster.wait(5) # Check explicit idle controller yield idle() yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0xAA, 0xAA) yield softMaster.sendBitCheck(False, False) yield softMaster.sendByteCheck(0x55, 0x55) yield softMaster.sendBitCheck(True, True) yield softMaster.sendStop() yield softMaster.wait(5) # Check tx clock stretching yield idle() yield txData(valid=False) yield txAck(valid=False) yield softMaster.wait(2) yield softMaster.sendStart() txThread = fork(softMaster.sendByteCheck(0xAA, 0x0A)) yield softMaster.wait(10) yield txData(valid = True, enable = True, value = 0x0F) yield txThread.join() txThread = fork(softMaster.sendBitCheck(True, False)) yield softMaster.wait(10) yield txAck(valid=True, enable=True, value=False) yield txThread.join() txThread = fork(softMaster.sendByteCheck(0x55, 0x50)) yield softMaster.wait(10) yield txData(valid = True, enable = True, value = 0xF0) yield txThread.join() txThread = fork(softMaster.sendBitCheck(True, False)) yield softMaster.wait(10) yield txAck(valid=True, enable=True, value=False) yield txThread.join() yield txData(valid = True, enable = True, value = 0x8F) yield txAck(valid=True, enable=True, value=True) yield softMaster.sendByteCheck(0xF3, 0x83) yield softMaster.sendBitCheck(True, True) yield softMaster.sendStop() yield softMaster.wait(5) # Check rxData clock streching yield idle() yield rxDataConfig(listen=True) yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0x11, 0x11) yield softMaster.sendBitCheck(False, False) txThread = fork(softMaster.sendByteCheck(0x22, 0x22)) yield softMaster.wait(16) yield rxDataValue(0x11) yield txThread.join() yield rxDataValue(0x22) yield softMaster.sendBitCheck(True, True) yield softMaster.sendStop() yield softMaster.wait(5) # Check rxAck clock streching yield idle() yield rxAckConfig(listen=True) yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0x11, 0x11) yield softMaster.sendBitCheck(False, False) yield softMaster.sendByteCheck(0x22, 0x22) txThread = fork(softMaster.sendBitCheck(True, True)) yield softMaster.wait(16) yield rxAckValue(False) yield txThread.join() yield rxAckValue(True) yield softMaster.sendStop() yield softMaster.wait(5) #check txData repeat yield idle() yield txData(valid = True, enable = True, value = 0x0F,repeat = True) yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0x33, 0x03) yield softMaster.sendBitCheck(False, False) yield softMaster.sendByteCheck(0x44, 0x04) yield softMaster.sendBitCheck(False, False) yield softMaster.sendByteCheck(0x55, 0x05) yield softMaster.sendBitCheck(True, True) yield softMaster.sendStop() yield softMaster.wait(5) # check txAck repeat yield idle() yield txAck(valid=True, enable=True, value=0x0, repeat=True) yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0x33, 0x33) yield softMaster.sendBitCheck(True, False) yield softMaster.sendByteCheck(0x44, 0x44) yield softMaster.sendBitCheck(True, False) yield softMaster.sendByteCheck(0x55, 0x55) yield softMaster.sendBitCheck(True, False) yield softMaster.sendStop() yield softMaster.wait(5) #Check address filter yield idle() yield addressFilter(index = 2, enable = True, is10Bits = False, value = 0x63) yield addressFilter(index = 1, enable = True, is10Bits = True, value = 0x123) for i in range(2): #7bits yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0x63*2, 0x63*2) t = fork(softMaster.sendBitCheck(True, False)) yield softMaster.wait(5) yield addressFilterHits(1 << 2) yield txData(valid=True, enable=True, value=0xF0) yield txAck(valid=True, enable=True, value=False) yield t.join() yield softMaster.sendByteCheck(0x44, 0x40) yield txAck(valid=True, repeat=True) yield softMaster.sendBitCheck(True, True) yield softMaster.sendStop() yield softMaster.wait(5) #10bits yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0xF3,0xF3) yield softMaster.sendBitCheck(True, False) yield softMaster.sendByteCheck(0x23,0x23) t = fork(softMaster.sendBitCheck(True, False)) yield softMaster.wait(5) yield addressFilterHits(1 << 1) yield txData(valid=True, enable=True, value=0xF0) yield txAck(valid=True, enable=True, value=False) yield t.join() yield softMaster.sendByteCheck(0x44, 0x40) yield txAck(valid=True, repeat=True) yield softMaster.sendBitCheck(True, True) yield softMaster.sendStop() yield softMaster.wait(5) #10bits no trigger yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0xF3,0xF3) yield softMaster.sendBitCheck(True, False) yield softMaster.sendByteCheck(0x54,0x54) yield softMaster.sendBitCheck(True, True) yield addressFilterHits(0 << 1) yield softMaster.sendStop() yield softMaster.wait(5) #7bits no trigger yield softMaster.wait(2) yield softMaster.sendStart() yield softMaster.sendByteCheck(0x13,0x13) yield softMaster.sendBitCheck(True, True) yield addressFilterHits(0 << 1) yield softMaster.sendStop() yield softMaster.wait(5)