w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tb_cdata2byte.vhd
Go to the documentation of this file.
1-- $Id: tb_cdata2byte.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2014- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: tb_cdata2byte - sim
7-- Description: Test bench for cdata2byte and byte2cdata
8--
9-- Dependencies: simlib/simclk
10-- simlib/simclkcnt
11-- tbd_cdata2byte [UUT]
12--
13-- To test: cdata2byte
14-- byte2cdata
15--
16-- Target Devices: generic
17--
18-- Verified (with tb_cdata2byte_stim.dat):
19-- Date Rev Code ghdl ise Target Comment
20-- 2014-10-25 599 _ssim 0.31 17.1 sc6slx16 c: ok
21-- 2014-10-25 599 - 0.31 - c: ok
22--
23-- Revision History:
24-- Date Rev Version Comment
25-- 2014-10-25 599 1.1.1 use wait_* to control stim and moni timing
26-- 2014-10-19 598 1.1 use simfifo with shared variables
27-- 2014-10-18 597 1.0 Initial version
28------------------------------------------------------------------------------
29
30library ieee;
31use ieee.std_logic_1164.all;
32use ieee.numeric_std.all;
33use ieee.std_logic_textio.all;
34use std.textio.all;
35
36use work.slvtypes.all;
37use work.simlib.all;
38use work.comlib.all;
39
42
43architecture sim of tb_cdata2byte is
44
45 constant clk_dsc : clock_dsc := (20 ns, 1 ns, 1 ns);
46 constant clk_offset : Delay_length := 200 ns;
47
48 signal CLK : slbit := '0';
49 signal RESET : slbit := '0';
50
51 signal CLK_STOP : slbit := '0';
52 signal CLK_CYCLE : integer := 0;
53
54 signal C2B_ESCXON : slbit := '0';
55 signal C2B_ESCFILL : slbit := '0';
56 signal C2B_DI : slv9 := (others=>'0');
57 signal C2B_ENA : slbit := '0';
58 signal C2B_BUSY : slbit := '0';
59 signal C2B_DO : slv8 := (others=>'0');
60 signal C2B_VAL : slbit := '0';
61
62 signal B2C_BUSY : slbit := '0';
63 signal B2C_DO : slv9 := (others=>'0');
64 signal B2C_VAL : slbit := '0';
65 signal B2C_HOLD : slbit := '0';
66
67 shared variable sv_sff_monc_cnt : natural := 0;
68 shared variable sv_sff_monc_arr : simfifo_type(0 to 7, 7 downto 0);
69 shared variable sv_sff_monb_cnt : natural := 0;
70 shared variable sv_sff_monb_arr : simfifo_type(0 to 7, 8 downto 0);
71
72begin
73
74 CLKGEN : simclk
75 generic map (
76 PERIOD => clk_dsc.period,
78 port map (
79 CLK => CLK,
81 );
82
83 CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
84
85 UUT : entity work.tbd_cdata2byte
86 port map (
87 CLK => CLK,
88 RESET => RESET,
91 C2B_DI => C2B_DI,
94 C2B_DO => C2B_DO,
97 B2C_DO => B2C_DO,
100 );
101
102 proc_stim: process
103 file fstim : text open read_mode is "tb_cdata2byte_stim";
104 variable iline : line;
105 variable oline : line;
106 variable ok : boolean;
107 variable dname : string(1 to 6) := (others=>' ');
108 variable idel : natural := 0;
109 variable ilen : natural := 0;
110 variable nbusy : integer := 0;
111
112 variable iesc : slbit := '0';
113 variable itxdata9 : slbit := '0';
114 variable itxdata : slv8 := (others=>'0');
115 variable irxdata9 : slbit := '0';
116 variable irxdata : slv8 := (others=>'0');
117 variable dat9 : slv9 := (others=>'0');
118
119 begin
120
121 wait_nextstim(CLK, clk_dsc);
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_nextstim(CLK, clk_dsc);
138 RESET <= '0';
139 wait_nextstim(CLK, clk_dsc);
140
141 when ".wait " => -- .wait
142 read_ea(iline, idel);
143 wait_nextstim(CLK, clk_dsc, idel);
144
145 when "escxon" => -- escxon
146 read_ea(iline, iesc);
147 C2B_ESCXON <= iesc;
148
149 when "escfil" => -- escfil
150 read_ea(iline, iesc);
151 C2B_ESCFILL <= iesc;
152
153 when "bhold " => -- bhold
154 read_ea(iline, idel);
155 read_ea(iline, ilen);
156 B2C_HOLD <= '1' after idel*clk_dsc.period,
157 '0' after (idel+ilen)*clk_dsc.period;
158
159 when "data " => -- data
160 read_ea(iline, itxdata9);
161 readgen_ea(iline, itxdata);
162 read_ea(iline, irxdata9);
163 if irxdata9 = '0' then
164 simfifo_put(sv_sff_monc_cnt, sv_sff_monc_arr, itxdata);
165 else
166 readgen_ea(iline, irxdata);
167 simfifo_put(sv_sff_monc_cnt, sv_sff_monc_arr, c_cdata_escape);
168 simfifo_put(sv_sff_monc_cnt, sv_sff_monc_arr, irxdata);
169 end if;
170 dat9 := itxdata9 & itxdata;
171 simfifo_put(sv_sff_monb_cnt, sv_sff_monb_arr, dat9);
172
173 C2B_DI <= dat9;
174 C2B_ENA <= '1';
175
176 wait_stim2moni(CLK, clk_dsc);
177 wait_untilsignal(CLK, clk_dsc, C2B_BUSY, '0', nbusy);
178
179 writetimestamp(oline, CLK_CYCLE, ": stim ");
180 write(oline, itxdata9, right, 2);
181 write(oline, itxdata, right, 9);
182 writeoptint(oline, " nbusy=", nbusy);
183 writeline(output, oline);
184
185 wait_nextstim(CLK, clk_dsc);
186 C2B_ENA <= '0';
187
188 when others => -- unknown command
189 write(oline, string'("?? unknown command: "));
190 write(oline, dname);
191 writeline(output, oline);
192 report "aborting" severity failure;
193 end case;
194
195 else
196 report "failed to find command" severity failure;
197
198 end if;
199
200 testempty_ea(iline);
201 end loop; -- file_loop:
202
203 writetimestamp(oline, CLK_CYCLE, ": DONE ");
204 writeline(output, oline);
205
206 wait_nextstim(CLK, clk_dsc, 12);
207
208 CLK_STOP <= '1';
209
210 wait; -- suspend proc_stim forever
211 -- clock is stopped, sim will end
212
213 end process proc_stim;
214
215
216 proc_monc: process
217 variable oline : line;
218 variable nhold : integer := 0;
219 begin
220
221 loop
222 wait_nextmoni(CLK, clk_dsc);
223
224 if C2B_VAL = '1' then
225 if B2C_BUSY = '1' then -- c2b_hold = b2c_busy !
226 nhold := nhold + 1;
227 else
228 writetimestamp(oline, CLK_CYCLE, ": monc ");
229 write(oline, string'(" "));
230 write(oline, C2B_DO, right, 9);
231 writeoptint(oline, " nhold=", nhold);
232 simfifo_writetest(oline, sv_sff_monc_cnt, sv_sff_monc_arr, C2B_DO);
233 writeline(output, oline);
234 nhold := 0;
235 end if;
236 end if;
237
238 end loop;
239
240 end process proc_monc;
241
242
243 proc_monb: process
244 variable oline : line;
245 variable nhold : integer := 0;
246 begin
247
248 loop
249 wait_nextmoni(CLK, clk_dsc);
250
251 if B2C_VAL = '1' then
252 if B2C_HOLD = '1' then
253 nhold := nhold + 1;
254 else
255 writetimestamp(oline, CLK_CYCLE, ": monb ");
256 write(oline, B2C_DO(8), right, 2);
257 write(oline, B2C_DO(7 downto 0), right, 9);
258 writeoptint(oline, " nhold=", nhold);
259 simfifo_writetest(oline, sv_sff_monb_cnt, sv_sff_monb_arr, B2C_DO);
260 writeline(output, oline);
261 nhold := 0;
262 end if;
263 end if;
264
265 end loop;
266
267 end process proc_monb;
268
269end 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( 8 downto 0) slv9
Definition: slvtypes.vhd:41
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40
slbit := '0' C2B_ESCXON
Delay_length := 200 ns clk_offset
slbit := '0' RESET
shared simfifo_type ( 0 to 7, 8 downto 0) sv_sff_monb_arr
slbit := '0' CLK_STOP
slv8 :=( others => '0') C2B_DO
slbit := '0' C2B_BUSY
slbit := '0' C2B_VAL
slbit := '0' CLK
slbit := '0' C2B_ENA
slv9 :=( others => '0') B2C_DO
slbit := '0' B2C_HOLD
integer := 0 CLK_CYCLE
slv9 :=( others => '0') C2B_DI
shared natural :=:= 0 sv_sff_monc_cnt
clock_dsc :=( 20 ns, 1 ns, 1 ns) clk_dsc
slbit := '0' B2C_VAL
slbit := '0' B2C_BUSY
shared simfifo_type ( 0 to 7, 7 downto 0) sv_sff_monc_arr
shared natural :=:= 0 sv_sff_monb_cnt
slbit := '0' C2B_ESCFILL
out C2B_DO slv8
out B2C_DO slv9
in C2B_ESCFILL slbit
out B2C_BUSY slbit
in B2C_HOLD slbit
out C2B_VAL slbit
out B2C_VAL slbit
out C2B_BUSY slbit
in C2B_ENA slbit
in C2B_ESCXON slbit