OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [rtl/] [vlib/] [rlink/] [tb/] [tbcore_rlink.vhd] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 18 wfjm
-- $Id: tbcore_rlink.vhd 469 2013-01-05 12:29:44Z mueller $
2 2 wfjm
--
3 18 wfjm
-- Copyright 2010-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 2 wfjm
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
-- 
14
------------------------------------------------------------------------------
15 9 wfjm
-- Module Name:    tbcore_rlink - sim
16
-- Description:    Core for a rlink_cext based test bench
17 2 wfjm
--
18 17 wfjm
-- Dependencies:   simlib/simclkcnt
19 2 wfjm
--
20 9 wfjm
-- To test:        generic, any rlink_cext based target
21 2 wfjm
--
22
-- Target Devices: generic
23 13 wfjm
-- Tool versions:  xst 11.4, 13.1; ghdl 0.26-0.29
24 2 wfjm
-- Revision History: 
25
-- Date         Rev Version  Comment
26 18 wfjm
-- 2013-01-04   469   3.1.2  use 1ns wait for .sinit to allow simbus debugging
27 17 wfjm
-- 2011-12-25   445   3.1.1  add SB_ init drivers to avoid SB_VAL='U' at start
28
-- 2011-12-23   444   3.1    redo clock handling, remove simclk, CLK now input
29 13 wfjm
-- 2011-11-19   427   3.0.1  now numeric_std clean
30 9 wfjm
-- 2010-12-29   351   3.0    rename rritb_core->tbcore_rlink; use rbv3 naming
31
-- 2010-06-05   301   1.1.2  rename .rpmon -> .rbmon
32 2 wfjm
-- 2010-05-02   287   1.1.1  rename config command .sdata -> .sinit;
33
--                           use sbcntl_sbf_(cp|rp)mon defs, use rritblib;
34
-- 2010-04-25   283   1.1    new clk handling in proc_stim, wait period-setup
35
-- 2010-04-24   282   1.0    Initial version (from vlib/s3board/tb/tb_s3board)
36
------------------------------------------------------------------------------
37
 
38
library ieee;
39
use ieee.std_logic_1164.all;
40 13 wfjm
use ieee.numeric_std.all;
41 2 wfjm
use ieee.std_logic_textio.all;
42
use std.textio.all;
43
 
44
use work.slvtypes.all;
45
use work.simlib.all;
46
use work.simbus.all;
47 9 wfjm
use work.rblib.all;
48
use work.rlinklib.all;
49
use work.rlinktblib.all;
50
use work.rlink_cext_vhpi.all;
51 2 wfjm
 
52 9 wfjm
entity tbcore_rlink is                  -- core of rlink_cext based test bench
53 2 wfjm
  port (
54 17 wfjm
    CLK : in slbit;                     -- control interface clock
55
    CLK_STOP : out slbit;               -- clock stop trigger
56 2 wfjm
    RX_DATA : out slv8;                 -- read data         (data ext->tb)
57
    RX_VAL : out slbit;                 -- read data valid   (data ext->tb)
58
    RX_HOLD : in slbit;                 -- read data hold    (data ext->tb)
59
    TX_DATA : in slv8;                  -- write data        (data tb->ext)
60
    TX_ENA : in slbit                   -- write data enable (data tb->ext)
61
  );
62 9 wfjm
end tbcore_rlink;
63 2 wfjm
 
64 9 wfjm
architecture sim of tbcore_rlink is
65 17 wfjm
 
66
  signal CLK_CYCLE : integer := 0;
67 2 wfjm
 
68
begin
69 17 wfjm
 
70
  CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
71 2 wfjm
 
72
  proc_conf: process
73 9 wfjm
    file fconf : text open read_mode is "rlink_cext_conf";
74 2 wfjm
    variable iline : line;
75
    variable oline : line;
76
    variable ok : boolean;
77
    variable dname : string(1 to 6) := (others=>' ');
