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/daq_header.vhd,v $
00015 --* $Revision: 1.7.2.6 $ *
00016 --* $Name: dev $ *
00017 --* $Author: mniegl $ *
00018 --* $Date: 2008/11/03 17:57:47 $ *
00019
00020
00021 --* *
00022 --**************************************************************
00023 --****************************************************************************
00024 --
00025 --* BCM DAQ Header
00026 --
00027 --****************************************************************************
00028
00029
00030
00031 library ieee;
00032
00033 use ieee.std_logic_1164.all;
00034
00035
00036 package daq_header is
00037
00038 ----------------------------- types ------------------------------------------
00039 type sixteentwo is array (16 downto 1) of (1 downto 0);
00040 type twofour is array (8 downto 1) of (2 downto 0);
00041 type fivetwo is array (2 downto 1) of (4 downto 0);
00042 type sixteen is array (8 downto 1) of (1 downto 0);
00043 type eight is array (4 downto 1) of (1 downto 0);
00044 type four is array (2 downto 1) of (1 downto 0);
00045 type threesix is array (2 downto 0) of (5 downto 0);
00046
00047 ----------------------------- constants --------------------------------------
00048 --constant ADJ_TIME_1 : integer := 0;
00049 --constant ADJ_TIME_2 : integer := 16;
00050
00051 ----------------------------- functions --------------------------------------
00052 function reverse_any_vector(a : ) return ;
00053 function dec13 (D : (2 downto 0)) return ;
00054 function dec23 (DAT : (2 downto 0)) return ;
00055 function ris_pattern (A : (3 downto 0)) return ;
00056 function fal_pattern (A : (3 downto 0)) return ;
00057 function ris_hole_pattern (A : (3 downto 0)) return ;
00058 function fal_hole_pattern (A : (3 downto 0)) return ;
00059 function spike_suppress (A : (2 downto 0)) return ;
00060 function or_check (B : (31 downto 0)) return ;
00061 function or_check_long (B : (31 downto 0)) return ;
00062 function lowest_zero (b : (2 downto 0)) return ;
00063 function cnt_ones (vec_in : (31 downto 0)) return ;
00064 --function XROL (ARG: STD_LOGIC_VECTOR; COUNT: NATURAL) return STD_LOGIC_VECTOR;
00065
00066 end daq_header;
00067
00068
00069 package body daq_header is
00070
00071 ----------------------------- functions --------------------------------------
00072
00073 function reverse_any_vector (a : in )
00074 return is
00075 variable result : (a'range);
00076 alias aa : (a'reverse_range) is a;
00077 begin
00078 for i in aa'range loop
00079 result(i) := aa(i);
00080 end loop;
00081 return result;
00082 end reverse_any_vector;
00083
00084
00085 function cnt_ones (vec_in : (31 downto 0))
00086 return is
00087 variable cnt : range 0 to vec_in'length := 0;
00088 begin
00089 for i in 0 to (vec_in'length)-1 loop
00090 if vec_in(i) = '1' then
00091 cnt := cnt + 1;
00092 end if;
00093 end loop; -- i
00094 return cnt;
00095 end cnt_ones;
00096
00097
00098 function dec13 (D : (2 downto 0))
00099 return is
00100 variable R : := '0';
00101 variable a, b, c, e, f, g : := '0';
00102 begin
00103 a := D(2);
00104 b := D(1);
00105 c := D(0);
00106 g := not(a);
00107 e := not(b);
00108 f := not(c);
00109 if ((a and e and f) or (g and b and f) or (g and e and c)) = '1' then
00110 R := '1';
00111 else
00112 R := '0';
00113 end if;
00114 return R;
00115 end dec13;
00116
00117
00118 function dec23 (DAT : (2 downto 0))
00119 return is
00120 variable X : := '0';
00121 variable a, b, c, e, f, g : := '0';
00122 begin
00123 a := DAT(2);
00124 b := DAT(1);
00125 c := DAT(0);
00126 g := not(a);
00127 e := not(b);
00128 f := not(c);
00129 X := (a and b and f) or (a and e and c) or (g and b and c);
00130 return X;
00131 end dec23;
00132
00133
00134 function ris_pattern (A : (3 downto 0))
00135 return is
00136 begin
00137 return ((not A(3)) and (not A(2)) and A(1) and A(0));
00138 end ris_pattern;
00139
00140
00141 function ris_hole_pattern (A : (3 downto 0))
00142 return is
00143 begin
00144 return (A(3) and A(2) and (not A(1)) and A(0));
00145 end ris_hole_pattern;
00146
00147
00148 function fal_pattern (A : (3 downto 0))
00149 return is
00150 begin
00151 return ((not A(0)) and (not A(1)) and A(2) and A(3));
00152 end fal_pattern;
00153
00154
00155 function fal_hole_pattern (A : (3 downto 0))
00156 return is
00157 begin
00158 return (A(3) and (not A(2)) and A(1) and A(0));
00159 end fal_hole_pattern;
00160
00161
00162 function spike_suppress (A : (2 downto 0))
00163 return is
00164 begin
00165 return not ((not A(2)) and A(1) and (not A(0)));
00166 end spike_suppress;
00167
00168
00169 function or_check_long (B : (31 downto 0))
00170 return is
00171 variable R : := '0';
00172 begin
00173 R := B(31) or B(30) or B(29) or B(28) or B(27) or B(26) or B(25) or B(24) or B(23) or B(22) or B(21) or B(20)
00174 or B(19) or B(18) or B(17) or B(16) or B(15) or B(14) or B(13) or B(12) or B(11) or B(10) or B(9) or B(8)
00175 or B(7) or B(6) or B(5) or B(4) or B(3) or B(2) or B(1) or B(0);
00176 return R;
00177 end or_check_long;
00178
00179
00180 function or_check (B : (31 downto 0))
00181 return is
00182 variable R : := '0';
00183 begin
00184 R := B(31) or B(30) or B(29) or B(28) or B(27) or B(26) or B(25) or B(24);
00185 return R;
00186 end or_check;
00187
00188
00189
00190 function lowest_zero (b : (2 downto 0))
00191 return is
00192 variable R : range 0 to 3 := 0;
00193 begin
00194 if b(0) = '0' then
00195 R := 0;
00196 elsif b(1) = '0' then
00197 R := 1;
00198 elsif b(2) = '0' then
00199 R := 2;
00200 else
00201 R := 3;
00202 end if;
00203 return R;
00204 end lowest_zero;
00205
00206 -- cyclic shift left for std_logic_vector
00207 --function XROL (ARG: STD_LOGIC_VECTOR; COUNT: NATURAL) return STD_LOGIC_VECTOR
00208 -- is
00209 -- constant ARG_L: INTEGER := 31;--ARG'LENGTH-1;
00210 -- alias XARG: STD_LOGIC_VECTOR(ARG_L downto 0) is ARG;
00211 -- variable RESULT: STD_LOGIC_VECTOR(ARG_L downto 0) := XARG;
00212 -- variable COUNTM: INTEGER;
00213 -- begin
00214 -- COUNTM := COUNT mod (ARG_L + 1);
00215 -- if COUNTM /= 0 then
00216 -- RESULT(ARG_L downto COUNTM) := XARG(ARG_L-COUNTM downto 0);
00217 -- RESULT(COUNTM-1 downto 0) := XARG(ARG_L downto ARG_L-COUNTM+1);
00218 -- end if;
00219 -- return RESULT;
00220 -- end XROL;
00221
00222 end daq_header;