-
Notifications
You must be signed in to change notification settings - Fork 101
/
axlite2wbsp.v
568 lines (538 loc) · 14.4 KB
/
axlite2wbsp.v
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
////////////////////////////////////////////////////////////////////////////////
//
// Filename: axlite2wbsp.v
// {{{
// Project: WB2AXIPSP: bus bridges and other odds and ends
//
// Purpose: Take an AXI lite input, and convert it into WB.
//
// We'll treat AXI as two separate busses: one for writes, another for
// reads, further, we'll insist that the two channels AXI uses for writes
// combine into one channel for our purposes.
//
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
// }}}
// Copyright (C) 2016-2024, Gisselquist Technology, LLC
// {{{
// This file is part of the WB2AXIP project.
//
// The WB2AXIP project contains free software and gateware, licensed under the
// Apache License, Version 2.0 (the "License"). You may not use this project,
// or this file, except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
//
////////////////////////////////////////////////////////////////////////////////
//
//
`default_nettype none
// }}}
module axlite2wbsp #(
// {{{
parameter C_AXI_DATA_WIDTH = 32,// Width of the AXI R&W data
parameter C_AXI_ADDR_WIDTH = 28, // AXI Address width
parameter LGFIFO = 4,
`ifdef FORMAL
parameter F_MAXSTALL = 3,
parameter F_MAXDELAY = 3,
`endif
parameter [0:0] OPT_READONLY = 1'b0,
parameter [0:0] OPT_WRITEONLY = 1'b0,
localparam AXILLSB = $clog2(C_AXI_DATA_WIDTH/8)
// }}}
) (
// {{{
input wire i_clk, // System clock
input wire i_axi_reset_n,
// AXI write address channel signals
// {{{
input wire i_axi_awvalid,
output wire o_axi_awready,
input wire [C_AXI_ADDR_WIDTH-1:0] i_axi_awaddr,
input wire [2:0] i_axi_awprot,
// }}}
// AXI write data channel signals
// {{{
input wire i_axi_wvalid,
output wire o_axi_wready,
input wire [C_AXI_DATA_WIDTH-1:0] i_axi_wdata,
input wire [C_AXI_DATA_WIDTH/8-1:0] i_axi_wstrb,
// }}}
// AXI write response channel signals
// {{{
output wire o_axi_bvalid,
input wire i_axi_bready,
output wire [1:0] o_axi_bresp,
// }}}
// AXI read address channel signals
// {{{
input wire i_axi_arvalid,
output wire o_axi_arready,
input wire [C_AXI_ADDR_WIDTH-1:0] i_axi_araddr,
input wire [2:0] i_axi_arprot,
// }}}
// AXI read data channel signals
// {{{
output wire o_axi_rvalid,
input wire i_axi_rready,
output wire [C_AXI_DATA_WIDTH-1:0] o_axi_rdata,
output wire [1:0] o_axi_rresp,
// }}}
// Wishbone signals
// {{{
// We'll share the clock and the reset
output wire o_reset,
output wire o_wb_cyc,
output wire o_wb_stb,
output wire o_wb_we,
output wire [C_AXI_ADDR_WIDTH-AXILLSB-1:0] o_wb_addr,
output wire [C_AXI_DATA_WIDTH-1:0] o_wb_data,
output wire [C_AXI_DATA_WIDTH/8-1:0] o_wb_sel,
input wire i_wb_stall,
input wire i_wb_ack,
input wire [(C_AXI_DATA_WIDTH-1):0] i_wb_data,
input wire i_wb_err
// }}}
// }}}
);
// Local definitions
// {{{
localparam DW = C_AXI_DATA_WIDTH;
localparam AW = C_AXI_ADDR_WIDTH-AXILLSB;
//
//
//
wire [(AW-1):0] w_wb_addr, r_wb_addr;
wire [(DW-1):0] w_wb_data;
wire [(DW/8-1):0] w_wb_sel, r_wb_sel;
wire r_wb_err, r_wb_cyc, r_wb_stb, r_wb_stall, r_wb_ack;
wire w_wb_err, w_wb_cyc, w_wb_stb, w_wb_stall, w_wb_ack;
// verilator lint_off UNUSED
wire r_wb_we, w_wb_we;
assign r_wb_we = 1'b0;
assign w_wb_we = 1'b1;
// verilator lint_on UNUSED
`ifdef FORMAL
// {{{
// Verilator lint_off UNUSED
localparam F_LGDEPTH = LGFIFO+1;
wire [LGFIFO:0] f_wr_fifo_first, f_rd_fifo_first,
f_wr_fifo_mid, f_rd_fifo_mid,
f_wr_fifo_last, f_rd_fifo_last;
// Verilator lint_on UNUSED
wire [(F_LGDEPTH-1):0] f_wb_nreqs, f_wb_nacks,
f_wb_outstanding;
wire [(F_LGDEPTH-1):0] f_wb_wr_nreqs, f_wb_wr_nacks,
f_wb_wr_outstanding;
wire [(F_LGDEPTH-1):0] f_wb_rd_nreqs, f_wb_rd_nacks,
f_wb_rd_outstanding;
wire f_pending_awvalid, f_pending_wvalid;
// }}}
`endif
// }}}
////////////////////////////////////////////////////////////////////////
//
// AXI-lite write channel to WB processing
// {{{
////////////////////////////////////////////////////////////////////////
//
//
generate if (!OPT_READONLY)
begin : AXI_WR
// {{{
axilwr2wbsp #(
// {{{
// .F_LGDEPTH(F_LGDEPTH),
// .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH),
.C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH), // .AW(AW),
.LGFIFO(LGFIFO)
// }}}
) axi_write_decoder (
// {{{
.i_clk(i_clk), .i_axi_reset_n(i_axi_reset_n),
//
.i_axi_awvalid(i_axi_awvalid),
.o_axi_awready(o_axi_awready),
.i_axi_awaddr( i_axi_awaddr),
.i_axi_awprot( i_axi_awprot),
//
.i_axi_wvalid( i_axi_wvalid),
.o_axi_wready( o_axi_wready),
.i_axi_wdata( i_axi_wdata),
.i_axi_wstrb( i_axi_wstrb),
//
.o_axi_bvalid(o_axi_bvalid),
.i_axi_bready(i_axi_bready),
.o_axi_bresp(o_axi_bresp),
//
.o_wb_cyc( w_wb_cyc),
.o_wb_stb( w_wb_stb),
.o_wb_addr( w_wb_addr),
.o_wb_data( w_wb_data),
.o_wb_sel( w_wb_sel),
.i_wb_stall(w_wb_stall),
.i_wb_ack( w_wb_ack),
.i_wb_err( w_wb_err)
`ifdef FORMAL
// {{{
,
.f_first(f_wr_fifo_first),
.f_mid( f_wr_fifo_mid),
.f_last( f_wr_fifo_last),
.f_wpending({ f_pending_awvalid, f_pending_wvalid })
// }}}
`endif
// }}}
);
// }}}
end else begin : EMPTY_WRITES
// {{{
assign w_wb_cyc = 0;
assign w_wb_stb = 0;
assign w_wb_addr = 0;
assign w_wb_data = 0;
assign w_wb_sel = 0;
assign o_axi_awready = 0;
assign o_axi_wready = 0;
assign o_axi_bvalid = (i_axi_wvalid);
assign o_axi_bresp = 2'b11;
`ifdef FORMAL
assign f_wr_fifo_first = 0;
assign f_wr_fifo_mid = 0;
assign f_wr_fifo_last = 0;
assign f_pending_awvalid=0;
assign f_pending_wvalid =0;
`endif
// }}}
end endgenerate
assign w_wb_we = 1'b1;
// }}}
////////////////////////////////////////////////////////////////////////
//
// AXI-lite read channel to WB processing
// {{{
////////////////////////////////////////////////////////////////////////
//
//
generate if (!OPT_WRITEONLY)
begin : AXI_RD
// {{{
axilrd2wbsp #(
// {{{
// .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH),
.C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH),
.LGFIFO(LGFIFO)
// }}}
) axi_read_decoder(
// {{{
.i_clk(i_clk), .i_axi_reset_n(i_axi_reset_n),
//
.i_axi_arvalid(i_axi_arvalid),
.o_axi_arready(o_axi_arready),
.i_axi_araddr( i_axi_araddr),
.i_axi_arprot( i_axi_arprot),
//
.o_axi_rvalid(o_axi_rvalid),
.i_axi_rready(i_axi_rready),
.o_axi_rdata( o_axi_rdata),
.o_axi_rresp( o_axi_rresp),
//
.o_wb_cyc( r_wb_cyc),
.o_wb_stb( r_wb_stb),
.o_wb_addr( r_wb_addr),
.o_wb_sel( r_wb_sel),
.i_wb_stall(r_wb_stall),
.i_wb_ack( r_wb_ack),
.i_wb_data( i_wb_data),
.i_wb_err( r_wb_err)
`ifdef FORMAL
// {{{
,
.f_first(f_rd_fifo_first),
.f_mid( f_rd_fifo_mid),
.f_last( f_rd_fifo_last)
// }}}
`endif
// }}}
);
// }}}
end else begin : EMPTY_READS
// {{{
assign r_wb_cyc = 0;
assign r_wb_stb = 0;
assign r_wb_addr = 0;
//
assign o_axi_arready = 1'b1;
assign o_axi_rvalid = (i_axi_arvalid)&&(o_axi_arready);
assign o_axi_rresp = (i_axi_arvalid) ? 2'b11 : 2'b00;
assign o_axi_rdata = 0;
`ifdef FORMAL
assign f_rd_fifo_first = 0;
assign f_rd_fifo_mid = 0;
assign f_rd_fifo_last = 0;
`endif
// }}}
end endgenerate
// }}}
////////////////////////////////////////////////////////////////////////
//
// The arbiter that pastes the two sides together
// {{{
////////////////////////////////////////////////////////////////////////
//
//
generate if (OPT_READONLY)
begin : ARB_RD
// {{{
assign o_wb_cyc = r_wb_cyc;
assign o_wb_stb = r_wb_stb;
assign o_wb_we = 1'b0;
assign o_wb_addr = r_wb_addr;
assign o_wb_data = 32'h0;
assign o_wb_sel = r_wb_sel;
assign r_wb_ack = i_wb_ack;
assign r_wb_stall= i_wb_stall;
assign r_wb_ack = i_wb_ack;
assign r_wb_err = i_wb_err;
`ifdef FORMAL
fwb_master #(.DW(DW), .AW(AW),
.F_LGDEPTH(F_LGDEPTH),
.F_MAX_STALL(F_MAXSTALL),
.F_MAX_ACK_DELAY(F_MAXDELAY))
f_wb(i_clk, !i_axi_reset_n,
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
o_wb_sel,
i_wb_ack, i_wb_stall, i_wb_data, i_wb_err,
f_wb_nreqs, f_wb_nacks, f_wb_outstanding);
assign f_wb_rd_nreqs = f_wb_nreqs;
assign f_wb_rd_nacks = f_wb_nacks;
assign f_wb_rd_outstanding = f_wb_outstanding;
//
assign f_wb_wr_nreqs = 0;
assign f_wb_wr_nacks = 0;
assign f_wb_wr_outstanding = 0;
`endif
// }}}
end else if (OPT_WRITEONLY)
begin : ARB_WR
// {{{
assign o_wb_cyc = w_wb_cyc;
assign o_wb_stb = w_wb_stb;
assign o_wb_we = 1'b1;
assign o_wb_addr = w_wb_addr;
assign o_wb_data = w_wb_data;
assign o_wb_sel = w_wb_sel;
assign w_wb_ack = i_wb_ack;
assign w_wb_stall= i_wb_stall;
assign w_wb_ack = i_wb_ack;
assign w_wb_err = i_wb_err;
`ifdef FORMAL
fwb_master #(.DW(DW), .AW(AW),
.F_LGDEPTH(F_LGDEPTH),
.F_MAX_STALL(F_MAXSTALL),
.F_MAX_ACK_DELAY(F_MAXDELAY))
f_wb(i_clk, !i_axi_reset_n,
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
o_wb_sel,
i_wb_ack, i_wb_stall, i_wb_data, i_wb_err,
f_wb_nreqs, f_wb_nacks, f_wb_outstanding);
assign f_wb_wr_nreqs = f_wb_nreqs;
assign f_wb_wr_nacks = f_wb_nacks;
assign f_wb_wr_outstanding = f_wb_outstanding;
//
assign f_wb_rd_nreqs = 0;
assign f_wb_rd_nacks = 0;
assign f_wb_rd_outstanding = 0;
`endif
// }}}
end else begin : ARB_WB
// {{{
wbarbiter #(
// {{{
.DW(DW), .AW(AW)
`ifdef FORMAL
, .F_LGDEPTH(F_LGDEPTH),
.F_MAX_STALL(F_MAXSTALL),
.F_MAX_ACK_DELAY(F_MAXDELAY)
`endif
// }}}
) readorwrite(
// {{{
.i_clk(i_clk), .i_reset(!i_axi_reset_n),
// Channel A - Reads
// {{{
.i_a_cyc(r_wb_cyc), .i_a_stb(r_wb_stb),
.i_a_we(1'b0),
.i_a_adr(r_wb_addr),
.i_a_dat(w_wb_data),
.i_a_sel(r_wb_sel),
.o_a_stall(r_wb_stall),
.o_a_ack(r_wb_ack),
.o_a_err(r_wb_err),
// }}}
// Channel B
// {{{
.i_b_cyc(w_wb_cyc), .i_b_stb(w_wb_stb),
.i_b_we(1'b1),
.i_b_adr(w_wb_addr),
.i_b_dat(w_wb_data),
.i_b_sel(w_wb_sel),
.o_b_stall(w_wb_stall),
.o_b_ack(w_wb_ack),
.o_b_err(w_wb_err),
// }}}
// Arbitrated outgoing channel
// {{{
.o_cyc(o_wb_cyc), .o_stb(o_wb_stb), .o_we(o_wb_we),
.o_adr(o_wb_addr),
.o_dat(o_wb_data),
.o_sel(o_wb_sel),
.i_stall(i_wb_stall),
.i_ack(i_wb_ack),
.i_err(i_wb_err)
// }}}
`ifdef FORMAL
// {{{
,
.f_nreqs(f_wb_nreqs), .f_nacks(f_wb_nacks),
.f_outstanding(f_wb_outstanding),
.f_a_nreqs(f_wb_rd_nreqs), .f_a_nacks(f_wb_rd_nacks),
.f_a_outstanding(f_wb_rd_outstanding),
.f_b_nreqs(f_wb_wr_nreqs), .f_b_nacks(f_wb_wr_nacks),
.f_b_outstanding(f_wb_wr_outstanding)
// }}}
`endif
// }}}
);
// }}}
end endgenerate
// }}}
assign o_reset = (i_axi_reset_n == 1'b0);
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Formal properties
// {{{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
`ifdef FORMAL
// Formal declarations
// {{{
reg f_past_valid;
initial f_past_valid = 1'b0;
always @(posedge i_clk)
f_past_valid <= 1'b1;
wire [(F_LGDEPTH-1):0] f_axi_rd_outstanding,
f_axi_wr_outstanding,
f_axi_awr_outstanding;
wire [LGFIFO:0] f_awr_fifo_axi_used,
f_rd_fifo_axi_used;
// }}}
initial assume(!i_axi_reset_n);
always @(*)
if (!f_past_valid)
assume(!i_axi_reset_n);
faxil_slave #(
// {{{
// .C_AXI_DATA_WIDTH(C_AXI_DATA_WIDTH),
.C_AXI_ADDR_WIDTH(C_AXI_ADDR_WIDTH),
.F_LGDEPTH(F_LGDEPTH),
.F_AXI_MAXWAIT(0),
.F_AXI_MAXDELAY(0)
// }}}
) f_axi(
// {{{
.i_clk(i_clk), .i_axi_reset_n(i_axi_reset_n),
// AXI write address channnel
.i_axi_awvalid(i_axi_awvalid),
.i_axi_awready(o_axi_awready),
.i_axi_awaddr( i_axi_awaddr),
.i_axi_awprot( i_axi_awprot),
// AXI write data channel
.i_axi_wvalid( i_axi_wvalid),
.i_axi_wready( o_axi_wready),
.i_axi_wdata( i_axi_wdata),
.i_axi_wstrb( i_axi_wstrb),
// AXI write acknowledgement channel
.i_axi_bvalid(o_axi_bvalid),
.i_axi_bready(i_axi_bready),
.i_axi_bresp( o_axi_bresp),
// AXI read address channel
.i_axi_arvalid(i_axi_arvalid),
.i_axi_arready(o_axi_arready),
.i_axi_araddr( i_axi_araddr),
.i_axi_arprot( i_axi_arprot),
// AXI read data return
.i_axi_rvalid( o_axi_rvalid),
.i_axi_rready( i_axi_rready),
.i_axi_rdata( o_axi_rdata),
.i_axi_rresp( o_axi_rresp),
// Quantify where we are within a transaction
.f_axi_rd_outstanding( f_axi_rd_outstanding),
.f_axi_wr_outstanding( f_axi_wr_outstanding),
.f_axi_awr_outstanding(f_axi_awr_outstanding)
// }}}
);
assign f_awr_fifo_axi_used = f_wr_fifo_first - f_wr_fifo_last;
assign f_rd_fifo_axi_used = f_rd_fifo_first - f_rd_fifo_last;
always @(*)
begin
assert(f_axi_rd_outstanding == f_rd_fifo_axi_used);
assert(f_axi_awr_outstanding == f_awr_fifo_axi_used+ (f_pending_awvalid?1:0));
assert(f_axi_wr_outstanding == f_awr_fifo_axi_used+ (f_pending_wvalid?1:0));
end
always @(*)
if (OPT_READONLY)
begin
assert(f_axi_awr_outstanding == 0);
assert(f_axi_wr_outstanding == 0);
end
always @(*)
if (OPT_WRITEONLY)
begin
assert(f_axi_rd_outstanding == 0);
end
//
initial assert((!OPT_READONLY)||(!OPT_WRITEONLY));
always @(*)
if (OPT_READONLY)
begin
assume(i_axi_awvalid == 0);
assume(i_axi_wvalid == 0);
assert(o_axi_bvalid == 0);
end
always @(*)
if (OPT_WRITEONLY)
begin
assume(i_axi_arvalid == 0);
assert(o_axi_rvalid == 0);
end
// Make Verilator happy
// {{{
// Verilator lint_off UNUSED
wire unused_formal;
assign unused_formal = &{ 1'b0, f_wb_nreqs, f_wb_nacks,
f_wb_outstanding, f_wb_wr_nreqs, f_wb_wr_nacks,
f_wb_wr_outstanding, f_wb_rd_nreqs, f_wb_rd_nacks,
f_wb_rd_outstanding };
// Verilator lint_on UNUSED
// }}}
`endif
// }}}
endmodule
`ifndef YOSYS
`default_nettype wire
`endif