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

Subversion Repositories uart

[/] [uart/] [tags/] [jan_23_2000/] [miniUART.vhd] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 olupas
--===========================================================================--
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      : miniuart.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
-- Simulator      : ModelSim PE/PLUS version 4.7b on a Windows95 PC
21
--===========================================================================--
22
-------------------------------------------------------------------------------
23
-- Revision list
24
-- Version   Author                 Date                        Changes
25
--
26
-- 0.1      Ovidiu Lupas     15 January 2000                   New model
27
--        ovilup@mail.dnttm.ro
28
-------------------------------------------------------------------------------
29
-- Description    : The memory consists of a dual-port memory addressed by
30
--                  two counters (RdCnt & WrCnt). The third counter (StatCnt)
31
--                  sets the status signals and keeps a track of the data flow.
32
-------------------------------------------------------------------------------
33
-- Entity for miniUART Unit - 9600 baudrate                                  --
34
-------------------------------------------------------------------------------
35
library ieee;
36
   use ieee.std_logic_1164.all;
37
   use ieee.numeric_std.all;
38
library work;
39
   use work.UART_Def.all;
40
 
41
entity miniUART is
42
  port (
43
     SysClk   : in  Std_Logic;  -- System Clock
44
     Reset    : in  Std_Logic;  -- Reset input
45
     CS_N     : in  Std_Logic;
46
     RD_N     : in  Std_Logic;
47
     WR_N     : in  Std_Logic;
48
     RxD      : in  Std_Logic;
49
     TxD      : out Std_Logic;
50
     IntRx_N  : out Std_Logic;  -- Receive interrupt
51
     IntTx_N  : out Std_Logic;  -- Transmit interrupt
52
     Addr     : in  Std_Logic_Vector(1 downto 0); -- 
53
     DataIn   : in  Std_Logic_Vector(7 downto 0); -- 
54
     DataOut  : out Std_Logic_Vector(7 downto 0)); -- 
55
end entity; --================== End of entity ==============================--
56
-------------------------------------------------------------------------------
57
-- Architecture for miniUART Controller Unit
58
-------------------------------------------------------------------------------
59
architecture uart of miniUART is
60
  -----------------------------------------------------------------------------
61
  -- Signals
62
  -----------------------------------------------------------------------------
63
  signal RxData : Std_Logic_Vector(7 downto 0); -- 
64
  signal TxData : Std_Logic_Vector(7 downto 0); -- 
65
  signal CSReg  : Std_Logic_Vector(7 downto 0); -- Ctrl & status register
66
  --             CSReg detailed 
67
  -----------+--------+--------+--------+--------+--------+--------+--------+
68
  -- CSReg(7)|CSReg(6)|CSReg(5)|CSReg(4)|CSReg(3)|CSReg(2)|CSReg(1)|CSReg(0)|
69
  --   Res   |  Res   |  Res   |  Res   | UndRun | OvrRun |  FErr  |  OErr  |
70
  -----------+--------+--------+--------+--------+--------+--------+--------+
71
  signal EnabRx : Std_Logic;  -- Enable RX unit
72
  signal EnabTx : Std_Logic;  -- Enable TX unit
73
  signal DRdy   : Std_Logic;  -- Receive Data ready
74
  signal TRegE  : Std_Logic;  -- Transmit register empty
75
  signal TBufE  : Std_Logic;  -- Transmit buffer empty
76
  signal FErr   : Std_Logic;  -- Frame error
77
  signal OErr   : Std_Logic;  -- Output error
78
  signal Read   : Std_Logic;  -- Read receive buffer
79
  signal Load   : Std_Logic;  -- Load transmit buffer
80
  -----------------------------------------------------------------------------
81
  -- Baud rate Generator
82
  -----------------------------------------------------------------------------
83
  component ClkUnit is
84
   port (
85
     SysClk   : in  Std_Logic;  -- System Clock
86
     EnableRX : out Std_Logic;  -- Control signal
87
     EnableTX : out Std_Logic;  -- Control signal
88
     Reset    : in  Std_Logic); -- Reset input
89
  end component;
90
  -----------------------------------------------------------------------------
91
  -- Receive Unit
92
  -----------------------------------------------------------------------------
93
  component RxUnit is
