w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tbcore_rlink.vhd
Go to the documentation of this file.
1-- $Id: tbcore_rlink.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2010-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: tbcore_rlink - sim
7-- Description: Core for a rlink_cext based test bench
8--
9-- Dependencies: simlib/simclkcnt
10-- rlink_cext_iface
11--
12-- To test: generic, any rlink_cext based target
13--
14-- Target Devices: generic
15-- Tool versions: ghdl 0.26-0.34
16-- Revision History:
17-- Date Rev Version Comment
18-- 2018-11-25 1074 3.3 wait 40 cycles after CONF_DONE
19-- 2016-09-17 807 3.2.2 conf: .sinit -> .sdata; finite length SB_VAL pulse
20-- 2016-09-02 805 3.2.1 conf: add .wait and CONF_DONE; drop CLK_STOP
21-- 2016-02-07 729 3.2 use rlink_cext_iface (allow VHPI and DPI backend)
22-- 2015-11-01 712 3.1.3 proc_stim: drive SB_CNTL from start to avoid 'U'
23-- 2013-01-04 469 3.1.2 use 1ns wait for .sinit to allow simbus debugging
24-- 2011-12-25 445 3.1.1 add SB_ init drivers to avoid SB_VAL='U' at start
25-- 2011-12-23 444 3.1 redo clock handling, remove simclk, CLK now input
26-- 2011-11-19 427 3.0.1 now numeric_std clean
27-- 2010-12-29 351 3.0 rename rritb_core->tbcore_rlink; use rbv3 naming
28-- 2010-06-05 301 1.1.2 rename .rpmon -> .rbmon
29-- 2010-05-02 287 1.1.1 rename config command .sdata -> .sinit;
30-- use sbcntl_sbf_(cp|rp)mon defs, use rritblib;
31-- 2010-04-25 283 1.1 new clk handling in proc_stim, wait period-setup
32-- 2010-04-24 282 1.0 Initial version (from vlib/s3board/tb/tb_s3board)
33------------------------------------------------------------------------------
34
35library ieee;
36use ieee.std_logic_1164.all;
37use ieee.numeric_std.all;
38use ieee.std_logic_textio.all;
39use std.textio.all;
40
41use work.slvtypes.all;
42use work.simlib.all;
43use work.simbus.all;
44use work.rblib.all;
45use work.rlinklib.all;
46
47entity tbcore_rlink is -- core of rlink_cext based test bench
48 port (
49 CLK : in slbit; -- control interface clock
50 RX_DATA : out slv8; -- read data (data ext->tb)
51 RX_VAL : out slbit; -- read data valid (data ext->tb)
52 RX_HOLD : in slbit; -- read data hold (data ext->tb)
53 TX_DATA : in slv8; -- write data (data tb->ext)
54 TX_ENA : in slbit -- write data enable (data tb->ext)
55 );
56end tbcore_rlink;
57
58architecture sim of tbcore_rlink is
59
60 signal CLK_CYCLE : integer := 0;
61 signal CEXT_CYCLE : slv32 := (others=>'0');
62 signal CEXT_RXDATA : slv32 := (others=>'0');
63 signal CEXT_RXVAL : slbit := '0';
64 signal CEXT_RXHOLD : slbit := '1';
65 signal CONF_DONE : slbit := '0';
66
67begin
68
69 CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
70
71 CEXT_IFACE : entity work.rlink_cext_iface
72 port map (
73 CLK => CLK,
79 TX_ENA => TX_ENA
80 );
81
82 CEXT_CYCLE <= slv(to_signed(CLK_CYCLE,32));
83
84 proc_conf: process
85 file fconf : text open read_mode is "rlink_cext_conf";
86 variable iline : line;
87 variable oline : line;
88 variable ok : boolean;
89 variable dname : string(1 to 6) := (others=>' ');
90 variable ien : slbit := '0';
91 variable ibit : integer := 0;
92 variable twait : Delay_length := 0 ns;
93 variable iaddr : slv8 := (others=>'0');
94 variable idata : slv16 := (others=>'0');
95 begin
96
97 CONF_DONE <= '0';
98 SB_SIMSTOP <= 'L';
99
100 SB_CNTL <= (others=>'L');
101 SB_VAL <= 'L';
102 SB_ADDR <= (others=>'L');
103 SB_DATA <= (others=>'L');
104
105 file_loop: while not endfile(fconf) loop
106
107 readline (fconf, iline);
108 readcomment(iline, ok);
109 next file_loop when ok;
110 readword(iline, dname, ok);
111
112 if ok then
113 case dname is
114
115 when ".scntl" => -- .scntl
116 read_ea(iline, ibit);
117 read_ea(iline, ien);
118 assert (ibit>=SB_CNTL'low and ibit<=SB_CNTL'high)
119 report "assert bit number in range of SB_CNTL"
120 severity failure;
121 wait for 1 ns;
122 if ien = '1' then
123 SB_CNTL(ibit) <= 'H';
124 else
125 SB_CNTL(ibit) <= 'L';
126 end if;
127
128 when ".rlmon" => -- .rlmon
129 read_ea(iline, ien);
130 wait for 1 ns;
131 if ien = '1' then
132 SB_CNTL(sbcntl_sbf_rlmon) <= 'H';
133 else
134 SB_CNTL(sbcntl_sbf_rlmon) <= 'L';
135 end if;
136
137 when ".rbmon" => -- .rbmon
138 read_ea(iline, ien);
139 wait for 1 ns;
140 if ien = '1' then
141 SB_CNTL(sbcntl_sbf_rbmon) <= 'H';
142 else
143 SB_CNTL(sbcntl_sbf_rbmon) <= 'L';
144 end if;
145
146 when ".sdata" => -- .sdata
147 readgen_ea(iline, iaddr, 16);
148 readgen_ea(iline, idata, 16);
149 wait for 1 ns;
150 SB_ADDR <= iaddr;
151 SB_DATA <= idata;
152 SB_VAL <= 'H';
153 wait for 1 ns;
154 SB_VAL <= 'L';
155 SB_ADDR <= (others=>'L');
156 SB_DATA <= (others=>'L');
157
158 when ".wait " => -- .wait
159 read_ea(iline, twait);
160 wait for twait;
161
162 when others => -- bad command
163 write(oline, string'("?? unknown command: "));
164 write(oline, dname);
165 writeline(output, oline);
166 report "aborting" severity failure;
167 end case;
168 else
169 report "failed to find command" severity failure;
170 end if;
171
172 testempty_ea(iline);
173
174 end loop; -- file_loop:
175
176 SB_VAL <= 'L';
177 SB_ADDR <= (others=>'L');
178 SB_DATA <= (others=>'L');
179
180 CONF_DONE <= '1';
181
182 wait; -- halt process here
183
184 end process proc_conf;
185
186 proc_stim: process
187 variable irxint : integer := 0;
188 variable irxslv : slv24 := (others=>'0');
189 variable ibit : integer := 0;
190 variable oline : line;
191 variable r_sb_cntl : slv16 := (others=>'Z');
192 variable iaddr : slv8 := (others=>'0');
193 variable idata : slv16 := (others=>'0');
194 begin
195
196 -- setup init values for all output ports
197 RX_DATA <= (others=>'0');
198 RX_VAL <= '0';
199
200 SB_VAL <= 'Z';
201 SB_ADDR <= (others=>'Z');
202 SB_DATA <= (others=>'Z');
203 SB_CNTL <= (others=>'Z');
204
205 CEXT_RXHOLD <= '1';
206
207 -- wait for CONF_DONE, plus addional 40 clock cycles (conf+design run up)
208 while CONF_DONE = '0' loop
209 wait until rising_edge(CLK);
210 end loop;
211 for i in 0 to 39 loop
212 wait until rising_edge(CLK);
213 end loop; -- i
214
215 writetimestamp(oline, CLK_CYCLE, ": START");
216 writeline(output, oline);
217
218 stim_loop: loop
219
220 wait until falling_edge(CLK);
221
222 SB_ADDR <= (others=>'Z');
223 SB_DATA <= (others=>'Z');
224
225 RX_VAL <= '0';
226
228
229 if RX_HOLD = '0' then
230 irxint := to_integer(signed(CEXT_RXDATA));
231 if CEXT_RXVAL = '1' then
232 if irxint <= 16#ff# then -- normal data byte
233 RX_DATA <= slv(to_unsigned(irxint, 8));
234 RX_VAL <= '1';
235 elsif irxint >= 16#1000000# then -- out-of-band message
236 irxslv := slv(to_unsigned(irxint mod 16#1000000#, 24));
237 iaddr := irxslv(23 downto 16);
238 idata := irxslv(15 downto 0);
239 writetimestamp(oline, CLK_CYCLE, ": OOB-MSG");
240 write(oline, irxslv(23 downto 16), right, 9);
241 write(oline, irxslv(15 downto 8), right, 9);
242 write(oline, irxslv( 7 downto 0), right, 9);
243 write(oline, string'(" : "));
244 writeoct(oline, iaddr, right, 3);
245 writeoct(oline, idata, right, 7);
246 writeline(output, oline);
247 if unsigned(iaddr) = 0 then
248 ibit := to_integer(unsigned(idata(15 downto 8)));
249 r_sb_cntl(ibit) := idata(0);
250 else
251 SB_ADDR <= iaddr;
252 SB_DATA <= idata;
253 -- In principle a delta cycle long pulse is enough to make the
254 -- simbus transfer. A 500 ps long pulse is generated to ensure
255 -- that SB_VAL is visible in a viewer. That works up to 1 GHz
256 SB_VAL <= '1';
257 wait for 500 ps;
258 SB_VAL <= 'Z';
259 wait for 0 ps;
260 end if;
261 end if;
262 elsif irxint = -1 then -- end-of-file seen
263 exit stim_loop;
264 else
265 report "rlink_cext_getbyte error: " & integer'image(-irxint)
266 severity failure;
267 end if; -- CEXT_RXVAL = '1'
268
269 end if; -- RX_HOLD = '0'
270
271 SB_CNTL <= r_sb_cntl;
272
273 end loop;
274
275 -- wait for 50 clock cycles (design run down)
276 for i in 0 to 49 loop
277 wait until rising_edge(CLK);
278 end loop; -- i
279
280 writetimestamp(oline, CLK_CYCLE, ": DONE ");
281 writeline(output, oline);
282
283 SB_SIMSTOP <= '1'; -- signal simulation stop
284 wait for 100 ns; -- monitor grace time
285 report "Simulation Finished" severity failure; -- end simulation
286
287 end process proc_stim;
288
289end sim;
Definition: rblib.vhd:32
out CLK_CYCLE integer
Definition: simclkcnt.vhd:29
in CLK slbit
Definition: simclkcnt.vhd:27
std_logic_vector( 31 downto 0) slv32
Definition: slvtypes.vhd:59
std_logic_vector( 15 downto 0) slv16
Definition: slvtypes.vhd:48
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40
std_logic_vector( 23 downto 0) slv24
Definition: slvtypes.vhd:57
std_logic_vector slv
Definition: slvtypes.vhd:31