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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
|
////////////////////////////////////////////////////////////////////////////////
//
// Filename: axisafety.v
// {{{
// Project: WB2AXIPSP: bus bridges and other odds and ends
//
// Purpose: Given that 1) AXI interfaces can be difficult to write and to
// get right, 2) my experiences with the AXI infrastructure of an
// ARM+FPGA is that the device needs a power cycle following a bus fault,
// and given that I've now found multiple interfaces that had some bug
// or other within them, the following is a bus fault isolator. It acts
// as a bump in the log between the interconnect and the user core. As
// such, it has two interfaces: The first is the slave interface,
// coming from the interconnect. The second interface is the master
// interface, proceeding to a slave that might be faulty.
//
// INTERCONNECT --> (S) AXISAFETY (M) --> POTENTIALLY FAULTY CORE
//
// The slave interface has been formally verified to be a valid AXI
// slave, independent of whatever the potentially faulty core might do.
// If the user core (i.e. the potentially faulty one) responds validly
// to the requests of a master, then this core will turn into a simple
// delay on the bus. If, on the other hand, the user core suffers from
// a protocol error, then this core will set one of two output
// flags--either o_write_fault or o_read_fault indicating whether a write
// or a read fault was detected. Further attempts to access the user
// core will result in bus errors, generated by the AXISAFETY core.
//
// Assuming the bus master can properly detect and deal with a bus error,
// this should then make it possible to properly recover from a bus
// protocol error without later needing to cycle power.
//
// The core does have a couple of limitations. For example, it can only
// handle one burst transaction, and one ID at a time. This matches the
// performances of Xilinx's example AXI full core, from which many user
// cores have have been copied/modified from. Therefore, there will be
// no performance loss for such a core.
//
// Because of this, it is still possible that the user core might have an
// undetected fault when using this core. For example, if the interconnect
// issues more than one bus request before receiving the response from the
// first request, this safety core will stall the second request,
// preventing the downstream core from seeing this second request. If the
// downstream core would suffer from an error while handling the second
// request, by preventing the user core from seeing the second request this
// core eliminates that potential for error.
//
// Usage: The important part of using this core is to connect the slave
// side to the interconnect, and the master side to the user core.
//
// Some options are available:
//
// 1) C_S_AXI_ADDR_WIDTH The number of address bits in the AXI channel
// 1) C_S_AXI_DATA_WIDTH The number of data bits in the AXI channel
// 3) C_S_AXI_ID_WIDTH The number of bits in an AXI ID. As currently
// written, this number cannot be zero. You can, however, set it
// to '1' and connect all of the relevant ID inputs to zero.
//
// These three parameters have currently been abbreviated with AW, DW, and
// IW. I anticipate returning them to their original meanings, I just
// haven't done so (yet).
//
// 4) OPT_TIMEOUT This is the number of clock periods, from
// interconnect request to interconnect response, that the
// slave needs to respond within. (The actual timeout from the
// user slave's perspective will be shorter than this.)
//
// This timeout is part of the check that a slave core will
// always return a response. From the standpoint of this core,
// it can be set arbitrarily large. (From the standpoint of
// formal verification, it needs to be kept short ...)
// Feel free to set this even as large as 1ms if you would like.
//
// 5) OPT_SELF_RESET If set, will send a reset signal to the slave
// following any write or read fault. This will cause the other
// side of the link (write or read) to fault as well. Once the
// channel then becomes inactive, the slave will be released from
// reset and will be able to interact with the rest of the bus
// again.
//
// 5) OPT_EXCLUSIVE If clear, will prohibit the slave from ever
// receiving an exclusive access request. This saves the logic
// in the firewall necessary to check that an EXOKAY response
// to a write request was truly an allowed response. Since that
// logic can explode with the ID width, sparing it can be quite
// useful. If set, provides full exclusive access checking in
// addition to the normal bus fault checking.
//
// Performance: As mentioned above, this core can handle one read burst and one
// write burst at a time, no more. Further, the core will delay
// an input path by one clock and the output path by another clock, so that
// the latency involved with using this core is a minimum of two extra
// clocks beyond the latency user slave core.
//
// Maximum write latency: N+3 clocks for a burst of N values
// Maximum read latency: N+3 clocks for a burst of N values
//
// Faults detected:
//
// Write channel:
// 1. Raising BVALID prior to the last write value being sent
// to the user/slave core.
// 2. Raising BVALID prior to accepting the write address
// 3. A BID return ID that doesn't match the request AWID
// 4. Sending too many returns, such as not dropping BVALID
// or raising it when there is no outstanding write
// request
//
// While the following technically isn't a violation of the
// AXI protocol, it is treated as such by this fault isolator.
//
// 5. Accepting write data prior to the write address
//
// The fault isolator will guarantee that AWVALID is raised before
// WVALID, so this shouldn't be a problem.
//
// Read channel:
//
// 1. Raising RVALID before accepting the read address, ARVALID
// 2. A return ID that doesn't match the ID that was sent.
// 3. Raising RVALID after the last return value, and so returning
// too many response values
// 4. Setting the RLAST value on anything but the last value from
// the bus.
//
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
// }}}
// Copyright (C) 2019-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 axisafety #(
// {{{
parameter C_S_AXI_ID_WIDTH = 1,
parameter C_S_AXI_DATA_WIDTH = 32,
parameter C_S_AXI_ADDR_WIDTH = 16,
// OPT_SELF_RESET: Set to true if the downstream slave should be
// reset upon detecting an error and separate from the upstream reset
// domain
parameter [0:0] OPT_SELF_RESET = 1'b0,
// OPT_EXCLUSIVE: Set to true if the downstream slave might possibly
// offer an exclusive access capability
parameter [0:0] OPT_EXCLUSIVE = 1'b0,
//
// I use the following abbreviations, IW, DW, and AW, to simplify
// the code below (and to help it fit within an 80 col terminal)
localparam IW = C_S_AXI_ID_WIDTH,
localparam DW = C_S_AXI_DATA_WIDTH,
localparam AW = C_S_AXI_ADDR_WIDTH,
//
// OPT_TIMEOUT references the number of clock cycles to wait
// between raising the *VALID signal and when the respective
// *VALID return signal must be high. You might wish to set this
// to a very high number, to allow your core to work its magic.
parameter OPT_TIMEOUT = 20
// }}}
) (
// {{{
output reg o_read_fault,
output reg o_write_fault,
// User ports ends
// Do not modify the ports beyond this line
// Global Clock Signal
input wire S_AXI_ACLK,
// Global Reset Signal. This Signal is Active LOW
input wire S_AXI_ARESETN,
output reg M_AXI_ARESETN,
//
// The input side. This is where slave requests come into
// the core.
// {{{
//
// Write address
input wire [IW-1 : 0] S_AXI_AWID,
input wire [AW-1 : 0] S_AXI_AWADDR,
input wire [7 : 0] S_AXI_AWLEN,
input wire [2 : 0] S_AXI_AWSIZE,
input wire [1 : 0] S_AXI_AWBURST,
input wire S_AXI_AWLOCK,
input wire [3 : 0] S_AXI_AWCACHE,
input wire [2 : 0] S_AXI_AWPROT,
input wire [3 : 0] S_AXI_AWQOS,
input wire S_AXI_AWVALID,
output reg S_AXI_AWREADY,
// Write data
input wire [DW-1 : 0] S_AXI_WDATA,
input wire [(DW/8)-1 : 0] S_AXI_WSTRB,
input wire S_AXI_WLAST,
input wire S_AXI_WVALID,
output reg S_AXI_WREADY,
// Write return
output reg [IW-1 : 0] S_AXI_BID,
output reg [1 : 0] S_AXI_BRESP,
output reg S_AXI_BVALID,
input wire S_AXI_BREADY,
// Read address
input wire [IW-1 : 0] S_AXI_ARID,
input wire [AW-1 : 0] S_AXI_ARADDR,
input wire [7 : 0] S_AXI_ARLEN,
input wire [2 : 0] S_AXI_ARSIZE,
input wire [1 : 0] S_AXI_ARBURST,
input wire S_AXI_ARLOCK,
input wire [3 : 0] S_AXI_ARCACHE,
input wire [2 : 0] S_AXI_ARPROT,
input wire [3 : 0] S_AXI_ARQOS,
input wire S_AXI_ARVALID,
output reg S_AXI_ARREADY,
// Read data
output reg [IW-1 : 0] S_AXI_RID,
output reg [DW-1 : 0] S_AXI_RDATA,
output reg [1 : 0] S_AXI_RRESP,
output reg S_AXI_RLAST,
output reg S_AXI_RVALID,
input wire S_AXI_RREADY,
// }}}
//
// The output side, where slave requests are forwarded to the
// actual slave
// {{{
// Write address
// {{{
output reg [IW-1 : 0] M_AXI_AWID,
output reg [AW-1 : 0] M_AXI_AWADDR,
output reg [7 : 0] M_AXI_AWLEN,
output reg [2 : 0] M_AXI_AWSIZE,
output reg [1 : 0] M_AXI_AWBURST,
output reg M_AXI_AWLOCK,
output reg [3 : 0] M_AXI_AWCACHE,
output reg [2 : 0] M_AXI_AWPROT,
output reg [3 : 0] M_AXI_AWQOS,
output reg M_AXI_AWVALID,
input wire M_AXI_AWREADY,
// Write data
output reg [DW-1 : 0] M_AXI_WDATA,
output reg [(DW/8)-1 : 0] M_AXI_WSTRB,
output reg M_AXI_WLAST,
output reg M_AXI_WVALID,
input wire M_AXI_WREADY,
// Write return
input wire [IW-1 : 0] M_AXI_BID,
input wire [1 : 0] M_AXI_BRESP,
input wire M_AXI_BVALID,
output wire M_AXI_BREADY,
// }}}
// Read address
// {{{
output reg [IW-1 : 0] M_AXI_ARID,
output reg [AW-1 : 0] M_AXI_ARADDR,
output reg [7 : 0] M_AXI_ARLEN,
output reg [2 : 0] M_AXI_ARSIZE,
output reg [1 : 0] M_AXI_ARBURST,
output reg M_AXI_ARLOCK,
output reg [3 : 0] M_AXI_ARCACHE,
output reg [2 : 0] M_AXI_ARPROT,
output reg [3 : 0] M_AXI_ARQOS,
output reg M_AXI_ARVALID,
input wire M_AXI_ARREADY,
// Read data
input wire [IW-1 : 0] M_AXI_RID,
input wire [DW-1 : 0] M_AXI_RDATA,
input wire [1 : 0] M_AXI_RRESP,
input wire M_AXI_RLAST,
input wire M_AXI_RVALID,
output wire M_AXI_RREADY
// }}}
// }}}
// }}}
);
localparam LGTIMEOUT = $clog2(OPT_TIMEOUT+1);
localparam [1:0] OKAY = 2'b00, EXOKAY = 2'b01;
localparam SLAVE_ERROR = 2'b10;
//
//
// Register declarations
// {{{
reg faulty_write_return, faulty_read_return;
reg clear_fault;
//
// Timer/timeout variables
reg [LGTIMEOUT-1:0] write_timer, read_timer;
reg write_timeout, read_timeout;
//
// Double buffer the write address channel
reg r_awvalid, m_awvalid;
reg [IW-1:0] r_awid, m_awid;
reg [AW-1:0] r_awaddr, m_awaddr;
reg [7:0] r_awlen, m_awlen;
reg [2:0] r_awsize, m_awsize;
reg [1:0] r_awburst, m_awburst;
reg r_awlock, m_awlock;
reg [3:0] r_awcache, m_awcache;
reg [2:0] r_awprot, m_awprot;
reg [3:0] r_awqos, m_awqos;
//
// Double buffer for the write channel
reg r_wvalid,m_wvalid;
reg [DW-1:0] r_wdata, m_wdata;
reg [DW/8-1:0] r_wstrb, m_wstrb;
reg r_wlast, m_wlast;
//
// Double buffer the write response channel
reg m_bvalid; // r_bvalid == 0
reg [IW-1:0] m_bid;
reg [1:0] m_bresp;
//
// Double buffer the read address channel
reg r_arvalid, m_arvalid;
reg [IW-1:0] r_arid, m_arid;
reg [AW-1:0] r_araddr, m_araddr;
reg [7:0] r_arlen, m_arlen;
reg [2:0] r_arsize, m_arsize;
reg [1:0] r_arburst, m_arburst;
reg r_arlock, m_arlock;
reg [3:0] r_arcache, m_arcache;
reg [2:0] r_arprot, m_arprot;
reg [3:0] r_arqos, m_arqos;
//
// Double buffer the read data response channel
reg r_rvalid,m_rvalid;
reg [IW-1:0] m_rid;
reg [1:0] r_rresp, m_rresp;
reg m_rlast;
reg [DW-1:0] r_rdata, m_rdata;
//
// Write FIFO data
wire [IW-1:0] wfifo_id;
wire wfifo_lock;
//
// Read FIFO data
reg [IW-1:0] rfifo_id;
reg rfifo_lock;
reg [8:0] rfifo_counter;
reg rfifo_empty, rfifo_last, rfifo_penultimate;
//
//
reg [0:0] s_wbursts;
reg [8:0] m_wpending;
reg m_wempty, m_wlastctr;
wire waddr_valid, raddr_valid;
wire lock_enabled, lock_failed;
wire [(1<<IW)-1:0] lock_active;
reg rfifo_first, exread;
// }}}
////////////////////////////////////////////////////////////////////////
//
// Write channel processing
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// Write address processing
// {{{
// S_AXI_AWREADY
// {{{
initial S_AXI_AWREADY = (OPT_SELF_RESET) ? 0:1;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
S_AXI_AWREADY <= !OPT_SELF_RESET;
else if (S_AXI_AWVALID && S_AXI_AWREADY)
S_AXI_AWREADY <= 0;
// else if (clear_fault)
// S_AXI_AWREADY <= 1;
else if (!S_AXI_AWREADY)
S_AXI_AWREADY <= S_AXI_BVALID && S_AXI_BREADY;
// }}}
generate if (OPT_EXCLUSIVE)
begin : GEN_LOCK_ENABLED
// {{{
reg r_lock_enabled, r_lock_failed;
// lock_enabled
// {{{
initial r_lock_enabled = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !OPT_EXCLUSIVE)
r_lock_enabled <= 0;
else if (S_AXI_AWVALID && S_AXI_AWREADY)
r_lock_enabled <= S_AXI_AWLOCK && lock_active[S_AXI_AWID];
else if (S_AXI_BVALID && S_AXI_BREADY)
r_lock_enabled <= 0;
// }}}
// lock_failed
// {{{
initial r_lock_failed = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !OPT_EXCLUSIVE)
r_lock_failed <= 0;
else if (S_AXI_AWVALID && S_AXI_AWREADY)
r_lock_failed <= S_AXI_AWLOCK && !lock_active[S_AXI_AWID];
else if (S_AXI_BVALID && S_AXI_BREADY)
r_lock_failed <= 0;
// }}}
assign lock_enabled = r_lock_enabled;
assign lock_failed = r_lock_failed;
// }}}
end else begin : NO_LOCK_ENABLE
// {{{
assign lock_enabled = 0;
assign lock_failed = 0;
// }}}
end endgenerate
// waddr_valid
// {{{
generate if (OPT_SELF_RESET)
begin : GEN_LCL_RESET
reg r_waddr_valid;
initial r_waddr_valid = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
r_waddr_valid <= 0;
else if (S_AXI_AWVALID && S_AXI_AWREADY)
r_waddr_valid <= 1;
else if (waddr_valid)
r_waddr_valid <= !S_AXI_BVALID || !S_AXI_BREADY;
assign waddr_valid = r_waddr_valid;
end else begin : NO_LCL_RESET
assign waddr_valid = !S_AXI_AWREADY;
end endgenerate
// }}}
// r_aw*
// {{{
// Double buffer for the AW* channel
//
initial r_awvalid = 0;
always @(posedge S_AXI_ACLK)
begin
if (S_AXI_AWVALID && S_AXI_AWREADY)
begin
r_awvalid <= 1'b0;
r_awid <= S_AXI_AWID;
r_awaddr <= S_AXI_AWADDR;
r_awlen <= S_AXI_AWLEN;
r_awsize <= S_AXI_AWSIZE;
r_awburst <= S_AXI_AWBURST;
r_awlock <= S_AXI_AWLOCK;
r_awcache <= S_AXI_AWCACHE;
r_awprot <= S_AXI_AWPROT;
r_awqos <= S_AXI_AWQOS;
end else if (M_AXI_AWREADY)
r_awvalid <= 0;
if (!S_AXI_ARESETN)
begin
r_awvalid <= 0;
r_awlock <= 0;
end
if (!OPT_EXCLUSIVE)
r_awlock <= 1'b0;
end
// }}}
// m_aw*
// {{{
// Second half of the AW* double-buffer. The m_* terms reference
// either the value in the double buffer (assuming one is in there),
// or the incoming value (if the double buffer is empty)
//
always @(*)
if (r_awvalid)
begin
m_awvalid = r_awvalid;
m_awid = r_awid;
m_awaddr = r_awaddr;
m_awlen = r_awlen;
m_awsize = r_awsize;
m_awburst = r_awburst;
m_awlock = r_awlock;
m_awcache = r_awcache;
m_awprot = r_awprot;
m_awqos = r_awqos;
end else begin
m_awvalid = S_AXI_AWVALID && S_AXI_AWREADY;
m_awid = S_AXI_AWID;
m_awaddr = S_AXI_AWADDR;
m_awlen = S_AXI_AWLEN;
m_awsize = S_AXI_AWSIZE;
m_awburst = S_AXI_AWBURST;
m_awlock = S_AXI_AWLOCK && OPT_EXCLUSIVE;
m_awcache = S_AXI_AWCACHE;
m_awprot = S_AXI_AWPROT;
m_awqos = S_AXI_AWQOS;
end
// }}}
// M_AXI_AW*
// {{{
// Set the output AW* channel outputs--but only on no fault
//
initial M_AXI_AWVALID = 0;
always @(posedge S_AXI_ACLK)
begin
if (!M_AXI_AWVALID || M_AXI_AWREADY)
begin
if (o_write_fault)
M_AXI_AWVALID <= 0;
else
M_AXI_AWVALID <= m_awvalid;
M_AXI_AWID <= m_awid;
M_AXI_AWADDR <= m_awaddr;
M_AXI_AWLEN <= m_awlen;
M_AXI_AWSIZE <= m_awsize;
M_AXI_AWBURST <= m_awburst;
M_AXI_AWLOCK <= m_awlock && lock_active[m_awid];
M_AXI_AWCACHE <= m_awcache;
M_AXI_AWPROT <= m_awprot;
M_AXI_AWQOS <= m_awqos;
end
if (!OPT_EXCLUSIVE)
M_AXI_AWLOCK <= 0;
if (!M_AXI_ARESETN)
M_AXI_AWVALID <= 0;
end
// }}}
// }}}
// s_wbursts
// {{{
// Count write bursts outstanding from the standpoint of
// the incoming (slave) channel
//
// Notice that, as currently built, the count can only ever be one
// or zero.
//
// We'll use this count in a moment to determine if a response
// has taken too long, or if a response is returned when there's
// no outstanding request
initial s_wbursts = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
s_wbursts <= 0;
else if (S_AXI_WVALID && S_AXI_WREADY && S_AXI_WLAST)
s_wbursts <= 1;
else if (S_AXI_BVALID && S_AXI_BREADY)
s_wbursts <= 0;
// }}}
// wfifo_id, wfifo_lock
// {{{
// Keep track of the ID of the last transaction. Since we only
// ever have one write transaction outstanding, this will need to be
// the ID of the returned value.
assign wfifo_id = r_awid;
assign wfifo_lock = r_awlock;
// }}}
// m_wpending, m_wempty, m_wlastctr
// {{{
// m_wpending counts the number of (remaining) write data values that
// need to be sent to the slave. It counts this number with respect
// to the *SLAVE*, not the master. When m_wpending == 1, WLAST shall
// be true. To make comparisons of (m_wpending == 0) or (m_wpending>0),
// m_wempty is assigned to (m_wpending). Similarly, m_wlastctr is
// assigned to (m_wpending == 1).
//
initial m_wpending = 0;
initial m_wempty = 1;
initial m_wlastctr = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || o_write_fault)
begin
// {{{
m_wpending <= 0;
m_wempty <= 1;
m_wlastctr <= 0;
// }}}
end else if (M_AXI_AWVALID && M_AXI_AWREADY)
begin
// {{{
if (M_AXI_WVALID && M_AXI_WREADY)
begin
// {{{
// Accepting AW* and W* packets on the same
// clock
if (m_wpending == 0)
begin
// The AW* and W* packets go together
m_wpending <= {1'b0, M_AXI_AWLEN};
m_wempty <= (M_AXI_AWLEN == 0);
m_wlastctr <= (M_AXI_AWLEN == 1);
end else begin
// The W* packet goes with the last
// AW* command, the AW* packet with a
// new one
m_wpending <= M_AXI_AWLEN+1;
m_wempty <= 0;
m_wlastctr <= (M_AXI_AWLEN == 0);
end
// }}}
end else begin
// {{{
m_wpending <= M_AXI_AWLEN+1;
m_wempty <= 0;
m_wlastctr <= (M_AXI_AWLEN == 0);
// }}}
end
// }}}
end else if (M_AXI_WVALID && M_AXI_WREADY && (!m_wempty))
begin
// {{{
// The AW* channel is idle, and we just accepted a value
// on the W* channel
m_wpending <= m_wpending - 1;
m_wempty <= (m_wpending <= 1);
m_wlastctr <= (m_wpending == 2);
// }}}
end
// }}}
// Write data processing
// {{{
// S_AXI_WREADY
// {{{
// The S_AXI_WREADY or write channel stall signal
//
// For this core, we idle at zero (stalled) until an AW* packet
// comes through
//
initial S_AXI_WREADY = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
S_AXI_WREADY <= 0;
else if (S_AXI_WVALID && S_AXI_WREADY)
begin
// {{{
if (S_AXI_WLAST)
S_AXI_WREADY <= 0;
else if (o_write_fault)
S_AXI_WREADY <= 1;
else if (!M_AXI_WVALID || M_AXI_WREADY)
S_AXI_WREADY <= 1;
else
S_AXI_WREADY <= 0;
// }}}
end else if ((s_wbursts == 0)&&(waddr_valid)
&&(o_write_fault || M_AXI_WREADY))
S_AXI_WREADY <= 1;
else if (S_AXI_AWVALID && S_AXI_AWREADY)
S_AXI_WREADY <= 1;
// }}}
// r_w*
// {{{
// Double buffer for the write channel
//
// As before, the r_* values contain the values in the double
// buffer itself
//
initial r_wvalid = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
r_wvalid <= 0;
else if (!r_wvalid)
begin
// {{{
r_wvalid <= (S_AXI_WVALID && S_AXI_WREADY
&& M_AXI_WVALID && !M_AXI_WREADY);
r_wdata <= S_AXI_WDATA;
r_wstrb <= S_AXI_WSTRB;
r_wlast <= S_AXI_WLAST;
// }}}
end else if (o_write_fault || M_AXI_WREADY || !M_AXI_ARESETN)
r_wvalid <= 0;
// }}}
// m_w*
// {{{
// Here's the result of our double buffer
//
// m_* references the value within the double buffer in the case that
// something is in the double buffer. Otherwise, it is the values
// directly from the inputs. In the case of a fault, neither is true.
// Write faults override.
//
always @(*)
if (o_write_fault)
begin
// {{{
m_wvalid = !m_wempty;
m_wlast = m_wlastctr;
m_wstrb = 0;
// }}}
end else if (r_wvalid)
begin
// {{{
m_wvalid = 1;
m_wstrb = r_wstrb;
m_wlast = r_wlast;
// }}}
end else begin
// {{{
m_wvalid = S_AXI_WVALID && S_AXI_WREADY;
m_wstrb = S_AXI_WSTRB;
m_wlast = S_AXI_WLAST;
// }}}
end
// }}}
// m_wdata
// {{{
// The logic for the DATA output of the double buffer doesn't
// matter so much in the case of o_write_fault
always @(*)
if (r_wvalid)
m_wdata = r_wdata;
else
m_wdata = S_AXI_WDATA;
// }}}
// M_AXI_W*
// {{{
// Set the downstream write channel values
//
// As per AXI spec, these values *must* be registered. Note that our
// source here is the m_* double buffer/incoming write data switch.
initial M_AXI_WVALID = 0;
always @(posedge S_AXI_ACLK)
begin
if (!M_AXI_WVALID || M_AXI_WREADY)
begin
M_AXI_WVALID <= m_wvalid;
M_AXI_WDATA <= m_wdata;
M_AXI_WSTRB <= m_wstrb;
if (OPT_EXCLUSIVE && lock_failed)
M_AXI_WSTRB <= 0;
M_AXI_WLAST <= m_wlast;
end
// Override the WVALID signal (only) on reset, voiding any
// output we might otherwise send.
if (!M_AXI_ARESETN)
M_AXI_WVALID <= 0;
end
// }}}
// }}}
// Write fault detection
// {{{
// write_timer
// {{{
// The write timer
//
// The counter counts up to saturation. It is reset any time
// the write channel is either clear, or a value is accepted
// at the *MASTER* (not slave) side. Why the master side? Simply
// because it makes the proof below easier. (At one time I checked
// both, but then couldn't prove that the faults wouldn't get hit
// if the slave responded in time.)
initial write_timer = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !waddr_valid)
write_timer <= 0;
else if (!o_write_fault && M_AXI_BVALID)
write_timer <= 0;
else if (S_AXI_WREADY)
write_timer <= 0;
else if (!(&write_timer))
write_timer <= write_timer + 1;
// }}}
// write_timeout
// {{{
// Write timeout detector
//
// If the write_timer reaches the OPT_TIMEOUT, then the write_timeout
// will get set true. This will force a fault, taking the write
// channel off line.
initial write_timeout = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || clear_fault)
write_timeout <= 0;
else if (M_AXI_BVALID)
write_timeout <= write_timeout;
else if (S_AXI_WVALID && S_AXI_WREADY)
write_timeout <= write_timeout;
else if (write_timer >= OPT_TIMEOUT)
write_timeout <= 1;
// }}}
// faulty_write_return
// {{{
// fault_write_return
//
// This combinational logic is used to catch an invalid return, and
// so take the slave off-line before the return can corrupt the master
// channel. Reasons for taking the write return off line are listed
// below.
always @(*)
begin
faulty_write_return = 0;
if (M_AXI_WVALID && M_AXI_WREADY
&& M_AXI_AWVALID && !M_AXI_AWREADY)
// Accepting the write *data* prior to the write
// *address* is a fault
faulty_write_return = 1;
if (M_AXI_BVALID)
begin
if (M_AXI_AWVALID || M_AXI_WVALID)
// Returning a B* acknowledgement while the
// request remains outstanding is also a fault
faulty_write_return = 1;
if (!m_wempty)
// Same as above, but this time the write
// channel is neither complete, nor is *WVALID
// active. Values remain to be written,
// and so a return is a fault.
faulty_write_return = 1;
if (s_wbursts <= (S_AXI_BVALID ? 1:0))
// Too many acknowledgments
//
// Returning more than one BVALID&BREADY for
// every AWVALID & AWREADY is a fault.
faulty_write_return = 1;
if (M_AXI_BID != wfifo_id)
// An attempt to return the wrong ID
faulty_write_return = 1;
if (M_AXI_BRESP == EXOKAY && (!OPT_EXCLUSIVE
|| !lock_enabled))
// An attempt to return a valid lock, without
// a prior request
faulty_write_return = 1;
end
end
// }}}
// o_write_fault
// {{{
// On a write fault, we're going to disconnect the write port from
// the slave, and return errors on each write connect. o_write_fault
// is our signal determining if the write channel is disconnected.
//
// Most of this work is determined within faulty_write_return above.
// Here we do just a bit more:
initial o_write_fault = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || clear_fault)
o_write_fault <= 0;
else if ((!M_AXI_ARESETN&&o_read_fault) || write_timeout)
o_write_fault <= 1;
else if (M_AXI_BVALID && M_AXI_BREADY)
o_write_fault <= (o_write_fault) || faulty_write_return;
else if (M_AXI_WVALID && M_AXI_WREADY
&& M_AXI_AWVALID && !M_AXI_AWREADY)
// Accepting the write data prior to the write address
// is a fault
o_write_fault <= 1;
// }}}
// }}}
// Write return generation
// {{{
// m_b*
// {{{
// Since we only ever allow a single write burst at a time, we don't
// need to double buffer the return channel. Hence, we'll set our
// return channel based upon the incoming values alone. Note that
// we're overriding the M_AXI_BID below, in order to make certain that
// the return goes to the right source.
//
always @(*)
if (o_write_fault)
begin
m_bvalid = (s_wbursts > (S_AXI_BVALID ? 1:0));
m_bid = wfifo_id;
m_bresp = SLAVE_ERROR;
end else begin
m_bvalid = M_AXI_BVALID;
if (faulty_write_return)
m_bvalid = 0;
m_bid = wfifo_id;
m_bresp = M_AXI_BRESP;
end
// }}}
// S_AXI_B*
// {{{
// We'll *never* stall the slaves BREADY channel
//
// If the slave returns the response we are expecting, then S_AXI_BVALID
// will be low and it can go directly into the S_AXI_BVALID slot. If
// on the other hand the slave returns M_AXI_BVALID at the wrong time,
// then we'll quietly accept it and send the write interface into
// fault detected mode, setting o_write_fault.
//
// Sadly, this will create a warning in Vivado. If/when you see it,
// see this note and then just ignore it.
assign M_AXI_BREADY = 1;
//
// Return a write acknowlegement at the end of every write
// burst--regardless of whether or not the slave does so
//
initial S_AXI_BVALID = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
S_AXI_BVALID <= 0;
else if (!S_AXI_BVALID || S_AXI_BREADY)
S_AXI_BVALID <= m_bvalid;
//
// Set the values associated with the response
//
always @(posedge S_AXI_ACLK)
if (!S_AXI_BVALID || S_AXI_BREADY)
begin
S_AXI_BID <= m_bid;
S_AXI_BRESP <= m_bresp;
end
// }}}
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Read channel processing
// {{{
////////////////////////////////////////////////////////////////////////
//
//
//
// Read address channel
// {{{
// S_AXI_ARREADY
// {{{
initial S_AXI_ARREADY = (OPT_SELF_RESET) ? 0:1;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
S_AXI_ARREADY <= !OPT_SELF_RESET;
else if (S_AXI_ARVALID && S_AXI_ARREADY)
S_AXI_ARREADY <= 0;
// else if (clear_fault)
// S_AXI_ARREADY <= 1;
else if (!S_AXI_ARREADY)
S_AXI_ARREADY <= (S_AXI_RVALID && S_AXI_RLAST && S_AXI_RREADY);
// }}}
// raddr_valid
// {{{
generate if (OPT_SELF_RESET)
begin : GEN_READ_RESET
assign raddr_valid = !rfifo_empty;
end else begin : SIMPLE_RADDR_VALID
assign raddr_valid = !S_AXI_ARREADY;
end endgenerate
// }}}
// r_ar*
// {{{
// Double buffer the values associated with any read address request
//
initial r_arvalid = 0;
always @(posedge S_AXI_ACLK)
begin
if (S_AXI_ARVALID && S_AXI_ARREADY)
begin
r_arvalid <= 0; // (M_AXI_ARVALID && !M_AXI_ARREADY);
r_arid <= S_AXI_ARID;
r_araddr <= S_AXI_ARADDR;
r_arlen <= S_AXI_ARLEN;
r_arsize <= S_AXI_ARSIZE;
r_arburst <= S_AXI_ARBURST;
r_arlock <= S_AXI_ARLOCK;
r_arcache <= S_AXI_ARCACHE;
r_arprot <= S_AXI_ARPROT;
r_arqos <= S_AXI_ARQOS;
end else if (M_AXI_ARREADY)
r_arvalid <= 0;
if (!M_AXI_ARESETN)
r_arvalid <= 0;
if (!OPT_EXCLUSIVE || !S_AXI_ARESETN)
r_arlock <= 1'b0;
end
// }}}
// m_ar*
// {{{
always @(*)
if (r_arvalid)
begin
m_arvalid = r_arvalid;
m_arid = r_arid;
m_araddr = r_araddr;
m_arlen = r_arlen;
m_arsize = r_arsize;
m_arburst = r_arburst;
m_arlock = r_arlock;
m_arcache = r_arcache;
m_arprot = r_arprot;
m_arqos = r_arqos;
end else begin
m_arvalid = S_AXI_ARVALID && S_AXI_ARREADY;
m_arid = S_AXI_ARID;
m_araddr = S_AXI_ARADDR;
m_arlen = S_AXI_ARLEN;
m_arsize = S_AXI_ARSIZE;
m_arburst = S_AXI_ARBURST;
m_arlock = S_AXI_ARLOCK && OPT_EXCLUSIVE;
m_arcache = S_AXI_ARCACHE;
m_arprot = S_AXI_ARPROT;
m_arqos = S_AXI_ARQOS;
end
// }}}
// M_AXI_AR*
// {{{
// Set the downstream values according to the transaction we've just
// received.
//
initial M_AXI_ARVALID = 0;
always @(posedge S_AXI_ACLK)
begin
if (!M_AXI_ARVALID || M_AXI_ARREADY)
begin
if (o_read_fault)
M_AXI_ARVALID <= 0;
else
M_AXI_ARVALID <= m_arvalid;
M_AXI_ARID <= m_arid;
M_AXI_ARADDR <= m_araddr;
M_AXI_ARLEN <= m_arlen;
M_AXI_ARSIZE <= m_arsize;
M_AXI_ARBURST <= m_arburst;
M_AXI_ARLOCK <= m_arlock && OPT_EXCLUSIVE;
M_AXI_ARCACHE <= m_arcache;
M_AXI_ARPROT <= m_arprot;
M_AXI_ARQOS <= m_arqos;
end
if (!M_AXI_ARESETN)
M_AXI_ARVALID <= 0;
end
// }}}
// }}}
//
// Read fault detection
// {{{
// read_timer
// {{{
// First step: a timer. The timer starts as soon as the S_AXI_ARVALID
// is accepted. Once that happens, rfifo_empty will no longer be true.
// The count is reset any time the slave produces a value for us to
// read. Once the count saturates, it stops counting.
initial read_timer = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || clear_fault)
read_timer <= 0;
else if (rfifo_empty||(S_AXI_RVALID))
read_timer <= 0;
else if (M_AXI_RVALID)
read_timer <= 0;
else if (!(&read_timer))
read_timer <= read_timer + 1;
// }}}
// read_timeout
// {{{
// Once the counter > OPT_TIMEOUT, we have a timeout condition.
// We'll detect this one clock earlier below. If we ever enter
// a read time out condition, we'll set the read fault. The read
// timeout condition can only be cleared by a reset.
initial read_timeout = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || clear_fault)
read_timeout <= 0;
else if (rfifo_empty||S_AXI_RVALID)
read_timeout <= read_timeout;
else if (M_AXI_RVALID)
read_timeout <= read_timeout;
else if (read_timer == OPT_TIMEOUT)
read_timeout <= 1;
// }}}
//
// faulty_read_return
// {{{
// To avoid returning a fault from the slave, it is important to
// determine within a single clock period whether or not the slaves
// return value is at fault or not. That's the purpose of the code
// below.
always @(*)
begin
faulty_read_return = 0;
if (M_AXI_RVALID)
begin
if (M_AXI_ARVALID)
// It is a fault to return data before the
// request has been accepted
faulty_read_return = 1;
if (M_AXI_RID != rfifo_id)
// It is a fault to return data from a
// different ID
faulty_read_return = 1;
if (rfifo_last && (S_AXI_RVALID || !M_AXI_RLAST))
faulty_read_return = 1;
if (rfifo_penultimate && S_AXI_RVALID && (r_rvalid || !M_AXI_RLAST))
faulty_read_return = 1;
if (M_AXI_RRESP == EXOKAY && (!OPT_EXCLUSIVE || !rfifo_lock))
faulty_read_return = 1;
if (OPT_EXCLUSIVE && exread && M_AXI_RRESP == OKAY)
// Can't switch from EXOKAY to OKAY
faulty_read_return = 1;
if ((!OPT_EXCLUSIVE || (!rfifo_first && !exread))
&& M_AXI_RRESP == EXOKAY)
// Can't switch from OKAY to EXOKAY
faulty_read_return = 1;
end
end
// }}}
// o_read_fault
// {{{
initial o_read_fault = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || clear_fault)
o_read_fault <= 0;
else if ((!M_AXI_ARESETN && o_write_fault) || read_timeout)
o_read_fault <= 1;
else if (M_AXI_RVALID)
begin
if (faulty_read_return)
o_read_fault <= 1;
if (!raddr_valid)
// It is a fault if we haven't issued an AR* request
// yet, and a value is returned
o_read_fault <= 1;
end
// }}}
// }}}
//
// Read return/acknowledgment processing
// {{{
// exread
// {{{
always @(posedge S_AXI_ACLK)
if (!M_AXI_ARESETN || !OPT_EXCLUSIVE)
exread <= 0;
else if (M_AXI_RVALID && M_AXI_RREADY)
begin
if (!M_AXI_RRESP[1])
exread <= (M_AXI_RRESP == EXOKAY);
end else if (S_AXI_RVALID && S_AXI_RREADY)
begin
if (S_AXI_RLAST)
exread <= 1'b0;
end
// }}}
// r_rvalid
// {{{
// Step one, set/create the read return double buffer. If r_rvalid
// is true, there's a valid value in the double buffer location.
//
initial r_rvalid = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || o_read_fault)
r_rvalid <= 0;
else if (!r_rvalid)
begin
// {{{
// Refuse to set the double-buffer valid on any fault.
// That will also keep (below) M_AXI_RREADY high--so that
// following the fault the slave might still (pretend) to
// respond properly
if (faulty_read_return)
r_rvalid <= 0;
else if (o_read_fault)
r_rvalid <= 0;
// If there's nothing in the double buffer, then we might
// place something in there. The double buffer only gets
// filled under two conditions: 1) something is pending to be
// returned, and 2) there's another return that we can't
// stall and so need to accept here.
r_rvalid <= M_AXI_RVALID && M_AXI_RREADY
&& (S_AXI_RVALID && !S_AXI_RREADY);
// }}}
end else if (S_AXI_RREADY)
// Once the up-stream read-channel clears, we can always
// clear the double buffer
r_rvalid <= 0;
// }}}
// r_rresp, r_rdata
// {{{
// Here's the actual values kept whenever r_rvalid is true. This is
// the double buffer. Notice that r_rid and r_last are generated
// locally, so not recorded here.
//
always @(posedge S_AXI_ACLK)
if (!r_rvalid)
begin
r_rresp <= M_AXI_RRESP;
r_rdata <= M_AXI_RDATA;
end
// }}}
// M_AXI_RREADY
// {{{
// Stall the downstream channel any time there's something in the
// double buffer. In spite of the ! here, this is a registered value.
assign M_AXI_RREADY = !r_rvalid;
// }}}
// rfifo_id, rfifo_lock
// {{{
// Copy the ID for later comparisons on the return
always @(*)
rfifo_id = r_arid;
always @(*)
rfifo_lock = r_arlock;
// }}}
// rfifo_[counter|empty|last|penultimate
// {{{
// Count the number of outstanding read elements. This is the number
// of read returns we still expect--from the upstream perspective. The
// downstream perspective will be off by both what's waiting for
// S_AXI_RREADY and what's in the double buffer
//
initial rfifo_counter = 0;
initial rfifo_empty = 1;
initial rfifo_last = 0;
initial rfifo_penultimate= 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
begin
rfifo_counter <= 0;
rfifo_empty <= 1;
rfifo_last <= 0;
rfifo_penultimate<= 0;
end else if (S_AXI_ARVALID && S_AXI_ARREADY)
begin
rfifo_counter <= S_AXI_ARLEN+1;
rfifo_empty <= 0;
rfifo_last <= (S_AXI_ARLEN == 0);
rfifo_penultimate <= (S_AXI_ARLEN == 1);
end else if (!rfifo_empty)
begin
if (S_AXI_RVALID && S_AXI_RREADY)
begin
rfifo_counter <= rfifo_counter - 1;
rfifo_empty <= (rfifo_counter <= 1);
rfifo_last <= (rfifo_counter == 2);
rfifo_penultimate <= (rfifo_counter == 3);
end
end
// }}}
// lock_active
// {{{
generate if (OPT_EXCLUSIVE)
begin : CALC_LOCK_ACTIVE
// {{{
genvar gk;
for(gk=0; gk<(1<<IW); gk=gk+1)
begin : LOCK_PER_ID
reg r_lock_active;
initial r_lock_active = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !M_AXI_ARESETN
|| faulty_read_return || faulty_write_return)
r_lock_active <= 0;
else if (M_AXI_RVALID && M_AXI_RREADY && rfifo_lock
&& !S_AXI_ARREADY
&& r_arid == gk[IW-1:0]
&&(!faulty_read_return && !o_read_fault)
&& M_AXI_RRESP == EXOKAY)
r_lock_active <= 1;
else if (M_AXI_BVALID && M_AXI_BREADY && wfifo_lock
&& r_awid == gk[IW-1:0]
&& (S_AXI_ARREADY
|| r_arid != gk[IW-1:0]
|| !r_arlock)
&& M_AXI_BRESP == OKAY)
r_lock_active <= 0;
else if (S_AXI_ARVALID && S_AXI_ARREADY && S_AXI_ARLOCK
&& S_AXI_ARID == gk[IW-1:0])
r_lock_active <= 0;
assign lock_active[gk] = r_lock_active;
end
// }}}
end else begin : LOCK_NEVER_ACTIVE
// {{{
assign lock_active = 0;
// Keep Verilator happy
// Verilator lint_off UNUSED
wire unused_lock;
assign unused_lock = &{ 1'b0, wfifo_lock };
// Verilator lint_on UNUSED
// }}}
end endgenerate
// }}}
// rfifo_first
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || !OPT_EXCLUSIVE)
rfifo_first <= 1'b0;
else if (S_AXI_ARVALID && S_AXI_ARREADY)
rfifo_first <= 1'b1;
else if (M_AXI_RVALID && M_AXI_RREADY)
rfifo_first <= 1'b0;
else if (o_read_fault)
rfifo_first <= 1'b0;
// }}}
// m_rvalid, m_rresp
// {{{
// Determine values to send back and return
//
// This data set includes all the return values, even though only
// RRESP and RVALID are set in this block.
always @(*)
if (o_read_fault || (!M_AXI_ARESETN && OPT_SELF_RESET))
begin
m_rvalid = !rfifo_empty;
if (S_AXI_RVALID && rfifo_last)
m_rvalid = 0;
m_rresp = SLAVE_ERROR;
end else if (r_rvalid)
begin
m_rvalid = r_rvalid;
m_rresp = r_rresp;
end else begin
m_rvalid = M_AXI_RVALID && raddr_valid && !faulty_read_return;
m_rresp = M_AXI_RRESP;
end
// }}}
// m_rid
// {{{
// We've stored the ID locally, so that our response will never be in
// error
always @(*)
m_rid = rfifo_id;
// }}}
// m_rlast
// {{{
// Ideally, we'd want to say m_rlast = rfifo_last. However, we might
// have a value in S_AXI_RVALID already. In that case, the last
// value can only be true if we are one further away from the end.
// (Remember, rfifo_last and rfifo_penultimate are both dependent upon
// the *upstream* number of read values outstanding, not the downstream
// number which we can't trust in all cases)
always @(*)
if (S_AXI_RVALID)
m_rlast = rfifo_penultimate;
else
m_rlast = (rfifo_last);
// }}}
// m_rdata
// {{{
// In the case of a fault, rdata is a don't care. Therefore we can
// always set it based upon the values returned from the slave.
always @(*)
if (r_rvalid)
m_rdata = r_rdata;
else
m_rdata = M_AXI_RDATA;
// }}}
// S_AXI_R*
// {{{
// Record our return data values
//
// These are the values from either the slave, the double buffer,
// or an error value bypassing either as determined by the m_* values.
// Per spec, all of these values must be registered. First the valid
// signal
initial S_AXI_RVALID = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
S_AXI_RVALID <= 0;
else if (!S_AXI_RVALID || S_AXI_RREADY)
S_AXI_RVALID <= m_rvalid;
// Then the various slave data channels
always @(posedge S_AXI_ACLK)
if (!S_AXI_RVALID || S_AXI_RREADY)
begin
S_AXI_RID <= m_rid;
S_AXI_RRESP <= m_rresp;
S_AXI_RLAST <= m_rlast;
S_AXI_RDATA <= m_rdata;
end
// }}}
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Self-reset
// {{{
////////////////////////////////////////////////////////////////////////
//
//
generate if (OPT_SELF_RESET)
begin : GEN_SELFRESET
// {{{
// Declarations
// {{{
reg [4:0] reset_counter;
reg r_clear_fault, w_clear_fault;
wire reset_timeout;
// }}}
// M_AXI_ARESETN
// {{{
initial M_AXI_ARESETN = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
M_AXI_ARESETN <= 0;
else if (clear_fault)
M_AXI_ARESETN <= 1;
else if (o_read_fault || o_write_fault)
M_AXI_ARESETN <= 0;
// }}}
// reset_counter
// {{{
initial reset_counter = 0;
always @(posedge S_AXI_ACLK)
if (M_AXI_ARESETN)
reset_counter <= 0;
else if (!reset_timeout)
reset_counter <= reset_counter+1;
// }}}
assign reset_timeout = reset_counter[4];
// r_clear_fault
// {{{
initial r_clear_fault <= 1;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
r_clear_fault <= 1;
else if (!M_AXI_ARESETN && !reset_timeout)
r_clear_fault <= 0;
else if (!o_read_fault && !o_write_fault)
r_clear_fault <= 0;
else if (raddr_valid || waddr_valid)
r_clear_fault <= 0;
else
r_clear_fault <= 1;
// }}}
// clear_fault
// {{{
always @(*)
if (S_AXI_AWVALID || S_AXI_ARVALID)
w_clear_fault = 0;
else if (raddr_valid || waddr_valid)
w_clear_fault = 0;
else
w_clear_fault = r_clear_fault;
assign clear_fault = w_clear_fault;
// }}}
// }}}
end else begin : NO_SELFRESET
// {{{
always @(*)
M_AXI_ARESETN = S_AXI_ARESETN;
assign clear_fault = 0;
// }}}
end endgenerate
// }}}
// Make Verilator happy
// {{{
// Verilator lint_off UNUSED
wire unused;
assign unused = &{ 1'b0 };
// Verilator lint_on UNUSED
// }}}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Formal properties
// {{{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
`ifdef FORMAL
// {{{
// Below are just some of the formal properties used to verify
// this core. The full property set is maintained elsewhere.
//
parameter [0:0] F_OPT_FAULTLESS = 1;
//
// ...
// }}}
faxi_slave #(
// {{{
.C_AXI_ID_WIDTH(C_S_AXI_ID_WIDTH),
.C_AXI_DATA_WIDTH(C_S_AXI_DATA_WIDTH),
.C_AXI_ADDR_WIDTH(C_S_AXI_ADDR_WIDTH)
// ...
// }}}
) f_slave(
// {{{
.i_clk(S_AXI_ACLK),
.i_axi_reset_n(S_AXI_ARESETN),
//
// Address write channel
// {{{
.i_axi_awid(S_AXI_AWID),
.i_axi_awaddr(S_AXI_AWADDR),
.i_axi_awlen(S_AXI_AWLEN),
.i_axi_awsize(S_AXI_AWSIZE),
.i_axi_awburst(S_AXI_AWBURST),
.i_axi_awlock(S_AXI_AWLOCK),
.i_axi_awcache(S_AXI_AWCACHE),
.i_axi_awprot(S_AXI_AWPROT),
.i_axi_awqos(S_AXI_AWQOS),
.i_axi_awvalid(S_AXI_AWVALID),
.i_axi_awready(S_AXI_AWREADY),
// }}}
// Write Data Channel
// {{{
.i_axi_wdata(S_AXI_WDATA),
.i_axi_wstrb(S_AXI_WSTRB),
.i_axi_wlast(S_AXI_WLAST),
.i_axi_wvalid(S_AXI_WVALID),
.i_axi_wready(S_AXI_WREADY),
// }}}
// Write response channel
// {{{
.i_axi_bid(S_AXI_BID),
.i_axi_bresp(S_AXI_BRESP),
.i_axi_bvalid(S_AXI_BVALID),
.i_axi_bready(S_AXI_BREADY),
// }}}
// Read address channel
// {{{
.i_axi_arid(S_AXI_ARID),
.i_axi_araddr(S_AXI_ARADDR),
.i_axi_arlen(S_AXI_ARLEN),
.i_axi_arsize(S_AXI_ARSIZE),
.i_axi_arburst(S_AXI_ARBURST),
.i_axi_arlock(S_AXI_ARLOCK),
.i_axi_arcache(S_AXI_ARCACHE),
.i_axi_arprot(S_AXI_ARPROT),
.i_axi_arqos(S_AXI_ARQOS),
.i_axi_arvalid(S_AXI_ARVALID),
.i_axi_arready(S_AXI_ARREADY),
// }}}
// Read data return channel
// {{{
.i_axi_rvalid(S_AXI_RVALID),
.i_axi_rready(S_AXI_RREADY),
.i_axi_rid(S_AXI_RID),
.i_axi_rdata(S_AXI_RDATA),
.i_axi_rresp(S_AXI_RRESP),
.i_axi_rlast(S_AXI_RLAST),
// }}}
// Formal induction values
// {{{
.f_axi_awr_nbursts(f_axi_awr_nbursts),
.f_axi_wr_pending(f_axi_wr_pending),
.f_axi_rd_nbursts(f_axi_rd_nbursts),
.f_axi_rd_outstanding(f_axi_rd_outstanding)
//
// ...
// }}}
// }}}
);
////////////////////////////////////////////////////////////////////////
//
// Write induction properties
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// 1. We will only ever handle a single burst--never any more
always @(*)
assert(f_axi_awr_nbursts <= 1);
always @(*)
if (f_axi_awr_nbursts == 1)
begin
assert(!S_AXI_AWREADY);
if (S_AXI_BVALID)
assert(f_axi_wr_pending == 0);
if (!o_write_fault && M_AXI_AWVALID)
assert(f_axi_wr_pending == M_AXI_AWLEN + 1
- (M_AXI_WVALID ? 1:0)
- (r_wvalid ? 1 : 0));
if (!o_write_fault && f_axi_wr_pending > 0)
assert((!M_AXI_WVALID || !M_AXI_WLAST)
&&(!r_wvalid || !r_wlast));
if (!o_write_fault && M_AXI_WVALID && M_AXI_WLAST)
assert(!r_wvalid || !r_wlast);
end else begin
assert(s_wbursts == 0);
assert(!S_AXI_WREADY);
if (OPT_SELF_RESET)
begin
assert(1 || S_AXI_AWREADY || !M_AXI_ARESETN || !S_AXI_ARESETN);
end else
assert(S_AXI_AWREADY);
end
//
// ...
//
//
// AWREADY will always be low mid-burst
always @(posedge S_AXI_ACLK)
if (!f_past_valid || $past(!S_AXI_ARESETN))
begin
assert(S_AXI_AWREADY == !OPT_SELF_RESET);
end else if (f_axi_wr_pending > 0)
begin
assert(!S_AXI_AWREADY);
end else if (s_wbursts)
begin
assert(!S_AXI_AWREADY);
end else if (!OPT_SELF_RESET)
begin
assert(S_AXI_AWREADY);
end else if (!o_write_fault && !o_read_fault)
assert(S_AXI_AWREADY || OPT_SELF_RESET);
always @(*)
if (f_axi_wr_pending > 0)
begin
assert(s_wbursts == 0);
end else if (f_axi_awr_nbursts > 0)
begin
assert((s_wbursts ? 1:0) == f_axi_awr_nbursts);
end else
assert(s_wbursts == 0);
always @(*)
if (!o_write_fault && S_AXI_AWREADY)
assert(!M_AXI_AWVALID);
always @(*)
if (M_AXI_ARESETN && (f_axi_awr_nbursts == 0))
begin
assert(o_write_fault || !M_AXI_AWVALID);
assert(!S_AXI_BVALID);
assert(s_wbursts == 0);
end else if (M_AXI_ARESETN && s_wbursts == 0)
assert(f_axi_wr_pending > 0);
always @(*)
if (S_AXI_WREADY)
begin
assert(waddr_valid);
end else if (f_axi_wr_pending > 0)
begin
if (!o_write_fault)
assert(M_AXI_WVALID && r_wvalid);
end
always @(*)
if (!OPT_SELF_RESET)
begin
assert(waddr_valid == !S_AXI_AWREADY);
end else begin
// ...
assert(waddr_valid == (f_axi_awr_nbursts > 0));
end
always @(*)
if (S_AXI_ARESETN && !o_write_fault && f_axi_wr_pending > 0 && !S_AXI_WREADY)
assert(M_AXI_WVALID);
always @(*)
if (S_AXI_ARESETN && !o_write_fault && m_wempty)
begin
assert(M_AXI_AWVALID || !M_AXI_WVALID);
assert(M_AXI_AWVALID || f_axi_wr_pending == 0);
end
always @(*)
if (S_AXI_ARESETN && M_AXI_AWVALID)
begin
if (!o_write_fault && !M_AXI_AWVALID)
begin
assert(f_axi_wr_pending + (M_AXI_WVALID ? 1:0) + (r_wvalid ? 1:0) == m_wpending);
end else if (!o_write_fault)
begin
assert(f_axi_wr_pending == M_AXI_AWLEN + 1 - (M_AXI_WVALID ? 1:0) - (r_wvalid ? 1:0));
assert(m_wpending == 0);
end
end
always @(*)
assert(m_wpending <= 9'h100);
always @(*)
if (M_AXI_ARESETN && (!o_write_fault)&&(f_axi_awr_nbursts == 0))
assert(!M_AXI_AWVALID);
always @(*)
if (S_AXI_ARESETN && !o_write_fault)
begin
if (f_axi_awr_nbursts == 0)
begin
assert(!M_AXI_AWVALID);
assert(!M_AXI_WVALID);
end
if (!M_AXI_AWVALID)
assert(f_axi_wr_pending
+(M_AXI_WVALID ? 1:0)
+ (r_wvalid ? 1:0)
== m_wpending);
if (f_axi_awr_nbursts == (S_AXI_BVALID ? 1:0))
begin
assert(!M_AXI_AWVALID);
assert(!M_AXI_WVALID);
end
if (S_AXI_BVALID)
assert(f_axi_awr_nbursts == 1);
if (M_AXI_AWVALID)
assert(m_wpending == 0);
if (S_AXI_AWREADY)
assert(!M_AXI_AWVALID);
end
always @(*)
assert(!r_awvalid);
always @(*)
assert(m_wempty == (m_wpending == 0));
always @(*)
assert(m_wlastctr == (m_wpending == 1));
//
// Verify the contents of the skid buffers
//
//
// ...
//
always @(*)
if (write_timer > OPT_TIMEOUT)
assert(o_write_fault || write_timeout);
always @(*)
if (!OPT_SELF_RESET)
begin
assert(waddr_valid == !S_AXI_AWREADY);
end else if (waddr_valid)
assert(!S_AXI_AWREADY);
always @(*)
if (!o_write_fault && M_AXI_ARESETN)
assert(waddr_valid == !S_AXI_AWREADY);
always @(*)
if (f_axi_wr_pending == 0)
assert(!S_AXI_WREADY);
// }}}
////////////////////////////////////////////////////////////////////////
//
// Read induction properties
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(*)
assert(f_axi_rd_nbursts <= 1);
always @(*)
assert(raddr_valid == (f_axi_rd_nbursts>0));
always @(*)
if (f_axi_rdid_nbursts > 0)
begin
assert(rfifo_id == f_axi_rd_checkid);
end else if (f_axi_rd_nbursts > 0)
assert(rfifo_id != f_axi_rd_checkid);
always @(*)
if (f_axi_rd_nbursts > 0)
assert(raddr_valid);
always @(*)
if (raddr_valid)
assert(!S_AXI_ARREADY);
always @(*)
if (!OPT_SELF_RESET)
begin
assert(raddr_valid == !S_AXI_ARREADY);
end else begin
// ...
assert(raddr_valid == (f_axi_rd_nbursts > 0));
end
//
// ...
//
always @(*)
if (f_axi_rd_outstanding == 0)
assert(!raddr_valid || OPT_SELF_RESET);
always @(*)
if (!o_read_fault && S_AXI_ARREADY)
assert(!M_AXI_ARVALID);
// Our "FIFO" counter
always @(*)
assert(rfifo_counter == f_axi_rd_outstanding);
always @(*)
begin
assert(rfifo_empty == (rfifo_counter == 0));
assert(rfifo_last == (rfifo_counter == 1));
assert(rfifo_penultimate == (rfifo_counter == 2));
end
//
// ...
//
always @(*)
if (r_arvalid)
assert(skid_arvalid);
always @(*)
if (read_timer > OPT_TIMEOUT)
assert(read_timeout);
always @(posedge S_AXI_ACLK)
if (OPT_SELF_RESET && (!f_past_valid || !$past(M_AXI_ARESETN)))
begin
assume(!M_AXI_BVALID);
assume(!M_AXI_RVALID);
end
always @(*)
if (!o_read_fault && M_AXI_ARESETN)
assert(raddr_valid == !S_AXI_ARREADY);
always @(*)
if (f_axi_rd_nbursts > 0)
assert(raddr_valid);
always @(*)
if (S_AXI_ARESETN && OPT_SELF_RESET)
begin
if (!M_AXI_ARESETN)
assert(o_read_fault || o_write_fault /* ... */ );
end
// }}}
////////////////////////////////////////////////////////////////////////
//
// Exclusive access property checking
// {{{
//
////////////////////////////////////////////////////////////////////////
//
// ...
// }}}
////////////////////////////////////////////////////////////////////////
//
// Cover properties
//
////////////////////////////////////////////////////////////////////////
//
// }}}
////////////////////////////////////////////////////////////////////////
//
// Good interface check
//
////////////////////////////////////////////////////////////////////////
//
//
generate if (F_OPT_FAULTLESS)
begin : ASSUME_FAULTLESS
// {{{
//
// ...
//
faxi_master #(
// {{{
.C_AXI_ID_WIDTH(C_S_AXI_ID_WIDTH),
.C_AXI_DATA_WIDTH(C_S_AXI_DATA_WIDTH),
.C_AXI_ADDR_WIDTH(C_S_AXI_ADDR_WIDTH)
// ...
// }}}
) f_master(
// {{{
.i_clk(S_AXI_ACLK),
.i_axi_reset_n(M_AXI_ARESETN),
//
// Address write channel
// {{{
.i_axi_awid(M_AXI_AWID),
.i_axi_awaddr(M_AXI_AWADDR),
.i_axi_awlen(M_AXI_AWLEN),
.i_axi_awsize(M_AXI_AWSIZE),
.i_axi_awburst(M_AXI_AWBURST),
.i_axi_awlock(M_AXI_AWLOCK),
.i_axi_awcache(M_AXI_AWCACHE),
.i_axi_awprot(M_AXI_AWPROT),
.i_axi_awqos(M_AXI_AWQOS),
.i_axi_awvalid(M_AXI_AWVALID),
.i_axi_awready(M_AXI_AWREADY),
// }}}
// Write Data Channel
// {{{
.i_axi_wvalid(M_AXI_WVALID),
.i_axi_wready(M_AXI_WREADY),
.i_axi_wdata(M_AXI_WDATA),
.i_axi_wstrb(M_AXI_WSTRB),
.i_axi_wlast(M_AXI_WLAST),
// }}}
// Write response channel
// {{{
.i_axi_bvalid(M_AXI_BVALID),
.i_axi_bready(M_AXI_BREADY),
.i_axi_bid(M_AXI_BID),
.i_axi_bresp(M_AXI_BRESP),
// }}}
// Read address channel
// {{{
.i_axi_arid(M_AXI_ARID),
.i_axi_araddr(M_AXI_ARADDR),
.i_axi_arlen(M_AXI_ARLEN),
.i_axi_arsize(M_AXI_ARSIZE),
.i_axi_arburst(M_AXI_ARBURST),
.i_axi_arlock(M_AXI_ARLOCK),
.i_axi_arcache(M_AXI_ARCACHE),
.i_axi_arprot(M_AXI_ARPROT),
.i_axi_arqos(M_AXI_ARQOS),
.i_axi_arvalid(M_AXI_ARVALID),
.i_axi_arready(M_AXI_ARREADY),
// }}}
// Read data return channel
// {{{
.i_axi_rvalid(M_AXI_RVALID),
.i_axi_rready(M_AXI_RREADY),
.i_axi_rid(M_AXI_RID),
.i_axi_rdata(M_AXI_RDATA),
.i_axi_rresp(M_AXI_RRESP),
.i_axi_rlast(M_AXI_RLAST),
// }}}
// Formal outputs
// {{{
.f_axi_awr_nbursts(fm_axi_awr_nbursts),
.f_axi_wr_pending(fm_axi_wr_pending),
.f_axi_rd_nbursts(fm_axi_rd_nbursts),
.f_axi_rd_outstanding(fm_axi_rd_outstanding)
//
// ...
// }}}
// }}}
);
////////////////////////////////////////////////////////////////
//
// Contract: If the downstream has no faults, then we
// shouldn't detect any here.
// {{{
////////////////////////////////////////////////////////////////
//
//
always @(*)
if (OPT_SELF_RESET)
begin
assert(!o_write_fault || !M_AXI_ARESETN);
end else
assert(!o_write_fault);
always @(*)
if (OPT_SELF_RESET)
begin
assert(!o_read_fault || !M_AXI_ARESETN);
end else
assert(!o_read_fault);
always @(*)
if (OPT_SELF_RESET)
begin
assert(!read_timeout || !M_AXI_ARESETN);
end else
assert(!read_timeout);
always @(*)
if (OPT_SELF_RESET)
begin
assert(!write_timeout || !M_AXI_ARESETN);
end else
assert(!write_timeout);
always @(*)
if (S_AXI_AWREADY)
assert(!M_AXI_AWVALID);
//
// ...
//
always @(*)
if (M_AXI_ARESETN && f_axi_rd_nbursts > 0)
assert(f_axi_rd_nbursts == fm_axi_rd_nbursts
+ (M_AXI_ARVALID ? 1 : 0)
+ (r_rvalid&&m_rlast ? 1 : 0)
+ (S_AXI_RVALID&&S_AXI_RLAST ? 1 : 0));
always @(*)
if (M_AXI_ARESETN && f_axi_rd_outstanding > 0)
assert(f_axi_rd_outstanding == fm_axi_rd_outstanding
+ (M_AXI_ARVALID ? M_AXI_ARLEN+1 : 0)
+ (r_rvalid ? 1 : 0)
+ (S_AXI_RVALID ? 1 : 0));
//
// ...
//
always @(*)
if (M_AXI_RVALID)
assert(!M_AXI_ARVALID);
always @(*)
if (S_AXI_ARESETN)
assert(m_wpending == fm_axi_wr_pending);
always @(*)
if (S_AXI_ARESETN && fm_axi_awr_nbursts > 0)
begin
assert(fm_axi_awr_nbursts== f_axi_awr_nbursts);
assert(fm_axi_awr_nbursts == 1);
//
// ...
//
end
// }}}
////////////////////////////////////////////////////////////////
//
// Exclusive address checking
// {{{
////////////////////////////////////////////////////////////////
//
//
//
//
// ...
//
////////////////////////////////////////////////////////////////
//
// Cover checks
// {{{
////////////////////////////////////////////////////////////////
//
//
// }}}
////////////////////////////////////////////////////////////////
//
// "Careless" assumptions
// {{{
////////////////////////////////////////////////////////////////
//
//
end endgenerate
//
// ...
//
////////////////////////////////////////////////////////////////////////
//
// Never path check
// {{{
////////////////////////////////////////////////////////////////////////
//
//
(* anyconst *) reg [C_S_AXI_ADDR_WIDTH-1:0] fc_never_write_addr,
fc_never_read_addr;
(* anyconst *) reg [C_S_AXI_DATA_WIDTH + C_S_AXI_DATA_WIDTH/8-1:0]
fc_never_write_data;
(* anyconst *) reg [C_S_AXI_DATA_WIDTH-1:0] fc_never_read_data;
// Write address
// {{{
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && S_AXI_AWVALID)
assume(S_AXI_AWADDR != fc_never_write_addr);
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && !o_write_fault && M_AXI_ARESETN && M_AXI_AWVALID)
assert(M_AXI_AWADDR != fc_never_write_addr);
// }}}
// Write data
// {{{
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && S_AXI_WVALID)
assume({ S_AXI_WDATA, S_AXI_WSTRB } != fc_never_write_data);
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && !o_write_fault && M_AXI_ARESETN && M_AXI_WVALID)
begin
if (lock_failed)
assert(M_AXI_WSTRB == 0);
else
assert({ M_AXI_WDATA, M_AXI_WSTRB } != fc_never_write_data);
end
// }}}
// Read address
// {{{
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && S_AXI_ARVALID)
assume(S_AXI_ARADDR != fc_never_read_addr);
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && r_arvalid)
assume(r_araddr != fc_never_read_addr);
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && !o_read_fault && M_AXI_ARESETN && M_AXI_ARVALID)
assert(M_AXI_ARADDR != fc_never_read_addr);
// }}}
// Read data
// {{{
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && M_AXI_ARESETN && M_AXI_RVALID)
assume(M_AXI_RDATA != fc_never_read_data);
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && S_AXI_RVALID && S_AXI_RRESP != SLAVE_ERROR)
assert(S_AXI_RDATA != fc_never_read_data);
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Cover properties
// {{{
////////////////////////////////////////////////////////////////////////
//
// We'll use these to determine the best performance this core
// can achieve
//
reg [4:0] f_dbl_rd_count, f_dbl_wr_count;
reg [4:0] f_rd_count, f_wr_count;
// f_wr_count
// {{{
initial f_wr_count = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || o_write_fault)
f_wr_count <= 0;
else if (S_AXI_BVALID && S_AXI_BREADY)
begin
if (!(&f_wr_count))
f_wr_count <= f_wr_count + 1;
end
// }}}
// f_dbl_wr_count
// {{{
initial f_dbl_wr_count = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || o_write_fault||(S_AXI_AWVALID && S_AXI_AWLEN < 3))
f_dbl_wr_count <= 0;
else if (S_AXI_BVALID && S_AXI_BREADY)
begin
if (!(&f_dbl_wr_count))
f_dbl_wr_count <= f_dbl_wr_count + 1;
end
// }}}
// f_rd_count
// {{{
initial f_rd_count = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || o_read_fault)
f_rd_count <= 0;
else if (S_AXI_RVALID && S_AXI_RREADY && S_AXI_RLAST)
begin
if (!(&f_rd_count))
f_rd_count <= f_rd_count + 1;
end
// }}}
// f_dbl_rd_count
// {{{
initial f_dbl_rd_count = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || o_read_fault||(S_AXI_ARVALID && S_AXI_ARLEN < 3))
f_dbl_rd_count <= 0;
else if (S_AXI_RVALID && S_AXI_RREADY && S_AXI_RLAST)
begin
if (!(&f_dbl_rd_count))
f_dbl_rd_count <= f_dbl_rd_count + 1;
end
// }}}
// Can we complete a single write burst without fault?
// {{{
always @(*)
if (S_AXI_ARESETN)
cover((f_wr_count > 1) && (!o_write_fault));
always @(*)
if (S_AXI_ARESETN)
cover((f_dbl_wr_count > 1) && (!o_write_fault));
// }}}
// Can we complete four write bursts without fault? (and return to idle)
// {{{
always @(*)
if (S_AXI_ARESETN)
cover((f_wr_count > 3) && (!o_write_fault)
&&(!S_AXI_AWVALID && !S_AXI_WVALID
&& !S_AXI_BVALID)
&& (f_axi_awr_nbursts == 0)
&& (f_axi_wr_pending == 0));
always @(*)
if (S_AXI_ARESETN)
cover((f_dbl_wr_count > 3) && (!o_write_fault)
&&(!S_AXI_AWVALID && !S_AXI_WVALID
&& !S_AXI_BVALID)
&& (f_axi_awr_nbursts == 0)
&& (f_axi_wr_pending == 0));
// }}}
// Can we complete a single read burst without fault?
// {{{
always @(*)
if (S_AXI_ARESETN)
cover((f_rd_count > 1) && (!o_read_fault));
always @(*)
if (S_AXI_ARESETN)
cover((f_dbl_rd_count > 1) && (!o_read_fault));
// }}}
// Can we complete four read bursts without fault?
// {{{
always @(*)
if (S_AXI_ARESETN)
cover((f_rd_count > 3) && (f_axi_rd_nbursts == 0)
&& !S_AXI_ARVALID && !S_AXI_RVALID);
always @(*)
if (S_AXI_ARESETN)
cover((f_dbl_rd_count > 3) && (f_axi_rd_nbursts == 0)
&& !S_AXI_ARVALID && !S_AXI_RVALID);
// }}}
`endif
// }}}
endmodule
`ifndef YOSYS
`default_nettype wire
`endif
|