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

Subversion Repositories System09

[/] [System09/] [tags/] [V10/] [rtl/] [vhdl/] [miniUART2.vhd] - Blame information for rev 66

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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 System68
9
--
10
-- File name      : miniuart2.vhd
11
--
12
-- Purpose        : Implements an miniUART device for communication purposes 
13
--                  between the CPU68 processor and the Host computer through
14
--                  an RS-232 communication protocol.
15
--                  
16
-- Dependencies   : ieee.std_logic_1164
17
--                  ieee.numeric_std
18
--
19
--===========================================================================--
20
-------------------------------------------------------------------------------
21
-- Revision list
22
-- Version   Author                 Date           Changes
23
--
24
-- 0.1      Ovidiu Lupas     15 January 2000       New model
25
-- 1.0      Ovidiu Lupas     January  2000         Synthesis optimizations
26
-- 2.0      Ovidiu Lupas     April    2000         Bugs removed - RSBusCtrl
27
--          the RSBusCtrl did not process all possible situations
28
--
29
--        olupas@opencores.org
30
--
31
-- 3.0      John Kent        October  2002         Changed Status bits to match mc6805
32
--                                                 Added CTS, RTS, Baud rate control
33
--                                                 & Software Reset
34
-- 3.1      John Kent        5 January 2003        Added Word Format control a'la mc6850
35
-- 3.2      John Kent        19 July 2003          Latched Data input to UART
36
-- 3.3      John Kent        6 September 2003      Changed Clock Edge.
37
--        dilbert57@opencores.org
38
--
39
-------------------------------------------------------------------------------
40
-- Entity for miniUART Unit - 9600 baudrate                                  --
41
-------------------------------------------------------------------------------
42
library ieee;
43
   use ieee.std_logic_1164.all;
44
   use ieee.numeric_std.all;
45
 
46
entity miniUART is
47
  port (
48
     SysClk   : in  Std_Logic;  -- System Clock
49
     rst      : in  Std_Logic;  -- Reset input (active high)
50
     cs       : in  Std_Logic;
51
     rw       : in  Std_Logic;
52
     RxD      : in  Std_Logic;
53
     TxD      : out Std_Logic;
54
     CTS_n    : in  Std_Logic;
55
     RTS_n    : out Std_Logic;
56
     Irq      : out Std_Logic;  -- interrupt
57
     Addr     : in  Std_Logic;  -- Register Select
58
     DataIn   : in  Std_Logic_Vector(7 downto 0); -- 
59
     DataOut  : out Std_Logic_Vector(7 downto 0)); -- 
60
end; --================== End of entity ==============================--
61
-------------------------------------------------------------------------------
62
-- Architecture for miniUART Controller Unit
63
-------------------------------------------------------------------------------
64
architecture uart of miniUART is
65
  -----------------------------------------------------------------------------
66
  -- Signals
67
  -----------------------------------------------------------------------------
68
  signal RxData : Std_Logic_Vector(7 downto 0); -- 
69
  signal TxData : Std_Logic_Vector(7 downto 0); -- 
70
  signal StatReg : Std_Logic_Vector(7 downto 0); -- status register
71
  --             StatReg detailed 
72
  -----------+--------+--------+--------+--------+--------+--------+--------+
73
  --  Irq    | PErr   | ORErr  | FErr   | CTS    | DCD    | TBufE  | DRdy   |
74
  -----------+--------+--------+--------+--------+--------+--------+--------+
75
  signal CtrlReg : Std_Logic_Vector(7 downto 0); -- control register
76
  --             CtrlReg detailed 
77
  -----------+--------+--------+--------+--------+--------+--------+--------+
78
  --  IrqEnb |TxCtl(1)|TxCtl(0)|WdFmt(2)|WdFmt(1)|WdFmt(0)|BdCtl(1)|BdCtl(0)|
79
  -----------+--------+--------+--------+--------+--------+--------+--------+
80
  -- IrqEnb
81
  -- 0       - Rx Interrupt disabled
82
  -- 1       - Rx Interrupt enabled
83
  -- TxCtl
84
  -- 0 1     - Tx Interrupt Enable
85
  -- 1 0     - RTS high
86
  -- WdFmt
87
  -- 0 0 0   - 7 data, even parity, 2 stop
88
  -- 0 0 1   - 7 data, odd  parity, 2 stop
