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

Subversion Repositories vhld_tb

[/] [vhld_tb/] [trunk/] [source/] [template_tb_bhv.vhd] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sckoarn
-------------------------------------------------------------------------------
2
--             Copyright 2007  Ken Campbell
3
-------------------------------------------------------------------------------
4
-- $Author: sckoarn $
5
--
6 10 sckoarn
-- $Date: 2007-09-02 04:04:04 $
7 2 sckoarn
--
8
-- $Name: not supported by cvs2svn $
9
--
10 10 sckoarn
-- $Id: template_tb_bhv.vhd,v 1.2 2007-09-02 04:04:04 sckoarn Exp $
11 2 sckoarn
--
12
-- $Source: /home/marcus/revision_ctrl_test/oc_cvs/cvs/vhld_tb/source/template_tb_bhv.vhd,v $
13
--
14
-- Description :  The the testbench package template behave file.
15
--                Initial GNU release.
16
--
17
------------------------------------------------------------------------------
18
--This file is part of The VHDL Test Bench.
19
--
20
--    The VHDL Test Bench is free software; you can redistribute it and/or modify
21
--    it under the terms of the GNU General Public License as published by
22
--    the Free Software Foundation; either version 2 of the License, or
23
--    (at your option) any later version.
24
--
25 10 sckoarn
--    The VHDL Test Bench  is distributed in the hope that it will be useful,
26 2 sckoarn
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
27
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
--    GNU General Public License for more details.
29
--
30
--    You should have received a copy of the GNU General Public License
31
--    along with The VHDL Test Bench; if not, write to the Free Software
32
--    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
33
-------------------------------------------------------------------------------
34
-- Revision History:
35
-- $Log: not supported by cvs2svn $
36 10 sckoarn
-- Revision 1.1.1.1  2007/04/06 04:06:48  sckoarn
37
-- Import of the vhld_tb
38 2 sckoarn
--
39 10 sckoarn
--
40 2 sckoarn
-------------------------------------------------------------------------------
41
 
42
architecture bhv of tb_Top is
43
 
44
 
45
  signal tb_clk            : std_logic;
46
 
47
-------------------------------------------------------------------------
48
-- Component defintion
49
 
50
-------------------------------------------------------------------------------
51
-- USER Component instantiations
52
--for all: Arbitor      use entity tb_objects.arbitor(bhv);
53
 
54
 
55
  begin
56
 
57
-------------------------------------------------------------------------------
58
-- clock driver process
59
-- the main clock generator
60
clock_driver:
61
  process
62
  begin
63
    tb_clk <=  '0';
64
    wait for 5 ns;
65
    tb_clk <=  '1';
66
    wait for 5 ns;
67
  end process clock_driver;
68
 
69
  --------------------------------------------------------------------------
70
  -- Read_file Process:
71
  --
72
  -- This process is the main process of the testbench.  This process reads
73
  -- the stumulus file, parses it, creates lists of records, then uses these
74
  -- lists to exicute user instructions.  There are two passes through the
75
  -- script.  Pass one reads in the stimulus text file, checks it, creates
76
  -- lists of valid instructions, valid list of variables and finialy a list
77
  -- of user instructions(the sequence).  The second pass through the file,
78
  -- records are drawn from the user instruction list, variables are converted
79
  -- to integers and put through the elsif structure for exicution.
80
  --------------------------------------------------------------------------
81
  Read_file: process
82
    variable current_line : text_line;  -- The current input line
83
    variable inst_list    : inst_def_ptr;  -- the instruction list
84
    variable defined_vars : var_field_ptr; -- defined variables
85
    variable inst_sequ    : stim_line_ptr; -- the instruction sequence
86 10 sckoarn
    variable file_list    : file_def_ptr;  -- pointer to the list of file names
87 2 sckoarn
 
88
    variable instruction  : text_field;   -- instruction field
89
    variable par1         : integer;      -- paramiter 1
90
    variable par2         : integer;      -- paramiter 2
91
    variable par3         : integer;      -- paramiter 3
92
    variable par4         : integer;      -- paramiter 4
93
    variable par5         : integer;      -- paramiter 5
94
    variable par6         : integer;      -- paramiter 6
95
    variable txt          : stm_text_ptr;
96
    variable nbase        : base;         -- the number base to use
97
    variable len          : integer;      -- length of the instruction field
98
    variable file_line    : integer;      -- Line number in the stimulus file
99
    variable file_name    : text_line;    -- the file name the line came from
100
    variable v_line       : integer := 0; -- sequence number
101
    variable stack        : stack_register; -- Call stack
