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

Subversion Repositories uart

[/] [uart/] [trunk/] [miniUART.vhd] - Blame information for rev 9

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