1 |
32 |
TobiasJ |
-----------------------------
|
2 |
|
|
-- rx_fifo
|
3 |
|
|
------------------------------
|
4 |
|
|
-- WB interface has the highest priority.
|
5 |
|
|
--
|
6 |
|
|
--
|
7 |
22 |
TobiasJ |
library IEEE;
|
8 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
9 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
10 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
11 |
|
|
|
12 |
|
|
entity rx_fifo is
|
13 |
|
|
generic(address_width : integer := 3);
|
14 |
|
|
port( clk, reset : in std_logic;
|
15 |
|
|
|
16 |
|
|
read_rx_data : in std_logic;
|
17 |
|
|
rx_data : out std_logic_vector(7 downto 0);
|
18 |
|
|
rx_fifo_full : out std_logic;
|
19 |
|
|
rx_fifo_empty : out std_logic;
|
20 |
|
|
rx_fifo_entries_free : out std_logic_vector(7 downto 0);
|
21 |
|
|
|
22 |
|
|
rx_func_data : in std_logic_vector(7 downto 0);
|
23 |
|
|
rx_func_data_ready : in std_logic);
|
24 |
|
|
end entity rx_fifo;
|
25 |
|
|
|
26 |
|
|
architecture behaviour of rx_fifo is
|
27 |
32 |
TobiasJ |
type ram_type is array (0 to 2**address_width-1) of std_logic_vector(7 downto 0);
|
28 |
|
|
signal ram : ram_type;
|
29 |
|
|
signal ram_we : std_logic;
|
30 |
|
|
signal ram_address : std_logic_vector(address_width-1 downto 0);
|
31 |
|
|
signal rx_in_addr_d, rx_out_addr_d : std_logic_vector(address_width-1 downto 0);
|
32 |
|
|
signal rx_in_addr_q, rx_out_addr_q : std_logic_vector(address_width-1 downto 0) := (others => '0');
|
33 |
22 |
TobiasJ |
|
34 |
32 |
TobiasJ |
signal rx_fifo_full_i, rx_fifo_empty_i : std_logic;
|
35 |
|
|
|
36 |
|
|
constant max_fifo_entries : std_logic_vector(address_width downto 0) := conv_std_logic_vector(2**address_width, address_width+1);
|
37 |
|
|
signal fifo_entries_back_q, fifo_entries_back_d : std_logic_vector(address_width downto 0);
|
38 |
|
|
signal data_ready_q, data_ready_d : std_logic;
|
39 |
|
|
|
40 |
22 |
TobiasJ |
begin
|
41 |
32 |
TobiasJ |
-------------------------
|
42 |
|
|
-- Combinational Logic --
|
43 |
|
|
-------------------------
|
44 |
|
|
ram_we <= '1' when read_rx_data = '0' and rx_fifo_full_i = '0' and data_ready_q = '1' else
|
45 |
|
|
'0';
|
46 |
|
|
data_ready_d <= not (reset or ram_we);
|
47 |
|
|
--'0' when reset = '1' or ram_we = '1' else
|
48 |
|
|
--'1';-- when rx_func_data_ready = '1' else --taken care of by register enable
|
49 |
|
|
--'0' when ram_we = '1' else
|
50 |
|
|
--data_ready_q;
|
51 |
|
|
ram_address <= rx_in_addr_q when ram_we = '1' else
|
52 |
|
|
rx_out_addr_q;
|
53 |
|
|
rx_in_addr_d <= (others => '0') when reset = '1' else
|
54 |
|
|
rx_in_addr_q + 1;-- when ram_we = '1' else --taken care of by register enable
|
55 |
|
|
--rx_in_addr_q;
|
56 |
|
|
rx_out_addr_d <= (others => '0') when reset = '1' else --taken care of by register enable
|
57 |
|
|
rx_out_addr_q + 1;-- when rx_read = '1' else
|
58 |
|
|
--rx_out_addr_q;
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
rx_fifo_entries_free <= conv_std_logic_vector(0, 7 - address_width) & fifo_entries_back_q;
|
63 |
|
|
fifo_entries_back_d <= max_fifo_entries when reset = '1' else
|
64 |
|
|
fifo_entries_back_q + 1 when read_rx_data = '1' else
|
65 |
|
|
fifo_entries_back_q - 1 when ram_we = '1' else --taken care of by register enable
|
66 |
|
|
fifo_entries_back_q;
|
67 |
|
|
|
68 |
|
|
rx_fifo_full <= rx_fifo_full_i;
|
69 |
|
|
rx_fifo_full_i <= '1' when fifo_entries_back_q = conv_std_logic_vector(0, address_width+1) else
|
70 |
|
|
'0';
|
71 |
|
|
|
72 |
|
|
rx_fifo_empty <= rx_fifo_empty_i;
|
73 |
|
|
rx_fifo_empty_i <= '1' when fifo_entries_back_q = max_fifo_entries else
|
74 |
|
|
'0';
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
--------------------
|
78 |
|
|
-- Register Logic --
|
79 |
|
|
--------------------
|
80 |
|
|
reg_control : process(clk)
|
81 |
22 |
TobiasJ |
begin
|
82 |
|
|
if rising_edge(clk) then
|
83 |
32 |
TobiasJ |
--if reset = '1' or read_rx_data = '1' or ram_we = '1' then
|
84 |
|
|
fifo_entries_back_q <= fifo_entries_back_d;
|
85 |
|
|
--end if;
|
86 |
|
|
if reset = '1' or ram_we = '1' or rx_func_data_ready = '1' then
|
87 |
|
|
data_ready_q <= data_ready_d;
|
88 |
22 |
TobiasJ |
end if;
|
89 |
32 |
TobiasJ |
if reset = '1' or ram_we = '1' then
|
90 |
|
|
rx_in_addr_q <= rx_in_addr_d;
|
91 |
|
|
end if;
|
92 |
|
|
if reset = '1' or read_rx_data = '1' then
|
93 |
|
|
rx_out_addr_q <= rx_out_addr_d;
|
94 |
|
|
end if;
|
95 |
22 |
TobiasJ |
end if;
|
96 |
32 |
TobiasJ |
end process;
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
-----------------------------------
|
100 |
|
|
-- RAM synchronous - single port --
|
101 |
|
|
-----------------------------------
|
102 |
|
|
ram_control : process(clk, ram_we, ram_address, rx_func_data)
|
103 |
|
|
begin
|
104 |
|
|
if rising_edge(clk) then
|
105 |
|
|
if ram_we = '1' then
|
106 |
|
|
ram(conv_integer(ram_address)) <= rx_func_data;
|
107 |
|
|
end if;
|
108 |
|
|
end if;
|
109 |
|
|
end process ram_control;
|
110 |
|
|
rx_data <= ram(conv_integer(ram_address));
|
111 |
|
|
|
112 |
|
|
end architecture behaviour;
|