------------------------------------------------------------ -- 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; use work.blakePkg.all; --============================================================================= package blakeTbPkg 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); TxD : std_logic_vector(WWIDTH*2-1 downto 0); end record; -- same for actual and expected response type responseRecordType is record HxD : std_logic_vector(WWIDTH*8-1 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 := 31.6 ns; -- 15.9 ns; -- 2.5 ns; constant RESPONSE_ACQUISITION_TIME : time := 28 ns; -- 15.0 ns; -- 2.150 ns; constant STIMULI_APPLICATION_TIME : time := 4 ns; -- 3.0 ns; -- 0.450 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/blake32_stimuli.asc"; constant EXPRESP_FILENAME : string := "../simvectors/blake32_expresp.asc"; constant SIMREPT_FILENAME : string := "../simvectors/blake32_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 blakeTbPkg; --============================================================================= package body blakeTbPkg 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', MxD => (others => 'X'), TxD => (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.MxD, in_line, in_line_tmp, STIMULI_FILENAME); GetFileEntry(stimulirecord.TxD, 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 := (HxD => (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.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 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'(" ")); hwrite(out_line, stimuliRecord.MxD(7 downto 0)); -- add actual response 1 write(out_line, string'(" ")); 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'(" ")); hwrite(out_line, expRespRecord.HxD); else write(out_line, string'(" ")); end if; writeline(simreptfile, out_line); end if; end PutSimulationReportFailure; end package body blakeTbPkg;