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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [async_ser_tx.vhd] - Blame information for rev 208

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

Line No. Rev Author Line
1 207 jshamlet
-- Copyright (c)2006, 2016, 2019 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 :  async_ser_tx
25
-- Description:  Asynchronous transmitter wired for 8[N/E/O]1 data. Parity mode
26
--                and bit rate are set with generics.
27
 
28
library ieee;
29
use ieee.std_logic_1164.all;
30
use ieee.std_logic_unsigned.all;
31
use ieee.std_logic_arith.all;
32
use ieee.std_logic_misc.all;
33
 
34
entity async_ser_tx is
35
generic(
36
    Reset_Level              : std_logic;
37
    Enable_Parity            : boolean;
38
    Parity_Odd_Even_n        : std_logic;
39
    Clock_Divider            : integer
40
);
41
port(
42
    Clock                    : in  std_logic;
43
    Reset                    : in  std_logic;
44
    --
45
    Tx_Data                  : in  std_logic_vector(7 downto 0);
46
    Tx_Valid                 : in  std_logic;
47
    --
48
    Tx_Out                   : out std_logic;
49
    Tx_Done                  : out std_logic
50
);
51
end entity;
52
 
53
architecture behave of async_ser_tx is
54
 
55 208 jshamlet
  -- The ceil_log2 function returns the minimum register width required to
56
  --  hold the supplied integer.
57
  function ceil_log2 (x : in natural) return natural is
58
    variable retval          : natural;
59
  begin
60
    retval                   := 1;
61
    while ((2**retval) - 1) < x loop
62
      retval                 := retval + 1;
63
    end loop;
64
    return retval;
65
  end ceil_log2;
66
 
67 207 jshamlet
  constant Tick_Base         : integer := Clock_Divider - 1;
68
  constant Tick_Bits         : integer := ceil_log2(Tick_Base);
69
  constant TICK_DIV          : std_logic_vector(Tick_Bits - 1 downto 0) :=
70
                                 conv_std_logic_vector(Tick_Base, Tick_Bits);
71
 
72 208 jshamlet
  signal Tick_Cntr           : std_logic_vector(Tick_Bits - 1 downto 0) :=
73
                                 (others => '0');
74 207 jshamlet
 
75 208 jshamlet
  signal Tick_Trig           : std_logic := '0';
76
  signal Tx_Enable           : std_logic := '0';
77
  signal Tx_Buffer           : std_logic_vector(7 downto 0) := x"00";
78
  signal Tx_Parity           : std_logic := '0';
79
  signal Tx_State            : std_logic_vector(3 downto 0) := x"0";
80 207 jshamlet
  alias  Tx_Bit_Sel          is Tx_State(2 downto 0);
81
 
82
  -- State machine definitions
83
  constant IO_RSV0           : std_logic_vector(3 downto 0) := "1011"; -- B
84
  constant IO_RSV1           : std_logic_vector(3 downto 0) := "1100"; -- C
85
  constant IO_RSV2           : std_logic_vector(3 downto 0) := "1101"; -- D
86
  constant IO_IDLE           : std_logic_vector(3 downto 0) := "1110"; -- E
87
  constant IO_STRT           : std_logic_vector(3 downto 0) := "1111"; -- F
88
  constant IO_BIT0           : std_logic_vector(3 downto 0) := "0000"; -- 0
89
  constant IO_BIT1           : std_logic_vector(3 downto 0) := "0001"; -- 1
90
  constant IO_BIT2           : std_logic_vector(3 downto 0) := "0010"; -- 2
91
  constant IO_BIT3           : std_logic_vector(3 downto 0) := "0011"; -- 3
92
  constant IO_BIT4           : std_logic_vector(3 downto 0) := "0100"; -- 4
93
  constant IO_BIT5           : std_logic_vector(3 downto 0) := "0101"; -- 5
94
  constant IO_BIT6           : std_logic_vector(3 downto 0) := "0110"; -- 6
95
  constant IO_BIT7           : std_logic_vector(3 downto 0) := "0111"; -- 7
96
  constant IO_PARI           : std_logic_vector(3 downto 0) := "1000"; -- 8
97
  constant IO_STOP           : std_logic_vector(3 downto 0) := "1001"; -- 9
98
  constant IO_DONE           : std_logic_vector(3 downto 0) := "1010"; -- A
99
 
100
begin
101
 
102
  UART_Regs: process( Clock, Reset )
103
  begin
104
    if( Reset = Reset_Level )then
105
      Tick_Cntr              <= (others => '0');
106
      Tick_Trig              <= '0';
107
      Tx_State               <= IO_IDLE;
108
      Tx_Enable              <= '0';
109
      Tx_Buffer              <= (others => '0');
110
      if( Enable_Parity )then
111
        Tx_Parity            <= '0';
112
      end if;
113
      Tx_Out                 <= '1';
114
      Tx_Done                <= '0';
115
    elsif( rising_edge(Clock) )then
116
      Tick_Cntr              <= (others => '0');
117
      Tick_Trig              <= '0';
118
 
119
      if( Tx_Enable = '1' )then
120
        Tick_Cntr            <= Tick_Cntr - 1;
121
        Tick_Trig            <= '0';
122
        if( or_reduce(Tick_Cntr) = '0' )then
123
          Tick_Cntr          <= TICK_DIV;
124
          Tick_Trig          <= '1';
125
        end if;
126
      end if;
127
 
128
      if( Tx_Valid = '1' )then
129
        Tx_Buffer            <= Tx_Data;
130
        Tx_Enable            <= '1';
131
      end if;
132
 
133
      Tx_State               <= Tx_State + Tick_Trig;
134
      Tx_Done                <= '0';
135
      Tx_Out                 <= '1';
136
 
137
      case( Tx_State )is
138
        when IO_IDLE =>
139
          if( Enable_Parity )then
140
            Tx_Parity        <= Parity_Odd_Even_n;
141
          end if;
142
 
143
        when IO_STRT =>
144
          Tx_Out             <= '0';
145
 
146
        when IO_BIT0 | IO_BIT1 | IO_BIT2 | IO_BIT3 |
147
             IO_BIT4 | IO_BIT5 | IO_BIT6 | IO_BIT7 =>
148
          Tx_Out             <= Tx_Buffer(conv_integer(Tx_Bit_Sel));
149
          if( Tick_Trig = '1' and Enable_Parity )then
150
            Tx_Parity        <= Tx_Parity xor Tx_Buffer(conv_integer(Tx_Bit_Sel));
151
          end if;
152
 
153
        when IO_PARI =>
154
          if( Enable_Parity )then
155
            Tx_Out           <= Tx_Parity;
156
          end if;
157
 
158
        when IO_STOP =>
159
 
160
        when IO_DONE =>
161
          Tx_Done            <= '1';
162
          Tx_Enable          <= '0';
163
          Tx_State           <= IO_IDLE;
164
 
165
        when others =>
166
 
167
      end case;
168
 
169
      if( Tx_Enable = '0' )then
170
        Tx_State             <= IO_IDLE;
171
      end if;
172
 
173
    end if;
174
  end process;
175
 
176
end architecture;

powered by: WebSVN 2.1.0

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