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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_async_serial.vhd] - Blame information for rev 209

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jshamlet
-- Copyright (c)2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  o8_async_serial
25
-- Description:  Provides a single 8-bit, asynchronous transceiver. While the
26
--               width is fixed at 8-bits, the bit rate and parity controls
27
--               are settable via generics.
28 209 jshamlet
--
29
-- Note: The baud rate generator will produce an approximate frequency. The
30
--        final bit rate should be within +/- 1% of the true bit rate to
31
--        ensure the receiver can successfully receive. With a sufficiently
32
--        high core clock, this is generally achievable for common PC serial
33
--        data rates.
34 207 jshamlet
 
35
library ieee;
36
use ieee.std_logic_1164.all;
37
use ieee.std_logic_unsigned.all;
38
use ieee.std_logic_arith.all;
39
use ieee.std_logic_misc.all;
40
 
41
library work;
42
  use work.open8_pkg.all;
43
 
44
entity o8_async_serial is
45
generic(
46
  Bit_Rate              : real;
47
  Enable_Parity         : boolean;
48
  Parity_Odd_Even_n     : std_logic;
49
  Sys_Freq              : real;
50
  Reset_Level           : std_logic;
51
  Address               : ADDRESS_TYPE
52
);
53
port(
54
  Clock                 : in  std_logic;
55
  Reset                 : in  std_logic;
56
  --
57
  Bus_Address           : in  ADDRESS_TYPE;
58
  Wr_Enable             : in  std_logic;
59
  Wr_Data               : in  DATA_TYPE;
60
  Rd_Enable             : in  std_logic;
61
  Rd_Data               : out DATA_TYPE;
62
  --
63
  TX_Out                : out std_logic;
64
  CTS_In                : in  std_logic;
65
  RX_In                 : in  std_logic;
66
  RTS_Out               : out std_logic
67
);
68
end entity;
69
 
70
architecture behave of o8_async_serial is
71
 
72
  signal FIFO_Reset          : std_logic := '0';
73
 
74
  constant User_Addr         : std_logic_vector(15 downto 1) :=
75
                                Address(15 downto 1);
76
  alias  Comp_Addr           is Bus_Address(15 downto 1);
77
  signal Addr_Match          : std_logic := '0';
78
 
79
  alias  Reg_Addr            is Bus_Address(0);
80
  signal Reg_Sel             : std_logic := '0';
81
  signal Rd_En               : std_logic := '0';
82
 
83
  signal TX_FIFO_Wr_En       : std_logic := '0';
84
  alias  TX_FIFO_Wr_Data     is Wr_Data;
85
  signal TX_FIFO_Rd_En       : std_logic := '0';
86
  signal TX_FIFO_Empty       : std_logic := '0';
87
  signal TX_FIFO_AFull       : std_logic := '0';
88
  signal TX_FIFO_Rd_Data     : DATA_TYPE := x"00";
89
 
90
  alias  Tx_Data             is TX_FIFO_Rd_Data;
91
 
92
  type TX_CTRL_STATES is (IDLE, TX_BYTE, TX_START, TX_WAIT );
93
  signal TX_Ctrl             : TX_CTRL_STATES := IDLE;
94
 
95
  signal TX_Xmit             : std_logic := '0';
96
  signal TX_Done             : std_logic := '0';
97
 
98
  constant BAUD_RATE_DIV     : integer := integer(Sys_Freq / Bit_Rate);
99
 
100
  signal CTS_sr              : std_logic_vector(3 downto 0) := "0000";
101
  alias  CTS_Okay            is CTS_sr(3);
102
 
103
  signal RX_FIFO_Wr_En       : std_logic := '0';
104 209 jshamlet
  signal RX_FIFO_Wr_Data     : DATA_TYPE := x"00";
105
  signal RX_FIFO_Rd_En       : std_logic := '0';
106
  signal RX_FIFO_Empty       : std_logic := '0';
107
  signal RX_FIFO_AFull       : std_logic := '0';
108
  signal RX_FIFO_Rd_Data     : DATA_TYPE := x"00";
109 207 jshamlet
 
110
begin
111
 
112
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
113
 
114
  io_reg: process( Clock, Reset )
115
  begin
116
    if( Reset = Reset_Level )then
117
      Rd_En             <= '0';
118
      Rd_Data           <= OPEN8_NULLBUS;
119
      RTS_Out           <= '0';
120
    elsif( rising_edge( Clock ) )then
121
      Rd_Data           <= OPEN8_NULLBUS;
122
      Rd_En             <= Rd_Enable and Addr_Match;
123
      Reg_Sel           <= Reg_Addr;
124
      if( Rd_En = '1' and Reg_Sel = '1' )then
125
        Rd_Data(4)      <= RX_FIFO_Empty;
