1 |
2 |
sckoarn |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Copyright 2007 Ken Campbell
|
3 |
|
|
-------------------------------------------------------------------------------
|
4 |
|
|
-- $Author: sckoarn $
|
5 |
|
|
--
|
6 |
4 |
sckoarn |
-- $Date: 2007-08-21 02:43:14 $
|
7 |
2 |
sckoarn |
--
|
8 |
|
|
-- $Name: not supported by cvs2svn $
|
9 |
|
|
--
|
10 |
4 |
sckoarn |
-- $Id: tb_pkg_header.vhd,v 1.2 2007-08-21 02:43:14 sckoarn Exp $
|
11 |
2 |
sckoarn |
--
|
12 |
|
|
-- $Source: /home/marcus/revision_ctrl_test/oc_cvs/cvs/vhld_tb/source/tb_pkg_header.vhd,v $
|
13 |
|
|
--
|
14 |
|
|
-- Description : The the testbench package header 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 |
|
|
-- Foobar is distributed in the hope that it will be useful,
|
26 |
|
|
-- 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 |
4 |
sckoarn |
-- Revision 1.1.1.1 2007/04/06 04:06:48 sckoarn
|
37 |
|
|
-- Import of the vhld_tb
|
38 |
2 |
sckoarn |
--
|
39 |
4 |
sckoarn |
--
|
40 |
2 |
sckoarn |
-------------------------------------------------------------------------------
|
41 |
|
|
library IEEE;
|
42 |
|
|
|
43 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
44 |
|
|
use IEEE.STD_LOGIC_ARITH.all;
|
45 |
|
|
use std.textio.all;
|
46 |
|
|
library ieee_proposed;
|
47 |
|
|
use ieee_proposed.STD_LOGIC_1164_additions.all;
|
48 |
|
|
|
49 |
4 |
sckoarn |
package tb_pkg is
|
50 |
2 |
sckoarn |
|
51 |
|
|
-- Constants
|
52 |
|
|
constant max_str_len : integer := 256;
|
53 |
|
|
constant max_field_len : integer := 48;
|
54 |
|
|
constant c_stm_text_len : integer := 128;
|
55 |
|
|
-- file handles
|
56 |
|
|
file stimulus : text; -- file main file
|
57 |
|
|
file include_file : text; -- file declaration for includes
|
58 |
|
|
|
59 |
|
|
-- Type Def's
|
60 |
|
|
type base is (bin, oct, hex, dec);
|
61 |
|
|
-- subtype stack_element is integer range 0 to 8192;
|
62 |
|
|
type stack_register is array(7 downto 0) of integer;
|
63 |
|
|
type state_register is array(7 downto 0) of boolean;
|
64 |
|
|
type int_array is array(1 to 16) of integer;
|
65 |
|
|
|
66 |
|
|
subtype text_line is string(1 to max_str_len);
|
67 |
|
|
subtype text_field is string(1 to max_field_len);
|
68 |
|
|
subtype stm_text is string(1 to c_stm_text_len);
|
69 |
|
|
type stm_text_ptr is access stm_text;
|
70 |
|
|
-- define the stimulus line record and access
|
71 |
|
|
type stim_line;
|
72 |
|
|
type stim_line_ptr is access stim_line; -- Pointer to stim_line record
|
73 |
|
|
type stim_line is record
|
74 |
|
|
instruction: text_field;
|
75 |
|
|
inst_field_1: text_field;
|
76 |
|
|
inst_field_2: text_field;
|
77 |
|
|
inst_field_3: text_field;
|
78 |
|
|
inst_field_4: text_field;
|
79 |
|
|
inst_field_5: text_field;
|
80 |
|
|
inst_field_6: text_field;
|
81 |
|
|
txt: stm_text_ptr;
|
82 |
|
|
line_number: integer; -- sequence line
|
83 |
|
|
num_of_lines: integer; -- total number of lines
|
84 |
|
|
file_line: integer; -- file line number
|
85 |
|
|
file_name: text_line;
|
86 |
|
|
next_rec: stim_line_ptr;
|
87 |
|
|
end record;
|
88 |
|
|
-- define the variables field and pointer
|
89 |
|
|
type var_field;
|
90 |
|
|
type var_field_ptr is access var_field; -- pointer to var_field
|
91 |
|
|
type var_field is record
|
92 |
|
|
var_name: text_field;
|
93 |
|
|
var_index: integer;
|
94 |
|
|
var_value: integer;
|
95 |
|
|
next_rec: var_field_ptr;
|
96 |
|
|
end record;
|
97 |
|
|
-- define the instruction structure
|
98 |
|
|
type inst_def;
|
99 |
|
|
type inst_def_ptr is access inst_def;
|
100 |
|
|
type inst_def is record
|
101 |
|
|
instruction: text_field;
|
102 |
|
|
instruction_l: integer;
|
103 |
|
|
params: integer;
|
104 |
|
|
next_rec: inst_def_ptr;
|
105 |
|
|
end record;
|
106 |
|
|
|
107 |
|
|
---*****************************************************************************
|
108 |
|
|
-- Function Declaration
|
109 |
|
|
-- function str_len(variable line: text_line) return text_field;
|
110 |
|
|
-- function fld_len(s : in text_field) integer;
|
111 |
|
|
function ew_to_slv(value : in integer;
|
112 |
|
|
length : in integer) return std_logic_vector;
|
113 |
|
|
|
114 |
|
|
function c2std_vec(c: in character) return std_logic_vector;
|
115 |
|
|
|
116 |
|
|
--------------------------------------------------------------------------------
|
117 |
|
|
-- Procedure declarations
|
118 |
|
|
--------------------------------------------------------------------------
|
119 |
|
|
-- define_instruction
|
120 |
|
|
-- inputs file_name the file to be read from
|
121 |
|
|
--
|
122 |
|
|
-- output file_line a line of text from the file
|
123 |
|
|
procedure define_instruction(variable inst_set: inout inst_def_ptr;
|
124 |
|
|
constant inst: in string;
|
125 |
|
|
constant args: in integer);
|
126 |
|
|
|
127 |
|
|
--------------------------------------------------------------------------------
|
128 |
|
|
-- index_variable
|
129 |
|
|
-- inputs:
|
130 |
|
|
-- index: the index of the variable being accessed
|
131 |
|
|
-- outputs:
|
132 |
|
|
-- Variable Value
|
133 |
|
|
-- valid is 1 if valid 0 if not
|
134 |
|
|
procedure index_variable(variable var_list : in var_field_ptr;
|
135 |
|
|
variable index : in integer;
|
136 |
|
|
variable value : out integer;
|
137 |
|
|
variable valid : out integer);
|
138 |
|
|
|
139 |
|
|
--------------------------------------------------------------------------------
|
140 |
|
|
-- update_variable
|
141 |
|
|
-- inputs:
|
142 |
|
|
-- index: the index of the variable being accessed
|
143 |
|
|
-- outputs:
|
144 |
|
|
-- Variable Value
|
145 |
|
|
-- valid is 1 if valid 0 if not
|
146 |
|
|
procedure update_variable(variable var_list : in var_field_ptr;
|
147 |
|
|
variable index : in integer;
|
148 |
|
|
variable value : in integer;
|
149 |
|
|
variable valid : out integer);
|
150 |
|
|
|
151 |
|
|
-------------------------------------------------------------------------------
|
152 |
|
|
-- read_instruction_file
|
153 |
|
|
-- This procedure reads the instruction file, name passed throught file_name.
|
154 |
|
|
-- Pointers to records are passed in and out. A table of variables is created
|
155 |
|
|
-- with variable name and value (converted to integer). The instructions are
|
156 |
|
|
-- parsesed into the inst_sequ list. Instructions are validated against the
|
157 |
|
|
-- inst_set which must have been set up prior to loading the instruction file.
|
158 |
|
|
procedure read_instruction_file(constant file_name: string;
|
159 |
|
|
variable inst_set: inout inst_def_ptr;
|
160 |
|
|
variable var_list: inout var_field_ptr;
|
161 |
|
|
variable inst_sequ: inout stim_line_ptr);
|
162 |
|
|
|
163 |
|
|
------------------------------------------------------------------------------
|
164 |
|
|
-- access_inst_sequ
|
165 |
|
|
-- This procedure retreeves an instruction from the sequence of instructions.
|
166 |
|
|
-- Based on the line number you pass to it, it returns the instruction with
|
167 |
|
|
-- any variables substituted as integers.
|
168 |
|
|
procedure access_inst_sequ(variable inst_sequ : in stim_line_ptr;
|
169 |
|
|
variable var_list : in var_field_ptr;
|
170 |
|
|
variable sequ_num : in integer;
|
171 |
|
|
variable inst : out text_field;
|
172 |
|
|
variable p1 : out integer;
|
173 |
|
|
variable p2 : out integer;
|
174 |
|
|
variable p3 : out integer;
|
175 |
|
|
variable p4 : out integer;
|
176 |
|
|
variable p5 : out integer;
|
177 |
|
|
variable p6 : out integer;
|
178 |
|
|
variable txt : out stm_text_ptr;
|
179 |
|
|
variable inst_len : out integer;
|
180 |
|
|
variable fname : out text_line;
|
181 |
|
|
variable file_line : out integer
|
182 |
|
|
);
|
183 |
|
|
------------------------------------------------------------------------
|
184 |
|
|
-- tokenize_line
|
185 |
|
|
-- This procedure takes a type text_line in and returns up to 6
|
186 |
|
|
-- tokens and the count in integer valid, as well if text string
|
187 |
|
|
-- is found the pointer to that is returned.
|
188 |
|
|
procedure tokenize_line(variable text_line: in text_line;
|
189 |
|
|
variable token1: out text_field;
|
190 |
|
|
variable token2: out text_field;
|
191 |
|
|
variable token3: out text_field;
|
192 |
|
|
variable token4: out text_field;
|
193 |
|
|
variable token5: out text_field;
|
194 |
|
|
variable token6: out text_field;
|
195 |
|
|
variable token7: out text_field;
|
196 |
|
|
variable txt_ptr: out stm_text_ptr;
|
197 |
|
|
variable valid: out integer);
|
198 |
|
|
-------------------------------------------------------------------------
|
199 |
|
|
-- string convertion
|
200 |
|
|
function ew_to_str(int: integer; b: base) return text_field;
|
201 |
|
|
function to_str(int: integer) return string;
|
202 |
|
|
|
203 |
|
|
-------------------------------------------------------------------------
|
204 |
|
|
-- Procedre print
|
205 |
|
|
-- print to stdout string
|
206 |
|
|
procedure print(s: in string);
|
207 |
|
|
-------------------------------------------------------------------------
|
208 |
|
|
-- Procedure print stim txt
|
209 |
|
|
procedure txt_print(variable ptr: in stm_text_ptr);
|
210 |
|
|
-------------------------------------------------------------------------
|
211 |
|
|
-- Procedure print stim txt sub variables found
|
212 |
|
|
procedure txt_print_wvar(variable var_list : in var_field_ptr;
|
213 |
|
|
variable ptr : in stm_text_ptr;
|
214 |
|
|
constant b : in base);
|
215 |
|
|
-------------------------------------------------------------------------
|
216 |
|
|
-- dump inst_sequ
|
217 |
|
|
-- This procedure dumps to the simulation window the current instruction
|
218 |
|
|
-- sequence. The whole thing will be dumped, which could be big.
|
219 |
|
|
-- ** intended for testbench development debug**
|
220 |
|
|
procedure dump_inst_sequ(variable inst_sequ : in stim_line_ptr);
|
221 |
|
|
|
222 |
4 |
sckoarn |
end tb_pkg;
|