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

Subversion Repositories plasma

[/] [plasma/] [tags/] [V2_1/] [vhdl/] [uart.vhd] - Blame information for rev 415

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 75 rhoads
use ieee.std_logic_unsigned.all;
19 47 rhoads
use std.textio.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 55 rhoads
   signal data_reg : std_logic_vector(8 downto 0);
35
   signal bits_reg : std_logic_vector(3 downto 0);
36
   signal div_reg  : std_logic_vector(9 downto 0);
37 48 rhoads
begin
38 47 rhoads
 
39 55 rhoads
uart_proc: process(clk, reset, data_reg, bits_reg, div_reg, uart_sel, data)
40
   constant DIV_VALUE : std_logic_vector(9 downto 0) :=
41
      "0100011110";  --33MHz/2/57600Hz = 0x11e
42
--      "0000000010";  --for debug
43
   variable data_next : std_logic_vector(8 downto 0);
44
   variable bits_next : std_logic_vector(3 downto 0);
45
   variable div_next  : std_logic_vector(9 downto 0);
46 47 rhoads
begin
47 55 rhoads
   data_next := data_reg;
48
   bits_next := bits_reg;
49
   div_next  := div_reg;
50 47 rhoads
 
51 55 rhoads
   if uart_sel = '1' then
52
      data_next := data & '0';
53
      bits_next := "1010";
54
      div_next  := ZERO(9 downto 0);
55
   elsif div_reg = DIV_VALUE then
56
      data_next := '1' & data_reg(8 downto 1);
57
      if bits_reg /= "0000" then
58
         bits_next := bits_reg - 1;
59
      end if;
60
      div_next  := ZERO(9 downto 0);
61 47 rhoads
   else
62 55 rhoads
      div_next := div_reg + 1;
63 47 rhoads
   end if;
64
 
65
   if reset = '1' then
66 55 rhoads
      data_reg <= ZERO(8 downto 0);
67
      bits_reg <= "0000";
68
      div_reg <= ZERO(9 downto 0);
69
   elsif rising_edge(clk) then
70
      data_reg <= data_next;
71
      bits_reg <= bits_next;
72
      div_reg  <= div_next;
73 47 rhoads
   end if;
74
 
75 55 rhoads
   uart_write <= data_reg(0);
76
   if uart_sel = '0' and bits_reg /= "0000"
77
         and log_file = "UNUSED"
78
         then
79 48 rhoads
      pause <= '1';
80 47 rhoads
   else
81 48 rhoads
      pause <= '0';
82 47 rhoads
   end if;
83
end process;
84
 
85 48 rhoads
   uart_logger:
86
   if log_file /= "UNUSED" generate
87
      uart_proc: process(clk, uart_sel, data)
88
         file store_file : text is out log_file;
89
         variable hex_file_line : line;
90
         variable c : character;
91
         variable index : natural;
92
         variable line_length : natural := 0;
93
      begin
94
         if rising_edge(clk) then
95
            if uart_sel = '1' then
96
               index := conv_integer(data(6 downto 0));
97
               if index /= 10 then
98
                  c := character'val(index);
99
                  write(hex_file_line, c);
100
                  line_length := line_length + 1;
101
               end if;
102
               if index = 10 or line_length >= 72 then
103 55 rhoads
--The following line had to be commented out for synthesis
104 48 rhoads
                  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.