1 |
16 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: axilwr2wbsp.v (AXI lite to wishbone slave, read channel)
|
4 |
|
|
//
|
5 |
|
|
// Project: Pipelined Wishbone to AXI converter
|
6 |
|
|
//
|
7 |
|
|
// Purpose: Bridge an AXI lite write channel triplet to a single wishbone
|
8 |
|
|
// write channel. A full AXI lite to wishbone bridge will also
|
9 |
|
|
// require the read channel and an arbiter.
|
10 |
|
|
//
|
11 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
12 |
|
|
// Gisselquist Technology, LLC
|
13 |
|
|
//
|
14 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
15 |
|
|
//
|
16 |
|
|
// Copyright (C) 2016-2019, Gisselquist Technology, LLC
|
17 |
|
|
//
|
18 |
|
|
// This file is part of the pipelined Wishbone to AXI converter project, a
|
19 |
|
|
// project that contains multiple bus bridging designs and formal bus property
|
20 |
|
|
// sets.
|
21 |
|
|
//
|
22 |
|
|
// The bus bridge designs and property sets are free RTL designs: you can
|
23 |
|
|
// redistribute them and/or modify any of them under the terms of the GNU
|
24 |
|
|
// Lesser General Public License as published by the Free Software Foundation,
|
25 |
|
|
// either version 3 of the License, or (at your option) any later version.
|
26 |
|
|
//
|
27 |
|
|
// The bus bridge designs and property sets are distributed in the hope that
|
28 |
|
|
// they will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
29 |
|
|
// warranty of MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
30 |
|
|
// GNU Lesser General Public License for more details.
|
31 |
|
|
//
|
32 |
|
|
// You should have received a copy of the GNU Lesser General Public License
|
33 |
|
|
// along with these designs. (It's in the $(ROOT)/doc directory. Run make
|
34 |
|
|
// with no target there if the PDF file isn't present.) If not, see
|
35 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
36 |
|
|
//
|
37 |
|
|
// License: LGPL, v3, as defined and found on www.gnu.org,
|
38 |
|
|
// http://www.gnu.org/licenses/lgpl.html
|
39 |
|
|
//
|
40 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
//
|
42 |
|
|
//
|
43 |
|
|
`default_nettype none
|
44 |
|
|
//
|
45 |
|
|
module axilwr2wbsp(i_clk, i_axi_reset_n,
|
46 |
|
|
// AXI write address channel signals
|
47 |
|
|
o_axi_awready, i_axi_awaddr, i_axi_awcache, i_axi_awprot, i_axi_awvalid,
|
48 |
|
|
// AXI write data channel signals
|
49 |
|
|
o_axi_wready, i_axi_wdata, i_axi_wstrb, i_axi_wvalid,
|
50 |
|
|
// AXI write response channel signals
|
51 |
|
|
o_axi_bresp, o_axi_bvalid, i_axi_bready,
|
52 |
|
|
// We'll share the clock and the reset
|
53 |
|
|
o_wb_cyc, o_wb_stb, o_wb_addr, o_wb_data, o_wb_sel,
|
54 |
|
|
i_wb_ack, i_wb_stall, i_wb_err
|
55 |
|
|
`ifdef FORMAL
|
56 |
|
|
, f_first, f_mid, f_last, f_wpending
|
57 |
|
|
`endif
|
58 |
|
|
);
|
59 |
|
|
parameter C_AXI_DATA_WIDTH = 32;// Width of the AXI R&W data
|
60 |
|
|
parameter C_AXI_ADDR_WIDTH = 28; // AXI Address width
|
61 |
|
|
localparam AW = C_AXI_ADDR_WIDTH-2;// WB Address width
|
62 |
|
|
parameter LGFIFO = 3;
|
63 |
|
|
localparam DW = C_AXI_DATA_WIDTH;
|
64 |
|
|
localparam FLEN=(1<<LGFIFO);
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
input wire i_clk; // Bus clock
|
68 |
|
|
input wire i_axi_reset_n; // Bus reset
|
69 |
|
|
|
70 |
|
|
// AXI write address channel signals
|
71 |
|
|
output reg o_axi_awready;//Slave is ready to accept
|
72 |
|
|
input wire [AW+1:0] i_axi_awaddr; // Write address
|
73 |
|
|
input wire [3:0] i_axi_awcache; // Write Cache type
|
74 |
|
|
input wire [2:0] i_axi_awprot; // Write Protection type
|
75 |
|
|
input wire i_axi_awvalid; // Write address valid
|
76 |
|
|
|
77 |
|
|
// AXI write data channel signals
|
78 |
|
|
output reg o_axi_wready; // Write data ready
|
79 |
|
|
input wire [DW-1:0] i_axi_wdata; // Write data
|
80 |
|
|
input wire [DW/8-1:0] i_axi_wstrb; // Write strobes
|
81 |
|
|
input wire i_axi_wvalid; // Write valid
|
82 |
|
|
|
83 |
|
|
// AXI write response channel signals
|
84 |
|
|
output reg [1:0] o_axi_bresp; // Write response
|
85 |
|
|
output reg o_axi_bvalid; // Write reponse valid
|
86 |
|
|
input wire i_axi_bready; // Response ready
|
87 |
|
|
|
88 |
|
|
// We'll share the clock and the reset
|
89 |
|
|
output reg o_wb_cyc;
|
90 |
|
|
output reg o_wb_stb;
|
91 |
|
|
output reg [(AW-1):0] o_wb_addr;
|
92 |
|
|
output reg [(DW-1):0] o_wb_data;
|
93 |
|
|
output reg [(DW/8-1):0] o_wb_sel;
|
94 |
|
|
input wire i_wb_ack;
|
95 |
|
|
input wire i_wb_stall;
|
96 |
|
|
input wire i_wb_err;
|
97 |
|
|
`ifdef FORMAL
|
98 |
|
|
// Output connections only used in formal mode
|
99 |
|
|
output wire [LGFIFO:0] f_first;
|
100 |
|
|
output wire [LGFIFO:0] f_mid;
|
101 |
|
|
output wire [LGFIFO:0] f_last;
|
102 |
|
|
output wire [1:0] f_wpending;
|
103 |
|
|
`endif
|
104 |
|
|
|
105 |
|
|
wire w_reset;
|
106 |
|
|
assign w_reset = (!i_axi_reset_n);
|
107 |
|
|
|
108 |
|
|
reg r_awvalid, r_wvalid;
|
109 |
|
|
reg [AW-1:0] r_addr;
|
110 |
|
|
reg [DW-1:0] r_data;
|
111 |
|
|
reg [DW/8-1:0] r_sel;
|
112 |
|
|
|
113 |
|
|
reg fifo_full, fifo_empty;
|
114 |
|
|
|
115 |
|
|
reg [LGFIFO:0] r_first, r_mid, r_last, r_next;
|
116 |
|
|
wire [LGFIFO:0] w_first_plus_one;
|
117 |
|
|
wire [LGFIFO:0] next_first, next_last, next_mid, fifo_fill;
|
118 |
|
|
reg wb_pending, last_ack;
|
119 |
|
|
reg [LGFIFO:0] wb_outstanding;
|
120 |
|
|
|
121 |
|
|
wire axi_write_accepted, pending_axi_write;
|
122 |
|
|
|
123 |
|
|
assign pending_axi_write =
|
124 |
|
|
((r_awvalid) || (i_axi_awvalid && o_axi_awready))
|
125 |
|
|
&&((r_wvalid)|| (i_axi_wvalid && o_axi_wready));
|
126 |
|
|
|
127 |
|
|
assign axi_write_accepted =
|
128 |
|
|
(!o_wb_stb || !i_wb_stall) && (!fifo_full) && (!err_state)
|
129 |
|
|
&& (pending_axi_write);
|
130 |
|
|
|
131 |
|
|
initial o_wb_cyc = 1'b0;
|
132 |
|
|
initial o_wb_stb = 1'b0;
|
133 |
|
|
always @(posedge i_clk)
|
134 |
|
|
if ((w_reset)||((o_wb_cyc)&&(i_wb_err))||(err_state))
|
135 |
|
|
o_wb_stb <= 1'b0;
|
136 |
|
|
else if (axi_write_accepted)
|
137 |
|
|
o_wb_stb <= 1'b1;
|
138 |
|
|
else if ((o_wb_cyc)&&(!i_wb_stall))
|
139 |
|
|
o_wb_stb <= 1'b0;
|
140 |
|
|
|
141 |
|
|
always @(*)
|
142 |
|
|
o_wb_cyc = (wb_pending)||(o_wb_stb);
|
143 |
|
|
|
144 |
|
|
always @(posedge i_clk)
|
145 |
|
|
if (!o_wb_stb || !i_wb_stall)
|
146 |
|
|
begin
|
147 |
|
|
if (r_awvalid)
|
148 |
|
|
o_wb_addr <= r_addr;
|
149 |
|
|
else
|
150 |
|
|
o_wb_addr <= i_axi_awaddr[AW+1:2];
|
151 |
|
|
|
152 |
|
|
if (r_wvalid)
|
153 |
|
|
begin
|
154 |
|
|
o_wb_data <= r_data;
|
155 |
|
|
o_wb_sel <= r_sel;
|
156 |
|
|
end else begin
|
157 |
|
|
o_wb_data <= i_axi_wdata;
|
158 |
|
|
o_wb_sel <= i_axi_wstrb;
|
159 |
|
|
end
|
160 |
|
|
end
|
161 |
|
|
|
162 |
|
|
initial r_awvalid <= 1'b0;
|
163 |
|
|
always @(posedge i_clk)
|
164 |
|
|
begin
|
165 |
|
|
if ((i_axi_awvalid)&&(o_axi_awready))
|
166 |
|
|
begin
|
167 |
|
|
r_addr <= i_axi_awaddr[AW+1:2];
|
168 |
|
|
r_awvalid <= (!axi_write_accepted);
|
169 |
|
|
end else if (axi_write_accepted)
|
170 |
|
|
r_awvalid <= 1'b0;
|
171 |
|
|
|
172 |
|
|
if (w_reset)
|
173 |
|
|
r_awvalid <= 1'b0;
|
174 |
|
|
end
|
175 |
|
|
|
176 |
|
|
initial r_wvalid <= 1'b0;
|
177 |
|
|
always @(posedge i_clk)
|
178 |
|
|
begin
|
179 |
|
|
if ((i_axi_wvalid)&&(o_axi_wready))
|
180 |
|
|
begin
|
181 |
|
|
r_data <= i_axi_wdata;
|
182 |
|
|
r_sel <= i_axi_wstrb;
|
183 |
|
|
r_wvalid <= (!axi_write_accepted);
|
184 |
|
|
end else if (axi_write_accepted)
|
185 |
|
|
r_wvalid <= 1'b0;
|
186 |
|
|
|
187 |
|
|
if (w_reset)
|
188 |
|
|
r_wvalid <= 1'b0;
|
189 |
|
|
end
|
190 |
|
|
|
191 |
|
|
initial o_axi_awready = 1'b1;
|
192 |
|
|
always @(posedge i_clk)
|
193 |
|
|
if (w_reset)
|
194 |
|
|
o_axi_awready <= 1'b1;
|
195 |
|
|
else if ((o_wb_stb && i_wb_stall)
|
196 |
|
|
&&(r_awvalid || (i_axi_awvalid && o_axi_awready)))
|
197 |
|
|
// Once a request has been received while the interface is
|
198 |
|
|
// stalled, we must stall and wait for it to clear
|
199 |
|
|
o_axi_awready <= 1'b0;
|
200 |
|
|
else if (err_state && (r_awvalid || (i_axi_awvalid && o_axi_awready)))
|
201 |
|
|
o_axi_awready <= 1'b0;
|
202 |
|
|
else if ((r_awvalid || (i_axi_awvalid && o_axi_awready))
|
203 |
|
|
&&(!r_wvalid && (!i_axi_wvalid || !o_axi_wready)))
|
204 |
|
|
// If the write address is given without any corresponding
|
205 |
|
|
// write data, immediately stall and wait for the write data
|
206 |
|
|
o_axi_awready <= 1'b0;
|
207 |
|
|
else if (!o_axi_awready && o_wb_stb && i_wb_stall)
|
208 |
|
|
// Once stalled, remain stalled while the WB bus is stalled
|
209 |
|
|
o_axi_awready <= 1'b0;
|
210 |
|
|
else if (fifo_full && (r_awvalid || (!o_axi_bvalid || !i_axi_bready)))
|
211 |
|
|
// Once the FIFO is full, we must remain stalled until at
|
212 |
|
|
// least one acknowledgment has been accepted
|
213 |
|
|
o_axi_awready <= 1'b0;
|
214 |
|
|
else if ((!o_axi_bvalid || !i_axi_bready)
|
215 |
|
|
&& (r_awvalid || (i_axi_awvalid && o_axi_awready)))
|
216 |
|
|
// If ever the FIFO becomes full, we must immediately drop
|
217 |
|
|
// the o_axi_awready signal
|
218 |
|
|
o_axi_awready <= (next_first[LGFIFO-1:0] != r_last[LGFIFO-1:0])
|
219 |
|
|
&&(next_first[LGFIFO]==r_last[LGFIFO]);
|
220 |
|
|
else
|
221 |
|
|
o_axi_awready <= 1'b1;
|
222 |
|
|
|
223 |
|
|
initial o_axi_wready = 1'b1;
|
224 |
|
|
always @(posedge i_clk)
|
225 |
|
|
if (w_reset)
|
226 |
|
|
o_axi_wready <= 1'b1;
|
227 |
|
|
else if ((o_wb_stb && i_wb_stall)
|
228 |
|
|
&&(r_wvalid || (i_axi_wvalid && o_axi_wready)))
|
229 |
|
|
// Once a request has been received while the interface is
|
230 |
|
|
// stalled, we must stall and wait for it to clear
|
231 |
|
|
o_axi_wready <= 1'b0;
|
232 |
|
|
else if (err_state && (r_wvalid || (i_axi_wvalid && o_axi_wready)))
|
233 |
|
|
o_axi_wready <= 1'b0;
|
234 |
|
|
else if ((r_wvalid || (i_axi_wvalid && o_axi_wready))
|
235 |
|
|
&&(!r_awvalid && (!i_axi_awvalid || !o_axi_awready)))
|
236 |
|
|
// If the write address is given without any corresponding
|
237 |
|
|
// write data, immediately stall and wait for the write data
|
238 |
|
|
o_axi_wready <= 1'b0;
|
239 |
|
|
else if (!o_axi_wready && o_wb_stb && i_wb_stall)
|
240 |
|
|
// Once stalled, remain stalled while the WB bus is stalled
|
241 |
|
|
o_axi_wready <= 1'b0;
|
242 |
|
|
else if (fifo_full && (r_wvalid || (!o_axi_bvalid || !i_axi_bready)))
|
243 |
|
|
// Once the FIFO is full, we must remain stalled until at
|
244 |
|
|
// least one acknowledgment has been accepted
|
245 |
|
|
o_axi_wready <= 1'b0;
|
246 |
|
|
else if ((!o_axi_bvalid || !i_axi_bready)
|
247 |
|
|
&& (i_axi_wvalid && o_axi_wready))
|
248 |
|
|
// If ever the FIFO becomes full, we must immediately drop
|
249 |
|
|
// the o_axi_wready signal
|
250 |
|
|
o_axi_wready <= (next_first[LGFIFO-1:0] != r_last[LGFIFO-1:0])
|
251 |
|
|
&&(next_first[LGFIFO]==r_last[LGFIFO]);
|
252 |
|
|
else
|
253 |
|
|
o_axi_wready <= 1'b1;
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
initial wb_pending = 0;
|
257 |
|
|
initial wb_outstanding = 0;
|
258 |
|
|
initial last_ack = 1;
|
259 |
|
|
always @(posedge i_clk)
|
260 |
|
|
if ((w_reset)||(!o_wb_cyc)||(i_wb_err)||(err_state))
|
261 |
|
|
begin
|
262 |
|
|
wb_pending <= 1'b0;
|
263 |
|
|
wb_outstanding <= 0;
|
264 |
|
|
last_ack <= 1;
|
265 |
|
|
end else case({ (o_wb_stb)&&(!i_wb_stall), i_wb_ack })
|
266 |
|
|
2'b01: begin
|
267 |
|
|
wb_outstanding <= wb_outstanding - 1'b1;
|
268 |
|
|
wb_pending <= (wb_outstanding >= 2);
|
269 |
|
|
last_ack <= (wb_outstanding <= 2);
|
270 |
|
|
end
|
271 |
|
|
2'b10: begin
|
272 |
|
|
wb_outstanding <= wb_outstanding + 1'b1;
|
273 |
|
|
wb_pending <= 1'b1;
|
274 |
|
|
last_ack <= (wb_outstanding == 0);
|
275 |
|
|
end
|
276 |
|
|
default: begin end
|
277 |
|
|
endcase
|
278 |
|
|
|
279 |
|
|
assign next_first = r_first + 1'b1;
|
280 |
|
|
assign next_last = r_last + 1'b1;
|
281 |
|
|
assign next_mid = r_mid + 1'b1;
|
282 |
|
|
assign fifo_fill = (r_first - r_last);
|
283 |
|
|
|
284 |
|
|
initial fifo_full = 1'b0;
|
285 |
|
|
initial fifo_empty = 1'b1;
|
286 |
|
|
always @(posedge i_clk)
|
287 |
|
|
if (w_reset)
|
288 |
|
|
begin
|
289 |
|
|
fifo_full <= 1'b0;
|
290 |
|
|
fifo_empty <= 1'b1;
|
291 |
|
|
end else case({ (o_axi_bvalid)&&(i_axi_bready),
|
292 |
|
|
(axi_write_accepted) })
|
293 |
|
|
2'b01: begin
|
294 |
|
|
fifo_full <= (next_first[LGFIFO-1:0] == r_last[LGFIFO-1:0])
|
295 |
|
|
&&(next_first[LGFIFO]!=r_last[LGFIFO]);
|
296 |
|
|
fifo_empty <= 1'b0;
|
297 |
|
|
end
|
298 |
|
|
2'b10: begin
|
299 |
|
|
fifo_full <= 1'b0;
|
300 |
|
|
fifo_empty <= 1'b0;
|
301 |
|
|
end
|
302 |
|
|
default: begin end
|
303 |
|
|
endcase
|
304 |
|
|
|
305 |
|
|
initial r_first = 0;
|
306 |
|
|
always @(posedge i_clk)
|
307 |
|
|
if (w_reset)
|
308 |
|
|
r_first <= 0;
|
309 |
|
|
else if (axi_write_accepted)
|
310 |
|
|
r_first <= r_first + 1'b1;
|
311 |
|
|
|
312 |
|
|
initial r_mid = 0;
|
313 |
|
|
always @(posedge i_clk)
|
314 |
|
|
if (w_reset)
|
315 |
|
|
r_mid <= 0;
|
316 |
|
|
else if ((o_wb_cyc)&&((i_wb_ack)||(i_wb_err)))
|
317 |
|
|
r_mid <= r_mid + 1'b1;
|
318 |
|
|
else if ((err_state)&&(r_mid != r_first))
|
319 |
|
|
r_mid <= r_mid + 1'b1;
|
320 |
|
|
|
321 |
|
|
initial r_last = 0;
|
322 |
|
|
always @(posedge i_clk)
|
323 |
|
|
if (w_reset)
|
324 |
|
|
r_last <= 0;
|
325 |
|
|
else if ((o_axi_bvalid)&&(i_axi_bready))
|
326 |
|
|
r_last <= r_last + 1'b1;
|
327 |
|
|
|
328 |
|
|
reg [LGFIFO:0] err_loc;
|
329 |
|
|
always @(posedge i_clk)
|
330 |
|
|
if ((o_wb_cyc)&&(i_wb_err))
|
331 |
|
|
err_loc <= r_mid;
|
332 |
|
|
|
333 |
|
|
wire [DW:0] read_data;
|
334 |
|
|
|
335 |
|
|
initial o_axi_bresp = 2'b00;
|
336 |
|
|
always @(posedge i_clk)
|
337 |
|
|
if (w_reset)
|
338 |
|
|
o_axi_bresp <= 0;
|
339 |
|
|
else if ((!o_axi_bvalid)||(i_axi_bready))
|
340 |
|
|
begin
|
341 |
|
|
if ((!err_state)&&((!o_wb_cyc)||(!i_wb_err)))
|
342 |
|
|
o_axi_bresp <= 2'b00;
|
343 |
|
|
else if ((!err_state)&&(o_wb_cyc)&&(i_wb_err))
|
344 |
|
|
begin
|
345 |
|
|
if (o_axi_bvalid)
|
346 |
|
|
o_axi_bresp <= (r_mid == next_last) ? 2'b10 : 2'b00;
|
347 |
|
|
else
|
348 |
|
|
o_axi_bresp <= (r_mid == r_last) ? 2'b10 : 2'b00;
|
349 |
|
|
end else if (err_state)
|
350 |
|
|
begin
|
351 |
|
|
if (next_last == err_loc)
|
352 |
|
|
o_axi_bresp <= 2'b10;
|
353 |
|
|
else if (o_axi_bresp[1])
|
354 |
|
|
o_axi_bresp <= 2'b11;
|
355 |
|
|
end else
|
356 |
|
|
o_axi_bresp <= 0;
|
357 |
|
|
end
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
reg err_state;
|
361 |
|
|
initial err_state = 0;
|
362 |
|
|
always @(posedge i_clk)
|
363 |
|
|
if (w_reset)
|
364 |
|
|
err_state <= 0;
|
365 |
|
|
else if (r_first == r_last)
|
366 |
|
|
err_state <= 0;
|
367 |
|
|
else if ((o_wb_cyc)&&(i_wb_err))
|
368 |
|
|
err_state <= 1'b1;
|
369 |
|
|
|
370 |
|
|
initial o_axi_bvalid = 1'b0;
|
371 |
|
|
always @(posedge i_clk)
|
372 |
|
|
if (w_reset)
|
373 |
|
|
o_axi_bvalid <= 0;
|
374 |
|
|
else if ((o_wb_cyc)&&((i_wb_ack)||(i_wb_err)))
|
375 |
|
|
o_axi_bvalid <= 1'b1;
|
376 |
|
|
else if ((o_axi_bvalid)&&(i_axi_bready))
|
377 |
|
|
begin
|
378 |
|
|
if (err_state)
|
379 |
|
|
o_axi_bvalid <= (next_last != r_first);
|
380 |
|
|
else
|
381 |
|
|
o_axi_bvalid <= (next_last != r_mid);
|
382 |
|
|
end
|
383 |
|
|
|
384 |
|
|
// Make Verilator happy
|
385 |
|
|
// verilator lint_off UNUSED
|
386 |
|
|
// verilator lint_on UNUSED
|
387 |
|
|
|
388 |
|
|
`ifdef FORMAL
|
389 |
|
|
reg f_past_valid;
|
390 |
|
|
wire f_axi_stalled;
|
391 |
|
|
wire [LGFIFO:0] f_wb_nreqs, f_wb_nacks, f_wb_outstanding;
|
392 |
|
|
wire [LGFIFO:0] wb_fill;
|
393 |
|
|
wire [LGFIFO:0] f_axi_rd_outstanding,
|
394 |
|
|
f_axi_wr_outstanding,
|
395 |
|
|
f_axi_awr_outstanding;
|
396 |
|
|
wire [LGFIFO:0] f_mid_minus_err, f_err_minus_last,
|
397 |
|
|
f_first_minus_err;
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
initial f_past_valid = 1'b0;
|
401 |
|
|
always @(posedge i_clk)
|
402 |
|
|
f_past_valid <= 1'b1;
|
403 |
|
|
|
404 |
|
|
`ifdef AXILWR2WBSP
|
405 |
|
|
`define ASSUME assume
|
406 |
|
|
`else
|
407 |
|
|
`define ASSUME assert
|
408 |
|
|
`endif
|
409 |
|
|
|
410 |
|
|
always @(*)
|
411 |
|
|
if (!f_past_valid)
|
412 |
|
|
`ASSUME(w_reset);
|
413 |
|
|
|
414 |
|
|
always @(*)
|
415 |
|
|
if (err_state)
|
416 |
|
|
begin
|
417 |
|
|
assert(!r_awvalid || !o_axi_awready);
|
418 |
|
|
assert(!r_wvalid || !o_axi_wready);
|
419 |
|
|
|
420 |
|
|
assert(!o_wb_cyc);
|
421 |
|
|
end
|
422 |
|
|
|
423 |
|
|
always @(*)
|
424 |
|
|
if ((fifo_empty)&&(!w_reset))
|
425 |
|
|
assert((!fifo_full)&&(r_first == r_last)&&(r_mid == r_last));
|
426 |
|
|
|
427 |
|
|
always @(*)
|
428 |
|
|
if (fifo_full)
|
429 |
|
|
begin
|
430 |
|
|
assert(!fifo_empty);
|
431 |
|
|
assert(r_first[LGFIFO-1:0] == r_last[LGFIFO-1:0]);
|
432 |
|
|
assert(r_first[LGFIFO] != r_last[LGFIFO]);
|
433 |
|
|
end
|
434 |
|
|
|
435 |
|
|
always @(*)
|
436 |
|
|
assert(fifo_fill <= (1<<LGFIFO));
|
437 |
|
|
|
438 |
|
|
always @(*)
|
439 |
|
|
if (fifo_full)
|
440 |
|
|
begin
|
441 |
|
|
assert(!r_awvalid || !o_axi_awready);
|
442 |
|
|
assert(!r_wvalid || !o_axi_wready);
|
443 |
|
|
end
|
444 |
|
|
|
445 |
|
|
always @(*)
|
446 |
|
|
assert(fifo_full == (fifo_fill >= (1<<LGFIFO)));
|
447 |
|
|
always @(*)
|
448 |
|
|
assert(wb_pending == (wb_outstanding != 0));
|
449 |
|
|
|
450 |
|
|
always @(*)
|
451 |
|
|
assert(last_ack == (wb_outstanding <= 1));
|
452 |
|
|
|
453 |
|
|
|
454 |
|
|
assign f_first = r_first;
|
455 |
|
|
assign f_mid = r_mid;
|
456 |
|
|
assign f_last = r_last;
|
457 |
|
|
assign f_wpending = { r_awvalid, r_wvalid };
|
458 |
|
|
|
459 |
|
|
fwb_master #(
|
460 |
|
|
.AW(AW), .DW(DW), .F_LGDEPTH(LGFIFO+1)
|
461 |
|
|
) fwb(i_clk, w_reset,
|
462 |
|
|
o_wb_cyc, o_wb_stb, 1'b1, o_wb_addr, o_wb_data, o_wb_sel,
|
463 |
|
|
i_wb_ack, i_wb_stall, {(DW){1'b0}}, i_wb_err,
|
464 |
|
|
f_wb_nreqs,f_wb_nacks, f_wb_outstanding);
|
465 |
|
|
|
466 |
|
|
always @(*)
|
467 |
|
|
if (o_wb_cyc)
|
468 |
|
|
assert(f_wb_outstanding == wb_outstanding);
|
469 |
|
|
|
470 |
|
|
always @(*)
|
471 |
|
|
if (o_wb_cyc)
|
472 |
|
|
assert(wb_outstanding <= (1<<LGFIFO));
|
473 |
|
|
|
474 |
|
|
assign wb_fill = r_first - r_mid;
|
475 |
|
|
always @(*)
|
476 |
|
|
assert(wb_fill <= fifo_fill);
|
477 |
|
|
always @(*)
|
478 |
|
|
if (!w_reset)
|
479 |
|
|
begin
|
480 |
|
|
if (o_wb_stb)
|
481 |
|
|
assert(wb_outstanding+1 == wb_fill);
|
482 |
|
|
else if (o_wb_cyc)
|
483 |
|
|
assert(wb_outstanding == wb_fill);
|
484 |
|
|
else if (!err_state)
|
485 |
|
|
assert((wb_fill == 0)&&(wb_outstanding == 0));
|
486 |
|
|
end
|
487 |
|
|
|
488 |
|
|
faxil_slave #(
|
489 |
|
|
.C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH),
|
490 |
|
|
.F_LGDEPTH(LGFIFO+1),
|
491 |
|
|
.F_OPT_NO_READS(1),
|
492 |
|
|
.F_AXI_MAXWAIT(0),
|
493 |
|
|
.F_AXI_MAXDELAY(0)
|
494 |
|
|
) faxil(i_clk, i_axi_reset_n,
|
495 |
|
|
//
|
496 |
|
|
// AXI write address channel signals
|
497 |
|
|
o_axi_awready, i_axi_awaddr, i_axi_awcache, i_axi_awprot, i_axi_awvalid,
|
498 |
|
|
// AXI write data channel signals
|
499 |
|
|
o_axi_wready, i_axi_wdata, i_axi_wstrb, i_axi_wvalid,
|
500 |
|
|
// AXI write response channel signals
|
501 |
|
|
o_axi_bresp, o_axi_bvalid, i_axi_bready,
|
502 |
|
|
// AXI read address channel signals
|
503 |
|
|
1'b0, i_axi_awaddr, i_axi_awcache, i_axi_awprot,
|
504 |
|
|
1'b0,
|
505 |
|
|
// AXI read data channel signals
|
506 |
|
|
o_axi_bresp, 1'b0, {(DW){1'b0}}, 1'b0,
|
507 |
|
|
f_axi_rd_outstanding, f_axi_wr_outstanding,
|
508 |
|
|
f_axi_awr_outstanding);
|
509 |
|
|
|
510 |
|
|
always @(*)
|
511 |
|
|
assert(f_axi_wr_outstanding - (r_wvalid ? 1:0)
|
512 |
|
|
== f_axi_awr_outstanding - (r_awvalid ? 1:0));
|
513 |
|
|
always @(*)
|
514 |
|
|
assert(f_axi_rd_outstanding == 0);
|
515 |
|
|
always @(*)
|
516 |
|
|
assert(f_axi_wr_outstanding - (r_wvalid ? 1:0) == fifo_fill);
|
517 |
|
|
always @(*)
|
518 |
|
|
assert(f_axi_awr_outstanding - (r_awvalid ? 1:0) == fifo_fill);
|
519 |
|
|
always @(*)
|
520 |
|
|
if (r_wvalid) assert(f_axi_wr_outstanding > 0);
|
521 |
|
|
always @(*)
|
522 |
|
|
if (r_awvalid) assert(f_axi_awr_outstanding > 0);
|
523 |
|
|
|
524 |
|
|
assign f_mid_minus_err = f_mid - err_loc;
|
525 |
|
|
assign f_err_minus_last = err_loc - f_last;
|
526 |
|
|
assign f_first_minus_err = f_first - err_loc;
|
527 |
|
|
always @(*)
|
528 |
|
|
if (o_axi_bvalid)
|
529 |
|
|
begin
|
530 |
|
|
if (!err_state)
|
531 |
|
|
assert(!o_axi_bresp[1]);
|
532 |
|
|
else if (err_loc == f_last)
|
533 |
|
|
assert(o_axi_bresp == 2'b10);
|
534 |
|
|
else if (f_err_minus_last < (1<<LGFIFO))
|
535 |
|
|
assert(!o_axi_bresp[1]);
|
536 |
|
|
else
|
537 |
|
|
assert(o_axi_bresp[1]);
|
538 |
|
|
end
|
539 |
|
|
|
540 |
|
|
always @(*)
|
541 |
|
|
if (err_state)
|
542 |
|
|
assert(o_axi_bvalid == (r_first != r_last));
|
543 |
|
|
else
|
544 |
|
|
assert(o_axi_bvalid == (r_mid != r_last));
|
545 |
|
|
|
546 |
|
|
always @(*)
|
547 |
|
|
if (err_state)
|
548 |
|
|
assert(f_first_minus_err <= (1<<LGFIFO));
|
549 |
|
|
|
550 |
|
|
always @(*)
|
551 |
|
|
if (err_state)
|
552 |
|
|
assert(f_first_minus_err != 0);
|
553 |
|
|
|
554 |
|
|
always @(*)
|
555 |
|
|
if (err_state)
|
556 |
|
|
assert(f_mid_minus_err <= f_first_minus_err);
|
557 |
|
|
|
558 |
|
|
assign f_axi_stalled = (fifo_full)||(err_state)
|
559 |
|
|
||((o_wb_stb)&&(i_wb_stall));
|
560 |
|
|
|
561 |
|
|
always @(*)
|
562 |
|
|
if ((r_awvalid)&&(f_axi_stalled))
|
563 |
|
|
assert(!o_axi_awready);
|
564 |
|
|
always @(*)
|
565 |
|
|
if ((r_wvalid)&&(f_axi_stalled))
|
566 |
|
|
assert(!o_axi_wready);
|
567 |
|
|
|
568 |
|
|
|
569 |
|
|
// WB covers
|
570 |
|
|
always @(*)
|
571 |
|
|
cover(o_wb_cyc && o_wb_stb && !i_wb_stall);
|
572 |
|
|
always @(*)
|
573 |
|
|
cover(o_wb_cyc && i_wb_ack);
|
574 |
|
|
|
575 |
|
|
always @(posedge i_clk)
|
576 |
|
|
cover(o_wb_cyc && $past(o_wb_cyc && o_wb_stb && !i_wb_stall));//
|
577 |
|
|
|
578 |
|
|
always @(posedge i_clk)
|
579 |
|
|
cover(o_wb_cyc && o_wb_stb && !i_wb_stall
|
580 |
|
|
&& $past(o_wb_cyc && o_wb_stb && !i_wb_stall,2)
|
581 |
|
|
&& $past(o_wb_cyc && o_wb_stb && !i_wb_stall,4)); //
|
582 |
|
|
|
583 |
|
|
always @(posedge i_clk)
|
584 |
|
|
cover(o_wb_cyc && o_wb_stb && !i_wb_stall
|
585 |
|
|
&& $past(o_wb_cyc && o_wb_stb && !i_wb_stall)
|
586 |
|
|
&& $past(o_wb_cyc && o_wb_stb && !i_wb_stall)); //
|
587 |
|
|
|
588 |
|
|
always @(posedge i_clk)
|
589 |
|
|
cover(o_wb_cyc && i_wb_ack
|
590 |
|
|
&& $past(o_wb_cyc && i_wb_ack)
|
591 |
|
|
&& $past(o_wb_cyc && i_wb_ack)); //
|
592 |
|
|
|
593 |
|
|
// AXI covers
|
594 |
|
|
always @(posedge i_clk)
|
595 |
|
|
cover(o_axi_bvalid && i_axi_bready
|
596 |
|
|
&& $past(o_axi_bvalid && i_axi_bready,1)
|
597 |
|
|
&& $past(o_axi_bvalid && i_axi_bready,2)); //
|
598 |
|
|
|
599 |
|
|
`endif
|
600 |
|
|
endmodule
|