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

Subversion Repositories uart

[/] [uart/] [tags/] [jan_23_2000/] [RxUnit.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      : RxUnit.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
--        ovilup@mail.dnttm.ro
27
-------------------------------------------------------------------------------
28
-- Description    : Implements the receive unit of the miniUART core. Samples
29
--                  16 times the RxD line and retain the value in the middle of
30
--                  the time interval. 
31
-------------------------------------------------------------------------------
32
-- Entity for Receive Unit - 9600 baudrate                                  --
33
-------------------------------------------------------------------------------
34
library ieee;
35
   use ieee.std_logic_1164.all;
36
   use ieee.numeric_std.all;
37
library work;
38
   use work.UART_Def.all;
39
-------------------------------------------------------------------------------
40
-- Receive unit
41
-------------------------------------------------------------------------------
42
entity RxUnit is
43
  port (
44
     Clk    : in  Std_Logic;  -- system clock signal
45
     Reset  : in  Std_Logic;  -- Reset input
46
     Enable : in  Std_Logic;  -- Enable input
47
     RxD    : in  Std_Logic;  -- RS-232 data input
48
     RD     : in  Std_Logic;  -- Read data signal
49
     FErr   : out Std_Logic;  -- Status signal
50
     OErr   : out Std_Logic;  -- Status signal
51
     DRdy   : out Std_Logic;  -- Status signal
52
     DataIn : out Std_Logic_Vector(7 downto 0));
53
end entity; --================== End of entity ==============================--
54
-------------------------------------------------------------------------------
55
-- Architecture for receive Unit
56
-------------------------------------------------------------------------------
57
architecture Behaviour of RxUnit is
58
  -----------------------------------------------------------------------------
59
  -- Signals
60
  -----------------------------------------------------------------------------
61
  signal Start     : Std_Logic;             -- Syncro signal
62
  signal tmpRxD    : Std_Logic;             -- 
63
  signal tmpDRdy   : Std_Logic;             -- 
64
  signal outErr    : Std_Logic;             -- 
65
  signal frameErr  : Std_Logic;             -- 
66
  signal BitCnt    : Unsigned(3 downto 0);  -- 
67
  signal SampleCnt : Unsigned(3 downto 0);  -- 
68
  signal ShtReg    : Std_Logic_Vector(7 downto 0);  --
69
  signal DOut      : Std_Logic_Vector(7 downto 0);  --
70
begin
71
  ---------------------------------------------------------------------
72
  -- Receiver process
73
  ---------------------------------------------------------------------
74
  RcvProc : process(Clk,Reset,Enable,RxD)
75
      variable tmpBitCnt    : Integer range 0 to 15;
76
      variable tmpSampleCnt : Integer range 0 to 15;
77
      constant CntOne       : Unsigned(3 downto 0):="0001";
78
  begin
79
     if Rising_Edge(Clk) then
80
        tmpBitCnt := ToInteger(BitCnt);
81
        tmpSampleCnt := ToInteger(SampleCnt);
82
        if Reset = '0' then
83
           BitCnt <= "0000";
84
           SampleCnt <= "0000";
85
           Start <= '0';
86
           tmpDRdy <= '0';
87
           tmpRxD <= '1';
88
           frameErr <= '0';
89
           outErr <= '0';
90
 
91
           ShtReg <= "00000000";  --
92
           DOut   <= "00000000";  --
93
        else
94
           if RD = '1' then
95
              tmpDRdy <= '0';      -- Data was read
96
           end if;
97
 
98
           if Enable = '1' then
99
              if Start = '0' then
100
                 if RxD = '0' then -- Start bit, 
101
                    SampleCnt <= SampleCnt + CntOne;
102
                    Start <= '1';
103
                 end if;
104
              else
105
                 if tmpSampleCnt = 8 then  -- reads the RxD line
106
                    tmpRxD <= RxD;
107
                    SampleCnt <= SampleCnt + CntOne;
108
                 elsif tmpSampleCnt = 15 then
109
                    case tmpBitCnt is
110
                         when 0 =>
111
                                if RxD = '1' then
112
                                   Start <= '0';
113
                                else
114
                                   BitCnt <= BitCnt + CntOne;
115
                                end if;
116
                         when 1|2|3|4|5|6|7|8 =>
117
                                BitCnt <= BitCnt + CntOne;
118
                                SampleCnt <= SampleCnt + CntOne;
119
                                ShtReg <= tmpRxD & ShtReg(7 downto 1);
120
                         when 9 =>
121
                                if tmpRxD = '0' then  -- stop bit expected
122
                                   frameErr <= '1';
123
                                else
124
                                   frameErr <= '0';
125
                                end if;
126
 
127
                                if tmpDRdy = '1' then -- 
128
                                   outErr <= '1';
129
                                else
130
                                   outErr <= '0';
131
                                end if;
132
 
133
                                tmpDRdy <= '1';
134
                                DOut <= ShtReg;
135
                                BitCnt <= "0000";
136
                                Start <= '0';
137
                         when others =>
138
                              null;
139
                    end case;
140
                 else
141
                    SampleCnt <= SampleCnt + CntOne;
142
                 end if;
143
              end if;
144
           end if;
145
        end if;
146
     end if;
147
  end process;
148
 
149
  DRdy <= tmpDRdy;
150
  DataIn <= DOut;
151
  FErr <= frameErr;
152
  OErr <= outErr;
153
 
154
end Behaviour; --==================== End of architecture ====================--

powered by: WebSVN 2.1.0

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