89
  -- 0 1 0   - 7 data, even parity, 1 stop
90
  -- 0 1 1   - 7 data, odd  parity, 1 stop
91
  -- 1 0 0   - 8 data, no   parity, 2 stop
92
  -- 1 0 1   - 8 data, no   parity, 1 stop
93
  -- 1 1 0   - 8 data, even parity, 1 stop
94
  -- 1 1 1   - 8 data, odd  parity, 1 stop
95
  -- BdCtl
96
  -- 0 0     - Baud Clk divide by 1 (not implemented)
97
  -- 0 1     - Baud Clk divide by 16
98
  -- 1 0     - Baud Clk divide by 64
99
  -- 1 1     - reset
100
 
101
  signal EnabRx : Std_Logic;  -- Enable RX unit
102
  signal EnabTx : Std_Logic;  -- Enable TX unit
103
  signal DRdy   : Std_Logic;  -- Receive Data ready
104
  signal TBufE  : Std_Logic;  -- Transmit buffer empty
105
  signal FErr   : Std_Logic;  -- Frame error
106
  signal OErr   : Std_Logic;  -- Output error
107
  signal PErr   : Std_Logic;  -- Parity Error
108
  signal Read   : Std_Logic;  -- Read receive buffer
109
  signal Load   : Std_Logic;  -- Load transmit buffer
110
  signal Int    : Std_Logic;  -- Interrupt bit
111
  signal Reset  : Std_Logic;  -- Reset (Software & Hardware)
112
  -----------------------------------------------------------------------------
113
  -- Baud rate Generator
114
  -----------------------------------------------------------------------------
115
  component ClkUnit
116
   port (
117
     Clk      : in  Std_Logic;  -- System Clock
118
     Reset    : in  Std_Logic;  -- Reset input
119
     EnableRX : out Std_Logic;  -- Control signal
120
     EnableTX : out Std_Logic;  -- Control signal
121
          BaudRate : in  Std_Logic_Vector(1 downto 0));
122
  end component;
123
  -----------------------------------------------------------------------------
124
  -- Receive Unit
125
  -----------------------------------------------------------------------------
126
  component RxUnit
127
  port (
128
     Clk    : in  Std_Logic;  -- Clock signal
129
     Reset  : in  Std_Logic;  -- Reset input
130
     Enable : in  Std_Logic;  -- Enable input
131
     RxD    : in  Std_Logic;  -- RS-232 data input
132
     ReadD  : in  Std_Logic;  -- Read data signal
133
     Format : in  Std_Logic_Vector(2 downto 0); -- word format
134
     FRErr  : out Std_Logic;  -- Status signal
135
     ORErr  : out Std_Logic;  -- Status signal
136
          PAErr  : out Std_logic;  -- Status signal
137
     DARdy  : out Std_Logic;  -- Status signal
138
     DAOut  : out Std_Logic_Vector(7 downto 0));
139
  end component;
140
  -----------------------------------------------------------------------------
141
  -- Transmitter Unit
142
  -----------------------------------------------------------------------------
143
  component TxUnit
144
  port (
145
     Clk    : in  Std_Logic;  -- Clock signal
146
     Reset  : in  Std_Logic;  -- Reset input
147
     Enable : in  Std_Logic;  -- Enable input
148
     LoadD  : in  Std_Logic;  -- Load transmit data
149
     Format : in  Std_Logic_Vector(2 downto 0); -- word format
150
     TxD    : out Std_Logic;  -- RS-232 data output
151
     TBE    : out Std_Logic;  -- Tx buffer empty
152
     DataO  : in  Std_Logic_Vector(7 downto 0));
153
  end component;
154
begin
155
  -----------------------------------------------------------------------------
156
  -- Instantiation of internal components
157
  -----------------------------------------------------------------------------
158
 
159
  ClkDiv  : ClkUnit port map (
160
                Clk      => SysClk,
161
                                         EnableRx => EnabRX,
162
                                         EnableTx => EnabTX,
163
                                         BaudRate => CtrlReg(1 downto 0),
164
                                         Reset    => Reset);
165
 
166
  TxDev   : TxUnit  port map (
167
                Clk      => SysClk,
168
                                         Reset    => Reset,
169
                                         Enable   => EnabTX,
170
                                         LoadD    => Load,
171
                                         Format   => CtrlReg(4 downto 2),
172
                                         TxD      => TxD,
173
                                         TBE      => TBufE,
174
                                         DataO    => TxData);
