class JPEGTestBench(object): def __init__(self, dut, debug=True): self.dut = dut self.master = OPBMaster(dut, "OPB", dut.CLK) self.monitor = OutputMonitor(self.dut) @cocotb.coroutine def initialise(self): cocotb.fork(Clock(self.dut.CLK, 100).start()) self.dut.RST = 1 for i in range(10): yield RisingEdge(self.dut.CLK) self.dut.RST = 0 yield RisingEdge(self.dut.CLK) self.dut.log.info("Programming Luminance ROM...") for index, value in enumerate(ROM_LUM): yield self.master.write(QUANTIZER_RAM_LUM + index*4, value) self.dut.log.info("Programming Chrom ROM...") for index, value in enumerate(ROM_CHROM): yield self.master.write(QUANTIZER_RAM_CHR + index*4, value) self.dut.log.info("JPEG Encoder initialised") @cocotb.coroutine def encode(self, image): yield self.master.write(ENC_START_REG, JPEG_RGB | JPEG_ENABLE) width, height = image.size pixels = image.load() yield self.master.write(IMAGE_SIZE_REG, (width<<16) | height) for y in range(height): for x in range(width): r, g, b = pixels[x, y] self.dut.iram_wdata = ((b<<16) | (g<<8) | r) self.dut.iram_wren = 1 while True: yield RisingEdge(self.dut.CLK) if not int(self.dut.iram_fifo_afull): break self.dut.iram_wren = 0 self.dut.log.info("Waiting for encoding to complete") while True: result = yield self.master.read(ENC_STS_REG) if int(result) == JPEG_DONE: break
def initial_test(dut): cocotb.fork(Clock(dut.CLK, 100).start()) master = OPBMaster(dut, "OPB", dut.CLK) dut.RST = 1 for i in range(10): yield RisingEdge(dut.CLK) dut.RST = 0 yield RisingEdge(dut.CLK) dut.log.info("Out of reset") yield master.read(0) yield master.write(0, 0xFFFFFFFF) result = yield master.read(0) dut.log.info(repr(result))
def __init__(self, dut, debug=True): self.dut = dut self.master = OPBMaster(dut, "OPB", dut.CLK) self.monitor = OutputMonitor(self.dut)