AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
memory_rnd.vhd
1 --**************************************
2 --
3 -- Block timer and wc load random
4 --
5 -- Dominique Gigi March 2012
6 --
7 -- To be used with Sergio vi
8 -- 16 lower bit is word count in bytes
9 -- 16 higher bit are time before next event
10 --
11 --**************************************
12 
13 LIBRARY ieee;
14 --LIBRARY altera_mf;
15 --LIBRARY altera;
16 
17 
18 USE ieee.std_logic_1164.all;
19 use ieee.numeric_std.all;
20 use ieee.std_logic_unsigned.all;
21 --LIBRARY lpm;
22 --USE lpm.lpm_components.all;
23 --USE altera_mf.altera_mf_components.all;
24 --USE altera.altera_primitives_components.all;
25 
26 entity memory_rnd is
27 
28 port (
29  RST_lowClk : IN std_logic;
30  low_clk : IN Std_logic;
31  RST_PCIClk : IN Std_logic;
32  PCIe_clk : IN std_logic;
33 
34  PCIe_dt : IN std_logic_vector(31 downto 0);
35  PCIe_func : IN std_logic_vector(15 downto 0);
36  PCIe_cs : IN std_logic;
37  PCIe_wen : IN std_logic;
38 
39  start : IN std_logic;
40 
41  wc : OUT std_logic_vector(15 downto 0);
42  RST_EvtClk : IN std_logic;
43  evt_clk : IN std_logic;
44  trigger : OUT std_logic;
45  end_evt : IN std_logic
46  );
47 end memory_rnd;
48 
49 architecture behavioral of memory_rnd is
50 
51 
52 --component LPM_FIFO !!!!!!!!!!!! ALTERA VERSION !!!!!!!!!!
53 --generic (
54 -- LPM_WIDTH : natural; -- MUST be greater than 0
55 -- LPM_WIDTHU : natural := 1; -- MUST be greater than 0
56 -- LPM_NUMWORDS : natural; -- MUST be greater than 0
57 -- LPM_SHOWAHEAD : string := "ON";
58 -- LPM_TYPE : string := L_FIFO;
59 -- LPM_HINT : string := "UNUSED");
60 -- port (
61 -- DATA : in std_logic_vector(LPM_WIDTH-1 downto 0);
62 -- CLOCK : in std_logic;
63 -- WRREQ : in std_logic;
64 -- RDREQ : in std_logic;
65 -- ACLR : in std_logic := '0';
66 -- SCLR : in std_logic := '0';
67 -- Q : out std_logic_vector(LPM_WIDTH-1 downto 0);
68 -- USEDW : out std_logic_vector(LPM_WIDTHU-1 downto 0);
69 -- FULL : out std_logic;
70 -- EMPTY : out std_logic);
71 --end component;
72 
73 --COMPONENT lpm_fifo --!!!!!!!!!!!!!!!!!!!! XILINX ISE VERSION !!!!!!!!!!!!!!!!!!!!!
74 -- PORT (
75 -- clk : IN STD_LOGIC;
76 -- rst : IN STD_LOGIC;
77 -- din : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
78 -- wr_en : IN STD_LOGIC;
79 -- rd_en : IN STD_LOGIC;
80 -- dout : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
81 -- full : OUT STD_LOGIC;
82 -- empty : OUT STD_LOGIC
83 -- );
84 --END COMPONENT;
85 
86 COMPONENT fifo_generator_0
87  PORT (
88  clk : IN STD_LOGIC;
89  rst : IN STD_LOGIC;
90  din : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
91  wr_en : IN STD_LOGIC;
92  rd_en : IN STD_LOGIC;
93  dout : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
94  full : OUT STD_LOGIC;
95  empty : OUT STD_LOGIC
96  );
97 END COMPONENT;
98 
99 component resync
100 port (
101  reset : in std_logic;
102  Free_clki : in std_logic;
103  clocki : in std_logic;
104  clocko : in std_logic;
105  input : in std_logic;
106  output : out std_logic
107  );
108 end component;
109 
110 signal data_mux : std_logic_vector(31 downto 0);
111 signal wen_mux : std_logic;
112 -- signal pcie_dt_ltch : std_logic_vector(31 downto 0);
113 signal low_wen_sync : std_logic;
114 signal end_evt_sync : std_logic;
115 signal fifo_dto : std_logic_vector(31 downto 0);
116 signal timer : std_logic_vector(15 downto 0);
117 signal timer_cnt : std_logic;
118 signal trig : std_logic;
119 signal soft_reset : std_logic;
120 
121 --******************************************************************************
122 --************************<< BEGIN >>***************************************
123 --******************************************************************************
124 begin
125 
126 wen_resync:resync
127 port map(
128  reset => RST_LowClk,
129  Free_clki => '1',
130  clocki => low_clk,
131  input => trig,
132 
133  clocko => PCIe_clk,
134  output => low_wen_sync
135  );
136 
137 process(RST_PCIClk,PCIe_clk)
138 begin
139  if RST_PCIClk = '0' then
140  wen_mux <= '0';
141  soft_reset <= '0';
142  elsif rising_edge(PCIe_clk) then
143  wen_mux <= '0';
144  if low_wen_sync = '1' or (PCIe_wen = '1' and PCIe_func(5) = '1' and PCIe_cs = '1') then
145  wen_mux <= '1';
146  end if;
147 
148  soft_reset <= '0';
149  if (PCIe_wen = '1' and PCIe_func(0) = '1' and PCIe_cs = '1' and PCIe_dt(5) = '1' ) then
150  soft_reset <= '1';
151  end if;
152 
153  if (PCIe_wen = '1' and PCIe_func(5) = '1' and PCIe_cs = '1') then
154  data_mux <= PCIe_dt;
155  else
156  data_mux <= fifo_dto;
157  end if;
158  end if;
159 end process;
160 
161 
162 
163 --fifo_rnd:LPM_FIFO !!!!!!!!!!!!!!!!!!!!!ALTERA VERSION !!!!!!!!!!!!!!!!!!!!!!!!!
164 --generic map(
165 -- LPM_WIDTH => 32,
166 -- LPM_WIDTHU => 10,
167 -- LPM_NUMWORDS => 1024)
168 --port map (
169 -- DATA => data_mux,
170 -- CLOCK => PCIe_clk,
171 -- WRREQ => wen_mux,
172 -- RDREQ => low_wen_sync,
173 -- ACLR => soft_reset,
174 -- Q => fifo_dto
175 -- );
176 
177 --fifo_rnd : lpm_fifo --!!!!!!!!!!!!!!!!!!!! XILINX ISE VERSION !!!!!!!!!!!!!!!!!
178 -- PORT MAP (
179 -- clk => PCIe_clk,
180 -- rst => soft_reset,
181 -- din => data_mux,
182 -- wr_en => wen_mux,
183 -- rd_en => low_wen_sync,
184 -- dout => fifo_dto
185 ---- full => full,
186 ---- empty => empty
187 -- );
188 
189 fifo_rnd: fifo_generator_0 --!!!!!!!!!!!!!!!!!!!! XILINX VIVADO VERSION !!!!!!!!!!!!!!!!!
190  PORT MAP (
191  clk => PCIe_clk,
192  rst => soft_reset,
193  din => data_mux,
194  wr_en => wen_mux,
195  rd_en => low_wen_sync,
196  dout => fifo_dto,
197  full => open,
198  empty => open
199  );
200 
201 End_evt_resync:resync
202 port map(
203  reset => RST_EvtClk,
204  Free_clki => '1',
205  clocki => evt_clk,
206  input => end_evt,
207 
208  clocko => low_clk,
209  output => end_evt_sync
210  );
211 
212 process(RST_LowClk,low_clk)
213 begin
214  if RST_LowClk = '0' then
215  timer <= (others => '0');
216  timer_cnt <= '0';
217  elsif rising_edge(low_clk) then
218  trig <= '0';
219  if timer_cnt = '1' and timer(15 downto 1) = "000000000000000" then -- we don't chekc the lower bit in case of the delay is set to 0
220  trig <= '1';
221  end if;
222 
223  if timer_cnt = '1' and timer(15 downto 1) = "000000000000000" then
224  timer_cnt <= '0';
225  elsif end_evt_sync = '1' then
226  timer_cnt <= '1';
227  end if;
228 
229  if timer_cnt = '1' then
230  timer <= timer - "1";
231  elsif end_evt_sync = '1' then
232  timer <= fifo_dto(31 downto 16);
233  end if;
234  end if;
235 end process;
236 
237 trigger <= low_wen_sync;
238 wc <= fifo_dto(15 downto 0);
239 
240 end behavioral;