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

Subversion Repositories lattice6502

[/] [lattice6502/] [ispLeaver/] [UART_RX.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 stanley82
------------------------------------------------------------------
2
--      6502 support module.
3
--
4
--      Copyright Ian Chapman October 28 2010
5
--
6
--      This file is part of the Lattice 6502 project
7
--      It is used to compile with Linux ghdl and ispLeaver.
8
--      The baude rate is 9600.
9
--
10
--      To do
11
--              Nothing.
12
--
13
--      *************************************************************
14
--      Distributed under the GNU Lesser General Public License.    *
15
--      This can be obtained from “www.gnu.org”.                    *
16
--      *************************************************************
17
--      This program is free software: you can redistribute it and/or modify
18
--      it under the terms of the GNU General Public License as published by
19
--      the Free Software Foundation, either version 3 of the License, or
20
--      (at your option) any later version.
21
--
22
--      This program is distributed in the hope that it will be useful,
23
--      but WITHOUT ANY WARRANTY; without even the implied warranty of
24
--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
--      GNU General Public License for more details.
26
--
27
--      You should have received a copy of the GNU General Public License
28
--      along with this program.  If not, see <http://www.gnu.org/licenses/>
29
--
30
--      UART_RX.vhd
31
--      *************************************************************
32
--
33
library IEEE;
34
--Library UNISIM;
35
--library WORK;
36
 
37
use IEEE.std_logic_1164.all;
38
use IEEE.numeric_std.all;                       --Needed for GHDL
39
--use UNISIM.vcomponents.all;
40
--use WORK.ALFT_GLOBAL_lib.all;
41
 
42
 
43
--      RX baude rate generator.  Zero sync to transitions on RX
44
entity UART_RX is
45
port(
46
        RX, OSC_10MHz, csr_usart :in std_logic;
47
        PG : in std_logic;                      --Power Good.
48
        RX_rdy : out std_logic;
49
        rx_reg : out unsigned(7 downto 0)
50
        );
51
end UART_RX;
52
 
53
Architecture behavioral of UART_RX is
54
 
55
--constant define_rx_baude_rate : unsigned (5 downto 0) := "101011";  --115.2 Kbps
56
constant define_rx_baude_rate : unsigned (10 downto 0) := "10000010010"; --9.6 Kbps
57
constant define_rx_mid_strob : unsigned (10 downto 0)  := "01000001001";
58
constant define_rx_bits : unsigned (3 downto 0) := x"A"; --start+8+stop
59
signal rx_start_pul, br_start_pul, RX_BR_clk : std_logic;
60
signal RX_sr : std_logic_vector (1 downto 0);
61
signal rx_clk_int : unsigned (3 downto 0);
62
signal rx_br_ctr_int   : unsigned (10 downto 0);
63
signal br_strob, br_mid_strob, end_ff : std_logic;
64
 
65
--      =============================================================
66
--      Synchronize BR counter to RX data transitions.
67
 
68
begin
69
Start_up:process (OSC_10MHz, PG,  RX)
70
begin
71
if PG = '0' then
72
        rx_start_pul <= '0';
73
elsif falling_edge (OSC_10MHz) then
74
        RX_sr <= RX_sr(0) & RX;
75
        if RX_sr = "10" and RX = '0' and rx_clk_int = define_rx_bits then
76
                rx_start_pul <= '1';            --Used to sync the BR clock
77
        else
78
                rx_start_pul <= '0';
79
        end if;
80
end if;
81
end process;
82
--====================================
83
--      The receive counter sits at end of count until transition
84
--      on the RX data in line then it is set to zero
85
Init_BR:process (rx_start_pul, rx_clk_int)
86
begin
87
if rx_clk_int = define_rx_bits then
88
        br_start_pul <= rx_start_pul;   --rx_start_pul is the transition
89
else
90
        br_start_pul <= '0';             --Used to start the Receive counter
91
end if;
92
end process;
93
--      =================================================
94
 
95
--      This divides the 10MHz down to the baud rate
96
--      The baude rate clock the receive counter
97
--      that counts the RX data bits into a register.
98
 
99
RX_BR_counter:process (OSC_10MHz, PG, rx_start_pul, rx_br_ctr_int, rx_clk_int, br_start_pul)
100
begin
101
if PG = '0' then
102
        rx_br_ctr_int <= define_rx_baude_rate;
103
        br_strob <= '0';
104
        br_mid_strob <= '0';
105
elsif rising_edge (OSC_10MHz) then
106
        if rx_start_pul = '1' or rx_br_ctr_int = define_rx_baude_rate then
107
                rx_br_ctr_int <= (others => '0');
108
        else
109
                rx_br_ctr_int <= rx_br_ctr_int + "1";           -- + 1;
110
        end if;
111
        if rx_br_ctr_int = define_rx_baude_rate then
112
                br_strob <= '1';
113
        else
114
                br_strob <= '0';
115
        end if;
116
        if rx_br_ctr_int = define_rx_mid_strob then
117
                br_mid_strob <= '1';
118
        else
119
                br_mid_strob <= '0';
120
        end if;
121
end if;
122
end process;
123
 
124
-- =================================================
125
 
126
--      This flip flop clocks the counter and Rx data
127
 
128
RX_clock:process (OSC_10MHz, br_strob, br_start_pul, rx_clk_int, rx_br_ctr_int)
129
begin
130
if br_start_pul = '1' then
131
        RX_BR_clk <= '0';
132
elsif falling_edge (OSC_10MHz) then
133
        if br_strob = '1' then
134
                RX_BR_clk <= not RX_BR_clk;
135
        end if;
136
end if;
137
end process;
138
--      ====================================================
139
 
140
--      This process counts the bits starting with the start bit
141
 
142
receive_ctr:process(OSC_10MHz, br_strob, br_start_pul, RX_BR_clk, RX,rx_clk_int)
143
begin
144
if PG = '0' then
145
        rx_clk_int <= define_rx_bits;
146
elsif rising_edge (OSC_10MHz) then
147
        if (rx_clk_int /= define_rx_bits and br_strob = '1') then
148
                rx_clk_int <= rx_clk_int + X"1";
149
        elsif br_start_pul = '1' then
150
                rx_clk_int <= (others => '0');
151
        end if;
152
end if;
153
end process;
154
 
155
Receiver:process (OSC_10MHz, RX, RX_BR_clk, rx_clk_int)
156
begin
157
if PG = '0' then
158
        rx_reg <= (others => '0');
159
 
160
elsif rising_edge (OSC_10MHz) then
161
        if br_mid_strob = '1' then
162
                case rx_clk_int is
163
                        when X"1" =>
164
                                rx_reg(0) <= RX;
165
                        when X"2" =>
166
                                rx_reg(1) <= RX;
167
                        when X"3" =>
168
                                rx_reg(2) <= RX;
169
                        when X"4" =>
170
                                rx_reg(3) <= RX;
171
                        when X"5" =>
172
                                rx_reg(4) <= RX;
173
                        when X"6" =>
174
                                rx_reg(5) <= RX;
175
                        when X"7" =>
176
                                rx_reg(6) <= RX;
177
                        when X"8" =>
178
                                rx_reg(7) <= RX;
179
                        when others =>
180
                                null;
181
        end case;
182
        end if;
183
end if;
184
end process;
185
 
186
Set_rdy :process (OSC_10MHz, rx_start_pul, rx_clk_int)
187
begin
188
if PG = '0' then
189
        RX_rdy <= '0';
190
        end_ff <= '0';
191
elsif rising_edge (OSC_10MHz) then
192
        if rx_clk_int = 9 then
193
                end_ff <= '1';
194
        end if;
195
        if rx_clk_int = 9 and end_ff ='0' then
196
                RX_rdy <= '1';
197
        elsif csr_usart = '1' then
198
                RX_rdy <= '0';
199
        elsif rx_start_pul = '1'then
200
                end_ff <= '0';
201
        end if;
202
end if;
203
end process;
204
 
205
end behavioral;
206
 

powered by: WebSVN 2.1.0

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