-
Notifications
You must be signed in to change notification settings - Fork 756
Expand file tree
/
Copy pathram_1p.sv
More file actions
71 lines (62 loc) · 1.74 KB
/
Copy pathram_1p.sv
File metadata and controls
71 lines (62 loc) · 1.74 KB
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
62
63
64
65
66
67
68
69
70
71
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
/**
* Single-port RAM with 1 cycle read/write delay, 32 bit words
*/
`include "prim_assert.sv"
module ram_1p #(
parameter int Depth = 128,
parameter MemInitFile = ""
) (
input clk_i,
input rst_ni,
input req_i,
input we_i,
input [ 3:0] be_i,
input [31:0] addr_i,
input [31:0] wdata_i,
output logic rvalid_o,
output logic [31:0] rdata_o
);
localparam int Aw = $clog2(Depth);
logic [Aw-1:0] addr_idx;
assign addr_idx = addr_i[Aw-1+2:2];
logic [31-Aw:0] unused_addr_parts;
assign unused_addr_parts = {addr_i[31:Aw+2], addr_i[1:0]};
// Convert byte mask to SRAM bit mask.
logic [31:0] wmask;
always_comb begin
for (int i = 0 ; i < 4 ; i++) begin
// mask for read data
wmask[8*i+:8] = {8{be_i[i]}};
end
end
// |rvalid| in the bus module is an "ack" (which is a different meaning than
// in the prim_ram_*_adv modules). prim_ram_1p is guaranteed to return data
// in the next cycle.
always_ff @(posedge clk_i, negedge rst_ni) begin
if (!rst_ni) begin
rvalid_o <= 1'b0;
end else begin
rvalid_o <= req_i;
end
end
prim_ram_1p #(
.Width(32),
.DataBitsPerMask(8),
.Depth(Depth),
.MemInitFile(MemInitFile)
) u_ram (
.clk_i (clk_i),
.rst_ni (rst_ni),
.req_i (req_i),
.write_i (we_i),
.addr_i (addr_idx),
.wdata_i (wdata_i),
.wmask_i (wmask),
.rdata_o (rdata_o),
.cfg_i ('0),
.cfg_rsp_o ()
);
endmodule