78
    variable ien : slbit := '0';
79
    variable ibit : integer := 0;
80
    variable iaddr : slv8 := (others=>'0');
81
    variable idata : slv16 := (others=>'0');
82
  begin
83
 
84
    SB_CNTL <= (others=>'L');
85
    SB_VAL  <= 'L';
86
    SB_ADDR <= (others=>'L');
87
    SB_DATA <= (others=>'L');
88
 
89
    file_loop: while not endfile(fconf) loop
90
 
91
      readline (fconf, iline);
92
      readcomment(iline, ok);
93
      next file_loop when ok;
94
      readword(iline, dname, ok);
95
 
96
      if ok then
97
        case dname is
98
 
99
          when ".scntl" =>              -- .scntl
100
            read_ea(iline, ibit);
101
            read_ea(iline, ien);
102
            assert (ibit>=SB_CNTL'low and ibit<=SB_CNTL'high)
103
              report "assert bit number in range of SB_CNTL"
104
              severity failure;
105
            if ien = '1' then
106
              SB_CNTL(ibit) <= 'H';
107
            else
108
              SB_CNTL(ibit) <= 'L';
109
            end if;
110
 
111 9 wfjm
          when ".rlmon" =>              -- .rlmon
112 2 wfjm
            read_ea(iline, ien);
113
            if ien = '1' then
114 9 wfjm
              SB_CNTL(sbcntl_sbf_rlmon) <= 'H';
115 2 wfjm
            else
116 9 wfjm
              SB_CNTL(sbcntl_sbf_rlmon) <= 'L';
117 2 wfjm
            end if;
118
 
119
          when ".rbmon" =>              -- .rbmon
120
            read_ea(iline, ien);
121
            if ien = '1' then
122
              SB_CNTL(sbcntl_sbf_rbmon) <= 'H';
123
            else
124
              SB_CNTL(sbcntl_sbf_rbmon) <= 'L';
125
            end if;
126
 
127
          when ".sinit" =>              -- .sinit
128
            readgen_ea(iline, iaddr, 8);
129
            readgen_ea(iline, idata, 8);
130
            SB_ADDR <= iaddr;
131
            SB_DATA <= idata;
132
            SB_VAL  <= 'H';
133 18 wfjm
            wait for 1 ns;
134 2 wfjm
            SB_VAL  <= 'L';
135
            SB_ADDR <= (others=>'L');
136
            SB_DATA <= (others=>'L');
137 18 wfjm
            wait for 1 ns;
138 2 wfjm
 
139
          when others =>                -- bad command
