2018-08-13 22:17:36 +00:00
|
|
|
|
2018-02-27 04:48:36 +00:00
|
|
|
`ifndef RAM_H
|
|
|
|
`define RAM_H
|
|
|
|
|
2018-02-28 03:35:42 +00:00
|
|
|
module RAM_sync(clk, addr, din, dout, we);
|
2018-02-26 21:42:20 +00:00
|
|
|
|
|
|
|
parameter A = 10; // # of address bits
|
|
|
|
parameter D = 8; // # of data bits
|
|
|
|
|
|
|
|
input clk; // clock
|
2018-06-01 17:33:37 +00:00
|
|
|
input [A-1:0] addr; // address
|
|
|
|
input [D-1:0] din; // data input
|
|
|
|
output [D-1:0] dout; // data output
|
2018-02-26 21:42:20 +00:00
|
|
|
input we; // write enable
|
|
|
|
|
2018-08-25 02:55:16 +00:00
|
|
|
reg [D-1:0] mem [1<<A]; // (1<<A)xD bit memory
|
2018-02-26 21:42:20 +00:00
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (we) // if write enabled
|
|
|
|
mem[addr] <= din; // write memory from din
|
2018-02-28 03:35:42 +00:00
|
|
|
dout <= mem[addr]; // read memory to dout (sync)
|
2018-02-26 21:42:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|
2018-02-28 03:35:42 +00:00
|
|
|
module RAM_async(clk, addr, din, dout, we);
|
|
|
|
|
|
|
|
parameter A = 10; // # of address bits
|
|
|
|
parameter D = 8; // # of data bits
|
|
|
|
|
|
|
|
input clk; // clock
|
2018-06-01 17:33:37 +00:00
|
|
|
input [A-1:0] addr; // address
|
|
|
|
input [D-1:0] din; // data input
|
|
|
|
output [D-1:0] dout; // data output
|
2018-02-28 03:35:42 +00:00
|
|
|
input we; // write enable
|
|
|
|
|
2018-08-25 02:55:16 +00:00
|
|
|
reg [D-1:0] mem [1<<A]; // (1<<A)xD bit memory
|
2018-02-28 03:35:42 +00:00
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (we) // if write enabled
|
|
|
|
mem[addr] <= din; // write memory from din
|
|
|
|
end
|
|
|
|
|
|
|
|
assign dout = mem[addr]; // read memory to dout (async)
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|
2018-07-22 12:31:42 +00:00
|
|
|
module RAM_async_tristate(clk, addr, data, we);
|
|
|
|
|
|
|
|
parameter A = 10; // # of address bits
|
|
|
|
parameter D = 8; // # of data bits
|
|
|
|
|
|
|
|
input clk; // clock
|
|
|
|
input [A-1:0] addr; // address
|
|
|
|
inout [D-1:0] data; // data in/out
|
|
|
|
input we; // write enable
|
|
|
|
|
2018-08-25 02:55:16 +00:00
|
|
|
reg [D-1:0] mem [1<<A]; // (1<<A)xD bit memory
|
2018-07-22 12:31:42 +00:00
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (we) // if write enabled
|
|
|
|
mem[addr] <= data; // write memory from data
|
|
|
|
end
|
|
|
|
|
|
|
|
assign data = !we ? mem[addr] : {D{1'bz}}; // read memory to data (async)
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|
2018-02-27 04:48:36 +00:00
|
|
|
`endif
|