w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tb_serport_uart_rx.vhd
Go to the documentation of this file.
1-- $Id: tb_serport_uart_rx.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_rx - sim
7-- Description: Test bench for serport_uart_rx
8--
9-- Dependencies: simlib/simclk
10-- simlib/simclkcnt
11-- tbd_serport_uart_rx [UUT]
12--
13-- To test: serport_uart_rx
14--
15-- Target Devices: generic
16--
17-- Verified (with tb_serport_uart_rx_stim.dat):
18-- Date Rev Code ghdl ise Target Comment
19-- 2007-11-02 93 _tsim 0.26 8.2.03 I34 xc3s1000 d:ok
20-- 2007-10-21 91 _ssim 0.26 8.1.03 I27 xc3s1000 c:ok (63488 cl 15.21s)
21-- 2007-10-21 91 - 0.26 - - c:ok (63488 cl 7.12s)
22--
23-- Revision History:
24-- Date Rev Version Comment
25-- 2011-12-23 444 1.1 use new simclk/simclkcnt
26-- 2011-10-22 417 1.0.3 now numeric_std clean
27-- 2010-04-24 281 1.0.2 use direct instatiation for tbd_
28-- 2008-03-24 129 1.0.1 CLK_CYCLE now 31 bits
29-- 2007-10-21 91 1.0 Initial version
30------------------------------------------------------------------------------
31
32library ieee;
33use ieee.std_logic_1164.all;
34use ieee.numeric_std.all;
35use ieee.std_logic_textio.all;
36use std.textio.all;
37
38use work.slvtypes.all;
39use work.simlib.all;
40use work.serportlib.all;
41
44
45architecture sim of tb_serport_uart_rx is
46
47 signal CLK : slbit := '0';
48 signal RESET : slbit := '0';
49 signal CLKDIV : slv5 := slv(to_unsigned(15, 5));
50 signal RXSD : slbit := '1';
51 signal RXDATA : slv8 := (others=>'0');
52 signal RXVAL : slbit := '0';
53 signal RXERR : slbit := '0';
54 signal RXACT : slbit := '0';
55
56 signal CLK_STOP : slbit := '0';
57 signal CLK_CYCLE : integer := 0;
58
59 signal N_MON_VAL : slbit := '0';
60 signal N_MON_ERR : slbit := '0';
61 signal N_MON_DAT : slv8 := (others=>'0');
62 signal R_MON_VAL_1 : slbit := '0';
63 signal R_MON_ERR_1 : slbit := '0';
64 signal R_MON_DAT_1 : slv8 := (others=>'0');
65 signal R_MON_VAL_2 : slbit := '0';
66 signal R_MON_ERR_2 : slbit := '0';
67 signal R_MON_DAT_2 : slv8 := (others=>'0');
68
69 constant clock_period : Delay_length := 20 ns;
70 constant clock_offset : Delay_length := 200 ns;
71 constant setup_time : Delay_length := 5 ns;
72 constant c2out_time : Delay_length := 10 ns;
73
74begin
75
76 CLKGEN : simclk
77 generic map (
80 port map (
81 CLK => CLK,
83 );
84
85 CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
86
87 UUT : entity work.tbd_serport_uart_rx
88 port map (
89 CLK => CLK,
90 RESET => RESET,
91 CLKDIV => CLKDIV,
92 RXSD => RXSD,
93 RXDATA => RXDATA,
94 RXVAL => RXVAL,
95 RXERR => RXERR,
96 RXACT => RXACT
97 );
98
99
100 proc_stim: process
101 file fstim : text open read_mode is "tb_serport_uart_rx_stim";
102 variable iline : line;
103 variable oline : line;
104 variable idelta : integer := 0;
105 variable itxdata : slv8 := (others=>'0');
106 variable irxval : slbit := '0';
107 variable irxerr : slbit := '0';
108 variable irxdata : slv8 := (others=>'0');
109 variable ok : boolean;
110 variable dname : string(1 to 6) := (others=>' ');
111 variable irate : integer := 16;
112
113 type bit_10_array_type is array(0 to 9) of slbit;
114 type int_10_array_type is array(0 to 9) of integer;
115 variable valpuls : bit_10_array_type := (others=>'0');
116 variable delpuls : int_10_array_type := (others=>0);
117 variable npuls : integer := 0;
118
119 begin
120
121 wait for clock_offset - setup_time;
122
123 file_loop: while not endfile(fstim) loop
124
125 readline (fstim, iline);
126
127 readcomment(iline, ok);
128 next file_loop when ok;
129
130 readword(iline, dname, ok);
131 if ok then
132 case dname is
133 when ".reset" => -- .reset
134 write(oline, string'(".reset"));
135 writeline(output, oline);
136 RESET <= '1';
137 wait for clock_period;
138 RESET <= '0';
139 wait for 9*clock_period;
140
141 when ".wait " => -- .wait
142 read_ea(iline, idelta);
143 wait for idelta*clock_period;
144
145 when ".rate " => -- .rate
146 idelta := 0;
147 while RXACT='1' loop -- ensure that uart isn't active
148 wait for clock_period;
149 idelta := idelta + 1;
150 exit when idelta>3000;
151 end loop;
152 read_ea(iline, irate);
153 wait for 2*clock_period;
154 CLKDIV <= slv(to_unsigned(irate-1, CLKDIV'length));
155 wait for 2*clock_period;
156
157 when ".xrate" => -- .xrate
158 read_ea(iline, irate);
159
160 when "puls " => -- puls
161 writetimestamp(oline, CLK_CYCLE, ": puls ");
162
163 read_ea(iline, irxval);
164 read_ea(iline, irxerr);
165 read_ea(iline, irxdata);
166
167 npuls := 0;
168 for i in valpuls'range loop
169 testempty(iline, ok);
170 if ok then
171 exit;
172 end if;
173 read_ea(iline, valpuls(i));
174 read_ea(iline, delpuls(i));
175 assert delpuls(i)>0
176 report "assert puls length > 0" severity failure;
177 npuls := npuls + 1;
178 write(oline, valpuls(i), right, 3);
179 write(oline, delpuls(i), right, 3);
180 end loop; -- i
181 writeline(output, oline);
182
183 if npuls > 0 then
184 N_MON_VAL <= irxval;
185 N_MON_ERR <= irxerr;
186 N_MON_DAT <= irxdata;
187 for i in 0 to npuls-1 loop
188 RXSD <= valpuls(i);
189 wait for clock_period;
190 N_MON_VAL <= '0';
191 wait for (delpuls(i)-1)*clock_period;
192 end loop; -- i
193 end if;
194
195 when "send " => -- send
196 read_ea(iline, idelta);
197 read_ea(iline, itxdata);
198
199 RXSD <= '1';
200 wait for idelta*clock_period;
201
202 writetimestamp(oline, CLK_CYCLE, ": send ");
203 write(oline, itxdata, right, 10);
204 writeline(output, oline);
205
206 N_MON_VAL <= '1';
207 N_MON_ERR <= '0';
208 N_MON_DAT <= itxdata;
209
210 RXSD <= '0'; -- start bit
211 wait for clock_period;
212 N_MON_VAL <= '0';
213 wait for (irate-1)*clock_period;
214 RXSD <= '1';
215
216 for i in itxdata'reverse_range loop -- transmit lsb first
217 RXSD <= itxdata(i); -- data bit
218 wait for irate*clock_period;
219 end loop;
220
221 RXSD <= '1'; -- stop bit
222 wait for irate*clock_period;
223
224 when others => -- unknown command
225 write(oline, string'("?? unknown command: "));
226 write(oline, dname);
227 writeline(output, oline);
228 report "aborting" severity failure;
229 end case;
230
231 else
232 report "failed to find command" severity failure;
233
234 end if;
235
236 testempty_ea(iline);
237 end loop; -- file_loop:
238
239 idelta := 0;
240 while RXACT='1' loop
241 wait for clock_period;
242 idelta := idelta + 1;
243 exit when idelta>3000;
244 end loop;
245
246 writetimestamp(oline, CLK_CYCLE, ": DONE ");
247 writeline(output, oline);
248
249 wait for 12*irate*clock_period;
250
251 CLK_STOP <= '1';
252
253 wait; -- suspend proc_stim forever
254 -- clock is stopped, sim will end
255
256 end process proc_stim;
257
258
259 proc_moni: process
260 variable oline : line;
261 begin
262
263 loop
264 wait until rising_edge(CLK);
265
266 if R_MON_VAL_1 = '1' then
267 if R_MON_VAL_2 = '1' then
268 writetimestamp(oline, CLK_CYCLE, ": moni ");
269 write(oline, string'(" FAIL MISSING ERR="));
270 write(oline, R_MON_ERR_2);
271 write(oline, string'(" DATA="));
272 write(oline, R_MON_DAT_2);
273 writeline(output, oline);
274 end if;
278 end if;
279
283
284 if RXVAL='1' or RXERR='1' then
285 writetimestamp(oline, CLK_CYCLE, ": moni ");
286 write(oline, RXDATA, right, 10);
287 if RXERR = '1' then
288 write(oline, string'(" RXERR=1"));
289 end if;
290
291 if R_MON_VAL_2 = '0' then
292 write(oline, string'(" FAIL UNEXPECTED"));
293 else
294 write(oline, string'(" CHECK"));
295 R_MON_VAL_2 <= '0';
296
297 if R_MON_ERR_2 = '0' then
298 if R_MON_DAT_2 = RXDATA and
299 RXERR='0' then
300 write(oline, string'(" OK"));
301 else
302 write(oline, string'(" FAIL"));
303 end if;
304
305 else
306 if RXERR = '1' then
307 write(oline, string'(" OK"));
308 else
309 write(oline, string'(" FAIL, RXERR=1 expected"));
310 end if;
311
312 end if;
313
314 end if;
315
316 writeline(output, oline);
317 end if;
318
319 end loop;
320
321 end process proc_moni;
322
323end 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( 4 downto 0) slv5
Definition: slvtypes.vhd:37
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
slv5 := slv( to_unsigned( 15, 5) ) CLKDIV
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
Delay_length := 20 ns clock_period