-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrequest_saver.sv
78 lines (59 loc) · 1.52 KB
/
request_saver.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
module request_saver import types_def::*;
(
input clk, // Clock
input rst_n, // reset active low
////////////////////////////////////////////////mapper
input opt_request request_i,
input logic [15:0] valid_i,
input logic [read_entries_log -1:0] index_i,
output logic grant_o2,
/////////////////////////////////////////////////fifo
input logic [15:0] grant_o,
output opt_request request_i2,
output logic [15:0] valid_i2,
output logic [read_entries_log -1:0] index_i2
);
logic waiting_valid ;
opt_request waiting ;
logic [read_entries_log -1:0] index_waiting ;
logic [$clog2(banks_no)-1 :0] j;
always_comb begin
for (int i = 0; i < banks_no; i++) begin
if (valid_i[i] == 1) begin
j=i;
end
end
if (grant_o[j] == 0 && valid_i[j] == 1 ) begin // save the request
grant_o2 = 0;
end
else begin // send normally
grant_o2 = 1;
valid_i2 = valid_i;
index_i2 = index_i;
request_i2 = request_i;
end
if (waiting_valid) begin // old request waiting
grant_o2 = 0;
if (grant_o[j]) begin
valid_i2[j] = 1;
index_i2 = index_waiting;
request_i2 = waiting;
end
end
end
always_ff @(posedge clk ) begin
if(rst_n) begin
if (waiting_valid == 1 && grant_o[j] ==1) begin
waiting_valid <=0;
end
if (grant_o[j] == 0 && valid_i[j] == 1 ) begin
waiting <= request_i;
index_waiting <= index_i;
waiting_valid <=1;
end
end
else begin // reset
waiting_valid <=0;
end
end
endmodule