Source

examples / mycores / aic23 / test_aic23.py

Full commit

from myhdl import *
from aic23_top import aic23_top
from i2s_model import i2s_model


def test_aic23():
    
    clock           = Signal(False)
    reset           = ResetSignal(True, active=0, async=True)
    au_in_r         = Signal(intbv(0)[32:])     
    au_in_l         = Signal(intbv(0)[32:])  
    au_out_r        = Signal(intbv(0)[32:])
    au_out_l        = Signal(intbv(0)[32:])
    mic_in          = Signal(intbv(0)[32:])      
    hp_out          = Signal(intbv(0)[32:])
    Ts              = Signal(False)
    AUDIO_BCLK      = Signal(False)
    AUDIO_DIN       = Signal(False)       
    AUDIO_DOUT      = Signal(False)      
    AUDIO_LRCIN     = Signal(False)     
    AUDIO_LRCOUT    = Signal(False)    
    AUDIO_MODE      = Signal(False)      
    AUDIO_CSN       = Signal(False)       
    AUDIO_SCLK      = Signal(False)       
    AUDIO_SDIN      = Signal(False)
    tst_pts         = Signal(intbv(0)[8:])

    auir, auil = [Signal(intbv(0)[32:]) for ii in (0,1)]
    auor, auol = [Signal(intbv(0)[32:]) for ii in (0,1)]

    def _test_aic():
        
        tb_i2s = i2s_model(AUDIO_LRCIN, AUDIO_LRCOUT, AUDIO_BCLK,
                           AUDIO_DIN, AUDIO_DOUT,
                           auir, auil, auor, auol)
        tb_dut = aic23_top(clock, reset, au_in_r, au_in_l, 
                       au_out_r, au_out_l, mic_in, hp_out, Ts,
                       AUDIO_BCLK, AUDIO_DIN, AUDIO_DOUT, 
                       AUDIO_LRCIN, AUDIO_LRCOUT, AUDIO_MODE,
                       AUDIO_CSN, AUDIO_SCLK, AUDIO_SDIN, tst_pts)

        @always(delay(2))
        def tb_clkgen():
            clock.next = not clock

        @always(delay(200))
        def tb_bclkgen():
            AUDIO_BLCK.next = not AUDIO_BCLK

        @instance
        def tb_stimulus():
            reset.next = False
            yield delay(100)
            reset.next = True
            yield clock.posedge

            for ii in range(333):
                yield delay(2000)

            raise StopSimulation
            
        return tb_stimulus, tb_clkgen, tb_i2s, tb_dut

    Simulation(traceSignals(_test_aic)).run()


if __name__ == '__main__':
    test_aic23()