-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathROC_ch_gen_v1.vhd
463 lines (401 loc) · 15 KB
/
ROC_ch_gen_v1.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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
use work.ipbus.all;
use work.user_package.all;
entity ROC_ch_gen_v1 is
port ( clk_i : in std_logic;
sclr_i : in std_logic;
--
start_i : in std_logic;
--
trigger_i : in std_logic;
trigger_en_i : in std_logic; --pause_trigger_i : pause/resume to wait new data set
--
ch_word4b_ROC : out std_logic_vector(3 downto 0 );
--param
--HIT_NB_ROC_MODE
--"0000" : fixed (predefined values updated from s/w)
--"0001" : cnt from [0:15]; incremented for each new frame (not yet)
--"0010" : pseudo-random (not yet)
hit_nb_ROC_mode_i : in std_logic_vector(3 downto 0);
--MATRIX_MODE [dcol-row]
--"0000" : fixed (predefined values updated from s/w)
--"0001" : cnt; but if several hits/roc => same value; incremented for each new frame; common for all ROC & Hit/ROC
--"0010" : pseudo-random (not yet)
matrix_mode_i : in std_logic_vector(3 downto 0);
--HIT_DATA_MODE
--MATRIX_MODE [dcol-row]
--"0000" : fixed (predefined values updated from s/w)
--"0001" : cnt (not yet)
--"0010" : pseudo-random (not yet)
hit_data_mode_i : in std_logic_vector(3 downto 0);
--
ROC_nb_i : in std_logic_vector(3 downto 0); --[0:8] with 1<=>1
--hitNbByROC
hit_nb_ROCn0_i : in std_logic_vector(3 downto 0); --"0000" : 0 / "1111" : 15
hit_nb_ROCn1_i : in std_logic_vector(3 downto 0);
hit_nb_ROCn2_i : in std_logic_vector(3 downto 0);
hit_nb_ROCn3_i : in std_logic_vector(3 downto 0);
hit_nb_ROCn4_i : in std_logic_vector(3 downto 0);
hit_nb_ROCn5_i : in std_logic_vector(3 downto 0);
hit_nb_ROCn6_i : in std_logic_vector(3 downto 0);
hit_nb_ROCn7_i : in std_logic_vector(3 downto 0);
--dcol if constant => base-6 format
dcol_ROCn0_i : in std_logic_vector(5 downto 0);
dcol_ROCn1_i : in std_logic_vector(5 downto 0);
dcol_ROCn2_i : in std_logic_vector(5 downto 0);
dcol_ROCn3_i : in std_logic_vector(5 downto 0);
dcol_ROCn4_i : in std_logic_vector(5 downto 0);
dcol_ROCn5_i : in std_logic_vector(5 downto 0);
dcol_ROCn6_i : in std_logic_vector(5 downto 0);
dcol_ROCn7_i : in std_logic_vector(5 downto 0);
--row if constant => base-6 format
row_ROCn0_i : in std_logic_vector(8 downto 0);
row_ROCn1_i : in std_logic_vector(8 downto 0);
row_ROCn2_i : in std_logic_vector(8 downto 0);
row_ROCn3_i : in std_logic_vector(8 downto 0);
row_ROCn4_i : in std_logic_vector(8 downto 0);
row_ROCn5_i : in std_logic_vector(8 downto 0);
row_ROCn6_i : in std_logic_vector(8 downto 0);
row_ROCn7_i : in std_logic_vector(8 downto 0);
--hit if constant => base-6 format
hit_ROCn0_i : in std_logic_vector(7 downto 0);
hit_ROCn1_i : in std_logic_vector(7 downto 0);
hit_ROCn2_i : in std_logic_vector(7 downto 0);
hit_ROCn3_i : in std_logic_vector(7 downto 0);
hit_ROCn4_i : in std_logic_vector(7 downto 0);
hit_ROCn5_i : in std_logic_vector(7 downto 0);
hit_ROCn6_i : in std_logic_vector(7 downto 0);
hit_ROCn7_i : in std_logic_vector(7 downto 0);
--
TOKEN_ROC_IN : in std_logic;
TOKEN_ROC_OUT : out std_logic
--stack
);
end ROC_ch_gen_v1;
architecture Behavioral of ROC_ch_gen_v1 is
type t_state is ( idle,
START_ROC,
STOP_ROC,
RH0,
RH1,
RH2,
RH3,
PXD1,
PXD2,
PXD3,
PXD4,
PXD5,
PXD6,
TT1
);
signal s_state : t_state;
--signal stack : std_logic_vector(5 downto 0) := (others=>'0');
signal ROC_cnt : integer range 0 to 15 := 0; --4b
signal ROC_index : integer range 0 to 7 := 0; --3b
signal ROC_cnt_end : std_logic:='0';
type array_8x6bit is array (0 to 7) of std_logic_vector(5 downto 0);
type array_8x9bit is array (0 to 7) of std_logic_vector(8 downto 0);
type array_8x8bit is array (0 to 7) of std_logic_vector(7 downto 0);
type array_8x4bit_unsigned is array (0 to 7) of unsigned(3 downto 0);
type array_8x4bit is array (0 to 7) of std_logic_vector(3 downto 0);
signal dcol_ROCn : array_8x6bit := (others => (others => '0'));
signal row_ROCn : array_8x9bit := (others => (others => '0'));
signal hit_ROCn : array_8x8bit := (others => (others => '0'));
-- signal hit_nb_ROCn : array_8x4bit_unsigned := (others => (others => '0'));
signal hit_nb_ROCn : array_8x4bit := (others => (others => '0'));
signal hit_cnt : integer range 0 to 15 := 0; --4b
signal dcol_cnt : std_logic_vector(5 downto 0) := (others => '0');
signal dcol_cnt_en : std_logic := '0'; --EN if '1' / one-pulse
signal dcol_cnt_end : std_logic := '0'; --active high
signal row_cnt : std_logic_vector(8 downto 0) := (others => '0');
signal row_cnt_en : std_logic := '0'; --EN if '1' / one-pulse
signal row_cnt_end : std_logic := '0'; --active high
constant CMD0 : std_logic_vector(hit_nb_ROC_mode_i'range) := std_logic_vector(to_unsigned(0,hit_nb_ROC_mode_i'length));
constant CMD1 : std_logic_vector(hit_nb_ROC_mode_i'range) := std_logic_vector(to_unsigned(1,hit_nb_ROC_mode_i'length));
constant CMD2 : std_logic_vector(hit_nb_ROC_mode_i'range) := std_logic_vector(to_unsigned(2,hit_nb_ROC_mode_i'length));
signal read_pixelData_en : std_logic := '0';
constant ch_word4b_ROC_Idle : std_logic_vector(3 downto 0) := x"F";
begin
--============--
-- OUTPUTTING --
--============--
--ch_word4b_o <= ch_word4b;
--=================--
-- MATRIX COUNTING --
--=================--
--ROW from [0:160], incremented first
row_counter_inst: entity work.row_counter
port map(
clk_i => clk_i,
sclr_i => sclr_i,
row_cnt_en_i => row_cnt_en,
row_cnt_o => row_cnt,
row_cnt_end_o => row_cnt_end
);
--DCOL from [0:26], incremented when row_cnt_end active
dcol_counter_inst: entity work.dcol_counter
port map(
clk_i => clk_i,
sclr_i => sclr_i,
dcol_cnt_en_i => dcol_cnt_en,
dcol_cnt_o => dcol_cnt,
dcol_cnt_end_o => dcol_cnt_end
);
row_cnt_en <= read_pixelData_en;
dcol_cnt_en <= row_cnt_end and read_pixelData_en;
--===================--
-- MATRIX [dcol-row] --
--===================--
process
begin
wait until rising_edge(clk_i);
--***************************************--
--with predefined constants for each ROC --
--***************************************--
if matrix_mode_i = CMD0 then
--dcol
dcol_ROCn(0) <= dcol_ROCn0_i;
dcol_ROCn(1) <= dcol_ROCn1_i;
dcol_ROCn(2) <= dcol_ROCn2_i;
dcol_ROCn(3) <= dcol_ROCn3_i;
dcol_ROCn(4) <= dcol_ROCn4_i;
dcol_ROCn(5) <= dcol_ROCn5_i;
dcol_ROCn(6) <= dcol_ROCn6_i;
dcol_ROCn(7) <= dcol_ROCn7_i;
--row
row_ROCn(0) <= row_ROCn0_i;
row_ROCn(1) <= row_ROCn1_i;
row_ROCn(2) <= row_ROCn2_i;
row_ROCn(3) <= row_ROCn3_i;
row_ROCn(4) <= row_ROCn4_i;
row_ROCn(5) <= row_ROCn5_i;
row_ROCn(6) <= row_ROCn6_i;
row_ROCn(7) <= row_ROCn7_i;
--***************************************--
-- with counting data common for all ROCs -
--***************************************--
-- but if several hits/roc => same value; incremented for each new frame; common for all ROC & Hit/ROC
elsif matrix_mode_i = CMD1 and read_pixelData_en = '1' then
--dcol
dcol_ROCn(0) <= dcol_cnt;
dcol_ROCn(1) <= dcol_cnt;
dcol_ROCn(2) <= dcol_cnt;
dcol_ROCn(3) <= dcol_cnt;
dcol_ROCn(4) <= dcol_cnt;
dcol_ROCn(5) <= dcol_cnt;
dcol_ROCn(6) <= dcol_cnt;
dcol_ROCn(7) <= dcol_cnt;
--row
row_ROCn(0) <= row_cnt;
row_ROCn(1) <= row_cnt;
row_ROCn(2) <= row_cnt;
row_ROCn(3) <= row_cnt;
row_ROCn(4) <= row_cnt;
row_ROCn(5) <= row_cnt;
row_ROCn(6) <= row_cnt;
row_ROCn(7) <= row_cnt;
end if;
end process;
--==========--
-- HIT DATA --
--==========--
--***************************************--
--with predefined constants for each ROC --
--***************************************--
hit_ROCn(0) <= hit_ROCn0_i;
hit_ROCn(1) <= hit_ROCn1_i;
hit_ROCn(2) <= hit_ROCn2_i;
hit_ROCn(3) <= hit_ROCn3_i;
hit_ROCn(4) <= hit_ROCn4_i;
hit_ROCn(5) <= hit_ROCn5_i;
hit_ROCn(6) <= hit_ROCn6_i;
hit_ROCn(7) <= hit_ROCn7_i;
-- process
-- begin
-- wait until rising_edge(clk_i);
-- --***************************************--
-- --with predefined constants for each ROC --
-- --***************************************--
-- if hit_data_mode_i = CMD0 then
-- hit_ROCn(0) <= hit_ROCn0_i;
-- hit_ROCn(1) <= hit_ROCn1_i;
-- hit_ROCn(2) <= hit_ROCn2_i;
-- hit_ROCn(3) <= hit_ROCn3_i;
-- hit_ROCn(4) <= hit_ROCn4_i;
-- hit_ROCn(5) <= hit_ROCn5_i;
-- hit_ROCn(6) <= hit_ROCn6_i;
-- hit_ROCn(7) <= hit_ROCn7_i;
-- end if;
-- end process;
--============--
-- HIT_NB_ROC --
--============--
--***************************************--
--with predefined constants for each ROC --
--***************************************--
hit_nb_ROCn(0) <= hit_nb_ROCn0_i;
hit_nb_ROCn(1) <= hit_nb_ROCn1_i;
hit_nb_ROCn(2) <= hit_nb_ROCn2_i;
hit_nb_ROCn(3) <= hit_nb_ROCn3_i;
hit_nb_ROCn(4) <= hit_nb_ROCn4_i;
hit_nb_ROCn(5) <= hit_nb_ROCn5_i;
hit_nb_ROCn(6) <= hit_nb_ROCn6_i;
hit_nb_ROCn(7) <= hit_nb_ROCn7_i;
-- process
-- begin
-- wait until rising_edge(clk_i);
-- --***************************************--
-- --with predefined constants for each ROC --
-- --***************************************--
-- if hit_nb_ROC_mode_i = CMD0 then
-- hit_nb_ROCn(0) <= hit_nb_ROCn0_i;
-- hit_nb_ROCn(1) <= hit_nb_ROCn1_i;
-- hit_nb_ROCn(2) <= hit_nb_ROCn2_i;
-- hit_nb_ROCn(3) <= hit_nb_ROCn3_i;
-- hit_nb_ROCn(4) <= hit_nb_ROCn4_i;
-- hit_nb_ROCn(5) <= hit_nb_ROCn5_i;
-- hit_nb_ROCn(6) <= hit_nb_ROCn6_i;
-- hit_nb_ROCn(7) <= hit_nb_ROCn7_i;
-- end if;
-- end process;
--
ROC_cnt_end <= '1' when ROC_cnt = 0 else '0';
--=======================--
-- FSM - Frame Generator --
--=======================--
process
begin
wait until rising_edge(clk_i); -- rising clock edge
--
if sclr_i = '1' then
ch_word4b_ROC <= ch_word4b_ROC_Idle;
--event_cnt <= (others=>'0');
ROC_cnt <= 15;
ROC_index <= 0;
read_pixelData_en <= '0';
TOKEN_ROC_OUT <= '0';
s_state <= idle;
else
case s_state is
when idle => --start + wait trigger
ch_word4b_ROC <= ch_word4b_ROC_Idle;
ROC_cnt <= to_integer(unsigned(ROC_nb_i));
ROC_index <= 0;
TOKEN_ROC_OUT <= '0';
--hit_cnt <= to_integer(unsigned(hit_nb_ROCn(0)));
--
if TOKEN_ROC_IN = '1' then
if ROC_nb_i = std_logic_vector(to_unsigned(0,ROC_nb_i'length)) then
TOKEN_ROC_OUT <= '1';
ch_word4b_ROC <= ch_word4b_ROC_Idle;
s_state <= TT1;
else
read_pixelData_en <= '1';
s_state <= RH1;
end if; else
s_state <= idle;
end if;
-------------------------------------------------------------------------
--when RH0 => --start + wait trigger
-------------------------------------------------------------------------
-- when START_ROC =>
-- --
-- if ROC_nb_i = std_logic_vector(to_unsigned(0,ROC_nb_i'length)) then
-- TOKEN_ROC_OUT <= '1';
-- ch_word4b_ROC <= ch_word4b_ROC_Idle;
-- s_state <= TT1;
-- else
-- read_pixelData_en <= '1';
-- s_state <= RH1;
-- end if;
--
-------------------------------------------------------------------------
when RH1 =>
ROC_cnt <= ROC_cnt - 1; --DEC
hit_cnt <= to_integer(unsigned(hit_nb_ROCn(ROC_index))); --mux/switch
ch_word4b_ROC <= x"7";
read_pixelData_en <= '0';
s_state <= RH2;
-------------------------------------------------------------------------
when RH2 =>
ch_word4b_ROC <= x"F";
read_pixelData_en <= '0'; --one-pulse
s_state <= RH3;
-------------------------------------------------------------------------
when RH3 =>
ch_word4b_ROC <= "10" & "00"; --ReadBackId = "00"
--
if hit_cnt = 0 then
--
if ROC_cnt = 0 then
TOKEN_ROC_OUT <= '1';
s_state <= TT1;
else
ROC_index <= ROC_index + 1;
s_state <= RH1;
end if;
--
else
hit_cnt <= hit_cnt - 1;
s_state <= PXD1;
end if;
--
-------------------------------------------------------------------------
when PXD1 =>
ch_word4b_ROC <= dcol_ROCn(ROC_index)(5 downto 2);
s_state <= PXD2;
-------------------------------------------------------------------------
when PXD2 =>
ch_word4b_ROC <= dcol_ROCn(ROC_index)(1 downto 0) & row_ROCn(ROC_index)(8 downto 7);
s_state <= PXD3;
-------------------------------------------------------------------------
when PXD3 =>
ch_word4b_ROC <= row_ROCn(ROC_index)(6 downto 3);
s_state <= PXD4;
-------------------------------------------------------------------------
when PXD4 =>
ch_word4b_ROC <= row_ROCn(ROC_index)(2 downto 0) & hit_ROCn(ROC_index)(7);
s_state <= PXD5;
----------------------------------------------------------------------
when PXD5 =>
ch_word4b_ROC <= hit_ROCn(ROC_index)(6 downto 4) & '0';
s_state <= PXD6;
----------------------------------------------------------------------
when PXD6 =>
ch_word4b_ROC <= hit_ROCn(ROC_index)(3 downto 0);
--
if hit_cnt = 0 then
--
if ROC_cnt = 0 then
TOKEN_ROC_OUT <= '1';
s_state <= TT1;
else
ROC_index <= ROC_index + 1;
s_state <= RH1;
end if;
--
else
hit_cnt <= hit_cnt - 1;
s_state <= PXD1;
end if;
--
--------------------------------------------------------------------------
when TT1 =>
ch_word4b_ROC <= ch_word4b_ROC_Idle;
TOKEN_ROC_OUT <= '0';
s_state <= idle;
when others =>
null;
end case;
end if;
end process;
end Behavioral;