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

Subversion Repositories cpu_lecture

[/] [cpu_lecture/] [trunk/] [src/] [uart.vhd] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jsauermann
-------------------------------------------------------------------------------
2
-- 
3
-- Copyright (C) 2009, 2010 Dr. Juergen Sauermann
4
-- 
5
--  This code is free software: you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation, either version 3 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This code is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this code (see the file named COPYING).
17
--  If not, see http://www.gnu.org/licenses/.
18
--
19
-------------------------------------------------------------------------------
20
-------------------------------------------------------------------------------
21
--
22
-- Module Name:    uart_baudgen - Behavioral 
23
-- Create Date:    14:34:27 11/07/2009 
24
-- Description:    a UART and a fixed baud rate generator.
25
--
26
-------------------------------------------------------------------------------
27
--
28
library IEEE;
29
use IEEE.STD_LOGIC_1164.ALL;
30
use IEEE.STD_LOGIC_ARITH.ALL;
31
use IEEE.STD_LOGIC_UNSIGNED.ALL;
32
 
33
entity uart is
34
    generic(CLOCK_FREQ  : std_logic_vector(31 downto 0);
35
            BAUD_RATE   : std_logic_vector(27 downto 0));
36
    port(   I_CLK     : in  std_logic;
37
            I_CLR     : in  std_logic;
38
 
39
            I_RD        : in  std_logic;
40
            I_WE        : in  std_logic;
41
 
42
            I_TX_DATA   : in  std_logic_vector(7 downto 0);
43
            I_RX        : in  std_logic;
44
 
45
            Q_TX        : out std_logic;
46
            Q_RX_DATA   : out std_logic_vector(7 downto 0);
47
            Q_RX_READY  : out std_logic;
48
            Q_TX_BUSY   : out std_logic);
49
end uart;
50
 
51
architecture Behavioral of uart is
52
 
53
component baudgen
54
    generic(CLOCK_FREQ  : std_logic_vector(31 downto 0);
55
            BAUD_RATE   : std_logic_vector(27 downto 0));
56
    port(   I_CLK       : in  std_logic;
57
 
58
            I_CLR       : in  std_logic;
59
 
60
            Q_CE_1      : out std_logic;
61
            Q_CE_16     : out std_logic);
62
end component;
63
 
64
signal B_CE_1           : std_logic;
65
signal B_CE_16          : std_logic;
66
 
67
component uart_rx
68
    port(   I_CLK       : in  std_logic;
69
            I_CLR       : in  std_logic;
70
            I_CE_16     : in  std_logic;
71
            I_RX        : in  std_logic;
72
 
73
            Q_DATA      : out std_logic_vector(7 downto 0);
74
            Q_FLAG      : out std_logic);
75
end component;
76
 
77
signal R_RX_FLAG        : std_logic;
78
 
79
component uart_tx
80
    port(   I_CLK       : in  std_logic;
81
            I_CLR       : in  std_logic;
82
            I_CE_1      : in  std_logic;
83
            I_DATA      : in  std_logic_vector(7 downto 0);
84
            I_FLAG      : in  std_logic;
85
 
86
            Q_TX        : out std_logic;
87
            Q_FLAG      : out std_logic);
88
end component;
89
 
90
signal L_RX_OLD_FLAG    : std_logic;
91
signal L_TX_FLAG        : std_logic;
92
signal L_TX_FLAGQ       : std_logic;
93
signal L_TX_DATA        : std_logic_vector(7 downto 0);
94
signal L_RX_READY       : std_logic;
95
 
96
begin
97
 
98
    Q_RX_READY <= L_RX_READY;
99
    Q_TX_BUSY  <= L_TX_FLAG xor L_TX_FLAGQ;
100
 
101
    baud: baudgen
102
    generic map(CLOCK_FREQ  => CLOCK_FREQ,
103
                BAUD_RATE   => BAUD_RATE)
104
    port map(   I_CLK       => I_CLK,
105
 
106
                I_CLR       => I_CLR,
107
                Q_CE_1      => B_CE_1,
108
                Q_CE_16     => B_CE_16);
109
 
110
    rx: uart_rx
111
    port map(   I_CLK   => I_CLK,
112
                I_CLR   => I_CLR,
113
                I_CE_16 => B_CE_16,
114
                I_RX    => I_RX,
115
 
116
                Q_DATA  => Q_RX_DATA,
117
                Q_FLAG  => R_RX_FLAG);
118
 
119
    tx: uart_tx
120
    port map(   I_CLK   => I_CLK,
121
                I_CLR   => I_CLR,
122
                I_CE_1  => B_CE_1,
123
                I_DATA  => L_TX_DATA,
124
                I_FLAG  => L_TX_FLAG,
125
 
126
                Q_TX    => Q_TX,
127
                Q_FLAG  => L_TX_FLAGQ);
128
 
129
    process(I_CLK)
130
    begin
131
        if (rising_edge(I_CLK)) then
132
            if (I_CLR = '1') then
133
                L_TX_FLAG <= '0';
134
                L_TX_DATA <= X"33";
135
            else
136
                if (I_RD = '1') then          -- read Rx data
137
                    L_RX_READY    <= '0';
138
                end if;
139
 
140
                if (I_WE = '1') then          -- write Tx data
141
                    L_TX_FLAG  <= not L_TX_FLAG;
142
                    L_TX_DATA <= I_TX_DATA;
143
                end if;
144
 
145
                if (R_RX_FLAG /= L_RX_OLD_FLAG) then
146
                    L_RX_READY <= '1';
147
                end if;
148
 
149
                L_RX_OLD_FLAG <= R_RX_FLAG;
150
            end if;
151
        end if;
152
    end process;
153
 
154
end Behavioral;
155
 

powered by: WebSVN 2.1.0

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