CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
mini_fifo.vhd
Go to the documentation of this file.
1 ----------------------------------------------------------------------------------
13 ----------------------------------------------------------------------------------
14 library IEEE;
15 use IEEE.STD_LOGIC_1164.ALL;
16 
17 library work;
18 use work.CMXpackage.all;
19 
20 
21 -- Uncomment the following library declaration if using
22 -- arithmetic functions with Signed or Unsigned values
23 use IEEE.NUMERIC_STD.ALL;
24 
25 -- Uncomment the following library declaration if instantiating
26 -- any Xilinx primitives in this code.
27 --library UNISIM;
28 --use UNISIM.VComponents.all;
29 
30 entity mini_fifo is
31  generic
32  (
33  numbits : integer := TX_fifo_indata_length
34  );
35  port (
36  DATA_in : in std_logic_vector(numbits-1 downto 0);
37  DATA_out : out std_logic_vector(numbits-1 downto 0);
38  clk_i_dom : in std_logic; --input domain clock
39  clk_o_dom : in std_logic; --output domain clock
40  set_mem_ctr_i : in std_logic;
41  set_mem_ctr_o : in std_logic); --set signal (active high)
42  --(after sync to respective domains)
43 end mini_fifo;
44 
45 architecture Behavioral of mini_fifo is
46 
47 -- signal set_r_clk_i : std_logic;
48 -- signal set_rr_clk_i : std_logic;
49 -- signal set_rrr_clk_i : std_logic;
50 
51 
52 -- signal set_rr_clk_i_r_clk_o : std_logic;
53 
54 
55  signal set_mem_ctr_i_r,set_mem_ctr_o_r : std_logic; -- the set signal
56  -- registered once to
57  -- help timing closure
58  -- in respective clock domains
59 
60  signal ctr_i : unsigned(2 downto 0); --input side counter
61  signal ctr_o : unsigned(2 downto 0); --output side counter
62  signal ctr_i_next : unsigned(2 downto 0); --input side counter
63  signal ctr_o_next : unsigned(2 downto 0); --output side counter
64 
65 
66 
67  signal ena : STD_LOGIC;
68  signal wea : STD_LOGIC_VECTOR(0 DOWNTO 0);
69  signal addra : STD_LOGIC_VECTOR(2 DOWNTO 0);
70  signal dina : STD_LOGIC_VECTOR(numbits-1 DOWNTO 0);
71 
72  signal doutb : STD_LOGIC_VECTOR(numbits-1 DOWNTO 0);
73 
74  signal rstb : STD_LOGIC;
75  signal enb : STD_LOGIC;
76  signal addrb : STD_LOGIC_VECTOR(2 DOWNTO 0);
77 
78 
79  component block_mem
80  port (
81  clka : IN STD_LOGIC;
82  ena : IN STD_LOGIC;
83  wea : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
84  addra : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
85  dina : IN STD_LOGIC_VECTOR(numbits-1 DOWNTO 0);
86  clkb : IN STD_LOGIC;
87  rstb : IN STD_LOGIC;
88  enb : IN STD_LOGIC;
89  addrb : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
90  doutb : OUT STD_LOGIC_VECTOR(numbits-1 DOWNTO 0));
91  end component;
92 
93 begin
94 
95 
97  begin
98  if rising_edge(clk_i_dom) then
99  set_mem_ctr_i_r<=set_mem_ctr_i;
100  end if;
101  end process set_mem_ctr_i_del_proc;
102 
103 
105  begin
106  if rising_edge(clk_o_dom) then
107  set_mem_ctr_o_r<=set_mem_ctr_o;
108  end if;
109  end process set_mem_ctr_o_del_proc;
110 
111 
113  begin -- process i_ctr_proc
114  if rising_edge(clk_i_dom) then
115 
116  if set_mem_ctr_i_r='0' then
117  ctr_i<=ctr_i_next;
118  else
119  ctr_i<=to_unsigned(0,3);
120  end if;
121  end if;
122 
123  end process i_ctr_proc;
124 
126  begin -- process i_ctr_proc
127  if rising_edge(clk_o_dom) then
128 
129 
130 
131  DATA_out<=doutb; --this register needed - otherwise the
132  --thing does not meet timing
133 
134  if set_mem_ctr_o_r='0' then
135  ctr_o<=ctr_o_next;
136  else
137  ctr_o<=to_unsigned(6,3);
138  end if;
139  end if;
140  end process o_ctr_proc;
141 
142  ctr_o_next <= ctr_o+1;
143  ctr_i_next <= ctr_i+1;
144 
145  wea(0)<=not set_mem_ctr_i_r;
146  ena <= not set_mem_ctr_i_r;
147  addra <= std_logic_vector(ctr_i);
148 
149  --dina<=DATA_in when ena='1' else (others => '0');
150  dina<=DATA_in;
151 
152  addrb <= std_logic_vector(ctr_o);
154  enb <= not set_mem_ctr_o_r;
155 
156 
157  block_mem_i: block_mem
158  port map (
159  clka => clk_i_dom,
160  ena => ena,
161  wea => wea,
162  addra => addra,
163  dina => dina,
164  clkb => clk_o_dom,
165  rstb => rstb,
166  enb => enb,
167  addrb => addrb,
168  doutb => doutb);
169 
170 
171 end Behavioral;
172 
block_mem block_mem_iblock_mem_i
Definition: mini_fifo.vhd:157
set_mem_ctr_i_del_procclk_i_dom
Definition: mini_fifo.vhd:96
unsigned (2 downto 0) ctr_i
Definition: mini_fifo.vhd:60
_library_ ieeeieee
in clk_i_domstd_logic
Definition: mini_fifo.vhd:38
set_mem_ctr_o_del_procclk_o_dom
Definition: mini_fifo.vhd:104
STD_LOGIC_VECTOR (2 downto 0) addra
Definition: mini_fifo.vhd:69
in DATA_instd_logic_vector (numbits - 1 downto 0)
Definition: mini_fifo.vhd:36
in clk_o_domstd_logic
Definition: mini_fifo.vhd:39
STD_LOGIC_VECTOR (2 downto 0) addrb
Definition: mini_fifo.vhd:76
unsigned (2 downto 0) ctr_o_next
Definition: mini_fifo.vhd:63
unsigned (2 downto 0) ctr_o
Definition: mini_fifo.vhd:61
STD_LOGIC_VECTOR (0 downto 0) wea
Definition: mini_fifo.vhd:68
unsigned (2 downto 0) ctr_i_next
Definition: mini_fifo.vhd:62
STD_LOGIC_VECTOR (numbits - 1 downto 0) doutb
Definition: mini_fifo.vhd:72
out DATA_outstd_logic_vector (numbits - 1 downto 0)
Definition: mini_fifo.vhd:37
numbitsinteger :=TX_fifo_indata_length
Definition: mini_fifo.vhd:33
std_logic set_mem_ctr_o_r
Definition: mini_fifo.vhd:55
STD_LOGIC_VECTOR (numbits - 1 downto 0) dina
Definition: mini_fifo.vhd:70
std_logic set_mem_ctr_i_r
Definition: mini_fifo.vhd:55