w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tb_serport_autobaud.vhd
Go to the documentation of this file.
1-- $Id: tb_serport_autobaud.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_autobaud - sim
7-- Description: Test bench for serport_autobaud
8--
9-- Dependencies: simlib/simclk
10-- simlib/simclkcnt
11-- tbd_serport_autobaud [UUT]
12--
13-- To test: serport_autobaud
14--
15-- Target Devices: generic
16--
17-- Verified (with tb_serport_autobaud_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
21-- 2007-10-21 91 - 0.26 - - c:ok
22-- 2007-10-14 89 - 0.26 - - c:ok
23-- 2007-10-12 88 _ssim 0.26 8.1.03 I27 xc3s1000 c:ok
24-- 2007-10-12 88 - 0.26 - - c:ok
25--
26-- Revision History:
27-- Date Rev Version Comment
28-- 2011-12-23 444 1.2 use new simclk/simclkcnt
29-- 2011-10-22 417 1.1.3 now numeric_std clean
30-- 2010-04-24 281 1.1.2 use direct instatiation for tbd_
31-- 2008-03-24 129 1.1.1 CLK_CYCLE now 31 bits
32-- 2007-10-21 91 1.1 now use 'send' command, self-checking (FAIL's)
33-- 2007-10-14 89 1.1 add extra stop bit for CLKDIV=0; drop c2out wait;
34-- add moni for autobauder
35-- 2007-10-12 88 1.0.1 avoid ieee.std_logic_unsigned, use cast to unsigned
36-- 2007-08-27 76 1.0 Initial version
37------------------------------------------------------------------------------
38
39library ieee;
40use ieee.std_logic_1164.all;
41use ieee.numeric_std.all;
42use ieee.std_logic_textio.all;
43use std.textio.all;
44
45use work.slvtypes.all;
46use work.simlib.all;
47use work.serportlib.all;
48
51
52architecture sim of tb_serport_autobaud is
53
54 signal CLK : slbit := '0';
55 signal RESET : slbit := '0';
56 signal RXSD : slbit := '0';
57 signal CE_USEC : slbit := '0';
58 signal CE_MSEC : slbit := '0';
59 signal CLKDIV : slv13 := (others=>'0');
60 signal ABACT : slbit := '0';
61 signal ABDONE : slbit := '0';
62 signal RXDATA : slv8 := (others=>'0');
63 signal RXVAL : slbit := '0';
64 signal RXERR : slbit := '0';
65 signal RXACT : slbit := '0';
66 signal TXSD2 : slbit := '0';
67 signal RXDATA3 : slv8 := (others=>'0');
68 signal RXVAL3 : slbit := '0';
69 signal RXERR3 : slbit := '0';
70 signal RXACT3 : slbit := '0';
71
72 signal CLK_STOP : slbit := '0';
73 signal CLK_CYCLE : integer := 0;
74
75 signal N_MON_VAL : slbit := '0';
76 signal N_MON_DAT : slv8 := (others=>'0');
77 signal R_MON_VAL_1 : slbit := '0';
78 signal R_MON_DAT_1 : slv8 := (others=>'0');
79 signal R_MON_VAL_2 : slbit := '0';
80 signal R_MON_DAT_2 : slv8 := (others=>'0');
81
82 constant clock_period : Delay_length := 20 ns;
83 constant clock_offset : Delay_length := 200 ns;
84 constant setup_time : Delay_length := 5 ns;
85 constant c2out_time : Delay_length := 10 ns;
86
87begin
88
89 CLKGEN : simclk
90 generic map (
93 port map (
94 CLK => CLK,
96 );
97
98 CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
99
100 UUT : entity work.tbd_serport_autobaud
101 port map (
102 CLK => CLK,
103 RESET => RESET,
104 RXSD => RXSD,
105 CE_USEC => CE_USEC,
106 CE_MSEC => CE_MSEC,
107 CLKDIV => CLKDIV,
108 ABACT => ABACT,
109 ABDONE => ABDONE,
110 RXDATA => RXDATA,
111 RXVAL => RXVAL,
112 RXERR => RXERR,
113 RXACT => RXACT,
114 TXSD2 => TXSD2,
115 RXDATA3 => RXDATA3,
116 RXVAL3 => RXVAL3,
117 RXERR3 => RXERR3,
118 RXACT3 => RXACT3
119 );
120
121
122 proc_stim: process
123 file fstim : text open read_mode is "tb_serport_autobaud_stim";
124 variable iline : line;
125 variable oline : line;
126 variable ok : boolean;
127 variable dname : string(1 to 6) := (others=>' ');
128 variable idelta : integer := 0;
129 variable irate : integer := 16;
130 variable ival : slbit;
131 variable itxdata : slv8 := (others=>'0');
132
133 begin
134
135 RXSD <= '1';
136
137 wait for clock_offset - setup_time;
138
139 file_loop: while not endfile(fstim) loop
140
141 readline (fstim, iline);
142
143 readcomment(iline, ok);
144 next file_loop when ok;
145
146 readword(iline, dname, ok);
147 if ok then
148 case dname is
149 when ".reset" => -- .reset
150 write(oline, string'(".reset"));
151 writeline(output, oline);
152 RESET <= '1';
153 wait for clock_period;
154 RESET <= '0';
155 wait for 9*clock_period;
156
157 when ".break" => -- .break
158 read_ea(iline, idelta);
159 write(oline, string'(".break"));
160 writeline(output, oline);
161 RXSD <= '0';
162 wait for idelta*clock_period;
163 RXSD <= '1';
164
165 when ".wait " => -- .wait
166 read_ea(iline, idelta);
167 wait for idelta*clock_period;
168
169 when ".rate " => -- .rate
170 read_ea(iline, irate);
171
172 when "send " => -- send
173 read_ea(iline, ival);
174 read_ea(iline, itxdata);
175
176 writetimestamp(oline, CLK_CYCLE, ": send ");
177 write(oline, itxdata, right, 10);
178 writeline(output, oline);
179
180 RXSD <= '0'; -- start bit
181 N_MON_VAL <= ival;
182 N_MON_DAT <= itxdata;
183 wait for clock_period;
184 N_MON_VAL <= '0';
185 wait for (irate-1)*clock_period;
186 RXSD <= '1';
187
188 for i in itxdata'reverse_range loop -- transmit lsb first
189 RXSD <= itxdata(i); -- data bit
190 wait for irate*clock_period;
191 end loop;
192
193 RXSD <= '1'; -- stop bit (plus extra cycle)
194 wait for (irate+1)*clock_period;
195
196 when others => -- unknown command
197 write(oline, string'("?? unknown command: "));
198 write(oline, dname);
199 writeline(output, oline);
200 report "aborting" severity failure;
201 end case;
202
203 else
204 report "failed to find command" severity failure;
205
206 end if;
207
208 end loop;
209
210 writetimestamp(oline, CLK_CYCLE, ": DONE ");
211 writeline(output, oline);
212
213 wait for 25*irate*clock_period;
214
215 CLK_STOP <= '1';
216
217 wait; -- suspend proc_stim forever
218 -- clock is stopped, sim will end
219
220 end process proc_stim;
221
222
223 proc_moni: process
224 variable oline : line;
225 variable iabact : slbit := '0';
226 begin
227
228 loop
229 wait until rising_edge(CLK);
230
231 if R_MON_VAL_1 = '1' then
232 if R_MON_VAL_2 = '1' then
233 writetimestamp(oline, CLK_CYCLE, ": moni ");
234 write(oline, string'(" FAIL MISSING DATA="));
235 write(oline, R_MON_DAT_2);
236 writeline(output, oline);
237 end if;
240 end if;
241
244
245 if (ABACT xor iabact)='1' then
246 writetimestamp(oline, CLK_CYCLE, ": auto ABACT =");
247 write(oline, ABACT, right, 2);
248 iabact := ABACT;
249 writeline(output, oline);
250 end if;
251
252 if ABDONE = '1' then
253 writetimestamp(oline, CLK_CYCLE, ": auto CLKDIV =");
254 write(oline, to_integer(unsigned(CLKDIV)), right, 3);
255 writeline(output, oline);
256 end if;
257
258 if RXVAL='1' or (ABACT='0' and RXERR='1' and unsigned(RXDATA)/=0) then
259 writetimestamp(oline, CLK_CYCLE, ": moni ");
260 write(oline, RXDATA, right, 10);
261 if RXERR = '1' then
262 write(oline, string'(" RXERR=1"));
263 end if;
264
265 if R_MON_VAL_2 = '0' then
266 write(oline, string'(" FAIL UNEXPECTED"));
267 else
268 write(oline, string'(" CHECK"));
269 R_MON_VAL_2 <= '0';
270
271 if R_MON_DAT_2 = RXDATA and
272 RXERR='0' then
273 write(oline, string'(" OK"));
274 else
275 write(oline, string'(" FAIL"));
276 end if;
277
278 end if;
279
280 writeline(output, oline);
281 end if;
282
283 end loop;
284
285 end process proc_moni;
286
287end 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
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 :=( others => '0') CLKDIV
slv8 :=( others => '0') RXDATA3
Delay_length := 20 ns clock_period