Created
April 3, 2015 19:28
-
-
Save ravijain056/91787a775a5045f07db6 to your computer and use it in GitHub Desktop.
This file contains 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
from __future__ import absolute_import | |
import os | |
path = os.path | |
from myhdl import * | |
def ram1(dout, din, addrx, addry, we, clk, depth=128, width=8): | |
""" Simple ram model """ | |
@instance | |
def logic(): | |
mem2d = [[intbv(0)[8:] for i in range(width)] for ii in range(depth)] | |
a = intbv(0)[8:] | |
while 1: | |
yield clk.posedge | |
if we: | |
ad = int(addrx) | |
aw = int(addry) | |
mem2d[int(addrx)][int(addry)][:] = din | |
dout.next = mem2d[int(addrx)][int(addry)] | |
return logic | |
def ram_clocked(dout, din, addrx, addry, we, clk, depth=128, width=8): | |
""" Ram model """ | |
mem2d = [[Signal(intbv(0)[8:]) for i in range(width)] for ii in range(depth)] | |
@instance | |
def access(): | |
while 1: | |
yield clk.posedge | |
if we: | |
mem2d[int(addrx)][int(addry)].next = din | |
dout.next = mem2d[int(addrx)][int(addry)] | |
return access | |
def ram_deco1(dout, din, addrx, addry, we, clk, depth=128, width=8): | |
""" Ram model """ | |
mem2d = [[Signal(intbv(0)[8:]) for i in range(width)] for ii in range(depth)] | |
@instance | |
def write(): | |
while True: | |
yield clk.posedge | |
if we: | |
mem2d[int(addrx)][int(addry)].next = din | |
@always_comb | |
def read(): | |
dout.next = mem2d[int(addrx)][int(addry)] | |
return write, read | |
def ram_deco2(dout, din, addrx, addry, we, clk, depth=128, width=8): | |
""" Ram model """ | |
mem2d = [[Signal(intbv(0)[8:]) for i in range(width)] for ii in range(depth)] | |
@always(clk.posedge) | |
def write(): | |
if we: | |
mem2d[int(addrx)][int(addry)].next = din | |
@always_comb | |
def read(): | |
dout.next = mem2d[int(addrx)][int(addry)] | |
return write, read | |
def ram2(dout, din, addrx, addry, we, clk, depth=128, width=8): | |
memL2d = [[Signal(intbv(0)[len(dout):]) for i in range(width)] for ii in range(depth)] | |
@instance | |
def wrLogic() : | |
while 1: | |
yield clk.posedge | |
if we: | |
memL2d[int(addrx)][int(addry)].next = din | |
@instance | |
def rdLogic() : | |
while 1: | |
yield clk.posedge | |
dout.next = memL2d[int(addrx)][int(addry)] | |
return wrLogic, rdLogic | |
def RamBench(ram, depth=128, width=8): | |
dout = Signal(intbv(0)[8:]) | |
dout_v = Signal(intbv(0)[8:]) | |
din = Signal(intbv(0)[8:]) | |
addrx = Signal(intbv(0)[7:]) | |
addry = Signal(intbv(0)[3:]) | |
we = Signal(bool(0)) | |
clk = Signal(bool(0)) | |
mem_inst = ram(dout, din, addrx, addry, we, clk, depth) | |
@instance | |
def stimulus(): | |
for iy in range(width): | |
addry.next = iy | |
for i in range(depth): | |
yield clk.negedge | |
din.next = i | |
addrx.next = i | |
we.next = True | |
yield clk.negedge | |
we.next = False | |
for iy in range(width): | |
addry.next = iy | |
for i in range(depth): | |
addrx.next = i | |
yield clk.posedge | |
yield delay(1) | |
assert dout == i | |
print(dout) | |
raise StopSimulation() | |
@instance | |
def clkgen(): | |
clk.next = 1 | |
while True: | |
yield delay(10) | |
clk.next = not clk | |
return clkgen, stimulus, mem_inst | |
def testram_deco1(): | |
assert conversion.verify(RamBench, ram_deco1) == 0 | |
def testram_deco2(): | |
assert conversion.verify(RamBench, ram_deco2) == 0 | |
def testram_clocked(): | |
assert conversion.verify(RamBench, ram_clocked) == 0 | |
def test2(): | |
assert conversion.verify(RamBench, ram2) == 0 | |
def test1(): | |
assert conversion.verify(RamBench, ram1) == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment