Last active
August 29, 2015 14:27
-
-
Save cfelton/950a0dcfb8bcd683686b to your computer and use it in GitHub Desktop.
list of interface conversion example
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
me = 0 | |
class Interface: | |
def __init__(self): | |
self.x = Signal(bool(0)) | |
self.y = Signal(bool(0)) | |
def mod_with_interface(intf): | |
global me | |
xi = me | |
@always(intf.clock.posedge) | |
def rtl(): | |
intf.y.next = (x + xi) & 1 | |
me += 1 | |
return rtl | |
def list_of_interfaces_top(clock, x, y, number_of_modules=120): | |
loi = [Interface() for _ in range(number_of_modules)] | |
mods = [] | |
for ii, intf in enumerate(loi): | |
if ii == 0: | |
intf.x = x | |
elif ii == number_of_modules-1: | |
intf.y = y | |
else: | |
intf.x = loi[ii-1].x | |
intf.clock = clock | |
mods += [mod_with_interface(intf)] | |
return mods | |
clock = Signal(bool(0)) | |
x, y = [Signal(bool(0)) for _ in range(2)] | |
toVerilog(list_of_interfaces_top, clock, x, y) |
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
me = 0 | |
class Interface: | |
def __init__(self): | |
self.x = Signal(bool(0)) | |
self.y = Signal(bool(0)) | |
def mod_with_interface(intf): | |
global me | |
xi = me | |
@always(intf.clock.posedge) | |
def rtl(): | |
intf.y.next = (x + xi) & 1 | |
me += 1 | |
return [rtl] | |
def list_of_interfaces_top(clock, x, y, number_of_modules=120): | |
loi = [Interface() for _ in range(number_of_modules)] | |
mods = [] | |
for ii, intf in enumerate(loi): | |
if ii == 0: | |
intf.x = x | |
elif ii == number_of_modules-1: | |
intf.y = y | |
else: | |
intf.x = loi[ii-1].x | |
intf.clock = clock | |
mods += mod_with_interface(intf) | |
return mods | |
clock = Signal(bool(0)) | |
x, y = [Signal(bool(0)) for _ in range(2)] | |
toVerilog(list_of_interfaces_top, clock, x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment