AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
FIFO65x8k.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 10:01:22 10/08/2013
6 -- Design Name:
7 -- Module Name: FIFO72x8192 - Behavioral
8 -- Project Name:
9 -- Target Devices:
10 -- Tool versions:
11 -- Description:
12 --
13 -- Dependencies:
14 --
15 -- Revision:
16 -- Revision 0.01 - File Created
17 -- Additional Comments:
18 --
19 ----------------------------------------------------------------------------------
20 library IEEE;
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;
25 
26 -- Uncomment the following library declaration if using
27 -- arithmetic functions with Signed or Unsigned values
28 --use IEEE.NUMERIC_STD.ALL;
29 
30 -- Uncomment the following library declaration if instantiating
31 -- any Xilinx primitives in this code.
32 library UNISIM;
33 use UNISIM.VComponents.all;
34 Library UNIMACRO;
35 use UNIMACRO.vcomponents.all;
36 
37 entity FIFO65x8k is
38  Port ( clk : in STD_LOGIC;
39  fifo_rst : in STD_LOGIC;
40  fifo_en : in STD_LOGIC;
41  di : in STD_LOGIC_VECTOR (32 downto 0);
42  we : in STD_LOGIC_VECTOR (1 downto 0);
43  re : in STD_LOGIC;
44  do : out STD_LOGIC_VECTOR (64 downto 0);
45  FIFO_WrErr : out STD_LOGIC;
46  empty : out STD_LOGIC);
47 end FIFO65x8k;
48 
49 architecture Behavioral of FIFO65x8k is
50 type array2x7 is array (0 to 1) of std_logic_vector(6 downto 0);
51 signal fifo_re : array2X7 := (others => (others => '0'));
52 signal fifo_we : array2X7 := (others => (others => '0'));
53 type array2x65 is array (0 to 1) of std_logic_vector(64 downto 0);
54 signal dip : array2X65 := (others => (others => '0'));
55 signal dop : array2X65 := (others => (others => '0'));
56 signal fifo_empty : std_logic_vector(13 downto 0) := (others => '0');
57 signal fifo_full : std_logic_vector(13 downto 0) := (others => '0');
58 signal fifo_Almostfull : std_logic_vector(13 downto 0) := (others => '0');
59 type array14X12 is array (0 to 13) of std_logic_vector(11 downto 0);
60 signal rdcount : array14X12 := (others => (others => '0'));
61 signal wrcount : array14X12 := (others => (others => '0'));
62 signal BRAM_re : std_logic := '0';
63 signal BRAM_vld : std_logic := '0';
64 signal wa_equal_ra_q : std_logic := '0';
65 signal do_vld : std_logic_vector(1 downto 0) := (others => '0');
66 signal wa : std_logic_vector(12 downto 0) := (others => '0');
67 signal ra : std_logic_vector(12 downto 0) := (others => '0');
68 
69 begin
70 dip(0)(64 downto 32) <= di;
71 process(clk)
72 begin
73  if(clk'event and clk = '1')then
74  if(we(0) = '1')then
75  dip(0)(31 downto 0) <= di(31 downto 0);
76  end if;
77  end if;
78 end process;
79 g_FIFO_j: for j in 0 to 1 generate
80  g_FIFO: for i in 0 to 6 generate
81  i_FIFO : FIFO_DUALCLOCK_MACRO
82  generic map (
83  DEVICE => "7SERIES", -- Target Device: "VIRTEX5", "VIRTEX6", "7SERIES"
84  DATA_WIDTH => 9, -- Valid values are 1-72 (37-72 only valid when FIFO_SIZE="36Kb")
85  FIFO_SIZE => "36Kb", -- Target BRAM, "18Kb" or "36Kb"
86  FIRST_WORD_FALL_THROUGH => TRUE) -- Sets the FIFO FWFT to TRUE or FALSE
87  port map (
88  ALMOSTEMPTY => open, -- 1-bit output almost empty
89  ALMOSTFULL => open, -- 1-bit output almost full
90  DO => dop(j)(i*9+8 downto i*9), -- Output data, width defined by DATA_WIDTH parameter
91  EMPTY => fifo_empty(j*7+i), -- 1-bit output empty
92  FULL => FIFO_full(j*7+i), -- 1-bit output full
93  RDCOUNT => rdcount(j*7+i), -- Output read count, width determined by FIFO depth
94  RDERR => open, -- 1-bit output read error
95  WRCOUNT => wrcount(j*7+i), -- Output write count, width determined by FIFO depth
96  WRERR => open, -- 1-bit output write error
97  DI => dip(j)(i*9+8 downto i*9), -- Input data, width defined by DATA_WIDTH parameter
98  RDCLK => clk, -- 1-bit input read clock
99  RDEN => FIFO_re(j)(i), -- 1-bit input read enable
100  RST => fifo_rst, -- 1-bit input reset
101  WRCLK => clk, -- 1-bit input write clock
102  WREN => FIFO_we(j)(i) -- 1-bit input write enable
103  );
104  end generate;
105 end generate;
106 dip(1)(62 downto 0) <= dop(0)(62 downto 0);
107 FIFO6463 : BRAM_SDP_MACRO
108  generic map (
109  BRAM_SIZE => "18Kb", -- Target BRAM, "18Kb" or "36Kb"
110  DEVICE => "7SERIES", -- Target device: "VIRTEX5", "VIRTEX6", "7SERIES", "SPARTAN6"
111  WRITE_WIDTH => 2, -- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
112  READ_WIDTH => 2) -- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
113  port map (
114  DO => dop(1)(64 downto 63), -- Output read data port, width defined by READ_WIDTH parameter
115  DI => dip(0)(64 downto 63), -- Input write data port, width defined by WRITE_WIDTH parameter
116  RDADDR => ra, -- Input read address, width defined by read port depth
117  RDCLK => clk, -- 1-bit input read clock
118  RDEN => BRAM_re, -- 1-bit input read port enable
119  REGCE => '0', -- 1-bit input read output register enable
120  RST => '0', -- 1-bit input reset
121  WE => "1", -- Input write enable, width defined by write port depth
122  WRADDR => wa, -- Input write address, width defined by write port depth
123  WRCLK => clk, -- 1-bit input write clock
124  WREN => we(1) -- 1-bit input write port enable
125  );
126 process(clk,fifo_rst)
127 begin
128  if(fifo_rst = '1')then
129  wa <= (others => '0');
130  ra <= (others => '0');
131  wa_equal_ra_q <= '0';
132  BRAM_vld <= '0';
133  do_vld <= "00";
134  empty <= '1';
135  elsif(clk'event and clk = '1')then
136  if(we(1) = '1' and fifo_en = '1')then
137  wa <= wa + 1;
138  end if;
139  if(BRAM_re = '1')then
140  ra <= ra + 1;
141  end if;
142  if(wa = ra)then
143  wa_equal_ra_q <= '1';
144  else
145  wa_equal_ra_q <= '0';
146  end if;
147  if(BRAM_re = '1')then
148  BRAM_vld <= '1';
149  elsif(do_vld(1) = '0' or re = '1')then
150  BRAM_vld <= '0';
151  end if;
152  if(BRAM_vld = '1')then
153  do_vld(1) <= '1';
154  elsif(re = '1')then
155  do_vld(1) <= '0';
156  end if;
157  if(fifo_empty(13) = '0')then
158  do_vld(0) <= '1';
159  elsif(re = '1')then
160  do_vld(0) <= '0';
161  end if;
162  if(fifo_empty(13) = '0')then
163  empty <= '0';
164  elsif(re = '1')then
165  empty <= '1';
166  end if;
167  end if;
168 end process;
169 BRAM_re <= '1' when fifo_en = '1' and wa /= ra and wa_equal_ra_q = '0' and (BRAM_vld = '0' or do_vld(1) = '0' or re = '1') else '0';
170 process(clk)
171 begin
172  if(clk'event and clk = '1')then
173  if(do_vld(1) = '0' or re = '1')then
174  do(64 downto 63) <= dop(1)(64 downto 63);
175  end if;
176  if(do_vld(0) = '0' or re = '1')then
177  do(62 downto 0) <= dop(1)(62 downto 0);
178  end if;
179  end if;
180 end process;
181 g_we_re : for i in 0 to 6 generate
182  FIFO_we(0)(i) <= '1' when we(1) = '1' and FIFO_en = '1' else '0';
183  FIFO_we(1)(i) <= '1' when FIFO_full(7+i) = '0' and fifo_empty(i) = '0' and FIFO_en = '1' else '0';
184  FIFO_re(1)(i) <= '1' when FIFO_en = '1' and fifo_empty(13) = '0' and (do_vld(0) = '0' or re = '1') else '0';
185 end generate;
186 FIFO_re(0) <= FIFO_we(1);
187 end Behavioral;
188