-
Notifications
You must be signed in to change notification settings - Fork 101
/
axilsafety.v
1449 lines (1332 loc) · 35.8 KB
/
axilsafety.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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
////////////////////////////////////////////////////////////////////////////////
//
// Filename: axilsafety.v
// {{{
// Project: WB2AXIPSP: bus bridges and other odds and ends
//
// Purpose: A AXI-Lite bus fault isolator. This core will isolate any
// downstream AXI-liite slave faults from the upstream channel.
// It sits as a bump in the wire between upstream and downstream channels,
// and so it will consume two clocks--slowing down the slave, but
// potentially allowing developer to recover in case of a fault.
//
// This core is configured by a couple parameters, which are key to its
// functionality.
//
// OPT_TIMEOUT Set this to a number to be roughly the longest time
// period you expect the slave to stall the bus, or likewise
// the longest time period you expect it to wait for a response.
// If the slave takes longer for either task, a fault will be
// detected and reported.
//
// OPT_SELF_RESET If set, this will send a reset signal to the downstream
// core so that you can attempt to restart it without reloading
// the FPGA. If set, the o_reset signal will be used to reset
// the downstream core.
//
// A second key feature of this core are the outgoing fault indicators,
// o_write_fault and o_read_fault. If either signal is ever raised, the
// slave has (somehow) violated protocol on either the write or the
// read channels respectively. Such a violation may (or may not) return an
// error upstream. For example, if the slave returns a response
// following no requests from the master, then no error will be returned
// up stream (doing so would be a protocol violation), but a fault will
// still be detected. Use this line to trigger any internal logic
// analyzers.
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
// }}}
// Copyright (C) 2020-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 axilsafety #(
// {{{
parameter C_AXI_ADDR_WIDTH = 28,
parameter C_AXI_DATA_WIDTH = 32,
parameter OPT_TIMEOUT = 12,
parameter MAX_DEPTH = (OPT_TIMEOUT),
localparam AW = C_AXI_ADDR_WIDTH,
localparam DW = C_AXI_DATA_WIDTH,
localparam LGTIMEOUT = $clog2(OPT_TIMEOUT+1),
localparam LGDEPTH = $clog2(MAX_DEPTH+1),
parameter [0:0] OPT_SELF_RESET = 1'b1,
parameter OPT_MIN_RESET = 16
`ifdef FORMAL
, parameter [0:0] F_OPT_WRITES = 1'b1,
parameter [0:0] F_OPT_READS = 1'b1,
parameter [0:0] F_OPT_FAULTLESS = 1'b1
`endif
// }}}
) (
// {{{
output reg o_write_fault,
output reg o_read_fault,
//
input wire S_AXI_ACLK,
input wire S_AXI_ARESETN,
output reg M_AXI_ARESETN,
//
input wire S_AXI_AWVALID,
output reg S_AXI_AWREADY,
input wire [AW-1:0] S_AXI_AWADDR,
input wire [2:0] S_AXI_AWPROT,
//
input wire S_AXI_WVALID,
output reg S_AXI_WREADY,
input wire [DW-1:0] S_AXI_WDATA,
input wire [DW/8-1:0] S_AXI_WSTRB,
//
output reg S_AXI_BVALID,
input wire S_AXI_BREADY,
output reg [1:0] S_AXI_BRESP,
//
input wire S_AXI_ARVALID,
output reg S_AXI_ARREADY,
input wire [AW-1:0] S_AXI_ARADDR,
input wire [2:0] S_AXI_ARPROT,
//
output reg S_AXI_RVALID,
input wire S_AXI_RREADY,
output reg [DW-1:0] S_AXI_RDATA,
output reg [1:0] S_AXI_RRESP,
//
//
//
output reg M_AXI_AWVALID,
input wire M_AXI_AWREADY,
output reg [AW-1:0] M_AXI_AWADDR,
output reg [2:0] M_AXI_AWPROT,
//
output reg M_AXI_WVALID,
input wire M_AXI_WREADY,
output reg [DW-1:0] M_AXI_WDATA,
output reg [DW/8-1:0] M_AXI_WSTRB,
//
input wire M_AXI_BVALID,
output wire M_AXI_BREADY,
input wire [1:0] M_AXI_BRESP,
//
output reg M_AXI_ARVALID,
input wire M_AXI_ARREADY,
output reg [AW-1:0] M_AXI_ARADDR,
output reg [2:0] M_AXI_ARPROT,
//
input wire M_AXI_RVALID,
output wire M_AXI_RREADY,
input wire [DW-1:0] M_AXI_RDATA,
input wire [1:0] M_AXI_RRESP
// }}}
);
// localparam, wire, and register declarations
// {{{
localparam OPT_LOWPOWER = 1'b0;
localparam OKAY = 2'b00,
EXOKAY = 2'b01,
SLVERR = 2'b10;
reg [LGDEPTH-1:0] aw_count, w_count, r_count;
reg aw_zero, w_zero, r_zero,
aw_full, w_full, r_full,
aw_w_greater, w_aw_greater;
reg [LGDEPTH-1:0] downstream_aw_count, downstream_w_count, downstream_r_count;
reg downstream_aw_zero, downstream_w_zero, downstream_r_zero;
// downstream_aw_w_greater, downstream_w_aw_greater;
wire awskd_valid;
wire [2:0] awskd_prot;
wire [AW-1:0] awskd_addr;
reg awskd_ready;
wire wskd_valid;
wire [DW-1:0] wskd_data;
wire [DW/8-1:0] wskd_strb;
reg wskd_ready;
wire bskd_valid;
wire [1:0] bskd_resp;
reg bskd_ready;
reg last_bvalid;
reg [1:0] last_bdata;
reg last_bchanged;
wire arskd_valid;
wire [2:0] arskd_prot;
wire [AW-1:0] arskd_addr;
reg arskd_ready;
reg last_rvalid;
reg [DW+1:0] last_rdata;
reg last_rchanged;
wire rskd_valid;
wire [1:0] rskd_resp;
wire [DW-1:0] rskd_data;
reg rskd_ready;
reg [LGTIMEOUT-1:0] aw_stall_counter, w_stall_counter,
r_stall_counter, w_ack_timer, r_ack_timer;
reg aw_stall_limit, w_stall_limit, r_stall_limit,
w_ack_limit, r_ack_limit;
// }}}
////////////////////////////////////////////////////////////////////////
//
// Write signaling
// {{{
////////////////////////////////////////////////////////////////////////
//
//
//
// Write address channel
// {{{
skidbuffer #(.DW(AW+3)
// {{{
`ifdef FORMAL
, .OPT_PASSTHROUGH(1'b1)
`endif
// }}}
) awskd(S_AXI_ACLK, !S_AXI_ARESETN,
// {{{
S_AXI_AWVALID, S_AXI_AWREADY, { S_AXI_AWPROT, S_AXI_AWADDR },
awskd_valid, awskd_ready, { awskd_prot, awskd_addr});
// }}}
// awskd_ready
// {{{
// awskd_ready is the critical piece here, since it determines when
// we accept a packet from the skid buffer.
//
always @(*)
if (!M_AXI_ARESETN || o_write_fault)
// On any fault, we'll always accept a request (and return an
// error). We always accept a value if there are already
// more writes than write addresses accepted.
awskd_ready = (w_aw_greater)
||((aw_zero)&&(!S_AXI_BVALID || S_AXI_BREADY));
else
// Otherwise, we accept if ever our counters aren't about to
// overflow, and there's a place downstream to accept it
awskd_ready = (!M_AXI_AWVALID || M_AXI_AWREADY)&& (!aw_full);
// }}}
// M_AXI_AWVALID
// {{{
initial M_AXI_AWVALID = 1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN)
M_AXI_AWVALID <= 1'b0;
else if (!M_AXI_AWVALID || M_AXI_AWREADY)
M_AXI_AWVALID <= awskd_valid && awskd_ready && !o_write_fault;
// }}}
// M_AXI_AWADDR, M_AXI_AWPROT
// {{{
always @(posedge S_AXI_ACLK)
if (OPT_LOWPOWER && (!M_AXI_ARESETN || o_write_fault))
begin
M_AXI_AWADDR <= 0;
M_AXI_AWPROT <= 0;
end else if (!M_AXI_AWVALID || M_AXI_AWREADY)
begin
M_AXI_AWADDR <= awskd_addr;
M_AXI_AWPROT <= awskd_prot;
end
// }}}
// }}}
//
// Write data channel
// {{{
skidbuffer #(.DW(DW+DW/8)
// {{{
`ifdef FORMAL
, .OPT_PASSTHROUGH(1'b1)
`endif
// }}}
) wskd(S_AXI_ACLK, !S_AXI_ARESETN,
// {{{
S_AXI_WVALID, S_AXI_WREADY, { S_AXI_WDATA, S_AXI_WSTRB },
wskd_valid, wskd_ready, { wskd_data, wskd_strb});
// }}}
// wskd_ready
// {{{
// As with awskd_ready, this logic is the critical key.
//
always @(*)
if (!M_AXI_ARESETN || o_write_fault)
wskd_ready = (aw_w_greater)
|| ((w_zero)&&(!S_AXI_BVALID || S_AXI_BREADY));
else
wskd_ready = (!M_AXI_WVALID || M_AXI_WREADY) && (!w_full);
// }}}
// M_AXI_WVALID
// {{{
initial M_AXI_WVALID = 1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN)
M_AXI_WVALID <= 1'b0;
else if (!M_AXI_WVALID || M_AXI_WREADY)
M_AXI_WVALID <= wskd_valid && wskd_ready && !o_write_fault;
// }}}
// M_AXI_WDATA, M_AXI_WSTRB
// {{{
always @(posedge S_AXI_ACLK)
if (OPT_LOWPOWER && (!M_AXI_ARESETN || o_write_fault))
begin
M_AXI_WDATA <= 0;
M_AXI_WSTRB <= 0;
end else if (!M_AXI_WVALID || M_AXI_WREADY)
begin
M_AXI_WDATA <= wskd_data;
M_AXI_WSTRB <= (o_write_fault) ? 0 : wskd_strb;
end
// }}}
// }}}
//
// Write return channel
// {{{
// bskd_valid, M_AXI_BREADY, bskd_resp
// {{{
`ifdef FORMAL
assign bskd_valid = M_AXI_BVALID;
assign M_AXI_BREADY= bskd_ready;
assign bskd_resp = M_AXI_BRESP;
`else
skidbuffer #(.DW(2)
) bskd(S_AXI_ACLK, !S_AXI_ARESETN || !M_AXI_ARESETN,
M_AXI_BVALID, M_AXI_BREADY, M_AXI_BRESP,
bskd_valid, bskd_ready, bskd_resp);
`endif
// }}}
// bskd_ready
// {{{
always @(*)
if (o_write_fault)
bskd_ready = 1'b1;
else
bskd_ready = (!S_AXI_BVALID || S_AXI_BREADY);
// }}}
// S_AXI_BVALID
// {{{
initial S_AXI_BVALID = 1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
S_AXI_BVALID <= 1'b0;
else if (!S_AXI_BVALID || S_AXI_BREADY)
begin
if (o_write_fault || !M_AXI_ARESETN)
S_AXI_BVALID <= (!S_AXI_BVALID&&(!aw_zero)&&(!w_zero));
else
S_AXI_BVALID <= (!downstream_aw_zero)
&&(!downstream_w_zero)&&(bskd_valid);
end
// }}}
// last_bvalid
// {{{
initial last_bvalid = 1'b0;
always @(posedge S_AXI_ACLK)
if (!M_AXI_ARESETN || o_write_fault)
last_bvalid <= 1'b0;
else
last_bvalid <= (M_AXI_BVALID && !M_AXI_BREADY);
// }}}
// last_bdata
// {{{
always @(posedge S_AXI_ACLK)
if (M_AXI_BVALID)
last_bdata <= M_AXI_BRESP;
// }}}
// last_bchanged
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_write_fault)
last_bchanged <= 1'b0;
else
last_bchanged <= (last_bvalid && (!M_AXI_BVALID
|| last_bdata != M_AXI_BRESP));
// }}}
// S_AXI_BRESP
// {{{
initial S_AXI_BRESP = OKAY;
always @(posedge S_AXI_ACLK)
if (!S_AXI_BVALID || S_AXI_BREADY)
begin
if (o_write_fault)
S_AXI_BRESP <= SLVERR;
else if (bskd_resp == EXOKAY)
S_AXI_BRESP <= SLVERR;
else
S_AXI_BRESP <= bskd_resp;
end
// }}}
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Read signaling
// {{{
////////////////////////////////////////////////////////////////////////
//
//
//
// Read address channel
// {{{
skidbuffer #(.DW(AW+3)
// {{{
`ifdef FORMAL
, .OPT_PASSTHROUGH(1'b1)
`endif
// }}}
) arskd(S_AXI_ACLK, !S_AXI_ARESETN,
// {{{
S_AXI_ARVALID, S_AXI_ARREADY, { S_AXI_ARPROT, S_AXI_ARADDR },
arskd_valid, arskd_ready, { arskd_prot, arskd_addr });
// }}}
// arskd_ready
// {{{
always @(*)
if (!M_AXI_ARESETN || o_read_fault)
arskd_ready =((r_zero)&&(!S_AXI_RVALID || S_AXI_RREADY));
else
arskd_ready = (!M_AXI_ARVALID || M_AXI_ARREADY) && (!r_full);
// }}}
// M_AXI_ARVALID
// {{{
initial M_AXI_ARVALID = 1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN)
M_AXI_ARVALID <= 1'b0;
else if (!M_AXI_ARVALID || M_AXI_ARREADY)
M_AXI_ARVALID <= arskd_valid && arskd_ready && !o_read_fault;
// }}}
// M_AXI_ARADDR, M_AXI_ARPROT
// {{{
always @(posedge S_AXI_ACLK)
if (OPT_LOWPOWER && (!M_AXI_ARESETN || o_read_fault))
begin
M_AXI_ARADDR <= 0;
M_AXI_ARPROT <= 0;
end else if (!M_AXI_ARVALID || M_AXI_ARREADY)
begin
M_AXI_ARADDR <= arskd_addr;
M_AXI_ARPROT <= arskd_prot;
end
// }}}
// }}}
//
// Read data channel
// {{{
// rskd_valid, rskd_resp, rskd_data skid buffer
// {{{
`ifdef FORMAL
assign rskd_valid = M_AXI_RVALID;
assign M_AXI_RREADY = rskd_ready;
assign { rskd_resp, rskd_data } = { M_AXI_RRESP, M_AXI_RDATA };
`else
skidbuffer #(.DW(DW+2)
) rskd(S_AXI_ACLK, !S_AXI_ARESETN || !M_AXI_ARESETN,
M_AXI_RVALID, M_AXI_RREADY, { M_AXI_RRESP, M_AXI_RDATA },
rskd_valid, rskd_ready, { rskd_resp, rskd_data });
`endif
// ?}}}
// rskd_ready
// {{{
always @(*)
if (o_read_fault)
rskd_ready = 1;
else
rskd_ready = (!S_AXI_RVALID || S_AXI_RREADY);
// }}}
// S_AXI_RVALID
// {{{
initial S_AXI_RVALID = 1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
S_AXI_RVALID <= 1'b0;
else if (!S_AXI_RVALID || S_AXI_RREADY)
begin
if (o_read_fault || !M_AXI_ARESETN)
S_AXI_RVALID <= (!S_AXI_RVALID && !r_zero)
|| (arskd_valid && arskd_ready);
else
S_AXI_RVALID <= (!downstream_r_zero)&&(rskd_valid);
end
// }}}
// S_AXI_RDATA, S_AXI_RRESP
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_RVALID || S_AXI_RREADY)
begin
if (o_read_fault || !M_AXI_ARESETN)
S_AXI_RDATA <= 0;
else
S_AXI_RDATA <= rskd_data;
S_AXI_RRESP <= OKAY;
if (o_read_fault || rskd_resp == EXOKAY || !M_AXI_ARESETN)
S_AXI_RRESP <= SLVERR;
else if (!downstream_r_zero)
S_AXI_RRESP <= rskd_resp;
end
// }}}
// last_rvalid
// {{{
initial last_rvalid = 1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_read_fault)
last_rvalid <= 1'b0;
else
last_rvalid <= (M_AXI_RVALID && !M_AXI_RREADY);
// }}}
// last_rdata
// {{{
always @(posedge S_AXI_ACLK)
if (M_AXI_RVALID)
last_rdata <= { M_AXI_RRESP, M_AXI_RDATA };
// }}}
// last_rchanged
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_read_fault)
last_rchanged <= 1'b0;
else
last_rchanged <= (last_rvalid && (!M_AXI_RVALID
|| last_rdata != { M_AXI_RRESP, M_AXI_RDATA }));
// }}}
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Usage counters
// {{{
////////////////////////////////////////////////////////////////////////
//
//
//
// Write address channel
// {{{
initial aw_count = 0;
initial aw_zero = 1;
initial aw_full = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
begin
aw_count <= 0;
aw_zero <= 1;
aw_full <= 0;
end else case({(awskd_valid && awskd_ready),S_AXI_BVALID&&S_AXI_BREADY})
2'b10: begin
aw_count <= aw_count + 1;
aw_zero <= 0;
aw_full <= (aw_count == { {(LGDEPTH-1){1'b1}}, 1'b0 });
end
2'b01: begin
aw_count <= aw_count - 1;
aw_zero <= (aw_count <= 1);
aw_full <= 0;
end
default: begin end
endcase
// }}}
//
// Write data channel
// {{{
initial w_count = 0;
initial w_zero = 1;
initial w_full = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
begin
w_count <= 0;
w_zero <= 1;
w_full <= 0;
end else case({(wskd_valid && wskd_ready), S_AXI_BVALID&& S_AXI_BREADY})
2'b10: begin
w_count <= w_count + 1;
w_zero <= 0;
w_full <= (w_count == { {(LGDEPTH-1){1'b1}}, 1'b0 });
end
2'b01: begin
w_count <= w_count - 1;
w_zero <= (w_count <= 1);
w_full <= 1'b0;
end
default: begin end
endcase
// }}}
// aw_w_greater, w_aw_greater
// {{{
initial aw_w_greater = 0;
initial w_aw_greater = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
begin
aw_w_greater <= 0;
w_aw_greater <= 0;
end else case({(awskd_valid && awskd_ready),
(wskd_valid && wskd_ready)})
2'b10: begin
aw_w_greater <= (aw_count + 1 > w_count);
w_aw_greater <= ( w_count > aw_count + 1);
end
2'b01: begin
aw_w_greater <= (aw_count > w_count + 1);
w_aw_greater <= ( w_count + 1 > aw_count);
end
default: begin end
endcase
// }}}
//
// Read channel
// {{{
// r_count, r_zero, r_full
initial r_count = 0;
initial r_zero = 1;
initial r_full = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
begin
r_count <= 0;
r_zero <= 1;
r_full <= 0;
end else case({(arskd_valid&&arskd_ready), S_AXI_RVALID&&S_AXI_RREADY})
2'b10: begin
r_count <= r_count + 1;
r_zero <= 0;
r_full <= (r_count == { {(LGDEPTH-1){1'b1}}, 1'b0 });
end
2'b01: begin
r_count <= r_count - 1;
r_zero <= (r_count <= 1);
r_full <= 0;
end
default: begin end
endcase
// }}}
//
// Downstream write address channel
// {{{
initial downstream_aw_count = 0;
initial downstream_aw_zero = 1;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_write_fault)
begin
downstream_aw_count <= 0;
downstream_aw_zero <= 1;
end else case({(M_AXI_AWVALID && M_AXI_AWREADY), M_AXI_BVALID && M_AXI_BREADY})
2'b10: begin
downstream_aw_count <= downstream_aw_count + 1;
downstream_aw_zero <= 0;
end
2'b01: begin
downstream_aw_count <= downstream_aw_count - 1;
downstream_aw_zero <= (downstream_aw_count <= 1);
end
default: begin end
endcase
// }}}
//
// Downstream write data channel
// {{{
initial downstream_w_count = 0;
initial downstream_w_zero = 1;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_write_fault)
begin
downstream_w_count <= 0;
downstream_w_zero <= 1;
end else case({(M_AXI_WVALID && M_AXI_WREADY), M_AXI_BVALID && M_AXI_BREADY})
2'b10: begin
downstream_w_count <= downstream_w_count + 1;
downstream_w_zero <= 0;
end
2'b01: begin
downstream_w_count <= downstream_w_count - 1;
downstream_w_zero <= (downstream_w_count <= 1);
end
default: begin end
endcase
// }}}
//
// Downstream read channel
// {{{
initial downstream_r_count = 0;
initial downstream_r_zero = 1;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_read_fault)
begin
downstream_r_count <= 0;
downstream_r_zero <= 1;
end else case({M_AXI_ARVALID && M_AXI_ARREADY, M_AXI_RVALID && M_AXI_RREADY})
2'b10: begin
downstream_r_count <= downstream_r_count + 1;
downstream_r_zero <= 0;
end
2'b01: begin
downstream_r_count <= downstream_r_count - 1;
downstream_r_zero <= (downstream_r_count <= 1);
end
default: begin end
endcase
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Timeout checking
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// The key piece here is that we define the timeout depending upon
// what happens (or doesn't happen) *DOWNSTREAM*. These timeouts
// will need to propagate upstream before taking place.
//
// Write address stall counter
// {{{
initial aw_stall_counter = 0;
initial aw_stall_limit = 1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || o_write_fault || !M_AXI_ARESETN)
begin
aw_stall_counter <= 0;
aw_stall_limit <= 0;
end else if (!M_AXI_AWVALID || M_AXI_AWREADY || M_AXI_BVALID)
begin
aw_stall_counter <= 0;
aw_stall_limit <= 0;
end else if (aw_w_greater && !M_AXI_WVALID)
begin
aw_stall_counter <= 0;
aw_stall_limit <= 0;
end else // if (!S_AXI_BVALID || S_AXI_BREADY)
begin
aw_stall_counter <= aw_stall_counter + 1;
aw_stall_limit <= (aw_stall_counter+1 >= OPT_TIMEOUT);
end
// }}}
//
// Write data stall counter
// {{{
initial w_stall_counter = 0;
initial w_stall_limit = 1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_write_fault)
begin
w_stall_counter <= 0;
w_stall_limit <= 0;
end else if (!M_AXI_WVALID || M_AXI_WREADY || M_AXI_BVALID)
begin
w_stall_counter <= 0;
w_stall_limit <= 0;
end else if (w_aw_greater && !M_AXI_AWVALID)
begin
w_stall_counter <= 0;
w_stall_limit <= 0;
end else // if (!M_AXI_BVALID || M_AXI_BREADY)
begin
w_stall_counter <= w_stall_counter + 1;
w_stall_limit <= (w_stall_counter + 1 >= OPT_TIMEOUT);
end
// }}}
//
// Write acknowledgment delay counter
// {{{
initial w_ack_timer = 0;
initial w_ack_limit = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_write_fault)
begin
w_ack_timer <= 0;
w_ack_limit <= 0;
end else if (M_AXI_BVALID || downstream_aw_zero || downstream_w_zero)
begin
w_ack_timer <= 0;
w_ack_limit <= 0;
end else
begin
w_ack_timer <= w_ack_timer + 1;
w_ack_limit <= (w_ack_timer + 1 >= OPT_TIMEOUT);
end
// }}}
//
// Read request stall counter
// {{{
initial r_stall_counter = 0;
initial r_stall_limit = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_read_fault)
begin
r_stall_counter <= 0;
r_stall_limit <= 0;
end else if (!M_AXI_ARVALID || M_AXI_ARREADY || M_AXI_RVALID)
begin
r_stall_counter <= 0;
r_stall_limit <= 0;
end else begin
r_stall_counter <= r_stall_counter + 1;
r_stall_limit <= (r_stall_counter + 1 >= OPT_TIMEOUT);
end
// }}}
//
// Read acknowledgement delay counter
// {{{
initial r_ack_timer = 0;
initial r_ack_limit = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN || o_read_fault)
begin
r_ack_timer <= 0;
r_ack_limit <= 0;
end else if (M_AXI_RVALID || downstream_r_zero)
begin
r_ack_timer <= 0;
r_ack_limit <= 0;
end else begin
r_ack_timer <= r_ack_timer + 1;
r_ack_limit <= (r_ack_timer + 1 >= OPT_TIMEOUT);
end
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Fault detection
// {{{
////////////////////////////////////////////////////////////////////////
//
//
//
// Determine if a write fault has taken place
// {{{
initial o_write_fault =1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
o_write_fault <= 1'b0;
else if (OPT_SELF_RESET && o_write_fault)
begin
//
// Clear any fault on reset
if (!M_AXI_ARESETN)
o_write_fault <= 1'b0;
end else begin
//
// A write fault takes place if you respond without a prior
// bus request on both write address and write data channels.
if ((downstream_aw_zero || downstream_w_zero)&&(bskd_valid))
o_write_fault <= 1'b1;
// AXI-lite slaves are not allowed to return EXOKAY responses
// from the bus
if (bskd_valid && bskd_resp == EXOKAY)
o_write_fault <= 1'b1;
// If the downstream core refuses to accept either a
// write address request, or a write data request, or for that
// matter if it doesn't return an acknowledgment in a timely
// fashion, then a fault has been detected.
if (aw_stall_limit || w_stall_limit || w_ack_limit)
o_write_fault <= 1'b1;
// If the downstream core changes BRESP while VALID && !READY,
// then it isn't stalling the channel properly--that's a fault.
if (last_bchanged)
o_write_fault <= 1'b1;
end
// }}}
// o_read_fault
// {{{
initial o_read_fault =1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
o_read_fault <= 1'b0;
else if (OPT_SELF_RESET && o_read_fault)
begin
//
// Clear any fault on reset
if (!M_AXI_ARESETN)
o_read_fault <= 1'b0;
end else begin
// Responding without a prior request is a fault. Can only
// respond after a request has been made.
if (downstream_r_zero && rskd_valid)
o_read_fault <= 1'b1;
// AXI-lite slaves are not allowed to return EXOKAY. This is
// an error.
if (rskd_valid && rskd_resp == EXOKAY)
o_read_fault <= 1'b1;
// The slave cannot stall the bus forever, nor should the
// master wait forever for a response from the slave.
if (r_stall_limit || r_ack_limit)
o_read_fault <= 1'b1;
// If the slave changes the data, or the RRESP on the wire,
// while the incoming bus is stalled, then that's also a fault.
if (last_rchanged)
o_read_fault <= 1'b1;
end
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Self reset handling
// {{{
////////////////////////////////////////////////////////////////////////
//
//
generate if (OPT_SELF_RESET)
begin : SELF_RESET_GENERATION
// {{{
wire min_reset;
if (OPT_MIN_RESET > 1)
begin : MIN_RESET
// {{{
reg r_min_reset;
reg [$clog2(OPT_MIN_RESET+1):0] reset_counter;
//
// Optionally insist that any downstream reset have a
// minimum duration. Many Xilinx components require
// a 16-clock reset. This ensures such reset
// requirements are achieved.
//
initial reset_counter = OPT_MIN_RESET-1;
initial r_min_reset = 1'b0;
always @(posedge S_AXI_ARESETN)
if (M_AXI_ARESETN)
begin
reset_counter <= OPT_MIN_RESET-1;
r_min_reset <= 1'b0;
end else if (!M_AXI_ARESETN)
begin
if (reset_counter > 0)
reset_counter <= reset_counter-1;
min_reset <= (reset_counter <= 1);
end
assign min_reset = r_min_reset;
`ifdef FORMAL
always @(*)
assert(reset_counter < OPT_MIN_RESET);
always @(*)
assert(min_reset == (reset_counter == 0));
`endif
// }}}
end else begin : NO_MIN_RESET
// {{{
assign min_reset = 1'b1;
// }}}
end
// M_AXI_ARESETN
// {{{
// Reset the downstream bus on either a write or a read fault.
// Once the bus returns to idle, and any minimum reset durations
// have been achieved, then release the downstream from reset.
//
initial M_AXI_ARESETN = 1'b0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)