Created
December 21, 2017 03:06
-
-
Save jblang/febdcc0b6987ff5d52e60e40f35fdfc0 to your computer and use it in GitHub Desktop.
New block ram
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
module ram(clk, addr, data_in, data_out, cs, we); | |
parameter ADDR_WIDTH = 11; | |
parameter DATA_WIDTH = 8; | |
parameter INIT_FILE = ""; | |
input clk; | |
input [ADDR_WIDTH-1:0] addr; | |
input [DATA_WIDTH-1:0] data_in; | |
output reg [DATA_WIDTH-1:0] data_out; | |
input cs; | |
input we; | |
reg [DATA_WIDTH-1:0] mem[(1 << ADDR_WIDTH)-1:0]; | |
initial | |
begin | |
if (INIT_FILE != "") begin | |
$readmemh(INIT_FILE, mem); | |
end | |
end | |
reg [ADDR_WIDTH-1:0] addr_reg; | |
always @(posedge clk) | |
begin | |
if (cs) | |
if (we) | |
mem[addr] <= data_in; | |
else | |
data_out <= mem[addr]; | |
else | |
data_out <= 8'bz; | |
//addr_reg <= addr; | |
end | |
//assign data_out = (cs && !we) ? mem[addr_reg] : 8'bz; | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment