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 38

Go to most recent revision | 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
        signal tx_entries_back_q : std_logic_vector(address_width downto 0) := max_fifo_entries ;
28
        signal tx_in_addr_d, tx_out_addr_d : std_logic_vector(address_width-1 downto 0);
29
        signal tx_in_addr_q, tx_out_addr_q : std_logic_vector(address_width-1 downto 0) := (others => '0');
30 7 TobiasJ
 
31 16 TobiasJ
        signal ram_we : std_logic;
32
        signal ram_address : std_logic_vector(address_width-1 downto 0) := (others => '0');
33
        signal tx_fifo_empty_i : std_logic := '1';
34
        signal tx_fifo_full_i : std_logic := '0';
35
 
36
        signal tx_func_apply_data_i : std_logic;
37
 
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
 
57
        tx_in_addr_d                    <=      (others => '0')          when reset = '1' else
58
                                                                tx_in_addr_q + 1;--     when ram_we = '1' else  --taken care of by the register enable
59
                                                                --tx_in_addr_q;
60
        tx_out_addr_d                   <=      (others => '0')  when reset = '1' else
61
                                                                tx_out_addr_q + 1;--    when tx_func_apply_data_i = '1' else
62
                                                                --tx_out_addr_q;
63
 
64
        tx_func_apply_data              <=      tx_func_apply_data_i;
65
        tx_func_apply_data_i    <=      not(ram_we or tx_func_sending or tx_fifo_empty_i);
66
--      tx_func_apply_data_i    <=      '1' when ram_we = '0' and tx_func_sending = '0' and tx_fifo_empty_i = '0' else
67
--                                                              '0';
68
 
69
        tx_fifo_empty                   <=      tx_fifo_empty_i;
70
        tx_fifo_empty_i                 <=      '0' when tx_entries_back_q /= max_fifo_entries else
71
                                                                '1';
72
        tx_fifo_full                    <=      tx_fifo_full_i;
73 30 TobiasJ
        tx_fifo_full_i                  <=      '0' when tx_entries_back_q /= conv_std_logic_vector(0, address_width+1) else
74 16 TobiasJ
                                                                '1';
75
 
76
        tx_fifo_entries_free    <=      conv_std_logic_vector(0,7-address_width) & tx_entries_back_q;
77
        tx_entries_back_d               <=      max_fifo_entries                when reset = '1' else
78
                                                                tx_entries_back_q - 1   when ram_we = '1' else
79
                                                                tx_entries_back_q + 1;--        when tx_func_apply_data_i = '1' else
80
                                                                --tx_entries_back_q;
81
 
82
--------------------
83
-- Register Logic --
84
--------------------
85
        reg_control : process(clk, reset, ram_we, tx_func_apply_data_i, tx_data)
86 7 TobiasJ
        begin
87 30 TobiasJ
                if rising_edge(clk) then
88 16 TobiasJ
                        if reset = '1' or ram_we = '1' or tx_func_apply_data_i = '1' then
89
                                tx_entries_back_q       <= tx_entries_back_d;
90
                        end if;
91
 
92
                        if reset = '1' or tx_func_apply_data_i = '1' then
93
                                tx_out_addr_q           <= tx_out_addr_d;
94
                        end if;
95
 
96
                        if reset = '1' or ram_we = '1' then
97
                                tx_in_addr_q            <= tx_in_addr_d;
98
                        end if;
99 7 TobiasJ
                end if;
100 16 TobiasJ
        end process reg_control;
101
 
102
-----------------------------------
103
-- RAM synchronous - single port --
104
-----------------------------------
105 30 TobiasJ
        ram_control : process(clk, ram_we, ram_address, tx_data)
106 16 TobiasJ
        begin
107
                if rising_edge(clk) then
108
                        if ram_we = '1' then
109 30 TobiasJ
                                ram(conv_integer(ram_address)) <= tx_data;
110 16 TobiasJ
                        end if;
111
                end if;
112
        end process ram_control;
113
        tx_func_data <= ram(conv_integer(ram_address));
114
 
115 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.