Skip to content

Instantly share code, notes, and snippets.

@josyb
Created September 17, 2015 13:23
Show Gist options
  • Save josyb/d414d8670006df5ce0d9 to your computer and use it in GitHub Desktop.
Save josyb/d414d8670006df5ce0d9 to your computer and use it in GitHub Desktop.
def array_2(clk, reset, D, Q):
''' testing a 2-dimensional Array
just making a simple pipeline
'''
mt = myhdl.Array( (4, 3,), myhdl.Signal( myhdl.intbv(0)[len(D):]))
@myhdl.always_comb
def rtlcomb():
Q.next = mt[3][2]
@myhdl.always_seq( clk.posedge, reset = reset)
def rtlreg():
mt[0][0].next = D
mt[0][1:].next = mt[0][:2]
for i in range(1,4):
mt[i][0].next = mt[i-1][2]
mt[i][1:].next = mt[i][:2]
return rtlcomb, rtlreg
def test_array_2():
clk = myhdl.Signal( bool( 0 ))
reset = myhdl.ResetSignal( 0, active = 1, async = True)
D, Q = [myhdl.Signal( myhdl.intbv(0)[8:]) for _ in range(2)]
assert myhdl.conversion.analyze(array_2, clk, reset, D, Q ) == 0
def tb_array_2():
clk = myhdl.Signal( bool( 0 ))
reset = myhdl.ResetSignal( 0, active = 1, async = True)
D, Q = [myhdl.Signal( myhdl.intbv(0)[8:]) for _ in range(2)]
tbdut = array_2(clk, reset, D, Q )
tCK = 10
RESETLENGTH = 35
@myhdl.instance
def genreset():
reset.next = 1
yield myhdl.delay( RESETLENGTH )
reset.next = 0
@myhdl.instance
def genclk():
while True:
clk.next = 1
yield myhdl.delay( int( tCK // 2 ))
clk.next = 0
yield myhdl.delay( tCK - int( tCK // 2 ))
@myhdl.instance
def stimulus():
D.next = 0
idxin = 1
idxout = 1
for i in range(5):
yield clk.posedge
yield myhdl.delay( int( tCK // 4 ))
for i in range( 12 ):
D.next = idxin
idxin += 1
yield clk.posedge
yield myhdl.delay( int( tCK // 4 ))
for i in range( 16 ):
D.next = idxin
idxin += 1
yield clk.posedge
print( Q )
assert Q == idxout
idxout += 1
yield myhdl.delay( int( tCK // 4 ))
raise myhdl.StopSimulation
return tbdut, genreset, genclk, stimulus
def test_tb_array_2():
assert myhdl.conversion.verify( tb_array_2 ) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment