source: firmware/FTM/ftu_control/FTM_ftu_control.vhd@ 10791

Last change on this file since 10791 was 10740, checked in by weitzel, 14 years ago
several bugfixes for FTM firmware
File size: 53.1 KB
Line 
1----------------------------------------------------------------------------------
2-- Company: ETH Zurich, Institute for Particle Physics
3-- Engineer: Q. Weitzel
4--
5-- Create Date: 17:54:04 02/02/2011
6-- Design Name:
7-- Module Name: FTM_ftu_control - Behavioral
8-- Project Name:
9-- Target Devices:
10-- Tool versions:
11-- Description: Communication of FTM with the 40 FTU boards of the FACT camera
12--
13-- Dependencies:
14--
15-- Revision:
16-- Revision 0.01 - File Created
17-- Additional Comments:
18--
19----------------------------------------------------------------------------------
20library IEEE;
21use IEEE.STD_LOGIC_1164.ALL;
22use IEEE.STD_LOGIC_ARITH.ALL;
23use IEEE.STD_LOGIC_UNSIGNED.ALL;
24
25library ftm_definitions;
26USE ftm_definitions.ftm_array_types.all;
27USE ftm_definitions.ftm_constants.all;
28
29---- Uncomment the following library declaration if instantiating
30---- any Xilinx primitives in this code.
31--library UNISIM;
32--use UNISIM.VComponents.all;
33
34entity FTM_ftu_control is
35 port(
36 clk_50MHz : in std_logic; -- main clock
37
38 -- global bus enables for FTU crates 0-3
39 rx_en : out STD_LOGIC; -- receiver enable
40 tx_en : out STD_LOGIC; -- transmitter enable
41
42 -- FTU crate 0 data I/O
43 rx_d_0 : in STD_LOGIC;
44 tx_d_0 : out STD_LOGIC;
45
46 -- FTU crate 1 data I/O
47 rx_d_1 : in STD_LOGIC;
48 tx_d_1 : out STD_LOGIC;
49
50 -- FTU crate 2 data I/O
51 rx_d_2 : in STD_LOGIC;
52 tx_d_2 : out STD_LOGIC;
53
54 -- FTU crate 3 data I/O
55 rx_d_3 : in STD_LOGIC;
56 tx_d_3 : out STD_LOGIC;
57
58 -- commands from FTM main control
59 new_config : in std_logic;
60 ping_all : in std_logic;
61 read_rates : in std_logic;
62
63 -- answers to FTM main control
64 read_rates_started : out std_logic := '0';
65 read_rates_done : out std_logic := '0';
66 new_config_started : out std_logic := '0';
67 new_config_done : out std_logic := '0';
68 ping_all_started : out std_logic := '0';
69 ping_all_done : out std_logic := '0';
70
71 -- active FTU lists
72 ftu_active_cr0 : in std_logic_vector (15 downto 0);
73 ftu_active_cr1 : in std_logic_vector (15 downto 0);
74 ftu_active_cr2 : in std_logic_vector (15 downto 0);
75 ftu_active_cr3 : in std_logic_vector (15 downto 0);
76
77 --error message interface to ethernet control
78 ftu_error_calls : out std_logic_vector (15 DOWNTO 0) := (others => '0');
79 ftu_error_data : out std_logic_vector ((FTU_RS485_BLOCK_WIDTH - 1) downto 0) := (others => '0');
80 ftu_error_send : out std_logic := '0';
81 ftu_error_send_ack : in std_logic;
82 ftu_error_send_ready : in std_logic;
83
84 -- communication with static (config) RAM
85 -- this RAM is only read by FTU_control
86 static_RAM_busy : in std_logic;
87 static_RAM_started : in std_logic;
88 static_RAM_ready : in std_logic;
89 data_static_RAM : in std_logic_vector(15 downto 0) := (others => '0');
90 read_static_RAM : out std_logic := '0';
91 addr_static_RAM : out std_logic_vector(11 downto 0) := (others => '0');
92
93 -- communication with dynamic RAM (e.g. rates)
94 -- this RAM is only written by FTU_control
95 dynamic_RAM_busy : in std_logic;
96 dynamic_RAM_started : in std_logic;
97 dynamic_RAM_ready : in std_logic;
98 data_dynamic_RAM : out std_logic_vector(15 downto 0) := (others => '0');
99 write_dynamic_RAM : out std_logic := '0';
100 addr_dynamic_RAM : out std_logic_vector(11 downto 0) := (others => '0');
101
102 -- communication with FTU-list RAM
103 -- this RAM is only written by FTU_control
104 FTUlist_RAM_busy : in std_logic;
105 FTUlist_RAM_started : in std_logic;
106 FTUlist_RAM_ready : in std_logic;
107 data_FTUlist_RAM : out std_logic_vector(15 downto 0) := (others => '0');
108 write_FTUlist_RAM : out std_logic := '0';
109 addr_FTUlist_RAM : out std_logic_vector(11 downto 0) := (others => '0')
110
111 );
112end FTM_ftu_control;
113
114architecture Behavioral of FTM_ftu_control is
115
116 -- list of active FTUs, read out from static RAM before starting to contact FTUs
117 signal active_FTU_array_sig : active_FTU_array_type := ((others => '0'), (others => '0'), (others => '0'), (others => '0'));
118 --signal active_FTU_array_sig : active_FTU_array_type := ("0000000000000001", (others => '0'), (others => '0'), (others => '0'));
119
120 -- signals to count the number of responding FTUs (per crate and total) in case of a ping
121 signal FTU_answer_array_sig : FTU_answer_array_type := (0,0,0,0);
122 signal no_of_FTU_answer_sig : integer range 0 to (NO_OF_CRATES * NO_OF_FTUS_PER_CRATE) := 0;
123
124 -- FTU configuration data, read out from static RAM (board by board)
125 signal FTU_dac_array_RAM_sig : FTU_dac_array_type := ((others => '0'), (others => '0'), (others => '0'), (others => '0'), (others => '0'));
126 signal FTU_enable_array_RAM_sig : FTU_enable_array_type := ((others => '0'), (others => '0'), (others => '0'), (others => '0'));
127 signal FTU_prescaling_RAM_sig : std_logic_vector(15 downto 0) := (others => '0');
128
129 -- signals for receiver of FTU communication
130 signal rec_reset_sig : std_logic := '0'; -- reset
131 signal rec_data_sig : std_logic_vector (7 DOWNTO 0);
132 signal rec_block_sig : std_logic_vector (FTU_RS485_BLOCK_WIDTH - 1 downto 0); -- initialized in FTM_ftu_rs485_receiver
133 signal rec_valid_sig : std_logic; -- initialized in FTM_ftu_rs485_receiver
134
135 -- select signal to multiplex the different crates
136 signal sel_crate_sig : STD_LOGIC_VECTOR (2 downto 0) := "111";
137
138 -- global signals after multiplexer
139 signal rx_en_sig : std_logic := '0';
140 signal tx_en_sig : std_logic := '0';
141 signal rx_valid_sig : std_logic := '0';
142 signal tx_busy_sig : std_logic := '0';
143 signal tx_start_sig : std_logic := '0';
144 signal tx_data_sig : std_logic_vector (7 DOWNTO 0) := (others => '0');
145 signal rx_busy_sig : std_logic := '0';
146 signal start_int_sig : std_logic := '0';
147
148 -- signals for interpreter of FTU communication
149 signal FTU_brd_add_sig : std_logic_vector (5 DOWNTO 0) := (others => '0');
150 signal FTU_command_sig : std_logic_vector (7 DOWNTO 0) := (others => '1');
151 signal FTU_answer_ok_sig : std_logic; -- initialized in interpreter
152 signal FTU_dac_array_sig : FTU_dac_array_type; -- initialized in interpreter
153 signal FTU_enable_array_sig : FTU_enable_array_type; -- initialized in interpreter
154 signal FTU_rate_array_sig : FTU_rate_array_type; -- initialized in interpreter
155 signal FTU_overflow_sig : std_logic_vector(7 downto 0); -- initialized in interpreter
156 signal FTU_prescaling_sig : std_logic_vector(7 downto 0); -- initialized in interpreter
157 signal FTU_crc_error_cnt_sig : std_logic_vector(7 downto 0); -- initialized in interpreter
158 signal FTU_dna_sig : std_logic_vector(63 downto 0); -- initialized in interpreter
159
160 -- rx_enable and tx_enable lines from different FTM_ftu_rs485_interface
161 -- initialized in corresponding interface
162 signal rx_en_0_sig : STD_LOGIC;
163 signal tx_en_0_sig : STD_LOGIC;
164 signal rx_en_1_sig : STD_LOGIC;
165 signal tx_en_1_sig : STD_LOGIC;
166 signal rx_en_2_sig : STD_LOGIC;
167 signal tx_en_2_sig : STD_LOGIC;
168 signal rx_en_3_sig : STD_LOGIC;
169 signal tx_en_3_sig : STD_LOGIC;
170
171 signal tx_start_0_sig : std_logic := '0';
172 signal tx_data_0_sig : std_logic_vector (7 DOWNTO 0) := (others => '0');
173 signal tx_busy_0_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_0
174 signal rx_valid_0_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_0
175 signal rx_data_0_sig : std_logic_vector (7 DOWNTO 0); -- initialized in FTM_ftu_rs485_interface_0
176 signal rx_busy_0_sig : std_logic; -- initialized in FTU_rs485_interface_0
177
178 signal tx_start_1_sig : std_logic := '0';
179 signal tx_data_1_sig : std_logic_vector (7 DOWNTO 0) := (others => '0');
180 signal tx_busy_1_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_1
181 signal rx_valid_1_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_1
182 signal rx_data_1_sig : std_logic_vector (7 DOWNTO 0); -- initialized in FTM_ftu_rs485_interface_1
183 signal rx_busy_1_sig : std_logic; -- initialized in FTU_rs485_interface_1
184
185 signal tx_start_2_sig : std_logic := '0';
186 signal tx_data_2_sig : std_logic_vector (7 DOWNTO 0) := (others => '0');
187 signal tx_busy_2_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_2
188 signal rx_valid_2_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_2
189 signal rx_data_2_sig : std_logic_vector (7 DOWNTO 0); -- initialized in FTM_ftu_rs485_interface_2
190 signal rx_busy_2_sig : std_logic; -- initialized in FTU_rs485_interface_2
191
192 signal tx_start_3_sig : std_logic := '0';
193 signal tx_data_3_sig : std_logic_vector (7 DOWNTO 0) := (others => '0');
194 signal tx_busy_3_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_3
195 signal rx_valid_3_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_3
196 signal rx_data_3_sig : std_logic_vector (7 DOWNTO 0); -- initialized in FTM_ftu_rs485_interface_3
197 signal rx_busy_3_sig : std_logic; -- initialized in FTU_rs485_interface_3
198
199 -- signals to control and read out CRC
200 signal sel_crc_input_source_sig : std_logic := '0'; -- 0 -> FSM, 1 -> interpreter
201 signal reset_crc_sig : std_logic;
202 signal enable_crc_sig : std_logic;
203 signal crc_data_sig : std_logic_vector (FTU_RS485_BLOCK_WIDTH - 9 downto 0) := (others => '0');
204 signal reset_crc_from_FSM_sig : std_logic := '0';
205 signal reset_crc_from_interpreter_sig : std_logic;
206 signal enable_crc_from_FSM_sig : std_logic := '0';
207 signal enable_crc_from_interpreter_sig : std_logic;
208 signal crc_data_from_FSM_sig : std_logic_vector (FTU_RS485_BLOCK_WIDTH - 9 downto 0) := (others => '0');
209 signal crc_data_from_FSM_sig_cp : std_logic_vector (FTU_RS485_BLOCK_WIDTH - 9 downto 0) := (others => '0');
210 signal crc_sig : std_logic_vector(CRC_POLYNOMIAL'length - 1 downto 0);
211 signal crc_sig_inv : std_logic_vector(CRC_POLYNOMIAL'length - 1 downto 0);
212
213 -- various loop counters
214 --signal active_FTU_list_cnt : integer range 0 to NO_OF_CRATES := 0;
215 signal crate_cnt : integer range 0 to NO_OF_CRATES := 0;
216 signal FTU_cnt : integer range 0 to NO_OF_FTUS_PER_CRATE := 0;
217 signal FTU_register_cnt : integer range 0 to (NO_OF_FTU_ENABLE_REG + NO_OF_FTU_DAC_REG + 1) := 0;
218 signal FTU_command_cnt : integer range 0 to 3 := 0;
219 signal frame_cnt : integer range 0 to (FTU_RS485_BLOCK_WIDTH / 8) := 0;
220 signal FTU_list_reg_cnt : integer range 0 to NO_OF_FTU_LIST_REG := 0;
221 signal FTU_list_header_cnt : integer range 0 to (FTU_LIST_RAM_OFFSET + 1):= 0;
222 signal DD_RAM_reg_cnt : integer range 0 to NO_OF_DD_RAM_REG := 0;
223
224 -- counter to define timeout and number of retries
225 signal timeout_cnt : integer range 0 to FTU_RS485_TIMEOUT := 0;
226 signal retry_cnt : integer range 0 to FTU_RS485_NO_OF_RETRY := 0;
227
228 --Zwischenrechnungen
229 signal FTU_cnt_offset_sig : integer range 0 to (NO_OF_DD_RAM_REG * NO_OF_FTUS_PER_CRATE) := 0;
230 signal crate_cnt_offset_sig : integer range 0 to (NO_OF_CRATES * NO_OF_FTUS_PER_CRATE * NO_OF_DD_RAM_REG) := 0;
231
232 component FTM_ftu_rs485_interface
233 port(
234 clk : IN std_logic;
235 -- RS485
236 rx_d : IN std_logic;
237 rx_en : OUT std_logic;
238 tx_d : OUT std_logic;
239 tx_en : OUT std_logic;
240 -- FPGA
241 rx_data : OUT std_logic_vector (7 DOWNTO 0);
242 rx_busy : OUT std_logic := '0';
243 rx_valid : OUT std_logic := '0';
244 tx_data : IN std_logic_vector (7 DOWNTO 0);
245 tx_busy : OUT std_logic := '0';
246 tx_start : IN std_logic
247 );
248 end component;
249
250 component FTM_ftu_rs485_receiver
251 port(
252 rec_clk : in std_logic;
253 rec_reset : in std_logic;
254 --rx_busy : in std_logic;
255 rec_din : in std_logic_vector(7 downto 0);
256 rec_den : in std_logic;
257 rec_dout : out std_logic_vector(FTU_RS485_BLOCK_WIDTH - 1 downto 0) := (others => '0');
258 rec_valid : out std_logic := '0'
259 );
260 end component;
261
262 component FTM_ftu_rs485_interpreter
263 port(
264 clk : IN std_logic;
265 data_block : IN std_logic_vector(FTU_RS485_BLOCK_WIDTH - 1 downto 0);
266 block_valid : IN std_logic;
267 crc : IN std_logic_vector(7 downto 0);
268 FTU_brd_add : IN std_logic_vector(5 downto 0);
269 FTU_command : IN std_logic_vector(7 downto 0);
270 reset_crc : OUT std_logic := '0';
271 enable_crc : OUT std_logic := '0';
272 FTU_answer_ok : OUT std_logic := '0';
273 FTU_dac_array : OUT FTU_dac_array_type;
274 FTU_enable_array : OUT FTU_enable_array_type;
275 FTU_rate_array : OUT FTU_rate_array_type;
276 FTU_overflow : OUT std_logic_vector(7 downto 0);
277 FTU_prescaling : OUT std_logic_vector(7 downto 0);
278 FTU_crc_error_cnt : OUT std_logic_vector(7 downto 0);
279 FTU_dna : OUT std_logic_vector(63 downto 0)
280 );
281 end component;
282
283 component ucrc_par
284 generic(
285 POLYNOMIAL : std_logic_vector;
286 INIT_VALUE : std_logic_vector;
287 DATA_WIDTH : integer range 2 to 256;
288 SYNC_RESET : integer range 0 to 1
289 );
290 port(
291 clk_i : in std_logic;
292 rst_i : in std_logic;
293 clken_i : in std_logic;
294 data_i : in std_logic_vector(DATA_WIDTH - 1 downto 0);
295 match_o : out std_logic;
296 crc_o : out std_logic_vector(POLYNOMIAL'length - 1 downto 0)
297 );
298 end component;
299
300 type FTM_ftu_rs485_control_StateType is (INIT, IDLE, ACTIVE_LIST, READ_CONFIG, TRANSMIT_CONFIG,
301 PING, PING_END, FTU_LIST,
302 SEND_ERROR_1, SEND_ERROR_2,
303 RATES, RATES_1, RATES_2, RATES_3,
304 DD_RAM, DD_RAM_1, DD_RAM_2, DD_RAM_3,
305 READ_CONFIG_1, READ_CONFIG_2, READ_CONFIG_3,
306 TRANSMIT_CONFIG_1, TRANSMIT_CONFIG_2, TRANSMIT_CONFIG_3,
307 PING_1, PING_2, PING_3, PING_END_1, PING_END_2, PING_END_3,
308 FTU_LIST_1, FTU_LIST_2, FTU_LIST_3);
309 signal FTM_ftu_rs485_control_State : FTM_ftu_rs485_control_StateType;
310 signal after_error_State : FTM_ftu_rs485_control_StateType;
311
312begin
313
314 Inst_FTM_ftu_rs485_interface_0 : FTM_ftu_rs485_interface -- crate 0
315 port map(
316 clk => clk_50MHz,
317 -- RS485
318 rx_d => rx_d_0,
319 rx_en => rx_en_0_sig,
320 tx_d => tx_d_0,
321 tx_en => tx_en_0_sig,
322 -- FPGA
323 rx_data => rx_data_0_sig,
324 rx_busy => rx_busy_0_sig,
325 rx_valid => rx_valid_0_sig,
326 tx_data => tx_data_0_sig,
327 tx_busy => tx_busy_0_sig,
328 tx_start => tx_start_0_sig
329 );
330
331 Inst_FTM_ftu_rs485_interface_1 : FTM_ftu_rs485_interface -- crate 1
332 port map(
333 clk => clk_50MHz,
334 -- RS485
335 rx_d => rx_d_1,
336 rx_en => rx_en_1_sig,
337 tx_d => tx_d_1,
338 tx_en => tx_en_1_sig,
339 -- FPGA
340 rx_data => rx_data_1_sig,
341 rx_busy => rx_busy_1_sig,
342 rx_valid => rx_valid_1_sig,
343 tx_data => tx_data_1_sig,
344 tx_busy => tx_busy_1_sig,
345 tx_start => tx_start_1_sig
346 );
347
348 Inst_FTM_ftu_rs485_interface_2 : FTM_ftu_rs485_interface -- crate 2
349 port map(
350 clk => clk_50MHz,
351 -- RS485
352 rx_d => rx_d_2,
353 rx_en => rx_en_2_sig,
354 tx_d => tx_d_2,
355 tx_en => tx_en_2_sig,
356 -- FPGA
357 rx_data => rx_data_2_sig,
358 rx_busy => rx_busy_2_sig,
359 rx_valid => rx_valid_2_sig,
360 tx_data => tx_data_2_sig,
361 tx_busy => tx_busy_2_sig,
362 tx_start => tx_start_2_sig
363 );
364
365 Inst_FTM_ftu_rs485_interface_3 : FTM_ftu_rs485_interface -- crate 3
366 port map(
367 clk => clk_50MHz,
368 -- RS485
369 rx_d => rx_d_3,
370 rx_en => rx_en_3_sig,
371 tx_d => tx_d_3,
372 tx_en => tx_en_3_sig,
373 -- FPGA
374 rx_data => rx_data_3_sig,
375 rx_busy => rx_busy_3_sig,
376 rx_valid => rx_valid_3_sig,
377 tx_data => tx_data_3_sig,
378 tx_busy => tx_busy_3_sig,
379 tx_start => tx_start_3_sig
380 );
381
382 Inst_FTM_ftu_rs485_receiver : FTM_ftu_rs485_receiver
383 port map(
384 rec_clk => clk_50MHz,
385 rec_reset => rec_reset_sig,
386 --rx_busy =>,
387 rec_din => rec_data_sig,
388 rec_den => rx_valid_sig,
389 rec_dout => rec_block_sig,
390 rec_valid => rec_valid_sig
391 );
392
393 Inst_FTM_ftu_rs485_interpreter : FTM_ftu_rs485_interpreter
394 port map(
395 clk => clk_50MHz,
396 data_block => rec_block_sig,
397 block_valid => start_int_sig,
398 crc => crc_sig,
399 FTU_brd_add => FTU_brd_add_sig,
400 FTU_command => FTU_command_sig,
401 reset_crc => reset_crc_from_interpreter_sig,
402 enable_crc => enable_crc_from_interpreter_sig,
403 FTU_answer_ok => FTU_answer_ok_sig,
404 FTU_dac_array => FTU_dac_array_sig,
405 FTU_enable_array => FTU_enable_array_sig,
406 FTU_rate_array => FTU_rate_array_sig,
407 FTU_overflow => FTU_overflow_sig,
408 FTU_prescaling => FTU_prescaling_sig,
409 FTU_crc_error_cnt => FTU_crc_error_cnt_sig,
410 FTU_dna => FTU_dna_sig
411 );
412
413 Inst_ucrc_par : ucrc_par
414 generic map(
415 POLYNOMIAL => CRC_POLYNOMIAL,
416 INIT_VALUE => CRC_INIT_VALUE,
417 DATA_WIDTH => (FTU_RS485_BLOCK_WIDTH - 8),
418 SYNC_RESET => 1
419 )
420 port map(
421 clk_i => clk_50MHz,
422 rst_i => reset_crc_sig,
423 clken_i => enable_crc_sig,
424 data_i => crc_data_sig,
425 match_o => open,
426 crc_o => crc_sig_inv
427 );
428
429 -- Main finite state machine to control all 40 FTUs
430 FTM_ftu_rs485_control_FSM: process (clk_50MHz)
431 begin
432 if Rising_edge(clk_50MHz) then
433 case FTM_ftu_rs485_control_State is
434
435 when INIT => -- reset CRC register
436 reset_crc_from_FSM_sig <= '1';
437 FTM_ftu_rs485_control_State <= IDLE;
438
439 when IDLE => -- wait for command from outside
440 sel_crate_sig <= "111";
441 sel_crc_input_source_sig <= '0';
442 reset_crc_from_FSM_sig <= '0';
443 enable_crc_from_FSM_sig <= '0';
444 --new_config_done <= '0';
445 --ping_all_done <= '0';
446 --read_rates_done <= '0';
447 if (new_config = '1') then
448 new_config_done <= '0';--
449 new_config_started <= '1';
450 ping_all_started <= '0';
451 read_rates_started <= '0';
452 FTM_ftu_rs485_control_State <= ACTIVE_LIST;
453 elsif (new_config = '0' and ping_all = '1') then
454 ping_all_done <= '0';--
455 new_config_started <= '0';
456 ping_all_started <= '1';
457 read_rates_started <= '0';
458 rec_reset_sig <= '1';
459 FTM_ftu_rs485_control_State <= PING;
460 elsif (new_config = '0' and ping_all = '0' and read_rates = '1') then
461 read_rates_done <= '0';--
462 new_config_started <= '0';
463 ping_all_started <= '0';
464 read_rates_started <= '1';
465 FTM_ftu_rs485_control_State <= RATES;
466 else
467 new_config_started <= '0';
468 ping_all_started <= '0';
469 read_rates_started <= '0';
470 FTM_ftu_rs485_control_State <= IDLE;
471 end if;
472
473 when ACTIVE_LIST => -- copy active FTU list from inputs to array
474 active_FTU_array_sig(0) <= ftu_active_cr0;
475 active_FTU_array_sig(1) <= ftu_active_cr1;
476 active_FTU_array_sig(2) <= ftu_active_cr2;
477 active_FTU_array_sig(3) <= ftu_active_cr3;
478 FTM_ftu_rs485_control_State <= READ_CONFIG;
479
480-- when ACTIVE_LIST => -- loop over 4 crates to get active FTU list
481-- if (active_FTU_list_cnt < NO_OF_CRATES) then
482-- active_FTU_list_cnt <= active_FTU_list_cnt + 1;
483-- FTM_ftu_rs485_control_State <= ACTIVE_LIST_1;
484-- else
485-- active_FTU_list_cnt <= 0;
486-- FTM_ftu_rs485_control_State <= READ_CONFIG;
487-- end if;
488
489-- when ACTIVE_LIST_1 =>
490-- if (static_RAM_busy = '0') then
491-- read_static_RAM <= '1';
492-- addr_static_RAM <= conv_std_logic_vector(STATIC_RAM_ACT_FTU_OFFSET + (active_FTU_list_cnt - 1), STATIC_RAM_ADDR_WIDTH);
493-- FTM_ftu_rs485_control_State <= ACTIVE_LIST_2;
494-- end if;
495
496-- when ACTIVE_LIST_2 =>
497-- if (static_RAM_started = '1') then
498-- FTM_ftu_rs485_control_State <= ACTIVE_LIST_3;
499-- end if;
500
501-- when ACTIVE_LIST_3 =>
502-- if (static_RAM_ready = '1') then
503-- active_FTU_array_sig(active_FTU_list_cnt - 1) <= data_static_RAM;
504-- read_static_RAM <= '0';
505-- FTM_ftu_rs485_control_State <= ACTIVE_LIST;
506-- end if;
507
508 when READ_CONFIG => -- read configuration of FTUs (one by one)
509 if (crate_cnt < NO_OF_CRATES) then
510 sel_crate_sig <= conv_std_logic_vector(crate_cnt, 3);
511 if (FTU_cnt < NO_OF_FTUS_PER_CRATE) then
512 if (FTU_register_cnt < (NO_OF_FTU_ENABLE_REG + NO_OF_FTU_DAC_REG + 1)) then
513 FTU_register_cnt <= FTU_register_cnt + 1;
514 FTM_ftu_rs485_control_State <= READ_CONFIG_1;
515 else
516 FTU_cnt <= FTU_cnt + 1;
517 FTU_register_cnt <= 0;
518 if (active_FTU_array_sig(crate_cnt)(FTU_cnt) = '1') then
519 rec_reset_sig <= '1';
520 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG;
521 else
522 FTM_ftu_rs485_control_State <= READ_CONFIG;
523 end if;
524 end if;
525 else
526 crate_cnt <= crate_cnt + 1;
527 FTU_cnt <= 0;
528 FTM_ftu_rs485_control_State <= READ_CONFIG;
529 end if;
530 else
531 crate_cnt <= 0;
532 new_config_started <= '0';
533 new_config_done <= '1';
534 sel_crate_sig <= "111";
535 FTM_ftu_rs485_control_State <= IDLE;
536 end if;
537
538 when READ_CONFIG_1 =>
539 if (static_RAM_busy = '0') then
540 read_static_RAM <= '1';
541 addr_static_RAM <= conv_std_logic_vector(STATIC_RAM_CFG_FTU_OFFSET +
542 crate_cnt * NO_OF_FTUS_PER_CRATE * (NO_OF_FTU_ENABLE_REG + NO_OF_FTU_DAC_REG + 1) +
543 FTU_cnt * (NO_OF_FTU_ENABLE_REG + NO_OF_FTU_DAC_REG + 1) +
544 (FTU_register_cnt - 1), STATIC_RAM_ADDR_WIDTH);
545 FTM_ftu_rs485_control_State <= READ_CONFIG_2;
546 end if;
547
548 when READ_CONFIG_2 =>
549 if (static_RAM_started = '1') then
550 FTM_ftu_rs485_control_State <= READ_CONFIG_3;
551 end if;
552
553 when READ_CONFIG_3 =>
554 if (static_RAM_ready = '1') then
555 if ((FTU_register_cnt - 1) < NO_OF_FTU_ENABLE_REG) then
556 FTU_enable_array_RAM_sig(FTU_register_cnt - 1) <= data_static_RAM;
557 elsif ((FTU_register_cnt - 1) < (NO_OF_FTU_ENABLE_REG + NO_OF_FTU_DAC_REG)) then
558 FTU_dac_array_RAM_sig((FTU_register_cnt - 1) - NO_OF_FTU_ENABLE_REG) <= data_static_RAM;
559 elsif ((FTU_register_cnt - 1) = (NO_OF_FTU_ENABLE_REG + NO_OF_FTU_DAC_REG)) then
560 FTU_prescaling_RAM_sig <= data_static_RAM;
561 end if;
562 read_static_RAM <= '0';
563 FTM_ftu_rs485_control_State <= READ_CONFIG;
564 end if;
565
566 when TRANSMIT_CONFIG => -- send configuration to FTUs (one by one)
567 rec_reset_sig <= '0';
568 if (FTU_command_cnt = 0) then -- DACs
569 FTU_command_cnt <= FTU_command_cnt + 1;
570 enable_crc_from_FSM_sig <= '1';
571 crc_data_from_FSM_sig <= "00000000"
572 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
573 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
574 & "00000000"
575 & FTU_dac_array_RAM_sig(4)(15 downto 8) & FTU_dac_array_RAM_sig(4)(7 downto 0)
576 & FTU_dac_array_RAM_sig(3)(15 downto 8) & FTU_dac_array_RAM_sig(3)(7 downto 0)
577 & FTU_dac_array_RAM_sig(2)(15 downto 8) & FTU_dac_array_RAM_sig(2)(7 downto 0)
578 & FTU_dac_array_RAM_sig(1)(15 downto 8) & FTU_dac_array_RAM_sig(1)(7 downto 0)
579 & FTU_dac_array_RAM_sig(0)(15 downto 8) & FTU_dac_array_RAM_sig(0)(7 downto 0)
580 & "00000000" & FIRMWARE_ID & FTM_ADDRESS
581 & "00" & conv_std_logic_vector((FTU_cnt - 1),4) & conv_std_logic_vector(crate_cnt,2)
582 & FTU_RS485_START_DELIM;
583 FTU_brd_add_sig <= conv_std_logic_vector((FTU_cnt - 1),4) & conv_std_logic_vector(crate_cnt,2);
584 FTU_command_sig <= "00000000";
585 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG_1;
586 elsif (FTU_command_cnt = 1) then -- enables
587 FTU_command_cnt <= FTU_command_cnt + 1;
588 enable_crc_from_FSM_sig <= '1';
589 crc_data_from_FSM_sig <= "00000000"
590 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
591 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
592 & "00000000" & "00000000" & "00000000"
593 & FTU_enable_array_RAM_sig(3)(15 downto 8) & FTU_enable_array_RAM_sig(3)(7 downto 0)
594 & FTU_enable_array_RAM_sig(2)(15 downto 8) & FTU_enable_array_RAM_sig(2)(7 downto 0)
595 & FTU_enable_array_RAM_sig(1)(15 downto 8) & FTU_enable_array_RAM_sig(1)(7 downto 0)
596 & FTU_enable_array_RAM_sig(0)(15 downto 8) & FTU_enable_array_RAM_sig(0)(7 downto 0)
597 & "00000011" & FIRMWARE_ID & FTM_ADDRESS
598 & "00" & conv_std_logic_vector((FTU_cnt - 1),4) & conv_std_logic_vector(crate_cnt,2)
599 & FTU_RS485_START_DELIM;
600 FTU_brd_add_sig <= conv_std_logic_vector((FTU_cnt - 1),4) & conv_std_logic_vector(crate_cnt,2);
601 FTU_command_sig <= "00000011";
602 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG_1;
603 elsif (FTU_command_cnt = 2) then -- prescaling
604 FTU_command_cnt <= FTU_command_cnt + 1;
605 enable_crc_from_FSM_sig <= '1';
606 crc_data_from_FSM_sig <= "00000000"
607 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
608 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
609 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
610 & "00000000" & "00000000" & "00000000" & "00000000"
611 & FTU_prescaling_RAM_sig(15 downto 8) & FTU_prescaling_RAM_sig(7 downto 0)
612 & "00000110" & FIRMWARE_ID & FTM_ADDRESS
613 & "00" & conv_std_logic_vector((FTU_cnt - 1),4) & conv_std_logic_vector(crate_cnt,2)
614 & FTU_RS485_START_DELIM;
615 FTU_brd_add_sig <= conv_std_logic_vector((FTU_cnt - 1),4) & conv_std_logic_vector(crate_cnt,2);
616 FTU_command_sig <= "00000110";
617 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG_1;
618 else
619 FTU_command_cnt <= 0;
620 enable_crc_from_FSM_sig <= '0';
621 FTM_ftu_rs485_control_State <= READ_CONFIG;
622 end if;
623
624 when TRANSMIT_CONFIG_1 => -- wait one cycle for CRC calculation
625 enable_crc_from_FSM_sig <= '0';
626 crc_data_from_FSM_sig_cp <= crc_data_from_FSM_sig;
627 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG_2;
628
629 when TRANSMIT_CONFIG_2 => -- transmit byte by byte
630 if (tx_busy_sig = '0') then
631 if (frame_cnt < 27) then
632 frame_cnt <= frame_cnt + 1;
633 tx_data_sig <= crc_data_from_FSM_sig (7 downto 0);
634 crc_data_from_FSM_sig <= "00000000" & crc_data_from_FSM_sig ((FTU_RS485_BLOCK_WIDTH - 9) downto 8);
635 tx_start_sig <= '1';
636 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG_2;
637 elsif (frame_cnt = 27) then
638 frame_cnt <= frame_cnt + 1;
639 ftu_error_data <= crc_sig & crc_data_from_FSM_sig_cp;
640 tx_data_sig <= crc_sig;
641 tx_start_sig <= '1';
642 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG_2;
643 else
644 frame_cnt <= 0;
645 reset_crc_from_FSM_sig <= '1';
646 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG_3;
647 end if;
648 else
649 tx_start_sig <= '0';
650 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG_2;
651 end if;
652
653 when TRANSMIT_CONFIG_3 => -- wait for FTU answer
654 reset_crc_from_FSM_sig <= '0';
655 if (FTU_answer_ok_sig = '1') then
656 timeout_cnt <= 0;
657 retry_cnt <= 0;
658 sel_crc_input_source_sig <= '0';
659 if (retry_cnt = 0) then -- no errors
660 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG;
661 else -- send error message and move to next command;
662 ftu_error_calls <= conv_std_logic_vector((retry_cnt + 1), 16);
663 after_error_State <= TRANSMIT_CONFIG;
664 FTM_ftu_rs485_control_State <= SEND_ERROR_1;
665 end if;
666 else
667 if (timeout_cnt < FTU_RS485_TIMEOUT) then
668 timeout_cnt <= timeout_cnt + 1;
669 sel_crc_input_source_sig <= '1';
670 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG_3;
671 else
672 timeout_cnt <= 0;
673 sel_crc_input_source_sig <= '0';
674 rec_reset_sig <= '1';
675 if (retry_cnt < FTU_RS485_NO_OF_RETRY) then
676 retry_cnt <= retry_cnt + 1;
677 FTU_command_cnt <= FTU_command_cnt - 1; -- try this command again
678 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG;
679 else
680 retry_cnt <= 0;
681 FTU_command_cnt <= FTU_command_cnt; -- send error message and move to next command
682 ftu_error_calls <= (others => '0');
683 after_error_State <= TRANSMIT_CONFIG;
684 FTM_ftu_rs485_control_State <= SEND_ERROR_1;
685 end if;
686 end if;
687 end if;
688
689 when SEND_ERROR_1 => -- send an error message
690 ftu_error_send <= '1';
691 if (ftu_error_send_ack = '1') then
692 ftu_error_send <= '0';
693 FTM_ftu_rs485_control_State <= SEND_ERROR_2;
694 end if;
695
696 when SEND_ERROR_2 =>
697 if (ftu_error_send_ready = '1') then
698 FTM_ftu_rs485_control_State <= after_error_state;
699 end if;
700
701 when PING => -- ping all FTUs
702 rec_reset_sig <= '0';
703 if (crate_cnt < NO_OF_CRATES) then
704 sel_crate_sig <= conv_std_logic_vector(crate_cnt, 3);
705 if (FTU_cnt < NO_OF_FTUS_PER_CRATE) then
706 FTU_cnt <= FTU_cnt + 1;
707 if (active_FTU_array_sig(crate_cnt)(FTU_cnt) = '1') then
708 enable_crc_from_FSM_sig <= '1';
709 crc_data_from_FSM_sig <= "00000000"
710 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
711 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
712 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
713 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
714 & "00000101" & FIRMWARE_ID & FTM_ADDRESS
715 & "00" & conv_std_logic_vector(FTU_cnt,4) & conv_std_logic_vector(crate_cnt,2)
716 & FTU_RS485_START_DELIM;
717 FTU_brd_add_sig <= conv_std_logic_vector(FTU_cnt,4) & conv_std_logic_vector(crate_cnt,2);
718 FTU_command_sig <= "00000101";
719 FTM_ftu_rs485_control_State <= PING_1;
720 else
721 FTM_ftu_rs485_control_State <= PING;
722 end if;
723 else
724 crate_cnt <= crate_cnt + 1;
725 FTU_cnt <= 0;
726 FTM_ftu_rs485_control_State <= PING;
727 end if;
728 else
729 crate_cnt <= 0;
730 FTM_ftu_rs485_control_State <= PING_END;
731 end if;
732
733 when PING_1 => -- wait one cycle for CRC calculation
734 enable_crc_from_FSM_sig <= '0';
735 rec_reset_sig <= '1';
736 FTM_ftu_rs485_control_State <= PING_2;
737
738 when PING_2 => -- transmit byte by byte
739 rec_reset_sig <= '0';
740 if (tx_busy_sig = '0') then
741 if (frame_cnt < 27) then
742 frame_cnt <= frame_cnt + 1;
743 tx_data_sig <= crc_data_from_FSM_sig (7 downto 0);
744 crc_data_from_FSM_sig <= "00000000" & crc_data_from_FSM_sig ((FTU_RS485_BLOCK_WIDTH - 9) downto 8);
745 tx_start_sig <= '1';
746 FTM_ftu_rs485_control_State <= PING_2;
747 elsif (frame_cnt = 27) then
748 frame_cnt <= frame_cnt + 1;
749 tx_data_sig <= crc_sig;
750 tx_start_sig <= '1';
751 FTM_ftu_rs485_control_State <= PING_2;
752 else
753 frame_cnt <= 0;
754 reset_crc_from_FSM_sig <= '1';
755 FTM_ftu_rs485_control_State <= PING_3;
756 end if;
757 else
758 tx_start_sig <= '0';
759 FTM_ftu_rs485_control_State <= PING_2;
760 end if;
761
762 when PING_3 => -- wait for FTU answer
763 reset_crc_from_FSM_sig <= '0';
764 if (FTU_answer_ok_sig = '1') then
765 FTU_answer_array_sig(crate_cnt) <= FTU_answer_array_sig(crate_cnt) + 1;
766 no_of_FTU_answer_sig <= no_of_FTU_answer_sig + 1;
767 timeout_cnt <= 0;
768 sel_crc_input_source_sig <= '0';
769 FTM_ftu_rs485_control_State <= FTU_LIST;
770 else
771 if (timeout_cnt < FTU_RS485_TIMEOUT) then
772 timeout_cnt <= timeout_cnt + 1;
773 sel_crc_input_source_sig <= '1';
774 FTM_ftu_rs485_control_State <= PING_3;
775 else
776 timeout_cnt <= 0;
777 sel_crc_input_source_sig <= '0';
778 rec_reset_sig <= '1';
779 if (retry_cnt < FTU_RS485_NO_OF_RETRY) then
780 retry_cnt <= retry_cnt + 1;
781 FTU_cnt <= FTU_cnt - 1; -- repeat this FTU
782 FTM_ftu_rs485_control_State <= PING;
783 else
784 FTU_cnt <= FTU_cnt; -- move on
785 FTM_ftu_rs485_control_State <= FTU_LIST;
786 end if;
787 end if;
788 end if;
789
790 when FTU_LIST => -- fill FTU-list for actual FTU
791 rec_reset_sig <= '0';
792 if (FTU_list_reg_cnt < NO_OF_FTU_LIST_REG) then
793 FTU_list_reg_cnt <= FTU_list_reg_cnt + 1;
794 FTM_ftu_rs485_control_State <= FTU_LIST_1;
795 else
796 FTU_list_reg_cnt <= 0;
797 retry_cnt <= 0;
798 FTM_ftu_rs485_control_State <= PING;
799 end if;
800
801 when FTU_LIST_1 =>
802 if (FTUlist_RAM_busy = '0') then
803 write_FTUlist_RAM <= '1';
804 addr_FTUlist_RAM <= conv_std_logic_vector(FTU_LIST_RAM_OFFSET +
805 (crate_cnt * NO_OF_FTUS_PER_CRATE * NO_OF_FTU_LIST_REG) +
806 ((FTU_cnt - 1) * NO_OF_FTU_LIST_REG) +
807 (FTU_list_reg_cnt - 1), FTU_LIST_RAM_ADDR_WIDTH);
808 if (retry_cnt < FTU_RS485_NO_OF_RETRY) then
809 if ((FTU_list_reg_cnt - 1) = 0) then
810 data_FTUlist_RAM <= "000000" & conv_std_logic_vector((retry_cnt + 1),2) & "00" & FTU_brd_add_sig;
811 elsif ((FTU_list_reg_cnt - 1) = 1) then
812 data_FTUlist_RAM <= FTU_dna_sig(63 downto 48);
813 elsif ((FTU_list_reg_cnt - 1) = 2) then
814 data_FTUlist_RAM <= FTU_dna_sig(47 downto 32);
815 elsif ((FTU_list_reg_cnt - 1) = 3) then
816 data_FTUlist_RAM <= FTU_dna_sig(31 downto 16);
817 elsif ((FTU_list_reg_cnt - 1) = 4) then
818 data_FTUlist_RAM <= FTU_dna_sig(15 downto 0);
819 elsif ((FTU_list_reg_cnt - 1) = 5) then
820 data_FTUlist_RAM <= "00000000" & FTU_crc_error_cnt_sig;
821 end if;
822 else
823 data_FTUlist_RAM <= (others => '0');
824 end if;
825 FTM_ftu_rs485_control_State <= FTU_LIST_2;
826 end if;
827
828 when FTU_LIST_2 =>
829 if (FTUlist_RAM_started = '1') then
830 write_FTUlist_RAM <= '0';
831 FTM_ftu_rs485_control_State <= FTU_LIST_3;
832 end if;
833
834 when FTU_LIST_3 =>
835 if (FTUlist_RAM_ready = '1') then
836 FTM_ftu_rs485_control_State <= FTU_LIST;
837 end if;
838
839 when PING_END => -- add final ping statistics to FTU-list
840 if (FTU_list_header_cnt < FTU_LIST_RAM_OFFSET) then
841 --FTU_list_header_cnt <= FTU_list_header_cnt + 1;
842 FTM_ftu_rs485_control_State <= PING_END_1;
843 else
844 FTU_list_header_cnt <= 0;
845 ping_all_started <= '0';
846 ping_all_done <= '1';
847 sel_crate_sig <= "111";
848 FTU_answer_array_sig(0) <= 0;
849 FTU_answer_array_sig(1) <= 0;
850 FTU_answer_array_sig(2) <= 0;
851 FTU_answer_array_sig(3) <= 0;
852 no_of_FTU_answer_sig <= 0;
853 FTM_ftu_rs485_control_State <= IDLE;
854 end if;
855
856 when PING_END_1 =>
857 if (FTUlist_RAM_busy = '0') then
858 write_FTUlist_RAM <= '1';
859 --addr_FTUlist_RAM <= conv_std_logic_vector((FTU_list_header_cnt - 1), FTU_LIST_RAM_ADDR_WIDTH);
860 addr_FTUlist_RAM <= conv_std_logic_vector((FTU_list_header_cnt), FTU_LIST_RAM_ADDR_WIDTH);
861 --if ((FTU_list_header_cnt - 1) = 0) then
862 if ((FTU_list_header_cnt) = 0) then
863 data_FTUlist_RAM <= conv_std_logic_vector(no_of_FTU_answer_sig, 16);
864 --elsif ((FTU_list_header_cnt - 1) < 5) then
865 elsif ((FTU_list_header_cnt) < 5) then
866 --data_FTUlist_RAM <= conv_std_logic_vector(FTU_answer_array_sig(FTU_list_header_cnt - 2), 16);
867 data_FTUlist_RAM <= conv_std_logic_vector(FTU_answer_array_sig(FTU_list_header_cnt - 1), 16);
868 --elsif ((FTU_list_header_cnt - 1) < 9) then
869 elsif ((FTU_list_header_cnt) < 9) then
870 --data_FTUlist_RAM <= active_FTU_array_sig(FTU_list_header_cnt - 6);
871 --data_FTUlist_RAM <= conv_std_logic_vector(FTU_list_header_cnt - 6, 16);
872 data_FTUlist_RAM <= active_FTU_array_sig(FTU_list_header_cnt - 5);
873 end if;
874 FTM_ftu_rs485_control_State <= PING_END_2;
875 end if;
876
877 when PING_END_2 =>
878 if (FTUlist_RAM_started = '1') then
879 write_FTUlist_RAM <= '0';
880 FTM_ftu_rs485_control_State <= PING_END_3;
881 end if;
882
883 when PING_END_3 =>
884 if (FTUlist_RAM_ready = '1') then
885 FTU_list_header_cnt <= FTU_list_header_cnt + 1;
886 FTM_ftu_rs485_control_State <= PING_END;
887 end if;
888
889 when RATES => -- read all FTU rates
890 rec_reset_sig <= '0';
891 if (crate_cnt < NO_OF_CRATES) then
892 sel_crate_sig <= conv_std_logic_vector(crate_cnt, 3);
893 if (FTU_cnt < NO_OF_FTUS_PER_CRATE) then
894 FTU_cnt <= FTU_cnt + 1;
895 if (active_FTU_array_sig(crate_cnt)(FTU_cnt) = '1') then
896 enable_crc_from_FSM_sig <= '1';
897 crc_data_from_FSM_sig <= "00000000"
898 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
899 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
900 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
901 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000" & "00000000"
902 & "00000010" & FIRMWARE_ID & FTM_ADDRESS
903 & "00" & conv_std_logic_vector(FTU_cnt,4) & conv_std_logic_vector(crate_cnt,2)
904 & FTU_RS485_START_DELIM;
905 FTU_brd_add_sig <= conv_std_logic_vector(FTU_cnt,4) & conv_std_logic_vector(crate_cnt,2);
906 FTU_command_sig <= "00000010";
907 FTM_ftu_rs485_control_State <= RATES_1;
908 else
909 FTM_ftu_rs485_control_State <= RATES;
910 end if;
911 else
912 crate_cnt <= crate_cnt + 1;
913 FTU_cnt <= 0;
914 FTM_ftu_rs485_control_State <= RATES;
915 end if;
916 else
917 crate_cnt <= 0;
918 read_rates_started <= '0';
919 read_rates_done <= '1';
920 sel_crate_sig <= "111";
921 FTM_ftu_rs485_control_State <= IDLE;
922 end if;
923
924 when RATES_1 => -- wait one cycle for CRC calculation
925 enable_crc_from_FSM_sig <= '0';
926 crc_data_from_FSM_sig_cp <= crc_data_from_FSM_sig;
927 FTM_ftu_rs485_control_State <= RATES_2;
928
929 when RATES_2 => -- transmit byte by byte
930 if (tx_busy_sig = '0') then
931 if (frame_cnt < 27) then
932 frame_cnt <= frame_cnt + 1;
933 tx_data_sig <= crc_data_from_FSM_sig (7 downto 0);
934 crc_data_from_FSM_sig <= "00000000" & crc_data_from_FSM_sig ((FTU_RS485_BLOCK_WIDTH - 9) downto 8);
935 tx_start_sig <= '1';
936 FTM_ftu_rs485_control_State <= RATES_2;
937 elsif (frame_cnt = 27) then
938 frame_cnt <= frame_cnt + 1;
939 ftu_error_data <= crc_sig & crc_data_from_FSM_sig_cp;
940 tx_data_sig <= crc_sig;
941 tx_start_sig <= '1';
942 FTM_ftu_rs485_control_State <= RATES_2;
943 else
944 frame_cnt <= 0;
945 reset_crc_from_FSM_sig <= '1';
946 FTM_ftu_rs485_control_State <= RATES_3;
947 end if;
948 else
949 tx_start_sig <= '0';
950 FTM_ftu_rs485_control_State <= RATES_2;
951 end if;
952
953 when RATES_3 => -- wait for FTU answer
954 reset_crc_from_FSM_sig <= '0';
955 if (FTU_answer_ok_sig = '1') then
956 timeout_cnt <= 0;
957 sel_crc_input_source_sig <= '0';
958 --FTM_ftu_rs485_control_State <= RATES;
959 if (retry_cnt = 0) then -- no errors
960 FTM_ftu_rs485_control_State <= DD_RAM;
961 else -- send error message and move to next command;
962 ftu_error_calls <= conv_std_logic_vector((retry_cnt + 1), 16);
963 after_error_State <= DD_RAM;
964 FTM_ftu_rs485_control_State <= SEND_ERROR_1;
965 end if;
966 else
967 if (timeout_cnt < FTU_RS485_TIMEOUT) then
968 timeout_cnt <= timeout_cnt + 1;
969 sel_crc_input_source_sig <= '1';
970 FTM_ftu_rs485_control_State <= RATES_3;
971 else
972 timeout_cnt <= 0;
973 sel_crc_input_source_sig <= '0';
974 rec_reset_sig <= '1';
975 if (retry_cnt < FTU_RS485_NO_OF_RETRY) then
976 retry_cnt <= retry_cnt + 1;
977 FTU_cnt <= FTU_cnt - 1; -- repeat this FTU
978 FTM_ftu_rs485_control_State <= RATES;
979 else
980 --retry_cnt <= 0;
981 FTU_cnt <= FTU_cnt; -- move on
982 ftu_error_calls <= (others => '0');
983 after_error_State <= DD_RAM;
984 FTM_ftu_rs485_control_State <= SEND_ERROR_1;
985 end if;
986 end if;
987 end if;
988
989 when DD_RAM => -- write rates of actual FTU to DD RAM
990 rec_reset_sig <= '0';
991 if (DD_RAM_reg_cnt < NO_OF_DD_RAM_REG) then
992 DD_RAM_reg_cnt <= DD_RAM_reg_cnt + 1;
993 FTU_cnt_offset_sig <= ((FTU_cnt - 1) * NO_OF_DD_RAM_REG);
994 crate_cnt_offset_sig <= (crate_cnt * NO_OF_FTUS_PER_CRATE * NO_OF_DD_RAM_REG);
995 FTM_ftu_rs485_control_State <= DD_RAM_1;
996 else
997 DD_RAM_reg_cnt <= 0;
998 retry_cnt <= 0;
999 FTM_ftu_rs485_control_State <= RATES;
1000 end if;
1001
1002 when DD_RAM_1 =>
1003 if (dynamic_RAM_busy = '0') then
1004 write_dynamic_RAM <= '1';
1005 addr_dynamic_RAM <= conv_std_logic_vector(DD_BLOCK_SIZE_GENERAL +
1006 crate_cnt_offset_sig +
1007 --(crate_cnt * NO_OF_FTUS_PER_CRATE * NO_OF_DD_RAM_REG) +
1008 --((FTU_cnt - 1) * NO_OF_DD_RAM_REG) +
1009 FTU_cnt_offset_sig +
1010 (DD_RAM_reg_cnt - 1), DYNAMIC_RAM_ADDR_WIDTH);
1011 if ( (retry_cnt < FTU_RS485_NO_OF_RETRY)
1012 and (FTU_cnt_offset_sig < (NO_OF_FTUS_PER_CRATE * NO_OF_DD_RAM_REG))
1013 and (crate_cnt_offset_sig < (NO_OF_CRATES * NO_OF_FTUS_PER_CRATE * NO_OF_DD_RAM_REG)) ) then
1014 if ((DD_RAM_reg_cnt - 1) = 0) then
1015 data_dynamic_RAM <= FTU_rate_array_sig(0)(31 downto 16);
1016 elsif ((DD_RAM_reg_cnt - 1) = 1) then
1017 data_dynamic_RAM <= FTU_rate_array_sig(0)(15 downto 0);
1018 elsif ((DD_RAM_reg_cnt - 1) = 2) then
1019 data_dynamic_RAM <= FTU_rate_array_sig(1)(31 downto 16);
1020 elsif ((DD_RAM_reg_cnt - 1) = 3) then
1021 data_dynamic_RAM <= FTU_rate_array_sig(1)(15 downto 0);
1022 elsif ((DD_RAM_reg_cnt - 1) = 4) then
1023 data_dynamic_RAM <= FTU_rate_array_sig(2)(31 downto 16);
1024 elsif ((DD_RAM_reg_cnt - 1) = 5) then
1025 data_dynamic_RAM <= FTU_rate_array_sig(2)(15 downto 0);
1026 elsif ((DD_RAM_reg_cnt - 1) = 6) then
1027 data_dynamic_RAM <= FTU_rate_array_sig(3)(31 downto 16);
1028 elsif ((DD_RAM_reg_cnt - 1) = 7) then
1029 data_dynamic_RAM <= FTU_rate_array_sig(3)(15 downto 0);
1030 elsif ((DD_RAM_reg_cnt - 1) = 8) then
1031 data_dynamic_RAM <= FTU_rate_array_sig(4)(31 downto 16);
1032 elsif ((DD_RAM_reg_cnt - 1) = 9) then
1033 data_dynamic_RAM <= FTU_rate_array_sig(4)(15 downto 0);
1034 elsif ((DD_RAM_reg_cnt - 1) = 10) then
1035 data_dynamic_RAM <= "00000000" & FTU_overflow_sig;
1036 elsif ((DD_RAM_reg_cnt - 1) = 11) then
1037 data_dynamic_RAM <= "00000000" & FTU_crc_error_cnt_sig;
1038-- elsif ((DD_RAM_reg_cnt - 1) = 10) then
1039-- data_dynamic_RAM <= "0000" & conv_std_logic_vector(DD_BLOCK_SIZE_GENERAL +
1040-- --((FTU_cnt - 1) * NO_OF_DD_RAM_REG) +
1041-- FTU_cnt_offset_sig +
1042-- (DD_RAM_reg_cnt - 1), DYNAMIC_RAM_ADDR_WIDTH);
1043-- elsif ((DD_RAM_reg_cnt - 1) = 11) then
1044-- --data_dynamic_RAM <= "0000" & conv_std_logic_vector(FTU_cnt_offset_sig, DYNAMIC_RAM_ADDR_WIDTH);
1045-- data_dynamic_RAM <= "0000" & conv_std_logic_vector(DD_BLOCK_SIZE_GENERAL +
1046-- --((FTU_cnt - 1) * NO_OF_DD_RAM_REG) +
1047-- FTU_cnt_offset_sig +
1048-- (DD_RAM_reg_cnt - 1), DYNAMIC_RAM_ADDR_WIDTH);
1049 end if;
1050 else
1051 data_dynamic_RAM <= (others => '0');
1052 end if;
1053 FTM_ftu_rs485_control_State <= DD_RAM_2;
1054 end if;
1055
1056 when DD_RAM_2 =>
1057 if (dynamic_RAM_started = '1') then
1058 write_dynamic_RAM <= '0';
1059 FTM_ftu_rs485_control_State <= DD_RAM_3;
1060 end if;
1061
1062 when DD_RAM_3 =>
1063 if (dynamic_RAM_ready = '1') then
1064 FTM_ftu_rs485_control_State <= DD_RAM;
1065 end if;
1066
1067 end case;
1068 end if;
1069 end process FTM_ftu_rs485_control_FSM;
1070
1071 -- Process to multiplex the different crate buses
1072 sel_crate_process: process (sel_crate_sig,
1073 rx_en_0_sig, rx_en_1_sig, rx_en_2_sig, rx_en_3_sig,
1074 tx_en_0_sig, tx_en_1_sig, tx_en_2_sig, tx_en_3_sig,
1075 rx_valid_0_sig, rx_valid_1_sig, rx_valid_2_sig, rx_valid_3_sig,
1076 rx_data_0_sig, rx_data_1_sig, rx_data_2_sig, rx_data_3_sig,
1077 tx_busy_0_sig, tx_busy_1_sig, tx_busy_2_sig, tx_busy_3_sig,
1078 rx_busy_0_sig, rx_busy_1_sig, rx_busy_2_sig, rx_busy_3_sig,
1079 tx_start_sig, tx_data_sig)
1080 begin
1081 case sel_crate_sig is
1082 when "000" => -- crate 0
1083 rx_en_sig <= rx_en_0_sig;
1084 tx_en_sig <= tx_en_0_sig;
1085 rx_valid_sig <= rx_valid_0_sig;
1086 rec_data_sig <= rx_data_0_sig;
1087 tx_busy_sig <= tx_busy_0_sig;
1088 rx_busy_sig <= rx_busy_0_sig;
1089 tx_start_0_sig <= tx_start_sig;
1090 tx_start_1_sig <= '0';
1091 tx_start_2_sig <= '0';
1092 tx_start_3_sig <= '0';
1093 tx_data_0_sig <= tx_data_sig;
1094 tx_data_1_sig <= (others => '0');
1095 tx_data_2_sig <= (others => '0');
1096 tx_data_3_sig <= (others => '0');
1097 when "001" => -- crate 1
1098 rx_en_sig <= rx_en_1_sig;
1099 tx_en_sig <= tx_en_1_sig;
1100 rx_valid_sig <= rx_valid_1_sig;
1101 rec_data_sig <= rx_data_1_sig;
1102 tx_busy_sig <= tx_busy_1_sig;
1103 rx_busy_sig <= rx_busy_1_sig;
1104 tx_start_0_sig <= '0';
1105 tx_start_1_sig <= tx_start_sig;
1106 tx_start_2_sig <= '0';
1107 tx_start_3_sig <= '0';
1108 tx_data_0_sig <= (others => '0');
1109 tx_data_1_sig <= tx_data_sig;
1110 tx_data_2_sig <= (others => '0');
1111 tx_data_3_sig <= (others => '0');
1112 when "010" => -- crate 2
1113 rx_en_sig <= rx_en_2_sig;
1114 tx_en_sig <= tx_en_2_sig;
1115 rx_valid_sig <= rx_valid_2_sig;
1116 rec_data_sig <= rx_data_2_sig;
1117 tx_busy_sig <= tx_busy_2_sig;
1118 rx_busy_sig <= rx_busy_2_sig;
1119 tx_start_0_sig <= '0';
1120 tx_start_1_sig <= '0';
1121 tx_start_2_sig <= tx_start_sig;
1122 tx_start_3_sig <= '0';
1123 tx_data_0_sig <= (others => '0');
1124 tx_data_1_sig <= (others => '0');
1125 tx_data_2_sig <= tx_data_sig;
1126 tx_data_3_sig <= (others => '0');
1127 when "011" => -- crate 3
1128 rx_en_sig <= rx_en_3_sig;
1129 tx_en_sig <= tx_en_3_sig;
1130 rx_valid_sig <= rx_valid_3_sig;
1131 rec_data_sig <= rx_data_3_sig;
1132 tx_busy_sig <= tx_busy_3_sig;
1133 rx_busy_sig <= rx_busy_3_sig;
1134 tx_start_0_sig <= '0';
1135 tx_start_1_sig <= '0';
1136 tx_start_2_sig <= '0';
1137 tx_start_3_sig <= tx_start_sig;
1138 tx_data_0_sig <= (others => '0');
1139 tx_data_1_sig <= (others => '0');
1140 tx_data_2_sig <= (others => '0');
1141 tx_data_3_sig <= tx_data_sig;
1142 when others => -- no crate specified
1143 rx_en_sig <= '0';
1144 tx_en_sig <= '0';
1145 rx_valid_sig <= '0';
1146 rec_data_sig <= (others => '0');
1147 tx_busy_sig <= '0';
1148 rx_busy_sig <= '0';
1149 tx_start_0_sig <= '0';
1150 tx_start_1_sig <= '0';
1151 tx_start_2_sig <= '0';
1152 tx_start_3_sig <= '0';
1153 tx_data_0_sig <= (others => '0');
1154 tx_data_1_sig <= (others => '0');
1155 tx_data_2_sig <= (others => '0');
1156 tx_data_3_sig <= (others => '0');
1157 end case;
1158 end process;
1159
1160 -- Process to select the CRC input source (FSM or interpreter)
1161 sel_crc_cource_process : process (sel_crc_input_source_sig,
1162 reset_crc_from_interpreter_sig, reset_crc_from_FSM_sig,
1163 enable_crc_from_interpreter_sig, enable_crc_from_FSM_sig,
1164 rec_block_sig((FTU_RS485_BLOCK_WIDTH - 9) downto 0), crc_data_from_FSM_sig)
1165 begin
1166 case sel_crc_input_source_sig is
1167 when '0' => -- FSM
1168 reset_crc_sig <= reset_crc_from_FSM_sig;
1169 enable_crc_sig <= enable_crc_from_FSM_sig;
1170 crc_data_sig <= crc_data_from_FSM_sig;
1171 when '1' => -- interpreter
1172 reset_crc_sig <= reset_crc_from_interpreter_sig;
1173 enable_crc_sig <= enable_crc_from_interpreter_sig;
1174 crc_data_sig <= rec_block_sig((FTU_RS485_BLOCK_WIDTH - 9) downto 0);
1175 when others => -- signal undefined
1176 reset_crc_sig <= reset_crc_from_FSM_sig;
1177 enable_crc_sig <= enable_crc_from_FSM_sig;
1178 crc_data_sig <= crc_data_from_FSM_sig;
1179 end case;
1180 end process;
1181
1182 rx_en <= rx_en_sig;
1183 tx_en <= tx_en_sig;
1184
1185 crc_sig <= crc_sig_inv(0) & crc_sig_inv(1) & crc_sig_inv(2) & crc_sig_inv(3) & crc_sig_inv(4) & crc_sig_inv(5) & crc_sig_inv(6) & crc_sig_inv(7);
1186 start_int_sig <= rec_valid_sig and (not rx_busy_sig); -- avoid continuing to early after FTU answer
1187
1188end Behavioral;
1189
Note: See TracBrowser for help on using the repository browser.