OpenCores
URL https://opencores.org/ocsvn/rs232_with_buffer_and_wb/rs232_with_buffer_and_wb/trunk

Subversion Repositories rs232_with_buffer_and_wb

[/] [rs232_with_buffer_and_wb/] [trunk/] [rtl/] [uart_tx_fifo.vhd] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 TobiasJ
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
 
6
entity tx_fifo is
7 16 TobiasJ
        generic(address_width : integer := 3);
8 7 TobiasJ
        port(   clk, reset              : in std_logic;
9
 
10
                        write_tx_data   : in std_logic;
11
                        tx_data                 : in std_logic_vector(7 downto 0);
12
                        tx_fifo_full    : out std_logic;
13
                        tx_fifo_empty   : out std_logic;
14
                        tx_fifo_entries_free : out std_logic_vector(7 downto 0);
15
 
16
                        tx_func_data            : out std_logic_vector(7 downto 0);
17
                        tx_func_apply_data      : out std_logic;
18
                        tx_func_sending         : in std_logic);
19
end entity tx_fifo;
20
 
21
architecture behaviour of tx_fifo is
22 16 TobiasJ
        type ram_type is array (0 to 2**address_width-1) of std_logic_vector(7 downto 0);
23
        signal ram : ram_type;
24
 
25
        constant max_fifo_entries : std_logic_vector(address_width downto 0) := conv_std_logic_vector(2**address_width, address_width+1);
26
        signal tx_entries_back_d : std_logic_vector(address_width downto 0);
27 51 TobiasJ
        signal tx_entries_back_q : std_logic_vector(address_width downto 0);
28 16 TobiasJ
        signal tx_in_addr_d, tx_out_addr_d : std_logic_vector(address_width-1 downto 0);
29 51 TobiasJ
        signal tx_in_addr_q, tx_out_addr_q : std_logic_vector(address_width-1 downto 0);
30
        signal tx_in_addr_en, tx_out_addr_en, tx_entries_back_en : std_logic;
31 7 TobiasJ
 
32 16 TobiasJ
        signal ram_we : std_logic;
33 51 TobiasJ
        signal ram_address : std_logic_vector(address_width-1 downto 0);
34 16 TobiasJ
        signal tx_fifo_empty_i : std_logic := '1';
35
        signal tx_fifo_full_i : std_logic := '0';
36
 
37
        signal tx_func_apply_data_i : std_logic;
38
 
39 7 TobiasJ
begin
40 16 TobiasJ
--------------------
41
-- Component used --
42
--------------------
43
 
44
 
45
-------------------------
46
-- Combinational Logic --
47
-------------------------
48
        ram_we                                  <=      write_tx_data and not tx_fifo_full_i;
49
--      ram_we                                  <=      '1' when write_tx_data = '1' and tx_fifo_full_i = '0' else
50
--                                                              '0';
51
 
52
        with ram_we select
53
        ram_address                     <=      tx_in_addr_q            when '1',
54
                                                                tx_out_addr_q           when '0',
55
                                                                tx_out_addr_q           when others;
56 51 TobiasJ
 
57
        tx_in_addr_en                   <=      reset or ram_we;
58 16 TobiasJ
        tx_in_addr_d                    <=      (others => '0')          when reset = '1' else
59
                                                                tx_in_addr_q + 1;--     when ram_we = '1' else  --taken care of by the register enable
60
                                                                --tx_in_addr_q;
61 51 TobiasJ
        tx_out_addr_en                  <=      reset or tx_func_apply_data_i;
62 16 TobiasJ
        tx_out_addr_d                   <=      (others => '0')  when reset = '1' else
63
                                                                tx_out_addr_q + 1;--    when tx_func_apply_data_i = '1' else
64
                                                                --tx_out_addr_q;
65
 
66
        tx_func_apply_data              <=      tx_func_apply_data_i;
67
        tx_func_apply_data_i    <=      not(ram_we or tx_func_sending or tx_fifo_empty_i);
68
--      tx_func_apply_data_i    <=      '1' when ram_we = '0' and tx_func_sending = '0' and tx_fifo_empty_i = '0' else
69
--                                                              '0';
70
 
71
        tx_fifo_empty                   <=      tx_fifo_empty_i;
72
        tx_fifo_empty_i                 <=      '0' when tx_entries_back_q /= max_fifo_entries else
73
                                                                '1';
74
        tx_fifo_full                    <=      tx_fifo_full_i;
75 30 TobiasJ
        tx_fifo_full_i                  <=      '0' when tx_entries_back_q /= conv_std_logic_vector(0, address_width+1) else
76 16 TobiasJ
                                                                '1';
77
 
78
        tx_fifo_entries_free    <=      conv_std_logic_vector(0,7-address_width) & tx_entries_back_q;
79 51 TobiasJ
        tx_entries_back_en              <=      reset or ram_we or tx_func_apply_data_i;
80 16 TobiasJ
        tx_entries_back_d               <=      max_fifo_entries                when reset = '1' else
81
                                                                tx_entries_back_q - 1   when ram_we = '1' else
82
                                                                tx_entries_back_q + 1;--        when tx_func_apply_data_i = '1' else
83
                                                                --tx_entries_back_q;
84
 
85
--------------------
86
-- Register Logic --
87
--------------------
88 51 TobiasJ
        reg_control : process(clk, tx_entries_back_en, tx_out_addr_en, tx_in_addr_en, tx_entries_back_d, tx_out_addr_d, tx_in_addr_d)
89 7 TobiasJ
        begin
90 30 TobiasJ
                if rising_edge(clk) then
91 51 TobiasJ
                        if tx_entries_back_en = '1' then
92 16 TobiasJ
                                tx_entries_back_q       <= tx_entries_back_d;
93
                        end if;
94
 
95 51 TobiasJ
                        if tx_out_addr_en = '1' then
96 16 TobiasJ
                                tx_out_addr_q           <= tx_out_addr_d;
97
                        end if;
98
 
99 51 TobiasJ
                        if tx_in_addr_en = '1' then
100 16 TobiasJ
                                tx_in_addr_q            <= tx_in_addr_d;
101
                        end if;
102 7 TobiasJ
                end if;
103 16 TobiasJ
        end process reg_control;
104
 
105
-----------------------------------
106
-- RAM synchronous - single port --
107
-----------------------------------
108 30 TobiasJ
        ram_control : process(clk, ram_we, ram_address, tx_data)
109 16 TobiasJ
        begin
110
                if rising_edge(clk) then
111
                        if ram_we = '1' then
112 30 TobiasJ
                                ram(conv_integer(ram_address)) <= tx_data;
113 16 TobiasJ
                        end if;
114
                end if;
115
        end process ram_control;
116
        tx_func_data <= ram(conv_integer(ram_address));
117
 
118 7 TobiasJ
end architecture behaviour;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.