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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [uart.vhd] - Diff between revs 48 and 55

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 48 Rev 55
Line 6... Line 6...
-- PROJECT: Plasma CPU core
-- PROJECT: Plasma CPU core
-- COPYRIGHT: Software placed into the public domain by the author.
-- COPYRIGHT: Software placed into the public domain by the author.
--    Software 'as is' without warranty.  Author liable for nothing.
--    Software 'as is' without warranty.  Author liable for nothing.
-- DESCRIPTION:
-- DESCRIPTION:
--    Implements the UART.
--    Implements the UART.
 
--    Stalls the CPU until the charater has been transmitted.
---------------------------------------------------------------------
---------------------------------------------------------------------
library ieee;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
use ieee.std_logic_misc.all;
use ieee.std_logic_misc.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_arith.all;
Line 29... Line 30...
        uart_write : out std_logic;
        uart_write : out std_logic;
        pause      : out std_logic);
        pause      : out std_logic);
end; --entity ram
end; --entity ram
 
 
architecture logic of uart is
architecture logic of uart is
   signal uart_data_reg : std_logic_vector(8 downto 0);
   signal data_reg : std_logic_vector(8 downto 0);
   signal uart_bits_reg : std_logic_vector(3 downto 0);
   signal bits_reg : std_logic_vector(3 downto 0);
   signal uart_div_reg  : std_logic_vector(7 downto 0);
   signal div_reg  : std_logic_vector(9 downto 0);
begin
begin
 
 
uart_proc: process(clk, reset, uart_sel, data,
uart_proc: process(clk, reset, data_reg, bits_reg, div_reg, uart_sel, data)
      uart_data_reg, uart_bits_reg, uart_div_reg)
   constant DIV_VALUE : std_logic_vector(9 downto 0) :=
   variable uart_data_next : std_logic_vector(8 downto 0);
      "0100011110";  --33MHz/2/57600Hz = 0x11e
   variable uart_bits_next : std_logic_vector(3 downto 0);
--      "0000000010";  --for debug
   variable uart_div_next  : std_logic_vector(7 downto 0);
   variable data_next : std_logic_vector(8 downto 0);
 
   variable bits_next : std_logic_vector(3 downto 0);
 
   variable div_next  : std_logic_vector(9 downto 0);
begin
begin
   uart_data_next := uart_data_reg;
   data_next := data_reg;
   uart_bits_next := uart_bits_reg;
   bits_next := bits_reg;
   uart_div_next  := uart_div_reg;
   div_next  := div_reg;
 
 
   if uart_bits_reg = "0000" and uart_sel = '1' then
   if uart_sel = '1' then
      uart_data_next := data & '0';
      data_next := data & '0';
      uart_bits_next := "1010";
      bits_next := "1010";
      uart_div_next := ZERO(7 downto 0);
      div_next  := ZERO(9 downto 0);
   elsif uart_bits_reg /= "0000" and
   elsif div_reg = DIV_VALUE then
         ((log_file /= "UNUSED" and uart_div_reg = "00000010") or
      data_next := '1' & data_reg(8 downto 1);
         (log_file = "UNUSED" and uart_div_reg = "10001100")) then
      if bits_reg /= "0000" then
      uart_data_next := '1' & uart_data_reg(8 downto 1);
         bits_next := bits_reg - 1;
      uart_bits_next := uart_bits_reg - 1;
      end if;
      uart_div_next := ZERO(7 downto 0);
      div_next  := ZERO(9 downto 0);
   else
   else
      uart_div_next := uart_div_reg + 1;
      div_next := div_reg + 1;
   end if;
   end if;
 
 
   if reset = '1' then
   if reset = '1' then
      uart_data_next := ONES(8 downto 0);
      data_reg <= ZERO(8 downto 0);
      uart_bits_next := "0000";
      bits_reg <= "0000";
      uart_div_next := ZERO(7 downto 0);
      div_reg <= ZERO(9 downto 0);
 
   elsif rising_edge(clk) then
 
      data_reg <= data_next;
 
      bits_reg <= bits_next;
 
      div_reg  <= div_next;
   end if;
   end if;
 
 
   if rising_edge(clk) then
   uart_write <= data_reg(0);
      uart_data_reg <= uart_data_next;
   if uart_sel = '0' and bits_reg /= "0000"
      uart_bits_reg <= uart_bits_next;
         and log_file = "UNUSED"
      uart_div_reg <= uart_div_next;
         then
   end if;
 
 
 
   uart_write <= uart_data_reg(0);
 
   if uart_bits_reg = ZERO(7 downto 0) or uart_sel = '1' then
 
      pause <= '0';
 
   elsif log_file = "UNUSED" then
 
      pause <= '1';
      pause <= '1';
   else
   else
--      pause <= '1';
 
      pause <= '0';
      pause <= '0';
   end if;
   end if;
end process;
end process;
 
 
   uart_logger:
   uart_logger:
Line 99... Line 99...
                  c := character'val(index);
                  c := character'val(index);
                  write(hex_file_line, c);
                  write(hex_file_line, c);
                  line_length := line_length + 1;
                  line_length := line_length + 1;
               end if;
               end if;
               if index = 10 or line_length >= 72 then
               if index = 10 or line_length >= 72 then
 
--The following line had to be commented out for synthesis
                  writeline(store_file, hex_file_line);
                  writeline(store_file, hex_file_line);
                  line_length := 0;
                  line_length := 0;
               end if;
               end if;
            end if; --uart_sel
            end if; --uart_sel
         end if; --rising_edge(clk)
         end if; --rising_edge(clk)

powered by: WebSVN 2.1.0

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