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

Subversion Repositories uart_block

[/] [uart_block/] [trunk/] [hdl/] [iseProject/] [uart_control.vhd] - Blame information for rev 9

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

Line No. Rev Author Line
1 9 leonardoar
--! uart control unit
2
library IEEE;
3
use IEEE.STD_LOGIC_1164.ALL;
4
 
5
--! Use CPU Definitions package
6
use work.pkgDefinitions.all;
7
 
8
entity uart_control is
9
    Port ( rst : in  STD_LOGIC;
10
           clk : in  STD_LOGIC;
11
                          WE    : in STD_LOGIC;
12
           reg_addr : in  STD_LOGIC_VECTOR (1 downto 0);
13
           DAT_I : in  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
14
           DAT_O : out  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
15
           tx_busy : in  STD_LOGIC;
16
           rx_ready : in  STD_LOGIC);
17
end uart_control;
18
 
19
architecture Behavioral of uart_control is
20
signal config_clk : std_logic_vector((nBitsLarge-1) downto 0);
21
signal config_baud : std_logic_vector((nBitsLarge-1) downto 0);
22
signal byte_out : std_logic_vector((nBitsLarge-1) downto 0);
23
signal byte_in : std_logic_vector((nBitsLarge-1) downto 0);
24
signal controlStates : uartControl;
25
 
26
signal sigDivRst : std_logic;
27
signal sigDivDone : std_logic;
28
signal sigDivQuotient : std_logic_vector((nBitsLarge-1) downto 0);
29
signal sigDivReminder : std_logic_vector((nBitsLarge-1) downto 0);
30
signal sigDivNumerator : std_logic_vector((nBitsLarge-1) downto 0);
31
signal sigDivDividend : std_logic_vector((nBitsLarge-1) downto 0);
32
 
33
-- Divisor component
34
component divisor is
35
    Port ( rst : in  STD_LOGIC;
36
           clk : in  STD_LOGIC;
37
           quotient : out  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
38
                          reminder : out  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
39
           numerator : in  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
40
           divident : in  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
41
           done : out  STD_LOGIC);
42
end component;
43
 
44
begin
45
        -- Instantiate block for calculate division
46
        uDiv : divisor port map (
47
                rst => sigDivRst,
48
                clk => clk,
49
                quotient => sigDivQuotient,
50
                reminder => sigDivReminder,
51
                numerator => sigDivNumerator,
52
                divident => sigDivDividend,
53
                done => sigDivDone
54
        );
55
 
56
        -- Process that populate/read the uart control registers
57
        process (rst, clk, reg_addr,WE)
58
        begin
59
                if rst = '1' then
60
                        config_clk <= (others => '0');
61
                        config_baud <= (others => '0');
62
                        byte_out <= (others => '0');
63
                        byte_in <= (others => '0');
64
                elsif rising_edge(clk) then
65
                        if WE = '1' then
66
                                case reg_addr is
67
                                        when "00" =>
68
                                                config_clk <= DAT_I;
69
                                        when "01" =>
70
                                                config_baud <= DAT_I;
71
                                        when "10" =>
72
                                                byte_out <= DAT_I((nBits-1) downto 0);
73
                                        when others =>
74
                                                null;
75
                                end case;
76
                        end if;
77
                end if;
78
        end process;
79
 
80
        -- Process to handle the next state logic
81
        process (rst, clk, reg_addr, WE)
82
        variable baud_configured : std_logic;
83
        variable clk_configured : std_logic;
84
        begin
85
                if rst = '1' then
86
                        controlStates <= idle;
87
                        baud_configured <= '0';
88
                        clk_configured <= '0';
89
                elsif rising_edge(clk) then
90
                        case controlStates is
91
                                when idle =>
92
                                        -- Go to config state
93
                                        if (reg_addr = "00") and (WE = '1') then
94
                                                controlStates <= config_state_clk;
95
                                                clk_configured <= '1';
96
                                        elsif (reg_addr = "01") and (WE = '1') then
97
                                                controlStates <= config_state_baud;
98
                                                baud_configured <= '1';
99
                                        end if;
100
 
101
                                when config_state_clk =>
102
                                        sigDivRst <= '1';
103
                                        sigDivNumerator <= config_clk;
104
                                        if baud_configured = '0' then
105
                                                -- Baud not configured yet so wait for it...
106
                                                controlStates <= idle;
107
                                        else
108
                                                -- If already configured wait for division completion...
109
                                                controlStates <= start_division;
110
                                        end if;
111
 
112
                                when config_state_baud =>
113
                                        sigDivRst <= '1';
114
                                        sigDivDividend <= config_baud;
115
                                        if clk_configured = '0' then
116
                                                -- Clock not configured yet so wait for it...
117
                                                controlStates <= idle;
118
                                        else
119
                                                -- If already configured wait for division completion...
120
                                                controlStates <= start_division;
121
                                        end if;
122
 
123
                                when start_division =>
124
                                        sigDivRst <= '0';
125
                                        controlStates <= wait_division;
126
 
127
                                when wait_division =>
128
                                        if sigDivDone = '0' then
129
                                                controlStates <= wait_division;
130
                                        else
131
                                                -- Division done, configure the Baud generator
132
                                        end if;
133
 
134
                        end case;
135
                end if;
136
        end process;
137
 
138
end Behavioral;
139
 

powered by: WebSVN 2.1.0

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