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

Subversion Repositories uart2bus

[/] [uart2bus/] [trunk/] [vhdl/] [rtl/] [uartTx.vhd] - Diff between revs 6 and 10

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 6 Rev 10
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-- uart transmit module  
-- uart transmit module  
--
--
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
library IEEE;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
 
entity uartTx is
entity uartTx is
  port ( clr       : in  std_logic;                    -- global reset input
  port ( clr       : in  std_logic;                    -- global reset input
         clk       : in  std_logic;                    -- global clock input
         clk       : in  std_logic;                    -- global clock input
         ce16      : in  std_logic;                    -- baud rate multiplyed by 16 - generated by baud module
         ce16      : in  std_logic;                    -- baud rate multiplyed by 16 - generated by baud module
         txData    : in  std_logic_vector(7 downto 0); -- data byte to transmit
         txData    : in  std_logic_vector(7 downto 0); -- data byte to transmit
         newTxData : in  std_logic;                    -- asserted to indicate that there is a new data byte for transmission
         newTxData : in  std_logic;                    -- asserted to indicate that there is a new data byte for transmission
         serOut    : out std_logic;                    -- serial data output
         serOut    : out std_logic;                    -- serial data output
         txBusy    : out std_logic);                   -- signs that transmitter is busy
         txBusy    : out std_logic);                   -- signs that transmitter is busy
end uartTx;
end uartTx;
 
 
architecture Behavioral of uartTx is
architecture Behavioral of uartTx is
 
 
  signal iTxBusy  : std_logic;
  signal iTxBusy  : std_logic;
  signal ce1      : std_logic; -- clock enable at bit rate
  signal ce1      : std_logic; -- clock enable at bit rate
  signal count16  : std_logic_vector(3 downto 0);
  signal count16  : std_logic_vector(3 downto 0);
  signal bitCount : std_logic_vector(3 downto 0);
  signal bitCount : std_logic_vector(3 downto 0);
  signal dataBuf  : std_logic_vector(8 downto 0);
  signal dataBuf  : std_logic_vector(8 downto 0);
 
 
  begin
  begin
    -- a counter to count 16 pulses of ce_16 to generate the ce_1 pulse
    -- a counter to count 16 pulses of ce_16 to generate the ce_1 pulse
    process (clr, clk)
    process (clr, clk)
    begin
    begin
      if (clr = '1') then
      if (clr = '1') then
        count16 <= (others => '0');
        count16 <= (others => '0');
      elsif (rising_edge(clk)) then
      elsif (rising_edge(clk)) then
        if ((iTxBusy = '1') and (ce16 = '1')) then
        if ((iTxBusy = '1') and (ce16 = '1')) then
          count16 <= count16 + 1;
          count16 <= count16 + 1;
        elsif (iTxBusy = '0') then
        elsif (iTxBusy = '0') then
          count16 <= (others => '0');
          count16 <= (others => '0');
        end if;
        end if;
      end if;
      end if;
    end process;
    end process;
    -- tx_busy flag
    -- tx_busy flag
    process (clr, clk)
    process (clr, clk)
    begin
    begin
      if (clr = '1') then
      if (clr = '1') then
        iTxBusy <= '0';
        iTxBusy <= '0';
      elsif (rising_edge(clk)) then
      elsif (rising_edge(clk)) then
        if ((iTxBusy = '0') and (newTxData = '1')) then
        if ((iTxBusy = '0') and (newTxData = '1')) then
          iTxBusy <= '1';
          iTxBusy <= '1';
        elsif ((iTxBusy = '1') and (bitCount = "1010") and (ce1 = '1')) then
        elsif ((iTxBusy = '1') and (bitCount = "1001") and (ce1 = '1')) then
          iTxBusy <= '0';
          iTxBusy <= '0';
        end if;
        end if;
      end if;
      end if;
    end process;
    end process;
    -- output bit counter
    -- output bit counter
    process (clr, clk)
    process (clr, clk)
    begin
    begin
      if (clr = '1') then
      if (clr = '1') then
        bitCount <= (others => '0');
        bitCount <= (others => '0');
      elsif (rising_edge(clk)) then
      elsif (rising_edge(clk)) then
        if ((iTxBusy = '1') and (ce1 = '1')) then
        if ((iTxBusy = '1') and (ce1 = '1')) then
          bitCount <= bitCount + 1;
          bitCount <= bitCount + 1;
        elsif (iTxBusy = '0') then
        elsif (iTxBusy = '0') then
          bitCount <= (others => '0');
          bitCount <= (others => '0');
        end if;
        end if;
      end if;
      end if;
    end process;
    end process;
    -- data shift register
    -- data shift register
    process (clr, clk)
    process (clr, clk)
    begin
    begin
      if (clr = '1') then
      if (clr = '1') then
        dataBuf <= (others => '0');
        dataBuf <= (others => '0');
      elsif (rising_edge(clk)) then
      elsif (rising_edge(clk)) then
        if (iTxBusy = '0') then
        if (iTxBusy = '0') then
          dataBuf <= txData & '0';
          dataBuf <= txData & '0';
        elsif ((iTxBusy = '1') and (ce1 = '1')) then
        elsif ((iTxBusy = '1') and (ce1 = '1')) then
          dataBuf <= '1' & dataBuf(8 downto 1);
          dataBuf <= '1' & dataBuf(8 downto 1);
        end if;
        end if;
      end if;
      end if;
    end process;
    end process;
    -- output data bit
    -- output data bit
    process (clr, clk)
    process (clr, clk)
    begin
    begin
      if (clr = '1') then
      if (clr = '1') then
        serOut <= '1';
        serOut <= '1';
      elsif (rising_edge(clk)) then
      elsif (rising_edge(clk)) then
        if (iTxBusy = '1') then
        if (iTxBusy = '1') then
          serOut <= dataBuf(0);
          serOut <= dataBuf(0);
        else
        else
          serOut <= '1';
          serOut <= '1';
        end if;
        end if;
      end if;
      end if;
    end process;
    end process;
    -- ce_1 pulse indicating output data bit should be updated
    -- ce_1 pulse indicating output data bit should be updated
    ce1 <= '1' when ((count16 = "1111") and (ce16 = '1')) else '0';
    ce1 <= '1' when ((count16 = "1111") and (ce16 = '1')) else '0';
    txBusy <= iTxBusy;
    txBusy <= iTxBusy;
  end Behavioral;
  end Behavioral;
 
 

powered by: WebSVN 2.1.0

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