102
    variable stack_ptr    : integer  := 0;  -- call stack pointer
103
    variable wh_stack     : stack_register; -- while stack
104
    variable wh_dpth      : integer := 0;   -- while depth
105
    variable wh_ptr       : integer  := 0;  -- while pointer
106
    variable loop_num         : integer := 0;
107
    variable curr_loop_count  : int_array := (others => 0);
108
    variable term_loop_count  : int_array := (others => 0);
109
    variable loop_line        : int_array := (others => 0);
110
 
111
    variable messages     : boolean  := TRUE;
112
    variable if_state     : boolean  := FALSE;
113
    variable wh_state     : boolean  := FALSE;
114
    variable wh_end       : boolean  := FALSE;
115
    variable rand         : std_logic_vector(31 downto 0);
116
    variable rand_back    : std_logic_vector(31 downto 0);
117 10 sckoarn
    variable valid        : integer;
118 2 sckoarn
 
119 10 sckoarn
    --  scratchpad variables
120 2 sckoarn
    variable temp_int     : integer;
121
    variable temp_index   : integer;
122
    variable temp_str     : text_field;
123
    variable v_temp_vec1  : std_logic_vector(31 downto 0);
124
    variable v_temp_vec2  : std_logic_vector(31 downto 0);
125
 
126
    --------------------------------------------------------------------------
127
    --  Area for Procedures which may be usefull to more than one instruction.
128
    --    By coding here commonly used  code sections ...
129
    --    you know the benifits.
130
    ---------------------------------------------------------------------
131
    -----------------------------------------------------------------
132
    -- This procedure writes to the arbitor model access port
