1 |
4 |
dilbert57 |
--===========================================================================--
|
2 |
|
|
--
|
3 |
|
|
-- S Y N T H E Z I A B L E miniUART C O R E
|
4 |
|
|
--
|
5 |
|
|
-- www.OpenCores.Org - January 2000
|
6 |
|
|
-- This core adheres to the GNU public license
|
7 |
|
|
--
|
8 |
|
|
-- Design units : miniUART core for the OCRP-1
|
9 |
|
|
--
|
10 |
|
|
-- File name : TxUnit.vhd
|
11 |
|
|
--
|
12 |
|
|
-- Purpose : Implements an miniUART device for communication purposes
|
13 |
|
|
-- between the OR1K processor and the Host computer through
|
14 |
|
|
-- an RS-232 communication protocol.
|
15 |
|
|
--
|
16 |
|
|
-- Library : uart_lib.vhd
|
17 |
|
|
--
|
18 |
|
|
-- Dependencies : IEEE.Std_Logic_1164
|
19 |
|
|
--
|
20 |
|
|
--===========================================================================--
|
21 |
|
|
-------------------------------------------------------------------------------
|
22 |
|
|
-- Revision list
|
23 |
|
|
-- Version Author Date Changes
|
24 |
|
|
--
|
25 |
|
|
-- 0.1 Ovidiu Lupas 15 January 2000 New model
|
26 |
|
|
-- 2.0 Ovidiu Lupas 17 April 2000 unnecessary variable removed
|
27 |
|
|
-- olupas@opencores.org
|
28 |
|
|
-------------------------------------------------------------------------------
|
29 |
|
|
-- Description :
|
30 |
|
|
-------------------------------------------------------------------------------
|
31 |
|
|
-- Entity for the Tx Unit --
|
32 |
|
|
-------------------------------------------------------------------------------
|
33 |
|
|
library ieee;
|
34 |
|
|
use ieee.std_logic_1164.all;
|
35 |
|
|
use ieee.numeric_std.all;
|
36 |
|
|
library work;
|
37 |
|
|
-- use work.Uart_Def.all;
|
38 |
|
|
-------------------------------------------------------------------------------
|
39 |
|
|
-- Transmitter unit
|
40 |
|
|
-------------------------------------------------------------------------------
|
41 |
|
|
entity TxUnit is
|
42 |
|
|
port (
|
43 |
|
|
Clk : in Std_Logic; -- Clock signal
|
44 |
|
|
Reset : in Std_Logic; -- Reset input
|
45 |
|
|
Enable : in Std_Logic; -- Enable input
|
46 |
|
|
LoadD : in Std_Logic; -- Load transmit data
|
47 |
|
|
TxD : out Std_Logic; -- RS-232 data output
|
48 |
|
|
TBE : out Std_Logic; -- Tx buffer empty
|
49 |
|
|
DataO : in Std_Logic_Vector(7 downto 0));
|
50 |
|
|
end entity; --================== End of entity ==============================--
|
51 |
|
|
-------------------------------------------------------------------------------
|
52 |
|
|
-- Architecture for TxUnit
|
53 |
|
|
-------------------------------------------------------------------------------
|
54 |
|
|
architecture Behaviour of TxUnit is
|
55 |
|
|
-----------------------------------------------------------------------------
|
56 |
|
|
-- Signals
|
57 |
|
|
-----------------------------------------------------------------------------
|
58 |
|
|
signal TBuff : Std_Logic_Vector(7 downto 0); -- transmit buffer
|
59 |
|
|
signal TReg : Std_Logic_Vector(7 downto 0); -- transmit register
|
60 |
|
|
signal BitCnt : Unsigned(3 downto 0); -- bit counter
|
61 |
|
|
signal tmpTRegE : Std_Logic; --
|
62 |
|
|
signal tmpTBufE : Std_Logic; --
|
63 |
|
|
begin
|
64 |
|
|
-----------------------------------------------------------------------------
|
65 |
|
|
-- Implements the Tx unit
|
66 |
|
|
-----------------------------------------------------------------------------
|
67 |
|
|
process(Clk,Reset,Enable,LoadD,DataO,TBuff,TReg,tmpTRegE,tmpTBufE)
|
68 |
|
|
constant CntOne : Unsigned(3 downto 0):="0001";
|
69 |
|
|
begin
|
70 |
|
|
if Clk'event and Clk = '1' then
|
71 |
|
|
if Reset = '1' then
|
72 |
|
|
tmpTRegE <= '1';
|
73 |
|
|
tmpTBufE <= '1';
|
74 |
|
|
TxD <= '1';
|
75 |
|
|
BitCnt <= "0000";
|
76 |
|
|
elsif LoadD = '1' then
|
77 |
|
|
TBuff <= DataO;
|
78 |
|
|
tmpTBufE <= '0';
|
79 |
|
|
elsif Enable = '1' then
|
80 |
|
|
if ( tmpTBufE = '0') and (tmpTRegE = '1') then
|
81 |
|
|
TReg <= TBuff;
|
82 |
|
|
tmpTRegE <= '0';
|
83 |
|
|
tmpTBufE <= '1';
|
84 |
|
|
end if;
|
85 |
|
|
|
86 |
|
|
if tmpTRegE = '0' then
|
87 |
|
|
case BitCnt is
|
88 |
|
|
when "0000" =>
|
89 |
|
|
TxD <= '0';
|
90 |
|
|
BitCnt <= BitCnt + CntOne;
|
91 |
|
|
when "0001" | "0010" | "0011" |
|
92 |
|
|
"0100" | "0101" | "0110" |
|
93 |
|
|
"0111" | "1000" =>
|
94 |
|
|
TxD <= TReg(0);
|
95 |
|
|
TReg <= '1' & TReg(7 downto 1);
|
96 |
|
|
BitCnt <= BitCnt + CntOne;
|
97 |
|
|
when "1001" =>
|
98 |
|
|
TxD <= '1'; -- 2 stop bits
|
99 |
|
|
BitCnt <= BitCnt + CntOne;
|
100 |
|
|
when "1010" =>
|
101 |
|
|
TxD <= '1';
|
102 |
|
|
BitCnt <= "0000";
|
103 |
|
|
tmpTRegE <= '1';
|
104 |
|
|
when others => null;
|
105 |
|
|
end case;
|
106 |
|
|
end if;
|
107 |
|
|
end if;
|
108 |
|
|
end if;
|
109 |
|
|
end process;
|
110 |
|
|
|
111 |
|
|
TBE <= tmpTBufE;
|
112 |
|
|
end Behaviour; --=================== End of architecture ====================--
|