blob: c4a1cc4da83c91fd98c74b34d5ea22701f5265e7 [file] [log] [blame]
Ahmed Ghazy22d29d62020-10-28 03:42:02 +02001module mem_synth_wb (
Manar14d35ac2020-10-21 22:47:15 +02002 input wb_clk_i,
3 input wb_rst_i,
4
5 input [31:0] wb_adr_i,
6 input [31:0] wb_dat_i,
7 input [3:0] wb_sel_i,
8 input wb_we_i,
9 input wb_cyc_i,
10 input wb_stb_i,
11
12 output wb_ack_o,
13 output [31:0] wb_dat_o
14);
15
16 wire valid;
17 wire ram_wen;
18 wire [3:0] wen; // write enable
19
20 assign valid = wb_cyc_i & wb_stb_i;
21 assign ram_wen = wb_we_i && valid;
22
23 assign wen = wb_sel_i & {4{ram_wen}} ;
24
25 reg wb_ack_read;
26 reg wb_ack_o;
27
28 always @(posedge wb_clk_i) begin
29 if (wb_rst_i == 1'b 1) begin
30 wb_ack_read <= 1'b0;
31 wb_ack_o <= 1'b0;
32 end else begin
33 wb_ack_o <= wb_we_i? (valid & !wb_ack_o): wb_ack_read;
34 wb_ack_read <= (valid & !wb_ack_o) & !wb_ack_read;
35 end
36 end
37
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020038 soc_mem_synth mem (
Manar14d35ac2020-10-21 22:47:15 +020039 .clk(wb_clk_i),
40 .ena(valid),
41 .wen(wen),
42 .addr(wb_adr_i[12:2]),
43 .wdata(wb_dat_i),
44 .rdata(wb_dat_o)
45 );
46
47endmodule
48
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020049module soc_mem_synth (
Manar14d35ac2020-10-21 22:47:15 +020050 input clk,
51 input ena,
52 input [3:0] wen,
53 input [10:0] addr,
54 input [31:0] wdata,
55 output[31:0] rdata
56);
57
58 reg [31:0] rdata;
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020059 reg [31:0] mem [0:`MEM_SYNTH_WORDS-1];
Manar14d35ac2020-10-21 22:47:15 +020060
61 always @(posedge clk) begin
62 if (ena == 1'b1) begin
63 rdata <= mem[addr];
64 if (wen[0]) mem[addr][ 7: 0] <= wdata[ 7: 0];
65 if (wen[1]) mem[addr][15: 8] <= wdata[15: 8];
66 if (wen[2]) mem[addr][23:16] <= wdata[23:16];
67 if (wen[3]) mem[addr][31:24] <= wdata[31:24];
68 end
69 end
70
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020071endmodule