-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- Copyright 2011 Ken Campbell
|
-- Copyright 2014 Ken Campbell
|
|
-- All rights reserved.
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- $Author: sckoarn $
|
-- $Author: sckoarn $
|
--
|
--
|
-- $Date: $
|
-- $Date: $
|
--
|
--
|
-- $Id: $
|
-- $Id: $
|
--
|
--
|
-- $Source: $
|
-- $Source: $
|
--
|
--
|
-- Description : The the testbench package header file.
|
-- Description : The the testbench package header file.
|
-- GNU release 2 Beta.
|
|
--
|
--
|
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
--This file is part of The VHDL Test Bench.
|
-- This file is part of The VHDL Test Bench Package.
|
--
|
--
|
-- The VHDL Test Bench is free software; you can redistribute it and/or modify
|
-- Redistribution and use in source and binary forms, with or without
|
-- it under the terms of the GNU General Public License as published by
|
-- modification, are permitted provided that the following conditions are met:
|
-- the Free Software Foundation; either version 2 of the License, or
|
--
|
-- (at your option) any later version.
|
-- 1. Redistributions of source code must retain the above copyright notice,
|
--
|
-- this list of conditions and the following disclaimer.
|
-- The VHDL Test Bench is distributed in the hope that it will be useful,
|
--
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
-- 2. Redistributions in binary form must reproduce the above copyright notice,
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
-- this list of conditions and the following disclaimer in the documentation
|
-- GNU General Public License for more details.
|
-- and/or other materials provided with the distribution.
|
--
|
--
|
-- You should have received a copy of the GNU General Public License
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
-- along with The VHDL Test Bench; if not, write to the Free Software
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
library IEEE;
|
library IEEE;
|
|
|
use IEEE.STD_LOGIC_1164.all;
|
use IEEE.STD_LOGIC_1164.all;
|
use IEEE.STD_LOGIC_ARITH.all;
|
use IEEE.STD_LOGIC_ARITH.all;
|
use std.textio.all;
|
use std.textio.all;
|
--library ieee_proposed;
|
--library ieee_proposed;
|
--use ieee_proposed.STD_LOGIC_1164_additions.all;
|
--use ieee_proposed.STD_LOGIC_1164_additions.all;
|
|
|
package tb_pkg is
|
package tb_pkg is
|
|
|
-- Constants
|
-- Constants
|
constant max_str_len : integer := 256;
|
constant max_str_len : integer := 256;
|
constant max_field_len : integer := 48;
|
constant max_field_len : integer := 48;
|
constant c_stm_text_len : integer := 200;
|
constant c_stm_text_len : integer := 200;
|
-- file handles
|
-- file handles
|
file stimulus : text; -- file main file
|
file stimulus : text; -- file main file
|
file include_file : text; -- file declaration for includes
|
file include_file : text; -- file declaration for includes
|
|
|
-- Type Def's
|
-- Type Def's
|
type base is (bin, oct, hex, dec);
|
type base is (bin, oct, hex, dec);
|
-- subtype stack_element is integer range 0 to 8192;
|
-- subtype stack_element is integer range 0 to 8192;
|
type stack_register is array(7 downto 0) of integer;
|
type stack_register is array(7 downto 0) of integer;
|
type state_register is array(7 downto 0) of boolean;
|
type state_register is array(7 downto 0) of boolean;
|
type int_array is array(1 to 16) of integer;
|
type int_array is array(1 to 16) of integer;
|
|
|
subtype text_line is string(1 to max_str_len);
|
subtype text_line is string(1 to max_str_len);
|
subtype text_field is string(1 to max_field_len);
|
subtype text_field is string(1 to max_field_len);
|
subtype stm_text is string(1 to c_stm_text_len);
|
subtype stm_text is string(1 to c_stm_text_len);
|
type stm_text_ptr is access stm_text;
|
type stm_text_ptr is access stm_text;
|
-- define the stimulus line record and access
|
-- define the stimulus line record and access
|
type stim_line;
|
type stim_line;
|
type stim_line_ptr is access stim_line; -- Pointer to stim_line record
|
type stim_line_ptr is access stim_line; -- Pointer to stim_line record
|
type stim_line is record
|
type stim_line is record
|
instruction: text_field;
|
instruction: text_field;
|
inst_field_1: text_field;
|
inst_field_1: text_field;
|
inst_field_2: text_field;
|
inst_field_2: text_field;
|
inst_field_3: text_field;
|
inst_field_3: text_field;
|
inst_field_4: text_field;
|
inst_field_4: text_field;
|
inst_field_5: text_field;
|
inst_field_5: text_field;
|
inst_field_6: text_field;
|
inst_field_6: text_field;
|
txt: stm_text_ptr;
|
txt: stm_text_ptr;
|
line_number: integer; -- sequence line
|
line_number: integer; -- sequence line
|
num_of_lines: integer; -- total number of lines
|
num_of_lines: integer; -- total number of lines
|
file_line: integer; -- file line number
|
file_line: integer; -- file line number
|
file_idx: integer;
|
file_idx: integer;
|
next_rec: stim_line_ptr;
|
next_rec: stim_line_ptr;
|
end record;
|
end record;
|
-- define the variables field and pointer
|
-- define the variables field and pointer
|
type var_field;
|
type var_field;
|
type var_field_ptr is access var_field; -- pointer to var_field
|
type var_field_ptr is access var_field; -- pointer to var_field
|
type var_field is record
|
type var_field is record
|
var_name: text_field;
|
var_name: text_field;
|
var_index: integer;
|
var_index: integer;
|
var_value: integer;
|
var_value: integer;
|
next_rec: var_field_ptr;
|
next_rec: var_field_ptr;
|
end record;
|
end record;
|
-- define the instruction structure
|
-- define the instruction structure
|
type inst_def;
|
type inst_def;
|
type inst_def_ptr is access inst_def;
|
type inst_def_ptr is access inst_def;
|
type inst_def is record
|
type inst_def is record
|
instruction: text_field;
|
instruction: text_field;
|
instruction_l: integer;
|
instruction_l: integer;
|
params: integer;
|
params: integer;
|
next_rec: inst_def_ptr;
|
next_rec: inst_def_ptr;
|
end record;
|
end record;
|
-- define the file handle record
|
-- define the file handle record
|
type file_def;
|
type file_def;
|
type file_def_ptr is access file_def;
|
type file_def_ptr is access file_def;
|
type file_def is record
|
type file_def is record
|
rec_idx: integer;
|
rec_idx: integer;
|
file_name: text_line;
|
file_name: text_line;
|
next_rec: file_def_ptr;
|
next_rec: file_def_ptr;
|
end record;
|
end record;
|
|
|
-- define the stimulus slave control record types
|
-- define the stimulus slave control record types
|
type stm_sctl is record
|
type stm_sctl is record
|
rst_n : std_logic;
|
rst_n : std_logic;
|
addr : std_logic_vector(31 downto 0);
|
addr : std_logic_vector(31 downto 0);
|
wdat : std_logic_vector(31 downto 0);
|
wdat : std_logic_vector(31 downto 0);
|
rwn : std_logic;
|
rwn : std_logic;
|
req_n : std_logic;
|
req_n : std_logic;
|
end record;
|
end record;
|
type stm_sack is record
|
type stm_sack is record
|
rdat : std_logic_vector(31 downto 0);
|
rdat : std_logic_vector(31 downto 0);
|
ack_n : std_logic;
|
ack_n : std_logic;
|
rdy_n : std_logic;
|
rdy_n : std_logic;
|
irq_n : std_logic;
|
irq_n : std_logic;
|
end record;
|
end record;
|
-- define the stimulus master control record types
|
-- define the stimulus master control record types
|
type stm_mctl is record
|
type stm_mctl is record
|
addr : std_logic_vector(31 downto 0);
|
addr : std_logic_vector(31 downto 0);
|
wdat : std_logic_vector(31 downto 0);
|
wdat : std_logic_vector(31 downto 0);
|
rwn : std_logic;
|
rwn : std_logic;
|
req_n : std_logic;
|
req_n : std_logic;
|
breq : std_logic;
|
breq : std_logic;
|
end record;
|
end record;
|
type stm_mack is record
|
type stm_mack is record
|
rdat : std_logic_vector(31 downto 0);
|
rdat : std_logic_vector(31 downto 0);
|
slv_rdy : std_logic_vector(15 downto 0);
|
slv_rdy : std_logic_vector(15 downto 0);
|
slv_irq : std_logic_vector(15 downto 0);
|
slv_irq : std_logic_vector(15 downto 0);
|
ack_n : std_logic;
|
ack_n : std_logic;
|
bgrant : std_logic;
|
bgrant : std_logic;
|
end record;
|
end record;
|
|
|
-----
|
-----
|
-- stm interface neutral functions
|
-- stm interface neutral functions
|
function stm_neut return stm_sctl;
|
function stm_neut return stm_sctl;
|
function stm_neut return stm_sack;
|
function stm_neut return stm_sack;
|
--function stm_neut() return stm_mctl;
|
--function stm_neut() return stm_mctl;
|
--function stm_neut() return stm_mack;
|
--function stm_neut() return stm_mack;
|
|
|
---*****************************************************************************
|
---*****************************************************************************
|
-- Function Declaration
|
-- Function Declaration
|
-- function str_len(variable line: text_line) return text_field;
|
-- function str_len(variable line: text_line) return text_field;
|
-- function fld_len(s : in text_field) integer;
|
-- function fld_len(s : in text_field) integer;
|
|
|
function c2std_vec(c: in character) return std_logic_vector;
|
function c2std_vec(c: in character) return std_logic_vector;
|
|
|
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
-- Procedure declarations
|
-- Procedure declarations
|
--------------------------------------------------------------------------
|
--------------------------------------------------------------------------
|
-- define_instruction
|
-- define_instruction
|
-- inputs file_name the file to be read from
|
-- inputs file_name the file to be read from
|
--
|
--
|
-- output file_line a line of text from the file
|
-- output file_line a line of text from the file
|
procedure define_instruction(variable inst_set: inout inst_def_ptr;
|
procedure define_instruction(variable inst_set: inout inst_def_ptr;
|
constant inst: in string;
|
constant inst: in string;
|
constant args: in integer);
|
constant args: in integer);
|
|
|
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
-- index_variable
|
-- index_variable
|
-- inputs:
|
-- inputs:
|
-- index: the index of the variable being accessed
|
-- index: the index of the variable being accessed
|
-- outputs:
|
-- outputs:
|
-- Variable Value
|
-- Variable Value
|
-- valid is 1 if valid 0 if not
|
-- valid is 1 if valid 0 if not
|
procedure index_variable(variable var_list : in var_field_ptr;
|
procedure index_variable(variable var_list : in var_field_ptr;
|
variable index : in integer;
|
variable index : in integer;
|
variable value : out integer;
|
variable value : out integer;
|
variable valid : out integer);
|
variable valid : out integer);
|
|
|
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
-- update_variable
|
-- update_variable
|
-- inputs:
|
-- inputs:
|
-- index: the index of the variable being accessed
|
-- index: the index of the variable being accessed
|
-- outputs:
|
-- outputs:
|
-- Variable Value
|
-- Variable Value
|
-- valid is 1 if valid 0 if not
|
-- valid is 1 if valid 0 if not
|
procedure update_variable(variable var_list : in var_field_ptr;
|
procedure update_variable(variable var_list : in var_field_ptr;
|
variable index : in integer;
|
variable index : in integer;
|
variable value : in integer;
|
variable value : in integer;
|
variable valid : out integer);
|
variable valid : out integer);
|
|
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- read_instruction_file
|
-- read_instruction_file
|
-- This procedure reads the instruction file, name passed throught file_name.
|
-- This procedure reads the instruction file, name passed throught file_name.
|
-- Pointers to records are passed in and out. A table of variables is created
|
-- Pointers to records are passed in and out. A table of variables is created
|
-- with variable name and value (converted to integer). The instructions are
|
-- with variable name and value (converted to integer). The instructions are
|
-- parsesed into the inst_sequ list. Instructions are validated against the
|
-- parsesed into the inst_sequ list. Instructions are validated against the
|
-- inst_set which must have been set up prior to loading the instruction file.
|
-- inst_set which must have been set up prior to loading the instruction file.
|
procedure read_instruction_file(constant file_name: string;
|
procedure read_instruction_file(constant file_name: string;
|
variable inst_set: inout inst_def_ptr;
|
variable inst_set: inout inst_def_ptr;
|
variable var_list: inout var_field_ptr;
|
variable var_list: inout var_field_ptr;
|
variable inst_sequ: inout stim_line_ptr;
|
variable inst_sequ: inout stim_line_ptr;
|
variable file_list: inout file_def_ptr);
|
variable file_list: inout file_def_ptr);
|
|
|
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
-- access_inst_sequ
|
-- access_inst_sequ
|
-- This procedure retreeves an instruction from the sequence of instructions.
|
-- This procedure retreeves an instruction from the sequence of instructions.
|
-- Based on the line number you pass to it, it returns the instruction with
|
-- Based on the line number you pass to it, it returns the instruction with
|
-- any variables substituted as integers.
|
-- any variables substituted as integers.
|
procedure access_inst_sequ(variable inst_sequ : in stim_line_ptr;
|
procedure access_inst_sequ(variable inst_sequ : in stim_line_ptr;
|
variable var_list : in var_field_ptr;
|
variable var_list : in var_field_ptr;
|
variable file_list : in file_def_ptr;
|
variable file_list : in file_def_ptr;
|
variable sequ_num : in integer;
|
variable sequ_num : in integer;
|
variable inst : out text_field;
|
variable inst : out text_field;
|
variable p1 : out integer;
|
variable p1 : out integer;
|
variable p2 : out integer;
|
variable p2 : out integer;
|
variable p3 : out integer;
|
variable p3 : out integer;
|
variable p4 : out integer;
|
variable p4 : out integer;
|
variable p5 : out integer;
|
variable p5 : out integer;
|
variable p6 : out integer;
|
variable p6 : out integer;
|
variable txt : out stm_text_ptr;
|
variable txt : out stm_text_ptr;
|
variable inst_len : out integer;
|
variable inst_len : out integer;
|
variable fname : out text_line;
|
variable fname : out text_line;
|
variable file_line : out integer;
|
variable file_line : out integer;
|
variable last_num : inout integer;
|
variable last_num : inout integer;
|
variable last_ptr : inout stim_line_ptr
|
variable last_ptr : inout stim_line_ptr
|
);
|
);
|
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
-- tokenize_line
|
-- tokenize_line
|
-- This procedure takes a type text_line in and returns up to 6
|
-- This procedure takes a type text_line in and returns up to 6
|
-- tokens and the count in integer valid, as well if text string
|
-- tokens and the count in integer valid, as well if text string
|
-- is found the pointer to that is returned.
|
-- is found the pointer to that is returned.
|
procedure tokenize_line(variable text_line: in text_line;
|
procedure tokenize_line(variable text_line: in text_line;
|
variable token1: out text_field;
|
variable token1: out text_field;
|
variable token2: out text_field;
|
variable token2: out text_field;
|
variable token3: out text_field;
|
variable token3: out text_field;
|
variable token4: out text_field;
|
variable token4: out text_field;
|
variable token5: out text_field;
|
variable token5: out text_field;
|
variable token6: out text_field;
|
variable token6: out text_field;
|
variable token7: out text_field;
|
variable token7: out text_field;
|
variable txt_ptr: out stm_text_ptr;
|
variable txt_ptr: out stm_text_ptr;
|
variable valid: out integer);
|
variable valid: out integer);
|
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
-- string convertion
|
-- string convertion
|
function ew_to_str(int: integer; b: base) return text_field;
|
function ew_to_str(int: integer; b: base) return text_field;
|
function to_str(int: integer) return string;
|
function to_str(int: integer) return string;
|
|
|
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
-- Procedre print
|
-- Procedre print
|
-- print to stdout string
|
-- print to stdout string
|
procedure print(s: in string);
|
procedure print(s: in string);
|
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
-- Procedure print stim txt
|
-- Procedure print stim txt
|
procedure txt_print(variable ptr: in stm_text_ptr);
|
procedure txt_print(variable ptr: in stm_text_ptr);
|
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
-- Procedure print stim txt sub variables found
|
-- Procedure print stim txt sub variables found
|
procedure txt_print_wvar(variable var_list : in var_field_ptr;
|
procedure txt_print_wvar(variable var_list : in var_field_ptr;
|
variable ptr : in stm_text_ptr;
|
variable ptr : in stm_text_ptr;
|
constant b : in base);
|
constant b : in base);
|
|
|
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
-- convert a std_logic_vector to an unsigned integer
|
-- convert a std_logic_vector to an unsigned integer
|
function to_uninteger ( constant vect : in std_logic_vector
|
function to_uninteger ( constant vect : in std_logic_vector
|
) return integer;
|
) return integer;
|
|
|
end tb_pkg;
|
end tb_pkg;
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- new version 1.4
|
-- new version 1.4
|
-- Revision History:
|
-- Revision History:
|
-- $Log: not supported by cvs2svn $
|
-- $Log: not supported by cvs2svn $
|
-- Revision 1.3 2007/09/02 04:04:04 sckoarn
|
-- Revision 1.3 2007/09/02 04:04:04 sckoarn
|
-- Update of version 1.2 tb_pkg
|
-- Update of version 1.2 tb_pkg
|
-- See documentation for details
|
-- See documentation for details
|
--
|
--
|
-- Revision 1.2 2007/08/21 02:43:14 sckoarn
|
-- Revision 1.2 2007/08/21 02:43:14 sckoarn
|
-- Fix package definition to match with body
|
-- Fix package definition to match with body
|
--
|
--
|
-- Revision 1.1.1.1 2007/04/06 04:06:48 sckoarn
|
-- Revision 1.1.1.1 2007/04/06 04:06:48 sckoarn
|
-- Import of the vhld_tb
|
-- Import of the vhld_tb
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
|
|