00001 --**************************************************************
00002 --* *
00003 --* The source code for the ATLAS BCM "AAA" FPGA is made *
00004 --* available via the GNU General Public License (GPL) *
00005 --* unless otherwise stated below. *
00006 --* *
00007 --* In case of problems/questions/bug reports etc. please *
00008 --* contact michael.niegl@cern.ch *
00009 --* *
00010 --**************************************************************
00011
00012 --**************************************************************
00013 --* *
00014 --* $Source: /local/reps/bcmfpga/bcm_aaa/bcm_aaa/rio/bunchcycle.vhd,v $
00015 --* $Revision: 1.6.2.7 $ *
00016 --* $Name: dev $ *
00017 --* $Author: mniegl $ *
00018 --* $Date: 2008/11/03 17:57:47 $ *
00019
00020
00021 --* *
00022 --**************************************************************
00023
00024 library ieee;
00025
00026 use ieee.std_logic_1164.all;
00027
00028 use ieee.std_logic_unsigned.all;
00029 library work;
00030 use work.daq_header.all;
00031
00032 library unisim;
00033
00034 use unisim.vcomponents.all;
00035
00036
00037 entity bunchcycle is
00038 port (
00039 CLK2X : in ;
00040 CLK : in ;
00041 RESET : in ;
00042 EN : in ;
00043 R1 : in (4 downto 0);
00044 R2 : in (4 downto 0);
00045 R3 : in (4 downto 0);
00046 F1 : in (4 downto 0);
00047 F2 : in (4 downto 0);
00048 F3 : in (4 downto 0);
00049 SR1 : in ;
00050 SR2 : in ;
00051 SR3 : in ;
00052 SF1 : in ;
00053 SF2 : in ;
00054 SF3 : in ;
00055 EDGE_RIS1 : out (5 downto 0);
00056 EDGE_RIS2 : out (5 downto 0);
00057 EDGE_RIS3 : out (5 downto 0);
00058 EDGE_FAL1 : out (5 downto 0);
00059 EDGE_FAL2 : out (5 downto 0);
00060 EDGE_FAL3 : out (5 downto 0);
00061 STATUS_ER1 : out ;
00062 STATUS_ER2 : out ;
00063 STATUS_ER3 : out ;
00064 STATUS_EF1 : out ;
00065 STATUS_EF2 : out ;
00066 STATUS_EF3 : out ;
00067 SUM_R_IN : in (5 downto 0);
00068 SUM_F_IN : in (5 downto 0);
00069 SUM_R_OUT : out (7 downto 0);
00070 SUM_F_OUT : out (7 downto 0)
00071 );
00072 end bunchcycle;
00073
00074
00075
00076
00077 architecture bunchcycle_arc of bunchcycle is
00078
00079 --*************************** Signal Declarations *****************************
00080 signal in_ris1 : (4 downto 0) := (others => '0');
00081 signal in_ris2 : (4 downto 0) := (others => '0');
00082 signal in_fal1 : (4 downto 0) := (others => '0');
00083 signal in_fal2 : (4 downto 0) := (others => '0');
00084 signal freg_r11 : (5 downto 0) := (others => '0');
00085 signal freg_r21 : (5 downto 0) := (others => '0');
00086 signal freg_f11 : (5 downto 0) := (others => '0');
00087 signal freg_f21 : (5 downto 0) := (others => '0');
00088 signal freg_r12 : (5 downto 0) := (others => '0');
00089 signal freg_r22 : (5 downto 0) := (others => '0');
00090 signal freg_f12 : (5 downto 0) := (others => '0');
00091 signal freg_f22 : (5 downto 0) := (others => '0');
00092 signal reg_r1 : (5 downto 0) := (others => '0');
00093 signal reg_r2 : (5 downto 0) := (others => '0');
00094 signal reg_f1 : (5 downto 0) := (others => '0');
00095 signal reg_f2 : (5 downto 0) := (others => '0');
00096 signal rsr11 : := '0';
00097 signal rsr21 : := '0';
00098 signal rsf11 : := '0';
00099 signal rsf21 : := '0';
00100 signal rsr12 : := '0';
00101 signal rsr22 : := '0';
00102 signal rsf12 : := '0';
00103 signal rsf22 : := '0';
00104 signal fal2 : := '0';
00105 signal ris2 : := '0';
00106 signal tog : := '0';
00107 signal low : := '0';
00108
00109 begin
00110
00111 EDGE_RIS3 <= (others => '0');
00112 EDGE_FAL3 <= (others => '0');
00113 STATUS_EF3 <= '0';
00114 STATUS_ER3 <= '0';
00115
00116 in_ris1 <= R1 when SR1 = '1' else (others => '0');
00117 in_ris2 <= R2 when SR2 = '1' else (others => '0');
00118 in_fal1 <= F1 when SF1 = '1' else (others => '0');
00119 in_fal2 <= F2 when SF2 = '1' else (others => '0');
00120
00121 freg_r21(5) <= '1' when (freg_r21(4 downto 0) = "11111") and rsr11 = '0' else '0';
00122 freg_r11(5) <= '0' when (freg_r11(4 downto 0) = "11111") and rsr21 = '0' else rsr11;
00123 freg_f21(5) <= '0';
00124 freg_f11(5) <= rsf11;
00125 freg_r22(5) <= '0';
00126 freg_r12(5) <= rsr12;
00127 freg_f22(5) <= '0';
00128 freg_f12(5) <= rsf12;
00129
00130
00131 read_out : process (CLK, RESET)
00132 begin -- process read
00133 if RESET = '1' then -- asynchronous reset (active high)
00134 STATUS_EF1 <= '0';
00135 STATUS_ER1 <= '0';
00136 STATUS_EF2 <= '0';
00137 STATUS_ER2 <= '0';
00138 EDGE_RIS1 <= (others => '0');
00139 EDGE_FAL1 <= (others => '0');
00140 EDGE_RIS2 <= (others => '0');
00141 EDGE_FAL2 <= (others => '0');
00142 elsif CLK'event and CLK = '1' then -- rising clock edge
00143 if (reg_f1 > reg_f2) and (fal2 = '1') then
00144 EDGE_FAL2 <= reg_f1;
00145 EDGE_FAL1 <= reg_f2;
00146 else
00147 EDGE_FAL2 <= reg_f2;
00148 EDGE_FAL1 <= reg_f1;
00149 end if;
00150 if (reg_r1 > reg_r2) and (ris2 = '1') then
00151 EDGE_RIS1 <= reg_r2;
00152 EDGE_RIS2 <= reg_r1;
00153 else
00154 EDGE_RIS1 <= reg_r1;
00155 EDGE_RIS2 <= reg_r2;
00156 end if;
00157 STATUS_EF1 <= rsf11 or rsf21;
00158 STATUS_ER1 <= rsr11 or rsr21;
00159 STATUS_EF2 <= fal2;
00160 STATUS_ER2 <= ris2;
00161 end if;
00162 end process read_out;
00163
00164 fal2 <= (rsf11 and (rsf12 or rsf21)) or (rsf21 and rsf22);
00165 ris2 <= (rsr11 and (rsr12 or rsr21)) or (rsr21 and rsr22);
00166
00167
00168 sums : process (CLK2X, RESET)
00169 begin -- process sums
00170 if RESET = '1' then -- asynchronous reset (active high)
00171 SUM_R_OUT <= (others => '0');
00172 SUM_F_OUT <= (others => '0');
00173 elsif CLK2X'event and CLK2X = '1' then -- rising clock edge
00174 SUM_R_OUT <= ("0000000" & SR1) + ("0000000" & SR2);
00175 SUM_F_OUT <= ("0000000" & SF1) + ("0000000" & SF2);
00176 end if;
00177 end process sums;
00178
00179 reg_r1 <= freg_r11 when rsr11 = '1' else
00180 freg_r12 when rsr12 = '1' else
00181 freg_r21 when rsr21 = '1' else
00182 freg_r22;
00183 reg_r2 <= freg_r12 when (rsr12 and rsr11) = '1' else
00184 freg_r21 when (rsr21 and (rsr11 or rsr12)) = '1' else
00185 freg_r22;
00186 reg_f1 <= freg_f11 when rsf11 = '1' else
00187 freg_f12 when rsf12 = '1' else
00188 freg_f21 when rsf21 = '1' else
00189 freg_f22;
00190 reg_f2 <= freg_f12 when (rsf12 and rsf11) = '1' else
00191 freg_f21 when (rsf21 and (rsf11 or rsf12)) = '1' else
00192 freg_f22;
00193
00194
00195 fill : process (CLK2X, RESET)
00196 begin -- process fill
00197 if RESET = '1' then -- asynchronous reset (active high)
00198 freg_r11(4 downto 0) <= (others => '0');
00199 freg_r21(4 downto 0) <= (others => '0');
00200 freg_f11(4 downto 0) <= (others => '0');
00201 freg_f21(4 downto 0) <= (others => '0');
00202 freg_r12(4 downto 0) <= (others => '0');
00203 freg_r22(4 downto 0) <= (others => '0');
00204 freg_f12(4 downto 0) <= (others => '0');
00205 freg_f22(4 downto 0) <= (others => '0');
00206 rsr12 <= '0';
00207 rsr22 <= '0';
00208 rsf12 <= '0';
00209 rsf22 <= '0';
00210 rsr11 <= '0';
00211 rsr21 <= '0';
00212 rsf11 <= '0';
00213 rsf21 <= '0';
00214 tog <= '0';
00215 elsif CLK2X'event and CLK2X = '1' then -- rising clock edge
00216 if EN = '1' then
00217
00218 tog <= not tog;
00219 -- first half
00220 if tog = '1' then
00221
00222 if (in_fal1 = 0) and (SR1 = '1') then
00223 freg_f11(4 downto 0) <= (others => '1');
00224 rsf11 <= SF1;
00225 freg_f12(4 downto 0) <= in_fal1;
00226 rsf12 <= SF1;
00227 freg_r11(4 downto 0) <= in_ris1;
00228 rsr11 <= SR1;
00229 freg_r12(4 downto 0) <= in_ris2;
00230 rsr12 <= SR2;
00231 elsif (in_fal2 = 0) and (SR2 = '1') then
00232 freg_f11(4 downto 0) <= in_fal1;
00233 rsf11 <= SF1;
00234 freg_f12(4 downto 0) <= (others => '1');
00235 rsf12 <= SF2;
00236 freg_r11(4 downto 0) <= in_ris1;
00237 rsr11 <= SR1;
00238 freg_r12(4 downto 0) <= in_ris2;
00239 rsr12 <= SR2;
00240 else
00241 freg_f11(4 downto 0) <= in_fal1;
00242 rsf11 <= SF1;
00243 freg_f12(4 downto 0) <= in_fal2;
00244 rsf12 <= SF2;
00245 freg_r11(4 downto 0) <= in_ris1;
00246 rsr11 <= SR1;
00247 freg_r12(4 downto 0) <= in_ris2;
00248 rsr12 <= SR2;
00249 end if;
00250
00251 -- second half
00252 else
00253
00254 if (in_fal1 = 0) and (SR1 = '1') then
00255 freg_f21(4 downto 0) <= (others => '1');
00256 rsf21 <= SF1;
00257 freg_f22(4 downto 0) <= in_fal1;
00258 rsf22 <= SF1;
00259 freg_r21(4 downto 0) <= in_ris1;
00260 rsr21 <= SR1;
00261 freg_r22(4 downto 0) <= in_ris2;
00262 rsr22 <= SR2;
00263 elsif (in_fal2 = 0) and (SR2 = '1') then
00264 freg_f21(4 downto 0) <= in_fal1;
00265 rsf21 <= SF1;
00266 freg_f22(4 downto 0) <= (others => '1');
00267 rsf22 <= SF2;
00268 freg_r21(4 downto 0) <= in_ris1;
00269 rsr21 <= SR1;
00270 freg_r22(4 downto 0) <= in_ris2;
00271 rsr22 <= SR2;
00272 else
00273 freg_f21(4 downto 0) <= in_fal1;
00274 rsf21 <= SF1;
00275 freg_f22(4 downto 0) <= in_fal2;
00276 rsf22 <= SF2;
00277 freg_r21(4 downto 0) <= in_ris1;
00278 rsr21 <= SR1;
00279 freg_r22(4 downto 0) <= in_ris2;
00280 rsr22 <= SR2;
00281 end if;
00282
00283 end if;
00284
00285 else
00286 tog <= '0';
00287 end if;
00288 end if;
00289 end process fill;
00290
00291 end bunchcycle_arc;
00292