------------------------------------------------------------
-- Copyright: 2011 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;
use work.sha_pack.all;
--=============================================================================
package SHA256MainTbPkg 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;
-- MxD : std_logic_vector(WWIDTH*16-1 downto 0);
-- SxD : std_logic_vector(WWIDTH*4-1 downto 0);
-- TxD : std_logic_vector(WWIDTH*2-1 downto 0);
-- end record;
type stimuliRecordType is record
RSTxRB : std_logic;
MessageInxD : expmess_arr;
HInxD : h_arr;
MessageReadyxS : std_logic;
end record;
-- same for actual and expected response
-- type responseRecordType is record
-- HxD : std_logic_vector(WWIDTH*8-1 downto 0);
-- end record;
type responseRecordType is record
HOutxD : h_arr;
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_PHASE_HIGH : time := 5 ns;
constant CLK_PHASE_LOW : time := 5 ns;
constant RESPONSE_ACQUISITION_TIME : time := 8 ns;
constant STIMULI_APPLICATION_TIME : time := 2 ns;
-- declaration of stimuli, expected responses, and simulation report files
constant STIMULI_FILENAME : string := "../simvectors/sha256main_stimuli.asc";
constant EXPRESP_FILENAME : string := "../simvectors/sha256main_expresp.asc";
constant SIMREPT_FILENAME : string := "../simvectors/sha256main_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 SHA256MainTbPkg;
--=============================================================================
package body SHA256MainTbPkg 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 => '0',
HInxD => (others => (others => 'X')),
MessageInxD => (others => (others => 'X')),
MessageReadyxS => '0'
);
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);
for i in 0 to 15 loop
GetFileEntry(stimulirecord.MessageInxD(i), in_line, in_line_tmp, STIMULI_FILENAME);
end loop;
for i in 7 downto 0 loop
GetFileEntry(stimulirecord.HInxD(i), in_line, in_line_tmp, STIMULI_FILENAME);
end loop;
GetFileEntry(stimulirecord.MessageReadyxS, in_line, in_line_tmp, STIMULI_FILENAME);
-- GetFileEntry(stimulirecord.MessageInxD, in_line, in_line_tmp, STIMULI_FILENAME);
-- GetFileEntry(stimulirecord.HxD, 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 := (HoutxD => (others => (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
for i in 0 to 7 loop
GetFileEntry(expresprecord.HOutxD(i), in_line, in_line_tmp, EXPRESP_FILENAME);
end loop;
-- GetFileEntry(expresprecord.HxD, 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
for i in 7 downto 0 loop
CheckValue(ActResponseRecxD.HoutxD(i), ExpResponseRecxD.HOutxD(i), respmatch(1), respaccount);
end loop;
-- CheckValue(ActResponseRecxD.HxD, ExpResponseRecxD.HxD, 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"));
writeline(simreptfile, out_line);
write(out_line, string'("| | MxDI HxDO"));
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
write(out_line, ht);
write(out_line, stimuliRecord.RSTxRB);
write(out_line, string'(" "));
-- add actual response 1
write(out_line, string'(" "));
for i in 7 downto 0 loop
hwrite(out_line, actRespRecord.HOutxD(i));
end loop;
-- hwrite(out_line, actRespRecord.HxD);
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'(" "));
for i in 7 downto 0 loop
hwrite(out_line, expRespRecord.HOutxD(i));
end loop;
-- hwrite(out_line, expRespRecord.HxD);
else
write(out_line, string'(" "));
end if;
writeline(simreptfile, out_line);
end if;
end PutSimulationReportFailure;
end package body SHA256MainTbPkg;