-
Notifications
You must be signed in to change notification settings - Fork 100
/
axidma.v
2977 lines (2651 loc) · 73.4 KB
/
axidma.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: axidma.v
// {{{
// Project: WB2AXIPSP: bus bridges and other odds and ends
//
// Purpose: To move memory from one location to another, at high speed.
// This is not a memory to stream, nor a stream to memory core,
// but rather a memory to memory core.
//
//
// Registers:
//
// 0. Control
// 8b KEY
// 3'b PROT
// 4'b QOS
// 1b Abort: Either aborting or aborted
// 1b Err: Ended on an error
// 1b Busy
// 1b Interrupt Enable
// 1b Interrupt Clear
// 1b Start
// 1. Unused
// 2-3. Source address, low and then high 64-bit words
// (Last value read address)
// 4-5. Destination address, low and then high 64-bit words
// (Next value to write address)
// 6-7. Length, low and then high words
// (Total number minus successful writes)
//
// Performance goals:
// 100% throughput
// Stay off the bus until you can drive it hard
// Other goals:
// Be both AXI3 and AXI4 capable
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
// }}}
// Copyright (C) 2020-2024, Gisselquist Technology, LLC
// {{{
// This file is part of the WB2AXIP project.
//
// The WB2AXIP project contains free software and gateware, licensed under the
// Apache License, Version 2.0 (the "License"). You may not use this project,
// or this file, except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
//
////////////////////////////////////////////////////////////////////////////////
//
//
`default_nettype none
// `define AXI3
// }}}
module axidma #(
// {{{
parameter C_AXI_ID_WIDTH = 1,
parameter C_AXI_ADDR_WIDTH = 32,
parameter C_AXI_DATA_WIDTH = 32,
//
// These two "parameters" really aren't things that can be
// changed externally. They control the size of the AXI4-lite
// port. Internally, it's defined to have 8, 32-bit registers.
// The registers are configured wide enough to support 64-bit
// AXI addressing. Similarly, the AXI-lite data width is fixed
// at 32-bits.
localparam C_AXIL_ADDR_WIDTH = 5,
localparam C_AXIL_DATA_WIDTH = 32,
//
// OPT_UNALIGNED turns on support for unaligned addresses,
// whether source, destination, or length parameters.
parameter [0:0] OPT_UNALIGNED = 1'b1,
//
// OPT_WRAPMEM controls what happens if the transfer runs off
// of the end of memory. If set, the transfer will continue
// again from the beginning of memory. If clear, the transfer
// will be aborted with an error if either read or write
// address ever get this far.
parameter [0:0] OPT_WRAPMEM = 1'b1,
//
// LGMAXBURST controls the size of the maximum burst produced
// by this core. Specifically, its the log (based 2) of that
// maximum size. Hence, for AXI4, this size must be 8
// (i.e. 2^8 or 256 beats) or less. For AXI3, the size must
// be 4 or less. Tests have verified performance for
// LGMAXBURST as low as 2. While I expect it to fail at
// LGMAXBURST=0, I haven't verified at what value this burst
// parameter is too small.
`ifdef AXI3
parameter LGMAXBURST=4, // 16 beats max
`else
parameter LGMAXBURST=8, // 256 beats
`endif
// LGFIFO: This is the (log-based-2) size of the internal FIFO.
// Hence if LGFIFO=8, the internal FIFO will have 256 elements
// (words) in it. High throughput transfers are accomplished
// by first storing data into a FIFO, then once a full burst
// size is available bursting that data over the bus. In
// order to be able to keep receiving data while bursting it
// out, the FIFO size must be at least twice the size of the
// maximum burst size. Larger sizes are possible as well.
parameter LGFIFO = LGMAXBURST+1, // 512 element FIFO
//
// LGLEN: specifies the number of bits in the transfer length
// register. If a transfer cannot be specified in LGLEN bits,
// it won't happen. LGLEN must be less than or equal to the
// address width.
parameter LGLEN = C_AXI_ADDR_WIDTH,
//
// OPT_LOWPOWER:
parameter [0:0] OPT_LOWPOWER = 1'b0,
//
// OPT_CLKGATE:
parameter [0:0] OPT_CLKGATE = OPT_LOWPOWER,
//
// AXI uses ID's to transfer information. This core rather
// ignores them. Instead, it uses a constant ID for all
// transfers. The following two parameters control that ID.
parameter [C_AXI_ID_WIDTH-1:0] AXI_READ_ID = 0,
parameter [C_AXI_ID_WIDTH-1:0] AXI_WRITE_ID = 0,
//
// The "ABORT_KEY" is a byte that, if written to the control
// word while the core is running, will cause the data transfer
// to be aborted.
parameter [7:0] ABORT_KEY = 8'h6d,
//
localparam ADDRLSB= $clog2(C_AXI_DATA_WIDTH)-3,
localparam AXILLSB= $clog2(C_AXIL_DATA_WIDTH)-3,
localparam LGLENW= LGLEN-ADDRLSB
// }}}
) (
// {{{
input wire S_AXI_ACLK,
input wire S_AXI_ARESETN,
// AXI low-power interface
// {{{
// This has been removed, due to a lack of definition from the
// AXI standard for these wires.
// }}}
//
// The AXI4-lite control interface
// {{{
input wire S_AXIL_AWVALID,
output wire S_AXIL_AWREADY,
input wire [C_AXIL_ADDR_WIDTH-1:0] S_AXIL_AWADDR,
input wire [2:0] S_AXIL_AWPROT,
//
input wire S_AXIL_WVALID,
output wire S_AXIL_WREADY,
input wire [C_AXIL_DATA_WIDTH-1:0] S_AXIL_WDATA,
input wire [C_AXIL_DATA_WIDTH/8-1:0] S_AXIL_WSTRB,
//
output reg S_AXIL_BVALID,
input wire S_AXIL_BREADY,
output wire [1:0] S_AXIL_BRESP,
//
input wire S_AXIL_ARVALID,
output wire S_AXIL_ARREADY,
input wire [C_AXIL_ADDR_WIDTH-1:0] S_AXIL_ARADDR,
input wire [2:0] S_AXIL_ARPROT,
//
output reg S_AXIL_RVALID,
input wire S_AXIL_RREADY,
output reg [C_AXIL_DATA_WIDTH-1:0] S_AXIL_RDATA,
output wire [1:0] S_AXIL_RRESP,
// }}}
// The AXI Master (DMA) interface
// {{{
output reg M_AXI_AWVALID,
input wire M_AXI_AWREADY,
output reg [C_AXI_ID_WIDTH-1:0] M_AXI_AWID,
output reg [C_AXI_ADDR_WIDTH-1:0] M_AXI_AWADDR,
`ifdef AXI3
output reg [3:0] M_AXI_AWLEN,
`else
output reg [7:0] M_AXI_AWLEN,
`endif
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_WVALID,
input wire M_AXI_WREADY,
`ifdef AXI3
output reg [C_AXI_ID_WIDTH-1:0] M_AXI_WID,
`endif
output reg [C_AXI_DATA_WIDTH-1:0] M_AXI_WDATA,
output reg [C_AXI_DATA_WIDTH/8-1:0] M_AXI_WSTRB,
output reg M_AXI_WLAST,
//
//
input wire M_AXI_BVALID,
output reg M_AXI_BREADY,
input wire [C_AXI_ID_WIDTH-1:0] M_AXI_BID,
input wire [1:0] M_AXI_BRESP,
//
//
output reg M_AXI_ARVALID,
input wire M_AXI_ARREADY,
output wire [C_AXI_ID_WIDTH-1:0] M_AXI_ARID,
output reg [C_AXI_ADDR_WIDTH-1:0] M_AXI_ARADDR,
`ifdef AXI3
output reg [3:0] M_AXI_ARLEN,
`else
output reg [7:0] M_AXI_ARLEN,
`endif
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 [C_AXI_ID_WIDTH-1:0] M_AXI_RID,
input wire [C_AXI_DATA_WIDTH-1:0] M_AXI_RDATA,
input wire M_AXI_RLAST,
input wire [1:0] M_AXI_RRESP,
// }}}
output reg o_int
// }}}
);
// Local declarations
// {{{
// The number of beats in this maximum burst size is
// automatically determined from LGMAXBURST, and so its
// forced to be a power of two this way.
localparam MAXBURST=(1<<LGMAXBURST);
//
localparam [2:0] CTRL_ADDR = 3'b000,
// UNUSED_ADDR = 3'b001,
SRCLO_ADDR = 3'b010,
SRCHI_ADDR = 3'b011,
DSTLO_ADDR = 3'b100,
DSTHI_ADDR = 3'b101,
LENLO_ADDR = 3'b110,
LENHI_ADDR = 3'b111;
localparam CTRL_START_BIT = 0,
CTRL_BUSY_BIT = 0,
CTRL_INT_BIT = 1,
CTRL_INTEN_BIT = 2,
CTRL_ABORT_BIT = 3,
CTRL_ERR_BIT = 4;
localparam [1:0] AXI_INCR = 2'b01, AXI_OKAY = 2'b00;
wire gated_clk, clk_active;
wire i_clk = gated_clk;
wire i_reset = !S_AXI_ARESETN;
reg axil_write_ready, axil_read_ready;
reg [2*C_AXIL_DATA_WIDTH-1:0] wide_src, wide_dst, wide_len;
reg [2*C_AXIL_DATA_WIDTH-1:0] new_widesrc, new_widedst, new_widelen;
reg r_busy, r_err, r_abort, w_start, r_int, r_int_enable,
r_done, last_write_ack, zero_len;
reg [3:0] r_qos;
reg [2:0] r_prot;
reg [LGLEN-1:0] r_len; // Length of transfer in octets
reg [C_AXI_ADDR_WIDTH-1:0] r_src_addr, r_dst_addr;
reg fifo_reset;
wire [LGFIFO:0] fifo_fill;
reg [LGFIFO:0] fifo_space_available;
reg [LGFIFO:0] fifo_data_available,
next_fifo_data_available;
wire fifo_full, fifo_empty;
reg [8:0] write_count;
//
reg phantom_read, w_start_read,
no_read_bursts_outstanding;
reg [LGLEN:0] readlen_b;
reg [LGLENW:0] readlen_w, initial_readlen_w;
reg [C_AXI_ADDR_WIDTH:0] read_address;
reg [LGLENW:0] reads_remaining_w,
read_beats_remaining_w,
read_bursts_outstanding;
reg [C_AXI_ADDR_WIDTH-1:0] read_distance_to_boundary_b;
reg reads_remaining_nonzero;
//
reg phantom_write, w_write_start;
reg [C_AXI_ADDR_WIDTH:0] write_address;
reg [LGLENW:0] writes_remaining_w,
write_bursts_outstanding;
reg [LGLENW:0] write_burst_length;
reg write_requests_remaining;
reg [LGLEN:0] writelen_b;
reg [LGLENW:0] write_beats_remaining;
wire awskd_valid;
wire [C_AXIL_ADDR_WIDTH-AXILLSB-1:0] awskd_addr;
wire wskd_valid;
wire [C_AXIL_DATA_WIDTH-1:0] wskd_data;
wire [C_AXIL_DATA_WIDTH/8-1:0] wskd_strb;
wire arskd_valid;
wire [C_AXIL_ADDR_WIDTH-AXILLSB-1:0] arskd_addr;
//
reg r_partial_in_valid;
reg r_write_fifo, r_read_fifo;
reg r_partial_outvalid;
reg [C_AXI_DATA_WIDTH/8-1:0] r_first_wstrb,
r_last_wstrb;
reg extra_realignment_write,
extra_realignment_read;
reg [2*ADDRLSB+2:0] write_realignment;
reg last_read_beat;
reg clear_read_pipeline;
reg last_write_burst;
//
// Push some write length calculations across clocks
reg [LGLENW:0] w_writes_remaining_w;
reg multiple_write_bursts_remaining,
first_write_burst;
reg [LGMAXBURST:0] initial_write_distance_to_boundary_w,
first_write_len_w;
// }}}
////////////////////////////////////////////////////////////////////////
//
// AXI-Lite control interface
// {{{
////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
//
// AXI-lite control write interface
// {{{
skidbuffer #(.OPT_OUTREG(0), .DW(C_AXIL_ADDR_WIDTH-AXILLSB))
axilawskid(//
.i_clk(S_AXI_ACLK), .i_reset(i_reset),
.i_valid(S_AXIL_AWVALID), .o_ready(S_AXIL_AWREADY),
.i_data(S_AXIL_AWADDR[C_AXIL_ADDR_WIDTH-1:AXILLSB]),
.o_valid(awskd_valid), .i_ready(axil_write_ready),
.o_data(awskd_addr));
skidbuffer #(.OPT_OUTREG(0), .DW(C_AXIL_DATA_WIDTH+C_AXIL_DATA_WIDTH/8))
axilwskid(//
.i_clk(S_AXI_ACLK), .i_reset(i_reset),
.i_valid(S_AXIL_WVALID), .o_ready(S_AXIL_WREADY),
.i_data({ S_AXIL_WSTRB, S_AXIL_WDATA }),
.o_valid(wskd_valid), .i_ready(axil_write_ready),
.o_data({ wskd_strb, wskd_data }));
always @(*)
begin
axil_write_ready = !S_AXIL_BVALID || S_AXIL_BREADY;
if (!awskd_valid || !wskd_valid)
axil_write_ready = 0;
if (!clk_active)
axil_write_ready = 0;
end
initial S_AXIL_BVALID = 1'b0;
always @(posedge i_clk)
if (i_reset)
S_AXIL_BVALID <= 1'b0;
else if (!S_AXIL_BVALID || S_AXIL_BREADY)
S_AXIL_BVALID <= axil_write_ready;
assign S_AXIL_BRESP = AXI_OKAY;
always @(*)
begin
w_start = !r_busy && axil_write_ready && wskd_strb[0]
&& wskd_data[CTRL_START_BIT]
&& (awskd_addr == CTRL_ADDR);
if (r_err && (!wskd_strb[0] || !wskd_data[CTRL_ERR_BIT]))
w_start = 0;
if (zero_len)
w_start = 0;
end
always @(posedge i_clk)
if (i_reset)
r_err <= 1'b0;
else if (!r_busy && axil_write_ready)
r_err <= (r_err) && (!wskd_strb[0] || !wskd_data[CTRL_ERR_BIT]);
else if (r_busy)
begin
if (M_AXI_BVALID && M_AXI_BRESP[1])
r_err <= 1'b1;
if (M_AXI_RVALID && M_AXI_RRESP[1])
r_err <= 1'b1;
if (!OPT_WRAPMEM && write_address[C_AXI_ADDR_WIDTH]
&& write_requests_remaining)
r_err <= 1'b1;
if (!OPT_WRAPMEM && read_address[C_AXI_ADDR_WIDTH]
&& reads_remaining_nonzero)
r_err <= 1'b1;
end
initial r_busy = 1'b0;
always @(posedge i_clk)
if (i_reset)
r_busy <= 1'b0;
else if (!r_busy && axil_write_ready)
r_busy <= w_start;
else if (r_busy)
begin
if (M_AXI_BVALID && M_AXI_BREADY && last_write_ack)
r_busy <= 1'b0;
if (r_done)
r_busy <= 1'b0;
end
always @(posedge i_clk)
if (i_reset || !r_int_enable || !r_busy)
o_int <= 0;
else if (r_done)
o_int <= 1'b1;
else
o_int <= (last_write_ack && M_AXI_BVALID && M_AXI_BREADY);
always @(posedge i_clk)
if (i_reset)
r_int <= 0;
else if (!r_busy)
begin
if (axil_write_ready && awskd_addr == CTRL_ADDR
&& wskd_strb[0])
begin
if (wskd_data[CTRL_START_BIT])
r_int <= 0;
else if (wskd_data[CTRL_INT_BIT])
r_int <= 0;
end
end else if (r_done)
r_int <= 1'b1;
else
r_int <= (last_write_ack && M_AXI_BVALID && M_AXI_BREADY);
initial r_abort = 0;
always @(posedge i_clk)
if (i_reset)
r_abort <= 1'b0;
else if (!r_busy)
begin
if (axil_write_ready && awskd_addr == CTRL_ADDR
&& wskd_strb[0])
begin
if(wskd_data[CTRL_START_BIT]
||wskd_data[CTRL_ABORT_BIT]
||wskd_data[CTRL_ERR_BIT])
r_abort <= 0;
end
end else if (!r_abort)
r_abort <= (axil_write_ready && awskd_addr == CTRL_ADDR)
&&(wskd_strb[3] && wskd_data[31:24] == ABORT_KEY);
wire [C_AXIL_DATA_WIDTH-1:0] newsrclo, newsrchi,
newdstlo, newdsthi, newlenlo, newlenhi;
always @(*)
begin
wide_src = 0;
wide_dst = 0;
wide_len = 0;
wide_src[C_AXI_ADDR_WIDTH-1:0] = r_src_addr;
wide_dst[C_AXI_ADDR_WIDTH-1:0] = r_dst_addr;
wide_len[LGLEN-1:0] = r_len;
if (!OPT_UNALIGNED)
begin
wide_src[ADDRLSB-1:0] = 0;
wide_dst[ADDRLSB-1:0] = 0;
wide_len[ADDRLSB-1:0] = 0;
end
end
assign newsrclo = apply_wstrb(
wide_src[C_AXIL_DATA_WIDTH-1:0],
wskd_data, wskd_strb);
assign newsrchi = apply_wstrb(
wide_src[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH],
wskd_data, wskd_strb);
assign newdstlo = apply_wstrb(
wide_dst[C_AXIL_DATA_WIDTH-1:0],
wskd_data, wskd_strb);
assign newdsthi = apply_wstrb(
wide_dst[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH],
wskd_data, wskd_strb);
assign newlenlo = apply_wstrb(
wide_len[C_AXIL_DATA_WIDTH-1:0],
wskd_data, wskd_strb);
assign newlenhi = apply_wstrb(
wide_len[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH],
wskd_data, wskd_strb);
always @(*)
begin
new_widesrc = wide_src;
new_widedst = wide_dst;
new_widelen = wide_len;
if (!awskd_addr[0])
begin
new_widesrc[C_AXIL_DATA_WIDTH-1:0] = newsrclo;
new_widedst[C_AXIL_DATA_WIDTH-1:0] = newdstlo;
new_widelen[C_AXIL_DATA_WIDTH-1:0] = newlenlo;
end else begin
new_widesrc[2*C_AXIL_DATA_WIDTH-1
:C_AXIL_DATA_WIDTH] = newsrchi;
new_widedst[2*C_AXIL_DATA_WIDTH-1
:C_AXIL_DATA_WIDTH] = newdsthi;
new_widelen[2*C_AXIL_DATA_WIDTH-1
:C_AXIL_DATA_WIDTH] = newlenhi;
end
new_widesrc[2*C_AXIL_DATA_WIDTH-1:C_AXI_ADDR_WIDTH] = 0;
new_widedst[2*C_AXIL_DATA_WIDTH-1:C_AXI_ADDR_WIDTH] = 0;
new_widelen[2*C_AXIL_DATA_WIDTH-1:LGLEN] = 0;
if (!OPT_UNALIGNED)
begin
new_widesrc[ADDRLSB-1:0] = 0;
new_widedst[ADDRLSB-1:0] = 0;
new_widelen[ADDRLSB-1:0] = 0;
end
end
initial r_len = 0;
initial zero_len = 1;
initial r_src_addr = 0;
initial r_dst_addr = 0;
always @(posedge i_clk)
if (i_reset)
begin
// {{{
r_len <= 0;
zero_len <= 1;
r_prot <= 0;
r_qos <= 0;
r_src_addr <= 0;
r_dst_addr <= 0;
r_int_enable <= 0;
// }}}
end else if (!r_busy && axil_write_ready)
begin
// {{{
case(awskd_addr)
CTRL_ADDR: begin
if (wskd_strb[2])
begin
r_prot <= wskd_data[22:20];
r_qos <= wskd_data[19:16];
end
if (wskd_strb[0])
r_int_enable <= wskd_data[CTRL_INTEN_BIT];
end
SRCLO_ADDR: begin
r_src_addr <= new_widesrc[C_AXI_ADDR_WIDTH-1:0];
end
SRCHI_ADDR: if (C_AXI_ADDR_WIDTH > C_AXIL_DATA_WIDTH) begin
r_src_addr <= new_widesrc[C_AXI_ADDR_WIDTH-1:0];
end
DSTLO_ADDR: begin
r_dst_addr <= new_widedst[C_AXI_ADDR_WIDTH-1:0];
end
DSTHI_ADDR: if (C_AXI_ADDR_WIDTH > C_AXIL_DATA_WIDTH) begin
r_dst_addr <= new_widedst[C_AXI_ADDR_WIDTH-1:0];
end
LENLO_ADDR: begin
r_len <= new_widelen[LGLEN-1:0];
zero_len <= (new_widelen == 0);
end
LENHI_ADDR: if (LGLEN > C_AXIL_DATA_WIDTH) begin
r_len <= new_widelen[LGLEN-1:0];
zero_len <= (new_widelen == 0);
end
default: begin end
endcase
// }}}
end else if (r_busy)
begin
// {{{
r_dst_addr <= write_address[C_AXI_ADDR_WIDTH-1:0];
if (writes_remaining_w[LGLENW])
r_len <= -1;
else
r_len <= { writes_remaining_w[LGLENW-1:0],
{(ADDRLSB){1'b0}} };
if (OPT_UNALIGNED)
r_len[ADDRLSB-1:0] <= 0;
zero_len <= (writes_remaining_w == 0);
if (M_AXI_RVALID && M_AXI_RREADY && !M_AXI_RRESP[1])
begin
r_src_addr[C_AXI_ADDR_WIDTH-1:ADDRLSB]
<= r_src_addr[C_AXI_ADDR_WIDTH-1:ADDRLSB]+1;
r_src_addr[ADDRLSB-1:0] <= 0;
end
// }}}
end
function [C_AXIL_DATA_WIDTH-1:0] apply_wstrb;
// {{{
input [C_AXIL_DATA_WIDTH-1:0] prior_data;
input [C_AXIL_DATA_WIDTH-1:0] new_data;
input [C_AXIL_DATA_WIDTH/8-1:0] wstrb;
integer k;
for(k=0; k<C_AXIL_DATA_WIDTH/8; k=k+1)
begin
apply_wstrb[k*8 +: 8] = wstrb[k] ? new_data[k*8 +: 8]
: prior_data[k*8 +: 8];
end
endfunction
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// AXI-lite control read interface
// {{{
skidbuffer #(.OPT_OUTREG(0), .DW(C_AXIL_ADDR_WIDTH-AXILLSB))
axilarskid(//
.i_clk(S_AXI_ACLK), .i_reset(i_reset),
.i_valid(S_AXIL_ARVALID), .o_ready(S_AXIL_ARREADY),
.i_data(S_AXIL_ARADDR[C_AXIL_ADDR_WIDTH-1:AXILLSB]),
.o_valid(arskd_valid), .i_ready(axil_read_ready),
.o_data(arskd_addr));
always @(*)
begin
axil_read_ready = !S_AXIL_RVALID || S_AXIL_RREADY;
if (!arskd_valid)
axil_read_ready = 1'b0;
if (!clk_active)
axil_read_ready = 1'b0;
end
initial S_AXIL_RVALID = 1'b0;
always @(posedge i_clk)
if (i_reset)
S_AXIL_RVALID <= 1'b0;
else if (!S_AXIL_RVALID || S_AXIL_RREADY)
S_AXIL_RVALID <= axil_read_ready;
always @(posedge i_clk)
if (i_reset)
S_AXIL_RDATA <= 0;
else if (!S_AXIL_RVALID || S_AXIL_RREADY)
begin
S_AXIL_RDATA <= 0;
case(arskd_addr)
CTRL_ADDR: begin
S_AXIL_RDATA[CTRL_ERR_BIT] <= r_err;
S_AXIL_RDATA[CTRL_ABORT_BIT] <= r_abort;
S_AXIL_RDATA[CTRL_INTEN_BIT] <= r_int_enable;
S_AXIL_RDATA[CTRL_INT_BIT] <= r_int;
S_AXIL_RDATA[CTRL_BUSY_BIT] <= r_busy;
end
SRCLO_ADDR:
S_AXIL_RDATA <= wide_src[C_AXIL_DATA_WIDTH-1:0];
SRCHI_ADDR:
S_AXIL_RDATA <= wide_src[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH];
DSTLO_ADDR:
S_AXIL_RDATA <= wide_dst[C_AXIL_DATA_WIDTH-1:0];
DSTHI_ADDR:
S_AXIL_RDATA <= wide_dst[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH];
LENLO_ADDR:
S_AXIL_RDATA <= wide_len[C_AXIL_DATA_WIDTH-1:0];
LENHI_ADDR:
S_AXIL_RDATA <= wide_len[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH];
default: begin end
endcase
if (!axil_read_ready)
S_AXIL_RDATA <= 0;
end
assign S_AXIL_RRESP = AXI_OKAY;
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// AXI read processing
// {{{
////////////////////////////////////////////////////////////////////////
//
//
//
// Read data into our FIFO
//
// read_address
// {{{
always @(posedge i_clk)
if (!r_busy)
read_address <= { 1'b0, r_src_addr };
else if (phantom_read)
begin
// Verilator lint_off WIDTH
read_address[C_AXI_ADDR_WIDTH:ADDRLSB]
<= read_address[C_AXI_ADDR_WIDTH:ADDRLSB] +(M_AXI_ARLEN+1);
// Verilator lint_on WIDTH
read_address[ADDRLSB-1:0] <= 0;
end
// }}}
// reads_remaining_w, reads_remaining_nonzero
// {{{
// Verilator lint_off WIDTH
always @(posedge i_clk)
if (!r_busy)
reads_remaining_w <= readlen_b[LGLEN:ADDRLSB];
else if (phantom_read)
reads_remaining_w <= reads_remaining_w - (M_AXI_ARLEN+1);
always @(posedge i_clk)
if (!r_busy)
reads_remaining_nonzero <= 1;
else if (phantom_read)
reads_remaining_nonzero
<= (reads_remaining_w != (M_AXI_ARLEN+1));
// Verilator lint_on WIDTH
// }}}
// read_beats_remaining_w
// {{{
always @(posedge i_clk)
if (!r_busy)
read_beats_remaining_w <= readlen_b[LGLEN:ADDRLSB];
else if (M_AXI_RVALID && M_AXI_RREADY)
read_beats_remaining_w <= read_beats_remaining_w - 1;
// }}}
// read_bursts_outstanding, no_read_bursts_outstanding
// {{{
initial read_bursts_outstanding = 0;
always @(posedge i_clk)
if (i_reset || !r_busy)
begin
read_bursts_outstanding <= 0;
end else case({phantom_read,M_AXI_RVALID&& M_AXI_RREADY && M_AXI_RLAST})
2'b01: read_bursts_outstanding <= read_bursts_outstanding - 1;
2'b10: read_bursts_outstanding <= read_bursts_outstanding + 1;
default: begin end
endcase
initial no_read_bursts_outstanding = 1;
always @(posedge i_clk)
if (i_reset || !r_busy)
begin
no_read_bursts_outstanding <= 1;
end else case({phantom_read,M_AXI_RVALID&& M_AXI_RREADY && M_AXI_RLAST})
2'b01: no_read_bursts_outstanding <= (read_bursts_outstanding == 1);
2'b10: no_read_bursts_outstanding <= 0;
default: begin end
endcase
// }}}
// M_AXI_ARADDR
// {{{
always @(posedge i_clk)
if (!S_AXI_ARESETN && OPT_LOWPOWER)
M_AXI_ARADDR <= 0;
else if (!r_busy)
begin
if (!OPT_LOWPOWER || w_start)
M_AXI_ARADDR <= r_src_addr;
else
M_AXI_ARADDR <= 0;
end else if (!M_AXI_ARVALID || M_AXI_ARREADY)
begin
M_AXI_ARADDR <= read_address[C_AXI_ADDR_WIDTH-1:0];
if (OPT_LOWPOWER && !w_start_read)
M_AXI_ARADDR <= 0;
end
// }}}
// readlen_b
// {{{
always @(*)
if (OPT_UNALIGNED)
readlen_b = r_len + { {(C_AXI_ADDR_WIDTH-ADDRLSB){1'b0}},
r_src_addr[ADDRLSB-1:0] }
+ { {(C_AXI_ADDR_WIDTH-ADDRLSB){1'b0}},
{(ADDRLSB){1'b1}} };
else begin
readlen_b = { 1'b0, r_len };
readlen_b[ADDRLSB-1:0] = 0;
end
// }}}
// read_distance_to_boundary_b
// {{{
always @(*)
begin
read_distance_to_boundary_b = 0;
read_distance_to_boundary_b[ADDRLSB +: LGMAXBURST]
= -r_src_addr[ADDRLSB +: LGMAXBURST];
end
// }}}
// initial_readlen_w
// {{{
always @(*)
begin
initial_readlen_w = 0;
initial_readlen_w[LGMAXBURST] = 1;
if (r_src_addr[ADDRLSB +: LGMAXBURST] != 0)
initial_readlen_w[LGMAXBURST:0] = { 1'b0,
read_distance_to_boundary_b[ADDRLSB +: LGMAXBURST] };
if (initial_readlen_w > readlen_b[LGLEN:ADDRLSB])
initial_readlen_w[LGMAXBURST:0] = { 1'b0,
readlen_b[ADDRLSB +: LGMAXBURST] };
initial_readlen_w[LGLENW-1:LGMAXBURST+1] = 0;
end
// }}}
// readlen_w
// {{{
// Verilator lint_off WIDTH
always @(posedge i_clk)
if (!r_busy)
begin
readlen_w <= initial_readlen_w;
end else if (phantom_read)
begin
readlen_w <= reads_remaining_w - (M_AXI_ARLEN+1);
if (reads_remaining_w - (M_AXI_ARLEN+1) > MAXBURST)
readlen_w <= MAXBURST;
end
// Verilator lint_on WIDTH
// }}}
// w_start_read
// {{{
always @(*)
begin
w_start_read = r_busy && reads_remaining_nonzero;
if (phantom_read)
w_start_read = 0;
if (!OPT_WRAPMEM && read_address[C_AXI_ADDR_WIDTH])
w_start_read = 0;
if (fifo_space_available < MAXBURST)
w_start_read = 0;
if (M_AXI_ARVALID && !M_AXI_ARREADY)
w_start_read = 0;
if (r_err || r_abort)
w_start_read = 0;
end
// }}}
// M_AXI_ARVALID, phantom_read
// {{{
initial M_AXI_ARVALID = 1'b0;
initial phantom_read = 1'b0;
always @(posedge i_clk)
if (i_reset || !r_busy)
begin
M_AXI_ARVALID <= 0;
phantom_read <= 0;
end else if (!M_AXI_ARVALID || M_AXI_ARREADY)
begin
M_AXI_ARVALID <= w_start_read;
phantom_read <= w_start_read;
end else
phantom_read <= 0;
// }}}
// M_AXI_ARLEN
// {{{
always @(posedge i_clk)
if (i_reset || !r_busy)
M_AXI_ARLEN <= 0;
else if (!M_AXI_ARVALID || M_AXI_ARREADY)
begin
`ifdef AXI3
M_AXI_ARLEN <= readlen_w[3:0] - 4'h1;
`else
M_AXI_ARLEN <= readlen_w[7:0] - 8'h1;
`endif
if (OPT_LOWPOWER && !w_start_read)
M_AXI_ARLEN <= 0;
end
// }}}
assign M_AXI_ARID = AXI_READ_ID;
assign M_AXI_ARBURST = AXI_INCR;
assign M_AXI_ARSIZE = ADDRLSB[2:0];
assign M_AXI_ARLOCK = 1'b0;
assign M_AXI_ARCACHE = 4'b0011;
assign M_AXI_ARPROT = r_prot;
assign M_AXI_ARQOS = r_qos;
//
assign M_AXI_RREADY = !no_read_bursts_outstanding;
// }}}
////////////////////////////////////////////////////////////////////////
//
// The intermediate FIFO
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(*)
fifo_reset = i_reset || !r_busy || r_done;
generate if (OPT_UNALIGNED)
begin : REALIGNMENT_FIFO
// {{{
reg [ADDRLSB-1:0] inbyte_shift, outbyte_shift,
remaining_read_realignment;
reg [ADDRLSB+3-1:0] inshift_down, outshift_down,
inshift_up, outshift_up;
reg [C_AXI_DATA_WIDTH-1:0] r_partial_inword,
r_outword, r_partial_outword,
r_realigned_incoming;
wire [C_AXI_DATA_WIDTH-1:0] fifo_data;
reg [ADDRLSB-1:0] r_last_write_addr;
reg r_oneword, r_firstword;
///////////////////
always @(posedge i_clk)
if (!r_busy)
begin
inbyte_shift <= r_src_addr[ADDRLSB-1:0];
inshift_up <= 0;
inshift_up[3 +: ADDRLSB] <= -r_src_addr[ADDRLSB-1:0];
end
always @(*)
inshift_down = { inbyte_shift, 3'b000 };
always @(*)
remaining_read_realignment = -r_src_addr[ADDRLSB-1:0];
// extra_realignment_read will be true if we need to flush
// the read processor after the last word has been read in an
// extra write to the FIFO that isn't associated with any reads.
// In other words, if the number of writes to the FIFO is
// greater than the number of read beats
// - (src_addr unaligned?1:0)
always @(posedge i_clk)
if (!r_busy)
begin
extra_realignment_read <= (remaining_read_realignment
>= r_len[ADDRLSB-1:0]) ? 1:0;
if (r_len[ADDRLSB-1:0] == 0)
extra_realignment_read <= 1'b0;
if (r_src_addr[ADDRLSB-1:0] == 0)
extra_realignment_read <= 1'b0;
end else if ((!r_write_fifo || !fifo_full) && clear_read_pipeline)
extra_realignment_read <= 1'b0;
always @(posedge i_clk)
if (!r_busy || !extra_realignment_read || clear_read_pipeline)
clear_read_pipeline <= 0;
else if (!r_write_fifo || !fifo_full)
clear_read_pipeline <= (read_beats_remaining_w
== (M_AXI_RVALID ? 1:0));
`ifdef FORMAL
always @(*)
if (r_busy)
begin
if (!extra_realignment_read)
begin
assert(!clear_read_pipeline);
end else if (read_beats_remaining_w > 0)
begin
assert(!clear_read_pipeline);
end else if (!no_read_bursts_outstanding)
begin
assert(!clear_read_pipeline);
end
end
`endif
always @(posedge i_clk)
if (fifo_reset)