w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tb_serport_uart_rxtx.vhd
Go to the documentation of this file.
1-- $Id: tb_serport_uart_rxtx.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: tb_serport_uart_rxtx - sim
7-- Description: Test bench for serport_uart_rxtx
8--
9-- Dependencies: simlib/simclk
10-- tbd_serport_uart_rxtx [UUT]
11--
12-- To test: serport_uart_rxtx
13--
14-- Target Devices: generic
15--
16-- Verified (with tb_serport_uart_rxtx_stim.dat):
17-- Date Rev Code ghdl ise Target Comment
18-- 2007-11-02 93 _tsim 0.26 8.2.03 I34 xc3s1000 d:ok
19-- 2007-10-21 91 _ssim 0.26 8.1.03 I27 xc3s1000 c:ok
20-- 2007-10-21 91 - 0.26 - - c:ok
21-- 2007-10-14 89 - 0.26 - - c:ok
22-- 2007-10-12 88 _ssim 0.26 8.1.03 I27 xc3s1000 c:ok
23-- 2007-10-12 88 - 0.26 - - c:ok
24--
25-- Revision History:
26-- Date Rev Version Comment
27-- 2011-12-23 444 1.2 use new simclk/simclkcnt
28-- 2011-10-22 417 1.1.3 now numeric_std clean
29-- 2010-04-24 281 1.1.2 use direct instatiation for tbd_
30-- 2008-03-24 129 1.1.1 CLK_CYCLE now 31 bits
31-- 2007-10-21 91 1.1 now use 'send' command, self-checking (FAIL's)
32-- 2007-10-12 88 1.0.1 avoid ieee.std_logic_unsigned, use cast to unsigned
33-- 2007-08-27 76 1.0 Initial version
34------------------------------------------------------------------------------
35
36library ieee;
37use ieee.std_logic_1164.all;
38use ieee.numeric_std.all;
39use ieee.std_logic_textio.all;
40use std.textio.all;
41
42use work.slvtypes.all;
43use work.simlib.all;
44use work.serportlib.all;
45
48
49architecture sim of tb_serport_uart_rxtx is
50
51 signal CLK : slbit := '0';
52 signal RESET : slbit := '0';
53 signal CLKDIV : slv13 := slv(to_unsigned(15, 13));
54 signal RXDATA : slv8 := (others=>'0');
55 signal RXVAL : slbit := '0';
56 signal RXERR : slbit := '0';
57 signal RXACT : slbit := '0';
58 signal TXSD : slbit := '0';
59 signal TXDATA : slv8 := (others=>'0');
60 signal TXENA : slbit := '0';
61 signal TXBUSY : slbit := '0';
62
63 signal CLK_STOP : slbit := '0';
64 signal CLK_CYCLE : integer := 0;
65
66 signal N_MON_VAL : slbit := '0';
67 signal N_MON_DAT : slv8 := (others=>'0');
68 signal R_MON_VAL_1 : slbit := '0';
69 signal R_MON_DAT_1 : slv8 := (others=>'0');
70 signal R_MON_VAL_2 : slbit := '0';
71 signal R_MON_DAT_2 : slv8 := (others=>'0');
72
73 constant clock_period : Delay_length := 20 ns;
74 constant clock_offset : Delay_length := 200 ns;
75 constant setup_time : Delay_length := 5 ns;
76 constant c2out_time : Delay_length := 10 ns;
77
78begin
79
80 CLKGEN : simclk
81 generic map (
84 port map (
85 CLK => CLK,
87 );
88
89 CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
90
91 UUT : entity work.tbd_serport_uart_rxtx
92 port map (
93 CLK => CLK,
94 RESET => RESET,
95 CLKDIV => CLKDIV,
96 RXSD => TXSD,
97 RXDATA => RXDATA,
98 RXVAL => RXVAL,
99 RXERR => RXERR,
100 RXACT => RXACT,
101 TXSD => TXSD,
102 TXDATA => TXDATA,
103 TXENA => TXENA,
104 TXBUSY => TXBUSY
105 );
106
107
108 proc_stim: process
109 file fstim : text open read_mode is "tb_serport_uart_rxtx_stim";
110 variable iline : line;
111 variable oline : line;
112 variable idelta : integer := 0;
113 variable itxdata : slv8 := (others=>'0');
114 variable ok : boolean;
115 variable dname : string(1 to 6) := (others=>' ');
116 variable irate : integer := 16;
117
118 begin
119
120 wait for clock_offset - setup_time;
121
122 file_loop: while not endfile(fstim) loop
123
124 readline (fstim, iline);
125
126 readcomment(iline, ok);
127 next file_loop when ok;
128
129 readword(iline, dname, ok);
130 if ok then
131 case dname is
132 when ".reset" => -- .reset
133 write(oline, string'(".reset"));
134 writeline(output, oline);
135 RESET <= '1';
136 wait for clock_period;
137 RESET <= '0';
138 wait for 9*clock_period;
139
140 when ".wait " => -- .wait
141 read_ea(iline, idelta);
142 wait for idelta*clock_period;
143
144 when ".rate " => -- .rate
145 read_ea(iline, irate);
146 CLKDIV <= slv(to_unsigned(irate-1, 13));
147
148 when "send " => -- send
149 read_ea(iline, idelta);
150 read_ea(iline, itxdata);
151
152 while TXBUSY='1' loop
153 wait for clock_period;
154 end loop;
155
156 wait for idelta*clock_period;
157
158 writetimestamp(oline, CLK_CYCLE, ": send ");
159 write(oline, itxdata, right, 10);
160 writeline(output, oline);
161
162 TXDATA <= itxdata;
163 TXENA <= '1';
164 N_MON_VAL <= '1';
165 N_MON_DAT <= itxdata;
166
167 wait for clock_period;
168 TXENA <= '0';
169 N_MON_VAL <= '0';
170
171 when others => -- unknown command
172 write(oline, string'("?? unknown command: "));
173 write(oline, dname);
174 writeline(output, oline);
175 report "aborting" severity failure;
176 end case;
177
178 else
179 report "failed to find command" severity failure;
180
181 end if;
182
183 testempty_ea(iline);
184 end loop; -- file_loop
185
186 idelta := 0;
187 while TXBUSY='1' or RXACT='1' loop
188 wait for clock_period;
189 idelta := idelta + 1;
190 exit when idelta>3000;
191 end loop;
192
193 writetimestamp(oline, CLK_CYCLE, ": DONE ");
194 writeline(output, oline);
195
196 wait for 12*irate*clock_period;
197
198 CLK_STOP <= '1';
199
200 wait; -- suspend proc_stim forever
201 -- clock is stopped, sim will end
202
203 end process proc_stim;
204
205
206 proc_moni: process
207 variable oline : line;
208 begin
209
210 loop
211 wait until rising_edge(CLK);
212
213 if R_MON_VAL_1 = '1' then
214 if R_MON_VAL_2 = '1' then
215 writetimestamp(oline, CLK_CYCLE, ": moni ");
216 write(oline, string'(" FAIL MISSING DATA="));
217 write(oline, R_MON_DAT_2);
218 writeline(output, oline);
219 end if;
222 end if;
223
226
227 if RXVAL='1' or RXERR='1' then
228 writetimestamp(oline, CLK_CYCLE, ": moni ");
229 write(oline, RXDATA, right, 10);
230 if RXERR = '1' then
231 write(oline, string'(" RXERR=1"));
232 end if;
233
234 if R_MON_VAL_2 = '0' then
235 write(oline, string'(" FAIL UNEXPECTED"));
236 else
237 write(oline, string'(" CHECK"));
238 R_MON_VAL_2 <= '0';
239
240 if R_MON_DAT_2 = RXDATA and
241 RXERR='0' then
242 write(oline, string'(" OK"));
243 else
244 write(oline, string'(" FAIL"));
245 end if;
246
247 end if;
248
249 writeline(output, oline);
250 end if;
251
252 end loop;
253
254 end process proc_moni;
255
256end sim;
out CLK slbit
Definition: simclk.vhd:33
OFFSET Delay_length := 200 ns
Definition: simclk.vhd:31
in CLK_STOP slbit := '0'
Definition: simclk.vhd:35
PERIOD Delay_length := 20 ns
Definition: simclk.vhd:30
out CLK_CYCLE integer
Definition: simclkcnt.vhd:29
in CLK slbit
Definition: simclkcnt.vhd:27
std_logic_vector( 12 downto 0) slv13
Definition: slvtypes.vhd:45
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40
std_logic_vector slv
Definition: slvtypes.vhd:31
slv8 :=( others => '0') R_MON_DAT_2
slv8 :=( others => '0') RXDATA
Delay_length := 200 ns clock_offset
Delay_length := 5 ns setup_time
slv8 :=( others => '0') N_MON_DAT
slv8 :=( others => '0') R_MON_DAT_1
Delay_length := 10 ns c2out_time
slv13 := slv( to_unsigned( 15, 13) ) CLKDIV
slv8 :=( others => '0') TXDATA
Delay_length := 20 ns clock_period