-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmembram.v
61 lines (55 loc) · 1.96 KB
/
membram.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// iceZ0mb1e - FPGA 8-Bit TV80 SoC for Lattice iCE40
// with complete open-source toolchain flow using yosys and SDCC
//
// Copyright (c) 2018 Franz Neumann ([email protected])
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
module membram #(
parameter ADDR_WIDTH = 14,
parameter MEM_HEX = "",
parameter MEM_INIT = 0
) (
input clk,
input reset_n,
output[7:0] data_out,
input[7:0] data_in,
input cs_n,
input rd_n,
input wr_n,
input[ADDR_WIDTH-1:0] addr
);
wire read_sel = !cs_n & !rd_n & wr_n;
wire write_sel = !cs_n & rd_n & !wr_n;
assign data_out = (read_sel) ? mem_8[addr] : 8'b0;
reg [7:0] mem_8 [0:(1 << ADDR_WIDTH)-1];
integer j;
initial begin
if( MEM_INIT > 0 ) begin
$readmemh(MEM_HEX, mem_8, 0, (1 << ADDR_WIDTH)-1);
end
end
always @(posedge clk)
begin
if (write_sel) begin
mem_8[addr] <= data_in;
end
end
endmodule