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

Subversion Repositories uart16750

[/] [uart16750/] [trunk/] [bench/] [vhdl/] [uart_transactor.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
-- UART transactor
2
--
3
-- Author:   Sebastian Witt
4
-- Date:     03.02.2008
5
-- Version:  1.0
6
--
7
-- This code is free software; you can redistribute it and/or
8
-- modify it under the terms of the GNU Lesser General Public
9
-- License as published by the Free Software Foundation; either
10
-- version 2.1 of the License, or (at your option) any later version.
11
--
12
-- This code is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
-- Lesser General Public License for more details.
16
--
17
-- You should have received a copy of the GNU Lesser General Public
18
-- License along with this library; if not, write to the
19
-- Free Software  Foundation, Inc., 59 Temple Place, Suite 330,
20
-- Boston, MA  02111-1307  USA
21
--
22
 
23
LIBRARY IEEE;
24
USE IEEE.std_logic_1164.all;
25
USE IEEE.std_logic_arith.all;
26
USE IEEE.std_logic_unsigned.all;
27
 
28
use std.textio.all;
29
use work.uart_package.all;
30
use work.txt_util.all;
31
 
32
entity uart_transactor is
33
    generic (
34
                stim_file    : string := "sim/uart_stim.dat";    -- Stimulus input file
35
                log_file     : string := "sim/uart_log.txt"      -- Log file
36
            );
37
end uart_transactor;
38
 
39
architecture tb of uart_transactor is
40
    file stimulus : TEXT open read_mode is stim_file;           -- Open stimulus file for read
41
    file log      : TEXT open write_mode is log_file;           -- Open log file for write
42
 
43
    -- The DUT
44
    component uart_16750 is
45
    port (
46
        CLK         : in std_logic;                             -- Clock
47
        RST         : in std_logic;                             -- Reset
48
        BAUDCE      : in std_logic;                             -- Baudrate generator clock enable
49
        CS          : in std_logic;                             -- Chip select
50
        WR          : in std_logic;                             -- Write to UART
51
        RD          : in std_logic;                             -- Read from UART
52
        A           : in std_logic_vector(2 downto 0);          -- Register select
53
        DIN         : in std_logic_vector(7 downto 0);          -- Data bus input
54
        DOUT        : out std_logic_vector(7 downto 0);         -- Data bus output
55
        DDIS        : out std_logic;                            -- Driver disable
56
        INT         : out std_logic;                            -- Interrupt output
57
        OUT1N       : out std_logic;                            -- Output 1
58
        OUT2N       : out std_logic;                            -- Output 2
59
        RCLK        : in std_logic;                             -- Receiver clock (16x baudrate)
60
        BAUDOUTN    : out std_logic;                            -- Baudrate generator output (16x baudrate)
61
        RTSN        : out std_logic;                            -- RTS output
62
        DTRN        : out std_logic;                            -- DTR output
63
        CTSN        : in std_logic;                             -- CTS input
64
        DSRN        : in std_logic;                             -- DSR input
65
        DCDN        : in std_logic;                             -- DCD input
66
        RIN         : in std_logic;                             -- RI input
67
        SIN         : in std_logic;                             -- Receiver input
68
        SOUT        : out std_logic                             -- Transmitter output
69
    );
70
    end component;
71
    component slib_clock_div is
72
        generic (
73
            RATIO       : integer := 18     -- Clock divider ratio
74
        );
75
        port (
76
            CLK         : in std_logic;     -- Clock
77
            RST         : in std_logic;     -- Reset
78
            CE          : in std_logic;     -- Clock enable input
79
            Q           : out std_logic     -- New clock enable output
80
        );
81
    end component;
82
 
83
 
84
    -- DUT signals
85
    signal clk, rst                 : std_logic;
86
    signal uart_if                  : uart_interface;
87
    signal dout                     : std_logic_vector (7 downto 0);
88
    signal ddis, int                : std_logic;
89
    signal baudce, rclk, baudoutn   : std_logic;
90
    signal out1n, out2n, rtsn, dtrn, ctsn, dsrn, dcdn, rin, sin, sout : std_logic;
91
 
92
    constant cycle : time := 30 ns;
93
 
94
begin
95
    -- Main clock
96
    CLOCK: process
97
    begin
98
        clk <= '0';
99
        wait for cycle/2;
100
        clk <= '1';
101
        wait for cycle/2;
102
    end process;
103
 
104
    -- Baudrate generator clock enable
105
    BGCE: slib_clock_div generic map (RATIO => 18) port map (clk, rst, '1', baudce);
106
 
107
    rclk <= baudoutn;
108
 
109
    -- Pull-up
110
    --uart_if.data <= (others => 'H');
111
 
112
    -- UART interface bus tri-state buffer
113
    LPCBUF: process (ddis, dout)
114
    begin
115
        if (ddis = '0') then
116
            uart_if.data <= dout;
117
        else
118
            uart_if.data <= (others => 'Z');
119
        end if;
120
    end process;
121
 
122
    DUT: uart_16750 port map (  CLK     => CLK,
123
                                RST     => RST,
124
                                BAUDCE  => BAUDCE,
125
                                CS      => uart_if.cs,
126
                                WR      => uart_if.wr,
127
                                RD      => uart_if.rd,
128
                                A       => uart_if.a,
129
                                DIN     => uart_if.data,
130
                                DOUT    => dout,
131
                                DDIS    => ddis,
132
                                INT     => int,
133
                                OUT1N   => out1n,
134
                                OUT2N   => out2n,
135
                                RCLK    => rclk,
136
                                BAUDOUTN=> baudoutn,
137
                                RTSN    => rtsn,
138
                                DTRN    => dtrn,
139
                                CTSN    => ctsn,
140
                                DSRN    => dsrn,
141
                                DCDN    => dcdn,
142
                                RIN     => rin,
143
                                SIN     => sin,
144
                                SOUT    => sout
145
                             );
146
 
147
    -- Main transaction process
148
    TRANPROC: process
149
        variable s          : string(1 to 100);
150
        variable address    : std_logic_vector(2 downto 0);
151
        variable data       : std_logic_vector(7 downto 0);
152
        variable data2      : std_logic_vector(7 downto 0);
153
    begin
154
        -- Default values
155
        rst  <= '1';
156
        ctsn <= '1';
157
        dsrn <= '1';
158
        dcdn <= '1';
159
        rin  <= '1';
160
        sin  <= '1';
161
        uart_if.a    <= (others => '0');
162
        uart_if.data <= (others => 'Z');
163
        uart_if.cs   <= '0';
164
        uart_if.rd   <= '0';
165
        uart_if.wr   <= '0';
166
 
167
        wait until falling_edge(clk);
168
 
169
        -- Get commands from stimulus file
170
        while not endfile(stimulus) loop
171
            str_read(stimulus, s);                                  -- Read line into string
172
 
173
            if (s(1 to 4) = "#SET") then                            -- Set values
174
                                                                    -- Format: RSTN CTSN DSRN DCDN RIN
175
                rst          <= to_std_logic(s(6));
176
                --CTSN         <= to_std_logic(s(8));
177
                --DSRN         <= to_std_logic(s(10));
178
                --DCDN         <= to_std_logic(s(12));
179
                --RIN          <= to_std_logic(s(14));
180
            elsif (s(1 to 5) = "#WAIT") then                        -- Wait n cycles
181
                wait for integer'value(s(7 to 12))*cycle;
182
            elsif (s(1 to 3) = "#RD") then                          -- Read from UART and compare
183
                address := to_std_logic_vector(s(5 to 7));
184
                data := to_std_logic_vector(s(9 to 16));
185
                uart_read (uart_if, address, data2, log);
186
                if (not compare(data, data2)) then
187
                    print (log, time'image(now) & ": " & "Failed: Expected 0x" & hstr(data) & " got 0x" & hstr(data2));
188
                end if;
189
            elsif (s(1 to 3) = "#WR") then                          -- Write to LPC
190
                address := to_std_logic_vector(s(5 to 7));
191
                data := to_std_logic_vector(s(9 to 16));
192
                uart_write (uart_if, address, data, log);
193
            elsif (s(1 to 4) = "#LOG") then                         -- Write message to log
194
                print (log, time'image(now) & ": " & s(6 to 80));
195
            elsif (s(1 to 4) = "#CUO") then                         -- Check UART outputs INT OUT1N OUT2N RTSN DTRN
196
                data2(4 downto 0) := to_std_logic_vector(s(6 to 10));
197
                data(4 downto 0) := INT & OUT1N & OUT2N & RTSN & DTRN;
198
                if (not compare(data(3 downto 0), data2(3 downto 0))) then
199
                    print (log, time'image(now) & ": " & "UART outputs failed: Expected " &
200
                    str(data2(4 downto 0)) & " got " & str(data(4 downto 0)));
201
                else
202
                    print (log, time'image(now) & ": " & "UART outputs: " & str(data(4 downto 0)));
203
                end if;
204
            else
205
                print ("Unknown command: " & s);
206
            end if;
207
        end loop;
208
 
209
        wait;
210
    end process;
211
 
212
end tb;
213
 

powered by: WebSVN 2.1.0

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