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

Subversion Repositories vhld_tb

[/] [vhld_tb/] [trunk/] [examples/] [example1/] [vhdl/] [example_dut_tb_bhv.vhd] - Blame information for rev 16

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

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

powered by: WebSVN 2.1.0

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