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 207

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
library work;
35
  use work.open8_pkg.all;
36
 
37
entity async_ser_tx is
38
generic(
39
    Reset_Level              : std_logic;
40
    Enable_Parity            : boolean;
41
    Parity_Odd_Even_n        : std_logic;
42
    Clock_Divider            : integer
43
);
44
port(
45
    Clock                    : in  std_logic;
46
    Reset                    : in  std_logic;
47
    --
48
    Tx_Data                  : in  std_logic_vector(7 downto 0);
49
    Tx_Valid                 : in  std_logic;
50
    --
51
    Tx_Out                   : out std_logic;
52
    Tx_Done                  : out std_logic
53
);
54
end entity;
55
 
56
architecture behave of async_ser_tx is
57
 
58
  constant Tick_Base         : integer := Clock_Divider - 1;
59
  constant Tick_Bits         : integer := ceil_log2(Tick_Base);
60
  constant TICK_DIV          : std_logic_vector(Tick_Bits - 1 downto 0) :=
61
                                 conv_std_logic_vector(Tick_Base, Tick_Bits);
62
 
63
  signal Tick_Cntr           : std_logic_vector(Tick_Bits - 1 downto 0);
64
  signal Tick_Trig           : std_logic;
65
 
66
  signal Tx_Enable           : std_logic;
67
  signal Tx_Buffer           : std_logic_vector(7 downto 0);
68
  signal Tx_Parity           : std_logic;
69
 
70
  signal Tx_State            : std_logic_vector(3 downto 0);
71
  alias  Tx_Bit_Sel          is Tx_State(2 downto 0);
72
 
73
  -- State machine definitions
74
  constant IO_RSV0           : std_logic_vector(3 downto 0) := "1011"; -- B
75
  constant IO_RSV1           : std_logic_vector(3 downto 0) := "1100"; -- C
76
  constant IO_RSV2           : std_logic_vector(3 downto 0) := "1101"; -- D
77
  constant IO_IDLE           : std_logic_vector(3 downto 0) := "1110"; -- E
78
  constant IO_STRT           : std_logic_vector(3 downto 0) := "1111"; -- F
79
  constant IO_BIT0           : std_logic_vector(3 downto 0) := "0000"; -- 0
80
  constant IO_BIT1           : std_logic_vector(3 downto 0) := "0001"; -- 1
81
  constant IO_BIT2           : std_logic_vector(3 downto 0) := "0010"; -- 2
82
  constant IO_BIT3           : std_logic_vector(3 downto 0) := "0011"; -- 3
83
  constant IO_BIT4           : std_logic_vector(3 downto 0) := "0100"; -- 4
84
  constant IO_BIT5           : std_logic_vector(3 downto 0) := "0101"; -- 5
85
  constant IO_BIT6           : std_logic_vector(3 downto 0) := "0110"; -- 6
86
  constant IO_BIT7           : std_logic_vector(3 downto 0) := "0111"; -- 7
87
  constant IO_PARI           : std_logic_vector(3 downto 0) := "1000"; -- 8
88
  constant IO_STOP           : std_logic_vector(3 downto 0) := "1001"; -- 9
89
  constant IO_DONE           : std_logic_vector(3 downto 0) := "1010"; -- A
90
 
91
begin
92
 
93
  UART_Regs: process( Clock, Reset )
94
  begin
95
    if( Reset = Reset_Level )then
96
      Tick_Cntr              <= (others => '0');
97
      Tick_Trig              <= '0';
98
      Tx_State               <= IO_IDLE;
99
      Tx_Enable              <= '0';
100
      Tx_Buffer              <= (others => '0');
101
      if( Enable_Parity )then
102
        Tx_Parity            <= '0';
103
      end if;
104
      Tx_Out                 <= '1';
105
      Tx_Done                <= '0';
106
    elsif( rising_edge(Clock) )then
107
      Tick_Cntr              <= (others => '0');
108
      Tick_Trig              <= '0';
109
 
110
      if( Tx_Enable = '1' )then
111
        Tick_Cntr            <= Tick_Cntr - 1;
112
        Tick_Trig            <= '0';
113
        if( or_reduce(Tick_Cntr) = '0' )then
114
          Tick_Cntr          <= TICK_DIV;
115
          Tick_Trig          <= '1';
116
        end if;
117
      end if;
118
 
119
      if( Tx_Valid = '1' )then
120
        Tx_Buffer            <= Tx_Data;
121
        Tx_Enable            <= '1';
122
      end if;
123
 
124
      Tx_State               <= Tx_State + Tick_Trig;
125
      Tx_Done                <= '0';
126
      Tx_Out                 <= '1';
127
 
128
      case( Tx_State )is
129
        when IO_IDLE =>
130
          if( Enable_Parity )then
131
            Tx_Parity        <= Parity_Odd_Even_n;
132
          end if;
133
 
134
        when IO_STRT =>
135
          Tx_Out             <= '0';
136
 
137
        when IO_BIT0 | IO_BIT1 | IO_BIT2 | IO_BIT3 |
138
             IO_BIT4 | IO_BIT5 | IO_BIT6 | IO_BIT7 =>
139
          Tx_Out             <= Tx_Buffer(conv_integer(Tx_Bit_Sel));
140
          if( Tick_Trig = '1' and Enable_Parity )then
141
            Tx_Parity        <= Tx_Parity xor Tx_Buffer(conv_integer(Tx_Bit_Sel));
142
          end if;
143
 
144
        when IO_PARI =>
145
          if( Enable_Parity )then
146
            Tx_Out           <= Tx_Parity;
147
          end if;
148
 
149
        when IO_STOP =>
150
 
151
        when IO_DONE =>
152
          Tx_Done            <= '1';
153
          Tx_Enable          <= '0';
154
          Tx_State           <= IO_IDLE;
155
 
156
        when others =>
157
 
158
      end case;
159
 
160
      if( Tx_Enable = '0' )then
161
        Tx_State             <= IO_IDLE;
162
      end if;
163
 
164
    end if;
165
  end process;
166
 
167
end architecture;

powered by: WebSVN 2.1.0

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