1 |
19 |
sckoarn |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Copyright 2011 Ken Campbell
|
3 |
|
|
-------------------------------------------------------------------------------
|
4 |
|
|
-- $Author: sckoarn $
|
5 |
|
|
--
|
6 |
|
|
-- $Date: $
|
7 |
|
|
--
|
8 |
|
|
-- $Id: $
|
9 |
|
|
--
|
10 |
|
|
-- $Source: $
|
11 |
|
|
--
|
12 |
|
|
-- Description : The the testbench package header file.
|
13 |
|
|
-- GNU release 2 Beta.
|
14 |
|
|
--
|
15 |
|
|
------------------------------------------------------------------------------
|
16 |
|
|
--This file is part of The VHDL Test Bench.
|
17 |
|
|
--
|
18 |
|
|
-- The VHDL Test Bench is free software; you can redistribute it and/or modify
|
19 |
|
|
-- it under the terms of the GNU General Public License as published by
|
20 |
|
|
-- the Free Software Foundation; either version 2 of the License, or
|
21 |
|
|
-- (at your option) any later version.
|
22 |
|
|
--
|
23 |
|
|
-- The VHDL Test Bench is distributed in the hope that it will be useful,
|
24 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
25 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
26 |
|
|
-- GNU General Public License for more details.
|
27 |
|
|
--
|
28 |
|
|
-- You should have received a copy of the GNU General Public License
|
29 |
|
|
-- along with The VHDL Test Bench; if not, write to the Free Software
|
30 |
|
|
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
31 |
|
|
-------------------------------------------------------------------------------
|
32 |
|
|
library IEEE;
|
33 |
|
|
|
34 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
35 |
|
|
use IEEE.STD_LOGIC_ARITH.all;
|
36 |
|
|
use std.textio.all;
|
37 |
|
|
--library ieee_proposed;
|
38 |
|
|
--use ieee_proposed.STD_LOGIC_1164_additions.all;
|
39 |
|
|
|
40 |
|
|
package tb_pkg is
|
41 |
|
|
|
42 |
|
|
-- Constants
|
43 |
|
|
constant max_str_len : integer := 256;
|
44 |
|
|
constant max_field_len : integer := 48;
|
45 |
|
|
constant c_stm_text_len : integer := 200;
|
46 |
|
|
-- file handles
|
47 |
|
|
file stimulus : text; -- file main file
|
48 |
|
|
file include_file : text; -- file declaration for includes
|
49 |
|
|
|
50 |
|
|
-- Type Def's
|
51 |
|
|
type base is (bin, oct, hex, dec);
|
52 |
|
|
-- subtype stack_element is integer range 0 to 8192;
|
53 |
|
|
type stack_register is array(7 downto 0) of integer;
|
54 |
|
|
type state_register is array(7 downto 0) of boolean;
|
55 |
|
|
type int_array is array(1 to 16) of integer;
|
56 |
|
|
|
57 |
|
|
subtype text_line is string(1 to max_str_len);
|
58 |
|
|
subtype text_field is string(1 to max_field_len);
|
59 |
|
|
subtype stm_text is string(1 to c_stm_text_len);
|
60 |
|
|
type stm_text_ptr is access stm_text;
|
61 |
|
|
-- define the stimulus line record and access
|
62 |
|
|
type stim_line;
|
63 |
|
|
type stim_line_ptr is access stim_line; -- Pointer to stim_line record
|
64 |
|
|
type stim_line is record
|
65 |
|
|
instruction: text_field;
|
66 |
|
|
inst_field_1: text_field;
|
67 |
|
|
inst_field_2: text_field;
|
68 |
|
|
inst_field_3: text_field;
|
69 |
|
|
inst_field_4: text_field;
|
70 |
|
|
inst_field_5: text_field;
|
71 |
|
|
inst_field_6: text_field;
|
72 |
|
|
txt: stm_text_ptr;
|
73 |
|
|
line_number: integer; -- sequence line
|
74 |
|
|
num_of_lines: integer; -- total number of lines
|
75 |
|
|
file_line: integer; -- file line number
|
76 |
|
|
file_idx: integer;
|
77 |
|
|
next_rec: stim_line_ptr;
|
78 |
|
|
end record;
|
79 |
|
|
-- define the variables field and pointer
|
80 |
|
|
type var_field;
|
81 |
|
|
type var_field_ptr is access var_field; -- pointer to var_field
|
82 |
|
|
type var_field is record
|
83 |
|
|
var_name: text_field;
|
84 |
|
|
var_index: integer;
|
85 |
|
|
var_value: integer;
|
86 |
|
|
next_rec: var_field_ptr;
|
87 |
|
|
end record;
|
88 |
|
|
-- define the instruction structure
|
89 |
|
|
type inst_def;
|
90 |
|
|
type inst_def_ptr is access inst_def;
|
91 |
|
|
type inst_def is record
|
92 |
|
|
instruction: text_field;
|
93 |
|
|
instruction_l: integer;
|
94 |
|
|
params: integer;
|
95 |
|
|
next_rec: inst_def_ptr;
|
96 |
|
|
end record;
|
97 |
|
|
-- define the file handle record
|
98 |
|
|
type file_def;
|
99 |
|
|
type file_def_ptr is access file_def;
|
100 |
|
|
type file_def is record
|
101 |
|
|
rec_idx: integer;
|
102 |
|
|
file_name: text_line;
|
103 |
|
|
next_rec: file_def_ptr;
|
104 |
|
|
end record;
|
105 |
|
|
|
106 |
|
|
-- define the stimulus slave control record types
|
107 |
|
|
type stm_sctl is record
|
108 |
|
|
rst_n : std_logic;
|
109 |
|
|
addr : std_logic_vector(31 downto 0);
|
110 |
|
|
wdat : std_logic_vector(31 downto 0);
|
111 |
|
|
rwn : std_logic;
|
112 |
|
|
req_n : std_logic;
|
113 |
|
|
end record;
|
114 |
|
|
type stm_sack is record
|
115 |
|
|
rdat : std_logic_vector(31 downto 0);
|
116 |
|
|
ack_n : std_logic;
|
117 |
|
|
rdy_n : std_logic;
|
118 |
|
|
irq_n : std_logic;
|
119 |
|
|
end record;
|
120 |
|
|
-- define the stimulus master control record types
|
121 |
|
|
type stm_mctl is record
|
122 |
|
|
addr : std_logic_vector(31 downto 0);
|
123 |
|
|
wdat : std_logic_vector(31 downto 0);
|
124 |
|
|
rwn : std_logic;
|
125 |
|
|
req_n : std_logic;
|
126 |
|
|
breq : std_logic;
|
127 |
|
|
end record;
|
128 |
|
|
type stm_mack is record
|
129 |
|
|
rdat : std_logic_vector(31 downto 0);
|
130 |
|
|
slv_rdy : std_logic_vector(15 downto 0);
|
131 |
|
|
slv_irq : std_logic_vector(15 downto 0);
|
132 |
|
|
ack_n : std_logic;
|
133 |
|
|
bgrant : std_logic;
|
134 |
|
|
end record;
|
135 |
|
|
|
136 |
|
|
-----
|
137 |
|
|
-- stm interface neutral functions
|
138 |
|
|
function stm_neut return stm_sctl;
|
139 |
|
|
function stm_neut return stm_sack;
|
140 |
|
|
--function stm_neut() return stm_mctl;
|
141 |
|
|
--function stm_neut() return stm_mack;
|
142 |
|
|
|
143 |
|
|
---*****************************************************************************
|
144 |
|
|
-- Function Declaration
|
145 |
|
|
-- function str_len(variable line: text_line) return text_field;
|
146 |
|
|
-- function fld_len(s : in text_field) integer;
|
147 |
|
|
|
148 |
|
|
function c2std_vec(c: in character) return std_logic_vector;
|
149 |
|
|
|
150 |
|
|
--------------------------------------------------------------------------------
|
151 |
|
|
-- Procedure declarations
|
152 |
|
|
--------------------------------------------------------------------------
|
153 |
|
|
-- define_instruction
|
154 |
|
|
-- inputs file_name the file to be read from
|
155 |
|
|
--
|
156 |
|
|
-- output file_line a line of text from the file
|
157 |
|
|
procedure define_instruction(variable inst_set: inout inst_def_ptr;
|
158 |
|
|
constant inst: in string;
|
159 |
|
|
constant args: in integer);
|
160 |
|
|
|
161 |
|
|
--------------------------------------------------------------------------------
|
162 |
|
|
-- index_variable
|
163 |
|
|
-- inputs:
|
164 |
|
|
-- index: the index of the variable being accessed
|
165 |
|
|
-- outputs:
|
166 |
|
|
-- Variable Value
|
167 |
|
|
-- valid is 1 if valid 0 if not
|
168 |
|
|
procedure index_variable(variable var_list : in var_field_ptr;
|
169 |
|
|
variable index : in integer;
|
170 |
|
|
variable value : out integer;
|
171 |
|
|
variable valid : out integer);
|
172 |
|
|
|
173 |
|
|
--------------------------------------------------------------------------------
|
174 |
|
|
-- update_variable
|
175 |
|
|
-- inputs:
|
176 |
|
|
-- index: the index of the variable being accessed
|
177 |
|
|
-- outputs:
|
178 |
|
|
-- Variable Value
|
179 |
|
|
-- valid is 1 if valid 0 if not
|
180 |
|
|
procedure update_variable(variable var_list : in var_field_ptr;
|
181 |
|
|
variable index : in integer;
|
182 |
|
|
variable value : in integer;
|
183 |
|
|
variable valid : out integer);
|
184 |
|
|
|
185 |
|
|
-------------------------------------------------------------------------------
|
186 |
|
|
-- read_instruction_file
|
187 |
|
|
-- This procedure reads the instruction file, name passed throught file_name.
|
188 |
|
|
-- Pointers to records are passed in and out. A table of variables is created
|
189 |
|
|
-- with variable name and value (converted to integer). The instructions are
|
190 |
|
|
-- parsesed into the inst_sequ list. Instructions are validated against the
|
191 |
|
|
-- inst_set which must have been set up prior to loading the instruction file.
|
192 |
|
|
procedure read_instruction_file(constant file_name: string;
|
193 |
|
|
variable inst_set: inout inst_def_ptr;
|
194 |
|
|
variable var_list: inout var_field_ptr;
|
195 |
|
|
variable inst_sequ: inout stim_line_ptr;
|
196 |
|
|
variable file_list: inout file_def_ptr);
|
197 |
|
|
|
198 |
|
|
------------------------------------------------------------------------------
|
199 |
|
|
-- access_inst_sequ
|
200 |
|
|
-- This procedure retreeves an instruction from the sequence of instructions.
|
201 |
|
|
-- Based on the line number you pass to it, it returns the instruction with
|
202 |
|
|
-- any variables substituted as integers.
|
203 |
|
|
procedure access_inst_sequ(variable inst_sequ : in stim_line_ptr;
|
204 |
|
|
variable var_list : in var_field_ptr;
|
205 |
|
|
variable file_list : in file_def_ptr;
|
206 |
|
|
variable sequ_num : in integer;
|
207 |
|
|
variable inst : out text_field;
|
208 |
|
|
variable p1 : out integer;
|
209 |
|
|
variable p2 : out integer;
|
210 |
|
|
variable p3 : out integer;
|
211 |
|
|
variable p4 : out integer;
|
212 |
|
|
variable p5 : out integer;
|
213 |
|
|
variable p6 : out integer;
|
214 |
|
|
variable txt : out stm_text_ptr;
|
215 |
|
|
variable inst_len : out integer;
|
216 |
|
|
variable fname : out text_line;
|
217 |
|
|
variable file_line : out integer;
|
218 |
|
|
variable last_num : inout integer;
|
219 |
|
|
variable last_ptr : inout stim_line_ptr
|
220 |
|
|
);
|
221 |
|
|
------------------------------------------------------------------------
|
222 |
|
|
-- tokenize_line
|
223 |
|
|
-- This procedure takes a type text_line in and returns up to 6
|
224 |
|
|
-- tokens and the count in integer valid, as well if text string
|
225 |
|
|
-- is found the pointer to that is returned.
|
226 |
|
|
procedure tokenize_line(variable text_line: in text_line;
|
227 |
|
|
variable token1: out text_field;
|
228 |
|
|
variable token2: out text_field;
|
229 |
|
|
variable token3: out text_field;
|
230 |
|
|
variable token4: out text_field;
|
231 |
|
|
variable token5: out text_field;
|
232 |
|
|
variable token6: out text_field;
|
233 |
|
|
variable token7: out text_field;
|
234 |
|
|
variable txt_ptr: out stm_text_ptr;
|
235 |
|
|
variable valid: out integer);
|
236 |
|
|
-------------------------------------------------------------------------
|
237 |
|
|
-- string convertion
|
238 |
|
|
function ew_to_str(int: integer; b: base) return text_field;
|
239 |
|
|
function to_str(int: integer) return string;
|
240 |
|
|
|
241 |
|
|
-------------------------------------------------------------------------
|
242 |
|
|
-- Procedre print
|
243 |
|
|
-- print to stdout string
|
244 |
|
|
procedure print(s: in string);
|
245 |
|
|
-------------------------------------------------------------------------
|
246 |
|
|
-- Procedure print stim txt
|
247 |
|
|
procedure txt_print(variable ptr: in stm_text_ptr);
|
248 |
|
|
-------------------------------------------------------------------------
|
249 |
|
|
-- Procedure print stim txt sub variables found
|
250 |
|
|
procedure txt_print_wvar(variable var_list : in var_field_ptr;
|
251 |
|
|
variable ptr : in stm_text_ptr;
|
252 |
|
|
constant b : in base);
|
253 |
|
|
|
254 |
|
|
-------------------------------------------------------------------------
|
255 |
|
|
-- convert a std_logic_vector to an unsigned integer
|
256 |
|
|
function to_uninteger ( constant vect : in std_logic_vector
|
257 |
|
|
) return integer;
|
258 |
|
|
|
259 |
|
|
end tb_pkg;
|
260 |
|
|
-------------------------------------------------------------------------------
|
261 |
|
|
-- new version 1.4
|
262 |
|
|
-- Revision History:
|
263 |
|
|
-- $Log: not supported by cvs2svn $
|
264 |
|
|
-- Revision 1.3 2007/09/02 04:04:04 sckoarn
|
265 |
|
|
-- Update of version 1.2 tb_pkg
|
266 |
|
|
-- See documentation for details
|
267 |
|
|
--
|
268 |
|
|
-- Revision 1.2 2007/08/21 02:43:14 sckoarn
|
269 |
|
|
-- Fix package definition to match with body
|
270 |
|
|
--
|
271 |
|
|
-- Revision 1.1.1.1 2007/04/06 04:06:48 sckoarn
|
272 |
|
|
-- Import of the vhld_tb
|
273 |
|
|
-------------------------------------------------------------------------------
|