Last active
August 29, 2015 14:16
-
-
Save cfelton/d52fc4abe8d50b73c13c to your computer and use it in GitHub Desktop.
Flatten a matrix of signals (list of lists) to a single intbv.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def m_flatten(matrix, flat): | |
_flat = ConcatSignal(*[col(4,0) for row in matrix for col in row]) | |
@always_comb | |
def rtl(): | |
flat.next = _flat | |
return rtl | |
def test_flatten(): | |
matrix = [[Signal(intbv(0)[8:]) for col in range(5)] for row in range(8)] | |
flat = Signal(intbv(0)[160:]) | |
tbdut = m_flatten(matrix, flat) | |
@instance | |
def tbstim(): | |
yield delay(1) | |
print(bin(flat, 160)) | |
assert flat == 0 | |
matrix[0][0].next = 0x8 | |
yield delay(1) | |
print(bin(flat, 160)) | |
assert flat[160-1] == 1 | |
return tbdut, tbstim | |
Simulation(test_flatten()).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment