------------------------------------------------------------
-- 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 skeintbpkg 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
    RstxRBI           : std_logic;
    BlockAvailablexSI : std_logic;
    FinBlockxSI       : std_logic;
    BlockxDI          : std_logic_vector(255 downto 0);
  end record;

  -- same for actual and expected response
  type responseRecordType is record
    HashxDO          : 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 := 8.421 ns; -- 3.787 ns;
  constant RESPONSE_ACQUISITION_TIME : time := 8.000 ns; -- 3.5 ns;
  constant STIMULI_APPLICATION_TIME  : time := 0.400 ns; -- 0.7 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/skein256_stimuli.asc";
  constant EXPRESP_FILENAME : string := "../simvectors/skein256_expresp.asc";
  constant SIMREPT_FILENAME : string := "../simvectors/skein256_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 skeintbpkg;
--=============================================================================

package body skeintbpkg 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 := (RstxRBI           => 'X',
                                                   BlockAvailablexSI => 'X',
                                                   FinBlockxSI       => 'X',
                                                   BlockxDI          => (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.RstxRBI, in_line, in_line_tmp, STIMULI_FILENAME);
    GetFileEntry(stimulirecord.BlockAvailablexSI, in_line, in_line_tmp, STIMULI_FILENAME);
    GetFileEntry(stimulirecord.FinBlockxSI, in_line, in_line_tmp, STIMULI_FILENAME);
    GetFileEntry(stimulirecord.BlockxDI, 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 := (HashxDO => (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.HashxDO, 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.HashxDO, ExpResponseRecxD.HashxDO, 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'("|               |   BlockxDI"));
      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.ResetxRBI);
    write(out_line, string'("   "));
   -- hwrite(out_line, stimuliRecord.BlockxDI);
    -- add actual response 1
   -- write(out_line, string'("        "));
    hwrite(out_line, actRespRecord.HashxDO);

    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.HashxDO);
        
      else
        write(out_line, string'("                  "));
      end if;

      writeline(simreptfile, out_line);
    end if;
  end PutSimulationReportFailure;

end package body skeintbpkg;

Generated on Fri Sep 24 10:39:12 CEST 2010
Home