94
  port (
95
     Clk    : in  Std_Logic;  -- Clock signal
96
     Reset  : in  Std_Logic;  -- Reset input
97
     Enable : in  Std_Logic;  -- Enable input
98
     RxD    : in  Std_Logic;  -- RS-232 data input
99
     RD     : in  Std_Logic;  -- Read data signal
100
     FErr   : out Std_Logic;  -- Status signal
101
     OErr   : out Std_Logic;  -- Status signal
102
     DRdy   : out Std_Logic;  -- Status signal
103
     DataIn : out Std_Logic_Vector(7 downto 0));
104
  end component;
105
  -----------------------------------------------------------------------------
106
  -- Transmitter Unit
107
  -----------------------------------------------------------------------------
108
  component TxUnit is
109
  port (
110
     Clk    : in  Std_Logic;  -- Clock signal
111
     Reset  : in  Std_Logic;  -- Reset input
112
     Enable : in  Std_Logic;  -- Enable input
113
     Load   : in  Std_Logic;  -- Load transmit data
114
     TxD    : out Std_Logic;  -- RS-232 data output
115
     TRegE  : out Std_Logic;  -- Tx register empty
116
     TBufE  : out Std_Logic;  -- Tx buffer empty
117
     DataO  : in  Std_Logic_Vector(7 downto 0));
118
  end component;
119
begin
120
  -----------------------------------------------------------------------------
121
  -- Instantiation of internal components
122
  -----------------------------------------------------------------------------
123
  ClkDiv  : ClkUnit port map (SysClk,EnabRX,EnabTX,Reset);
124
  TxDev   : TxUnit port map (SysClk,Reset,EnabTX,Load,TxD,TRegE,TBufE,TxData);
125
  RxDev   : RxUnit port map (SysClk,Reset,EnabRX,RxD,Read,FErr,OErr,DRdy,RxData);
126
  -----------------------------------------------------------------------------
127
  -- Implements the controller for Rx&Tx units
128
  -----------------------------------------------------------------------------
129
  RSBusCtrl : process(SysClk,Reset,Read,Load)
130
     variable StatM : unsigned(4 downto 0);
131
  begin
132
     if Rising_Edge(SysClk) then
133
        if Reset = '0' then
134
           StatM := "00000";
135
           IntTx_N <= '1';
136
           IntRx_N <= '1';
137
           CSReg <= "11110000";
138
        else
139
           StatM(0) := DRdy;
140
           StatM(1) := FErr;
141
           StatM(2) := OErr;
142
           StatM(3) := TBufE;
143
           StatM(4) := TRegE;
144
        end if;
145
        case StatM is
146
             when "00001" =>
147
                  IntRx_N <= '0';
148
                  CSReg(2) <= '1';
149
             when "01000" =>
150
                  IntTx_N <= '0';
151
             when "11000" =>
152
                  IntTx_N <= '0';
153
                  CSReg(3) <= '1';
154
             when others => null;
155
        end case;
156
 
157
        if Read = '1' then
158
           CSReg(2) <= '0';
159
           IntRx_N <= '1';
160
        end if;
161
 
162
        if Load = '1' then
163
           CSReg(3) <= '0';
164
           IntTx_N <= '1';
165
        end if;
166
     end if;
167
  end process;
168
  -----------------------------------------------------------------------------
169
  -- Combinational section
170
  -----------------------------------------------------------------------------
171
  process(SysClk)
172
  begin
173
     if (CS_N = '0' and RD_N = '0') then
174
        Read <= '1';
175
     else Read <= '0';
176
     end if;
177
 
178
     if (CS_N = '0' and WR_N = '0') then
179
        Load <= '1';
180
     else Load <= '0';
181
     end if;
182
 
183
     if Read = '0' then
184
        DataOut <= "ZZZZZZZZ";
185
     elsif (Read = '1' and Addr = "00") then
186
        DataOut <= RxData;
187
     elsif (Read = '1' and Addr = "01") then
188
        DataOut <= CSReg;
189
     end if;
190
 
191
     if Load = '0' then
192
        TxData <= "ZZZZZZZZ";
193
     elsif (Load = '1' and Addr = "00") then
194
        TxData <= DataIn;
195
     end if;
196
  end process;
197
end uart; --===================== End of architecture =======================--

powered by: WebSVN 2.1.0

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