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

Subversion Repositories miniuart2

[/] [miniuart2/] [branches/] [avendor/] [rtl/] [vhdl/] [miniuart.vhd] - Blame information for rev 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 philippe
-------------------------------------------------------------------------------
2
-- Title      : UART
3
-- Project    : UART
4
-------------------------------------------------------------------------------
5
-- File        : Uart.vhd
6
-- Author      : Philippe CARTON 
7
--               (pc@microsystemes.com / philippe.carton2@libertysurf.fr)
8
-- Organization: Microsystemes
9
-- Created     : 15/12/2001
10
-- Last update : 28/12/2001
11
-- Platform    : Foundation 3.1i
12
-- Simulators  : Foundation logic simulator
13
-- Synthesizers: Foundation Synopsys
14
-- Targets     : Xilinx Spartan
15
-- Dependency  : IEEE std_logic_1164, Rxunit.vhd, Txunit.vhd, utils.vhd
16
-------------------------------------------------------------------------------
17
-- Description: Uart (Universal Asynchronous Receiver Transmitter) for SoC.
18
--    Wishbone compatable.
19
-------------------------------------------------------------------------------
20
-- Copyright (c) notice
21
--    This core adheres to the GNU public license 
22
--
23
-------------------------------------------------------------------------------
24
-- Revisions       :
25
-- Revision Number :
26
-- Version         :
27
-- Date    :
28
-- Modifier        : name <email>
29
-- Description     :
30
--
31
------------------------------------------------------------------------------
32
 
33
library ieee;
34
   use ieee.std_logic_1164.all;
35
 
36
entity UART is
37
  generic(BRDIVISOR: INTEGER range 0 to 65535 := 130); -- Baud rate divisor
38
  port (
39
-- Wishbone signals
40
     WB_CLK_I : in  Std_Logic;  -- clock
41
     WB_RST_I : in  Std_Logic;  -- Reset input
42
     WB_ADR_I : in  Std_Logic_Vector(1 downto 0); -- Adress bus          
43
     WB_DAT_I : in  Std_Logic_Vector(7 downto 0); -- DataIn Bus
44
     WB_DAT_O : out Std_Logic_Vector(7 downto 0); -- DataOut Bus
45
     WB_WE_I  : in  Std_Logic;  -- Write Enable
46
     WB_STB_I : in  Std_Logic;  -- Strobe
47
     WB_ACK_O : out Std_Logic;  -- Acknowledge
48
-- process signals     
49
     IntTx_O  : out Std_Logic;  -- Transmit interrupt: indicate waiting for Byte
50
     IntRx_O  : out Std_Logic;  -- Receive interrupt: indicate Byte received
51
     BR_Clk_I : in  Std_Logic;  -- Clock used for Transmit/Receive
52
     TxD_PAD_O: out Std_Logic;  -- Tx RS232 Line
53
     RxD_PAD_I: in  Std_Logic);  -- Rx RS232 Line     
54
end entity;
55
 
56
-- Architecture for UART for synthesis
57
architecture Behaviour of UART is
58
 
59
  component Counter is
60
  generic(COUNT: INTEGER range 0 to 65535); -- Count revolution
61
  port (
62
     Clk      : in  Std_Logic;  -- Clock
63
     Reset    : in  Std_Logic;  -- Reset input
64
     CE       : in  Std_Logic;  -- Chip Enable
65
     O        : out Std_Logic); -- Output  
66
  end component;
67
 
68
  component RxUnit is
69
  port (
70
     Clk    : in  Std_Logic;  -- system clock signal
71
     Reset  : in  Std_Logic;  -- Reset input
72
     Enable : in  Std_Logic;  -- Enable input
73
     ReadA  : in  Std_logic;  -- Async Read Received Byte
74
     RxD    : in  Std_Logic;  -- RS-232 data input
75
     RxAv   : out Std_Logic;  -- Byte available
76
     DataO  : out Std_Logic_Vector(7 downto 0)); -- Byte received
