AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
FIFO_sync.vhd
1 ------------------------------------------------------
2 -- Component FIFO
3 --
4 -- Ver 1.00
5 --
6 -- Dominique Gigi Feb 2012
7 ------------------------------------------------------
8 --
9 --
10 --
11 --
12 ------------------------------------------------------
13 LIBRARY ieee;
14 -- LIBRARY altera_mf;
15 -- LIBRARY altera;
16 
17 
18 
19 USE ieee.std_logic_1164.all;
20 use ieee.numeric_std.all;
21 
22 
23 -- LIBRARY lpm;
24 -- USE lpm.lpm_components.all;
25 -- USE altera_mf.altera_mf_components.all;
26 -- USE altera.altera_primitives_components.all;
27 
28 entity FIFO_sync is
29 generic ( fifo_deep : integer := 6
30  );
31 port
32  (
33  aclr : in std_logic; -- active low
34  clk_w : in std_logic;
35  wen : in std_logic;
36  dataw : in std_logic_vector(65 downto 0);
37  almost_f: out std_logic; -- active low
38  clk_r : in std_logic;
39  datar : out std_logic_vector(65 downto 0);
40  ren : in std_logic;
41  empty : out std_logic -- active low
42  );
43 end FIFO_sync;
44 
45 architecture behavioral of FIFO_sync is
46 
47 
48 
49 --***********************************************************
50 --********************** ALTERA DC FIFO *******************
51 --***********************************************************
52 -- component LPM_FIFO_DC --!!!!!!!!!!!!!!!!!!!!!!! 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_DC;
59  -- UNDERFLOW_CHECKING : string := "ON";
60  -- OVERFLOW_CHECKING : string := "ON";
61  -- LPM_HINT : string := "UNUSED");
62 -- port (
63  -- DATA : in std_logic_vector(LPM_WIDTH-1 downto 0);
64  -- WRCLOCK : in std_logic;
65  -- RDCLOCK : in std_logic;
66  -- WRREQ : in std_logic;
67  -- RDREQ : in std_logic;
68  -- ACLR : in std_logic := '0';
69  -- Q : out std_logic_vector(LPM_WIDTH-1 downto 0);
70  -- WRUSEDW : out std_logic_vector(LPM_WIDTHU-1 downto 0);
71  -- RDUSEDW : out std_logic_vector(LPM_WIDTHU-1 downto 0);
72  -- WRFULL : out std_logic;
73  -- RDFULL : out std_logic;
74  -- WREMPTY : out std_logic;
75  -- RDEMPTY : out std_logic);
76 -- end component;
77 
78 COMPONENT lpm_fifo_dc -- !!!!!!!!!!!!!!! XILINX VERSION !!!!!!!!!!!!!
79  PORT (
80 
81  wr_clk : IN STD_LOGIC;
82  wr_rst : IN STD_LOGIC;
83  rd_clk : IN STD_LOGIC;
84  rd_rst : IN STD_LOGIC;
85  din : IN STD_LOGIC_VECTOR(65 DOWNTO 0);
86  wr_en : IN STD_LOGIC;
87  rd_en : IN STD_LOGIC;
88  dout : OUT STD_LOGIC_VECTOR(65 DOWNTO 0);
89  full : OUT STD_LOGIC;
90  empty : OUT STD_LOGIC;
91  wr_data_count : OUT STD_LOGIC_VECTOR(5 DOWNTO 0)
92 
93  );
94 END COMPONENT;
95 
96 signal almost_full_reg : std_logic;
97 signal resetp : std_logic;
98 signal word_used : std_logic_vector(fifo_deep-1 downto 0);
99 
100 
101 --***********************************************************
102 --********************** BEGIN ****************************
103 --***********************************************************
104 begin
105 
106 resetp <= '1' when aclr = '0' else '0';
107 
108 -- fifo_dc:LPM_FIFO_DC -- !!!!!!!!!!!!! ALTERA VERSION
109 -- generic MAP(
110  -- LPM_WIDTH => 66, -- MUST be greater than 0
111  -- LPM_WIDTHU => fifo_deep, -- MUST be greater than 0
112  -- LPM_NUMWORDS => 64 -- MUST be greater than 0
113  -- )
114 -- port MAP(
115  -- DATA => dataw,
116  -- WRCLOCK => clk_w,
117  -- RDCLOCK => clk_r,
118  -- WRREQ => wen,
119  -- RDREQ => ren,
120  -- ACLR => resetp,
121  -- Q => datar,
122  -- WRUSEDW => word_used,
123  -- RDEMPTY => empty
124  -- );
125 
126 fifo_dc : lpm_fifo_dc -- !!!!!!!!!!!!!!! XILINX VERSION !!!!!!!!!!!!!
127  PORT MAP (
128 
129  wr_clk => clk_w,
130  wr_rst => resetp,
131  rd_clk => clk_r,
132  rd_rst => resetp,
133  din => dataw,
134  wr_en => wen,
135  rd_en => ren,
136  dout => datar,
137  -- full => full,
138  empty => empty,
139  wr_data_count => word_used
140  );
141 
142 
143 
144 
145 process(aclr,clk_w)
146 begin
147 if aclr = '0' then
148  almost_full_reg <= '1';
149 elsif rising_edge(clk_w) then
150  if word_used >= "110000" then --enable almostFull when reaches 48 data in FIFO of 64
151  almost_full_reg <= '0';
152  elsif word_used < "100101" then -- realize almostFull below 37 data in FIFO of 64
153  almost_full_reg <= '1';
154  end if;
155 end if;
156 end process;
157 
158 almost_f <= almost_full_reg;
159 
160 end behavioral;