-
Notifications
You must be signed in to change notification settings - Fork 101
/
axis2mm.v
2234 lines (2034 loc) · 59.7 KB
/
axis2mm.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: axis2mm
// {{{
// Project: WB2AXIPSP: bus bridges and other odds and ends
//
// Purpose: Converts an AXI-stream (input) to an AXI (full) memory
// 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:
//
// 0: CMD_CONTROL
// Controls the transaction via either starting or aborting an
// ongoing transaction, provides feedback regarding the current
// status.
//
// [31] r_busy
// True if the core is in the middle of a transaction. Set this
// bit to one to begin a transaction.
//
// [30] r_err
// True if the core has detected an error, such as FIFO
// overflow while writing, or FIFO overflow in continuous mode.
//
// Writing a '1' to this bit while the core is idle will clear it.
// New transfers will not start until this bit is cleared. For
// this reason, I often start a new transfer by writing to bits
// 31 and 30 of this register.
//
// _s2mm->a_control = 0xc0000000;
//
// Other bits may be appropriate as well, as discussed below,
// depending on your application.
//
// [29] r_complete
// True if the transaction has completed, whether normally or
// abnormally (error or abort).
//
// Any write to the CMD_CONTROL register will clear this flag.
//
// [28] r_continuous
// Normally the FIFO gets cleared and reset between operations.
// However, if you set r_continuous, the core will then expectt
// a second operation to take place following the first one.
// In this case, the FIFO doesn't get cleared. However, if the
// FIFO fills and the incoming data is both valid and changing,
// the r_err flag will be set.
//
// Any write to the CMD_CONTROL register while the core is not
// busy will adjust this bit.
//
// [27] !r_increment
//
// If clear, the core writes to subsequent and incrementing
// addresses--the normal copy to memory case. If !r_increment is
// set, the core writes to the same address throughout the
// transaction. This is useful if you want to copy data to a
// FIFO or other device living at a single address in the memory
// map.
//
// Writes to CMD_CONTROL while the core is idle will adjust this
// bit.
//
// [26] !tlast_syncd
//
// Read only status indicator. Reads 0 if OPT_TLAST_SYNC isn't
// set. If OPT_TLAST_SYNC is set, then this bit indicates whether
// or not the memory transfer is currently aligned with any stream
// packets, or whether it is out of synchronization and waiting to
// sync with the incoming stream. If the IP is out of alignment
// and OPT_TLAST_SYNC is set, then the core will synchronize
// itself automatically by holding TREADY high and ignoring data
// until the first sample after TLAST.
//
// [25] Error code, decode error
//
// Read only bit. True following any AXI decode error. This will
// also set the error bit. When the error bit is cleared, this
// bit will be automatically cleared as well.
//
// [24] Error code, slave error
//
// Read only bit. True following any AXI slave error. This will
// also set the error bit. When the error bit is cleared, this bit
// will be automatically cleared as well.
//
// [23] Error code, overflow error
//
// Read only bit. True following any AXI stream overflow. As with
// the other two error code bits, this one will also set the error
// bit. It will also be cleared whenever the error bit is cleared.
//
// A "proper" AXI stream will never nor can it ever overflow. This
// overflow check therefore looks for AXI stream protocol
// violations. Such a violation might be not maintaining TVALID
// when !TREADY, or changing TDATA when TVALID && !TREADY.
// Likewise, if TLAST changes while TVALID && !TREADY an overflow
// condition will be generated--but in this case only if the
// OPT_TLAST_SYNC option is set.
//
// [22] Abort in progress
//
// Read only bit. This bit will be true following any abort until
// the bus transactions complete. Self-clearing.
//
// [20:16] LGFIFO
// These are read-only bits, returning the size of the FIFO.
//
// ABORT
// If the core is busy, and the ABORT_KEY (currently set to 8'h26
// below) is written to the top 8-bits ([31:24]) of this command
// register, then the current transfer will be aborted. Yes, this
// does repurpose the other bits written above. Any pending writes
// will be completed, but nothing more will be written.
//
// Alternatively, the core will enter into an abort state
// following any returned bus error indications.
//
// x4-c: (Unused and reserved)
//
// x10-14: CMD_ADDR
// [C_AXI_ADDR_WIDTH-1:($clog2(C_AXI_DATA_WIDTH)-3)]
//
// If idle, this is address the core will write to when it starts.
//
// If busy, this is the address of either the current or next
// address the core will request writing to.
//
// Upon completion, the address either returns to the starting
// address (if r_continuous is clear), or otherwise becomes the
// address where the core left off. In the case of an abort or an
// error, this will be (near) the address that was last written.
//
// Why "near"? Because this address records the writes that have
// been issued while no error is pending. If a bus error return
// comes back, there may have been several writes issued before
// that error address. Likewise if an overflow is detected, the
// data associated with the overflow may have already been
// somewhat written--the AXI bus doesn't stop on a dime.
//
// I hope to eventually add support for unaligned bursts. Such
// support is not currently part of this core.
//
// x18-1c: CMD_LEN
// [LGLEN-1:0]
// The size of the transfer in bytes. Only accepts aligned
// addresses, therefore bits [($clog2(C_AXI_DATA_WIDTH)-3):0]
// will always be forced to zero. To find out what size bus
// this core is conencted to, or the maximum transfer length,
// write a -1 to this value and read the returning result.
// Only the active bits will be set.
//
// While the core is busy, reads from this address will return
// the number of items still to be written to the bus.
//
// }}}
//
// Status:
// {{{
// 1. The core passes both cover checks and formal property (assertion)
// based checks. It has not (yet) been tested in real hardware.
//
// 2. I'd also like to support unaligned addresses (not lengths). This
// will require aligning the data coming out of the FIFO as well.
// As written, the core doesn't yet support these features.
//
// }}}
//
// Updates:
// {{{
// 20210426 - Fix. Upon reading, the current AXI write address and length
// will (now) be returned. These are word address and lengths, not
// packet address and lengths, and may (or may not) be aligned with
// packet boundaries.
//
// In a similar fashion, the cmd_addr and cmd_length registers will
// be adjusted on any error to (approximate) the address and length
// remaining upon any discovered error.
// }}}
//
// 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 axis2mm #(
// {{{
//
// Downstream AXI (MM) address width. Remember, this is *byte*
// oriented, so an address width of 32 means this core can
// interact with a full 2^(C_AXI_ADDR_WIDTH) *bytes*.
parameter C_AXI_ADDR_WIDTH = 32,
// ... and the downstream AXI (MM) data width. High speed can
// be achieved by increasing this data width.
parameter C_AXI_DATA_WIDTH = 32,
parameter C_AXI_ID_WIDTH = 1,
parameter C_AXIS_TUSER_WIDTH = 0,
//
// OPT_AXIS_SKIDBUFFER will place a buffer between the incoming
// AXI stream interface and the outgoing AXI stream ready. This
// is technically necessary, and probably good practice too,
// when dealing with high speed networks.
parameter [0:0] OPT_AXIS_SKIDBUFFER = 1,
//
// OPT_AXIS_SKIDREGISTER will force the outputs of the skid
// buffer to be registered. This is something you would
// do primarily if you are trying to hit high speeds through
// this core.
parameter [0:0] OPT_AXIS_SKIDREGISTER = 0,
//
// OPT_TLAST_SYNC will synchronize the write with any incoming
// packets. Packets are assumed to be synchronized initially
// after any reset, or on the TVALID following any TLAST
parameter [0:0] OPT_TLAST_SYNC = 1,
//
// OPT_TREADY_WHILE_IDLE controls how the stream idle is set
// when the memory copy isn't running. If 1, then TREADY will
// be 1 and the core will ignore/throw out data when the core
// isn't busy. Otherwise, if this is set to 0, the core will
// force the stream to stall if ever no data is being copied.
parameter [0:0] OPT_TREADY_WHILE_IDLE = 1,
//
// If the ABORT_KEY is written to the upper 8-bits of the
// control/status word, the current operation will be halted.
// Any currently active (AxVALID through xVALID & xREADY)
// requests will continue to completion, and the core will then
// come to a halt.
parameter [7:0] ABORT_KEY = 8'h26,
//
// The size of the FIFO, log-based two. Hence LGFIFO=9 gives
// you a FIFO of size 2^(LGFIFO) or 512 elements. This is about
// as big as the FIFO should ever need to be, since AXI bursts
// can be 256 in length.
parameter LGFIFO = 9,
//
// Maximum number of bytes that can ever be transferred, in
// log-base 2. Hence LGLEN=20 will transfer 1MB of data.
parameter LGLEN = C_AXI_ADDR_WIDTH-1,
//
// We only ever use one AXI ID for all of our transactions.
// Here it is given as 0. Feel free to change it as necessary.
parameter [C_AXI_ID_WIDTH-1:0] AXI_ID = 0,
//
// Set OPT_UNALIGNED to be able to transfer from unaligned
// addresses. Only applies to non fixed addresses and
// (possibly) non-continuous bursts. (THIS IS A PLACEHOLDER.
// UNALIGNED ADDRESSING IS NOT CURRENTLY SUPPORTED.)
localparam [0:0] OPT_UNALIGNED = 0,
//
parameter [0:0] OPT_LOWPOWER = 1'b0,
parameter [0:0] OPT_CLKGATE = OPT_LOWPOWER,
//
// OPT_ASYNCMEM. The default FIFO implementation uses an
// asynchronous memory read, which will return the result in
// the same clock it is requested within. This forces the
// FIFO to use distributed RAM. For those architectures that
// don't have distributed RAM, or those designs that need to
// use block RAM, this flag should be set to zero.
parameter [0:0] OPT_ASYNCMEM = 1'b1,
//
// Size of the AXI-lite bus. These are fixed, since 1) AXI-lite
// is fixed at a width of 32-bits by Xilinx def'n, and 2) since
// we only ever have 4 configuration words.
localparam C_AXIL_ADDR_WIDTH = 5,
localparam C_AXIL_DATA_WIDTH = 32
// }}}
) (
// {{{
input wire S_AXI_ACLK,
input wire S_AXI_ARESETN,
//
// The stream interface
// {{{
input wire S_AXIS_TVALID,
output wire S_AXIS_TREADY,
input wire [C_AXI_DATA_WIDTH-1:0] S_AXIS_TDATA,
input wire S_AXIS_TLAST,
input wire [((C_AXIS_TUSER_WIDTH>0) ? C_AXIS_TUSER_WIDTH-1:0):0]
S_AXIS_TUSER,
// }}}
//
// The 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 wire 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 wire S_AXIL_RVALID,
input wire S_AXIL_RREADY,
output wire [C_AXIL_DATA_WIDTH-1:0] S_AXIL_RDATA,
output wire [1:0] S_AXIL_RRESP,
// }}}
//
//
// The AXI (full) write interface
// {{{
output wire M_AXI_AWVALID,
input wire M_AXI_AWREADY,
output wire [C_AXI_ID_WIDTH-1:0] M_AXI_AWID,
output wire [C_AXI_ADDR_WIDTH-1:0] M_AXI_AWADDR,
output wire [7:0] M_AXI_AWLEN,
output wire [2:0] M_AXI_AWSIZE,
output wire [1:0] M_AXI_AWBURST,
output wire M_AXI_AWLOCK,
output wire [3:0] M_AXI_AWCACHE,
output wire [2:0] M_AXI_AWPROT,
output wire [3:0] M_AXI_AWQOS,
//
output wire M_AXI_WVALID,
input wire M_AXI_WREADY,
output wire [C_AXI_DATA_WIDTH-1:0] M_AXI_WDATA,
output wire [C_AXI_DATA_WIDTH/8-1:0] M_AXI_WSTRB,
output wire M_AXI_WLAST,
output wire [(C_AXIS_TUSER_WIDTH>0 ? C_AXIS_TUSER_WIDTH-1:0):0]
M_AXI_WUSER,
//
input wire M_AXI_BVALID,
output wire M_AXI_BREADY,
input wire [C_AXI_ID_WIDTH-1:0] M_AXI_BID,
input wire [1:0] M_AXI_BRESP,
// }}}
//
//
// Create an output signal to indicate that we've finished
output reg o_int
// }}}
);
// Local parameters
// {{{
localparam AXILLSB = $clog2(C_AXIL_DATA_WIDTH)-3;
localparam ADDRLSB = $clog2(C_AXI_DATA_WIDTH)-3;
localparam [2:0] CMD_CONTROL = 3'b000,
// CMD_UNUSED_1 = 3'b001,
// CMD_UNUSED_2 = 3'b010,
// CMD_UNUSED_3 = 3'b011,
CMD_ADDRLO = 3'b100,
CMD_ADDRHI = 3'b101,
CMD_LENLO = 3'b110,
CMD_LENHI = 3'b111;
// CMD_RESERVED = 2'b11;
// The maximum burst size is either 256, or half the FIFO size,
// whichever is smaller.
localparam TMP_LGMAXBURST=(LGFIFO > 8) ? 8 : LGFIFO-1;
// Of course, if this busts our 4kB packet size, it's an error.
// Let's clip to that size, then, if the LGMAXBURST would otherwise
// break it. So .. if 4kB is larger than our maximum burst size, then
// no change is required.
localparam LGMAXBURST = ((4096 / (C_AXI_DATA_WIDTH / 8))
> (1<<TMP_LGMAXBURST))
? TMP_LGMAXBURST : $clog2(4096 * 8 / C_AXI_DATA_WIDTH);
localparam LGMAX_FIXED_BURST = (LGMAXBURST > 4) ? 4 : LGMAXBURST;
localparam MAX_FIXED_BURST = (1<<LGMAX_FIXED_BURST);
localparam LGLENW = LGLEN - ADDRLSB;
// localparam LGFIFOB = LGFIFO + ADDRLSB;
localparam ERRCODE_NOERR = 0,
ERRCODE_OVERFLOW = 0,
ERRCODE_SLVERR = 1,
ERRCODE_DECERR = 2;
// }}}
// Signal declarations
// {{{
wire clk_active, gated_clk;
wire i_clk = gated_clk;
wire i_reset = !S_AXI_ARESETN;
// Incoming stream buffer
wire sskd_valid, sskd_ready, sskd_last;
wire [C_AXI_DATA_WIDTH-1:0] sskd_data;
wire [((C_AXIS_TUSER_WIDTH>0) ? C_AXIS_TUSER_WIDTH : 1)-1:0] sskd_user;
reg r_busy, r_err, r_complete, r_continuous, r_increment,
cmd_abort, zero_length, r_pre_start,
w_cmd_start, w_complete, w_cmd_abort;
reg [2:0] r_errcode;
// reg cmd_start;
reg axi_abort_pending;
reg [LGLENW-1:0] aw_requests_remaining,
aw_bursts_outstanding,
aw_next_remaining;
reg [LGMAXBURST:0] wr_writes_pending;
reg [LGMAXBURST:0] r_max_burst;
reg [C_AXI_ADDR_WIDTH-1:0] axi_addr;
reg [C_AXI_ADDR_WIDTH-1:0] cmd_addr;
reg [LGLENW-1:0] cmd_length_w;
reg [2*C_AXIL_DATA_WIDTH-1:0] wide_address, wide_length,
new_wideaddr, new_widelen,
wide_len_remaining,wide_current_address;
wire [C_AXIL_DATA_WIDTH-1:0] new_cmdaddrlo, new_cmdaddrhi,
new_lengthlo, new_lengthhi;
// FIFO signals
wire reset_fifo, write_to_fifo,
read_from_fifo;
wire [C_AXIS_TUSER_WIDTH+C_AXI_DATA_WIDTH-1:0] fifo_data;
wire [LGFIFO:0] fifo_fill;
wire fifo_full, fifo_empty;
wire awskd_valid, axil_write_ready;
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;
reg axil_bvalid;
//
wire arskd_valid, axil_read_ready;
wire [C_AXIL_ADDR_WIDTH-AXILLSB-1:0] arskd_addr;
reg [C_AXIL_DATA_WIDTH-1:0] axil_read_data;
reg axil_read_valid;
reg last_stalled, overflow, last_tlast;
reg [C_AXI_DATA_WIDTH-1:0] last_tdata;
reg [C_AXIL_DATA_WIDTH-1:0] w_status_word;
reg [LGLENW-1:0] r_remaining_w;
reg axi_awvalid;
reg [C_AXI_ADDR_WIDTH-1:0] axi_awaddr;
reg [7:0] axi_awlen;
reg axi_wvalid, axi_wlast;
reg [C_AXI_DATA_WIDTH/8-1:0] axi_wstrb;
// Speed up checking for zeros
reg aw_none_remaining,
aw_none_outstanding,
aw_last_outstanding,
wr_none_pending; // r_none_remaining;
reg w_phantom_start, phantom_start;
reg [LGMAXBURST:0] initial_burstlen;
reg [LGMAXBURST-1:0] addralign;
//
// Option processing
wire tlast_syncd;
reg aw_multiple_full_bursts,
aw_multiple_fixed_bursts,
aw_multiple_bursts_remaining,
aw_needs_alignment;
reg [LGFIFO:0] data_available;
reg sufficiently_filled;
// }}}
////////////////////////////////////////////////////////////////////////
//
// AXI Stream skidbuffer
// {{{
////////////////////////////////////////////////////////////////////////
//
//
skidbuffer #(
// {{{
.OPT_OUTREG(OPT_AXIS_SKIDREGISTER),
.DW(C_AXI_DATA_WIDTH + 1
+ ((C_AXIS_TUSER_WIDTH > 0) ? C_AXIS_TUSER_WIDTH:1)),
.OPT_LOWPOWER(OPT_LOWPOWER),
.OPT_PASSTHROUGH(!OPT_AXIS_SKIDBUFFER)
// }}}
) skd_stream(
// {{{
.i_clk(S_AXI_ACLK), .i_reset(reset_fifo),
.i_valid(S_AXIS_TVALID), .o_ready(S_AXIS_TREADY),
.i_data({ S_AXIS_TUSER, S_AXIS_TDATA, S_AXIS_TLAST }),
.o_valid(sskd_valid), .i_ready(sskd_ready),
.o_data({ sskd_user, sskd_data, sskd_last })
// }}}
);
// }}}
////////////////////////////////////////////////////////////////////////
//
// AXI-lite signaling
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// This is mostly the skidbuffer logic, and handling of the VALID
// and READY signals for the AXI-lite control logic in the next
// section.
//
// Write signaling
//
// {{{
skidbuffer #(
// {{{
.OPT_OUTREG(0), .DW(C_AXIL_ADDR_WIDTH-AXILLSB),
.OPT_LOWPOWER(OPT_LOWPOWER)
// }}}
) 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),
.OPT_LOWPOWER(OPT_LOWPOWER)
// }}}
) axilwskid(
// {{{
.i_clk(S_AXI_ACLK), .i_reset(i_reset),
.i_valid(S_AXIL_WVALID), .o_ready(S_AXIL_WREADY),
.i_data({ S_AXIL_WDATA, S_AXIL_WSTRB }),
.o_valid(wskd_valid), .i_ready(axil_write_ready),
.o_data({ wskd_data, wskd_strb })
// }}}
);
assign axil_write_ready = clk_active && awskd_valid && wskd_valid
&& (!S_AXIL_BVALID || S_AXIL_BREADY);
initial axil_bvalid = 0;
always @(posedge i_clk)
if (i_reset)
axil_bvalid <= 0;
else if (axil_write_ready)
axil_bvalid <= 1;
else if (S_AXIL_BREADY)
axil_bvalid <= 0;
assign S_AXIL_BVALID = axil_bvalid;
assign S_AXIL_BRESP = 2'b00;
// }}}
//
// Read signaling
//
// {{{
skidbuffer #(
// {{{
.OPT_OUTREG(0), .DW(C_AXIL_ADDR_WIDTH-AXILLSB),
.OPT_LOWPOWER(OPT_LOWPOWER)
// }}}
) 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)
// }}}
);
assign axil_read_ready = clk_active && arskd_valid
&& (!axil_read_valid || S_AXIL_RREADY);
initial axil_read_valid = 1'b0;
always @(posedge i_clk)
if (i_reset)
axil_read_valid <= 1'b0;
else if (axil_read_ready)
axil_read_valid <= 1'b1;
else if (S_AXIL_RREADY)
axil_read_valid <= 1'b0;
assign S_AXIL_RVALID = axil_read_valid;
assign S_AXIL_RDATA = axil_read_data;
assign S_AXIL_RRESP = 2'b00;
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// AXI-lite controlled logic
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// last_stalled -- used in overflow checking
// {{{
initial last_stalled = 1'b0;
always @(posedge i_clk)
last_stalled <= (!i_reset) && (S_AXIS_TVALID && !S_AXIS_TREADY);
// }}}
// last_tlast -- used to check for protocol violations in overflow next
// {{{
always @(posedge i_clk)
if (!OPT_TLAST_SYNC)
last_tlast <= 0;
else
last_tlast <= S_AXIS_TLAST;
// }}}
// last_tdata -- used for overflow checking
// {{{
always @(posedge i_clk)
last_tdata <= S_AXIS_TDATA;
// }}}
// overflow
// {{{
// Capture and check whether or not the incoming data stream overflowed
// This is primarily a check for AXI-stream protocol violations, since
// you can't really overflow an AXI stream when following protocol. The
// problem is that many stream sources--such as ADCs for example--can't
// handle back-pressure. Hence, checking for stream violations can
// be used in those cases to check for overflows. The check is only
// so good, however, since an overflow condition might take place if
// an ADC produces two consecutive (identical) values, one of which gets
// skipped--and this check will not capture that.
initial overflow = 0;
always @(posedge i_clk)
if (i_reset)
overflow <= 0;
else if (last_stalled)
begin
// The overflow pulse is only one clock period long
overflow <= 0;
if (!sskd_valid)
overflow <= 1;
if (S_AXIS_TDATA != last_tdata)
overflow <= 1;
if (OPT_TLAST_SYNC && S_AXIS_TLAST != last_tlast)
overflow <= 1;
// This will be caught by r_err and r_continuous
end
// }}}
// w_cmd_abort, cmd_abort -- Abort transaction on user request
// {{{
// w_cmd_abort is a combinational value capturing a user abort request
// {{{
always @(*)
begin
w_cmd_abort = 0;
w_cmd_abort = (axil_write_ready && awskd_addr == CMD_CONTROL)
&& (wskd_strb[3] && wskd_data[31:24] == ABORT_KEY);
if (!r_busy)
w_cmd_abort = 0;
end
// }}}
// cmd_abort latches the user request until the abort is complete
// {{{
initial cmd_abort = 0;
always @(posedge i_clk)
if (i_reset)
cmd_abort <= 0;
else if (!r_busy)
cmd_abort <= 0;
else
cmd_abort <= cmd_abort || w_cmd_abort;
// }}}
// }}}
//
// Start command
//
always @(*)
if (r_busy)
w_cmd_start = 0;
else begin
w_cmd_start = 0;
if ((axil_write_ready && awskd_addr == CMD_CONTROL)
&& (wskd_strb[3] && wskd_data[31]))
w_cmd_start = 1;
if (r_err && !wskd_data[30])
w_cmd_start = 0;
if (zero_length)
w_cmd_start = 0;
end
// r_busy, r_complete -- Calculate busy or complete flags
// {{{
initial r_busy = 0;
initial r_complete = 0;
always @(posedge i_clk)
if (i_reset)
begin
r_busy <= 0;
r_complete <= 0;
end else if (!r_busy)
begin
// Core is idle, waiting for a command to start
if (w_cmd_start)
r_busy <= 1'b1;
// Any write to the control register will clear the
// completion flag
if (axil_write_ready && awskd_addr == CMD_CONTROL)
r_complete <= 1'b0;
end else if (w_complete)
begin
// Clear busy once the transaction is complete
// This includes clearing busy on any error
r_complete <= 1;
r_busy <= 1'b0;
end
// }}}
// o_int -- interrupt generation
// {{{
initial o_int = 0;
always @(posedge i_clk)
if (i_reset)
o_int <= 0;
else
o_int <= (r_busy && w_complete)
|| (r_continuous && overflow);
// }}}
// r_err, r_errcode: Error conditions checking
// {{{
initial r_err = 0;
initial r_errcode = ERRCODE_NOERR;
always @(posedge i_clk)
if (i_reset)
begin
r_err <= 0;
r_errcode <= ERRCODE_NOERR;
end else if (!r_busy)
begin
if (r_continuous && overflow)
begin
r_err <= 1;
r_errcode[ERRCODE_OVERFLOW] <= 1'b1;
end
if (axil_write_ready && awskd_addr == CMD_CONTROL
&& wskd_strb[3] && wskd_data[30])
begin
r_err <= 0;
r_errcode <= ERRCODE_NOERR;
end
end else if (r_busy)
begin
if (M_AXI_BVALID && M_AXI_BREADY && M_AXI_BRESP[1])
begin
r_err <= 1'b1;
if (M_AXI_BRESP[0])
r_errcode[ERRCODE_DECERR] <= 1'b1;
else
r_errcode[ERRCODE_SLVERR] <= 1'b1;
end
if (overflow)
begin
r_err <= 1'b1;
r_errcode[ERRCODE_OVERFLOW] <= 1'b1;
end
end
// }}}
// r_continuous
// {{{
initial r_continuous = 0;
always @(posedge i_clk)
if (i_reset)
r_continuous <= 0;
else begin
if (r_continuous && overflow)
r_continuous <= 1'b0;
if (!r_busy && axil_write_ready && awskd_addr == CMD_CONTROL)
r_continuous <= wskd_strb[3] && wskd_data[28];
end
// }}}
// wide_*
// {{{
always @(*)
begin
wide_address = 0;
wide_address[C_AXI_ADDR_WIDTH-1:0] = cmd_addr;
wide_current_address = 0;
wide_current_address[C_AXI_ADDR_WIDTH-1:0] = axi_addr;
wide_length = 0;
wide_length[ADDRLSB +: LGLENW] = cmd_length_w;
wide_len_remaining = 0;
wide_len_remaining[ADDRLSB +: LGLENW] = r_remaining_w;
end
// }}}
// new_* wires created via apply_wstrb
// {{{
assign new_cmdaddrlo= apply_wstrb(
wide_address[C_AXIL_DATA_WIDTH-1:0],
wskd_data, wskd_strb);
assign new_cmdaddrhi=apply_wstrb(
wide_address[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH],
wskd_data, wskd_strb);
assign new_lengthlo= apply_wstrb(
wide_length[C_AXIL_DATA_WIDTH-1:0],
wskd_data, wskd_strb);
assign new_lengthhi= apply_wstrb(
wide_length[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH],
wskd_data, wskd_strb);
// }}}
// new_wideaddr, new_widelen
// {{{
// These are the wide_* adjusted for any write, and then adjusted again
// to make sure they are within the correct number of bits for the
// interface.
always @(*)
begin
new_wideaddr = wide_address;
if (awskd_addr == CMD_ADDRLO)
new_wideaddr[C_AXIL_DATA_WIDTH-1:0]
= new_cmdaddrlo;
if (awskd_addr == CMD_ADDRHI)
new_wideaddr[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH]
= new_cmdaddrhi;
if (!OPT_UNALIGNED)
new_wideaddr[ADDRLSB-1:0] = 0;
// We only support C_AXI_ADDR_WIDTH address bits
new_wideaddr[2*C_AXIL_DATA_WIDTH-1:C_AXI_ADDR_WIDTH] = 0;
//
///////////////
//
new_widelen = wide_length;
if (awskd_addr == CMD_LENLO)
new_widelen[C_AXIL_DATA_WIDTH-1:0] = new_lengthlo;
if (awskd_addr == CMD_LENHI)
new_widelen[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH]
= new_lengthhi;
// We only support integer numbers of words--even if unaligned
new_widelen[ADDRLSB-1:0] = 0;
// We only support LGLEN length bits
new_widelen[2*C_AXIL_DATA_WIDTH-1:LGLEN] = 0;
end
// }}}
// cmd_addr, cmd_length_w, r_increment, zero_length, aw_multiple_*
// {{{
initial r_increment = 1'b1;
initial cmd_addr = 0;
initial cmd_length_w = 0; // Counts in bytes
initial zero_length = 1;
initial aw_multiple_full_bursts = 0;
initial aw_multiple_fixed_bursts = 0;
always @(posedge i_clk)
if (i_reset)
begin
// {{{
r_increment <= 1'b1;
cmd_addr <= 0;
cmd_length_w <= 0;
zero_length <= 1;
aw_multiple_full_bursts <= 0;
aw_multiple_fixed_bursts <= 0;
// }}}
end else if (axil_write_ready && !r_busy)
begin // Set the command, address, and length prior to operation
// {{{
case(awskd_addr)
CMD_CONTROL:
r_increment <= !wskd_data[27];
CMD_ADDRLO:
cmd_addr <= new_wideaddr[C_AXI_ADDR_WIDTH-1:0];
CMD_ADDRHI: if (C_AXI_ADDR_WIDTH > C_AXIL_DATA_WIDTH)
begin
cmd_addr <= new_wideaddr[C_AXI_ADDR_WIDTH-1:0];
end
CMD_LENLO: begin
cmd_length_w <= new_widelen[ADDRLSB +: LGLENW];
zero_length <= (new_widelen[ADDRLSB +: LGLENW] == 0);
aw_multiple_full_bursts <= |new_widelen[LGLEN-1:(ADDRLSB+LGMAXBURST)];
aw_multiple_fixed_bursts <= |new_widelen[LGLEN-1:(ADDRLSB+LGMAX_FIXED_BURST)];
end
CMD_LENHI: if (LGLEN > C_AXIL_DATA_WIDTH)
begin
cmd_length_w <= new_widelen[ADDRLSB +: LGLENW];
zero_length <= (new_widelen[ADDRLSB +: LGLENW] == 0);
aw_multiple_full_bursts <= |new_widelen[LGLEN-1:(ADDRLSB+LGMAXBURST)];
aw_multiple_fixed_bursts <= |new_widelen[LGLEN-1:(ADDRLSB+LGMAX_FIXED_BURST)];
end
default: begin end
endcase
// }}}
end else if (r_busy)
begin // Updated cmd_addr && cmd_length during operation
// {{{
// Capture the last address written to in case of r_continuous
// (where we'll want to start again from this address),
// cmd_abort (where we'll want to know how far we got), or
// a bus error (where again we'll want to know how far we got)
if (r_continuous||axi_abort_pending)
cmd_addr <= axi_addr;
// Capture the number of remaining requests on either an error
// or an abort. Need to be careful here that we don't capture
// this address twice--hence the check for
// w_cmd_abort && !cmd_abort, and again for BVALID && !r_err
//
// Note that we can't check for axi_abort_pending here, since
// as soon as axi_abort_pending becomes true then cmd_length_w
// will get set to zero. Hence we need to capture this before
// axi_abort_pending gets set.
//
// Note that this is only an *approximate* length--especially
// in the case of either a bus error or an overflow, in which
// cases we won't really know what writes have been accomplished
// only that the last one failed. In that case, this will
// indicate the amount of writes we haven't requested
// (yet)--knowing that at least one (or more) of those prior
// must've failed. In the case of an overflow error, the
// overflow error may (or may not) have been written to memory
// by this time.
if (!axi_abort_pending && (cmd_abort || r_err
|| (M_AXI_BVALID && M_AXI_BRESP[1])))
begin
cmd_length_w <= aw_requests_remaining;
zero_length <= (aw_requests_remaining == 0);
aw_multiple_full_bursts <= |aw_requests_remaining[LGLENW-1:LGMAXBURST];
aw_multiple_fixed_bursts <= |aw_requests_remaining[LGLENW-1:LGMAX_FIXED_BURST];
end
// Note that, because cmd_addr and cmd_length_w here aren't set
// on the same conditions that it is possible, on an error,
// that the two will not match.
// }}}
end
// }}}
// w_status_word
// {{{
always @(*)
begin
w_status_word = 0;
// The ABORT_KEY needs to be chosen so as not to look
// like these bits, lest someone read from the register
// and write back to it accidentally aborting any transaction
w_status_word[31] = r_busy;
w_status_word[30] = r_err;
w_status_word[29] = r_complete;
w_status_word[28] = r_continuous;
w_status_word[27] = !r_increment;