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
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 resync
87 port (
88  reset : in std_logic;
89  Free_clki : in std_logic;
90  clocki : in std_logic;
91  clocko : in std_logic;
92  input : in std_logic;
93  output : out std_logic
94  );
95 end component;
96 
97 signal data_mux : std_logic_vector(31 downto 0);
98 signal wen_mux : std_logic;
99 -- signal pcie_dt_ltch : std_logic_vector(31 downto 0);
100 signal low_wen_sync : std_logic;
101 signal end_evt_sync : std_logic;
102 signal fifo_dto : std_logic_vector(31 downto 0);
103 signal timer : std_logic_vector(15 downto 0);
104 signal timer_cnt : std_logic;
105 signal trig : std_logic;
106 signal soft_reset : std_logic;
107 
108 --******************************************************************************
109 --************************<< BEGIN >>***************************************
110 --******************************************************************************
111 begin
112 
113 wen_resync:resync
114 port map(
115  reset => RST_LowClk,
116  Free_clki => '1',
117  clocki => low_clk,
118  input => trig,
119 
120  clocko => PCIe_clk,
121  output => low_wen_sync
122  );
123 
124 process(RST_PCIClk,PCIe_clk)
125 begin
126  if RST_PCIClk = '0' then
127  wen_mux <= '0';
128  soft_reset <= '0';
129  elsif rising_edge(PCIe_clk) then
130  wen_mux <= '0';
131  if low_wen_sync = '1' or (PCIe_wen = '1' and PCIe_func(5) = '1' and PCIe_cs = '1') then
132  wen_mux <= '1';
133  end if;
134 
135  soft_reset <= '0';
136  if (PCIe_wen = '1' and PCIe_func(0) = '1' and PCIe_cs = '1' and PCIe_dt(5) = '1' ) then
137  soft_reset <= '1';
138  end if;
139 
140  if (PCIe_wen = '1' and PCIe_func(5) = '1' and PCIe_cs = '1') then
141  data_mux <= PCIe_dt;
142  else
143  data_mux <= fifo_dto;
144  end if;
145  end if;
146 end process;
147 
148 
149 
150 --fifo_rnd:LPM_FIFO !!!!!!!!!!!!!!!!!!!!!ALTERA VERSION !!!!!!!!!!!!!!!!!!!!!!!!!
151 --generic map(
152 -- LPM_WIDTH => 32,
153 -- LPM_WIDTHU => 10,
154 -- LPM_NUMWORDS => 1024)
155 --port map (
156 -- DATA => data_mux,
157 -- CLOCK => PCIe_clk,
158 -- WRREQ => wen_mux,
159 -- RDREQ => low_wen_sync,
160 -- ACLR => soft_reset,
161 -- Q => fifo_dto
162 -- );
163 
164 fifo_rnd : lpm_fifo --!!!!!!!!!!!!!!!!!!!! XILINX VERSION !!!!!!!!!!!!!!!!!
165  PORT MAP (
166  clk => PCIe_clk,
167  rst => soft_reset,
168  din => data_mux,
169  wr_en => wen_mux,
170  rd_en => low_wen_sync,
171  dout => fifo_dto
172 -- full => full,
173 -- empty => empty
174  );
175 
176 End_evt_resync:resync
177 port map(
178  reset => RST_EvtClk,
179  Free_clki => '1',
180  clocki => evt_clk,
181  input => end_evt,
182 
183  clocko => low_clk,
184  output => end_evt_sync
185  );
186 
187 process(RST_LowClk,low_clk)
188 begin
189  if RST_LowClk = '0' then
190  timer <= (others => '0');
191  timer_cnt <= '0';
192  elsif rising_edge(low_clk) then
193  trig <= '0';
194  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
195  trig <= '1';
196  end if;
197 
198  if timer_cnt = '1' and timer(15 downto 1) = "000000000000000" then
199  timer_cnt <= '0';
200  elsif end_evt_sync = '1' then
201  timer_cnt <= '1';
202  end if;
203 
204  if timer_cnt = '1' then
205  timer <= timer - "1";
206  elsif end_evt_sync = '1' then
207  timer <= fifo_dto(31 downto 16);
208  end if;
209  end if;
210 end process;
211 
212 trigger <= low_wen_sync;
213 wc <= fifo_dto(15 downto 0);
214 
215 end behavioral;