-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathsdax_mm2s.v
2386 lines (2194 loc) · 64.5 KB
/
sdax_mm2s.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: rtl/sdax_mm2s.v
// {{{
// Project: SD-Card controller
//
// Purpose: Converts an AXI (full) memory port to an AXI-stream
// interface.
//
// While I am aware that other vendors sell similar components, if you
// look under the hood you'll find no relation to anything but my own
// work here.
//
// Registers: (None--this IP is controlled from elsewhere)
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
// }}}
// Copyright (C) 2016-2025, Gisselquist Technology, LLC
// {{{
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. (It's in the $(ROOT)/doc directory. Run make with no
// target there if the PDF file isn't present.) If not, see
// <http://www.gnu.org/licenses/> for a copy.
// }}}
// License: GPL, v3, as defined and found on www.gnu.org,
// {{{
// http://www.gnu.org/licenses/gpl.html
//
////////////////////////////////////////////////////////////////////////////////
//
`default_nettype none
`timescale 1ns/1ps
// }}}
module sdax_mm2s #(
// {{{
parameter ADDRESS_WIDTH = 32,
parameter BUS_WIDTH = 32,
parameter AXI_IW = 1,
//
// AXI_ID is the ID we will use for all of our AXI transactions
parameter [AXI_IW-1:0] AXI_ID = 0,
//
parameter [0:0] OPT_LOWPOWER = 1'b0,
// LGMAXBURST is the log based 2 of the maximum number of
// beats per burst. The maximum ARLEN will then be
// (1<<LGMAXBURST)-1.
parameter LGMAXBURST = 8,
// The size of the FIFO. Should nominally be big enough for
// two bursts.
parameter LGFIFO = LGMAXBURST+1,
//
// The bottom AXILSB bits of any AXI address are subword bits
localparam AXILSB = $clog2(BUS_WIDTH/8),
//
// LGLENGTH: Log based 2 of the maximum number of bytes that
// will ever be transferred in one request
parameter LGLENGTH = AXILSB + LGFIFO + 1
// }}}
) (
// {{{
input wire i_clk,
input wire i_reset,
input wire i_soft_reset,
// Configuration
// {{{
input wire i_request,
output wire o_busy, o_err,
input wire i_inc,
input wire [1:0] i_size,
input wire [LGLENGTH-1:0] i_transferlen,
input wire [ADDRESS_WIDTH-1:0] i_addr, // Byte address
// }}}
// The AXI (full) read interface
// {{{
output wire M_AXI_ARVALID,
input wire M_AXI_ARREADY,
output wire [AXI_IW-1:0] M_AXI_ARID,
output wire [ADDRESS_WIDTH-1:0] M_AXI_ARADDR,
output wire [7:0] M_AXI_ARLEN,
output wire [2:0] M_AXI_ARSIZE,
output wire [1:0] M_AXI_ARBURST,
output wire M_AXI_ARLOCK,
output wire [3:0] M_AXI_ARCACHE,
output wire [2:0] M_AXI_ARPROT,
output wire [3:0] M_AXI_ARQOS,
//
input wire M_AXI_RVALID,
output wire M_AXI_RREADY,
input wire [BUS_WIDTH-1:0] M_AXI_RDATA,
input wire M_AXI_RLAST,
input wire [AXI_IW-1:0] M_AXI_RID,
input wire [1:0] M_AXI_RRESP,
// }}}
// The stream interface
// {{{
output wire M_AXIS_VALID,
input wire M_AXIS_READY,
output wire [BUS_WIDTH-1:0] M_AXIS_DATA,
output wire [AXILSB:0] M_AXIS_BYTES,
output wire M_AXIS_LAST
// }}}
// }}}
);
// Key questions:
// OPT_CONTINUOUS: Do we allow a restart mid-op, or force the
// entire pipeline to flush between operations?
//
// The realignment FIFO, depending on axi_raddr, would struggle
// with such an option.
// Soft resets would force discontinuities in things alread read
// Bus errors might also struggle with such an option, if
// read returns were still in progress
// Signal declarations
// {{{
// Local parameter declarations
// {{{
localparam [1:0] SZ_BYTE = 2'b11,
SZ_16B = 2'b10,
SZ_32B = 2'b01,
SZ_BUS = 2'b00;
localparam LGMAXBURST_LIMIT =$clog2(4096*8/BUS_WIDTH);
localparam LCLMAXBURST = (LGMAXBURST > LGMAXBURST_LIMIT)
? LGMAXBURST_LIMIT : LGMAXBURST;
localparam LGMAX_FIXED_BURST = (LGMAXBURST < 4) ? LGMAXBURST : 4,
MAX_FIXED_BURST = (1<<LGMAX_FIXED_BURST);
localparam LCLMAXBURST_SUB = (LGMAXBURST > 8) ? 8 : LGMAXBURST;
localparam FIFO_WIDTH = 1+(AXILSB+1)+BUS_WIDTH;
localparam FIFO_BYTES = (BUS_WIDTH / 8) * (1<<LGFIFO);
// localparam [AXILSB-1:0] LSBZEROS = 0;
// }}}
reg r_busy, r_inc, r_err, cmd_abort;
reg [1:0] r_size;
reg [2:0] axi_size;
reg [7:0] maxlen;
reg [LGLENGTH-1:0] rawlen, rawbeats, rawbursts,
rawfirstln, rawblkln;
reg [LGLENGTH-1:0] ar_requests_remaining, ar_beats_remaining;
reg ar_none_remaining;
reg ar_none_outstanding;
reg [LGLENGTH-1:0] ar_bursts_outstanding;
// reg rd_none_remaining;
// reg [LGLENGTH:0] rd_reads_remaining;
reg w_complete;
reg start_burst, phantom_start;
reg [LGLENGTH-1:0] ar_next_remaining;
reg [7:0] axi_arlen;
reg [ADDRESS_WIDTH:0] nxt_araddr, axi_araddr;
reg axi_arvalid;
reg [LGLENGTH-1:0] returned_bytes, r_bytes_remaining;
reg [ADDRESS_WIDTH-1:0] axi_raddr;
reg rx_valid, rx_last;
wire rx_ready;
reg [AXILSB:0] rx_bytes;
reg [BUS_WIDTH-1:0] rx_data;
wire gbox_valid, gbox_last;
wire [BUS_WIDTH-1:0] gbox_data;
wire [AXILSB:0] gbox_bytes;
reg [LGLENGTH:0] nxt_commitment, rd_uncommitted;
reg [1:0] rd_ubursts;
wire fifo_full, fifo_empty;
wire [LGFIFO:0] ign_fifo_fill;
`ifdef FORMAL
wire [LGLENGTH:0] fgbox_rcvd, fgbox_sent;
wire [LGFIFO:0] ffif_first_addr, ffif_second_addr;
wire [FIFO_WIDTH-1:0] ffif_first_data, ffif_second_data;
wire ffif_first_in_fifo, ffif_second_in_fifo;
wire [LGFIFO:0] ffif_distance_to_first, ffif_distance_to_second;
wire ffif_first_last, ffif_second_last;
wire [AXILSB:0] ffif_first_bytes, ffif_second_bytes;
`endif
// }}}
////////////////////////////////////////////////////////////////////////
//
// Configuration logic
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// r_busy
// {{{
initial r_busy = 1'b0;
always @(posedge i_clk)
if (i_reset)
r_busy <= 1'b0;
else if (!o_busy && i_request && !i_soft_reset)
r_busy <= 1'b1;
else if (w_complete)
r_busy <= 1'b0;
assign o_busy = r_busy;
// }}}
// r_inc, r_size, axi_size, maxlen
// {{{
always @(posedge i_clk)
if (!o_busy && (!OPT_LOWPOWER || i_request))
begin
r_inc <= i_inc;
r_size <= i_size;
case(i_size)
SZ_BYTE: axi_size <= 3'h0;
SZ_16B: axi_size <= 3'h1;
SZ_32B: axi_size <= 3'h2;
SZ_BUS: axi_size <= AXILSB[2:0];
endcase
if (i_inc)
begin
case(i_size)
SZ_BYTE: maxlen <= (1<<LCLMAXBURST_SUB)-1;
SZ_16B: maxlen <= (1<<LCLMAXBURST_SUB)-1;
SZ_32B: maxlen <= (1<<LCLMAXBURST_SUB)-1;
SZ_BUS: maxlen <= (1<<LCLMAXBURST)-1;
endcase
end else
maxlen <= MAX_FIXED_BURST-1;
end
// }}}
// cmd_abort
// {{{
initial cmd_abort = 1'b0;
always @(posedge i_clk)
if (i_reset)
cmd_abort <= 1'b0;
else if (!o_busy || w_complete)
cmd_abort <= 1'b0;
else begin
if (i_soft_reset)
cmd_abort <= 1'b1;
if (r_inc && nxt_araddr[ADDRESS_WIDTH] && !ar_none_remaining)
cmd_abort <= 1'b1;
if (M_AXI_RVALID && M_AXI_RREADY && M_AXI_RRESP[1])
cmd_abort <= 1'b1;
if (M_AXI_ARVALID && M_AXI_ARREADY && r_inc
&& nxt_araddr[ADDRESS_WIDTH])
cmd_abort <= 1'b1;
end
// }}}
// o_err, r_err
// {{{
always @(posedge i_clk)
if (i_reset)
r_err <= 1'b0;
else if (!o_busy)
r_err <= 1'b0;
else if (M_AXI_RVALID && M_AXI_RREADY && M_AXI_RRESP[1])
r_err <= 1'b1;
assign o_err = r_err;
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// The incoming AXI (full) protocol section
// {{{
////////////////////////////////////////////////////////////////////////
//
//
//
// Some counters to keep track of our state
// {{{
/*
always @(posedge i_clk)
if (!r_busy)
r_pre_start <= 1;
else
r_pre_start <= 0;
*/
always @(*)
begin
// Since we're doing beats of the given size, the
// transfer length must be increased by whatever it
// takes to align ourselves with a truncated word
// (not burst) boundary.
case(i_size)
SZ_BYTE: rawlen = i_transferlen;
// Verilator lint_off WIDTH
SZ_16B: begin
rawlen = i_transferlen + i_addr[ 0] + 1;
rawlen[0] = 1'b0;
end
SZ_32B: begin
rawlen = i_transferlen + i_addr[1:0] + 3;
rawlen[1:0] = 2'b00;
end
SZ_BUS: begin
rawlen = i_transferlen + i_addr[AXILSB-1:0]
+ (1<<AXILSB)-1;
rawlen[AXILSB-1:0] = 0;
end
// Verilator lint_on WIDTH
endcase
case(i_size)
SZ_BYTE: rawbeats = rawlen;
// Verilator lint_off WIDTH
SZ_16B: rawbeats = rawlen >> 1;
SZ_32B: rawbeats = rawlen >> 2;
SZ_BUS: rawbeats = rawlen >> AXILSB;
// Verilator lint_on WIDTH
endcase
case(i_size)
SZ_BYTE: begin
// Verilator lint_off WIDTH
rawblkln = i_transferlen + i_addr[LCLMAXBURST_SUB-1:0];
rawblkln = rawblkln + (1<<LCLMAXBURST_SUB)-1;
end
SZ_16B: begin
rawblkln = i_transferlen + i_addr[LCLMAXBURST_SUB:0];
rawblkln = rawblkln + (2<<LCLMAXBURST_SUB)-1;
end
SZ_32B: begin
rawblkln = i_transferlen + i_addr[LCLMAXBURST_SUB+1:0];
rawblkln = rawblkln + (4<<LCLMAXBURST_SUB)-1;
end
SZ_BUS: begin
rawblkln= i_transferlen +i_addr[LCLMAXBURST+AXILSB-1:0];
rawblkln = rawblkln + (1<<(AXILSB+LCLMAXBURST))-1;
end
// Verilator lint_on WIDTH
endcase
if (i_inc)
begin
case(i_size)
// Verilator lint_off WIDTH
SZ_BYTE: rawbursts = rawblkln >> LCLMAXBURST_SUB;
SZ_16B: rawbursts = rawblkln >> (1+LCLMAXBURST_SUB);
SZ_32B: rawbursts = rawblkln >> (2+LCLMAXBURST_SUB);
SZ_BUS: rawbursts = rawblkln >> (AXILSB+LCLMAXBURST);
endcase
end else
rawbursts = rawbeats[LGLENGTH-1:LGMAX_FIXED_BURST]
+ ((|rawbeats[LGMAX_FIXED_BURST-1:0]) ? 1:0);
// Verilator lint_on WIDTH
if (i_inc)
begin
case(i_size)
// Verilator lint_off WIDTH
SZ_BYTE:rawfirstln = (1<<LCLMAXBURST_SUB)
- i_addr[0+:LCLMAXBURST_SUB]-1;
SZ_16B: rawfirstln = (1<<LCLMAXBURST_SUB)
- i_addr[1+:LCLMAXBURST_SUB]-1;
SZ_32B: rawfirstln = (1<<LCLMAXBURST_SUB)
- i_addr[2+:LCLMAXBURST_SUB]-1;
SZ_BUS: rawfirstln = (1<<LCLMAXBURST)
- i_addr[AXILSB +: LCLMAXBURST]-1;
// Verilator lint_on WIDTH
endcase
end else
rawfirstln = MAX_FIXED_BURST-1;
if (rawfirstln >= rawbeats)
rawfirstln = rawbeats-1;
end
initial ar_none_remaining = 1;
initial ar_requests_remaining = 0;
initial ar_beats_remaining = 0;
always @(posedge i_clk)
if (i_reset || cmd_abort)
begin
ar_requests_remaining <= 0;
ar_beats_remaining <= 0;
ar_none_remaining <= 1;
end else if (!r_busy)
begin
if (!OPT_LOWPOWER || i_request)
begin
ar_requests_remaining <= rawbursts;
ar_beats_remaining <= rawbeats;
ar_none_remaining <= (i_transferlen == 0);
end
end else if (phantom_start)
begin
// Verilator lint_off WIDTH
ar_requests_remaining <= ar_requests_remaining - 1;
ar_beats_remaining <= ar_beats_remaining - M_AXI_ARLEN - 1;
ar_none_remaining <= (ar_requests_remaining <= 1);
// Verilator lint_on WIDTH
end
`ifdef FORMAL
always @(*)
if (!i_reset && r_busy)
assert(ar_none_remaining == (ar_requests_remaining == 0));
always @(*)
if (!i_reset && phantom_start)
assert(M_AXI_ARVALID);
`endif
// }}}
// Count the number of bursts outstanding--these are the number of
// ARVALIDs that have been accepted, but for which the RVALID && RLAST
// has not (yet) been returned.
// {{{
initial ar_none_outstanding = 1;
initial ar_bursts_outstanding = 0;
always @(posedge i_clk)
if (i_reset)
begin
ar_bursts_outstanding <= 0;
ar_none_outstanding <= 1;
end else case ({ phantom_start,
M_AXI_RVALID && M_AXI_RREADY && M_AXI_RLAST })
2'b01: begin
ar_bursts_outstanding <= ar_bursts_outstanding - 1;
ar_none_outstanding <= (ar_bursts_outstanding == 1);
end
2'b10: begin
ar_bursts_outstanding <= ar_bursts_outstanding + 1;
ar_none_outstanding <= 0;
end
default: begin end
endcase
`ifdef FORMAL
always @(*)
if (!i_reset)
assert(ar_none_outstanding == (ar_bursts_outstanding == 0));
`endif
// }}}
// rd_reads_remaining, rd_none_remaining: Are we there yet?
// {{{
// initial rd_reads_remaining = 0;
// initial rd_none_remaining = 1;
// always @(posedge i_clk)
// if (!r_busy)
// begin
// rd_reads_remaining <= rawbeats;
// rd_none_remaining <= (i_transferlen == 0);
// end else if (M_AXI_RVALID && M_AXI_RREADY)
// begin
// rd_reads_remaining <= rd_reads_remaining - 1;
// rd_none_remaining <= (rd_reads_remaining <= 1);
// end
always @(*)
if (!r_busy || !ar_none_outstanding || M_AXI_ARVALID)
w_complete = 0;
else if (cmd_abort)
w_complete = 1;
else
w_complete = //(rd_none_remaining && !M_AXIS_VALID)
// && fifo_empty && !gbox_valid && !rx_valid;
M_AXIS_VALID && M_AXIS_READY && M_AXIS_LAST;
// }}}
// start_burst, phantom_start
// {{{
always @(*)
begin
start_burst = !ar_none_remaining;
if (r_inc && nxt_araddr[ADDRESS_WIDTH])
start_burst = 1'b0;
// Make sure there's room in the FIFO ... must we? YES, WE MUST
if (rd_ubursts == 0)
start_burst = 0;
if (phantom_start) // || r_pre_start)
// Insist on a minimum of one clock between burst
// starts, so we can get our lengths right
start_burst = 0;
if (M_AXI_ARVALID && !M_AXI_ARREADY)
start_burst = 0;
if (!r_busy || cmd_abort)
start_burst = 0;
end
initial phantom_start = 0;
always @(posedge i_clk)
if (i_reset)
phantom_start <= 0;
else
phantom_start <= start_burst;
// }}}
// Calculate ARLEN for the next ARVALID
// {{{
always @(*)
begin
ar_next_remaining = ar_beats_remaining;
if (phantom_start)
// Verilator lint_off WIDTH
ar_next_remaining = ar_next_remaining - (M_AXI_ARLEN+1);
// Verilator lint_on WIDTH
end
always @(posedge i_clk)
if (!r_busy)
axi_arlen <= rawfirstln[7:0];
else if (M_AXI_ARVALID && M_AXI_ARREADY)
begin
// Verilator lint_off WIDTH
if (maxlen < ar_next_remaining)
// Verilator lint_on WIDTH
axi_arlen <= maxlen;
else
axi_arlen <= ar_next_remaining[7:0]-1;
end
// }}}
// Calculate ARADDR for the next ARVALID
// {{{
always @(*)
begin
nxt_araddr = 0;
case(r_size)
// Verilator lint_off WIDTH
SZ_BYTE: nxt_araddr = axi_araddr + (M_AXI_ARLEN + 1);
SZ_16B: nxt_araddr[ADDRESS_WIDTH:1]
= axi_araddr[ADDRESS_WIDTH-1:1]
+ (M_AXI_ARLEN + 1);
SZ_32B: nxt_araddr[ADDRESS_WIDTH:2]
= axi_araddr[ADDRESS_WIDTH-1:2]
+ (M_AXI_ARLEN + 1);
SZ_BUS: nxt_araddr[ADDRESS_WIDTH:AXILSB]
= axi_araddr[ADDRESS_WIDTH-1:AXILSB]
+ (M_AXI_ARLEN + 1);
// Verilator lint_on WIDTH
endcase
if (!r_busy || !r_inc || !M_AXI_ARVALID)
nxt_araddr = axi_araddr;
end
initial axi_araddr = 0;
always @(posedge i_clk)
begin
if (M_AXI_ARVALID && M_AXI_ARREADY && r_inc)
axi_araddr <= nxt_araddr;
if (!r_busy)
begin
axi_araddr <= { 1'b0, i_addr };
if (!i_inc)
case(i_size)
SZ_BYTE: begin end
SZ_16B: axi_araddr[0] <= 0;
SZ_32B: axi_araddr[1:0] <= 0;
SZ_BUS: axi_araddr[AXILSB-1:0] <= 0;
endcase
if (OPT_LOWPOWER && !i_request)
axi_araddr <= 0;
end
end
// }}}
// ARVALID
// {{{
initial axi_arvalid = 0;
always @(posedge i_clk)
if (i_reset)
axi_arvalid <= 0;
else if (!M_AXI_ARVALID || M_AXI_ARREADY)
axi_arvalid <= start_burst;
// }}}
// Assignments to the actual M_AXI_* signals
// {{{
assign M_AXI_ARVALID= axi_arvalid;
assign M_AXI_ARID = AXI_ID;
assign M_AXI_ARADDR = axi_araddr[ADDRESS_WIDTH-1:0];
assign M_AXI_ARLEN = axi_arlen;
// Verilator lint_off WIDTH
assign M_AXI_ARSIZE = axi_size;
// Verilator lint_on WIDTH
assign M_AXI_ARBURST= { 1'b0, r_inc };
assign M_AXI_ARLOCK = 0;
assign M_AXI_ARCACHE= 4'b0011;
assign M_AXI_ARPROT = 0;
assign M_AXI_ARQOS = 0;
// We could try to be fancy here, but actually ... we're guaranteeing
// via the gearbox and FIFO that we'll never request data we don't
// have room for. Hence, we can simplify our calculation and just
// hold RREADY low.
assign M_AXI_RREADY = 1'b1;
// assign M_AXI_RREADY = (!rx_valid || ign_rx_ready);
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// RX Gears
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// returned_bytes
// {{{
// Bytes returned this clock cycle -- if RVALID && RREADY true
always @(*)
case(r_size)
SZ_BYTE: returned_bytes = 1;
// Verilator lint_off WIDTH
SZ_16B: if (r_bytes_remaining >= 2 - axi_raddr[0])
returned_bytes = 2 - axi_raddr[0];
else
returned_bytes = r_bytes_remaining;
SZ_32B: if (r_bytes_remaining >= 4 - axi_raddr[1:0])
returned_bytes = 4 - axi_raddr[1:0];
else
returned_bytes = r_bytes_remaining;
SZ_BUS: if (r_bytes_remaining >= (1<<AXILSB)
- axi_raddr[AXILSB-1:0])
returned_bytes = (1<<AXILSB)
- axi_raddr[AXILSB-1:0];
else
returned_bytes = r_bytes_remaining;
// Verilator lint_on WIDTH
endcase
// }}}
// r_bytes_remaining
// {{{
always @(posedge i_clk)
if (!r_busy && (!OPT_LOWPOWER || i_request))
r_bytes_remaining <= i_transferlen;
else if (M_AXI_RVALID && M_AXI_RREADY)
r_bytes_remaining <= r_bytes_remaining - returned_bytes;
// }}}
// axi_raddr
// {{{
initial axi_raddr = 0;
always @(posedge i_clk)
begin
if (M_AXI_RVALID && M_AXI_RREADY)
begin
if (r_inc)
begin
case(r_size)
SZ_BYTE: axi_raddr <= axi_raddr + 1;
SZ_16B: begin
axi_raddr <= axi_raddr + 2;
axi_raddr[0] <= 1'b0;
end
SZ_32B: begin
axi_raddr <= axi_raddr + 4;
axi_raddr[1:0] <= 2'b0;
end
SZ_BUS: begin
axi_raddr <= axi_raddr + (1<<AXILSB);
axi_raddr[AXILSB-1:0] <= {(AXILSB){1'b0}};
end
endcase
end else begin
case(r_size)
SZ_BYTE: begin end
SZ_16B: axi_raddr[0] <= 1'b0;
SZ_32B: axi_raddr[1:0] <= 2'b0;
SZ_BUS: axi_raddr[AXILSB-1:0] <= {(AXILSB){1'b0}};
endcase
end
end
if (!r_busy)
begin
axi_raddr <= i_addr;
/*
if (i_inc)
axi_raddr <= i_addr;
else case(i_size)
SZ_BYTE: axi_raddr <= i_addr;
SZ_16B: axi_raddr<= { i_addr[ADDRESS_WIDTH-1:1], 1'b0 };
SZ_32B: axi_raddr<= { i_addr[ADDRESS_WIDTH-1:2], 2'b0 };
SZ_BUS: axi_raddr<= { i_addr[ADDRESS_WIDTH-1:AXILSB],
{(AXILSB){1'b0}} };
endcase
*/
end
end
// }}}
// rx_valid
// {{{
// Realign the data before releasing it (to the external FIFO)
initial rx_valid = 1'b0;
always @(posedge i_clk)
if(i_reset || cmd_abort || i_soft_reset)
rx_valid <= 0;
else if (M_AXI_RVALID && M_AXI_RREADY)
rx_valid <= !M_AXI_RRESP[1];
else if (rx_ready)
rx_valid <= 0;
// }}}
// rx_data
// {{{
always @(posedge i_clk)
if (M_AXI_RVALID && M_AXI_RREADY)
rx_data <= M_AXI_RDATA >> (8*axi_raddr[AXILSB-1:0]);
// }}}
// rx_bytes
// {{{
always @(posedge i_clk)
if (M_AXI_RVALID && M_AXI_RREADY)
begin
if (returned_bytes[AXILSB])
rx_bytes <= (1<<AXILSB);
else
rx_bytes <= {1'b0,returned_bytes[AXILSB-1:0]};
end
// }}}
// rx_last
// {{{
always @(posedge i_clk)
if (M_AXI_RVALID && M_AXI_RREADY)
rx_last <= (returned_bytes >= r_bytes_remaining);
// }}}
sddma_rxgears #(
.BUS_WIDTH(BUS_WIDTH),
.OPT_LITTLE_ENDIAN(1'b1) // AXI is always little endian
`ifdef FORMAL
, .F_LGCOUNT(LGLENGTH+1)
`endif
) u_rxgears (
// {{{
.i_clk(i_clk), .i_reset(i_reset), .i_soft_reset(cmd_abort),
//
.S_VALID(rx_valid), .S_READY(rx_ready),
.S_DATA(rx_data), .S_BYTES(rx_bytes), .S_LAST(rx_last),
//
.M_VALID(gbox_valid), .M_READY(1'b1 || !fifo_full),
.M_DATA(gbox_data), .M_BYTES(gbox_bytes),
.M_LAST(gbox_last)
`ifdef FORMAL
, .f_rcvd(fgbox_rcvd), .f_sent(fgbox_sent)
`endif
// }}}
);
// }}}
////////////////////////////////////////////////////////////////////////
//
// Data FIFO / Outgoing stream
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// nxt_commitment
// {{{
always @(*)
begin
// Verilator lint_off WIDTH
case(r_size)
SZ_BYTE: nxt_commitment = M_AXI_ARLEN+1;
SZ_16B: nxt_commitment = ((M_AXI_ARLEN+1) << 1);
SZ_32B: nxt_commitment = ((M_AXI_ARLEN+1) << 2);
SZ_BUS: nxt_commitment = ((M_AXI_ARLEN+1) << AXILSB);
endcase
// Verilator lint_on WIDTH
end
// }}}
// rd_uncommitted (units: bytes)
// {{{
// Verilator lint_off WIDTH
initial rd_uncommitted = FIFO_BYTES;
always @(posedge i_clk)
if (i_reset || !r_busy || cmd_abort || i_soft_reset
|| (M_AXIS_VALID && M_AXIS_READY && M_AXIS_LAST))
rd_uncommitted <= FIFO_BYTES;
else case({ phantom_start, M_AXIS_VALID && M_AXIS_READY })
2'b00: begin end
2'b01: rd_uncommitted <= rd_uncommitted + (BUS_WIDTH/8);
2'b10: rd_uncommitted <= rd_uncommitted - nxt_commitment;
2'b11: rd_uncommitted <= rd_uncommitted + (BUS_WIDTH/8)
- nxt_commitment;
endcase
// Verilator lint_on WIDTH
// }}}
// rd_ubursts: Two bits, first bit indicates 2+ bursts can be made,
// {{{
// LSB indicates at least one burst can be made.
initial rd_ubursts = 2'b11;
always @(posedge i_clk)
if (i_reset || cmd_abort || i_soft_reset
|| (M_AXIS_VALID && M_AXIS_READY && M_AXIS_LAST))
rd_ubursts <= 2'b11;
else begin
if (r_inc)
begin
case(r_size)
SZ_BYTE: rd_ubursts <= { (rd_uncommitted >= 2<<LCLMAXBURST_SUB),
(rd_uncommitted >= 1<<LCLMAXBURST_SUB) };
SZ_16B: rd_ubursts <= { (rd_uncommitted >= 4<<LCLMAXBURST_SUB),
(rd_uncommitted >= 2<<LCLMAXBURST_SUB) };
// Verilator lint_off WIDTH
SZ_32B: rd_ubursts <= { (rd_uncommitted >= 8<<LCLMAXBURST_SUB),
(rd_uncommitted >= 4<<LCLMAXBURST_SUB) };
SZ_BUS: rd_ubursts <= {
(rd_uncommitted >= 2 * BUS_WIDTH/8
* (1<<LCLMAXBURST)),
(rd_uncommitted >= BUS_WIDTH/8
* (1<<LCLMAXBURST))
};
// Verilator lint_on WIDTH
endcase
end else begin
// Verilator lint_off WIDTH
case(r_size)
SZ_BYTE: rd_ubursts <= { (rd_uncommitted >= 32),
(rd_uncommitted >= 16) };
SZ_16B: rd_ubursts <= { (rd_uncommitted >= 64),
(rd_uncommitted >= 32) };
SZ_32B: rd_ubursts <= { (rd_uncommitted >= 128),
(rd_uncommitted >= 64) };
SZ_BUS: rd_ubursts <= { (rd_uncommitted >= (BUS_WIDTH*4)),
(rd_uncommitted >= (BUS_WIDTH*2)) };
// Verilator lint_on WIDTH
endcase
end
if (phantom_start)
rd_ubursts[0] <= 1'b0;
end
// }}}
sdfifo #(
// {{{
.BW(FIFO_WIDTH), .LGFLEN(LGFIFO),
.OPT_ASYNC_READ(1'b0),
.OPT_WRITE_ON_FULL(1'b0),
.OPT_READ_ON_EMPTY(1'b0)
// }}}
) u_fifo (
// {{{
.i_clk(i_clk), .i_reset(i_reset || cmd_abort),
//
.i_wr(gbox_valid),
.i_data({ gbox_last, gbox_bytes, gbox_data }),
.o_full(fifo_full), .o_fill(ign_fifo_fill),
.i_rd(M_AXIS_READY),
.o_data({ M_AXIS_LAST, M_AXIS_BYTES, M_AXIS_DATA }),
.o_empty(fifo_empty)
`ifdef FORMAL
, .f_first_addr(ffif_first_addr),
.f_second_addr(ffif_second_addr),
.f_first_data(ffif_first_data),
.f_second_data(ffif_second_data),
.f_first_in_fifo(ffif_first_in_fifo),
.f_second_in_fifo(ffif_second_in_fifo),
.f_distance_to_first(ffif_distance_to_first),
.f_distance_to_second(ffif_distance_to_second)
`endif
// }}}
);
assign M_AXIS_VALID = !fifo_empty;
`ifdef FORMAL
assign ffif_first_last = ffif_first_data[FIFO_WIDTH-1];
assign ffif_second_last = ffif_second_data[FIFO_WIDTH-1];
assign ffif_first_bytes = ffif_first_data[BUS_WIDTH +: AXILSB+1];
assign ffif_second_bytes = ffif_second_data[BUS_WIDTH +: AXILSB+1];
`endif
// }}}
// Keep Verilator happy
// {{{
// Verilator coverage_off
// Verilator lint_off UNUSED
wire unused;
assign unused = &{ 1'b0, M_AXI_RID, M_AXI_RRESP[0], ign_fifo_fill
};
// Verilator coverage_on
// Verilator lint_on UNUSED
// }}}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Formal properties
// {{{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
`ifdef FORMAL
reg f_past_valid;
reg [LGLENGTH:0] ftot_beats, frx_beats, ftot_bursts, frx_bursts,
fbeat_count, fburst_count;
reg [ADDRESS_WIDTH:0] frx_addr, flast_addr;
reg [ADDRESS_WIDTH:0] far_pages, far_starting_page,
far_ending_page;
reg f_bkfirst; // f_cklast;
reg [ADDRESS_WIDTH-1:0] f_bkaddr, f_eob;
reg f_ckfirst, f_cklast;
reg [ADDRESS_WIDTH-1:0] f_ckaddr, f_ckeob;
(* anyconst *) reg fc_inc;
(* anyconst *) reg [1:0] fc_size;
(* anyconst *) reg [LGLENGTH:0] fc_transferlen;
(* anyconst *) reg [ADDRESS_WIDTH-1:0] fc_addr;
reg [LGLENGTH:0] f_committed, faxis_beats, ftot_count;
reg ffif_assume_result, fgbox_rcvd_valid;
initial f_past_valid = 0;
always @(posedge i_clk)
f_past_valid <= 1;
always @(*)
if (!f_past_valid)
assume(i_reset);
////////////////////////////////////////////////////////////////////////
//
// Properties of the AXI-stream data interface
// {{{
//
////////////////////////////////////////////////////////////////////////
//
//
// (These are captured by the FIFO within)
// }}}
////////////////////////////////////////////////////////////////////////
//
// The control interface
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(*)
begin
assume(fc_transferlen != 0);
assume(fc_transferlen <= (1<<LGLENGTH));
end
always @(*)
if (i_request && !o_busy)
begin
assume(i_inc == fc_inc);
assume(i_size == fc_size);
assume(i_transferlen == fc_transferlen);
assume(i_addr == fc_addr);
end else if (!i_reset && o_busy)
begin
assert(r_inc == fc_inc);
assert(r_size == fc_size);
if (r_inc)
assert(cmd_abort || (ar_none_remaining && axi_araddr == 0) || axi_araddr >= fc_addr);
else case(r_size)
SZ_BYTE: assert(axi_araddr == fc_addr);
SZ_16B: assert(axi_araddr == { fc_addr[ADDRESS_WIDTH-1:1], 1'b0 });
SZ_32B: assert(axi_araddr == { fc_addr[ADDRESS_WIDTH-1:2], 2'b00 });
SZ_BUS: assert(axi_araddr == { fc_addr[ADDRESS_WIDTH-1:AXILSB], {(AXILSB){1'b0}} });
endcase
case(r_size)
SZ_BYTE: assert(M_AXI_ARSIZE == 3'h0);
SZ_16B: assert(M_AXI_ARSIZE == 3'h1);
SZ_32B: assert(M_AXI_ARSIZE == 3'h2);
SZ_BUS: assert(M_AXI_ARSIZE == AXILSB);
endcase
end