eFEX firmware  1.7.3
ATLAS l1-calo - electron and tau feature extraction firmware for eFEX boards

Back to eFEX documentation
ParallelSorter.vhd
Go to the documentation of this file.
1 
6 
7 library ieee;
8 use ieee.std_logic_1164.all;
9 use ieee.numeric_std.all;
10 
11 use work.DataTypes.all;
12 use work.AlgoDataTypes.all;
13 
14 -------------------------------------------------------------------------------
15 
17 entity ParallelSorter is
18  generic (
19  USE_EXTERNAL_WRITE : boolean := false;
20  N_TOBS_IN : integer := 5;
21  N_TOBS_OUT : integer := 10
22  );
23 
24  port (
25  clk : in std_logic;
26  IN_Start : in std_logic_vector(1 downto 0);
27  IN_Write : in std_logic_vector(1 downto 0);
28  IN_Data : in AlgoTriggerObjects(1 downto 0);
29 
30  OUT_Start : out std_logic;
31  OUT_Write : out std_logic;
32  OUT_Data : out AlgoTriggerObject
33  );
34 
35 end entity ParallelSorter;
36 
37 -------------------------------------------------------------------------------
38 
40 architecture str of ParallelSorter is
41  -----------------------------------------------------------------------------
42  -- Internal signal declarations
43  -----------------------------------------------------------------------------
44  constant N_TOBS : integer := N_TOBS_OUT - N_TOBS_IN;
45 
46  signal FifoReset : std_logic;
47  signal OutWrite, OutStart : std_logic;
48  signal Done : std_logic;
49  signal WriteInt, Write0, Write1 : std_logic;
50  signal Ack : std_logic_vector(1 downto 0);
51  signal Acknowledge : std_logic := '0';
52  signal Data : AlgoTriggerObjects(1 downto 0);
53  signal OneOrTwo : integer range 0 to 1 := 0;
54  signal TOB_Count : integer range 0 to N_TOBS_OUT-1 := 0;
55  signal Start : std_logic;
56 
57 begin -- architecture str
58 
59  -----------------------------------------------------------------------------
60  -- Component instantiations
61  -----------------------------------------------------------------------------
62  Start <= IN_Start(0) or IN_Start(1);
63  Write0 <= IN_Write(0) when USE_EXTERNAL_WRITE else (WriteInt or Start);
64  Write1 <= IN_Write(1) when USE_EXTERNAL_WRITE else (WriteInt or Start);
65 
66  FastFifo_1 : entity work.FastFifo
67  generic map (
68  FASTFIFO_DATA_DEPTH => N_TOBS_OUT)
69  port map (
70  clk => clk,
71  IN_Reset => FifoReset,
72  IN_Data => IN_Data(0),
73  IN_Write => Write0,
74  IN_Ack => Ack(0) and (not Done),
75  OUT_Empty => open,
76  OUT_Data => Data(0));
77 
78  FastFifo_2 : entity work.FastFifo
79  generic map (
80  FASTFIFO_DATA_DEPTH => N_TOBS_OUT)
81  port map (
82  clk => clk,
83  IN_Reset => FifoReset,
84  IN_Data => IN_Data(1),
85  IN_Write => Write1,
86  IN_Ack => Ack(1) and (not Done),
87  OUT_Empty => open,
88  OUT_Data => Data(1));
89 
90  OneOrTwo <= 0 when (TOBEnergy(Data(0)) > TOBEnergy(Data(1))) else 1;
91  Done <= '1' when (unsigned(TOBEnergy(Data(0))) = 0 and unsigned(TOBEnergy(Data(1))) = 0) else '0';
92  Ack(0) <= Acknowledge when OneOrTwo = 0 else '0';
93  Ack(1) <= Acknowledge when OneOrTwo = 1 else '0';
94 
95  delayProc : process (clk) is
96  begin
97  if rising_edge(clk) then
98  OUT_Data <= Data(OneOrTwo);
99  OUT_Start <= OutStart;
100  OUT_Write <= (OutWrite or OutStart) and not Done;
101  end if;
102  end process;
103 
104  CounterProc : process (clk) is
105  begin -- process SortingProc
106  if rising_edge(clk) then
107  if Start = '1' then
108  if TOB_Count > 0 then
109  report "Early start!" severity error;
110  end if;
111  if IN_Start /= "11" then
112  report "Start error: one of the 2 starts is 0!" severity error;
113  end if;
114 
115  OutStart <= '1';
116  TOB_Count <= N_TOBS_OUT-1; --because it actually starts one tick before
117  else
118  OutStart <= '0';
119  if TOB_Count > 0 then
120  TOB_Count <= TOB_Count - 1;
121  else
122  TOB_Count <= 0;
123  end if;
124 
125  end if;
126  end if;
127  end process CounterProc;
128 
129 
130 
131  WritingProc : process(clk) is
132  begin
133  if rising_edge(clk) then
134  if TOB_Count > N_TOBS+2 or Start = '1' then --writing
135  WriteInt <= '1';
136 
137  elsif TOB_Count < N_TOBS+2 then --done
138  WriteInt <= '0';
139 
140  else --last writing cycle
141  WriteInt <= '1';
142  end if;
143  end if;
144  end process WritingProc;
145 
146  ReadingProc : process (clk) is
147  begin -- process SortingProc
148  if rising_edge(clk) then
149  if TOB_Count > 1 or Start = '1' then --reading
150  FifoReset <= '0';
151  OutWrite <= '1'; -- protection against both fifo empty
152  Acknowledge <= '1';
153 
154  elsif TOB_Count > 0 then --last reading cycle (Count=1)
155  FifoReset <= '1';
156  OutWrite <= '1';
157  Acknowledge <= '0';
158 
159  else --done (Count=0)
160  FifoReset <= '0';
161  OutWrite <= '0';
162  Acknowledge <= '0';
163  end if;
164  end if;
165  end process ReadingProc;
166 
167 
168 
169 end architecture str;
170 
171 -------------------------------------------------------------------------------
External data-types and functions.
array(natural range <> ) of AlgoTriggerObject AlgoTriggerObjects
Algorithm OUTPUT port.
std_logic_vector( OUT_TOB_WIDTH- 1 downto 0) AlgoTriggerObject
Algorithm Trigger Object TOB.
Fast FIFO, without control signal but with 1 clock tick i/0 delay.
Definition: FastFifo.vhd:18
Parallel sorter module.
Parallel sorter module.