forked from ZipCPU/wb2axip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
axispacker.v
890 lines (814 loc) · 21.3 KB
/
axispacker.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
////////////////////////////////////////////////////////////////////////////////
//
// Filename: axispacker
// {{{
// Project: WB2AXIPSP: bus bridges and other odds and ends
//
// Purpose: AXI-Stream packer: This uses TKEEP to pack bytes in a stream.
// Bytes with TKEEP clear on input will be removed from the
// output stream.
//
// TID, TDEST, and TUSER fields are not (currently) implemented, although
// they shouldn't be too hard to add back in.
//
// This design *ASSUMES* that TLAST will only be set if TKEEP is not zero.
// This assumption is not required by the AXI-stream specification, and
// should be removed in the future.
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
// }}}
// Copyright (C) 2019-2021, 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 axispacker #(
parameter C_AXIS_DATA_WIDTH = 32,
parameter [0:0] OPT_LOWPOWER = 1
) (
// {{{
input wire S_AXI_ACLK, S_AXI_ARESETN,
// Incoming slave interface
// {{{
input wire S_AXIS_TVALID,
output wire S_AXIS_TREADY,
input wire [C_AXIS_DATA_WIDTH-1:0] S_AXIS_TDATA,
input wire [C_AXIS_DATA_WIDTH/8-1:0] S_AXIS_TSTRB,
input wire [C_AXIS_DATA_WIDTH/8-1:0] S_AXIS_TKEEP,
input wire S_AXIS_TLAST,
// }}}
// Outgoing AXI-Stream master interface
// {{{
output reg M_AXIS_TVALID,
input wire M_AXIS_TREADY,
output reg [C_AXIS_DATA_WIDTH-1:0] M_AXIS_TDATA,
output reg [C_AXIS_DATA_WIDTH/8-1:0] M_AXIS_TSTRB,
output reg [C_AXIS_DATA_WIDTH/8-1:0] M_AXIS_TKEEP,
output reg M_AXIS_TLAST
// }}}
// }}}
);
// Local declarations
// {{{
localparam DW = C_AXIS_DATA_WIDTH;
wire pre_tvalid, pre_tready;
wire [DW-1:0] pre_tdata;
wire [DW/8-1:0] pre_tstrb, pre_tkeep;
wire pre_tlast;
localparam MAX_COUNT = DW/8;
localparam COUNT_BITS = $clog2(MAX_COUNT+1)+1;
reg [DW-1:0] pck_tdata;
reg [DW/8-1:0] pck_tstrb, pck_tkeep;
reg pck_tlast;
reg [COUNT_BITS-1:0] pck_count;
reg axis_ready;
wire skd_valid;
wire [DW-1:0] skd_data;
wire [DW/8-1:0] skd_strb, skd_keep;
wire [COUNT_BITS-1:0] skd_count;
wire skd_last;
reg [COUNT_BITS-1:0] mid_fill;
reg [DW-1:0] mid_data;
reg [DW/8-1:0] mid_strb, mid_keep;
reg mid_last;
reg [2*DW-1:0] w_packed_data;
reg [2*DW/8-1:0] w_packed_strb, w_packed_keep;
localparam TRIM_MAX = MAX_COUNT[COUNT_BITS-1:0];
reg next_valid, next_last;
// }}}
////////////////////////////////////////////////////////////////////////
//
// Incoming skid buffer
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// This makes it so that we can control VALID && DATA (and so
// backpressure) with a combinatorial value, something that would
// otherwise be against protocol.
//
`ifdef FORMAL
// {{{
assign pre_tvalid = S_AXIS_TVALID;
assign S_AXIS_TREADY = pre_tready;
assign pre_tdata = S_AXIS_TDATA;
assign pre_tstrb = S_AXIS_TSTRB;
assign pre_tkeep = S_AXIS_TKEEP;
assign pre_tlast = S_AXIS_TLAST;
// }}}
`else
skidbuffer #(
// {{{
.DW(DW + DW/8 + DW/8 + 1),
.OPT_OUTREG(1'b1)
// }}}
) slave_skd (
// {{{
.i_clk(S_AXI_ACLK),
.i_reset(!S_AXI_ARESETN),
.i_valid(S_AXIS_TVALID), .o_ready(S_AXIS_TREADY),
.i_data({ S_AXIS_TDATA, S_AXIS_TSTRB,
S_AXIS_TKEEP, S_AXIS_TLAST }),
.o_valid(pre_tvalid), .i_ready(pre_tready),
.o_data({ pre_tdata, pre_tstrb, pre_tkeep, pre_tlast })
// }}}
);
`endif
// }}}
////////////////////////////////////////////////////////////////////////
//
// Beat packing stage
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(*)
begin
{ pck_tdata, pck_tstrb, pck_tkeep }
= pack( pre_tdata, pre_tstrb,
(pre_tvalid) ? pre_tkeep : {(DW/8){1'b0}} );
pck_tlast = pre_tlast;
// Verilator lint_off WIDTH
pck_count = $countones(pre_tkeep);
// Verilator lint_on WIDTH
end
`ifdef FORMAL
// {{{
assign skd_valid = pre_tvalid;
assign pre_tready = axis_ready;
assign skd_data = pck_tdata;
assign skd_strb = pck_tstrb;
assign skd_keep = pck_tkeep;
assign skd_last = pck_tlast;
assign skd_count= pck_count;
// }}}
`else
skidbuffer #(
// {{{
.DW(DW + DW/8 + DW/8 + 1 + COUNT_BITS),
.OPT_OUTREG(1'b1)
// }}}
) beat_skd (
// {{{
.i_clk(S_AXI_ACLK),
.i_reset(!S_AXI_ARESETN),
.i_valid(pre_tvalid), .o_ready(pre_tready),
.i_data({ pck_count, pck_tdata, pck_tstrb,
pck_tkeep, pck_tlast }),
.o_valid(skd_valid), .i_ready(axis_ready),
.o_data({ skd_count, skd_data, skd_strb, skd_keep,
skd_last })
// }}}
);
`endif
function [DW+DW/8+DW/8-1:0] pack; // (i_data, i_strb, i_keep)
// {{{
input [DW-1:0] i_data;
input [DW/8-1:0] i_strb;
input [DW/8-1:0] i_keep;
reg [DW-1:0] p_data;
reg [DW/8-1:0] p_strb;
reg [DW/8-1:0] p_keep;
integer rounds, ik;
begin
p_data = i_data;
p_strb = i_strb;
p_keep = i_keep;
for(ik=0; ik < DW/8; ik=ik+1)
begin
if (!p_keep[ik])
begin
p_data[ik*8 +: 8]= 8'h00;
p_strb[ik] = 1'b0;
end
end
for(rounds = 0; rounds < DW/8; rounds = rounds+1)
begin
for(ik=0; ik < DW/8-1; ik=ik+1)
begin
if (!p_keep[ik])
begin
p_data[ik*8 +: 8]=p_data[(ik+1)*8 +: 8];
p_keep[ik] = p_keep[ik+1];
p_strb[ik] = p_strb[ik+1];
p_keep[ik+1] = 0;
p_data[(ik+1)*8 +: 8] = 0;
p_strb[ik+1] = 0;
end
end
end
pack = { p_data, p_strb, p_keep };
/*
p_data = 0;
p_strb = 0;
p_keep = 0;
for(fill=0; fill<2*DW; fill=fill+1)
begin
p_data[(fill *8) +: 8] = i_data[fill*8 +: 8];
p_strb[ fill ] = i_strb[fill];
p_keep[ fill ] = i_keep[fill];
if (fill != 0)
p_keep[ fill ] = i_keep[fill]
&& $countones(i_keep[((fill > 0)?(fill-1):0):0]) == fill;
for(ik=fill; ik<2*DW; ik=ik+1)
if (i_keep[ik] && $countones(i_keep[ik-1:0]) == fill)
begin
p_data[fill*8 +: 8] = i_data[ik*8 +: 8];
p_strb[fill ] = i_strb[ik];
p_keep[fill ] = i_keep[ik];
end
if (!p_keep[fill])
begin
p_strb[fill] = 1'b0;
if (OPT_LOWPOWER)
p_data[(fill *8) +: 8] = 8'h00;
end
end
pack = { p_data, p_strb, p_keep };
*/
end endfunction
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Word Packing stage
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// axis_ready
// {{{
always @(*)
begin
axis_ready = 1;
if ((mid_last || (skd_count + mid_fill >= TRIM_MAX))
&&(M_AXIS_TVALID && !M_AXIS_TREADY))
axis_ready = 0;
if (!skd_valid)
axis_ready = 0;
end
// }}}
// mid_fill
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
mid_fill <= 0;
else if (mid_last && (!M_AXIS_TVALID || M_AXIS_TREADY))
mid_fill <= (axis_ready) ? skd_count : 0;
else if (skd_valid && skd_last && (!M_AXIS_TVALID || M_AXIS_TREADY))
mid_fill <= (skd_count + mid_fill <= TRIM_MAX) ? 0 : skd_count + mid_fill - TRIM_MAX;
else
mid_fill <= mid_fill + (axis_ready ? skd_count : 0)
- ((next_valid && (!M_AXIS_TVALID || M_AXIS_TREADY))
? TRIM_MAX : 0);
// }}}
// mid_last
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
mid_last <= 0;
else if (axis_ready)
begin
mid_last <= !next_last || (M_AXIS_TVALID && !M_AXIS_TREADY);
if (mid_last)
mid_last <= 1'b1;
if (!skd_last)
mid_last <= 1'b0;
end else if (!M_AXIS_TVALID || M_AXIS_TREADY)
mid_last <= 0;
// }}}
// mid_data, mid_strb, mid_keep
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
begin
mid_data <= 0;
mid_strb <= 0;
mid_keep <= 0;
end else if (mid_last && (!M_AXIS_TVALID || M_AXIS_TREADY))
begin
mid_data <= (axis_ready) ? skd_data : 0;
mid_strb <= (axis_ready) ? skd_strb : 0;
mid_keep <= (axis_ready) ? skd_keep : 0;
end else if (skd_valid && skd_last && (!M_AXIS_TVALID || M_AXIS_TREADY))
begin
if (skd_count + mid_fill <= TRIM_MAX)
begin
mid_data <= 0;
mid_strb <= 0;
mid_keep <= 0;
end else begin
mid_data <= w_packed_data[2*DW-1:DW];
mid_strb <= w_packed_strb[2*DW/8-1:DW/8];
mid_keep <= w_packed_keep[2*DW/8-1:DW/8];
end
end else if (axis_ready)
begin
if (mid_fill + skd_count >= TRIM_MAX)
begin
mid_data <= w_packed_data[2*DW-1:DW];
mid_strb <= w_packed_strb[2*DW/8-1:DW/8];
mid_keep <= w_packed_keep[2*DW/8-1:DW/8];
end else begin
mid_data <= w_packed_data[DW-1:0];
mid_strb <= w_packed_strb[DW/8-1:0];
mid_keep <= w_packed_keep[DW/8-1:0];
end
end
// }}}
// w_packed_data, w_packed_strb, w_packed_keep
// {{{
always @(*)
begin
w_packed_data = 0;
w_packed_strb = 0;
w_packed_data = { {(DW){1'b0}}, mid_data }
| ( { {(DW){1'b0}}, skd_data } << (mid_fill * 8));
w_packed_strb = { {(DW/8){1'b0}}, mid_strb }
| ( { {(DW/8){1'b0}}, skd_strb } << (mid_fill));
w_packed_keep = { {(DW/8){1'b0}}, mid_keep }
| ( { {(DW/8){1'b0}}, skd_keep } << (mid_fill));
end
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Outputs
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// next_valid
// {{{
always @(*)
begin
next_valid = skd_valid && (skd_count + mid_fill >= TRIM_MAX);
if (mid_last || (skd_last && skd_valid))
next_valid = 1;
if (skd_count + mid_fill == 0)
next_valid = 0;
end
// }}}
// next_last
// {{{
always @(*)
begin
next_last = mid_last;
if (skd_valid && skd_last && (skd_count + mid_fill <= TRIM_MAX))
next_last = 1;
if (!next_valid)
next_last = 0;
end
// }}}
// M_AXIS_TVALID
// {{{
initial M_AXIS_TVALID = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
M_AXIS_TVALID <= 0;
else if (!M_AXIS_TVALID || M_AXIS_TREADY)
M_AXIS_TVALID <= next_valid;
// }}}
// M_AXIS_TDATA, M_AXIS_TSTRB, M_AXIS_TKEEP, M_AXIS_TLAST
// {{{
initial M_AXIS_TDATA = 0;
initial M_AXIS_TSTRB = 0;
initial M_AXIS_TKEEP = 0;
initial M_AXIS_TLAST = 0;
always @(posedge S_AXI_ACLK)
if (OPT_LOWPOWER && !S_AXI_ARESETN)
begin
M_AXIS_TDATA <= 0;
M_AXIS_TSTRB <= 0;
M_AXIS_TKEEP <= 0;
M_AXIS_TLAST <= 0;
end else if (!M_AXIS_TVALID || M_AXIS_TREADY)
begin
if (mid_last)
begin
M_AXIS_TDATA <= mid_data;
M_AXIS_TSTRB <= mid_strb;
M_AXIS_TKEEP <= mid_keep;
M_AXIS_TLAST <= 1'b1;
end else begin
M_AXIS_TDATA <= w_packed_data[DW-1:0];
M_AXIS_TSTRB <= w_packed_strb[DW/8-1:0];
M_AXIS_TKEEP <= w_packed_keep[DW/8-1:0];
M_AXIS_TLAST <= next_last;
end
if (OPT_LOWPOWER && !next_valid)
begin
M_AXIS_TDATA <= 0;
M_AXIS_TSTRB <= 0;
M_AXIS_TKEEP <= 0;
M_AXIS_TLAST <= 0;
end
end
// }}}
// }}}
// Keep Verilator happy
// {{{
// Verilator lint_off UNUSED
wire unused;
assign unused = &{ 1'b0 };
// Verilator lint_on UNUSED
// }}}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Formal properties
// {{{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
`ifdef FORMAL
reg f_past_valid;
localparam F_COUNT = COUNT_BITS + 4 + 16;
reg [F_COUNT-1:0] f_icount, f_ocount, f_ibeat, f_obeat,
f_mcount, f_mbeat;
initial f_past_valid = 0;
always @(posedge S_AXI_ACLK)
f_past_valid <= 1;
always @(*)
if (!f_past_valid)
assume(!S_AXI_ARESETN);
////////////////////////////////////////////////////////////////////////
//
// Incoming stream assumptions
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(posedge S_AXI_ACLK)
if (!f_past_valid || $past(!S_AXI_ARESETN))
begin
assume(!S_AXIS_TVALID);
end else if ($past(S_AXIS_TVALID && !S_AXIS_TREADY))
begin
assume(S_AXIS_TVALID);
assume($stable(S_AXIS_TDATA));
assume($stable(S_AXIS_TSTRB));
assume($stable(S_AXIS_TKEEP));
assume($stable(S_AXIS_TLAST));
end
// If TKEEP is low, TSTRB must be low as well
always @(*)
if (S_AXI_ARESETN)
assume(((~S_AXIS_TKEEP) & S_AXIS_TSTRB) == 0);
// TLAST requires at least one beat
always @(*)
if (S_AXI_ARESETN && S_AXIS_TVALID && S_AXIS_TLAST)
assume(S_AXIS_TKEEP != 0);
// }}}
////////////////////////////////////////////////////////////////////////
//
// Outgoing stream assertions
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(posedge S_AXI_ACLK)
if (!f_past_valid || $past(!S_AXI_ARESETN))
begin
assert(!M_AXIS_TVALID);
end else if ($past(S_AXIS_TVALID && !S_AXIS_TREADY))
begin
assert(M_AXIS_TVALID);
assert($stable(M_AXIS_TDATA));
assert($stable(M_AXIS_TSTRB));
assert($stable(M_AXIS_TKEEP));
assert($stable(M_AXIS_TLAST));
end
// If TKEEP is low, TSTRB must be low as well
always @(*)
if (S_AXI_ARESETN && M_AXIS_TVALID)
assert(((~M_AXIS_TKEEP) & M_AXIS_TSTRB) == 0);
// Our output requirement is that if TLAST is ever low, TKEEP must
// be all ones
always @(*)
if (S_AXI_ARESETN && M_AXIS_TVALID && !M_AXIS_TLAST)
assert(&M_AXIS_TKEEP);
always @(*)
if (S_AXI_ARESETN && OPT_LOWPOWER && !M_AXIS_TVALID)
begin
assert(M_AXIS_TDATA == 0);
assert(M_AXIS_TSTRB == 0);
assert(M_AXIS_TKEEP == 0);
assert(M_AXIS_TLAST == 0);
end
// TLAST requires at least one beat
always @(*)
if (S_AXI_ARESETN && M_AXIS_TVALID && M_AXIS_TLAST)
assert(M_AXIS_TKEEP != 0);
// }}}
////////////////////////////////////////////////////////////////////////
//
// Induction assertions for the middle
// {{{
////////////////////////////////////////////////////////////////////////
//
//
genvar gk;
always @(*)
if (S_AXI_ARESETN)
assert(mid_fill == { 1'b0, $countones(mid_keep) });
always @(*)
if (S_AXI_ARESETN && mid_last)
assert(mid_fill > 0);
// If TKEEP is low, TSTRB must be low as well
always @(*)
if (S_AXI_ARESETN)
begin
if (mid_fill > 0)
begin
assert(((~mid_keep) & mid_strb) == 0);
end else begin
// assert(mid_data == 0);
assert(mid_strb == 0);
end
end
// Our output requirement is that if TLAST is ever low, TKEEP must
// be all ones
generate for(gk=1; gk<DW/8; gk=gk+1)
begin
always @(*)
if (S_AXI_ARESETN && mid_fill > 0 && mid_keep[gk])
assert(&mid_keep[gk-1:0]);
end endgenerate
always @(*)
if (S_AXI_ARESETN && OPT_LOWPOWER && !M_AXIS_TVALID)
begin
assert(M_AXIS_TDATA == 0);
assert(M_AXIS_TSTRB == 0);
assert(M_AXIS_TKEEP == 0);
assert(M_AXIS_TLAST == 0);
end
// }}}
////////////////////////////////////////////////////////////////////////
//
// Contract properties
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// Pick a byte of the given packet. Force that byte to have a known
// value. Prove that the same byte on the output has the same known
// value.
(* anyconst *) reg [F_COUNT-1:0] fc_count;
(* anyconst *) reg [8-1:0] fc_data;
(* anyconst *) reg fc_strb, fc_last;
wire [F_COUNT:0] f_chk_count;
// Assume the special input
// {{{
generate for(gk=0; gk<DW/8; gk=gk+1)
begin
if (gk == 0)
begin
always @(*)
if (S_AXIS_TVALID && S_AXIS_TKEEP[0]
&& f_icount == fc_count)
begin
assume(fc_data == S_AXIS_TDATA[7:0]);
assume(fc_strb == S_AXIS_TSTRB[0]);
if (fc_last)
begin
assume(S_AXIS_TKEEP[DW/8-1:1] == 0);
assume(S_AXIS_TLAST);
end else if (S_AXIS_TLAST)
assume(S_AXIS_TKEEP[DW/8-1:1] != 0);
end
end else begin
always @(*)
if (S_AXIS_TKEEP[gk] && (f_icount
// Verilator lint_off WIDTH
+ $countones(S_AXIS_TKEEP[gk-1:0]) == fc_count))
// Verilator lint_on WIDTH
begin
assume(S_AXIS_TDATA[gk*8 +: 8] == fc_data);
assume(S_AXIS_TSTRB[gk] == fc_strb);
if (fc_last)
begin
if (gk < DW/8-1)
assume(S_AXIS_TKEEP[DW/8-1:gk+1] == 0);
assume(S_AXIS_TLAST);
end else if (gk < DW/8-1)
begin
if (S_AXIS_TLAST)
assume(S_AXIS_TKEEP[DW/8-1:gk+1] != 0);
end else
assume(!S_AXIS_TLAST);
end
end
end endgenerate
// }}}
// Assert the special output
// {{{
generate for(gk=0; gk<DW/8; gk=gk+1)
begin
if (gk == 0)
begin
always @(*)
if (S_AXI_ARESETN && M_AXIS_TVALID && M_AXIS_TKEEP[0]
&& f_ocount == fc_count)
begin
assert(M_AXIS_TDATA[7:0] == fc_data);
assert(M_AXIS_TSTRB[0] == fc_strb);
if (fc_last)
begin
assert(M_AXIS_TKEEP[DW/8-1:1] == 0);
assert(M_AXIS_TLAST);
end else if (M_AXIS_TLAST)
assert(M_AXIS_TKEEP[DW/8-1:1] != 0);
end
end else begin
always @(*)
if (S_AXI_ARESETN && M_AXIS_TKEEP[gk] &&
// Verilator lint_off WIDTH
(f_ocount + $countones(M_AXIS_TKEEP[gk-1:0])
== fc_count))
// Verilator lint_on WIDTH
begin
assert(M_AXIS_TDATA[gk*8 +: 8] == fc_data);
assert(M_AXIS_TSTRB[gk] == fc_strb);
if (fc_last)
begin
if (gk < DW/8-1)
assert(M_AXIS_TKEEP[DW/8-1:gk+1] == 0);
assert(M_AXIS_TLAST);
end else if (gk < DW/8-1)
begin
if (M_AXIS_TLAST)
assert(M_AXIS_TKEEP[DW/8-1:gk+1] != 0);
end else
assert(!M_AXIS_TLAST);
end
end
end endgenerate
// }}}
// f_icount
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
f_icount <= 0;
else if (S_AXIS_TVALID && S_AXIS_TREADY)
// Verilator lint_off WIDTH
f_icount <= f_icount + $countones(S_AXIS_TKEEP);
// Verilator lint_on WIDTH
// }}}
// f_ocount
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
f_ocount <= 0;
else if (M_AXIS_TVALID && M_AXIS_TREADY)
// Verilator lint_off WIDTH
f_ocount <= f_ocount + $countones(M_AXIS_TKEEP);
// Verilator lint_on WIDTH
// }}}
// Induction assertion(s) on mid_*
// {{{
always @(*)
// Verilator lint_off WIDTH
f_mcount = f_icount - mid_fill;
// Verilator lint_on WIDTH
generate for(gk=0; gk<DW/8; gk=gk+1)
begin
if (gk == 0)
begin
always @(*)
if (S_AXI_ARESETN && mid_fill > 0
&& f_mcount == fc_count)
begin
assert(mid_data[7:0] == fc_data);
assert(mid_strb[0] == fc_strb);
assert(mid_keep[0]);
if (fc_last)
begin
assert(mid_fill == 1);
assert(mid_last);
end else if (mid_last)
assert(mid_fill > 1);
end else if (S_AXI_ARESETN && mid_fill == 0)
begin
assert(mid_data[7:0] == 8'h00);
assert(!mid_strb[0]);
assert(!mid_keep[0]);
end
end else begin
always @(*)
if (S_AXI_ARESETN && mid_fill > gk
&& (f_mcount + gk == fc_count))
begin
assert(mid_data[gk*8 +: 8] == fc_data);
assert(mid_strb[gk] == fc_strb);
assert(mid_keep[gk]);
if (fc_last)
begin
assert(mid_fill == gk + 1);
assert(mid_last);
end else if (gk < DW/8-1)
begin
if (mid_last)
assert(mid_fill > gk + 1);
end else
assert(!mid_last);
end else if (S_AXI_ARESETN && mid_fill <= gk)
begin
assert(mid_data[gk*8 +: 8] == 8'h00);
assert(!mid_strb[gk]);
assert(!mid_keep[gk]);
end
end
end endgenerate
// }}}
// Relate icount to ocount
// {{{
// Verilator lint_off WIDTH
assign f_chk_count = f_ocount + mid_fill + $countones(M_AXIS_TKEEP);
// Verilator lint_on WIDTH
always @(*)
if (S_AXI_ARESETN)
begin
assume(f_chk_count[F_COUNT] == 1'b0);
assert(f_icount == f_chk_count[F_COUNT-1:0]);
end
// }}}
// f_ibeat
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
f_ibeat <= 0;
else if (S_AXIS_TVALID && S_AXIS_TREADY)
begin
// Verilator lint_off WIDTH
f_ibeat <= f_ibeat + $countones(S_AXIS_TKEEP);
// Verilator lint_on WIDTH
if (M_AXIS_TLAST)
f_ibeat <= 0;
end
// }}}
// f_obeat
// {{{
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
f_obeat <= 0;
else if (M_AXIS_TVALID && M_AXIS_TREADY)
begin
// Verilator lint_off WIDTH
f_obeat <= f_obeat + $countones(M_AXIS_TKEEP);
// Verilator lint_on WIDTH
if (M_AXIS_TLAST)
f_obeat <= 0;
end
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Cover checks
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && $past(S_AXI_ARESETN))
cover(M_AXIS_TVALID && M_AXIS_TREADY && M_AXIS_TLAST
&& $past(M_AXIS_TVALID&& M_AXIS_TREADY&& M_AXIS_TLAST));
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && $past(S_AXI_ARESETN))
cover(M_AXIS_TVALID && !M_AXIS_TLAST
&& $past(M_AXIS_TVALID&& M_AXIS_TREADY&& M_AXIS_TLAST));
always @(posedge S_AXI_ACLK)
if (S_AXI_ARESETN && $past(S_AXI_ARESETN))
cover(M_AXIS_TVALID && M_AXIS_TLAST
&& $past(M_AXIS_TVALID&& M_AXIS_TREADY&&!M_AXIS_TLAST));
// }}}
// Keep Verilator happy
// {{{
// Verilator lint_off UNUSED
wire unused_formal;
assign unused_formal = &{ 1'b0, f_ibeat, f_obeat, f_icount, f_ocount };
// Verilator lint_on UNUSED
// }}}
`endif // FORMAL
// }}}
endmodule