From 6499a90fe1556cbcb259ade5558cb4a82aee40aa Mon Sep 17 00:00:00 2001 From: jand Date: Mon, 19 Dec 2005 10:18:33 +0000 Subject: [PATCH] added --- example/manual/ram.py | 27 +++++++++++++++++++++++++++ example/manual/rom.py | 19 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 example/manual/ram.py create mode 100644 example/manual/rom.py diff --git a/example/manual/ram.py b/example/manual/ram.py new file mode 100644 index 00000000..354d851a --- /dev/null +++ b/example/manual/ram.py @@ -0,0 +1,27 @@ +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: + mem[int(addr)].next = din + + @always_comb + def read(): + dout.next = mem[int(addr)] + + 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)) + +toVerilog(ram, dout, din, addr, we, clk) diff --git a/example/manual/rom.py b/example/manual/rom.py new file mode 100644 index 00000000..b5f83841 --- /dev/null +++ b/example/manual/rom.py @@ -0,0 +1,19 @@ +from myhdl import * + +CONTENT = (17, 134, 52, 9) + +def rom(dout, addr, CONTENT): + """ ROM model """ + + @always_comb + def read(): + dout.next = CONTENT[int(addr)] + + return read + +dout = Signal(intbv(0)[8:]) +addr = Signal(intbv(0)[4:]) +CONTENT = (17, 134, 52, 9) + +toVerilog(rom, dout, addr, CONTENT) +