126
        Rd_Data(5)      <= RX_FIFO_AFull;
127
        Rd_Data(6)      <= TX_FIFO_Empty;
128
        Rd_Data(7)      <= TX_FIFO_AFull;
129
      end if;
130
      if( Rd_En = '1' and Reg_Sel = '0' )then
131
        Rd_Data         <= RX_FIFO_Rd_Data;
132
      end if;
133
      RTS_Out           <= not RX_FIFO_AFull;
134
    end if;
135
  end process;
136
 
137
  TX_FIFO_Wr_En              <= Wr_Enable and Addr_Match and not Reg_Addr;
138
 
139
  FIFO_Reset                 <= '1' when Reset = Reset_Level else '0';
140
 
141
  U_TX_FIFO : entity work.fifo_1k_core
142
  port map(
143
    aclr                     => FIFO_Reset,
144
    clock                    => Clock,
145
    data                     => TX_FIFO_Wr_Data,
146
    rdreq                    => TX_FIFO_Rd_En,
147
    wrreq                    => TX_FIFO_Wr_En,
148
    empty                    => TX_FIFO_Empty,
149
    almost_full              => TX_FIFO_AFull,
150
    q                        => TX_FIFO_Rd_Data
151
  );
152
 
153
  tx_FSM: process( Clock, Reset )
154
  begin
155
    if( Reset = Reset_Level )then
156
      TX_Ctrl                <= IDLE;
157
      TX_Xmit                <= '0';
158
      TX_FIFO_Rd_En          <= '0';
159
      CTS_sr                 <= (others => '0');
160
    elsif( rising_edge(Clock) )then
161
      TX_Xmit                <= '0';
162
      TX_FIFO_Rd_En          <= '0';
163
      CTS_sr                 <= CTS_sr(2 downto 0) & CTS_In;
164
 
165
      case( TX_Ctrl )is
166
        when IDLE =>
167
          if( TX_FIFO_Empty = '0' and CTS_Okay = '1' )then
168
            TX_FIFO_Rd_En    <= '1';
169
            TX_Ctrl          <= TX_BYTE;
170
          end if;
171
 
172
        when TX_BYTE =>
173
          TX_Xmit            <= '1';
174
          TX_Ctrl            <= TX_START;
175
 
176
        when TX_START =>
177
          if( Tx_Done = '0' )then
178
            TX_Ctrl          <= TX_WAIT;
179
          end if;
180
 
181
        when TX_WAIT =>
182
          if( Tx_Done = '1' )then
183
            TX_Ctrl          <= IDLE;
184
          end if;
185
 
186
        when others => null;
187
      end case;
188
 
189
    end if;
190
  end process;
191
 
192
  U_TX : entity work.async_ser_tx
193
  generic map(
194
    Reset_Level              => Reset_Level,
195
    Enable_Parity            => Enable_Parity,
196
    Parity_Odd_Even_n        => Parity_Odd_Even_n,
197
    Clock_Divider            => BAUD_RATE_DIV
198
  )
199
  port map(
200
    Clock                    => Clock,
201
    Reset                    => Reset,
202
    --
203
    Tx_Data                  => Tx_Data,
204
    Tx_Valid                 => TX_Xmit,
205
    --
206
    Tx_Out                   => TX_Out,
207
    Tx_Done                  => Tx_Done
208
  );
209
 
210
  U_RX : entity work.async_ser_rx
211
  generic map(
212
    Reset_Level              => Reset_Level,
213
    Enable_Parity            => Enable_Parity,
214
    Parity_Odd_Even_n        => Parity_Odd_Even_n,
215
    Clock_Divider            => BAUD_RATE_DIV
216
  )
217
  port map(
218
    Clock                    => Clock,
219
    Reset                    => Reset,
220
    --
221
    Rx_In                    => RX_In,
222
    --
223
    Rx_Data                  => RX_FIFO_Wr_Data,
224
    Rx_Valid                 => RX_FIFO_Wr_En,
225
    Rx_PErr                  => open
226
  );
227
 
228
  RX_FIFO_Rd_En              <= Rd_Enable and Addr_Match and not Reg_Addr;
229
 
230
  U_RX_FIFO : entity work.fifo_1k_core
231
  port map(
232
    aclr                     => FIFO_Reset,
233
    clock                    => Clock,
234
    data                     => RX_FIFO_Wr_Data,
235
    rdreq                    => RX_FIFO_Rd_En,
236
    wrreq                    => RX_FIFO_Wr_En,
237
    empty                    => RX_FIFO_Empty,
238
    almost_full              => RX_FIFO_AFull,
239
    q                        => RX_FIFO_Rd_Data
240
  );
241
 
242
end architecture;

powered by: WebSVN 2.1.0

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