175
 
176
  RxDev   : RxUnit  port map (
177
                Clk      => SysClk,
178
                                         Reset    => Reset,
179
                                         Enable   => EnabRX,
180
                                         RxD      => RxD,
181
                                         ReadD    => Read,
182
                                         Format   => CtrlReg(4 downto 2),
183
                                         FRErr    => FErr,
184
                                         ORErr    => OErr,
185
                                         PAErr    => PErr,
186
                                         DARdy    => DRdy,
187
                                         DAOut    => RxData);
188
 
189
  -----------------------------------------------------------------------------
190
  -- Implements the controller for Rx&Tx units
191
  -----------------------------------------------------------------------------
192
  RSBusCtrl : process(SysClk, Reset, DRdy, TBufE, FErr, OErr, CTS_n, PErr, Int, CtrlReg)
193
     variable StatM : Std_Logic_Vector(7 downto 0);
194
  begin
195
     if SysClk'event and SysClk='0' then
196
        if Reset = '1' then
197
           StatM := "00000000";
198
           Int <= '0';
199
        else
200
           StatM(0) := DRdy;
201
           StatM(1) := TBufE;
202
                          StatM(2) := '0';  -- DCD
203
                          StatM(3) := CTS_n;
204
           StatM(4) := FErr; -- Framing error
205
           StatM(5) := OErr; -- Overrun error
206
           StatM(6) := PErr; -- Parity error
207
                     StatM(7) := Int;
208
                     Int <= (CtrlReg(7) and DRdy) or
209
                           ((not CtrlReg(6)) and CtrlReg(5) and TBufE);
210
        end if;
211
 
212
                 RTS_n <= CtrlReg(6) and not CtrlReg(5);
213
       Irq <= Int;
214
       StatReg <= StatM;
215
     end if;
216
  end process;
217
 
218
-----------------------------------------------------------------------------
219
-- Combinational section
220
-----------------------------------------------------------------------------
221
 
222
control_strobe:  process(SysClk, Reset, cs, rw, Addr, DataIn, CtrlReg, TxData )
223
  begin
224
   if SysClk'event and SysClk='0' then
225
          if (reset = '1') then
226
            CtrlReg <= "00000000";
227
                 Load <= '0';
228
                 Read <= '0';
229
          else
230
            if cs = '1' then
231
              if Addr = '1' then
232
                     CtrlReg <= CtrlReg;
233
                     if rw = '0' then   -- write data register
234
             TxData <= DataIn;
235
                  Load <= '1';
236
                       Read <= '0';
237
                else               -- read Data Register
238
             TxData <= TxData;
239
                  Load <= '0';
240
             Read <= '1';
241
                          end if; -- rw
242
              else                 -- read Status Register
243
           TxData <= TxData;
244
                Load <= '0';
245
                     Read <= '0';
246
                     if rw = '0' then   -- write control register
247
                            CtrlReg <= DataIn;
248
                else               -- read control Register
249
                       CtrlReg <= CtrlReg;
250
                          end if; -- rw
251
                   end if; -- Addr
252
            else                   -- not selected
253
              Load <= '0';
254
                   Read <= '0';
255
                        CtrlReg <= CtrlReg;
256
            end if;  -- cs
257
          end if; -- reset
258
   end if; -- SysClk
259
end process;
260
 
261
---------------------------------------------------------------
262
--
263
-- set data output mux
264
--
265
--------------------------------------------------------------
266
 
267
data_port: process(Addr, StatReg, RxData )
268
begin
269
          if Addr = '1' then
270
                 DataOut <= RxData;    -- read data register
271
          else
272
                 DataOut <= StatReg;   -- read status register
273
          end if; -- Addr
274
end process;
275
 
276
---------------------------------------------------------------
277
--
278
-- reset may be hardware or software
279
--
280
---------------------------------------------------------------
281
 
282
uart_reset: process(CtrlReg, rst )
283
begin
284
          Reset <= (CtrlReg(1) and CtrlReg(0)) or rst;
285
end process;
286
 
287
end uart; --===================== End of architecture =======================--
288
 

powered by: WebSVN 2.1.0

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