forked from peterotte/A2ExpTrigger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvuprom_tdc_v3.vhd
783 lines (670 loc) · 26.8 KB
/
vuprom_tdc_v3.vhd
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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Library UNISIM;
use UNISIM.vcomponents.all;
entity vuprom_CBMaster is
Port (
--............................. VME Signals ............................................
AD : inout std_logic_vector(31 downto 0); --VME Address-Data bus
ASI : in std_logic; -- Address strobe
WRI : in std_logic; -- Write
BERRO : out std_logic; -- bus error for chain block transfer
DS0I, DS1I : in std_logic; -- data strobe
DACKP : in std_logic; -- acknowledge over CPLD (CON(0))
IACKII, IACK : in std_logic; -- interrupt acknowledge chain
IRBLO, IACKOU : out std_logic; -- interrupt acknowledge chain
--............................. DSP control signals ............................................
AHOLD, ARDY : out std_logic; --
AHOLDA, AECKO : in std_logic; --
AOE, ARE, AWE : in std_logic; --
AS : in std_logic_vector(19 downto 0); -- address bus of EMIFA
DS : inout std_logic_vector(31 downto 0); -- data bus
DSPRS, NMI : inout std_logic; --
INT : inout std_logic_vector(7 downto 4); --
TINP : out std_logic_vector(2 downto 0); --
TOUT : in std_logic_vector(2 downto 0); --
AECKO1 : in std_logic; -- clock from DSP 100MHz for SDRAM
CEL : in std_logic_vector(3 downto 0); --
BCLK, BHOLD, BRDY : out std_logic; -- EMIF_B, not used
CLKR0, CLKS0, CLKX0, DX, FSR0, FSX0, DR0, DX0 : in std_logic; -- serial links
AX : in std_logic_vector(19 downto 16);
CKFPH : in std_logic; -- Clock from DSP 100 MHz
--............................... HPI ..........................................................DSP
HCS, HRW : inout std_logic; --
HD : inout std_logic_vector(31 downto 0); -- hpi data
HIA : inout std_logic_vector(2 downto 0); -- hpi address
HRDY : in std_logic; --
--............................. Buffer/Register Control Signals ............................................
CAIV : out std_logic; -- Address buffer clock signal Int->VME
CAVI, CDIV, CDVI : in std_logic; -- not used yet
OAIV : out std_logic; -- Address buffer OE Int->VME
OAVI, ODIV, ODVI : in std_logic; -- not used yet
--............................. Front panel Control Signals ............................................
IN1X, IN2X, IN3X :in std_logic_vector(32 downto 1);-- signals from LVDS inputs ch4
OU1X :inout std_logic_vector(32 downto 1);--
PGIO1X, PGIO2X, PGIO3X, PGIO4X :inout std_logic_vector(32 downto 1);-- 1:in, 2:i/o 3:i/o 4:o
LED, PGXLED : out std_logic_vector(8 downto 1); -- Front panel LED on board, piggy back
COD :in std_logic_vector(2 downto 1); -- piggy board 1I3O=b"00 3I1O=b"11"
LEMIN1 :in std_logic; -- signal from LEMO NIM or TTL
LEMOE :out std_logic; -- /OE for LEMLEMOTTL output
LEMOTTL :out std_logic;-- TTL output to LEMO, if JU1 is selected.
LEMONIM :out std_logic;-- NIM output to LEMO, if JU2 is selected.
--............................. SRAM Control Signals ............................................
SAD : inout std_logic_vector(17 downto 0); -- address
SDA : inout std_logic_vector(15 downto 0); -- data
SCS : inout std_logic;
SOE : inout std_logic;
SWE : inout std_logic;
--............................. DISPLAY
AI : inout std_logic_vector(1 downto 0); -- display address ( use 1 and 2 only, 0 and 3 can't be seen)
DI : inout std_logic_vector(6 downto 0); -- display data
WRDIS : inout std_logic; -- display write
DOUTLCD : out std_logic;
--............................. System Signals ............................................
PRES, SRESI : in std_logic; -- reset positive from reset IC
RES : in std_logic_vector(2 downto 1); -- reset from CPLD
CKFNL, CKFPL : in std_logic; -- Clock from buffer 100 MHz
CON : inout std_logic_vector(15 downto 0); -- Connection between PROG and vupm_1
HPV, HPW : out std_logic_vector(15 downto 0) -- Logic analyzer signals
);
end vuprom_CBMaster;
architecture rtl of vuprom_CBMaster is
attribute keep : string;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- VME access
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- TOP level design --
constant YEAR: integer :=10;
constant MONTH: integer :=7;
constant DATE: integer :=11;
constant TRIAL: integer :=3;
constant version: std_logic_vector ( 31 downto 0):=x"00030508"; -- v0003.00.10
signal ymdt: std_logic_vector (31 downto 0);
--signal tdcsetting : std_logic_vector (31 downto 0);
constant vmead_clkstatus: std_logic_vector ( 11 downto 2) :=b"0000000000";
constant vmead_ymdt: std_logic_vector ( 11 downto 2) :=b"0000000001";
constant vmead_version: std_logic_vector ( 11 downto 2) :=b"0000000010";
signal vme_clkrst : std_logic_vector ( 1 downto 0);
signal vme_clkstatus: std_logic_vector(1 downto 0);
signal top_data_o: std_logic_vector(31 downto 0);
signal top_oecsr : std_logic;
signal top_ckcsr : std_logic;
------------------ VME address modifier ------------------------------
-- CON(8) = am_b = Extended non-privileged block transfer
-- CON(7) = am_9 = Extended non-privileged data access
------------------ VME addresses --------------------------------------
--- address bus (23 downto 20)
--- address bit 23 = 1 : access to CPLD
--- XXC0 0000 0000 for Flash Memory Access from CPLD
--- XX80 0000 0000 for Configure FPGA from Flash Memory
constant csr_ad :std_logic_vector(3 downto 0) := b"0000"; -- vmeaddr=XX00 0000 - XX00 000C a23-20
-- constant dspcsr_ad :std_logic_vector(3 downto 0) := b"0100"; -- DSP CSR register
-- constant hpi_ad : std_logic_vector(3 downto 0) := b"0110"; -- DSP HPI access
-- constant vmeram_ad : std_logic_vector(3 downto 0):= b"0001"; -- dual ported VME RAM in FPGA
-- constant sram_ad: std_logic_vector(3 downto 0) := b"0010"; -- SRAM memory
-- constant sram_ad :std_logic_vector(3 downto 2) := x"01";----vmeaddr=XX40 0000 - XX40 FFFC
----- address sharing for vmecsr address bus (19 downto 12)
constant scal_base :std_logic_vector(7 downto 0) :=x"01";
constant trig_base :std_logic_vector(7 downto 0) :=x"02";
constant scal_base_SC :std_logic_vector(7 downto 0) :=x"03";
-- constant pw_base : std_logic_vector(7 downto 0) :=x"03";
constant top_base : std_logic_vector(7 downto 0) :=x"04";
constant disp_base : std_logic_vector(7 downto 0) :=x"05";
constant oszihisto_base : std_logic_vector(7 downto 0) :=x"0a";
-- vme bus control signals
signal ckcsr : std_logic; -- internal CSR
signal oecsr : std_logic; -- internal CSR
signal din : std_logic_vector (31 downto 0); -- internal data bus, CSR
signal u_ad_reg :std_logic_vector(31 downto 2);
signal u_dat_in :std_logic_vector(31 downto 0);
signal u_data_o :std_logic_vector(31 downto 0);
signal ckaddr, ws : std_logic;
signal VMEAccess_Reset : std_logic;
COMPONENT vme_access
generic (
BASE_AD : std_logic_vector( 23 downto 20) := csr_ad
-- VME base address D23 to D 20
);
Port ( AD : inout STD_LOGIC_VECTOR (31 downto 0);
VME_Reset : in std_logic;
ASI : in STD_LOGIC;
WRI : in STD_LOGIC;
DS0I : in STD_LOGIC;
DS1I : in STD_LOGIC;
CON : inout STD_LOGIC_VECTOR (15 downto 0);
CKADDR : out STD_LOGIC;
WS : out STD_LOGIC;
CKCSR : out STD_LOGIC;
OECSR : out STD_LOGIC;
U_AD_REG : out STD_LOGIC_VECTOR ( 31 downto 2);
U_DAT_IN : in STD_LOGIC_VECTOR ( 31 downto 0);
U_DAT_OUT : out STD_LOGIC_VECTOR ( 31 downto 0);
CLK : in STD_LOGIC
);
END COMPONENT;
-------------------------------------------
type TypeGlobal_Module_Step is (PreInit, Init, PostInit, Working);
signal Global_Module_Step : TypeGlobal_Module_Step;
signal Global_Reset_After_Power_Up_Delay_1msec : std_logic;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- CLOCK
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
signal clk50, clk100, clk200, clk400, clk1, clk0_5: std_logic;
signal clk_rst, clk_locked: std_logic_vector ( 3 downto 0);
COMPONENT clock_boost
PORT(
CLKIN_N_IN : IN std_logic;
CLKIN_P_IN : IN std_logic;
CLK_RST_IN : IN std_logic_vector(3 downto 0);
CLK_LOCKED_OUT : OUT std_logic_vector(3 downto 0);
CLK50MHz_OUT : OUT std_logic;
CLK100MHz_OUT : OUT std_logic;
CLK200MHz_OUT : OUT std_logic;
CLK400MHz_OUT : OUT std_logic;
clock1MHz_OUT : out STD_LOGIC;
clock0_5Hz_OUT : out STD_LOGIC
);
END COMPONENT;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- Display
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
signal dispmem_in, dispmem_out :std_logic_vector(7 downto 0);
signal disp_data_o : std_logic_vector(31 downto 0);
signal disp_oecsr : std_logic;
signal disp_ckcsr : std_logic;
signal disp_in : std_logic_vector(3 downto 0);
component display_matrix is
Port ( reset : in std_logic_vector(1 downto 0);
LCD_DIN : inout STD_LOGIC;
LCD_LP : inout STD_LOGIC;
LCD_FLM : inout STD_LOGIC;
LCD_SCP : inout STD_LOGIC;
LCD_LED_GRN : inout STD_LOGIC;
LCD_LED_RED : inout STD_LOGIC;
-- DSP interface -------------------------
clk50 : in std_logic;
disp_in : in std_logic_vector(3 downto 0);
u_ad_reg :in std_logic_vector(11 downto 2);
u_dat_in :in std_logic_vector(31 downto 0);
u_data_o :out std_logic_vector(31 downto 0);
ckaddr, ws, oecsr, ckcsr:in std_logic
);
end component;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- I/O
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
signal vhdc_out : std_logic_vector ( 63 downto 0);
signal vhdc_in : std_logic_vector (191 downto 0);
--
signal count : std_logic_vector (23 downto 0);
signal counth : std_logic_vector (27 downto 0);
--signal gate_vhdl : std_logic_vector ( (8*10-1) downto 0);
signal led_out : std_logic_vector(15 downto 0);
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- SCALER
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
signal scal_data_o : std_logic_vector(31 downto 0);
constant SCCH: integer := 32*6+4;
constant SCBit: integer := 32;
signal scal_in : std_logic_vector(SCCH-1 downto 0);
attribute keep of scal_in: signal is "TRUE";
signal scal_oecsr : std_logic;
signal scal_ckcsr : std_logic;
-- SC Scaler
signal scal_data_o_SC : std_logic_vector(31 downto 0);
constant SCCH_SC: integer := 134;
signal scal_in_SC : std_logic_vector(SCCH_SC-1 downto 0);
attribute keep of scal_in_SC: signal is "TRUE";
signal scal_oecsr_SC : std_logic;
signal scal_ckcsr_SC : std_logic;
component scaler
generic (
NCh : integer;
NBit : integer := SCBit
);
port (
clkl : in STD_LOGIC;
clkh : in STD_LOGIC;
scal_in : STD_LOGIC_VECTOR ( (NCh-1) downto 0);
--............. vme interface .............
u_ad_reg :in std_logic_vector(11 downto 2);
u_dat_in :in std_logic_vector(31 downto 0);
u_data_o :out std_logic_vector(31 downto 0);
oecsr, ckcsr:in std_logic
);
end component;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- TRIGGER
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
signal trig_data_o : std_logic_vector(31 downto 0);
signal trig_in : std_logic_vector( 191 downto 0);
signal trig_out : std_logic_vector( 63 downto 0);
signal trig_oecsr : std_logic;
signal trig_ckcsr : std_logic;
signal SignalsTriggerToScaler : std_logic_vector(195 downto 0);
signal Debug_ActualState : STD_LOGIC_VECTOR(3 downto 0);
signal SC_Scalers_L1Out : STD_LOGIC_VECTOR(7 downto 0);
signal SC_Scalers_L2Out : STD_LOGIC_VECTOR(7 downto 0);
component trigger
port (
clock50 : in STD_LOGIC;
clock100 : in STD_LOGIC;
clock200 : in STD_LOGIC;
clock400 : in STD_LOGIC;
clock1 : in STD_LOGIC;
clock0_5 : in STD_LOGIC;
trig_in : in STD_LOGIC_VECTOR ( 191 downto 0);
trig_out : out STD_LOGIC_VECTOR ( 63 downto 0);
nim_in : in STD_LOGIC;
nim_out : out STD_LOGIC;
ToScalerOut : out STD_LOGIC_VECTOR(195 downto 0);
Debug_ActualState_Out : out STD_LOGIC_VECTOR(3 downto 0);
SC_Scalers_L1Out : out STD_LOGIC_VECTOR(7 downto 0);
SC_Scalers_L2Out : out STD_LOGIC_VECTOR(7 downto 0);
led : out STD_LOGIC_VECTOR(8 downto 1); -- 8 LEDs onboard
pgxled : out STD_LOGIC_VECTOR(8 downto 1); -- 8 LEDs on PIG board
Global_Reset_After_Power_Up : in std_logic;
--............................. vme interface ....................
u_ad_reg :in std_logic_vector(11 downto 2);
u_dat_in :in std_logic_vector(31 downto 0);
u_data_o :out std_logic_vector(31 downto 0);
oecsr, ckcsr:in std_logic
);
end component;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- Oszi Histo
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
signal oszihisto_data_o : std_logic_vector(31 downto 0);
signal oszihisto_in : std_logic_vector( 191 downto 0);
signal oszihisto_out : std_logic_vector( 63 downto 0);
signal oszihisto_oecsr : std_logic;
signal oszihisto_ckcsr : std_logic;
COMPONENT OsziHisto
PORT(
SelectedSignalsIN : IN std_logic_vector(3 downto 0);
clock200 : IN std_logic;
clock50 : IN std_logic;
OsziAcquisionRunning : OUT std_logic;
Debug_Out : OUT std_logic_vector(31 downto 0);
--............................. vme interface ....................
u_ad_reg : IN std_logic_vector(11 downto 2);
u_dat_in : IN std_logic_vector(31 downto 0);
u_data_o : OUT std_logic_vector(31 downto 0);
oecsr : IN std_logic;
ckcsr : IN std_logic
);
END COMPONENT;
------------------------------------------------------------------------------------------
begin ---- BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN -----------------
------------------------------------------------------------------------------------------
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- CLOCK
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
clock_boost_1: clock_boost PORT MAP(
CLKIN_N_IN => CKFNL,
CLKIN_P_IN => CKFPL,
CLK50MHz_OUT => clk50,
CLK100MHz_OUT => clk100,
CLK200MHz_OUT => clk200,
CLK400MHz_OUT => clk400,
CLK_LOCKED_OUT => clk_locked,
CLK_RST_IN => clk_rst,
clock1MHz_OUT => clk1,
clock0_5Hz_OUT => clk0_5
);
------------------------------------------------------------------------------------------
-- Reset after Power Up
-- Needed e.g. for reset of PLL of clock boost 200 -> 200 MHz
clk_rst(0) <= vme_clkrst(0);
clk_rst(1) <= vme_clkrst(1) or Global_Reset_After_Power_Up_Delay_1msec;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- VME access
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
vme_access_1: vme_access PORT MAP(
AD => AD,
VME_Reset => VMEAccess_Reset,
ASI => ASI,
WRI => WRI,
DS0I => DS0I,
DS1I => DS1I,
CON => CON,
CKADDR => ckaddr,
WS => ws,
CKCSR => ckcsr,
OECSR => oecsr,
U_AD_REG => u_ad_reg,
U_DAT_IN => din,
U_DAT_OUT => u_dat_in,
CLK =>clk50
);
--VMEAccess_Reset <= LEMIN1;
VMEAccess_Reset <= '0';
BERRO <= '1'; -- H means inactive
IACKOU <= IACKII; -- interrupt acknowledge chain
-- SRESI -- system reset
CAIV <= '1'; -- clock for address ram0begister internal<-VME, disabled
OAIV <= '1'; -- OE for address register internal<-VME, disabled, '1' means high
IRBLO <= '1';
---VME access for top level design
vme_clkstatus(1 downto 0) <= clk_locked(1 downto 0);
ymdt(7 downto 0) <= CONV_STD_LOGIC_VECTOR(TRIAL, 8);
ymdt(15 downto 8) <= CONV_STD_LOGIC_VECTOR(DATE, 8);
ymdt(23 downto 16) <= CONV_STD_LOGIC_VECTOR(MONTH, 8);
ymdt(31 downto 24) <= CONV_STD_LOGIC_VECTOR(YEAR, 8);
-- tdcsetting(7 downto 0) <= b"00000001";
-- tdcsetting(15 downto 8) <= CONV_STD_LOGIC_VECTOR(TDCCH, 8);
-- tdcsetting(23 downto 16) <= CONV_STD_LOGIC_VECTOR(TDCBIT, 8);
process(clk50, oecsr, ckcsr, u_ad_reg)
begin
if (rising_edge(clk50)) then
if (oecsr ='1' and u_ad_reg(19 downto 12)=top_base) then
top_oecsr <='1';
else
top_oecsr <='0';
end if;
if (ckcsr ='1' and u_ad_reg(19 downto 12)=top_base) then
top_ckcsr <='1';
else
top_ckcsr <='0';
end if;
end if;
end process;
-- Write cycle --
process(clk50, top_ckcsr, u_ad_reg)
begin
if (clk50'event and clk50 ='1') then
if (top_ckcsr='1' and u_ad_reg(11 downto 2)=vmead_clkstatus) then
vme_clkrst(1) <= u_dat_in(1);
else vme_clkrst(1) <='0';
end if;
end if;
vme_clkrst(0)<='0';
end process;
-----Read cycle ----
process(clk50, top_oecsr, u_ad_reg)
begin
if (clk50'event and clk50 ='1') then
if (top_oecsr='1' and u_ad_reg(11 downto 2)=vmead_clkstatus) then
top_data_o <= EXT(vme_clkstatus,32);
elsif (top_oecsr='1' and u_ad_reg(11 downto 2)=vmead_ymdt) then
top_data_o <= ymdt;
elsif (top_oecsr='1' and u_ad_reg(11 downto 2)=vmead_version) then
top_data_o <= version;
-- elsif (oecsr='1' and u_ad_reg(15 downto 4)=x"300"
-- and u_ad_reg(3 downto 2)=b"10") then
-- top_data_o <= tdcsetting;
-- elsif (oecsr='1' and u_ad_reg(15 downto 4)=x"300"
-- and u_ad_reg(3 downto 2)=b"11") then
-- top_data_o <= EXT(TDCOVF, 32);
else top_data_o <= (others =>'0');
end if;
end if;
end process;
----------------------- DATA for OUTPUT to VME -------------------------------------------
process(clk50, scal_oecsr, trig_oecsr, top_oecsr)
begin
if (rising_edge(clk50)) then
if (scal_oecsr ='1' ) then
din <= scal_data_o;
elsif (scal_oecsr_SC ='1' ) then
din <= scal_data_o_SC;
elsif (trig_oecsr ='1' ) then
din <= trig_data_o;
elsif (top_oecsr ='1') then
din <= top_data_o;
elsif (disp_oecsr ='1') then
din <= disp_data_o;
elsif (oszihisto_oecsr ='1') then
din <= oszihisto_data_o;
else
din <= (others => '0');
end if;
end if;
end process;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- Display
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
DOUTLCD <= '0';
-- WRDIS <= '1';
disp_matrix1: display_matrix
port map (reset => res,
lcd_din => DI(0),
lcd_lp => DI(1),
lcd_flm => DI(2),
lcd_scp => DI(3),
lcd_led_grn => DI(4),
lcd_led_red => DI(5),
clk50 => clk50,
disp_in => disp_in,
u_ad_reg=>u_ad_reg(11 downto 2),
u_dat_in=>u_dat_in,
u_data_o=>disp_data_o,
ckaddr=> ckaddr,
ws=>ws,
oecsr=>disp_oecsr,
ckcsr=>disp_ckcsr
);
-- vme_access --
process(clk50, oecsr, ckcsr, u_ad_reg)
begin
if (rising_edge(clk50)) then
if (oecsr ='1' and u_ad_reg(19 downto 12)=disp_base) then
disp_oecsr <='1';
else
disp_oecsr <='0';
end if;
if (ckcsr ='1' and u_ad_reg(19 downto 12)=disp_base) then
disp_ckcsr <='1';
else
disp_ckcsr <='0';
end if;
end if;
end process;
disp_in(0)<= clk_locked(0) and clk_locked(1);
disp_in(1)<= COD(1) or COD(2);
disp_in(2)<= CON(7) or CON(8);
disp_in(3)<= LEMIN1;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- I/O
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
vhdc_in( 31 downto 0) <= IN1X ( 32 downto 1);
vhdc_in( 63 downto 32) <= IN2X ( 32 downto 1);
vhdc_in( 95 downto 64) <= IN3X ( 32 downto 1);
vhdc_in( 127 downto 96) <= PGIO1X ( 32 downto 1);
vhdc_in( 159 downto 128) <= PGIO2X ( 32 downto 1);
vhdc_in( 191 downto 160) <= PGIO3X ( 32 downto 1);
OU1X( 32 downto 1) <= vhdc_out ( 31 downto 0);
PGIO4X( 32 downto 1) <= vhdc_out ( 63 downto 32);
-- PGIO2X( 32 downto 1) <= vhdc_out ( 63 downto 32);
-- PGIO3X( 32 downto 1) <= vhdc_out ( 95 downto 64);
-- PGIO4X( 32 downto 1) <= vhdc_out ( 127 downto 96);
-- LEMONIM<= tdc_tst_stop_o or trig_allor;
-- LEMONIM<= tdc_tst_stop_o or LEMIN1;
-- vhdc_out <= tdc_tst_start_o or trig_out;
--vhdc_out <= trig_out(63 downto 32)&vmeaccess_out;
vhdc_out <= trig_out;
-- tdc i/o
-- tdc_start( 127 downto 0) <= vhdc_in( 127 downto 0) ;
---- tdc_stop <= LEMIN1;
---- tdc_clr <= '0';
---- tdc_en <= '1';
-- tdc_selrnd <= CON(7);
-- scaler i/o
--scal_in(32*6-1 downto 0) <= vhdc_in( 32*6-1 downto 0);
scal_in <= SignalsTriggerToScaler;
scal_in_SC <= SignalsTriggerToScaler(195 downto 192) & SC_Scalers_L2Out & SC_Scalers_L1Out & Debug_ActualState &
SignalsTriggerToScaler(191 downto 176) & PGIO3X ( 32 downto 1) & PGIO1X ( 32 downto 1) & IN2X ( 6 downto 1) & IN1X ( 24 downto 1);
-- trigger i/o
trig_in( 191 downto 0) <= vhdc_in( 191 downto 0);
LEMOE <='1'; -- LEMTTL set to Z.
LEMOTTL <='0';
----- DSP ------
BCLK <= clk50;
BHOLD <= '0';
BRDY <= '1';
ARDY <= '1';
AHOLD <= '1';
NMI <= 'Z';
TINP <= (others => '0');
DS <= (others =>'Z');
DSPRS <='Z';
---- SRAM -----
SCS <= '1';
SOE <= '1';
SWE <= '1';
SAD <= (others => 'Z');
SDA <= (others => 'Z');
CON(15 downto 9) <= b"0000000";
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- SCALER
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
scaler_DAQ: scaler generic map (NCh => SCCH) port map (
clkl=>clk50, clkh => clk100,
scal_in=>scal_in,
u_ad_reg=>u_ad_reg(11 downto 2),
u_dat_in=>u_dat_in,
u_data_o=>scal_data_o,
oecsr=>scal_oecsr,
ckcsr=>scal_ckcsr
);
scaler_SC: scaler generic map (NCh => SCCH_SC) port map (
clkl=>clk50, clkh => clk100,
scal_in=>scal_in_SC,
u_ad_reg=>u_ad_reg(11 downto 2),
u_dat_in=>u_dat_in,
u_data_o=>scal_data_o_SC,
oecsr=>scal_oecsr_SC,
ckcsr=>scal_ckcsr_SC
);
process(clk50, oecsr, ckcsr, u_ad_reg)
begin
if (rising_edge(clk50)) then
--scaler--
if (oecsr ='1' and u_ad_reg(19 downto 12)=scal_base) then scal_oecsr <='1'; else scal_oecsr <='0'; end if;
if (ckcsr ='1' and u_ad_reg(19 downto 12)=scal_base) then scal_ckcsr <='1'; else scal_ckcsr <='0'; end if;
if (oecsr ='1' and u_ad_reg(19 downto 12)=scal_base_SC) then scal_oecsr_SC <='1'; else scal_oecsr_SC <='0'; end if;
if (ckcsr ='1' and u_ad_reg(19 downto 12)=scal_base_SC) then scal_ckcsr_SC <='1'; else scal_ckcsr_SC <='0'; end if;
end if;
end process;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- TRIGGER
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
trigger_1: trigger
port map (
clock50=>clk50,
clock100=>clk100,
clock200=>clk200,
clock400=>clk400,
clock1 => clk1,
clock0_5 => clk0_5,
trig_in=>trig_in,
trig_out=>trig_out,
nim_in => LEMIN1,
nim_out => LEMONIM,
ToScalerOut => SignalsTriggerToScaler,
Debug_ActualState_Out => Debug_ActualState,
SC_Scalers_L1Out => SC_Scalers_L1Out,
SC_Scalers_L2Out => SC_Scalers_L2Out,
led => led,
pgxled => pgxled,
Global_Reset_After_Power_Up => Global_Reset_After_Power_Up_Delay_1msec,
u_ad_reg=>u_ad_reg(11 downto 2),
u_dat_in=>u_dat_in,
u_data_o=>trig_data_o,
oecsr=>trig_oecsr,
ckcsr=>trig_ckcsr
);
process(clk50, oecsr, ckcsr, u_ad_reg)
begin
if (rising_edge(clk50)) then
if (oecsr ='1' and u_ad_reg(19 downto 12)=trig_base) then
trig_oecsr <='1';
else
trig_oecsr <='0';
end if;
if (ckcsr ='1' and u_ad_reg(19 downto 12)=trig_base) then
trig_ckcsr <='1';
else
trig_ckcsr <='0';
end if;
end if;
end process;
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
-- Oszi Histo
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
OsziHisto_1: OsziHisto PORT MAP(
SelectedSignalsIN => Debug_ActualState, --trig_in(3 downto 0),
OsziAcquisionRunning => open,
clock200 => clk200,
clock50 => clk50,
Debug_Out => open,
u_ad_reg => u_ad_reg(11 downto 2),
u_dat_in => u_dat_in,
u_data_o => oszihisto_data_o,
oecsr => oszihisto_oecsr,
ckcsr => oszihisto_ckcsr
);
process(clk50, oecsr, ckcsr, u_ad_reg)
begin
if (rising_edge(clk50)) then
if (oecsr ='1' and u_ad_reg(19 downto 12)=oszihisto_base) then
oszihisto_oecsr <='1';
else
oszihisto_oecsr <='0';
end if;
if (ckcsr ='1' and u_ad_reg(19 downto 12)=oszihisto_base) then
oszihisto_ckcsr <='1';
else
oszihisto_ckcsr <='0';
end if;
end if;
end process;
--======================================================================================================
hpw(7 downto 0) <= x"00";
hpw(8) <= '0' when led_out(15 downto 0)=x"0000" else '1';
hpw(9) <= LEMIN1;
hpw(15 downto 10) <= IN1X ( 6 downto 1);
hpv(0)<=CON(7);
hpv(1)<=CON(8);
hpv(6 downto 2)<=CON(4 downto 0);
hpv(7) <= clk50;
hpv(15 downto 8 ) <= (others => '0');
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
-- Reset after Power Up
-- Needed e.g. for reset of PLL of clock boost 200 -> 400 MHz
------------------------------------------------------------------------------------------
process (clk50)
variable ZaehlerGlobalModuleStep : integer;
begin
if rising_edge(Clk50) then
if Global_Module_Step /= Working then
ZaehlerGlobalModuleStep := ZaehlerGlobalModuleStep + 1;
end if;
if ZaehlerGlobalModuleStep < 50000*1 then -- before 1 msecond
Global_Module_Step <= PreInit;
elsif ZaehlerGlobalModuleStep < 50000*2 then -- before 2 mseconds
Global_Module_Step <= Init;
elsif ZaehlerGlobalModuleStep < 50000*3 then -- before 3 mseconds
Global_Module_Step <= PostInit;
else
Global_Module_Step <= Working;
end if;
end if;
end process;
process (Global_Module_Step)
begin
case Global_Module_Step is
when PreInit =>
Global_Reset_After_Power_Up_Delay_1msec <= '0';
when Init =>
Global_Reset_After_Power_Up_Delay_1msec <= '1';
when PostInit =>
Global_Reset_After_Power_Up_Delay_1msec <= '0';
when Working =>
Global_Reset_After_Power_Up_Delay_1msec <= '0';
end case;
end process;
end rtl;