source: firmware/FTM/FTM_central_control.vhd@ 10267

Last change on this file since 10267 was 10256, checked in by weitzel, 14 years ago
new version of FTM ethernet module; first version of clock conditioner
File size: 7.7 KB
Line 
1----------------------------------------------------------------------------------
2-- Company: ETH Zurich, Institute for Particle Physics
3-- Engineer: Q. Weitzel
4--
5-- Create Date: 15:56:13 02/28/2011
6-- Design Name:
7-- Module Name: FTM_central_control - Behavioral
8-- Project Name:
9-- Target Devices:
10-- Tool versions:
11-- Description: Central FSM for FTM firmware
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_central_control is
35 port(
36 clk : IN std_logic;
37 clk_scaler : IN std_logic;
38 new_config : IN std_logic;
39 config_started : OUT std_logic := '0';
40 config_started_ack : IN std_logic;
41 config_start_eth : OUT std_logic := '0';
42 config_started_eth : IN std_logic;
43 config_ready_eth : IN std_logic;
44 config_start_ftu : OUT std_logic := '0';
45 config_started_ftu : IN std_logic ;
46 config_ready_ftu : IN std_logic ;
47 ping_ftu_start : IN std_logic;
48 ping_ftu_started : OUT std_logic := '0';
49 ping_ftu_ready : OUT std_logic := '0';
50 ping_ftu_start_ftu : OUT std_logic := '0';
51 ping_ftu_started_ftu : IN std_logic;
52 ping_ftu_ready_ftu : IN std_logic;
53 rates_ftu : OUT std_logic := '0';
54 rates_started_ftu : IN std_logic;
55 rates_ready_ftu : IN std_logic;
56 prescaling_FTU01 : IN std_logic_vector(7 downto 0);
57 dd_send : OUT std_logic := '0';
58 dd_send_ack : IN std_logic;
59 dd_send_ready : IN std_logic;
60 config_start_cc : out std_logic := '0';
61 config_started_cc : in std_logic;
62 config_ready_cc : in std_logic
63 );
64end FTM_central_control;
65
66architecture Behavioral of FTM_central_control is
67
68 signal reset_scaler_sig : std_logic := '0';
69 signal scaler_counts_sig : integer := 0;
70 signal scaler_period_sig : integer range 0 to 128 * (LOW_FREQUENCY / SCALER_FREQ_DIVIDER) := 128 * (LOW_FREQUENCY / SCALER_FREQ_DIVIDER);
71
72 type state_central_proc_type is (CP_INIT,
73 CP_CONFIG_START, CP_CONFIG, CP_CONFIG_01,
74 CP_CONFIG_CC, CP_CONFIG_CC_01,
75 CP_CONFIG_FTU, CP_CONFIG_FTU_01, CP_CONFIG_SCALER,
76 CP_IDLE, CP_PING, CP_READ_RATES, CP_READ_RATES_01,
77 CP_SEND_START, CP_SEND_END);
78 signal state_central_proc : state_central_proc_type := CP_INIT;
79
80begin
81
82 central_proc : process (clk, prescaling_FTU01)
83 begin
84 if rising_edge (clk) then
85 case state_central_proc is
86
87 when CP_INIT =>
88 state_central_proc <= CP_CONFIG;
89
90 when CP_CONFIG_START =>
91 reset_scaler_sig <= '1';
92 if (config_started_ack = '1') then
93 config_started <= '0';
94 state_central_proc <= CP_CONFIG;
95 end if;
96
97 when CP_CONFIG =>
98 reset_scaler_sig <= '1';
99 config_start_eth <= '1';
100 if (config_started_eth = '1') then
101 config_start_eth <= '0';
102 state_central_proc <= CP_CONFIG_01;
103 end if;
104
105 when CP_CONFIG_01 =>
106 if (config_ready_eth = '1') then
107 state_central_proc <= CP_CONFIG_CC;
108 --state_central_proc <= CP_CONFIG_SCALER;
109 --state_central_proc <= CP_IDLE;
110 end if;
111
112 when CP_CONFIG_CC =>
113 config_start_cc <= '1';
114 if (config_started_cc = '1') then
115 config_start_cc <= '0';
116 state_central_proc <= CP_CONFIG_CC_01;
117 end if;
118
119 when CP_CONFIG_CC_01 =>
120 if (config_ready_cc = '1') then
121 state_central_proc <= CP_CONFIG_FTU;
122 end if;
123
124 when CP_CONFIG_FTU =>
125 config_start_ftu <= '1';
126 if (config_started_ftu = '1') then
127 config_start_ftu <= '0';
128 state_central_proc <= CP_CONFIG_FTU_01;
129 end if;
130
131 when CP_CONFIG_FTU_01 =>
132 if (config_ready_ftu = '1') then
133 state_central_proc <= CP_CONFIG_SCALER;
134 end if;
135
136 when CP_CONFIG_SCALER =>
137 --if ((conv_integer(unsigned(prescaling_FTU01))) mod 2 = 0) then
138 --scaler_period_sig <= ((((conv_integer(unsigned(prescaling_FTU01)) / 2)) * (LOW_FREQUENCY / SCALER_FREQ_DIVIDER)) + (LOW_FREQUENCY / (2 * SCALER_FREQ_DIVIDER)));
139 --else
140 --scaler_period_sig <= (((conv_integer(unsigned(prescaling_FTU01)) - 1) / 2) + 1) * (LOW_FREQUENCY / SCALER_FREQ_DIVIDER);
141 --end if;
142 reset_scaler_sig <= '1';
143 state_central_proc <= CP_IDLE;
144
145 when CP_IDLE =>
146 reset_scaler_sig <= '0';
147 if (new_config = '1') then
148 config_started <= '1';
149 state_central_proc <= CP_CONFIG_START;
150 elsif (ping_ftu_start = '1') then
151 --else
152 ping_ftu_start_ftu <= '1';
153 if (ping_ftu_started_ftu = '1') then
154 ping_ftu_start_ftu <= '0';
155 ping_ftu_started <= '1';
156 ping_ftu_ready <= '0';
157 state_central_proc <= CP_PING;
158 end if;
159 --elsif (scaler_counts_sig = scaler_period_sig) then
160 -- reset_scaler_sig <= '1';
161 -- rates_ftu <= '1';
162 -- state_central_proc <= CP_READ_RATES;
163 end if;
164
165 when CP_PING =>
166 if (ping_ftu_ready_ftu = '1') then
167 if (ping_ftu_start = '0') then
168 ping_ftu_started <= '0';
169 ping_ftu_ready <= '1';
170 state_central_proc <= CP_IDLE;
171 end if;
172 end if;
173
174 when CP_READ_RATES =>
175 reset_scaler_sig <= '0';
176 if (rates_started_ftu = '1') then
177 rates_ftu <= '0';
178 state_central_proc <= CP_READ_RATES_01;
179 end if;
180
181 when CP_READ_RATES_01 =>
182 if (rates_ready_ftu = '1') then
183 state_central_proc <= CP_SEND_START;
184 end if;
185
186 when CP_SEND_START =>
187 dd_send <= '1';
188 if (dd_send_ack = '1') then
189 dd_send <= '0';
190 state_central_proc <= CP_SEND_END;
191 end if;
192
193 when CP_SEND_END =>
194 if (dd_send_ready = '1') then
195 state_central_proc <= CP_IDLE;
196 end if;
197
198 end case;
199 end if;
200 end process central_proc;
201
202 scaler_process: process(reset_scaler_sig, clk_scaler)
203 begin
204 if reset_scaler_sig = '1' then
205 scaler_counts_sig <= 0;
206 elsif rising_edge(clk_scaler) then
207 if (scaler_counts_sig < scaler_period_sig) then
208 scaler_counts_sig <= scaler_counts_sig + 1;
209 else
210 scaler_counts_sig <= scaler_counts_sig;
211 end if;
212 end if;
213 end process scaler_process;
214
215 process(reset_scaler_sig, prescaling_FTU01)
216 begin
217 if rising_edge(reset_scaler_sig) then
218 if ((conv_integer(unsigned(prescaling_FTU01))) mod 2 = 0) then
219 scaler_period_sig <= ((((conv_integer(unsigned(prescaling_FTU01)) / 2)) * (LOW_FREQUENCY / SCALER_FREQ_DIVIDER)) + (LOW_FREQUENCY / (2 * SCALER_FREQ_DIVIDER)));
220 else
221 scaler_period_sig <= (((conv_integer(unsigned(prescaling_FTU01)) - 1) / 2) + 1) * (LOW_FREQUENCY / SCALER_FREQ_DIVIDER);
222 end if;
223 end if;
224 end process;
225
226end Behavioral;
Note: See TracBrowser for help on using the repository browser.