Skip to content

Commit 8071742

Browse files
committed
Fix reminder computation in cutter
1 parent 278fe27 commit 8071742

File tree

1 file changed

+45
-60
lines changed

1 file changed

+45
-60
lines changed

rtl/variable_latency_interconnect/burst_cutter.sv

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ module burst_cutter
4747
input logic req_ready_i
4848
);
4949

50+
`include "common_cells/registers.svh"
51+
5052
localparam int unsigned BurstLen = NumIn;
5153
localparam int unsigned BurstLenWidth = NumInLog2;
5254
localparam int unsigned NumBanks = NumOut;
@@ -57,6 +59,15 @@ module burst_cutter
5759
BurstCut // second cut of burst
5860
} burst_cutter_fsm_e;
5961

62+
// Keep everything same width
63+
logic [31:0] bank_offset;
64+
logic [31:0] max_blen;
65+
logic [31:0] remaining_len;
66+
assign bank_offset = {{(32-BankOffsetBits){1'b0}}, req_tgt_addr_i[AddrMemWidth-1 : ByteOffWidth]};
67+
assign max_blen = NumBanks - bank_offset;
68+
assign remaining_len = {{(32-BurstLenWidth){1'b0}}, req_burst_i.blen} > max_blen ?
69+
{{(32-BurstLenWidth){1'b0}}, req_burst_i.blen} - max_blen : '0;
70+
6071
// FSM state
6172
burst_cutter_fsm_e state_d, state_q;
6273
burst_cutter_fsm_e next_state;
@@ -67,43 +78,27 @@ module burst_cutter
6778
logic [DataWidth-1:0] cut_wdata_d, cut_wdata_q;
6879
burst_t cut_burst_d, cut_burst_q;
6980

70-
logic [BankOffsetBits-1:0] bank_offset;
71-
logic [BurstLenWidth:0] max_blen;
72-
logic [BurstLenWidth:0] remaining_len;
73-
74-
always_ff @(posedge clk_i or negedge rst_ni) begin : burst_cutter_proc
75-
if(~rst_ni) begin
76-
state_q <= Bypass;
77-
cut_burst_q <= '0;
78-
cut_ini_addr_q <= '0;
79-
cut_tgt_addr_q <= '0;
80-
cut_wdata_q <= '0;
81-
end else begin
82-
state_q <= state_d;
83-
cut_ini_addr_q <= cut_tgt_addr_d;
84-
cut_tgt_addr_q <= cut_tgt_addr_d;
85-
cut_wdata_q <= cut_wdata_d;
86-
cut_burst_q <= cut_burst_d;
87-
end
88-
end
81+
// Store FSM state and signals
82+
`FF(state_q, state_d, Bypass, clk_i, rst_ni);
83+
`FF(cut_burst_q, cut_burst_d, '0, clk_i, rst_ni);
84+
`FF(cut_ini_addr_q, cut_ini_addr_d, '0, clk_i, rst_ni);
85+
`FF(cut_tgt_addr_q, cut_tgt_addr_d, '0, clk_i, rst_ni);
86+
`FF(cut_wdata_q, cut_wdata_d, '0, clk_i, rst_ni);
8987

9088
always_comb begin
91-
// FSM defaults
92-
state_d = state_q;
93-
cut_burst_d = cut_burst_q;
94-
cut_tgt_addr_d = cut_tgt_addr_q;
95-
cut_ini_addr_d = cut_ini_addr_q;
96-
cut_wdata_d = cut_wdata_q;
97-
98-
bank_offset = '0;
99-
max_blen = '0;
100-
remaining_len = '0;
10189

102-
next_state = Bypass;
90+
// FSM defaults
91+
state_d = state_q;
92+
cut_burst_d = cut_burst_q;
93+
cut_tgt_addr_d = cut_tgt_addr_q;
94+
cut_ini_addr_d = cut_ini_addr_q;
95+
cut_wdata_d = cut_wdata_q;
10396

10497
// Need to cut, use FSM to realize the logic
10598
case (state_q)
99+
106100
Bypass: begin
101+
107102
// Bypass the signals
108103
req_ini_addr_o = req_ini_addr_i;
109104
req_tgt_addr_o = req_tgt_addr_i;
@@ -113,70 +108,60 @@ module burst_cutter
113108
req_burst_o = req_burst_i;
114109
req_valid_o = req_valid_i;
115110
req_ready_o = req_ready_i;
116-
// Keep current state by default
117-
next_state = state_q;
118111

119112
// Check if it is valid and being a burst request
120113
if (req_burst_i.isburst) begin
121-
bank_offset = req_tgt_addr_i[AddrMemWidth-1 : ByteOffWidth];
122-
max_blen = NumBanks - bank_offset;
123114

115+
// No support for write burst, tie to 0
124116
if (req_wen_i) begin
125-
// no support for write burst, tie to 0
126117
req_burst_o = '0;
127118

128119
end else begin
129-
if (req_burst_i.blen > max_blen) begin
130-
next_state = BurstCut;
131-
120+
// Cut burst when it is longer than the max length
121+
if (remaining_len > 0) begin
122+
if (remaining_len > NumBanks) begin
123+
$error("Only one cut is supported, reduce the burst length.");
124+
end
132125
// pause taking in new requests
133126
req_ready_o = 1'b0;
134127
// Send out the first burst
135128
req_burst_o.isburst = 1'b1;
136129
req_burst_o.blen = max_blen;
137-
138130
// store the info for next burst
139131
cut_ini_addr_d = req_ini_addr_i + (max_blen << ByteOffWidth);
140132
cut_tgt_addr_d = req_tgt_addr_i + (max_blen << ByteOffWidth);
141133
cut_wdata_d = req_wdata_i[max_blen];
142-
143-
remaining_len = req_burst_i.blen - max_blen;
144-
if (remaining_len > NumBanks) begin
145-
$error("Only one cut is supported, reduce the burst length.");
146-
end
147-
148134
cut_burst_d.isburst = 1'b1;
149-
cut_burst_d.blen = remaining_len;
150-
135+
cut_burst_d.blen = remaining_len[BurstLenWidth-1:0];
136+
// Keep state until the current one is picked
137+
if (req_ready_i) begin
138+
state_d = BurstCut;
139+
end
151140
end
141+
152142
end
153143
end
154-
// Keep state until the current one is picked
155-
if (req_ready_i) begin
156-
state_d = next_state;
157-
end
144+
158145
end
159146

160147
BurstCut: begin
161-
next_state = state_q;
162148
// assign the outputs
163149
// send out this part and wait for ready
164150
req_tgt_addr_o = cut_ini_addr_q;
165151
req_tgt_addr_o = cut_tgt_addr_q;
166-
req_wdata_o = cut_wdata_q;
167-
req_wen_o = '0; // only read burst is supported
168-
req_be_o = '0;
169-
req_burst_o = cut_burst_q;
170-
req_valid_o = 1'b1;
171-
req_ready_o = 1'b0;
152+
req_wdata_o = cut_wdata_q;
153+
req_wen_o = '0; // only read burst is supported
154+
req_be_o = '0;
155+
req_burst_o = cut_burst_q;
156+
req_valid_o = 1'b1;
157+
req_ready_o = 1'b0;
172158

173159
// When we get the ready, the second part is out
174160
if (req_ready_i) begin
175-
next_state = Bypass;
176161
req_ready_o = req_ready_i;
162+
state_d = Bypass;
177163
end
178164

179-
state_d = next_state;
180165
end
181166

182167
default: state_d = Bypass;

0 commit comments

Comments
 (0)