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

Subversion Repositories uart2bus

[/] [uart2bus/] [trunk/] [vhdl/] [rtl/] [uartTx.vhd] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 smuller
-----------------------------------------------------------------------------------------
2
-- uart transmit module  
3
--
4
-----------------------------------------------------------------------------------------
5 11 smuller
library ieee;
6
use ieee.std_logic_1164.all;
7 13 smuller
use ieee.numeric_std.all;
8 6 smuller
 
9
entity uartTx is
10
  port ( clr       : in  std_logic;                    -- global reset input
11
         clk       : in  std_logic;                    -- global clock input
12
         ce16      : in  std_logic;                    -- baud rate multiplyed by 16 - generated by baud module
13
         txData    : in  std_logic_vector(7 downto 0); -- data byte to transmit
14
         newTxData : in  std_logic;                    -- asserted to indicate that there is a new data byte for transmission
15
         serOut    : out std_logic;                    -- serial data output
16
         txBusy    : out std_logic);                   -- signs that transmitter is busy
17
end uartTx;
18
 
19
architecture Behavioral of uartTx is
20
 
21
  signal iTxBusy  : std_logic;
22
  signal ce1      : std_logic; -- clock enable at bit rate
23
  signal count16  : std_logic_vector(3 downto 0);
24
  signal bitCount : std_logic_vector(3 downto 0);
25
  signal dataBuf  : std_logic_vector(8 downto 0);
26
 
27
  begin
28
    -- a counter to count 16 pulses of ce_16 to generate the ce_1 pulse
29
    process (clr, clk)
30
    begin
31
      if (clr = '1') then
32
        count16 <= (others => '0');
33
      elsif (rising_edge(clk)) then
34
        if ((iTxBusy = '1') and (ce16 = '1')) then
35 13 smuller
          count16 <= std_logic_vector(unsigned(count16) + 1);
36 6 smuller
        elsif (iTxBusy = '0') then
37
          count16 <= (others => '0');
38
        end if;
39
      end if;
40
    end process;
41
    -- tx_busy flag
42
    process (clr, clk)
43
    begin
44
      if (clr = '1') then
45
        iTxBusy <= '0';
46
      elsif (rising_edge(clk)) then
47
        if ((iTxBusy = '0') and (newTxData = '1')) then
48
          iTxBusy <= '1';
49 10 smuller
        elsif ((iTxBusy = '1') and (bitCount = "1001") and (ce1 = '1')) then
50 6 smuller
          iTxBusy <= '0';
51
        end if;
52
      end if;
53
    end process;
54
    -- output bit counter
55
    process (clr, clk)
56
    begin
57
      if (clr = '1') then
58
        bitCount <= (others => '0');
59
      elsif (rising_edge(clk)) then
60
        if ((iTxBusy = '1') and (ce1 = '1')) then
61 13 smuller
          bitCount <= std_logic_vector(unsigned(bitCount) + 1);
62 6 smuller
        elsif (iTxBusy = '0') then
63
          bitCount <= (others => '0');
64
        end if;
65
      end if;
66
    end process;
67
    -- data shift register
68
    process (clr, clk)
69
    begin
70
      if (clr = '1') then
71
        dataBuf <= (others => '0');
72
      elsif (rising_edge(clk)) then
73
        if (iTxBusy = '0') then
74
          dataBuf <= txData & '0';
75
        elsif ((iTxBusy = '1') and (ce1 = '1')) then
76
          dataBuf <= '1' & dataBuf(8 downto 1);
77
        end if;
78
      end if;
79
    end process;
80
    -- output data bit
81
    process (clr, clk)
82
    begin
83
      if (clr = '1') then
84
        serOut <= '1';
85
      elsif (rising_edge(clk)) then
86
        if (iTxBusy = '1') then
87
          serOut <= dataBuf(0);
88
        else
89
          serOut <= '1';
90
        end if;
91
      end if;
92
    end process;
93
    -- ce_1 pulse indicating output data bit should be updated
94
    ce1 <= '1' when ((count16 = "1111") and (ce16 = '1')) else '0';
95
    txBusy <= iTxBusy;
96
  end Behavioral;

powered by: WebSVN 2.1.0

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