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

Back to eFEX documentation
ipbus_sorting_inputRAM_wrapper.vhd
1 -- generalised from: ipbus_dpram
2 -- F. Gonnella, October 2017
3 --
4 
5 library IEEE;
6 use IEEE.STD_LOGIC_1164.all;
7 use ieee.numeric_std.all;
8 library ipbus_lib;
9 
10 use ipbus_lib.ipbus.all;
11 use work.DataTypes.all;
12 use work.AlgoDataTypes.all;
13 
15  port(
16  clk_ipb : in std_logic;
17  rst : in std_logic;
18  ipb_in : in ipb_wbus;
19  ipb_out : out ipb_rbus;
20  SortingIn : in AlgoOutput;
21  BCNIn : in std_logic_vector(11 downto 0);
22  SpyBCNIn : in std_logic := '0';
23 
24  rclk : in std_logic; --280
25  Sync : in std_logic;
26  we : in std_logic := '0';
27  SortingOut : out AlgoOutput
28  );
29 
31 
33 
34  component SortingInputRAM
35  port (
36  clka : in std_logic;
37  ena : in std_logic;
38  wea : in std_logic_vector(0 downto 0);
39  addra : in std_logic_vector(9 downto 0);
40  dina : in std_logic_vector(31 downto 0);
41  douta : out std_logic_vector(31 downto 0);
42  clkb : in std_logic;
43  enb : in std_logic;
44  web : in std_logic_vector(0 downto 0);
45  addrb : in std_logic_vector(6 downto 0); --contains 16 BCs*5TOBS
46  dinb : in std_logic_vector(255 downto 0);
47  doutb : out std_logic_vector(255 downto 0)
48  );
49  end component;
50 
51 
52  -- algorithm signals
53  signal dSync : std_logic_vector(5 downto 0);
54  signal din : std_logic_vector(255 downto 0);
55  signal q : std_logic_vector(255 downto 0);
56  signal address : std_logic_vector(6 downto 0) := "0000000"; --16 BCs*5TOBs
57  signal counter : std_logic_vector(2 downto 0) := "000"; --0-6
58  signal BC_counter : std_logic_vector(3 downto 0) := "0000"; --16 BCs*5TOBs
59  signal FirstFive : std_logic := '0';
60 
61  type AlgoOutputArray is array (3 downto 0) of AlgoOutput; -- output shift register
62  signal dOutput : AlgoOutputArray;
63 
64  --ipbus signals
65  signal ack : std_logic;
66  signal ack2 : std_logic;
67  signal ipbus_write : std_logic_vector(0 downto 0);
68  signal write_enable : std_logic_vector(0 downto 0);
69 
70 begin
71  IPBUS_RAM : process(clk_ipb)
72  begin
73  if rising_edge(clk_ipb) then
74  if ipb_in.ipb_strobe = '1' and ipb_in.ipb_write = '1' then
75  ipbus_write(0) <= '1';
76  else
77  ipbus_write(0) <= '0';
78  end if;
79  ack2 <= ipb_in.ipb_strobe and (not ack2) and (not ack);
80  ack <= ack2;
81 
82  end if;
83  end process;
84 
85  ipb_out.ipb_ack <= ack;
86  ipb_out.ipb_err <= '0';
87  --selects the first 5 ticks of the BCs
88 -- FirstFive <= '0' when unsigned(counter) > 4 else '1';
89  FirstFive <= '0' when counter = "101" or counter = "110" or counter = "111" else '1';
90 
91  write_enable(0) <= we and FirstFive; --don't write on RAM on 6th and 7th tick
92 
93  COUNTER_PROC : process(rclk)
94  begin
95  if rising_edge(rclk) then
96  dSync(0) <= Sync;
97  dSync(dSync'high downto 1) <= dSync(dSync'high-1 downto 0);
98 
99  if dSync(5) = '1' then
100  BC_counter <= std_logic_vector(unsigned(BC_counter) + 1);
101  end if;
102 
103  if BC_Counter = "0000" and dSync(5) = '1' then
104  counter <= (others => '0');
105  address <= (others => '0');
106  else
107  if counter = "110" then --counts the 7 ticks in one BC
108  counter <= (others => '0');
109  else
110  counter <= std_logic_vector(unsigned(counter) + 1);
111  end if;
112 
113  if FirstFive = '1' then
114  if address = "1001111" then
115  address <= (others => '0');
116  else
117  address <= std_logic_vector(unsigned(address) + 1);
118  end if;
119  else
120  address <= address;
121  end if;
122 
123 -- -- Output is sync'ed with
124  dOutput(0) <= to_AlgoOutput(q);
125  dOutput(dOutput'high downto 1) <= dOutput(dOutput'high-1 downto 0);
126  end if;
127  end if;
128  end process;
129 
130  ALGO_OUTPUT_RAM : SortingInputRAM
131  port map (
132  clka => clk_ipb,
133  ena => ipb_in.ipb_strobe,
134  wea => ipbus_write,
135  addra => ipb_in.ipb_addr(9 downto 0),
136  dina => ipb_in.ipb_wdata,
137  douta => ipb_out.ipb_rdata,
138  clkb => rclk,
139  enb => '1',
140  web => write_enable,
141  addrb => address,
142  dinb => din,
143  doutb => q
144  );
145 
146  SortingOut <= dOutput(3);
147  din <= to_LogicVector(SortingIn) when spyBCNIn = '0' else to_LogicVector(SortingIn)(din'high - 32 downto 0) & x"f" & BCNIn & x"0fff";
148 
149 end rtl;
External data-types and functions.
( OUTPUT_TOBS- 1 downto 0) AlgoTriggerObject AlgoOutput
Algorithm OUTPUT port.