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

Subversion Repositories uart_plb

[/] [uart_plb/] [trunk/] [pcores/] [uart_plb_v1_00_a/] [hdl/] [vhdl/] [uart.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 gavinux
-- $Id$
2
library IEEE;
3
use IEEE.STD_LOGIC_1164.ALL;
4
use IEEE.STD_LOGIC_ARITH.ALL;
5
use IEEE.STD_LOGIC_UNSIGNED.ALL;
6
use work.uart_components.ALL;
7
---- Uncomment the following library declaration if instantiating
8
---- any Xilinx primitives in this code.
9
--library UNISIM;
10
--use UNISIM.VComponents.all;
11
 
12
entity uart is
13
    generic (DATA_BITS        : integer);
14
    Port (
15
        rst                   : in  std_logic;
16
        clk                   : in  std_logic;
17
        dlw                   : in  std_logic_vector(15 downto 0);
18
        --
19
        tx_wr                 : in  std_logic;   -- pulse signal
20
        tx_fifo_reset         : in  std_logic;   -- pulse signal
21
        tx_din                : in  std_logic_vector(DATA_BITS-1 downto 0);
22
        tx_fifo_full          : out std_logic;   -- level signal
23
        tx_fifo_almost_full   : out std_logic;   -- level signal
24
        tx_fifo_empty         : out std_logic;   -- level signal
25
        tx_fifo_almost_empty  : out std_logic;   -- level signal
26
        tx_xmt_empty          : out std_logic;   -- level signal, transmit shift register empty
27
        --
28
        rx_rd                 : in  std_logic;   -- pulse signal
29
        rx_fifo_reset         : in  std_logic;   -- pulse signal
30
        rx_dout               : out std_logic_vector(DATA_BITS-1 downto 0);
31
        rx_fifo_full          : out std_logic;   -- level signal
32
        rx_fifo_almost_full   : out std_logic;   -- level signal
33
        rx_fifo_empty         : out std_logic;   -- level signal
34
        rx_fifo_almost_empty  : out std_logic;   -- level signal
35
        rx_timeout            : out std_logic;   -- pulse signal
36
        --
37
        tx_sout               : out std_logic;
38
        rx_sin                : in  std_logic
39
     );
40
end uart;
41
 
42
architecture rtl of uart is
43
 
44
-------- BaudRate -----------
45
signal tick_s : std_logic;
46
-------- TXD ----------------
47
type   tx_state_type is (stTxIDLE, stTxDoWRITE, stTxDoREAD, stTxDONE);
48
signal ctxstate, ntxstate : tx_state_type;
49
signal xmt_done_s         : std_logic;
50
signal xmt_wr_s           : std_logic;
51
signal tx_fifo_rd_s       : std_logic;
52
signal tx_fifo_empty_s    : std_logic;
53
signal tx_fifo_dout_s     : std_logic_vector(DATA_BITS-1 downto 0);
54
-------- RXD ----------------
55
signal rcv_done_s         : std_logic := '0';
56
signal rcv_dout_s         : std_logic_vector(DATA_BITS-1 downto 0) := (others=>'0');
57
 
58
signal tx_fifo_reset_s    : std_logic;
59
signal rx_fifo_reset_s    : std_logic;
60
 
61
begin
62
 
63
-------- BaudRate -----------
64
baud_gen : baudrate
65
    port map (
66
        clk          => clk,
67
        rst          => rst,
68
        dlw          => dlw,
69
        tick         => tick_s
70
    );
71
 
72
------------ TXD -------------------
73
tx : xmt
74
    generic map (DATA_BITS => DATA_BITS)
75
    port map (
76
        clk          => clk,
77
        rst          => rst,
78
        tick         => tick_s,
79
        wr           => xmt_wr_s,
80
        din          => tx_fifo_dout_s,
81
        sout         => tx_sout,
82
        done         => xmt_done_s
83
    );
84
 
85
    tx_fifo_reset_s <= tx_fifo_reset or rst;
86
 
87
tx_fifo_8x16 : fifo_generator_v8_1_8x16
88
    PORT MAP (
89
        clk          => clk,
90
        srst         => tx_fifo_reset_s,
91
        din          => tx_din,
92
        wr_en        => tx_wr,
93
        rd_en        => tx_fifo_rd_s,
94
        dout         => tx_fifo_dout_s,
95
        full         => tx_fifo_full,
96
        almost_full  => tx_fifo_almost_full,
97
        empty        => tx_fifo_empty_s,
98
        almost_empty => tx_fifo_almost_empty
99
    );
100
 
101
    tx_xmt_empty  <= xmt_done_s;
102
    tx_fifo_empty <= tx_fifo_empty_s;
103
 
104
    process(clk)
105
    begin
106
        if rising_edge(clk) then
107
            if rst = '1' then
108
                ctxstate <= stTxIDLE;
109
            else
110
                ctxstate <= ntxstate;
111
            end if;
112
        end if;
113
    end process;
114
 
115
    process(xmt_done_s, tx_fifo_empty_s, ctxstate)
116
    begin
117
        ntxstate <= ctxstate;
118
        case ctxstate is
119
            when stTxIDLE    =>
120
                if (xmt_done_s = '1' and tx_fifo_empty_s = '0') then
121
                    ntxstate <= stTxDoWRITE;
122
                end if;
123
            when stTxDoWRITE => ntxstate <= stTxDoREAD;
124
            when stTxDoREAD  => ntxstate <= stTxDONE;
125
            when stTxDONE    => ntxstate <= stTxIDLE;
126
        end case;
127
    end process;
128
 
129
    process(ctxstate)
130
    begin
131
        xmt_wr_s <= '0';
132
        tx_fifo_rd_s <= '0';
133
        case ctxstate is
134
            when stTxDoWRITE => xmt_wr_s <= '1';
135
            when stTxDoREAD  => tx_fifo_rd_s <= '1';
136
            when others      => null;
137
        end case;
138
    end process;
139
 
140
 
141
------------ RXD -------------------
142
 
143
timeout : tmo
144
    Port map (
145
        clk          => clk,
146
        clr          => rcv_done_s,
147
        tick         => tick_s,
148
        timeout      => rx_timeout
149
    );
150
 
151
rx : rcv
152
    generic map (DATA_BITS => DATA_BITS)
153
    port map (
154
        clk          => clk,
155
        rst          => rst,
156
        tick         => tick_s,
157
        sin          => rx_sin,
158
        dout         => rcv_dout_s,
159
        done         => rcv_done_s
160
    );
161
 
162
    rx_fifo_reset_s <= rx_fifo_reset or rst;
163
 
164
rx_fifo_8x16 : fifo_generator_v8_1_8x16
165
    PORT MAP (
166
        clk          => clk,
167
        srst         => rx_fifo_reset_s,
168
        din          => rcv_dout_s,
169
        wr_en        => rcv_done_s,
170
        rd_en        => rx_rd,
171
        dout         => rx_dout,
172
        full         => rx_fifo_full,
173
        almost_full  => rx_fifo_almost_full,
174
        empty        => rx_fifo_empty,
175
        almost_empty => rx_fifo_almost_empty
176
    );
177
 
178
end rtl;

powered by: WebSVN 2.1.0

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