-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_bram_reg_file.sv
95 lines (86 loc) · 2.99 KB
/
multi_bram_reg_file.sv
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
`timescale 1ns / 1ps
`include "riscv_core.svh"
module multi_bram_reg_file #(
parameter NUM_BRAMS=4,
parameter DEPTH=`NUM_PR
)(
input clk, reset,
input [1:0] mode,
input [$clog2(`NUM_PR)-1:0] write_addr [2],
input [31:0] write_data [2],
input [$clog2(`NUM_PR)-1:0] read_addr [NUM_BRAMS*2],
output logic [31:0] read_data [NUM_BRAMS*2]
);
logic [1:0] prev_state;
always_ff @(posedge clk) begin
if(reset) begin
prev_state <= 2'b00;
end else begin
prev_state <= mode;
end
end
logic [31:0] din [NUM_BRAMS][2];
logic [$clog2(`NUM_PR)-1:0] addr [NUM_BRAMS][2];
logic we [NUM_BRAMS][2];
logic [31:0] dout [NUM_BRAMS][2];
genvar i;
generate
for(i = 0; i < NUM_BRAMS; i++) begin : gen_bram
bram_block #(
.WIDTH(32),
.DEPTH(DEPTH)
) BRAM_BLOCK (
.clk,
.reset,
.addr(addr[i]),
.we(we[i]),
.din(din[i]),
.dout(dout[i])
);
always_comb begin
if(mode == 2'b00) begin //2 writes
addr[i][0] = write_addr[0];
addr[i][1] = write_addr[1];
we[i][0] = 1;
we[i][1] = 1;
din[i][0] = write_data[0];
din[i][1] = write_data[1];
end else if(mode == 2'b01) begin //1 writes
addr[i][0] = write_addr[0];
addr[i][1] = read_addr[i];
we[i][0] = 1;
we[i][1] = 0;
din[i][0] = write_data[0];
din[i][1] = 0;
end else if(mode == 2'b10) begin //0 writes
addr[i][0] = read_addr[2*i];
addr[i][1] = read_addr[2*i+1];
we[i][0] = 0;
we[i][1] = 0;
din[i][0] = 0;
din[i][1] = 0;
end else if(mode == 2'b11) begin //do nothing
addr[i][0] = read_addr[0];
addr[i][1] = read_addr[0];
we[i][0] = 0;
we[i][1] = 0;
din[i][0] = 0;
din[i][1] = 0;
end
if(prev_state == 2'b00) begin
read_data[2*i] = 0;
read_data[2*i+1] = 0;
end else if(prev_state == 2'b01) begin
read_data[i+NUM_BRAMS] = 0;
read_data[i] = dout[i][1];
end else if(prev_state == 2'b10) begin
read_data[2*i] = dout[i][0];
read_data[2*i+1] = dout[i][1];
end else if(prev_state == 2'b11) begin
read_data[2*i] = 0;
read_data[2*i+1] = 0;
end
end
end
endgenerate
endmodule