77
  end component;
78
 
79
  component TxUnit is
80
  port (
81
     Clk    : in  Std_Logic;  -- Clock signal
82
     Reset  : in  Std_Logic;  -- Reset input
83
     Enable : in  Std_Logic;  -- Enable input
84
     LoadA  : in  Std_Logic;  -- Asynchronous Load
85
     TxD    : out Std_Logic;  -- RS-232 data output
86
     Busy   : out Std_Logic;  -- Tx Busy
87
     DataI  : in  Std_Logic_Vector(7 downto 0)); -- Byte to transmit
88
  end component;
89
 
90
  signal RxData : Std_Logic_Vector(7 downto 0); -- Last Byte received
91
  signal TxData : Std_Logic_Vector(7 downto 0); -- Last bytes transmitted
92
  signal SReg   : Std_Logic_Vector(7 downto 0); -- Status register
93
  signal EnabRx : Std_Logic;  -- Enable RX unit
94
  signal EnabTx : Std_Logic;  -- Enable TX unit
95
  signal RxAv   : Std_Logic;  -- Data Received
96
  signal TxBusy : Std_Logic;  -- Transmiter Busy
97
  signal ReadA  : Std_Logic;  -- Async Read receive buffer
98
  signal LoadA  : Std_Logic;  -- Async Load transmit buffer
99
  signal Sig0   : Std_Logic;  -- gnd signal
100
  signal Sig1   : Std_Logic;  -- vcc signal  
101
 
102
  begin
103
  sig0 <= '0';
104
  sig1 <= '1';
105
  Uart_Rxrate : Counter -- Baud Rate adjust
106
     generic map (COUNT => BRDIVISOR)
107
     port map (BR_CLK_I, sig0, sig1, EnabRx);
108
  Uart_Txrate : Counter -- 4 Divider for Tx
109
     generic map (COUNT => 4)
110
     port map (BR_CLK_I, Sig0, EnabRx, EnabTx);
111
  Uart_TxUnit : TxUnit port map (BR_CLK_I, WB_RST_I, EnabTX, LoadA, TxD_PAD_O, TxBusy, TxData);
112
  Uart_RxUnit : RxUnit port map (BR_CLK_I, WB_RST_I, EnabRX, ReadA, RxD_PAD_I, RxAv, RxData);
113
  IntTx_O <= not TxBusy;
114
  IntRx_O <= RxAv;
115
  SReg(0) <= not TxBusy;
116
  SReg(1) <= RxAv;
117
 
118
  -- Implements WishBone data exchange.
119
  -- Clocked on rising edge. Synchronous Reset RST_I
120
  WBctrl : process(WB_CLK_I, WB_RST_I, WB_STB_I, WB_WE_I, WB_ADR_I)
121
  variable StatM : Std_Logic_Vector(4 downto 0);
122
  begin
123
     if Rising_Edge(WB_CLK_I) then
124
        if (WB_RST_I = '1') then
125
           ReadA <= '0';
126
           LoadA <= '0';
127
        else
128
           if (WB_STB_I = '1' and WB_WE_I = '1' and WB_ADR_I = "00") then -- Write Byte to Tx
129
              TxData <= WB_DAT_I;
130
              LoadA <= '1';   -- Load signal        
131
           else LoadA <= '0';
132
           end if;
133
           if (WB_STB_I = '1' and WB_WE_I = '0' and WB_ADR_I = "00") then -- Read Byte from Rx
134
              ReadA <= '1';   -- Read signal
135
           else ReadA <= '0';
136
           end if;
137
        end if;
138
     end if;
139
  end process;
140
  WB_ACK_O <= WB_STB_I;
141
  WB_DAT_O <=
142
     RxData when WB_ADR_I = "00" else  -- Read Byte from Rx
143
     SReg when WB_ADR_I = "01" else    -- Read Status Reg
144
     X"00";
145
end Behaviour;

powered by: WebSVN 2.1.0

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