-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmapper.sv
197 lines (141 loc) · 5.02 KB
/
mapper.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
module mapper import types_def::*;
(
input clk, // Clock
input rst_n, // synchronous reset active low
input in_valid, // from rnic
input request in_request, // from rnic
output logic out_busy_o, // to rnic
input stop_reading, // from over flow stopper
input stop_writing, // from over flow stopper
output logic valid_out_o, // to over flow stopper
output opt_request out_req_o,// to bank
output logic [read_entries_log -1:0] out_index_o,// to the bank
input [15:0] in_busy, // from bank
output logic [15:0] bank_out_valid_o // to bank
);
typedef struct packed {
logic valid ;
r_type req_type ;
address_type address ;
logic [data_width -1:0] data ;
} waiting_request ;
waiting_request waiting_req;
address_type mapped_address;
logic [read_entries_log -1:0] read_counter;
logic [write_entries_log -1:0] write_counter;
logic [15:0] bank_out_valid;
logic [3:0] bank_id ,waiting_bank_id;
/*
// permutation
/////////////////////////////////// scheme applier \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// mapped_address = { bank_group , bank , row , column }
// 2 2 16 10
// scheme row bank column bank_group column ////////// the mapping scheme
// bits_no. 16 2 6 2 4
always_comb begin
mapped_address.bank_group = in_request.address [5:4] ^ in_request.address[29 - t+3 :29 - t+2 ];
mapped_address.bank = in_request.address [13:12] ^ in_request.address[29 - t+1 :29 - t ] ;
mapped_address.row = in_request.address [29:14];
mapped_address.column = { in_request.address [11:6] , in_request.address [3:0] };
end
/////////////////////////////////// scheme applier \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*/
//direct mapping
/////////////////////////////////// scheme applier \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// mapped_address = { bank_group , bank , row , column }
// 2 2 16 10
// scheme row bank column bank_group column ////////// the mapping scheme
// bits_no. 16 2 6 2 4
always_comb begin
mapped_address.bank_group = in_request.address [5:4] ;// ^ in_request.address[29 - t+3 :29 - t+2 ];
mapped_address.bank = in_request.address [13:12];// ^ in_request.address[29 - t+1 :29 - t ] ;
mapped_address.row = in_request.address [29:14];
mapped_address.column = { in_request.address [11:6] , in_request.address [3:0] };
end
/////////////////////////////////// scheme applier \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
always_comb begin
waiting_bank_id = { waiting_req.address.bank_group , waiting_req.address.bank};
bank_id = { mapped_address.bank_group , mapped_address.bank};
bank_out_valid = 0;
bank_out_valid[bank_id] = 1;
end
always_ff @(posedge clk) begin
if(rst_n) begin
if (waiting_req.valid) begin
if ( ( (waiting_req.req_type == write && stop_writing == 0) || (waiting_req.req_type == read && stop_reading == 0) ) && in_busy [waiting_bank_id] == 0) begin // send the saved req
out_req_o.address.column <= waiting_req.address.column;
out_req_o.address.row <= waiting_req.address.row;
out_req_o.data <= waiting_req.data;
out_req_o.req_type <= waiting_req.req_type;
if (waiting_req.req_type == read) begin
out_index_o <= read_counter;
read_counter <= read_counter +1;
end
else begin
out_index_o <= write_counter;
write_counter <= write_counter +1;
end
bank_out_valid_o <= bank_out_valid;
valid_out_o <= 1;
out_busy_o <= 0;
waiting_req <= 0;
end
else begin // idle but still busy
out_busy_o <= 1;
bank_out_valid_o <= 0;
valid_out_o <= 0;
out_index_o <= 0;
out_req_o <= 0;
end
end
else begin
if (in_valid) begin
if (( (in_request.req_type == write && stop_writing == 0) || (in_request.req_type == read && stop_reading == 0) ) && in_busy [bank_id] == 0) begin // send new req
out_req_o.address.column <= mapped_address.column;
out_req_o.address.row <= mapped_address.row;
out_req_o.data <= in_request.data;
out_req_o.req_type <= in_request.req_type;
if (in_request.req_type == read) begin
out_index_o <= read_counter;
read_counter <= read_counter +1;
end
else begin
out_index_o <= write_counter;
write_counter <= write_counter +1;
end
bank_out_valid_o <= bank_out_valid;
valid_out_o <= 1;
out_busy_o <= 0;
end
else begin // save new req & idle & busy
waiting_req.valid <= 1;
waiting_req.req_type <= in_request.req_type;
waiting_req.address <= mapped_address;
waiting_req.data <= in_request.data;
out_busy_o <= 1;
bank_out_valid_o <= 0;
valid_out_o <= 0;
out_index_o <= 0;
out_req_o <= 0;
end
end
else begin // idle
out_busy_o <= 0;
bank_out_valid_o <= 0;
valid_out_o <= 0;
out_index_o <= 0;
out_req_o <= 0;
end
end
end
else begin // reset
read_counter <= 0;
write_counter <= 0;
waiting_req <= 0; //
out_busy_o <= 0; //
bank_out_valid_o <= 0; //
valid_out_o <= 0;
out_index_o <= 0; //
end
end
endmodule