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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [vhdl/] [uart.vhd] - Blame information for rev 48

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
---------------------------------------------------------------------
12
library ieee;
13
use ieee.std_logic_1164.all;
14
use ieee.std_logic_misc.all;
15
use ieee.std_logic_arith.all;
16
use ieee.std_logic_textio.all;
17
use std.textio.all;
18
 
19
use ieee.std_logic_unsigned.all;
20
use work.mlite_pack.all;
21
 
22
entity uart is
23 48 rhoads
   generic(log_file : string := "UNUSED");
24
   port(clk        : in std_logic;
25
        reset      : in std_logic;
26
        uart_sel   : in std_logic;
27
        data       : in std_logic_vector(7 downto 0);
28
        uart_read  : in std_logic;
29
        uart_write : out std_logic;
30
        pause      : out std_logic);
31 47 rhoads
end; --entity ram
32
 
33
architecture logic of uart is
34
   signal uart_data_reg : std_logic_vector(8 downto 0);
35
   signal uart_bits_reg : std_logic_vector(3 downto 0);
36
   signal uart_div_reg  : std_logic_vector(7 downto 0);
37 48 rhoads
begin
38 47 rhoads
 
39
uart_proc: process(clk, reset, uart_sel, data,
40
      uart_data_reg, uart_bits_reg, uart_div_reg)
41
   variable uart_data_next : std_logic_vector(8 downto 0);
42
   variable uart_bits_next : std_logic_vector(3 downto 0);
43
   variable uart_div_next  : std_logic_vector(7 downto 0);
44
begin
45
   uart_data_next := uart_data_reg;
46
   uart_bits_next := uart_bits_reg;
47
   uart_div_next  := uart_div_reg;
48
 
49
   if uart_bits_reg = "0000" and uart_sel = '1' then
50 48 rhoads
      uart_data_next := data & '0';
51
      uart_bits_next := "1010";
52 47 rhoads
      uart_div_next := ZERO(7 downto 0);
53 48 rhoads
   elsif uart_bits_reg /= "0000" and
54
         ((log_file /= "UNUSED" and uart_div_reg = "00000010") or
55
         (log_file = "UNUSED" and uart_div_reg = "10001100")) then
56
      uart_data_next := '1' & uart_data_reg(8 downto 1);
57 47 rhoads
      uart_bits_next := uart_bits_reg - 1;
58
      uart_div_next := ZERO(7 downto 0);
59
   else
60
      uart_div_next := uart_div_reg + 1;
61
   end if;
62
 
63
   if reset = '1' then
64 48 rhoads
      uart_data_next := ONES(8 downto 0);
65 47 rhoads
      uart_bits_next := "0000";
66
      uart_div_next := ZERO(7 downto 0);
67
   end if;
68
 
69
   if rising_edge(clk) then
70
      uart_data_reg <= uart_data_next;
71
      uart_bits_reg <= uart_bits_next;
72
      uart_div_reg <= uart_div_next;
73
   end if;
74
 
75 48 rhoads
   uart_write <= uart_data_reg(0);
76 47 rhoads
   if uart_bits_reg = ZERO(7 downto 0) or uart_sel = '1' then
77 48 rhoads
      pause <= '0';
78
   elsif log_file = "UNUSED" then
79
      pause <= '1';
80 47 rhoads
   else
81
--      pause <= '1';
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
                  writeline(store_file, hex_file_line);
105
                  line_length := 0;
106
               end if;
107
            end if; --uart_sel
108
         end if; --rising_edge(clk)
109
      end process; --uart_proc
110
   end generate; --uart_logger
111
 
112 47 rhoads
end; --architecture logic
113
 

powered by: WebSVN 2.1.0

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