2016-03-10 20:27:07 +01:00
|
|
|
import myhdl
|
2005-12-19 10:18:33 +00:00
|
|
|
from myhdl import *
|
|
|
|
|
|
|
|
def ram(dout, din, addr, we, clk, depth=128):
|
|
|
|
""" Ram model """
|
|
|
|
|
|
|
|
mem = [Signal(intbv(0)[8:]) for i in range(depth)]
|
|
|
|
|
|
|
|
@always(clk.posedge)
|
|
|
|
def write():
|
|
|
|
if we:
|
2010-10-09 11:35:58 +02:00
|
|
|
mem[addr].next = din
|
2005-12-19 10:18:33 +00:00
|
|
|
|
|
|
|
@always_comb
|
|
|
|
def read():
|
2010-10-09 11:35:58 +02:00
|
|
|
dout.next = mem[addr]
|
2005-12-19 10:18:33 +00:00
|
|
|
|
|
|
|
return write, read
|
|
|
|
|
|
|
|
|
|
|
|
dout = Signal(intbv(0)[8:])
|
|
|
|
dout_v = Signal(intbv(0)[8:])
|
|
|
|
din = Signal(intbv(0)[8:])
|
|
|
|
addr = Signal(intbv(0)[7:])
|
|
|
|
we = Signal(bool(0))
|
|
|
|
clk = Signal(bool(0))
|
|
|
|
|
2005-12-27 14:38:27 +00:00
|
|
|
def main():
|
|
|
|
toVerilog.name = 'ram_1'
|
|
|
|
toVerilog(ram, dout, din, addr, we, clk)
|
2008-11-19 21:19:13 +01:00
|
|
|
toVHDL(ram, dout, din, addr, we, clk)
|
2005-12-27 14:38:27 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|