-
Notifications
You must be signed in to change notification settings - Fork 101
/
axivdisplay.v
1438 lines (1299 loc) · 36.8 KB
/
axivdisplay.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: axivdisplay
// {{{
// Project: WB2AXIPSP: bus bridges and other odds and ends
//
// Purpose: Reads from memory for the purposes of serving a video frame
// {{{
// buffer. The result of this core is an AXI stream having the
// word size of the memory interface in the first place. TLAST is set
// based upon the end of the frame, and TUSER based upon the end of the
// line. An option exists to use Xilinx's encoding instead where TLAST
// is the end of the line and TUSER is the first pixel word of the frame.
//
// This core is in many ways similar to the AXI MM2S core, but with some
// key differences: The AXI MM2S core generates a single transfer. This
// core generates a repeating set of transfers--one per line, repeated
// per frame.
//
// To insure high bandwidth, data is first copied into a FIFO of twice
// the width of the longest burst.
//
// }}}
// Registers:
// {{{
// 0: FBUF_CONTROL and status
// bit 0: START(1)/STOP(0)
// Command the core to start by writing a '1' to this bit. It
// will then remain busy/active until either you tell it to halt,
// or an error occurrs.
// bit 1: BUSY
// bit 2: ERR
// If the core receives a bus error, it assumes it has been
// inappropriately set up, sets this error bit and then halts.
// It will not start again until this bit is cleared. Only a
// write to the control register with the ERR bit set will clear
// it. (Don't do this unless you know what caused it to halt ...)
// bit 3: DIRTY
// If you update core parameters while it is running, the busy
// bit will be set. This bit is an indication that the current
// configuration doesn't necessarily match the one you are reading
// out. To clear DIRTY, deactivate the core, wait for it to be
// no longer busy, and then start it again. This will also start
// it under the new configuration so the two match.
//
// 2: FBUF_LINESTEP
// Controls the distance from one line to the next. This is the
// value added to the address of the beginning of the line to get
// to the beginning of the next line. This should nominally be
// equal to the number of bytes per line, although it doesn't
// need to be.
//
// Any attempt to set this value to zero will simply copy the
// number of data bytes per line into this value.
//
// 4: FBUF_LINEBYTES
// This is the number of data bytes necessary to capture all of
// the video data in a line. This value must be more than zero
// in order to activate the core.
//
// At present, this core can only handle a number of bytes aligned
// with the word size of the bus.
//
// 6: FBUF_NUMLINES
// The number of lines of active video data in a frame. This
// number must be greater than zero in order to activate and
// operate the core.
//
// 8: FBUF_ADDRESS
// The is the first address of video data in memory. Each frame
// will start reading from this address.
//
// 12: (reserved for the upper FBUF_ADDRESS)
//
// BUGS:
// 1. Memory reads are currently allowed to wrap around the end of memory.
// I'm not (yet) sure if this is a good thing or a bad thing. I mean, its
// a great thing for small dedicated memories designated for this purpose
// alone, but perhaps a bad thing if the memory space is shared with
// peripherals as well as a CPU.
//
// 2. I'd still like to add an option to handle memory addresses that
// aren't aligned. Until that is done, the means of interacting with the
// core will change from one implementation to another.
//
// 3. If the configuration changes mid-write, but without de-activating
// the core and waiting for it to come to idle, the synchronization flags
// might out-of-sync with the pixels. To resolve, deactivate the core and
// let it come to whenever changing configuration parameters.
// }}}
//
// 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
// }}}
module axivdisplay #(
// {{{
parameter C_AXI_ADDR_WIDTH = 32,
parameter C_AXI_DATA_WIDTH = 32,
parameter C_AXI_ID_WIDTH = 1,
//
// We support five 32-bit AXI-lite registers, requiring 5-bits
// of AXI-lite addressing
localparam C_AXIL_ADDR_WIDTH = 4,
localparam C_AXIL_DATA_WIDTH = 32,
//
// The bottom ADDRLSB bits of any AXI address are subword bits
localparam ADDRLSB = $clog2(C_AXI_DATA_WIDTH)-3,
localparam AXILLSB = $clog2(C_AXIL_DATA_WIDTH)-3,
//
// OPT_UNALIGNED: Allow unaligned accesses, address requests
// and sizes which may or may not match the underlying data
// width. If set, the core will quietly align these requests.
// parameter [0:0] OPT_UNALIGNED = 1'b0,
//
// OPT_LGMAXBURST
parameter OPT_LGMAXBURST = 8,
//
parameter [0:0] DEF_ACTIVE_ON_RESET = 0,
parameter [15:0] DEF_LINES_PER_FRAME = 1024,
parameter [16-ADDRLSB-1:0] DEF_WORDS_PER_LINE = (1280 * 32)/C_AXI_DATA_WIDTH,
//
// DEF_FRAMEADDR: the default AXI address of the frame buffer
// containing video memory. Unless OPT_UNALIGNED is set, this
// should be aligned so that DEF_FRAMEADDR[ADDRLSB-1:0] == 0.
parameter [C_AXI_ADDR_WIDTH-1:0] DEF_FRAMEADDR = 0,
//
// The (log-based two of the) size of the FIFO in words.
// I like to set this to the size of two AXI bursts, so that
// while one is being read out the second can be read in. Can
// also be set larger if desired.
parameter LGFIFO = OPT_LGMAXBURST+1,
//
// AXI_ID is the ID we will use for all of our AXI transactions
parameter AXI_ID = 0,
//
// OPT_TUSER_IS_SOF. Xilinx and I chose different stream
// encodings. I encode TLAST== VLAST and
// TUSER == (optional) HLAST. Xilinx chose TLAST == HLAST
// and TUSER == SOF(start of frame). Set OPT_TUSER_IS_SOF to
// use Xilinx's encoding.
parameter [0:0] OPT_TUSER_IS_SOF = 0
// }}}
) (
// {{{
input wire S_AXI_ACLK,
input wire S_AXI_ARESETN,
//
// The video stream interface
// {{{
output wire M_AXIS_TVALID,
input wire M_AXIS_TREADY,
output wire [C_AXI_DATA_WIDTH-1:0] M_AXIS_TDATA,
output wire /* VLAST or HLAST */ M_AXIS_TLAST,
output wire /* HLAST or SOF */ M_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) read interface
// {{{
output wire M_AXI_ARVALID,
input wire M_AXI_ARREADY,
output wire [C_AXI_ID_WIDTH-1:0] M_AXI_ARID,
output wire [C_AXI_ADDR_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 [C_AXI_DATA_WIDTH-1:0] M_AXI_RDATA,
input wire M_AXI_RLAST,
input wire [C_AXI_ID_WIDTH-1:0] M_AXI_RID,
input wire [1:0] M_AXI_RRESP
// }}}
// }}}
);
// Core logic implementation
// {{{
// Local parameter declarations
// {{{
localparam [1:0] FBUF_CONTROL = 2'b00,
FBUF_FRAMEINFO = 2'b01,
FBUF_ADDRLO = 2'b10,
FBUF_ADDRHI = 2'b11;
localparam CBIT_ACTIVE = 0,
CBIT_BUSY = 1,
CBIT_ERR = 2,
CBIT_DIRTY = 3;
localparam TMPLGMAXBURST=(LGFIFO-1 > OPT_LGMAXBURST)
? OPT_LGMAXBURST : LGFIFO-1;
localparam LGMAXBURST = (TMPLGMAXBURST+ADDRLSB > 12)
? (12-ADDRLSB) : TMPLGMAXBURST;
// }}}
wire i_clk = S_AXI_ACLK;
wire i_reset = !S_AXI_ARESETN;
// Signal declarations
// {{{
reg soft_reset, r_err, r_stopped;
reg cfg_active, cfg_zero_length, cfg_dirty;
reg [C_AXI_ADDR_WIDTH-1:0] cfg_frame_addr;
reg [15:0] cfg_frame_lines, cfg_line_step;
reg [16-ADDRLSB-1:0] cfg_line_words;
// FIFO signals
wire reset_fifo, write_to_fifo,
read_from_fifo;
wire [C_AXI_DATA_WIDTH-1:0] write_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 [C_AXIL_DATA_WIDTH-1:0] w_status_word;
reg [2*C_AXIL_DATA_WIDTH-1:0] wide_address, new_wideaddr;
wire [C_AXIL_DATA_WIDTH-1:0] new_cmdaddrlo, new_cmdaddrhi;
reg [C_AXIL_DATA_WIDTH-1:0] wide_config;
wire [C_AXIL_DATA_WIDTH-1:0] new_config;
// reg partial_burst_requested;
// reg [LGMAXBURST-1:0] addralign;
// reg [LGFIFO:0] rd_uncommitted;
// reg [LGMAXBURST:0] initial_burstlen;
// reg [LGLENWA-1:0] rd_reads_remaining;
// reg rd_none_remaining,
// rd_last_remaining;
// wire realign_last_valid;
reg axi_arvalid, lag_start, phantom_start, start_burst,
ar_none_outstanding;
reg [C_AXI_ADDR_WIDTH-1:0] axi_araddr;
reg [LGMAXBURST:0] max_burst;
reg [7:0] axi_arlen;
reg [15:0] ar_bursts_outstanding;
//
wire vlast, hlast;
reg [15:0] r_frame_lines, r_line_step;
reg [16-ADDRLSB-1:0] r_line_words;
reg req_hlast, req_vlast;
reg [15:0] req_nlines;
reg [16-ADDRLSB-1:0] req_line_words;
reg [C_AXI_ADDR_WIDTH:0] req_addr, req_line_addr;
//
reg rd_hlast, rd_vlast;
reg [15:0] rd_lines;
reg [16-ADDRLSB-1:0] rd_line_beats;
wire no_fifo_space_available;
//
reg [LGMAXBURST-1:0] till_boundary;
reg [LGFIFO:0] fifo_space_available;
`ifdef FORMAL
reg [C_AXI_ADDR_WIDTH:0] f_rd_line_addr, f_rd_addr;
`endif
wire M_AXIS_VLAST, M_AXIS_HLAST;
// }}}
////////////////////////////////////////////////////////////////////////
//
// 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))
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_WDATA, S_AXIL_WSTRB }),
.o_valid(wskd_valid), .i_ready(axil_write_ready),
.o_data({ wskd_data, wskd_strb }));
assign axil_write_ready = 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))
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 = 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
//
////////////////////////////////////////////////////////////////////////
//
// {{{
//
// soft_reset, r_err
// {{{
initial soft_reset = 1;
always @(posedge i_clk)
if (i_reset)
begin
soft_reset <= 1;
r_err <= 0;
end else if (soft_reset)
begin
if ((axil_write_ready && awskd_addr == FBUF_CONTROL)
&& wskd_strb[0] && wskd_data[CBIT_ERR])
r_err <= cfg_zero_length;
if (cfg_active && !r_err && r_stopped)
soft_reset <= 0;
end else // if (!soft_reset)
begin
// Halt on any bus error. We'll require user intervention
// to start back up again
if (M_AXI_RREADY && M_AXI_RVALID && M_AXI_RRESP[1])
begin
soft_reset <= 1;
r_err <= 1;
end
// Halt on any user request
if (!cfg_active)
soft_reset <= 1;
end
// }}}
// wide_* and new_* write setup registers
// {{{
always @(*)
begin
wide_address = 0;
wide_address[C_AXI_ADDR_WIDTH-1:0] = cfg_frame_addr;
wide_address[ADDRLSB-1:0] = 0;
wide_config = { cfg_frame_lines, cfg_line_words,
{(ADDRLSB){1'b0}} };
end
assign new_cmdaddrlo = apply_wstrb(
wide_address[C_AXIL_DATA_WIDTH-1:0],
wskd_data, wskd_strb);
generate if (C_AXI_ADDR_WIDTH > 32)
begin : GEN_LARGE_AW
assign new_cmdaddrhi = apply_wstrb(
wide_address[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH],
wskd_data, wskd_strb);
end else begin : GEN_SINGLE_WORD_AW
assign new_cmdaddrhi = 0;
end endgenerate
wire [C_AXIL_DATA_WIDTH-1:0] new_control;
assign new_control = apply_wstrb(w_status_word, wskd_data, wskd_strb);
assign new_config = apply_wstrb(wide_config, wskd_data, wskd_strb);
always @(*)
begin
new_wideaddr = wide_address;
if (awskd_addr == FBUF_ADDRLO)
new_wideaddr[C_AXIL_DATA_WIDTH-1:0] = new_cmdaddrlo;
if (awskd_addr == FBUF_ADDRHI)
new_wideaddr[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH] = new_cmdaddrhi;
new_wideaddr[ADDRLSB-1:0] = 0;
new_wideaddr[2*C_AXIL_DATA_WIDTH-1:C_AXI_ADDR_WIDTH] = 0;
end
// }}}
// Configuration registers (Write)
// {{{
initial cfg_active = 0;
initial cfg_frame_addr = DEF_FRAMEADDR;
initial cfg_frame_addr[ADDRLSB-1:0] = 0;
initial cfg_line_words = DEF_WORDS_PER_LINE;
initial cfg_frame_lines = DEF_LINES_PER_FRAME;
initial cfg_zero_length = (DEF_WORDS_PER_LINE == 0)
||(DEF_LINES_PER_FRAME == 0);
always @(posedge i_clk)
if (i_reset)
begin
cfg_active <= DEF_ACTIVE_ON_RESET;
cfg_frame_addr <= DEF_FRAMEADDR;
cfg_line_words <= DEF_WORDS_PER_LINE;
cfg_line_step <= { DEF_WORDS_PER_LINE, {(ADDRLSB){1'b0}} };
cfg_frame_lines <= DEF_LINES_PER_FRAME;
cfg_zero_length <= (DEF_WORDS_PER_LINE==0)
||(DEF_LINES_PER_FRAME == 0);
cfg_dirty <= 0;
end else begin
if (r_stopped)
cfg_dirty <= 0;
if (cfg_active && req_hlast && req_vlast && phantom_start)
cfg_dirty <= 0;
if (M_AXI_RREADY && M_AXI_RVALID && M_AXI_RRESP[1])
cfg_active <= 0;
if (axil_write_ready)
case(awskd_addr)
FBUF_CONTROL: begin
if (wskd_strb[0])
cfg_active <= wskd_data[CBIT_ACTIVE]
&& (!r_err || wskd_data[CBIT_ERR])
&& (!cfg_zero_length);
if (new_control[31:16] == 0)
begin
cfg_line_step <= 0;
cfg_line_step[16-1:ADDRLSB] <= cfg_line_words;
// Verilator lint_off WIDTH
cfg_dirty <= (cfg_line_step
!= (cfg_line_words << ADDRLSB));
// Verilator lint_on WIDTH
end else begin
cfg_line_step <= new_control[31:16];
cfg_dirty <= (cfg_line_step != new_control[31:16]);
end end
FBUF_FRAMEINFO: begin
{ cfg_frame_lines, cfg_line_words }
<= new_config[C_AXI_DATA_WIDTH-1:ADDRLSB];
cfg_zero_length <= (new_config[31:16] == 0)
||(new_config[15:ADDRLSB] == 0);
if ((new_config[31:16] == 0)
||(new_config[15:ADDRLSB] == 0))
cfg_active <= 0;
cfg_dirty <= 1;
end
FBUF_ADDRLO, FBUF_ADDRHI: begin
cfg_frame_addr <= new_wideaddr[C_AXI_ADDR_WIDTH-1:0];
cfg_dirty <= 1;
end
default: begin end
endcase
end
// }}}
// AXI-Lite read register data
// {{{
always @(*)
begin
w_status_word = 0;
w_status_word[31:16] = cfg_line_step;
w_status_word[CBIT_DIRTY] = cfg_dirty;
w_status_word[CBIT_ERR] = r_err;
w_status_word[CBIT_BUSY] = !soft_reset;
w_status_word[CBIT_ACTIVE] = cfg_active || (!soft_reset || !r_stopped);
end
always @(posedge i_clk)
if (!axil_read_valid || S_AXIL_RREADY)
begin
axil_read_data <= 0;
case(arskd_addr)
FBUF_CONTROL: axil_read_data <= w_status_word;
FBUF_FRAMEINFO: axil_read_data <= { cfg_frame_lines,
cfg_line_words, {(ADDRLSB){1'b0}} };
FBUF_ADDRLO: axil_read_data <= wide_address[C_AXIL_DATA_WIDTH-1:0];
FBUF_ADDRHI: axil_read_data <= wide_address[2*C_AXIL_DATA_WIDTH-1:C_AXIL_DATA_WIDTH];
default axil_read_data <= 0;
endcase
end
// }}}
// apply_wstrb function for applying wstrbs to register words
// {{{
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
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// The data FIFO section
//
////////////////////////////////////////////////////////////////////////
//
// {{{
// {{{
assign reset_fifo = r_stopped;
assign write_to_fifo = M_AXI_RVALID;
assign write_data = M_AXI_RDATA;
// assign realign_last_valid = 0;
assign vlast = rd_vlast;
assign hlast = rd_hlast;
assign M_AXI_RREADY = !fifo_full;
// }}}
generate if (LGFIFO > 0)
begin : GEN_SPACE_AVAILBLE
// Here's where we'll put the actual outgoing FIFO
// {{{
initial fifo_space_available = (1<<LGFIFO);
always @(posedge i_clk)
if (reset_fifo)
fifo_space_available <= (1<<LGFIFO);
else case({phantom_start, read_from_fifo && !fifo_empty })
2'b00: begin end
// Verilator lint_off WIDTH
2'b10: fifo_space_available <= fifo_space_available - (M_AXI_ARLEN+1);
2'b11: fifo_space_available <= fifo_space_available - (M_AXI_ARLEN);
// Verilator lint_on WIDTH
2'b01: fifo_space_available <= fifo_space_available + 1;
endcase
assign M_AXIS_TVALID = !fifo_empty;
assign read_from_fifo = M_AXIS_TVALID && M_AXIS_TREADY;
sfifo #(.BW(C_AXI_DATA_WIDTH+2), .LGFLEN(LGFIFO))
sfifo(i_clk, reset_fifo,
write_to_fifo, { vlast && hlast, hlast, write_data },
fifo_full, fifo_fill,
read_from_fifo, { M_AXIS_VLAST, M_AXIS_HLAST,
M_AXIS_TDATA }, fifo_empty);
assign no_fifo_space_available = (fifo_space_available < (1<<LGMAXBURST));
// }}}
end else begin : NO_FIFO
// {{{
assign fifo_full = !M_AXIS_TREADY;
assign fifo_fill = 0;
assign fifo_empty = !M_AXIS_TVALID;
assign M_AXIS_TVALID = write_to_fifo;
assign M_AXIS_VLAST = vlast && hlast;
assign M_AXIS_HLAST = hlast;
assign M_AXIS_TDATA = M_AXI_RDATA;
assign no_fifo_space_available = (ar_bursts_outstanding >= 3);
// }}}
end endgenerate
// }}}
// Switch between TLAST/TUSER encodings if necessary
// {{{
generate if (OPT_TUSER_IS_SOF)
begin : XILINX_ENCODING
reg SOF;
initial SOF = 1'b1;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || r_stopped)
SOF <= 1'b1;
else if (M_AXIS_TVALID && M_AXIS_TREADY)
SOF <= M_AXIS_VLAST;
assign M_AXIS_TLAST = M_AXIS_HLAST;
assign M_AXIS_TUSER = SOF;
end else begin : VLAST_EQUALS_TLAST
assign M_AXIS_TLAST = M_AXIS_VLAST;
assign M_AXIS_TUSER = M_AXIS_HLAST;
end endgenerate
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// Outoing frame address counting
//
////////////////////////////////////////////////////////////////////////
//
//
// {{{
always @(posedge i_clk)
if (i_reset || r_stopped || (phantom_start && req_hlast && req_vlast))
begin
r_frame_lines <= cfg_frame_lines;
r_line_words <= cfg_line_words;
r_line_step <= { {(ADDRLSB){1'b0}}, cfg_line_step[15:ADDRLSB] };
end
initial req_addr = 0;
initial req_line_addr = 0;
always @(posedge i_clk)
if (i_reset || r_stopped)
begin
req_addr <= { 1'b0, cfg_frame_addr };
req_line_addr <= { 1'b0, cfg_frame_addr };
req_line_words <= cfg_line_words;
end else if (phantom_start)
begin
if (req_hlast && req_vlast)
begin
req_addr <= { 1'b0, cfg_frame_addr };
req_line_addr <= { 1'b0, cfg_frame_addr };
req_line_words <= cfg_line_words;
end else if (req_hlast)
begin
// verilator lint_off WIDTH
req_addr <= req_line_addr
+ (r_line_step << M_AXI_ARSIZE);
req_line_addr <= req_line_addr
+ (r_line_step << M_AXI_ARSIZE);
// verilator lint_on WIDTH
req_line_words <= r_line_words;
end else begin
// verilator lint_off WIDTH
req_addr <= req_addr + (1<<(LGMAXBURST+ADDRLSB));
req_line_words <= req_line_words - (M_AXI_ARLEN+1);
// verilator lint_on WIDTH
req_addr[LGMAXBURST+ADDRLSB-1:0] <= 0;
end
end
always @(posedge i_clk)
if (i_reset || r_stopped)
begin
req_nlines <= cfg_frame_lines-1;
req_vlast <= (cfg_frame_lines <= 1);
end else if (phantom_start && req_hlast)
begin
if (req_vlast)
begin
req_nlines <= cfg_frame_lines-1;
req_vlast <= (cfg_frame_lines <= 1);
end else begin
req_nlines <= req_nlines - 1;
req_vlast <= (req_nlines <= 1);
end
end
`ifdef FORMAL
always @(*)
if (!r_stopped)
begin
assert(req_vlast == (req_nlines == 0));
assert(req_addr >= { 1'b0, cfg_frame_addr });
assert(req_line_addr >= { 1'b0, cfg_frame_addr });
assert(req_line_addr <= req_addr);
end
always @(*)
if (cfg_active)
begin
assert(cfg_frame_lines != 0);
assert(cfg_line_words != 0);
end
always @(*)
if (!r_stopped)
begin
assert(r_frame_lines != 0);
assert(r_line_words != 0);
end
`endif
// }}}
////////////////////////////////////////////////////////////////////////
//
// Incoming frame address counting
//
////////////////////////////////////////////////////////////////////////
//
//
// {{{
always @(posedge i_clk)
if (i_reset || r_stopped)
begin
rd_line_beats <= cfg_line_words-1;
rd_hlast <= (cfg_line_words == 1);
end else if (M_AXI_RVALID && M_AXI_RREADY)
begin
if (rd_hlast)
begin
rd_line_beats <= r_line_words - 1;
rd_hlast <= (r_line_words <= 1);
end else begin
rd_line_beats <= rd_line_beats - 1;
rd_hlast <= (rd_line_beats <= 1);
end
end
always @(posedge i_clk)
if (i_reset || r_stopped)
begin
rd_lines <= cfg_frame_lines-1;
rd_vlast <= (cfg_frame_lines == 1);
end else if (M_AXI_RVALID && M_AXI_RREADY && rd_hlast)
begin
if (vlast)
begin
rd_lines <= r_frame_lines - 1;
rd_vlast <= (r_frame_lines <= 1);
end else begin
rd_lines <= rd_lines - 1;
rd_vlast <= (rd_lines <= 1);
end
end
`ifdef FORMAL
always @(posedge i_clk)
if (i_reset || r_stopped)
begin
f_rd_addr <= { 1'b0, cfg_frame_addr };
f_rd_line_addr <= { 1'b0, cfg_frame_addr };
end else if (M_AXI_RVALID && M_AXI_RREADY)
begin
if (rd_vlast && rd_hlast)
begin
f_rd_addr <= cfg_frame_addr;
f_rd_line_addr <= cfg_frame_addr;
end else if (rd_hlast)
begin
f_rd_addr <= f_rd_line_addr + (r_line_step << M_AXI_ARSIZE);
f_rd_line_addr <= f_rd_line_addr + (r_line_step << M_AXI_ARSIZE);
end else begin
f_rd_addr <= f_rd_addr + (1<<ADDRLSB);
end
end
`endif
// }}}
////////////////////////////////////////////////////////////////////////
//
// The incoming AXI (full) protocol section
//
////////////////////////////////////////////////////////////////////////
//
//
// {{{
// Some counters to keep track of our state
// {{{
// ar_bursts_outstanding
// {{{
// 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
// }}}
// r_stopped
// {{{
// Following an error or drop of cfg_active, soft_reset will go high.
// We then come to a stop once everything becomes inactive
initial r_stopped = 1;
always @(posedge i_clk)
if (i_reset)
r_stopped <= 1;
else if (r_stopped)
r_stopped <= soft_reset || !cfg_active;
else if (soft_reset && ar_none_outstanding && !M_AXI_ARVALID)
r_stopped <= 1;
// }}}
// }}}
//
// start_burst
// {{{
always @(*)
begin
start_burst = 1;
if (no_fifo_space_available)
start_burst = 0;
if (phantom_start || lag_start)
// Insist on a minimum of two clocks between burst
// starts, so we can get our lengths right
start_burst = 0;
// Can't start a new burst if the outgoing channel is still
// stalled.
if (M_AXI_ARVALID && !M_AXI_ARREADY)
start_burst = 0;
// If the user wants us to stop, then stop
if (!cfg_active || soft_reset)
start_burst = 0;
end
// }}}
// ARLEN
// {{{
// Coming in, req_addr and req_line_words can be trusted
// lag_start will be true to reflect this
always @(posedge i_clk)
if (lag_start)
begin
if (req_line_words >= (1<<LGMAXBURST))
max_burst <= (1<<LGMAXBURST);
else
// Verilator lint_off WIDTH
max_burst <= req_line_words;
// Verilator lint_on WIDTH
end
always @(*)
till_boundary = ~req_addr[ADDRLSB +: LGMAXBURST];
always @(posedge i_clk)
if (!M_AXI_ARVALID || M_AXI_ARREADY)
begin
// Verilator lint_off WIDTH
if (till_boundary > 0 && max_burst <= till_boundary)
axi_arlen <= max_burst-1;
// Verilator lint_on WIDTH
else
axi_arlen <= till_boundary;
end
// }}}
// req_hlast
// {{{
always @(posedge i_clk)
if (lag_start || start_burst)
begin
req_hlast <= 1;
// Verilator lint_off WIDTH
if (req_line_words > till_boundary+1)
req_hlast <= 0;
if (req_line_words > max_burst)
req_hlast <= 0;
// Verilator lint_on WIDTH
end
`ifdef FORMAL
always @(*)
if (phantom_start)
begin
if (req_hlast)
begin
assert(axi_arlen+1 == req_line_words);
end else
assert(axi_arlen+1 < req_line_words);
end else if (!soft_reset && !r_stopped && !lag_start)
begin
if (max_burst != req_line_words)
begin
assert(!req_hlast);
end else if (!req_hlast && !M_AXI_ARVALID)
assert(axi_arlen < max_burst);
assert(max_burst > 0);
if (req_line_words > (1<<LGMAXBURST))
begin
assert(max_burst == (1<<LGMAXBURST));