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

Subversion Repositories uart16750

[/] [uart16750/] [trunk/] [bench/] [vhdl/] [uart_package.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 hasw
--
2
-- Package for UART testing
3
--
4
-- Author:  Sebastian Witt
5
-- Version: 1.0
6
-- Date:    31.01.2008
7
--
8
-- This code is free software; you can redistribute it and/or
9
-- modify it under the terms of the GNU Lesser General Public
10
-- License as published by the Free Software Foundation; either
11
-- version 2.1 of the License, or (at your option) any later version.
12
--
13
-- This code is distributed in the hope that it will be useful,
14
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
-- Lesser General Public License for more details.
17
--
18
-- You should have received a copy of the GNU Lesser General Public
19
-- License along with this library; if not, write to the
20
-- Free Software  Foundation, Inc., 59 Temple Place, Suite 330,
21
-- Boston, MA  02111-1307  USA
22
--
23
 
24
LIBRARY IEEE;
25
USE IEEE.std_logic_1164.all;
26
use std.textio.all;
27
 
28
use work.txt_util.all;
29
 
30
 
31
package uart_package is
32
    constant CYCLE  : time := 30 ns;
33
 
34
    -- UART register addresses
35
    constant A_RBR  : std_logic_vector(2 downto 0) := "000";
36
    constant A_DLL  : std_logic_vector(2 downto 0) := "000";
37
    constant A_THR  : std_logic_vector(2 downto 0) := "000";
38
    constant A_DLM  : std_logic_vector(2 downto 0) := "001";
39
    constant A_IER  : std_logic_vector(2 downto 0) := "001";
40
    constant A_IIR  : std_logic_vector(2 downto 0) := "010";
41
    constant A_FCR  : std_logic_vector(2 downto 0) := "010";
42
    constant A_LCR  : std_logic_vector(2 downto 0) := "011";
43
    constant A_MCR  : std_logic_vector(2 downto 0) := "100";
44
    constant A_LSR  : std_logic_vector(2 downto 0) := "101";
45
    constant A_MSR  : std_logic_vector(2 downto 0) := "110";
46
    constant A_SCR  : std_logic_vector(2 downto 0) := "111";
47
 
48
    -- UART input interface
49
    type uart_interface is record
50
        CS      : std_logic;
51
        WR      : std_logic;
52
        RD      : std_logic;
53
        A       : std_logic_vector (2 downto 0);
54
        DATA    : std_logic_vector (7 downto 0);
55
    end record;
56
 
57
    -- Write to UART
58
    procedure uart_write (signal ui : inout uart_interface;
59
                          addr      : in std_logic_vector (2 downto 0);
60
                          data      : in std_logic_vector (7 downto 0);
61
                          file log  : TEXT
62
                         );
63
 
64
    -- Read from UART
65
    procedure uart_read  (signal ui : inout uart_interface;
66
                          addr      : in std_logic_vector(2 downto 0);
67
                          ret       : out std_logic_vector(7 downto 0);
68
                          file log  : TEXT
69
                         );
70
 
71
    -- Compare two std_logig_vectors (handles don't-care)
72
    function compare (d1 : std_logic_vector; d2 : std_logic_vector) return boolean;
73
 
74
end uart_package;
75
 
76
package body uart_package is
77
    -- Write to UART
78
    procedure uart_write (signal ui : inout uart_interface;
79
                          addr      : in std_logic_vector (2 downto 0);
80
                          data      : in std_logic_vector (7 downto 0);
81
                          file log  : TEXT
82
                         ) is
83
    begin
84
        print (log, "UART write: 0x" & hstr(addr) & " : 0x" & hstr(data));
85
        wait for cycle;
86
        assert ui.DATA = "ZZZZZZZZ" report "Data bus not tri-state" severity warning;
87
        ui.A     <= addr;
88
        ui.DATA  <= data;
89
        ui.CS    <= '1';
90
        wait for cycle;
91
        ui.WR   <= '1';
92
        wait for cycle;
93
        ui.WR   <= '0';
94
        ui.CS   <= '0';
95
        ui.DATA <= (others => 'Z');
96
    end uart_write;
97
 
98
    -- Read from UART
99
    procedure uart_read  (signal ui : inout uart_interface;
100
                          addr      : in std_logic_vector(2 downto 0);
101
                          ret       : out std_logic_vector(7 downto 0);
102
                          file log  : TEXT
103
                         ) is
104
        variable data : std_logic_vector(7 downto 0);
105
    begin
106
        wait for cycle;
107
        assert ui.DATA = "ZZZZZZZZ" report "Data bus not tri-state" severity warning;
108
        ui.A    <= addr;
109
        ui.CS   <= '1';
110
        wait for cycle;
111
        ui.RD   <= '1';
112
        wait for cycle;
113
        data    := ui.DATA;
114
        wait for cycle;
115
        ui.RD   <= '0';
116
        ui.CS   <= '0';
117
        print (log, "UART read:  0x" & hstr(addr) & " : 0x" & hstr(data));
118
        ret     := data;
119
    end uart_read;
120
 
121
    -- Compare two std_logig_vectors (handles don't-care)
122
    function compare (d1 : std_logic_vector; d2 : std_logic_vector) return boolean is
123
        variable i : natural;
124
    begin
125
        for i in d1'range loop
126
            if (not (d1(i)='-' or d2(i)='-')) then
127
                if (d1(i)/=d2(i)) then
128
                    return false;
129
                end if;
130
            end if;
131
        end loop;
132
        return true;
133
    end compare;
134
 
135
end uart_package;
136
 

powered by: WebSVN 2.1.0

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