예제 #1
0
def test_lt24lcd(args=None):
    args = tb_default_args(args)

    clock = Clock(0, frequency=50e6)
    reset = Reset(0, active=0, async=True)
    glbl = Global(clock, reset)

    lcd_on = Signal(bool(0))
    lcd_resetn = Signal(bool(0))
    lcd_csn = Signal(bool(0))
    lcd_rs = Signal(bool(0))
    lcd_wrn = Signal(bool(0))
    lcd_rdn = Signal(bool(0))
    lcd_data = Signal(intbv(0)[16:])

    lcd = LT24Interface()
    resolution = lcd.resolution
    color_depth = lcd.color_depth
    # assign the ports to the interface
    lcd.assign(lcd_on, lcd_resetn, lcd_csn, lcd_rs, lcd_wrn,
               lcd_rdn, lcd_data)
    mvd = LT24LCDDisplay()

    @myhdl.block
    def bench_lt24lcdsys():
        tbdut = mm_lt24lcdsys(
            clock, reset, lcd_on, lcd_resetn,
            lcd_csn, lcd_rs, lcd_wrn, lcd_rdn, lcd_data
        )
        tbvd = mvd.process(glbl, lcd)   # LCD display model 
        tbclk = clock.gen()

        @instance
        def tbstim():
            yield reset.pulse(33)
            yield clock.posedge
            timeout = 33000
            while mvd.update_cnt < 3 and timeout > 0:
                yield delay(1000)
                timeout -= 1

            yield delay(100)
            print("{:<10d}: simulation real time {}".format(now(), mvd.get_time()))
            raise StopSimulation

        return tbdut, tbvd, tbclk, tbstim

    run_testbench(bench_lt24lcdsys)
예제 #2
0
def tb_lt24lcd_driver(args=None):
    clock = Clock(0, frequency=50e6)
    reset = Reset(0, active=1, async=False)
    glbl = Global(clock, reset)
    lcd = LT24Interface()
    display = LT24LCDDisplay()

    cmd = Signal(intbv(0)[8:])
    datalen = Signal(intbv(0, min=0, max=lcd.number_of_pixels+1))
    data = Signal(intbv(0)[16:])
    datasent = Signal(bool(0))
    datalast = Signal(bool(0))
    cmd_in_progress = Signal(bool(0))
    
    def _bench_lt24lcd_driver():
        tbdut = lt24lcd_driver(glbl, lcd, cmd, datalen, data,
                               datasent, datalast, cmd_in_progress,
                               maxlen=lcd.number_of_pixels)
        gtck = glbl_timer_ticks(glbl, tick_div=100)
        tbmdl = display.process(glbl, lcd)
        
        tbclk = clock.gen()
        
        @instance
        def tbstim():
            yield reset.pulse(111)
            yield clock.posedge

            # --------------------------------------------
            # send a column write command
            print("column write command")
            cmd.next = 0x2A
            bytes = [0, 0, 0, 239]
            data.next = bytes[0]
            datalen.next = 4 
            
            for ii in range(4):
                yield datasent.posedge
                data.next = bytes[ii+1] if ii < 3 else 0
            cmd.next = 0
            yield cmd_in_progress.negedge
            yield clock.posedge

            # --------------------------------------------
            # send a page address write command
            print("page address write command")
            cmd.next = 0x2B
            bytes = [0, 0, 1, 0x3F]
            data.next = bytes[0]
            datalen.next = 4

            for ii in range(4):
                yield datasent.posedge
                data.next = bytes[ii+1] if ii < 3 else 0
            cmd.next = 0
            yield cmd_in_progress.negedge
            yield clock.posedge

            # --------------------------------------------
            # write display memory, full update
            print("display update")
            cmd.next = 0x2C
            data.next = randint(0, data.max-1)
            datalen.next = lcd.number_of_pixels

            for ii in range(lcd.number_of_pixels):
                yield datasent.posedge
                data.next = randint(0, data.max-1)
                if (ii % 5000) == 0:
                    print("{} pixels xfer'd".format(ii))
            cmd.next = 0
            yield cmd_in_progress.negedge
            yield clock.posedge
            print("display update complete")
    
            # --------------------------------------------
            # @todo: verify the display received an image
            yield delay(100)

            raise StopSimulation
            
        return tbdut, tbmdl, tbclk, tbstim, gtck

    run_testbench(_bench_lt24lcd_driver)