1 |
20 |
magro732 |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- RapidIO IP Library Core
|
4 |
|
|
--
|
5 |
|
|
-- This file is part of the RapidIO IP library project
|
6 |
|
|
-- http://www.opencores.org/cores/rio/
|
7 |
|
|
--
|
8 |
|
|
-- Description
|
9 |
|
|
-- Contains a testbench for the generic UART entity.
|
10 |
|
|
--
|
11 |
|
|
-- To Do:
|
12 |
|
|
-- -
|
13 |
|
|
--
|
14 |
|
|
-- Author(s):
|
15 |
|
|
-- - Magnus Rosenius, magro732@opencores.org
|
16 |
|
|
--
|
17 |
|
|
-------------------------------------------------------------------------------
|
18 |
|
|
--
|
19 |
|
|
-- Copyright (C) 2013 Authors and OPENCORES.ORG
|
20 |
|
|
--
|
21 |
|
|
-- This source file may be used and distributed without
|
22 |
|
|
-- restriction provided that this copyright statement is not
|
23 |
|
|
-- removed from the file and that any derivative work contains
|
24 |
|
|
-- the original copyright notice and the associated disclaimer.
|
25 |
|
|
--
|
26 |
|
|
-- This source file is free software; you can redistribute it
|
27 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
28 |
|
|
-- Public License as published by the Free Software Foundation;
|
29 |
|
|
-- either version 2.1 of the License, or (at your option) any
|
30 |
|
|
-- later version.
|
31 |
|
|
--
|
32 |
|
|
-- This source is distributed in the hope that it will be
|
33 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
34 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
35 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
36 |
|
|
-- details.
|
37 |
|
|
--
|
38 |
|
|
-- You should have received a copy of the GNU Lesser General
|
39 |
|
|
-- Public License along with this source; if not, download it
|
40 |
|
|
-- from http://www.opencores.org/lgpl.shtml
|
41 |
|
|
--
|
42 |
|
|
-------------------------------------------------------------------------------
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
-------------------------------------------------------------------------------
|
46 |
|
|
-- TestUart.
|
47 |
|
|
-------------------------------------------------------------------------------
|
48 |
|
|
|
49 |
|
|
library ieee;
|
50 |
|
|
use ieee.std_logic_1164.all;
|
51 |
|
|
use ieee.numeric_std.all;
|
52 |
|
|
library std;
|
53 |
|
|
use std.textio.all;
|
54 |
24 |
magro732 |
use work.rio_common.all;
|
55 |
20 |
magro732 |
|
56 |
|
|
|
57 |
|
|
-------------------------------------------------------------------------------
|
58 |
|
|
-- Entity for TestUart.
|
59 |
|
|
-------------------------------------------------------------------------------
|
60 |
|
|
entity TestUart is
|
61 |
|
|
end entity;
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
-------------------------------------------------------------------------------
|
65 |
|
|
-- Architecture for TestUart.
|
66 |
|
|
-------------------------------------------------------------------------------
|
67 |
|
|
architecture TestUartImpl of TestUart is
|
68 |
|
|
|
69 |
|
|
component Uart is
|
70 |
|
|
generic(
|
71 |
|
|
DIVISOR_WIDTH : natural;
|
72 |
|
|
DATA_WIDTH : natural);
|
73 |
|
|
port(
|
74 |
|
|
clk : in std_logic;
|
75 |
|
|
areset_n : in std_logic;
|
76 |
|
|
|
77 |
|
|
divisor_i : in std_logic_vector(DIVISOR_WIDTH-1 downto 0);
|
78 |
|
|
|
79 |
|
|
serial_i : in std_logic;
|
80 |
|
|
serial_o : out std_logic;
|
81 |
|
|
|
82 |
|
|
empty_o : out std_logic;
|
83 |
|
|
read_i : in std_logic;
|
84 |
|
|
data_o : out std_logic_vector(DATA_WIDTH-1 downto 0);
|
85 |
|
|
|
86 |
|
|
full_o : out std_logic;
|
87 |
|
|
write_i : in std_logic;
|
88 |
|
|
data_i : in std_logic_vector(DATA_WIDTH-1 downto 0));
|
89 |
|
|
end component;
|
90 |
|
|
|
91 |
|
|
signal clk : std_logic;
|
92 |
|
|
signal areset_n : std_logic;
|
93 |
|
|
|
94 |
|
|
signal rxSerial : std_logic;
|
95 |
|
|
signal txSerial : std_logic;
|
96 |
|
|
|
97 |
|
|
signal rxEmpty : std_logic;
|
98 |
|
|
signal rxRead : std_logic;
|
99 |
|
|
signal rxData : std_logic_vector(7 downto 0);
|
100 |
|
|
|
101 |
|
|
signal txFull : std_logic;
|
102 |
|
|
signal txWrite : std_logic;
|
103 |
|
|
signal txData : std_logic_vector(7 downto 0);
|
104 |
|
|
|
105 |
|
|
begin
|
106 |
|
|
|
107 |
|
|
-----------------------------------------------------------------------------
|
108 |
|
|
-- Clock generation.
|
109 |
|
|
-----------------------------------------------------------------------------
|
110 |
|
|
ClockGenerator: process
|
111 |
|
|
begin
|
112 |
|
|
clk <= '0';
|
113 |
|
|
wait for 20 ns;
|
114 |
|
|
clk <= '1';
|
115 |
|
|
wait for 20 ns;
|
116 |
|
|
end process;
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
-----------------------------------------------------------------------------
|
120 |
|
|
-- Serial port emulator.
|
121 |
|
|
-----------------------------------------------------------------------------
|
122 |
|
|
TestDriver: process
|
123 |
|
|
|
124 |
|
|
procedure SerialSend(
|
125 |
|
|
constant data : in std_logic_vector(7 downto 0)) is
|
126 |
|
|
variable outgoing : std_logic_vector(9 downto 0);
|
127 |
|
|
begin
|
128 |
|
|
-- Create the complete transmission character.
|
129 |
|
|
outgoing(0) := '0';
|
130 |
|
|
for i in 0 to 7 loop
|
131 |
|
|
outgoing(i+1) := data(i);
|
132 |
|
|
end loop;
|
133 |
|
|
outgoing(9) := '1';
|
134 |
|
|
|
135 |
|
|
-- Send the character.
|
136 |
|
|
for i in 0 to 9 loop
|
137 |
|
|
txSerial <= outgoing(i);
|
138 |
|
|
wait for 500 ns;
|
139 |
|
|
end loop;
|
140 |
|
|
end procedure;
|
141 |
|
|
|
142 |
|
|
procedure SerialReceive(
|
143 |
|
|
constant data : in std_logic_vector(7 downto 0)) is
|
144 |
|
|
variable incomming : std_logic_vector(9 downto 0);
|
145 |
|
|
begin
|
146 |
|
|
-- Receive the character.
|
147 |
|
|
wait until rxSerial = '0';
|
148 |
|
|
incomming(0) := '0';
|
149 |
|
|
for i in 1 to 9 loop
|
150 |
|
|
wait for 500 ns;
|
151 |
|
|
incomming(i) := rxSerial;
|
152 |
|
|
end loop;
|
153 |
|
|
|
154 |
|
|
-- Check if the received character is expected.
|
155 |
|
|
assert (incomming(0) = '0') report "Start bit." severity error;
|
156 |
|
|
assert (incomming(8 downto 1) = data) report "Data bit" severity error;
|
157 |
|
|
assert (incomming(9) = '1') report "Stop bit." severity error;
|
158 |
|
|
end procedure;
|
159 |
|
|
|
160 |
|
|
begin
|
161 |
|
|
txSerial <= '1';
|
162 |
|
|
txWrite <= '0';
|
163 |
|
|
rxRead <= '0';
|
164 |
|
|
areset_n <= '0';
|
165 |
|
|
|
166 |
|
|
wait until clk'event and clk = '1';
|
167 |
|
|
wait until clk'event and clk = '1';
|
168 |
|
|
areset_n <= '1';
|
169 |
|
|
wait until clk'event and clk = '1';
|
170 |
|
|
wait until clk'event and clk = '1';
|
171 |
|
|
|
172 |
|
|
---------------------------------------------------------------------------
|
173 |
|
|
-- Send byte to uart.
|
174 |
|
|
---------------------------------------------------------------------------
|
175 |
|
|
SerialSend(x"55");
|
176 |
|
|
wait until rxEmpty = '0' and clk'event and clk = '1';
|
177 |
|
|
rxRead <= '1';
|
178 |
|
|
wait until clk'event and clk = '1';
|
179 |
|
|
rxRead <= '0';
|
180 |
|
|
wait until clk'event and clk = '1';
|
181 |
|
|
assert rxData = x"55" report "rxData" severity error;
|
182 |
|
|
|
183 |
|
|
SerialSend(x"62");
|
184 |
|
|
wait until rxEmpty = '0' and clk'event and clk = '1';
|
185 |
|
|
rxRead <= '1';
|
186 |
|
|
wait until clk'event and clk = '1';
|
187 |
|
|
rxRead <= '0';
|
188 |
|
|
wait until clk'event and clk = '1';
|
189 |
|
|
assert rxData = x"62" report "rxData" severity error;
|
190 |
|
|
|
191 |
|
|
wait until txFull = '0' and clk'event and clk = '1';
|
192 |
|
|
txWrite <= '1';
|
193 |
|
|
txData <= x"55";
|
194 |
|
|
wait until clk'event and clk = '1';
|
195 |
|
|
txWrite <= '0';
|
196 |
|
|
SerialReceive(x"55");
|
197 |
|
|
|
198 |
|
|
wait until txFull = '0' and clk'event and clk = '1';
|
199 |
|
|
txWrite <= '1';
|
200 |
|
|
txData <= x"62";
|
201 |
|
|
wait until clk'event and clk = '1';
|
202 |
|
|
txWrite <= '0';
|
203 |
|
|
SerialReceive(x"62");
|
204 |
|
|
|
205 |
|
|
-- REMARK: Formalize the tests and write more testcases...
|
206 |
|
|
|
207 |
|
|
---------------------------------------------------------------------------
|
208 |
|
|
-- Test completed.
|
209 |
|
|
---------------------------------------------------------------------------
|
210 |
|
|
|
211 |
|
|
TestEnd;
|
212 |
|
|
end process;
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
-----------------------------------------------------------------------------
|
216 |
|
|
-- Instantiate the uart.
|
217 |
|
|
-----------------------------------------------------------------------------
|
218 |
|
|
|
219 |
|
|
UartInst: Uart
|
220 |
|
|
generic map(DIVISOR_WIDTH=>4, DATA_WIDTH=>8)
|
221 |
|
|
port map(
|
222 |
|
|
clk=>clk, areset_n=>areset_n,
|
223 |
|
|
divisor_i=>"1011",
|
224 |
|
|
serial_i=>txSerial, serial_o=>rxSerial,
|
225 |
|
|
empty_o=>rxEmpty, read_i=>rxRead, data_o=>rxData,
|
226 |
|
|
full_o=>txFull, write_i=>txWrite, data_i=>txData);
|
227 |
|
|
|
228 |
|
|
end architecture;
|