------------------------------------------------------------
-- Copyright: 2010 Integrated Sytems Laboratory, ETH Zurich
-- http://www.iis.ee.ethz.ch/~sha3
------------------------------------------------------------
use std.textio.all;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_textio.all;
use work.simulstuff.all;
--=============================================================================
package jhtbpkg is
-- declarations of all those signals that do connect to the MUT
-- most of them are collected in records to facilitate data handling
-- note: any bidirectional must be made part of both stimuli and responses
type stimuliRecordType is record
RSTxRB : std_logic;
VALIDINxS : std_logic;
MsgInxD : std_logic_vector(511 downto 0);
end record;
-- same for actual and expected response
type responseRecordType is record
HashOutxD : std_logic_vector(255 downto 0);
end record;
-- as there is one element in the response record, an array with one
-- element of type respmatchtype is needed
type respMatchArray is array (1 to 1) of respmatchtype;
signal CLKxC : std_logic := '1'; -- driving clock
signal StimuliRecxD : stimuliRecordType; -- record of stimuli
signal ActResponseRecxD : responseRecordType; -- record of actual responses
signal ExpResponseRecxD : responseRecordType; -- record of expected responses
-- timing of clock and simulation events
constant CLK_PERIOD : time := 71.11 ns; -- 1.31578 ns;
constant RESPONSE_ACQUISITION_TIME : time := 65 ns; -- 1.1 ns;
constant STIMULI_APPLICATION_TIME : time := 15 ns; -- 0.30 ns;
constant CLK_PHASE_HIGH : time := CLK_PERIOD/2;
constant CLK_PHASE_LOW : time := CLK_PERIOD/2;
-- declaration of stimuli, expected responses, and simulation report files
constant STIMULI_FILENAME : string := "../simvectors/jh_stimuli.asc";
constant EXPRESP_FILENAME : string := "../simvectors/jh_expresp.asc";
constant SIMREPT_FILENAME : string := "../simvectors/jh_simrept.asc";
-- the files are opened implicitly right here
file stimulifile : text open read_mode is STIMULI_FILENAME;
file simreptfile : text open write_mode is SIMREPT_FILENAME;
-------------------------------------------------------------------------------
-- function for reading stimuli data from the stimuli file
impure function GetStimuliRecord (file stimulifile : text)
return stimuliRecordType;
-- function for reading expected responses from the expected response file
impure function GetExpectedResponseRecord (file exprespfile : text)
return responseRecordType;
-- procedure for comparing actual and expected response
procedure CheckResponse
(actRespRecord : in responseRecordType;
expRespRecord : in responseRecordType;
respmatch : inout respMatchArray;
respaccount : inout respaccounttype);
-- procedure for writing stimuli and actual responses to the report file
procedure PutSimulationReportTrace
(file simreptfile : text;
stimulirecord : in stimuliRecordType;
actRespRecord : in responseRecordType;
respmatch : in respMatchArray;
respaccount : in respaccounttype;
simRepLineCount : inout natural);
-- compose a failure message line and write it to the report file
procedure PutSimulationReportFailure
(file simreptfile : text;
expRespRecord : in responseRecordType;
respmatch : in respMatchArray);
end package jhtbpkg;
--=============================================================================
package body jhtbpkg is
-- purpose: get one record worth of expected responses from file.get one record worth of stimuli from file.
impure function GetStimuliRecord
(file stimulifile : text)
return stimuliRecordType
is
variable in_line, in_line_tmp : line;
-- stimuli to default to unknown in case no value is obtained from file
variable stimulirecord : stimuliRecordType := (RSTxRB => 'X',
VALIDINxS => 'X',
MsgInxD => (others => 'X')
);
begin
-- read a line from the stimuli file
-- skipping any empty and comment lines encountered
loop
readline(stimulifile, in_line);
-- copy line read to enable meaningful error messages later
in_line_tmp := new string'(in_line(in_line'low to in_line'high));
if in_line_tmp'length >= 1 then
exit when in_line_tmp(1) /= '%';
end if;
deallocate(in_line_tmp);
end loop;
-- extract all values of a record of stimuli
GetFileEntry(stimulirecord.RSTxRB, in_line, in_line_tmp, STIMULI_FILENAME);
GetFileEntry(stimulirecord.VALIDINxS, in_line, in_line_tmp, STIMULI_FILENAME);
GetFileEntry(stimulirecord.MsgInxD, in_line, in_line_tmp, STIMULI_FILENAME);
-- deallocate line copy now that all entries have been read
deallocate(in_line_tmp);
return stimulirecord;
end GetStimuliRecord;
-------------------------------------------------------------------------------
-- purpose: get one record worth of expected responses from file.
impure function GetExpectedResponseRecord (file exprespfile : text)
return responseRecordType
is
variable in_line, in_line_tmp : line;
-- expected responses to default to don't care
-- in case no value is obtained from file
variable expresprecord : responseRecordType := (HashOutxD => (others => '-'));
begin
-- read a line from the expected response file as long as there are any
-- skipping any empty and comment lines encountered
if not(endfile(exprespfile)) then
loop
readline(exprespfile, in_line);
-- copy line read to enable meaningful error messages later
in_line_tmp := new string'(in_line(in_line'low to in_line'high));
if in_line_tmp'length >= 1 then
exit when in_line_tmp(1) /= '%';
end if;
deallocate(in_line_tmp);
end loop;
-- extract all values of a record of expected responses
GetFileEntry(expresprecord.HashOutxD, in_line, in_line_tmp, EXPRESP_FILENAME);
-- deallocate line copy now that all entries have been read
deallocate(in_line_tmp);
-- return default value in case EOF is overrun, no else clause needed
end if;
return expresprecord;
end GetExpectedResponseRecord;
-------------------------------------------------------------------------------
-- purpose: procedure for comparing actual and expected response
procedure CheckResponse
(actRespRecord : in responseRecordType;
expRespRecord : in responseRecordType;
respmatch : inout respMatchArray;
respaccount : inout respaccounttype)
is
begin
CheckValue(ActResponseRecxD.HashOutxD, ExpResponseRecxD.HashOutxD, respmatch(1), respaccount);
end CheckResponse;
-------------------------------------------------------------------------------
-- purpose: writing stimuli and actual responses to the report file.
procedure PutSimulationReportTrace
(file simreptfile : text;
stimuliRecord : in stimuliRecordType;
actRespRecord : in responseRecordType;
respmatch : in respMatchArray;
respaccount : in respaccounttype;
simRepLineCount : inout natural)
is
constant N : natural := 10000;
variable out_line : line;
begin
-- write every N lines the caption of the signals to the simulation report
if simRepLineCount mod N = 0 then
write(out_line, string'(" "));
writeline(simreptfile, out_line);
write(out_line, string'("Time RSTxRB"));
write(out_line, string'(" HashOutxDO"));
writeline(simreptfile, out_line);
write(out_line, string'("| | |"));
writeline(simreptfile, out_line);
write(out_line, string'("| | |"));
writeline(simreptfile, out_line);
write(out_line, string'("| | |"));
writeline(simreptfile, out_line);
end if;
simRepLineCount := simRepLineCount + 1;
-- begin with simulation time
write(out_line, string'("at "));
write(out_line, now);
-- add stimuli (skipped, because of block messages)
write(out_line, ht);
write(out_line, stimuliRecord.RSTxRB);
write(out_line, string'(" "));
-- add actual response 1
write(out_line, string'(" "));
hwrite(out_line, actRespRecord.HashOutxD);
case respmatch(1) is
when mok =>
write(out_line, string'(" ")); -- if the actual matches with
-- the expected response
when mne =>
")); -- if there was no expected response
-- for this actual response, write
-- a '-' behind the actual response
when mlf =>
write(out_line, string'(" l ")); -- if the actual doesn't match logically
-- with the expected response, write an
-- an 'l' behind the actual response
when msf =>
write(out_line, string'(" s ")); -- if the actual doesn't match in strength
-- with the expected response, write an
-- an 's' behind the actual response
when others => -- when mil
write(out_line, string'(" i ")); -- if the actual response is "don't care",
-- write an 'i' behind the actual response
end case;
-- write the output line to the report file
writeline(simreptfile, out_line);
end PutSimulationReportTrace;
-------------------------------------------------------------------------------
-- purpose: compose a failure message line and write it to the report file.
procedure PutSimulationReportFailure
(file simreptfile : text;
expRespRecord : in responseRecordType;
respmatch : in respMatchArray)
is
variable out_line : line;
begin
-- if at least one actual doesn't match with its expected response
if (respmatch(1) /= mok and respmatch(1) /= mne) then
write(out_line, string'("^^ Failure! Expected was :"));
-- if actual response 1 doesn't match with its expected response
if respmatch(1) /= mok and respmatch(1) /= mne then
-- add expected response
write(out_line, string'(" "));
hwrite(out_line, expRespRecord.HashOutxD);
else
write(out_line, string'(" "));
end if;
writeline(simreptfile, out_line);
end if;
end PutSimulationReportFailure;
end package body jhtbpkg;