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

Subversion Repositories wb_uart

[/] [wb_uart/] [trunk/] [src/] [wb8_uart_transactor.vhd] - Blame information for rev 11

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

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

powered by: WebSVN 2.1.0

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