1 ----------------------------------------------------------------------------------
5 -- Create Date: 11:
02:
29 01/25/2013
7 -- Module Name: ddr_wportA - Behavioral
16 -- Revision 0.
01 -
File Created
17 -- Additional Comments:
19 ----------------------------------------------------------------------------------
21 use IEEE.STD_LOGIC_1164.
ALL;
22 use IEEE.STD_LOGIC_ARITH.
ALL;
23 use IEEE.STD_LOGIC_UNSIGNED.
ALL;
24 use IEEE.std_logic_misc.
all;
27 -- Uncomment the following library declaration if using
28 -- arithmetic functions with or values
29 --use IEEE.NUMERIC_STD.ALL;
31 -- Uncomment the following library declaration if instantiating
32 -- any Xilinx primitives in this code.
34 use UNISIM.VComponents.
all;
36 use UNIMACRO.vcomponents.
all;
46 din : in (65 downto 0);
48 port_rdy : out ;
-- port ready to accept a new event
51 KiloByte_toggle : out ;
54 event_addr : in (13 downto 0);
56 rqst : out ;
-- request to output data
57 ack : in ;
-- permission to output data
62 app_addr : out (23 downto 0) := (others => '0');
-- starting address of write burst(1Kbytes or until end of event)
63 dout : out (255 downto 0) := (others => '0');
64 cs_out : out (511 downto 0);
65 debug : out (63 downto 0)
82 signal AddrQueue_di : (13 downto 0) := (others => '0');
83 signal AddrQueue_do : (13 downto 0) := (others => '0');
84 signal AddrQueue_dop : (13 downto 12) := (others => '0');
85 signal AddrQueue_wa : (4 downto 0) := (others => '0');
86 signal AddrQueue_rap : (1 downto 0) := (others => '0');
87 signal AddrQueue_ra : (4 downto 0) := (others => '0');
88 signal AddrQueue_wa0SyncRegs : (2 downto 0) := (others => '0');
89 signal AddrQueue_wa1SyncRegs : (2 downto 0) := (others => '0');
90 signal EoE_toggleSyncRegs : (3 downto 0) := (others => '0');
91 signal EoB_toggleSyncRegs : (3 downto 0) := (others => '0');
92 signal en_din : := '0';
93 signal rqst_i : := '0';
94 signal KiloByte_toggle_i : := '0';
95 signal EoB_toggle_i : := '0';
96 signal EoE_toggle_i : := '0';
97 signal last_word : := '0';
98 signal EventDone : := '0';
99 signal EventDone_dl : := '0';
100 signal FIFO_empty : := '1';
101 --signal FIFO_empty_q : := '1';
102 signal FIFO_AlmostEmpty : := '1';
103 signal FIFO_sel : (1 downto 0) := (others => '0');
104 signal FIFO_we : (3 downto 0) := (others => '0');
105 signal FIFO_DI : (65 downto 0) := (others => '0');
106 signal FIFO_DO : (257 downto 0) := (others => '0');
107 signal WRCOUNT : array4x9;
108 signal RDCOUNT : array4x9;
109 signal dout_wc : (4 downto 0) := (others => '0');
110 signal app_wren : := '0';
111 signal app_addr_i : (13 downto 0) := (others => '0');
115 -- if(memclk'event and memclk = '1')then
116 -- cs_out(39) <= rqst_i
and ack
and fifo_empty;
117 -- cs_out(38) <= rqst_i
and fifo_empty;
120 cs_out(42) <= app_wdf_rdy;
121 cs_out(41) <= app_rdy;
123 cs_out(37) <= din(64);
124 cs_out(36) <= din_we;
125 cs_out(35) <= en_din;
126 cs_out(34 downto 31) <= FIFO_we;
127 cs_out(30 downto 29) <= FIFO_sel;
128 cs_out(28 downto 25) <= EoE_toggleSyncRegs;
129 cs_out(24 downto 23) <= AddrQueue_rap;
130 cs_out(22 downto 21) <= AddrQueue_wa(1 downto 0);
131 cs_out(20) <= EoE_toggle_i;
132 cs_out(19) <= EoB_toggle_i;
133 cs_out(18) <= rqst_i;
134 cs_out(17) <= EventDone;
135 cs_out(16) <= last_word;
136 cs_out(15) <= FIFO_DO(256);
137 cs_out(14) <= FIFO_AlmostEmpty;
138 cs_out(13) <= FIFO_empty;
139 cs_out(12 downto 10) <= AddrQueue_wa0SyncRegs;
140 cs_out(9 downto 7) <= AddrQueue_wa1SyncRegs;
141 cs_out(6 downto 5) <= AddrQueue_ra(1 downto 0);
142 cs_out(4 downto 0) <= dout_wc;
143 --cs_out(14) <= rqst_i;
144 --cs_out(13) <= EventDone;
145 --cs_out(12) <= last_word;
146 --cs_out(11) <= FIFO_DO(
256);
147 --cs_out(10) <= FIFO_AlmostEmpty;
148 --cs_out(9) <= FIFO_empty;
149 --cs_out(8) <= AddrQueue_wa0SyncRegs(
2);
150 --cs_out(7) <= AddrQueue_wa1SyncRegs(
2);
151 --cs_out(6 downto 5) <= AddrQueue_ra(
1 downto 0);
152 --cs_out(4 downto 0) <= dout_wc;
153 debug(63 downto 1) <= (others => '0');
156 if(memclk'event and memclk = '1')then
157 if(resetMem = '1')then
159 elsif(ack = '1' and fifo_empty = '1')then
164 KiloByte_toggle <= KiloByte_toggle_i;
165 EoB_toggle <= EoB_toggle_i;
166 rqst <= '0' when rqst_i = '0' or ((FIFO_DO(256) = '1' or last_word = '1') and app_wren = '1') else '1';
167 app_wdf_wren <= app_wren;
169 --app_wren <= ack and app_rdy and app_wdf_rdy and not FIFO_empty and not FIFO_empty_q;
170 app_wren <= ack and app_rdy and app_wdf_rdy;
171 app_addr <= AddrQueue_do(13 downto 4) & app_addr_i;
172 g_AddrQueue : for i in 0 to 1 generate
176 di => AddrQueue_di
(i*6+5
downto i*6
),
181 do => AddrQueue_do
(i*6+5
downto i*6
)
183 i_AddrQueueH : RAM32X1D
185 DPO => AddrQueue_dop
(i+12
),
-- Read-only 1-bit data output
186 SPO =>
open,
-- R/W 1-bit data output
187 A0 => AddrQueue_wa
(0),
-- R/W address[0] input
188 A1 => AddrQueue_wa
(1),
-- R/W address[1] input
189 A2 => AddrQueue_wa
(2),
-- R/W address[2] input
190 A3 => AddrQueue_wa
(3),
-- R/W address[3] input
191 A4 => AddrQueue_wa
(4),
-- R/W address[4] input
192 D => AddrQueue_di
(i+12
),
-- Write 1-bit data input
193 DPRA0 => AddrQueue_ra
(0),
-- Read-only address[0] input
194 DPRA1 => AddrQueue_ra
(1),
-- Read-only address[1] input
195 DPRA2 => AddrQueue_ra
(2),
-- Read-only address[2] input
196 DPRA3 => AddrQueue_ra
(3),
-- Read-only address[3] input
197 DPRA4 => AddrQueue_ra
(4),
-- Read-only address[4] input
198 WCLK => sysclk,
-- Write clock input
199 WE => addr_we
-- Write enable input
204 if(memclk'event and memclk = '1')then
205 AddrQueue_do(13 downto 12) <= AddrQueue_dop(13 downto 12);
208 AddrQueue_di <= event_addr;
209 process(sysclk, AddrQueue_wa, AddrQueue_rap)
210 variable dist : (3 downto 0);
212 dist := AddrQueue_wa(1 downto 0) & AddrQueue_rap;
213 if(sysclk'event and sysclk = '1')then
214 if(fifo_en = '0' or (din(64) = '1' and din_we = '1'))then
216 elsif(addr_we = '1')then
219 if(fifo_en = '0')then
220 AddrQueue_wa <= (others => '0');
221 elsif(en_din = '1' and din(64) = '1' and din_we = '1')then
222 AddrQueue_wa(1) <= AddrQueue_wa(0);
223 AddrQueue_wa(0) <= not AddrQueue_wa(1);
225 if(fifo_en = '0')then
226 AddrQueue_rap <= (others => '0');
227 elsif(EoB_toggleSyncRegs(3) /= EoB_toggleSyncRegs(2))then
228 AddrQueue_rap(1) <= AddrQueue_rap(0);
229 AddrQueue_rap(0) <= not AddrQueue_rap(1);
231 EoB_toggleSyncRegs <= EoB_toggleSyncRegs(2 downto 0) & EoB_toggle_i;
232 EoE_toggleSyncRegs <= EoE_toggleSyncRegs(2 downto 0) & EoE_toggle_i;
233 if(resetSys = '1' or EoB_toggleSyncRegs(3) = EoB_toggleSyncRegs(2))then
234 WrtMonBlkDone <= '0';
236 WrtMonBlkDone <= '1';
238 if(resetSys = '1' or EoE_toggleSyncRegs(3) = EoE_toggleSyncRegs(2))then
239 WrtMonEvtDone <= '0';
241 WrtMonEvtDone <= '1';
247 when x"1" | x"7" | x"8" | x"e" => port_rdy <= '0';
248 when others => port_rdy <= '1';
252 if(resetSys = '1' or en_din = '0')then
253 FIFO_sel <= (others => '0');
254 elsif(din_we = '1')then
255 FIFO_sel <= FIFO_sel + 1;
257 FIFO_we(0) <= en_din and din_we and not FIFO_sel(1) and not FIFO_sel(0);
258 FIFO_we(1) <= en_din and din_we and not FIFO_sel(1) and (din(64) or FIFO_sel(0));
259 FIFO_we(2) <= en_din and din_we and ((din(64) and not FIFO_sel(1)) or (FIFO_sel(1) and not FIFO_sel(0)));
260 FIFO_we(3) <= en_din and din_we and (din(64) or (FIFO_sel(1) and FIFO_sel(0)));
263 g_FIFO: for i in 0 to 2 generate
264 i_FIFO : FIFO_DUALCLOCK_MACRO
266 DEVICE =>
"7SERIES",
-- Target Device: "VIRTEX5",
"VIRTEX6",
"7SERIES"
267 ALMOST_FULL_OFFSET => X"0080",
-- Sets almost full threshold
268 ALMOST_EMPTY_OFFSET => X"0080",
-- Sets the almost empty threshold
269 DATA_WIDTH =>
64,
-- Valid values are 1-72 (37-72 only valid when FIFO_SIZE="36Kb")
270 FIFO_SIZE =>
"36Kb",
-- Target BRAM, "18Kb" or "36Kb"
271 FIRST_WORD_FALL_THROUGH => TRUE
) -- Sets the FIFO FWFT to TRUE or FALSE
273 ALMOSTEMPTY =>
open,
-- 1-bit output almost empty
274 ALMOSTFULL =>
open,
-- 1-bit output almost full
275 DO => FIFO_DO
(i*64+63
downto i*64
),
-- Output data, width defined by DATA_WIDTH parameter
276 EMPTY =>
open,
-- 1-bit output empty
277 FULL =>
open,
-- 1-bit output full
278 RDCOUNT => RDCOUNT
(i
),
-- Output read count, width determined by FIFO depth
279 RDERR =>
open,
-- 1-bit output read error
280 WRCOUNT => WRCOUNT
(i
),
-- Output write count, width determined by FIFO depth
281 WRERR =>
open,
-- 1-bit output write error
282 DI => FIFO_DI
(63 downto 0),
-- Input data, width defined by DATA_WIDTH parameter
283 RDCLK => memclk,
-- 1-bit input read clock
284 RDEN => app_wren,
-- 1-bit input read enable
285 RST => fifo_rst,
-- 1-bit input reset
286 WRCLK => sysclk,
-- 1-bit input write clock
287 WREN => FIFO_we
(i
) -- 1-bit input write enable
290 i_FIFO3 : FIFO_DUALCLOCK_MACRO
292 DEVICE =>
"7SERIES",
-- Target Device: "VIRTEX5",
"VIRTEX6",
"7SERIES"
293 ALMOST_FULL_OFFSET => X"0008",
-- Sets almost full threshold
294 ALMOST_EMPTY_OFFSET => X"001f",
-- Sets the almost empty threshold
295 DATA_WIDTH =>
66,
-- Valid values are 1-72 (37-72 only valid when FIFO_SIZE="36Kb")
296 FIFO_SIZE =>
"36Kb",
-- Target BRAM, "18Kb" or "36Kb"
297 FIRST_WORD_FALL_THROUGH => TRUE
) -- Sets the FIFO FWFT to TRUE or FALSE
299 ALMOSTEMPTY => FIFO_AlmostEmpty,
-- 1-bit output almost empty
300 ALMOSTFULL => buf_full,
-- 1-bit output almost full
301 DO => FIFO_DO
(257 downto 192),
-- Output data, width defined by DATA_WIDTH parameter
302 EMPTY => FIFO_empty,
-- 1-bit output empty
303 FULL =>
open,
-- 1-bit output full
304 RDCOUNT => RDCOUNT
(3),
-- Output read count, width determined by FIFO depth
305 RDERR =>
open,
-- 1-bit output read error
306 WRCOUNT => WRCOUNT
(3),
-- Output write count, width determined by FIFO depth
307 WRERR =>
open,
-- 1-bit output write error
308 DI => FIFO_DI,
-- Input data, width defined by DATA_WIDTH parameter
309 RDCLK => memclk,
-- 1-bit input read clock
310 RDEN => app_wren,
-- 1-bit input read enable
311 RST => fifo_rst,
-- 1-bit input reset
312 WRCLK => sysclk,
-- 1-bit input write clock
313 WREN => FIFO_we
(3) -- 1-bit input write enable
317 if(memclk'event and memclk = '1')then
318 if(resetMem = '1' or run = '0')then
319 AddrQueue_wa0SyncRegs <= (others => '0');
320 AddrQueue_wa1SyncRegs <= (others => '0');
321 AddrQueue_ra <= (others => '0');
326 dout_wc <= (others => '0');
328 AddrQueue_wa0SyncRegs <= AddrQueue_wa0SyncRegs(1 downto 0) & AddrQueue_wa(0);
329 AddrQueue_wa1SyncRegs <= AddrQueue_wa1SyncRegs(1 downto 0) & AddrQueue_wa(1);
330 if(EventDone = '1' and EventDone_dl = '0')then
331 AddrQueue_ra(1) <= AddrQueue_ra(0);
332 AddrQueue_ra(0) <= not AddrQueue_ra(1);
334 if(EventDone = '1' and FIFO_empty = '0')then
336 elsif(FIFO_DO(256) = '1' and app_wren = '1')then
339 EventDone_dl <= EventDone;
340 if(app_wren = '1')then
341 if(dout_wc = "11110")then
347 if(fifo_en = '0' or EventDone = '1' or FIFO_empty = '1' or ((FIFO_DO(256) = '1' or last_word = '1') and app_wren = '1'))then
349 elsif((AddrQueue_ra(1) /= AddrQueue_wa1SyncRegs(2) or AddrQueue_ra(0) /= AddrQueue_wa0SyncRegs(2)) or FIFO_AlmostEmpty = '0')then
352 if(EventDone = '1')then
353 dout_wc <= (others => '0');
354 elsif(app_wren = '1')then
355 dout_wc <= dout_wc + 1;
358 -- if(resetMem = '0' and run = '1' and FIFO_DO(256) = '0'
and last_word = '1'
and app_wren = '1')
then
359 if(resetMem = '0' and run = '1' and last_word = '1' and app_wren = '1')then
360 KiloByte_toggle_i <= not KiloByte_toggle_i;
362 if(resetMem = '0' and run = '1' and FIFO_DO(256) = '1' and app_wren = '1')then
363 EoB_toggle_i <= not EoB_toggle_i;
365 if(resetMem = '0' and run = '1' and FIFO_DO(257) = '1' and app_wren = '1')then
366 EoE_toggle_i <= not EoE_toggle_i;
372 if(memclk'event and memclk = '1')then
373 if(EventDone_dl = '1')then
374 app_addr_i(9 downto 0) <= (others => '0');
375 app_addr_i(13 downto 10) <= AddrQueue_do(3 downto 0);
376 elsif(app_wren = '1')then
377 app_addr_i(13 downto 0) <= app_addr_i(13 downto 0) + 1;
381 dout <= FIFO_DO(255 downto 0);