133
--    procedure arb_write(add: in integer; .....
134
--    end arb_write;
135
 
136
 
137
  begin  -- process Read_file
138
-- parse_tb1 start input initialization
139
    -----------------------------------------------------------------------
140
    --           Stimulus file instruction definition
141
    --  This is where the instructions used in the stimulus file are defined.
142
    --  Syntax is
143
    --     define_instruction(inst_def_ptr, instruction, paramiters)
144
    --           inst_def_ptr: is a record pointer defined in tb_pkg_header
145
    --           instruction:  the text instruction name  ie. "DEFINE_VAR"
146
    --           paramiters:   the number of fields or paramiters passed
147
    --
148
    --  Some basic instruction are created here, the user should create new
149
    --  instructions below the standard ones.
150
    ------------------------------------------------------------------------
151
    define_instruction(inst_list, "DEFINE_VAR", 2);  -- Define a Variable
152
    define_instruction(inst_list, "EQU_VAR", 2);
153
    define_instruction(inst_list, "ADD_VAR", 2);
154
    define_instruction(inst_list, "SUB_VAR", 2);
155
    define_instruction(inst_list, "CALL", 1);
156
    define_instruction(inst_list, "RETURN_CALL", 0);
157
    define_instruction(inst_list, "JUMP", 1);
158
    define_instruction(inst_list, "LOOP", 1);
159
    define_instruction(inst_list, "END_LOOP", 0);
160
    define_instruction(inst_list, "IF", 3);
161 10 sckoarn
    define_instruction(inst_list, "ELSEIF", 3);
162 2 sckoarn
    define_instruction(inst_list, "ELSE", 0);
163
    define_instruction(inst_list, "END_IF", 0);
164
    define_instruction(inst_list, "WHILE", 3);
165
    define_instruction(inst_list, "END_WHILE", 0);
166
    define_instruction(inst_list, "MESSAGES_OFF", 0);
167
    define_instruction(inst_list, "MESSAGES_ON", 0);
168
    define_instruction(inst_list, "ABORT", 0);       -- Error exit from sim
169
    define_instruction(inst_list, "FINISH", 0);      -- Normal exit from sim
170
    define_instruction(inst_list, "INCLUDE", 1);  -- Define a Variable
171
 
172
    --  User defined instructions
173
 
174
    ------------------------------------------------------------------------
175
    -- Read, test, and load the stimulus file
176 10 sckoarn
    read_instruction_file(stimulus_file, inst_list, defined_vars, inst_sequ,
177
                          file_list);
178 2 sckoarn
 
179
------------------------------------------------------------------------
180
-- Using the Instruction record list, get the instruction and implement
181
-- it as per the statements in the elsif tree.
182
  while(v_line < inst_sequ.num_of_lines) loop
183
    v_line := v_line + 1;
184 10 sckoarn
    access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
185 2 sckoarn
         par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
186
 
187
--------------------------------------------------------------------------
188 10 sckoarn
    --if(instruction(1 to len) = "DEFINE_VAR") then
189
    --  null;  -- This instruction was implemented while reading the file
190 2 sckoarn
 
191
--------------------------------------------------------------------------
192 10 sckoarn
    if(instruction(1 to len) = "INCLUDE") then
193 2 sckoarn
      null;  -- This instruction was implemented while reading the file
194
 
195
--------------------------------------------------------------------------
196
    elsif(instruction(1 to len) = "ABORT") then
197
      assert (false)
198
        report "The test has aborted due to an error!!"
199
      severity failure;
200
 
201
--------------------------------------------------------------------------
202
    elsif(instruction(1 to len) = "FINISH") then
203
      assert (false)
204
        report "Test Finished with NO errors!!"
205
      severity failure;
206
 
207
--------------------------------------------------------------------------
208
    elsif(instruction(1 to len) = "EQU_VAR") then
209
      update_variable(defined_vars, par1, par2, valid);
210
 
211
--------------------------------------------------------------------------
212
    elsif(instruction(1 to len) = "ADD_VAR") then
213
      index_variable(defined_vars, par1, temp_int, valid);
214
      if(valid /= 0) then
215
        temp_int  :=  temp_int + par2;
216
        update_variable(defined_vars, par1, temp_int, valid);
217
      else
218
        assert (false)
219
          report "ADD_VAR Error: Not a valid Variable??"
220
        severity failure;
221
      end if;
222
 
223
--------------------------------------------------------------------------
224
    elsif(instruction(1 to len) = "SUB_VAR") then
225
      index_variable(defined_vars, par1, temp_int, valid);
226
      if(valid /= 0) then
227
        temp_int  :=  temp_int - par2;
228
        update_variable(defined_vars, par1, temp_int, valid);
229
      else
230
        assert (false)
231
          report "SUB_VAR Error: Not a valid Variable??"
232
        severity failure;
233
      end if;
234
 
235
--------------------------------------------------------------------------
236
    elsif(instruction(1 to len) = "CALL") then
237
      if(stack_ptr >= 7) then
238
        assert (false)
239
          report "Call Error: Stack over run, calls to deeply nested!!"
240
        severity failure;
241
      end if;
242
      stack(stack_ptr)  :=  v_line;
243
      stack_ptr  :=  stack_ptr + 1;
244
      v_line       :=  par1 - 1;
245
 
246
--------------------------------------------------------------------------
247
    elsif(instruction(1 to len) = "RETURN_CALL") then
248
      if(stack_ptr <= 0) then
249
        assert (false)
250
          report "Call Error: Stack under run??"
251
        severity failure;
252
      end if;
253
      stack_ptr  :=  stack_ptr - 1;
254
      v_line  :=  stack(stack_ptr);
255
 
256
--------------------------------------------------------------------------
257
    elsif(instruction(1 to len) = "JUMP") then
258
      v_line    :=  par1 - 1;
259
      wh_state  :=  false;
260
      wh_stack  := (others => 0);
261
      wh_dpth   := 0;
262
      wh_ptr    := 0;
263
      stack     := (others => 0);
264
      stack_ptr := 0;
265
 
266
--------------------------------------------------------------------------------
267
     elsif (instruction(1 to len) = "LOOP") then
268
        loop_num := loop_num + 1;
269
        loop_line(loop_num) := v_line;
270
        curr_loop_count(loop_num) := 0;
271
        term_loop_count(loop_num) := par1;
272
        assert (messages)
273
          report LF & "Executing LOOP Command" &
274
                 LF & "  Nested Loop:" & HT & integer'image(loop_num) &
275
                 LF & "  Loop Length:" & HT & integer'image(par1)
276
          severity note;
277
 
278
--------------------------------------------------------------------------------
279
     elsif (instruction(1 to len) = "END_LOOP") then
280
        curr_loop_count(loop_num) := curr_loop_count(loop_num) + 1;
281
        if (curr_loop_count(loop_num) = term_loop_count(loop_num)) then
282
          loop_num := loop_num - 1;
283
        else
284
          v_line := loop_line(loop_num);
285
        end if;
286
 
287
--------------------------------------------------------------------------------
288
     elsif (instruction(1 to len) = "IF") then
289
       if_state  :=  false;
290
       case par2 is
291
         when 0 => if(par1 = par3) then if_state  :=  true; end if;
292
         when 1 => if(par1 > par3) then if_state  :=  true; end if;
293
         when 2 => if(par1 < par3) then if_state  :=  true; end if;
294
         when 3 => if(par1 /= par3) then if_state :=  true; end if;
295
         when 4 => if(par1 >= par3) then if_state :=  true; end if;
296
         when 5 => if(par1 <= par3) then if_state :=  true; end if;
297
         when others =>
298
           assert (false)
299
             report LF & "ERROR:  IF instruction got an unexpected value" &
300
                 LF & "  in parameter 2!" & LF &
301
                  "Found on line " & (ew_to_str(file_line,dec)) & " in file " & file_name
302
             severity failure;
303
       end case;
304
 
305
       if(if_state = false) then
306
         v_line := v_line + 1;
307 10 sckoarn
         access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
308 2 sckoarn
             par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
309
         while(instruction(1 to len) /= "ELSE" and
310
               instruction(1 to len) /= "ELSEIF" and
311
               instruction(1 to len) /= "END_IF") loop
312
           if(v_line < inst_sequ.num_of_lines) then
313
             v_line := v_line + 1;
314 10 sckoarn
             access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
315 2 sckoarn
                 par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
316
           else
317
             assert (false)
318
              report LF & "ERROR:  IF instruction unable to find terminating" &
319
                     LF & "    ELSE, ELSEIF or END_IF statement."
320
              severity failure;
321
           end if;
322
         end loop;
323
         v_line := v_line - 1;  -- re-align so it will be operated on.
324
       end if;
325
 
326
--------------------------------------------------------------------------------
327
     elsif (instruction(1 to len) = "ELSEIF") then
328
       if(if_state = true) then  -- if the if_state is true then skip to the end
329
         v_line := v_line + 1;
330 10 sckoarn
         access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
331 2 sckoarn
             par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
332
         while(instruction(1 to len) /= "END_IF") loop
333
           if(v_line < inst_sequ.num_of_lines) then
334
             v_line := v_line + 1;
335 10 sckoarn
             access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
336 2 sckoarn
                 par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
337
           else
338
             assert (false)
339
              report LF & "ERROR:  IF instruction unable to find terminating" &
340
                     LF & "    ELSE, ELSEIF or END_IF statement."
341
              severity failure;
342
           end if;
343
         end loop;
344
         v_line := v_line - 1;  -- re-align so it will be operated on.
345
 
346
       else
347
         case par2 is
348
           when 0 => if(par1 = par3) then if_state  :=  true; end if;
349
           when 1 => if(par1 > par3) then if_state  :=  true; end if;
350
           when 2 => if(par1 < par3) then if_state  :=  true; end if;
351
           when 3 => if(par1 /= par3) then if_state :=  true; end if;
352
           when 4 => if(par1 >= par3) then if_state :=  true; end if;
353
           when 5 => if(par1 <= par3) then if_state :=  true; end if;
354
           when others =>
355
             assert (false)
356
               report LF & "ERROR:  ELSEIF instruction got an unexpected value" &
357
                   LF & "  in parameter 2!" & LF &
358
                    "Found on line " & (ew_to_str(file_line,dec)) & " in file " & file_name
359
               severity failure;
360
         end case;
361
 
362
         if(if_state = false) then
363
           v_line := v_line + 1;
364 10 sckoarn
           access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
365 2 sckoarn
               par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
366
           while(instruction(1 to len) /= "ELSE" and
367
                 instruction(1 to len) /= "ELSEIF" and
368
                 instruction(1 to len) /= "END_IF") loop
369
             if(v_line < inst_sequ.num_of_lines) then
370
               v_line := v_line + 1;
371 10 sckoarn
               access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
372 2 sckoarn
                   par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
373
             else
374
               assert (false)
375
                report LF & "ERROR:  ELSEIF instruction unable to find terminating" &
376
                       LF & "    ELSE, ELSEIF or END_IF statement."
377
                severity failure;
378
             end if;
379
           end loop;
380
           v_line := v_line - 1;  -- re-align so it will be operated on.
381
         end if;
382
       end if;
383
 
384
--------------------------------------------------------------------------------
385
     elsif (instruction(1 to len) = "ELSE") then
386
       if(if_state = true) then  -- if the if_state is true then skip the else
387
         v_line := v_line + 1;
388 10 sckoarn
         access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
389 2 sckoarn
             par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
390
         while(instruction(1 to len) /= "END_IF") loop
391
           if(v_line < inst_sequ.num_of_lines) then
392
             v_line := v_line + 1;
393 10 sckoarn
             access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
394 2 sckoarn
                 par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
395
           else
396
             assert (false)
397
              report LF & "ERROR:  IF instruction unable to find terminating" &
398
                     LF & "    ELSE, ELSEIF or END_IF statement."
399
              severity failure;
400
           end if;
401
         end loop;
402
         v_line := v_line - 1;  -- re-align so it will be operated on.
403
       end if;
404
 
405
--------------------------------------------------------------------------------
406
     elsif (instruction(1 to len) = "END_IF") then
407
       null;  -- instruction is a place holder for finding the end of IF.
408
 
409
--------------------------------------------------------------------------------
410
     elsif (instruction(1 to len) = "WHILE") then
411
       wh_state  :=  false;
412
       case par2 is
413
         when 0 => if(par1 = par3) then if_state  :=  true; end if;
414
         when 1 => if(par1 > par3) then if_state  :=  true; end if;
415
         when 2 => if(par1 < par3) then if_state  :=  true; end if;
416
         when 3 => if(par1 /= par3) then if_state :=  true; end if;
417
         when 4 => if(par1 >= par3) then if_state :=  true; end if;
418
         when 5 => if(par1 <= par3) then if_state :=  true; end if;
419
         when others =>
420
           assert (false)
421
             report LF & "ERROR:  WHILE instruction got an unexpected value" &
422
                 LF & "  in parameter 2!" & LF &
423
                  "Found on line " & (ew_to_str(file_line,dec)) & " in file " & file_name
424
             severity failure;
425
       end case;
426
 
427
       if(wh_state = true) then
428
         wh_stack(wh_ptr) :=  v_line;
429
         wh_ptr  := wh_ptr + 1;
430
       else
431
         wh_end := false;
432
         while(wh_end /= true) loop
433
           if(v_line < inst_sequ.num_of_lines) then
434
             v_line := v_line + 1;
435 10 sckoarn
             access_inst_sequ(inst_sequ, defined_vars, file_list, v_line, instruction,
436 2 sckoarn
                 par1, par2, par3, par4, par5, par6, txt, len, file_name, file_line);
437
           else
438
             assert (false)
439
               report LF & "ERROR:  WHILE instruction unable to find terminating" &
440
                      LF & "    END_WHILE statement."
441
             severity failure;
442
           end if;
443
 
444
           -- if is a while need to escape it
445
           if(instruction(1 to len) = "WHILE") then
446
             wh_dpth := wh_dpth + 1;
447
           -- if is the end_while we are looking for
448
           elsif(instruction(1 to len) = "END_WHILE") then
449
             if(wh_dpth = 0) then
450
               wh_end := true;
451
             else
452
               wh_dpth := wh_dpth - 1;
453
             end if;
454
           end if;
455
         end loop;
456
       end if;
457
 
458
--------------------------------------------------------------------------------
459
     elsif (instruction(1 to len) = "END_WHILE") then
460
       if(wh_ptr > 0) then
461
         v_line  :=  wh_stack(wh_ptr - 1) - 1;
462
         wh_ptr  := wh_ptr - 1;
463
       end if;
464
 
465
--------------------------------------------------------------------------------
466
     elsif (instruction(1 to len) = "MESSAGES_OFF") then
467
       messages  := TRUE;
468
--------------------------------------------------------------------------------
469
     elsif (instruction(1 to len) = "MESSAGES_ON") then
470
       messages  := FALSE;
471
 
472
 
473
--------------------------------------------------------------------------------
474
--------------------------------------------------------------------------------
475
--  USER Istruction area.  Add all user instructions below this
476
--------------------------------------------------------------------------------
477
--------------------------------------------------------------------------------
478
--    elsif (instruction(1 to len) = "RESET_SYS") then
479
 
480
 
481
--------------------------------------------------------------------------------
482
--  USER Istruction area.  Add all user instructions above this
483
--------------------------------------------------------------------------------
484
    --------------------------------------------------------------------------
485
    -- catch those little mistakes
486
    else
487 10 sckoarn
      assert (false)
488
        report LF & "ERROR:  Seems the command  " & instruction(1 to len) & " was defined but" & LF &
489
                    "was not found in the elsif chain, please check spelling."
490 2 sckoarn
        severity failure;
491
    end if;  -- else if structure end
492 10 sckoarn
    -- after the instruction is finished print out any txt and sub vars
493
    txt_print_wvar(defined_vars, txt, hex);
494 2 sckoarn
  end loop;  -- Main Loop end
495
 
496
  assert (false)
497
    report LF & "The end of the simulation! It was not terminated as expected." & LF
498
  severity failure;
499
 
500
  end process Read_file;
501
 
502
 
503
end bhv;

powered by: WebSVN 2.1.0

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