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

Subversion Repositories lattice6502

[/] [lattice6502/] [ispLeaver/] [UART_TX.vhd] - Blame information for rev 3

Go to most recent revision | 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_TX.vhd
31
--      *************************************************************
32
--
33
library IEEE;
34
 
35
use IEEE.std_logic_1164.all;
36
use IEEE.numeric_std.all;                       --Needed for GHDL
37
 
38
--      RX baude rate generator.  Zero sync to transitions on RX
39
entity UART_TX is
40
port(
41
        OSC_10MHz, PG, csw_usart :in std_logic;
42
        tx_dat : in unsigned(7 downto 0);
43
        TX, tx_rdy : out std_logic
44
        );
45
end UART_TX;
46
 
47
Architecture behavioral of UART_TX is
48
 
49
--constant define_tx_baude_rate : unsigned (6 downto 0) := "1010111"; --115.2 Kbps
50
constant define_tx_baude_rate : unsigned (10 downto 0) := "10000010010"; --9.6 Kbps
51
constant define_tx_bits : unsigned (3 downto 0) := x"B"; --start+8+stop+extra
52
 
53
signal tx_clk_int : unsigned (3 downto 0);
54
--      signal tx_clk : unsigned (3 downto 0);
55
signal br_ctr_tx_int : unsigned (10 downto 0);
56
signal br_strob : std_logic;
57
signal reg_tx_dat : unsigned (7 downto 0);
58
 
59
begin
60
 
61
--      =================================================
62
--      Load data to be transmitted
63
ld_tx : process (osc_10MHz, csw_usart, PG)
64
begin
65
if PG = '0' then
66
        reg_tx_dat <= (others => '0');
67
elsif rising_edge(osc_10MHz)then
68
        if csw_usart = '1' then
69
                reg_tx_dat <= tx_dat;
70
        end if;
71
end if;
72
end process;
73
--      =================================================
74
--      TX baude rate generator
75
TX_brg:process (OSC_10MHz, csw_usart, br_ctr_tx_int)
76
begin
77
if PG = '0' then
78
                br_ctr_tx_int <= (others => '0');
79
                br_strob <= '0';
80
elsif rising_edge (OSC_10MHz) then
81
          if br_ctr_tx_int = define_tx_baude_rate or csw_usart = '1' then
82
                br_ctr_tx_int <= (others => '0');
83
         else
84
                br_ctr_tx_int <= br_ctr_tx_int + 1;
85
         end if;
86
 
87
        if br_ctr_tx_int = define_tx_baude_rate then
88
                br_strob <= '1';
89
        else
90
                br_strob <= '0';
91
        end if;
92
end if;
93
end process;
94
 
95
-- =================================================
96
--      TX process gen clk for uart tx
97
transmit_ctr:process(osc_10MHz, csw_usart, br_strob, tx_clk_int, reg_tx_dat)
98
begin
99
 
100
if PG = '0' then
101
        tx_clk_int <= define_tx_bits;
102
        TX <= '1';
103
elsif rising_edge (osc_10MHz) then
104
        if csw_usart = '1' then
105
                tx_clk_int <= (others => '0');
106
        elsif tx_clk_int /= define_tx_bits and br_strob = '1' then
107
                tx_clk_int <= tx_clk_int + 1;
108
        end if;
109
end if;
110
--------------------------------------
111
case tx_clk_int is
112
--              Start bit
113
                when X"0" =>
114
                        TX <= '0';
115
                        tx_rdy <= '1';
116
                when X"1" =>
117
                        TX <= reg_tx_dat(0);
118
                when X"2" =>
119
                        TX <= reg_tx_dat(1);
120
                when X"3" =>
121
                        TX <= reg_tx_dat(2);
122
                when X"4" =>
123
                        TX <= reg_tx_dat(3);
124
                when X"5" =>
125
                        TX <= reg_tx_dat(4);
126
                when X"6" =>
127
                        TX <= reg_tx_dat(5);
128
                when X"7" =>
129
                        TX <= reg_tx_dat(6);
130
                when X"8" =>
131
                        TX <= reg_tx_dat(7);
132
--              Stop bit
133
                when X"9" =>
134
                        TX <= '1';
135
 
136
                when X"A" =>
137
                        TX <= '1';
138
--                      tx_rdy <= '0';
139
                when X"b" =>
140
                        TX <= '1';
141
                        tx_rdy <= '0';
142
--              when X"c" =>
143
--                      TX <= '1';
144
--                      tx_rdy <= '0';
145
--              when X"d" =>
146
--                      TX <= '1';
147
--                      tx_rdy <= '0';
148
                when others =>
149
                        TX <= '1';
150
                        tx_rdy <= '0';
151
        end case;
152
--end if;
153
end process;
154
 
155
end behavioral;
156
 
157
 

powered by: WebSVN 2.1.0

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