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

Subversion Repositories uart16750

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

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 25 hasw
USE IEEE.numeric_std.all;
27 2 hasw
use std.textio.all;
28
 
29
use work.txt_util.all;
30
 
31
 
32
package uart_package is
33
    constant CYCLE  : time := 30 ns;
34
 
35
    -- UART register addresses
36
    constant A_RBR  : std_logic_vector(2 downto 0) := "000";
37
    constant A_DLL  : std_logic_vector(2 downto 0) := "000";
38
    constant A_THR  : std_logic_vector(2 downto 0) := "000";
39
    constant A_DLM  : std_logic_vector(2 downto 0) := "001";
40
    constant A_IER  : std_logic_vector(2 downto 0) := "001";
41
    constant A_IIR  : std_logic_vector(2 downto 0) := "010";
42
    constant A_FCR  : std_logic_vector(2 downto 0) := "010";
43
    constant A_LCR  : std_logic_vector(2 downto 0) := "011";
44
    constant A_MCR  : std_logic_vector(2 downto 0) := "100";
45
    constant A_LSR  : std_logic_vector(2 downto 0) := "101";
46
    constant A_MSR  : std_logic_vector(2 downto 0) := "110";
47
    constant A_SCR  : std_logic_vector(2 downto 0) := "111";
48
 
49
    -- UART input interface
50
    type uart_interface is record
51
        CS      : std_logic;
52
        WR      : std_logic;
53
        RD      : std_logic;
54
        A       : std_logic_vector (2 downto 0);
55
        DATA    : std_logic_vector (7 downto 0);
56
    end record;
57
 
58
    -- Write to UART
59
    procedure uart_write (signal ui : inout uart_interface;
60
                          addr      : in std_logic_vector (2 downto 0);
61
                          data      : in std_logic_vector (7 downto 0);
62
                          file log  : TEXT
63
                         );
64
 
65
    -- Read from UART
66
    procedure uart_read  (signal ui : inout uart_interface;
67
                          addr      : in std_logic_vector(2 downto 0);
68
                          ret       : out std_logic_vector(7 downto 0);
69
                          file log  : TEXT
70
                         );
71
 
72
    -- Compare two std_logig_vectors (handles don't-care)
73
    function compare (d1 : std_logic_vector; d2 : std_logic_vector) return boolean;
74
 
75 25 hasw
    -- Send serial data to UART
76
    procedure uart_send  (signal sout   : out std_logic;
77
                          baud          : in time;
78
                          wl            : in integer;
79
                          count         : in integer;
80
                          file log      : TEXT
81
                         );
82 2 hasw
end uart_package;
83
 
84
package body uart_package is
85
    -- Write to UART
86
    procedure uart_write (signal ui : inout uart_interface;
87
                          addr      : in std_logic_vector (2 downto 0);
88
                          data      : in std_logic_vector (7 downto 0);
89
                          file log  : TEXT
90
                         ) is
91
    begin
92
        print (log, "UART write: 0x" & hstr(addr) & " : 0x" & hstr(data));
93
        wait for cycle;
94
        assert ui.DATA = "ZZZZZZZZ" report "Data bus not tri-state" severity warning;
95
        ui.A     <= addr;
96
        ui.DATA  <= data;
97
        ui.CS    <= '1';
98
        wait for cycle;
99
        ui.WR   <= '1';
100
        wait for cycle;
101
        ui.WR   <= '0';
102
        ui.CS   <= '0';
103
        ui.DATA <= (others => 'Z');
104
    end uart_write;
105
 
106
    -- Read from UART
107
    procedure uart_read  (signal ui : inout uart_interface;
108
                          addr      : in std_logic_vector(2 downto 0);
109
                          ret       : out std_logic_vector(7 downto 0);
110
                          file log  : TEXT
111
                         ) is
112
        variable data : std_logic_vector(7 downto 0);
113
    begin
114
        wait for cycle;
115
        assert ui.DATA = "ZZZZZZZZ" report "Data bus not tri-state" severity warning;
116
        ui.A    <= addr;
117
        ui.CS   <= '1';
118
        wait for cycle;
119
        ui.RD   <= '1';
120
        wait for cycle;
121
        data    := ui.DATA;
122
        wait for cycle;
123
        ui.RD   <= '0';
124
        ui.CS   <= '0';
125
        print (log, "UART read:  0x" & hstr(addr) & " : 0x" & hstr(data));
126
        ret     := data;
127
    end uart_read;
128
 
129
    -- Compare two std_logig_vectors (handles don't-care)
130
    function compare (d1 : std_logic_vector; d2 : std_logic_vector) return boolean is
131
        variable i : natural;
132
    begin
133
        for i in d1'range loop
134
            if (not (d1(i)='-' or d2(i)='-')) then
135
                if (d1(i)/=d2(i)) then
136
                    return false;
137
                end if;
138
            end if;
139
        end loop;
140
        return true;
141
    end compare;
142
 
143 25 hasw
    -- Send serial data to UART
144
    procedure uart_send  (signal sout   : out std_logic;
145
                          baud          : in time;
146
                          wl            : in integer;
147
                          count         : in integer;
148
                          file log      : TEXT
149
                         ) is
150
        variable data : unsigned(7 downto 0);
151
    begin
152
        print (log, "UART send:  Sending " & integer'image(count) & " symbols with " & integer'image(wl) & " bits");
153
 
154
        data := (others => '0');
155
 
156
        for i in 0 to count loop
157
 
158
            -- Start bit
159
            sout <= '0';
160
            wait for baud;
161
 
162
            for i in 0 to wl loop
163
                sout <= data(i);
164
                wait for baud;
165
            end loop;
166
 
167
            -- Stop bit
168
            sout <= '1';
169
            wait for baud;
170
 
171
            data := data + 1;
172
        end loop;
173
 
174
    end uart_send;
175 2 hasw
end uart_package;
176
 

powered by: WebSVN 2.1.0

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