Skip to content

Instantly share code, notes, and snippets.

@josyb
Last active September 14, 2015 14:05
Show Gist options
  • Save josyb/30dbccb626220b79ebe2 to your computer and use it in GitHub Desktop.
Save josyb/30dbccb626220b79ebe2 to your computer and use it in GitHub Desktop.
Issue with having to ad a 'delta'after clk,posedge
def array_3(clk, reset, Sel1, Sel2, Q):
''' testing a 2-dimensional Constant Array
'''
aoc = myhdl.Array( [[1,2,3], [4,5,6], [7,8,9]], myhdl.intbv(0)[len(Q):])
@myhdl.always_seq( clk.posedge, reset = reset)
def rtlreg():
Q.next = aoc[Sel2][Sel1]
return rtlreg
def test_array_3():
clk = myhdl.Signal( bool( 0 ))
reset = myhdl.ResetSignal( 0, active = 1, async = True)
Sel1 = myhdl.Signal( myhdl.intbv(0)[2:])
Sel2 = myhdl.Signal( myhdl.intbv(0)[2:])
Q = myhdl.Signal( myhdl.intbv(0)[4:])
assert myhdl.conversion.analyze(array_3, clk, reset, Sel1, Sel2, Q ) == 0
def tb_array_3():
clk = myhdl.Signal( bool( 0 ))
reset = myhdl.ResetSignal( 0, active = 1, async = True)
Sel1 = myhdl.Signal( myhdl.intbv(0)[2:])
Sel2 = myhdl.Signal( myhdl.intbv(0)[2:])
Q = myhdl.Signal( myhdl.intbv(0)[4:])
tbdut = array_3(clk, reset, Sel1, Sel2, 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():
Sel1.next = 2
Sel2.next = 2
for i in range(8):
yield clk.posedge
yield myhdl.delay( int( tCK // 4 ))
for j in range( 3 ):
Sel2.next= j
for i in range( 3 ):
Sel1.next = i
yield clk.posedge
yield myhdl.delay(0) # need this one for a strange reason???
print( Q )
assert Q == 1 + j * 3 + i
yield myhdl.delay( int( tCK // 4 ))
raise myhdl.StopSimulation
return tbdut, genreset, genclk, stimulus
def test_tb_array_3():
assert myhdl.conversion.verify( tb_array_3 ) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment