blob: 67e1f4439bf56b066e87ce6239efd0c10049f50a [file] [log] [blame]
Matt Venn08cd6eb2020-11-16 12:01:14 +01001`default_nettype none
Ahmed Ghazy22d29d62020-10-28 03:42:02 +02002module mem_wb (
Manar61dce922020-11-10 19:26:28 +02003`ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +02004 input VPWR,
5 input VGND,
6`endif
shalanfd13eb52020-08-21 16:48:07 +02007 input wb_clk_i,
8 input wb_rst_i,
9
10 input [31:0] wb_adr_i,
11 input [31:0] wb_dat_i,
12 input [3:0] wb_sel_i,
13 input wb_we_i,
14 input wb_cyc_i,
15 input wb_stb_i,
16
17 output wb_ack_o,
18 output [31:0] wb_dat_o
19
20);
Manar6bedda92020-11-02 20:29:07 +020021
22 localparam ADR_WIDTH = $clog2(`MEM_WORDS);
23
shalanfd13eb52020-08-21 16:48:07 +020024 wire valid;
25 wire ram_wen;
26 wire [3:0] wen; // write enable
27
28 assign valid = wb_cyc_i & wb_stb_i;
29 assign ram_wen = wb_we_i && valid;
30
31 assign wen = wb_sel_i & {4{ram_wen}} ;
32
shalanfd13eb52020-08-21 16:48:07 +020033 /*
34 Ack Generation
35 - write transaction: asserted upon receiving adr_i & dat_i
36 - read transaction : asserted one clock cycle after receiving the adr_i & dat_i
37 */
38
shalan0d14e6e2020-08-31 16:50:48 +020039 reg wb_ack_read;
40 reg wb_ack_o;
shalanfd13eb52020-08-21 16:48:07 +020041
42 always @(posedge wb_clk_i) begin
43 if (wb_rst_i == 1'b 1) begin
shalan0d14e6e2020-08-31 16:50:48 +020044 wb_ack_read <= 1'b0;
45 wb_ack_o <= 1'b0;
shalanfd13eb52020-08-21 16:48:07 +020046 end else begin
shalan0d14e6e2020-08-31 16:50:48 +020047 // wb_ack_read <= {2{valid}} & {1'b1, wb_ack_read[1]};
48 wb_ack_o <= wb_we_i? (valid & !wb_ack_o): wb_ack_read;
49 wb_ack_read <= (valid & !wb_ack_o) & !wb_ack_read;
shalanfd13eb52020-08-21 16:48:07 +020050 end
51 end
52
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020053 soc_mem
54`ifndef USE_OPENRAM
Manar6bedda92020-11-02 20:29:07 +020055 #(
56 .WORDS(`MEM_WORDS),
57 .ADR_WIDTH(ADR_WIDTH)
58 )
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020059`endif
60 mem (
Manar61dce922020-11-10 19:26:28 +020061 `ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +020062 .VPWR(VPWR),
63 .VGND(VGND),
64 `endif
shalanfd13eb52020-08-21 16:48:07 +020065 .clk(wb_clk_i),
66 .ena(valid),
67 .wen(wen),
Manar6bedda92020-11-02 20:29:07 +020068 .addr(wb_adr_i[ADR_WIDTH+1:2]),
shalanfd13eb52020-08-21 16:48:07 +020069 .wdata(wb_dat_i),
70 .rdata(wb_dat_o)
71 );
72
73endmodule
74
75module soc_mem
76`ifndef USE_OPENRAM
77#(
Manar6bedda92020-11-02 20:29:07 +020078 parameter integer WORDS = 256,
79 parameter ADR_WIDTH = 8
shalanfd13eb52020-08-21 16:48:07 +020080)
81`endif
82 (
Manar61dce922020-11-10 19:26:28 +020083`ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +020084 input VPWR,
85 input VGND,
86`endif
shalanfd13eb52020-08-21 16:48:07 +020087 input clk,
88 input ena,
89 input [3:0] wen,
Manar6bedda92020-11-02 20:29:07 +020090 input [ADR_WIDTH-1:0] addr,
shalanfd13eb52020-08-21 16:48:07 +020091 input [31:0] wdata,
92 output[31:0] rdata
93);
94
95`ifndef USE_OPENRAM
Manar8f131792020-11-11 16:38:32 +020096 DFFRAM #(.COLS(`COLS)) SRAM (
Manar61dce922020-11-10 19:26:28 +020097 `ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +020098 .VPWR(VPWR),
99 .VGND(VGND),
100 `endif
Ahmed Ghazy5586f1b2020-11-06 21:34:43 +0200101 .CLK(clk),
102 .WE(wen),
103 .EN(ena),
104 .Di(wdata),
105 .Do(rdata),
106 // 8-bit address if using the default custom DFF RAM
107 .A(addr)
108 );
shalanfd13eb52020-08-21 16:48:07 +0200109`else
110
111 /* Using Port 0 Only - Size: 1KB, 256x32 bits */
112 //sram_1rw1r_32_256_8_scn4m_subm
Manar14d35ac2020-10-21 22:47:15 +0200113 sram_1rw1r_32_256_8_sky130 SRAM(
shalanfd13eb52020-08-21 16:48:07 +0200114 .clk0(clk),
115 .csb0(~ena),
116 .web0(~|wen),
117 .wmask0(wen),
Manar14d35ac2020-10-21 22:47:15 +0200118 .addr0(addr[7:0]),
shalanfd13eb52020-08-21 16:48:07 +0200119 .din0(wdata),
120 .dout0(rdata)
121 );
122
123`endif
124
Ahmed Ghazy5586f1b2020-11-06 21:34:43 +0200125endmodule
Tim Edwards581068f2020-11-19 12:45:25 -0500126`default_nettype wire