140
            write(oline, string'("?? unknown command: "));
141
            write(oline, dname);
142
            writeline(output, oline);
143
            report "aborting" severity failure;
144
        end case;
145
      else
146
        report "failed to find command" severity failure;
147
      end if;
148
 
149
      testempty_ea(iline);
150
 
151
    end loop; -- file_loop:
152
 
153 17 wfjm
    SB_VAL  <= 'L';
154
    SB_ADDR <= (others=>'L');
155
    SB_DATA <= (others=>'L');
156
 
157 2 wfjm
    wait;     -- halt process here 
158
 
159
  end process proc_conf;
160
 
161
  proc_stim: process
162
    variable irxint : integer := 0;
163
    variable irxslv : slv24 := (others=>'0');
164
    variable ibit : integer := 0;
165
    variable oline : line;
166
    variable r_sb_cntl : slv16 := (others=>'Z');
167
    variable iaddr : slv8 := (others=>'0');
168
    variable idata : slv16 := (others=>'0');
169
  begin
170
 
171 17 wfjm
    -- setup init values for all output ports
172
    CLK_STOP <= '0';
173
    RX_DATA  <= (others=>'0');
174
    RX_VAL   <= '0';
175 2 wfjm
 
176 17 wfjm
    SB_VAL  <= 'Z';
177
    SB_ADDR <= (others=>'Z');
178
    SB_DATA <= (others=>'Z');
179
 
180
    -- wait for 10 clock cycles (design run up)
181
    for i in 0 to 9 loop
182
      wait until rising_edge(CLK);
183
    end loop;  -- i
184
 
185 2 wfjm
    stim_loop: loop
186
 
187 17 wfjm
      wait until falling_edge(CLK);
188
 
189 2 wfjm
      SB_ADDR <= (others=>'Z');
190
      SB_DATA <= (others=>'Z');
191
 
192
      RX_VAL <= '0';
193
 
194
      if RX_HOLD = '0'  then
195 17 wfjm
        irxint := rlink_cext_getbyte(CLK_CYCLE);
196 2 wfjm
        if irxint >= 0 then
197
          if irxint <= 16#ff# then      -- normal data byte
198 13 wfjm
            RX_DATA <= slv(to_unsigned(irxint, 8));
199 2 wfjm
            RX_VAL  <= '1';
200
          elsif irxint >= 16#1000000# then  -- out-of-band message
201 13 wfjm
            irxslv := slv(to_unsigned(irxint mod 16#1000000#, 24));
202 2 wfjm
            iaddr := irxslv(23 downto 16);
203
            idata := irxslv(15 downto  0);
204 17 wfjm
            writetimestamp(oline, CLK_CYCLE, ": OOB-MSG");
205 2 wfjm
            write(oline, irxslv(23 downto 16), right, 9);
206
            write(oline, irxslv(15 downto  8), right, 9);
207
            write(oline, irxslv( 7 downto  0), right, 9);
208
            write(oline, string'(" : "));
209
            writeoct(oline, iaddr, right, 3);
210
            writeoct(oline, idata, right, 7);
211
            writeline(output, oline);
212
            if unsigned(iaddr) = 0 then
213 13 wfjm
              ibit := to_integer(unsigned(idata(15 downto 8)));
214 2 wfjm
              r_sb_cntl(ibit) := idata(0);
215
            else
216
              SB_ADDR <= iaddr;
217
              SB_DATA <= idata;
218
              SB_VAL  <= '1';
219
              wait for 0 ns;
220
              SB_VAL  <= 'Z';
221
              wait for 0 ns;
222
            end if;
223
          end if;
224
        elsif irxint = -1 then           -- end-of-file seen
225
          exit stim_loop;
226
        else
227 9 wfjm
          report "rlink_cext_getbyte error: " & integer'image(-irxint)
228 2 wfjm
            severity failure;
229
        end if;
230
      end if;
231
 
232
      SB_CNTL <= r_sb_cntl;
233
 
234
    end loop;
235
 
236 17 wfjm
    -- wait for 50 clock cycles (design run down)
237
    for i in 0 to 49 loop
238
      wait until rising_edge(CLK);
239
    end loop;  -- i
240
 
241 2 wfjm
    CLK_STOP <= '1';
242
 
243 17 wfjm
    writetimestamp(oline, CLK_CYCLE, ": DONE ");
244 2 wfjm
    writeline(output, oline);
245
 
246
    wait;                               -- suspend proc_stim forever
247
                                        -- clock is stopped, sim will end
248
 
249
  end process proc_stim;
250
 
251
  proc_moni: process
252
    variable itxdata : integer := 0;
253
    variable itxrc : integer := 0;
254
    variable oline : line;
255
  begin
256
 
257
    loop
258 17 wfjm
      wait until rising_edge(CLK);
259 2 wfjm
      if TX_ENA = '1' then
260 13 wfjm
        itxdata := to_integer(unsigned(TX_DATA));
261 9 wfjm
        itxrc := rlink_cext_putbyte(itxdata);
262 2 wfjm
        assert itxrc=0
263 9 wfjm
          report "rlink_cext_putbyte error: "  & integer'image(itxrc)
264 2 wfjm
          severity failure;
265
      end if;
266
 
267
    end loop;
268
 
269
  end process proc_moni;
270
 
271
end sim;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.