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 25

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 25 jsauermann
            Q_TX_N      : out std_logic;
87
            Q_BUSY      : out std_logic);
88 2 jsauermann
end component;
89
 
90
signal L_RX_OLD_FLAG    : std_logic;
91 25 jsauermann
signal L_RX_READY       : std_logic;
92 2 jsauermann
signal L_TX_FLAG        : std_logic;
93
signal L_TX_DATA        : std_logic_vector(7 downto 0);
94
 
95
begin
96
 
97
    Q_RX_READY <= L_RX_READY;
98
 
99
    baud: baudgen
100
    generic map(CLOCK_FREQ  => CLOCK_FREQ,
101
                BAUD_RATE   => BAUD_RATE)
102
    port map(   I_CLK       => I_CLK,
103
 
104
                I_CLR       => I_CLR,
105
                Q_CE_1      => B_CE_1,
106
                Q_CE_16     => B_CE_16);
107
 
108
    rx: uart_rx
109
    port map(   I_CLK   => I_CLK,
110
                I_CLR   => I_CLR,
111
                I_CE_16 => B_CE_16,
112
                I_RX    => I_RX,
113
 
114
                Q_DATA  => Q_RX_DATA,
115
                Q_FLAG  => R_RX_FLAG);
116
 
117
    tx: uart_tx
118
    port map(   I_CLK   => I_CLK,
119
                I_CLR   => I_CLR,
120
                I_CE_1  => B_CE_1,
121
                I_DATA  => L_TX_DATA,
122
                I_FLAG  => L_TX_FLAG,
123
 
124 25 jsauermann
                Q_TX_N  => Q_TX,
125
                Q_BUSY  => Q_TX_BUSY);
126 2 jsauermann
 
127
    process(I_CLK)
128
    begin
129
        if (rising_edge(I_CLK)) then
130
            if (I_CLR = '1') then
131 25 jsauermann
                L_RX_OLD_FLAG <= R_RX_FLAG;
132
                L_RX_READY <= '0';
133 2 jsauermann
                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 25 jsauermann
                if (L_RX_OLD_FLAG /= R_RX_FLAG) then
146
                    L_RX_OLD_FLAG <= R_RX_FLAG;
147 2 jsauermann
                    L_RX_READY <= '1';
148
                end if;
149
            end if;
150
        end if;
151
    end process;
152
 
153
end Behavioral;
154
 

powered by: WebSVN 2.1.0

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