-
Notifications
You must be signed in to change notification settings - Fork 2
/
openadc_interface.v
1229 lines (1076 loc) · 47.2 KB
/
openadc_interface.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
`include "includes.v"
`timescale 1 ns / 1 ps
`default_nettype none
/***********************************************************************
This file is part of the ChipWhisperer Project. See www.newae.com for more
details, or the codebase at http://www.chipwhisperer.com
Copyright (c) 2012-2021, NewAE Technology Inc. All rights reserved.
Author: Colin O'Flynn <[email protected]>
chipwhisperer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
chipwhisperer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
along with chipwhisperer. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************/
module openadc_interface #(
parameter pBYTECNT_SIZE = 7
)(
input wire clk_usb, // 96 MHz
input wire ADC_slow_clk_even, // used by sad_x2_slowclock only
input wire ADC_slow_clk_odd, // used by sad_x2_slowclock only
input wire ADC_slow_clk1, // used by sad_x4_slowclock only
input wire ADC_slow_clk2, // used by sad_x4_slowclock only
input wire ADC_slow_clk3, // used by sad_x4_slowclock only
input wire ADC_slow_clk4, // used by sad_x4_slowclock only
output wire reset_o,
input wire xadc_error,
output reg LED_armed, // Armed LED
output reg LED_capture, // Capture in Progress LED (only illuminate during capture, very quick)
output reg freq_measure,
output wire O_disable_adc_error,
// OpenADC Interface Pins
input wire [11:0] ADC_data,
input wire ADC_clk_feedback, // Feedback path for ADC Clock. If unused connect to ADC_clk_out
input wire pll_fpga_clk,
input wire PLL_STATUS,
input wire DUT_CLK_i, // target_hs1
input wire DUT_trigger_i,
input wire trigger_io4_i, // debug only
input wire sad_active,
input wire sad_trigger_in_use,
input wire edge_trigger_active,
input wire adc_trigger_active,
output reg trigger_adc,
output wire trigger_sad,
output wire trigger_edge_counter,
output wire amp_gain,
output wire [7:0] fifo_dout,
input wire trace_flushing,
input wire la_flushing,
input wire shared_fifo_empty,
// register interface
input wire [7:0] reg_address,
input wire [pBYTECNT_SIZE-1:0] reg_bytecnt,
input wire [7:0] reg_datai,
output wire [7:0] reg_datao,
input wire reg_read,
input wire reg_write,
output wire fast_fifo_read,
output wire fifo_error_flag,
output wire stream_segment_available,
output wire capture_active,
input wire trigger_in,
output reg flash_pattern,
// for UART triggering:
output wire cmd_arm_usb,
`ifdef PRO
// DDR3 (Pro) stuff:
output wire O_xo_en,
output wire O_vddr_enable,
input wire I_vddr_pgood,
output wire [15:0] ddr3_addr,
output wire [2:0] ddr3_ba,
output wire ddr3_cas_n,
output wire ddr3_ck_n,
output wire ddr3_ck_p,
output wire ddr3_cke,
output wire ddr3_ras_n,
output wire ddr3_reset_n,
output wire ddr3_we_n,
inout wire [7:0] ddr3_dq,
inout wire ddr3_dqs_n,
inout wire ddr3_dqs_p,
output wire ddr3_dm,
output wire ddr3_cs_n,
output wire ddr3_odt,
input wire [11:0] temp_out,
// for LA and trace in Pro:
output wire ui_clk,
output wire preddr_trace_rd,
input wire [63:0] preddr_trace_data,
input wire preddr_trace_empty,
output wire preddr_la_rd,
input wire [63:0] preddr_la_data,
input wire preddr_la_empty,
input wire capture_go_trace,
input wire capture_go_la,
input wire write_done_trace,
input wire write_done_la,
output wire clear_fifo_errors,
input wire [1:0] trace_fifo_errors,
input wire [1:0] la_fifo_errors,
input wire tb_ui_clk,
`ifdef CW310
input wire ADC_clk_fbp,
input wire ADC_clk_fbn,
`endif
`endif
// for trigger sequencing:
output wire armed_and_ready,
// for debug only:
output wire slow_fifo_wr,
output wire slow_fifo_rd,
output wire [8:0] la_debug,
output wire [7:0] la_debug2,
output wire [7:0] sad_debug,
output wire [7:0] fifo_debug,
output wire [7:0] edge_trigger_debug
);
wire ADC_clk_sample;
wire armed;
wire capture_go;
wire adc_capture_done;
wire reset;
wire fast_fifo_empty;
wire fifo_stream;
wire [15:0] num_segments;
wire [19:0] segment_cycles;
wire segment_cycle_counter_en;
wire [1:0] led_select;
wire data_source_select;
wire [13:0] fifo_error_stat;
wire [13:0] fifo_first_error_stat;
wire [2:0] fifo_first_error_state;
wire no_clip_errors;
wire no_gain_errors;
wire capture_done;
wire [2:0] fifo_state;
wire [2:0] ddr_state;
wire trigger_too_soon;
wire adc_flushing;
wire postddr_flush;
wire single_write;
wire single_read;
wire [29:0] single_address;
wire [63:0] single_write_data;
wire [63:0] single_read_data;
wire ddr_read_data_done;
wire [29:0] ddr_la_start_address;
wire [29:0] ddr_trace_start_address;
wire ddr_start_la_read;
wire ddr_start_trace_read;
wire ddr_start_adc_read;
wire ddr_single_done;
wire ddr_write_data_done;
wire [6:0] ddr_stat;
wire ddr_test_pass;
wire ddr_test_fail;
wire ddr_test_clear_fail;
wire ddr_rwtest_en;
wire use_ddr;
assign reset_o = reset;
reg extclk_change;
reg extclk_change_usb;
wire extclk_monitor_disabled;
wire [31:0] extclk_limit;
`ifndef PRO
wire clear_fifo_errors;
wire preddr_trace_empty = 1'b1;
wire preddr_la_empty = 1'b1;
`endif
//Divide clock by 2^24 for heartbeat LED
//Divide clock by 2^23 for frequency measurement
reg [25:0] timer_heartbeat;
reg timer_heartbeat22r;
always @(posedge clk_usb)
if (reset) begin
timer_heartbeat <= 26'b0;
timer_heartbeat22r <= 1'b0;
freq_measure <= 1'b0;
end
else begin
timer_heartbeat <= timer_heartbeat + 26'd1;
timer_heartbeat22r <= timer_heartbeat[22];
if (timer_heartbeat[22] && ~timer_heartbeat22r)
freq_measure <= 1'b1;
else
freq_measure <= 1'b0;
end
reg [24:0] clkgen_heartbeat;
always @(posedge clk_usb) clkgen_heartbeat <= clkgen_heartbeat + 25'd1;
reg [24:0] adc_fb_heartbeat;
always @(posedge ADC_clk_feedback) adc_fb_heartbeat <= adc_fb_heartbeat + 25'd1;
reg [24:0] adc_out_heartbeat;
always @(posedge DUT_CLK_i) adc_out_heartbeat <= adc_out_heartbeat + 25'd1;
reg [24:0] pll_fpga_clk_heartbeat;
always @(posedge pll_fpga_clk) pll_fpga_clk_heartbeat <= pll_fpga_clk_heartbeat + 25'd1;
always @(posedge clk_usb) begin
if (timer_heartbeat[25])
flash_pattern <= ~timer_heartbeat[23];
end
always @(*) begin
if (extclk_change_usb) begin
LED_armed = flash_pattern;
LED_capture = flash_pattern;
end
else if (led_select == 2'b01) begin
LED_armed = timer_heartbeat[24];
LED_capture = clkgen_heartbeat[24];
end
else if (led_select == 2'b10) begin
LED_armed = adc_fb_heartbeat[24];
LED_capture = adc_out_heartbeat[24];
end
else if (led_select == 2'b11) begin
LED_armed = pll_fpga_clk_heartbeat[24];
LED_capture = extclk_change_usb;
end
else begin
LED_armed = armed;
LED_capture = capture_active;
end
end
wire freq_measure_adc;
wire freq_measure_ui;
wire freq_measure_pll;
wire freq_measure_ext;
cdc_pulse U_freq_measure_adc (
.reset_i (reset),
.src_clk (clk_usb),
.src_pulse (freq_measure),
.dst_clk (ADC_clk_sample),
.dst_pulse (freq_measure_adc)
);
cdc_pulse U_freq_measure_pll (
.reset_i (reset),
.src_clk (clk_usb),
.src_pulse (freq_measure),
.dst_clk (pll_fpga_clk),
.dst_pulse (freq_measure_pll)
);
cdc_pulse U_freq_measure_ext (
.reset_i (reset),
.src_clk (clk_usb),
.src_pulse (freq_measure),
.dst_clk (DUT_CLK_i),
.dst_pulse (freq_measure_ext)
);
// ...and CDC the above pulses back to USB so we know if they're alive!
wire freq_measure_adc_back;
wire freq_measure_ui_back;
wire freq_measure_pll_back;
wire freq_measure_ext_back;
cdc_pulse U_freq_measure_adc_back (
.reset_i (reset),
.src_clk (ADC_clk_sample),
.src_pulse (freq_measure_adc),
.dst_clk (clk_usb),
.dst_pulse (freq_measure_adc_back)
);
cdc_pulse U_freq_measure_pll_back (
.reset_i (reset),
.src_clk (pll_fpga_clk),
.src_pulse (freq_measure_pll),
.dst_clk (clk_usb),
.dst_pulse (freq_measure_pll_back)
);
cdc_pulse U_freq_measure_ext_back (
.reset_i (reset),
.src_clk (DUT_CLK_i),
.src_pulse (freq_measure_ext),
.dst_clk (clk_usb),
.dst_pulse (freq_measure_ext_back)
);
reg adc_back;
reg pll_back;
reg ext_back;
reg adc_alive;
reg pll_alive;
reg ext_alive;
always @(posedge clk_usb) begin
if (freq_measure) begin
adc_back <= 1'b0;
pll_back <= 1'b0;
ext_back <= 1'b0;
if (adc_back) adc_alive <= 1'b1;
else adc_alive <= 1'b0;
if (pll_back) pll_alive <= 1'b1;
else pll_alive <= 1'b0;
if (ext_back) ext_alive <= 1'b1;
else ext_alive <= 1'b0;
end
else begin
if (freq_measure_adc_back)
adc_back <= 1'b1;
if (freq_measure_pll_back)
pll_back <= 1'b1;
if (freq_measure_ext_back)
ext_back <= 1'b1;
end
end
reg [31:0] extclk_frequency_int;
reg [31:0] adcclk_frequency_int;
reg [31:0] pllclk_frequency_int;
reg [31:0] extclk_frequency;
reg [31:0] adcclk_frequency;
reg [31:0] pllclk_frequency;
always @(posedge DUT_CLK_i) begin
if (freq_measure_ext) begin
extclk_frequency_int <= 32'd1;
extclk_frequency <= extclk_frequency_int;
end
else begin
extclk_frequency_int <= extclk_frequency_int + 32'd1;
end
if (extclk_monitor_disabled)
extclk_change <= 1'b0;
else if (freq_measure_ext && (extclk_frequency_int > 0) &&
( (extclk_frequency > extclk_frequency_int)? ((extclk_frequency - extclk_frequency_int) > extclk_limit) :
((extclk_frequency_int - extclk_frequency) > extclk_limit) )
)
extclk_change <= 1'b1;
end
// replicate some of the logic above in clk_usb domain so that clearing the error works when DUT_CLK_i goes away:
always @(posedge clk_usb) begin
if (extclk_monitor_disabled)
extclk_change_usb <= 1'b0;
else if (freq_measure_ext_back)
extclk_change_usb <= extclk_change;
end
always @(posedge ADC_clk_sample) begin
if (freq_measure_adc) begin
adcclk_frequency_int <= 32'd1;
adcclk_frequency <= adcclk_frequency_int;
end
else begin
adcclk_frequency_int <= adcclk_frequency_int + 32'd1;
end
end
wire [31:0] extclk_frequency_masked = (ext_alive)? extclk_frequency : 32'b0;
wire [31:0] adcclk_frequency_masked = (adc_alive)? adcclk_frequency : 32'b0;
wire [31:0] pllclk_frequency_masked = (pll_alive)? pllclk_frequency : 32'b0;
`ifdef PRO
reg [31:0] uiclk_frequency_int;
reg [31:0] uiclk_frequency;
always @(posedge ui_clk) begin
if (freq_measure_ui) begin
uiclk_frequency_int <= 32'd1;
uiclk_frequency <= uiclk_frequency_int;
end
else begin
uiclk_frequency_int <= uiclk_frequency_int + 32'd1;
end
end
reg ui_back;
reg ui_alive;
always @(posedge clk_usb) begin
if (freq_measure) begin
ui_back <= 1'b0;
if (ui_back) ui_alive <= 1'b1;
else ui_alive <= 1'b0;
end
else begin
if (freq_measure_ui_back)
ui_back <= 1'b1;
end
end
wire [31:0] uiclk_frequency_masked = (ui_alive)? uiclk_frequency : 32'b0;
cdc_pulse U_freq_measure_ui (
.reset_i (reset),
.src_clk (clk_usb),
.src_pulse (freq_measure),
.dst_clk (ui_clk),
.dst_pulse (freq_measure_ui)
);
cdc_pulse U_freq_measure_ui_back (
.reset_i (reset),
.src_clk (ui_clk),
.src_pulse (freq_measure_ui),
.dst_clk (clk_usb),
.dst_pulse (freq_measure_ui_back)
);
`else
wire [31:0] uiclk_frequency_masked = 32'b0;
`endif // PRO
always @(posedge pll_fpga_clk) begin
if (freq_measure_pll) begin
pllclk_frequency_int <= 32'd1;
pllclk_frequency <= pllclk_frequency_int;
end
else begin
pllclk_frequency_int <= pllclk_frequency_int + 32'd1;
end
end
reg [11:0] ADC_data_tofifo_pre;
reg [11:0] ADC_data_tofifo;
reg [11:0] datacounter = 0;
wire [11:0] trigger_adclevel;
always @(posedge ADC_clk_sample) begin
ADC_data_tofifo <= ADC_data_tofifo_pre; // resample to account for delay in fifo_top_husky.v
ADC_data_tofifo_pre <= data_source_select? ADC_data : datacounter;
datacounter <= datacounter + 1;
end
wire [7:0] reg_status;
wire fifo_overflow;
//1 = trigger on high, 0 = trigger on low
wire trigger_mode;
//1 = wait for trigger to be INACTIVE before arming (e.g.: avoid triggering immediatly)
//0 = arm as soon as cmd_arm goes high (e.g.: if trigger is already in active state, trigger)
wire trigger_wait;
wire cmd_arm_adc;
wire trigger_now;
wire [31:0] trigger_offset;
wire [31:0] trigger_length;
trigger_unit tu_inst(
.reset (reset),
.adc_clk (ADC_clk_sample),
.trigger (DUT_trigger_i),
.trigger_level_i (trigger_mode),
.trigger_now_i (trigger_now),
.trigger_wait_i (trigger_wait),
.arm_i (cmd_arm_adc),
.arm_o (armed),
.trigger_offset_i (trigger_offset),
.trigger_length_o (trigger_length),
.capture_active_o (capture_active),
.capture_go_o (capture_go),
.capture_done_i (adc_capture_done),
.armed_and_ready (armed_and_ready),
.trigger_too_soon (trigger_too_soon),
.cmd_arm_usb (cmd_arm_usb),
.debug2 (la_debug2),
.la_debug (la_debug)
);
reg triggered;
reg armed_and_ready_r;
// ADC trigger is simple except that we only want a single trigger generated:
always @(posedge ADC_clk_sample) begin
if (reset) begin
triggered <= 1'b0;
trigger_adc <= 1'b0;
armed_and_ready_r <= 1'b0;
end
else begin
armed_and_ready_r <= armed_and_ready;
if (~triggered && adc_trigger_active && armed_and_ready_r)
trigger_adc <= trigger_adclevel[11]? ADC_data_tofifo > trigger_adclevel:
ADC_data_tofifo < trigger_adclevel;
else
trigger_adc <= 1'b0;
if (trigger_adc)
triggered <= 1'b1;
else if (armed_and_ready && ~armed_and_ready_r)
triggered <= 1'b0;
end
end
`ifdef ILA_ADC_TRIG
ila_adc_trig U_ila_adc_trig (
.clk (clk_usb), // input wire clk
.probe0 (trigger_adc), // input wire [0:0] probe0
.probe1 (triggered), // input wire [0:0] probe1
.probe2 (trigger_adclevel), // input wire [11:0] probe2
.probe3 (ADC_data_tofifo), // input wire [11:0] probe3
.probe4 (armed_and_ready) // input wire [0:0] probe4
);
`endif
assign reg_status[0] = armed;
assign reg_status[1] = ~capture_active;
assign reg_status[2] = DUT_trigger_i;
assign reg_status[3] = 1'b0;
assign reg_status[4] = PLL_STATUS;
assign reg_status[5] = 1'b0;
assign reg_status[6] = 1'b0;
assign reg_status[7] = fifo_overflow;
wire [7:0] PWM_incr;
wire fifo_empty;
wire fifo_rd_en;
wire low_res;
wire low_res_lsb;
wire [16:0] stream_segment_threshold;
wire [14:0] presamples;
wire [31:0] maxsamples_limit;
wire [31:0] maxsamples;
wire [12:0] downsample;
wire [7:0] reg_datao_oadc;
wire [7:0] reg_datao_fifo;
wire [7:0] reg_datao_sad;
wire [7:0] reg_datao_edge;
wire [31:0] fifo_read_count;
wire [31:0] fifo_read_count_error_freeze;
wire [7:0] underflow_count;
wire no_underflow_errors;
wire [15:0] ddr_test_iteration;
wire [7:0] ddr_test_errors;
wire [31:0] ddr_read_read;
wire [31:0] ddr_read_idle;
wire [31:0] ddr_write_write;
wire [31:0] ddr_write_idle;
wire [15:0] ddr_max_read_stall_count;
wire [15:0] ddr_max_write_stall_count;
assign reg_datao = reg_datao_oadc | reg_datao_fifo | reg_datao_sad | reg_datao_edge;
`ifdef PLUS
localparam pREF_SAMPLES = 512;
localparam pSAD_COUNTER_WIDTH = 14;
localparam pNUM_GROUPS = 16;
`elsif PRO
localparam pREF_SAMPLES = 736;
localparam pSAD_COUNTER_WIDTH = 14;
`else
localparam pREF_SAMPLES = 512;
localparam pSAD_COUNTER_WIDTH = 12;
localparam pNUM_GROUPS = 16;
`endif
`ifdef SAD_X2
sad_x2_slowclock #(
.pBYTECNT_SIZE (pBYTECNT_SIZE),
.pREF_SAMPLES (pREF_SAMPLES),
.pSAD_COUNTER_WIDTH (pSAD_COUNTER_WIDTH),
.pBITS_PER_SAMPLE (8)
) U_sad (
.reset (reset ),
.xadc_error (xadc_error ),
.adc_datain (ADC_data_tofifo[11:4]),
.adc_sampleclk (ADC_clk_sample),
.slow_clk_even (ADC_slow_clk_even),
.slow_clk_odd (ADC_slow_clk_odd),
.armed_and_ready (armed_and_ready),
.active (sad_trigger_in_use),
.trigger_allowed (sad_active ),
.clk_usb (clk_usb ),
.reg_address (reg_address ),
.reg_bytecnt (reg_bytecnt ),
.reg_datai (reg_datai ),
.reg_datao (reg_datao_sad),
.reg_read (reg_read ),
.reg_write (reg_write ),
.ext_trigger (DUT_trigger_i),
.io4 (trigger_io4_i),
.trigger (trigger_sad )
);
`elsif SAD_X4
sad_x4_slowclock #(
.pBYTECNT_SIZE (pBYTECNT_SIZE),
.pREF_SAMPLES (pREF_SAMPLES),
.pSAD_COUNTER_WIDTH (pSAD_COUNTER_WIDTH),
.pBITS_PER_SAMPLE (8)
) U_sad (
.reset (reset ),
.xadc_error (xadc_error ),
.adc_datain (ADC_data_tofifo[11:4]),
.adc_sampleclk (ADC_clk_sample),
.slow_clk1 (ADC_slow_clk1),
.slow_clk2 (ADC_slow_clk2),
.slow_clk3 (ADC_slow_clk3),
.slow_clk4 (ADC_slow_clk4),
.armed_and_ready (armed_and_ready),
.active (sad_trigger_in_use),
.trigger_allowed (sad_active ),
.clk_usb (clk_usb ),
.reg_address (reg_address ),
.reg_bytecnt (reg_bytecnt ),
.reg_datai (reg_datai ),
.reg_datao (reg_datao_sad),
.reg_read (reg_read ),
.reg_write (reg_write ),
.ext_trigger (DUT_trigger_i),
.io4 (trigger_io4_i),
.trigger (trigger_sad )
);
`elsif SAD_X2B
sad_x2 #(
.pBYTECNT_SIZE (pBYTECNT_SIZE),
.pREF_SAMPLES (pREF_SAMPLES),
.pSAD_COUNTER_WIDTH (pSAD_COUNTER_WIDTH),
.pBITS_PER_SAMPLE (8)
) U_sad (
.reset (reset ),
.xadc_error (xadc_error ),
.adc_datain (ADC_data_tofifo[11:4]),
.adc_sampleclk (ADC_clk_sample),
.armed_and_ready (armed_and_ready),
.active (sad_trigger_in_use),
.trigger_allowed (sad_active ),
.clk_usb (clk_usb ),
.reg_address (reg_address ),
.reg_bytecnt (reg_bytecnt ),
.reg_datai (reg_datai ),
.reg_datao (reg_datao_sad),
.reg_read (reg_read ),
.reg_write (reg_write ),
.ext_trigger (DUT_trigger_i),
.io4 (trigger_io4_i),
.trigger (trigger_sad )
);
`elsif SAD_SINGLE
sad_single_counter #(
.pBYTECNT_SIZE (pBYTECNT_SIZE),
.pREF_SAMPLES (pREF_SAMPLES),
.pSAD_COUNTER_WIDTH (pSAD_COUNTER_WIDTH),
.pBITS_PER_SAMPLE (8)
) U_sad (
.reset (reset ),
.xadc_error (xadc_error ),
.adc_datain (ADC_data_tofifo[11:4]),
.adc_sampleclk (ADC_clk_sample),
.armed_and_ready (armed_and_ready),
.active (sad_trigger_in_use),
.trigger_allowed (sad_active ),
.clk_usb (clk_usb ),
.reg_address (reg_address ),
.reg_bytecnt (reg_bytecnt ),
.reg_datai (reg_datai ),
.reg_datao (reg_datao_sad),
.reg_read (reg_read ),
.reg_write (reg_write ),
.ext_trigger (DUT_trigger_i),
.io4 (trigger_io4_i),
.trigger (trigger_sad )
);
`elsif ESAD
esad #(
.pBYTECNT_SIZE (pBYTECNT_SIZE),
.pREF_SAMPLES (pREF_SAMPLES),
.pSAD_COUNTER_WIDTH (pSAD_COUNTER_WIDTH),
.pBITS_PER_SAMPLE (8),
.pNUM_GROUPS (pNUM_GROUPS)
) U_sad (
.reset (reset ),
.xadc_error (xadc_error ),
.adc_datain (ADC_data_tofifo[11:4]),
.adc_sampleclk (ADC_clk_sample),
.armed_and_ready (armed_and_ready),
.active (sad_trigger_in_use),
.trigger_allowed (sad_active ),
.clk_usb (clk_usb ),
.reg_address (reg_address ),
.reg_bytecnt (reg_bytecnt ),
.reg_datai (reg_datai ),
.reg_datao (reg_datao_sad),
.reg_read (reg_read ),
.reg_write (reg_write ),
.ext_trigger (DUT_trigger_i),
.io4 (trigger_io4_i),
.sad_debug (sad_debug ),
.trigger (trigger_sad )
);
`else
sad #(
.pBYTECNT_SIZE (pBYTECNT_SIZE),
.pREF_SAMPLES (pREF_SAMPLES),
.pSAD_COUNTER_WIDTH (pSAD_COUNTER_WIDTH),
.pBITS_PER_SAMPLE (8),
.pNUM_GROUPS (pNUM_GROUPS)
) U_sad (
.reset (reset ),
.xadc_error (xadc_error ),
.adc_datain (ADC_data_tofifo[11:4]),
.adc_sampleclk (ADC_clk_sample),
.armed_and_ready (armed_and_ready),
.active (sad_trigger_in_use),
.trigger_allowed (sad_active ),
.clk_usb (clk_usb ),
.reg_address (reg_address ),
.reg_bytecnt (reg_bytecnt ),
.reg_datai (reg_datai ),
.reg_datao (reg_datao_sad),
.reg_read (reg_read ),
.reg_write (reg_write ),
.ext_trigger (DUT_trigger_i),
.io4 (trigger_io4_i),
.trigger (trigger_sad )
);
`endif
edge_trigger #(
.pBYTECNT_SIZE (pBYTECNT_SIZE)
) U_edge_trigger (
.reset (reset ),
.trigger_in (trigger_in ),
.adc_sampleclk (ADC_clk_sample),
.armed_and_ready (armed_and_ready),
.active (edge_trigger_active),
.clk_usb (clk_usb ),
.reg_address (reg_address ),
.reg_bytecnt (reg_bytecnt ),
.reg_datai (reg_datai ),
.reg_datao (reg_datao_edge),
.reg_read (reg_read ),
.reg_write (reg_write ),
.trigger (trigger_edge_counter),
.debug (edge_trigger_debug)
);
reg_openadc #(
.pBYTECNT_SIZE (pBYTECNT_SIZE),
.pTRIGGER_FIFO_WIDTH (32),
`ifdef PLUS
.pTRIGGER_FIFO_DEPTH (2048) // TODO: TBD max size
`else
.pTRIGGER_FIFO_DEPTH (1024)
`endif
) U_reg_openadc (
.reset_i (1'b0),
.reset_o (reset),
.clk_usb (clk_usb),
.adc_sampleclk (ADC_clk_sample),
.reg_address (reg_address),
.reg_bytecnt (reg_bytecnt),
.reg_datao (reg_datao_oadc),
.reg_datai (reg_datai),
.reg_read (reg_read),
.reg_write (reg_write),
.gain (PWM_incr),
.status (reg_status),
.cmd_arm_adc (cmd_arm_adc),
.cmd_arm_usb (cmd_arm_usb),
.trigger_mode (trigger_mode),
.trigger_wait (trigger_wait),
.trigger_adclevel (trigger_adclevel),
.trigger_now (trigger_now),
.trigger_offset (trigger_offset),
.trigger_length (trigger_length),
.extclk_frequency (extclk_frequency_masked),
.adcclk_frequency (adcclk_frequency_masked),
.uiclk_frequency (uiclk_frequency_masked),
.pllclk_frequency (pllclk_frequency_masked),
.presamples_o (presamples),
.maxsamples_i (maxsamples_limit),
.maxsamples_o (maxsamples),
.downsample_o (downsample),
.clkblock_dcm_locked_i (1'b0),
.clkblock_gen_locked_i (1'b0),
.fifo_stream (fifo_stream),
.num_segments (num_segments),
.segment_cycles (segment_cycles),
.segment_cycle_counter_en (segment_cycle_counter_en),
.led_select (led_select),
.no_clip_errors (no_clip_errors),
.no_gain_errors (no_gain_errors),
.trigger_event (capture_go),
.extclk_change (extclk_change_usb),
.extclk_monitor_disabled (extclk_monitor_disabled),
.extclk_limit (extclk_limit),
.O_disable_adc_error (O_disable_adc_error)
);
`ifndef PRO
wire ui_clk = 1'b0;
wire [1:0] trace_fifo_errors = 2'b0;
wire [1:0] la_fifo_errors = 2'b0;
wire O_xo_en;
wire O_vddr_enable;
wire I_vddr_pgood = 1'b0;
`endif
reg_openadc_adcfifo #(
.pBYTECNT_SIZE (pBYTECNT_SIZE)
) U_reg_openadc_adcfifo (
.reset_i (reset),
.clk_usb (clk_usb),
.ui_clk (ui_clk),
.reg_address (reg_address),
.reg_bytecnt (reg_bytecnt),
.reg_datao (reg_datao_fifo),
.reg_datai (reg_datai),
.reg_read (reg_read),
.reg_write (reg_write),
.state ({ddr_state, 1'b0, fifo_state}),
.fifo_empty (fifo_empty),
.fifo_rd_en (fifo_rd_en),
.low_res (low_res),
.low_res_lsb (low_res_lsb),
.fast_fifo_read_mode (fast_fifo_read),
.stream_segment_threshold (stream_segment_threshold),
.fifo_error_stat (fifo_error_stat),
.fifo_first_error_stat (fifo_first_error_stat),
.fifo_first_error_state (fifo_first_error_state),
.fifo_read_count (fifo_read_count),
.fifo_read_count_error_freeze (fifo_read_count_error_freeze),
.underflow_count (underflow_count),
.no_underflow_errors (no_underflow_errors),
.clear_fifo_errors (clear_fifo_errors),
.capture_done (capture_done),
.O_data_source_select (data_source_select),
.trace_fifo_errors (trace_fifo_errors),
.la_fifo_errors (la_fifo_errors),
.adc_flushing (adc_flushing),
.la_flushing (la_flushing),
.trace_flushing (trace_flushing),
.postddr_flush (postddr_flush),
.preddr_adc_fifo_empty (preddr_adc_fifo_empty),
.preddr_la_empty (preddr_la_empty),
.preddr_trace_empty (preddr_trace_empty),
.fast_fifo_empty (fast_fifo_empty),
.shared_fifo_empty (shared_fifo_empty),
.ddr_single_write (single_write ),
.ddr_single_read (single_read ),
.ddr_single_address (single_address ),
.ddr_single_write_data (single_write_data ),
.ddr_single_read_data (single_read_data ),
.ddr_read_data_done (ddr_read_data_done),
.ddr_single_done (ddr_single_done ),
.ddr_write_data_done (ddr_write_data_done ),
.ddr_la_start_address (ddr_la_start_address ),
.ddr_trace_start_address (ddr_trace_start_address ),
.ddr_start_la_read (ddr_start_la_read ),
.ddr_start_trace_read (ddr_start_trace_read ),
.ddr_start_adc_read (ddr_start_adc_read ),
.O_use_ddr (use_ddr ),
.O_ddr3_rwtest_en (ddr_rwtest_en ),
.O_xo_en (O_xo_en ),
.O_vddr_enable (O_vddr_enable ),
.I_vddr_pgood (I_vddr_pgood ),
.I_ddr3_pass (ddr_test_pass ),
.I_ddr3_fail (ddr_test_fail ),
.O_ddr3_clear_fail (ddr_test_clear_fail ),
.I_ddr3_stat (ddr_stat ),
.I_ddr3_iteration (ddr_test_iteration ),
.I_ddr3_errors (ddr_test_errors ),
.I_ddr3_read_read (ddr_read_read ),
.I_ddr3_read_idle (ddr_read_idle ),
.I_ddr3_write_write (ddr_write_write ),
.I_ddr3_write_idle (ddr_write_idle ),
.I_ddr3_max_read_stall_count (ddr_max_read_stall_count ),
.I_ddr3_max_write_stall_count (ddr_max_write_stall_count )
);
clock_managment_advanced genclocks(
.ADC_clk_feedback (ADC_clk_feedback),
.ADC_clk_sample (ADC_clk_sample)
);
reg [8:0] PWM_accumulator;
always @(posedge clk_usb) begin
if (reset)
PWM_accumulator <= 0;
else
PWM_accumulator <= PWM_accumulator[7:0] + PWM_incr;
end
assign amp_gain = PWM_accumulator[8];
`ifdef SAD_ONLY
assign armed_and_ready = 1'b1;
wire preddr_adc_fifo_empty = 1'b1;
`else
`ifdef PRO
wire capture_go_adc;
wire write_done_adc;
wire preddr_adc_fifo_rd;
wire [63:0] preddr_adc_fifo_dout;
wire preddr_adc_fifo_empty;
wire preddr_adc_fifo_underflow;
wire postddr_fifo_overflow;
wire postddr_fifo_underflow_masked;
wire error_flag; // TODO: nothing driving this?
wire fifo_overflow_noddr;
wire arm_pulse_usb;
wire reading_too_soon_error;
wire ddr_full_error;
wire source_flushing = adc_flushing || la_flushing || trace_flushing;
fifo_top_husky_pro U_fifo (
.reset (reset),
.adc_datain (ADC_data_tofifo),
.adc_sampleclk (ADC_clk_sample),
.capture_active (capture_active),
.capture_go (capture_go),
.adc_capture_stop (adc_capture_done),
.arm_i (armed),
.arm_usb (cmd_arm_usb),
.num_segments (num_segments),
.segment_cycles (segment_cycles),
.segment_cycle_counter_en (segment_cycle_counter_en),
.clk_usb (clk_usb),
.presample_i (presamples),
.max_samples_i (maxsamples),
.max_samples_o (maxsamples_limit),
.downsample_i (downsample),
.fifo_overflow (fifo_overflow_noddr),
.reading_too_soon_error (reading_too_soon_error),
.ddr_full_error (ddr_full_error),
.error_flag (fifo_error_flag),
.error_stat (fifo_error_stat),
.first_error_stat (fifo_first_error_stat),
.first_error_state (fifo_first_error_state),