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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [uart.vhd] - Blame information for rev 55

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

Line No. Rev Author Line
1 47 rhoads
---------------------------------------------------------------------
2
-- TITLE: UART
3
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 5/29/02
5
-- FILENAME: uart.vhd
6
-- PROJECT: Plasma CPU core
7
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- DESCRIPTION:
10
--    Implements the UART.
11 55 rhoads
--    Stalls the CPU until the charater has been transmitted.
12 47 rhoads
---------------------------------------------------------------------
13
library ieee;
14
use ieee.std_logic_1164.all;
15
use ieee.std_logic_misc.all;
16
use ieee.std_logic_arith.all;
17
use ieee.std_logic_textio.all;
18
use std.textio.all;
19
 
20
use ieee.std_logic_unsigned.all;
21
use work.mlite_pack.all;
22
 
23
entity uart is
24 48 rhoads
   generic(log_file : string := "UNUSED");
25
   port(clk        : in std_logic;
26
        reset      : in std_logic;
27
        uart_sel   : in std_logic;
28
        data       : in std_logic_vector(7 downto 0);
29
        uart_read  : in std_logic;
30
        uart_write : out std_logic;
31
        pause      : out std_logic);
32 47 rhoads
end; --entity ram
33
 
34
architecture logic of uart is
35 55 rhoads
   signal data_reg : std_logic_vector(8 downto 0);
36
   signal bits_reg : std_logic_vector(3 downto 0);
37
   signal div_reg  : std_logic_vector(9 downto 0);
38 48 rhoads
begin
39 47 rhoads
 
40 55 rhoads
uart_proc: process(clk, reset, data_reg, bits_reg, div_reg, uart_sel, data)
41
   constant DIV_VALUE : std_logic_vector(9 downto 0) :=
42
      "0100011110";  --33MHz/2/57600Hz = 0x11e
43
--      "0000000010";  --for debug
44
   variable data_next : std_logic_vector(8 downto 0);
45
   variable bits_next : std_logic_vector(3 downto 0);
46
   variable div_next  : std_logic_vector(9 downto 0);
47 47 rhoads
begin
48 55 rhoads
   data_next := data_reg;
49
   bits_next := bits_reg;
50
   div_next  := div_reg;
51 47 rhoads
 
52 55 rhoads
   if uart_sel = '1' then
53
      data_next := data & '0';
54
      bits_next := "1010";
55
      div_next  := ZERO(9 downto 0);
56
   elsif div_reg = DIV_VALUE then
57
      data_next := '1' & data_reg(8 downto 1);
58
      if bits_reg /= "0000" then
59
         bits_next := bits_reg - 1;
60
      end if;
61
      div_next  := ZERO(9 downto 0);
62 47 rhoads
   else
63 55 rhoads
      div_next := div_reg + 1;
64 47 rhoads
   end if;
65
 
66
   if reset = '1' then
67 55 rhoads
      data_reg <= ZERO(8 downto 0);
68
      bits_reg <= "0000";
69
      div_reg <= ZERO(9 downto 0);
70
   elsif rising_edge(clk) then
71
      data_reg <= data_next;
72
      bits_reg <= bits_next;
73
      div_reg  <= div_next;
74 47 rhoads
   end if;
75
 
76 55 rhoads
   uart_write <= data_reg(0);
77
   if uart_sel = '0' and bits_reg /= "0000"
78
         and log_file = "UNUSED"
79
         then
80 48 rhoads
      pause <= '1';
81 47 rhoads
   else
82 48 rhoads
      pause <= '0';
83 47 rhoads
   end if;
84
end process;
85
 
86 48 rhoads
   uart_logger:
87
   if log_file /= "UNUSED" generate
88
      uart_proc: process(clk, uart_sel, data)
89
         file store_file : text is out log_file;
90
         variable hex_file_line : line;
91
         variable c : character;
92
         variable index : natural;
93
         variable line_length : natural := 0;
94
      begin
95
         if rising_edge(clk) then
96
            if uart_sel = '1' then
97
               index := conv_integer(data(6 downto 0));
98
               if index /= 10 then
99
                  c := character'val(index);
100
                  write(hex_file_line, c);
101
                  line_length := line_length + 1;
102
               end if;
103
               if index = 10 or line_length >= 72 then
104 55 rhoads
--The following line had to be commented out for synthesis
105 48 rhoads
                  writeline(store_file, hex_file_line);
106
                  line_length := 0;
107
               end if;
108
            end if; --uart_sel
109
         end if; --rising_edge(clk)
110
      end process; --uart_proc
111
   end generate; --uart_logger
112
 
113 47 rhoads
end; --architecture logic
114
 

powered by: WebSVN 2.1.0

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