OpenCores
URL https://opencores.org/ocsvn/pltbutils/pltbutils/trunk

Subversion Repositories pltbutils

[/] [pltbutils/] [branches/] [dev_beta0002/] [src/] [vhdl/] [pltbutils_func_pkg.vhd] - Diff between revs 95 and 96

Show entire file | Details | Blame | View Log

Rev 95 Rev 96
Line 15... Line 15...
----                                                              ----
----                                                              ----
---- To Do:                                                       ----
---- To Do:                                                       ----
---- -                                                            ----
---- -                                                            ----
----                                                              ----
----                                                              ----
---- Author(s):                                                   ----
---- Author(s):                                                   ----
---- - Per Larsson, pela@opencores.org                            ----
---- - Per Larsson, pela.opencores@gmail.com                      ----
----                                                              ----
----                                                              ----
----------------------------------------------------------------------
----------------------------------------------------------------------
----                                                              ----
----                                                              ----
---- Copyright (C) 2013-2014 Authors and OPENCORES.ORG            ----
---- Copyright (C) 2013-2014 Authors and OPENCORES.ORG            ----
----                                                              ----
----                                                              ----
Line 123... Line 123...
  -- endsim
  -- endsim
  procedure endsim(
  procedure endsim(
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
    signal   pltbs              : out   pltbs_t;
    signal   pltbs              : out   pltbs_t;
    constant show_success_fail  : in    boolean := false;
    constant show_success_fail  : in    boolean := false;
    constant force              : in    boolean := false
    constant force_stop         : in    boolean := false
  );
  );
 
 
  -- starttest
  -- starttest
  procedure starttest(
  procedure starttest(
    constant num                : in    integer := -1;
    constant num                : in    integer := -1;
Line 288... Line 288...
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
    signal   pltbs              : out   pltbs_t;
    signal   pltbs              : out   pltbs_t;
    constant falling            : in    boolean := false;
    constant falling            : in    boolean := false;
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
  );
  );
 
  procedure waitsig(
 
    signal   s                  : in    std_logic;
 
    constant value              : in    std_logic;
 
    variable pltbv              : inout pltbv_t;
 
    signal   pltbs              : out   pltbs_t;
 
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
 
  );
 
 
  -- check
  -- check
  procedure check(
  procedure check(
    constant rpt                : in    string;
    constant rpt                : in    string;
    constant actual             : in    integer;
    constant actual             : in    integer;
Line 562... Line 569...
  --
  --
  -- procedure endsim(
  -- procedure endsim(
  --   variable pltbv              : inout pltbv_t;
  --   variable pltbv              : inout pltbv_t;
  --   signal   pltbs              : out   pltbs_t;
  --   signal   pltbs              : out   pltbs_t;
  --   constant show_success_fail  : in  boolean := false;
  --   constant show_success_fail  : in  boolean := false;
  --   constant force              : in  boolean := false
  --   constant force_stop         : in  boolean := false
  -- )
  -- )
  --
  --
  -- Displays a message at end of simulation message, presents the simulation
  -- Displays a message at end of simulation message, presents the simulation
  -- results, and stops the simulation.
  -- results, and stops the simulation.
  -- Call endsim() it only once.
  -- Call endsim() it only once.
Line 577... Line 584...
  --
  --
  --   show_success_fail        If true, endsim() shows "*** SUCCESS ***",
  --   show_success_fail        If true, endsim() shows "*** SUCCESS ***",
  --                            "*** FAIL ***", or "*** NO CHECKS ***".
  --                            "*** FAIL ***", or "*** NO CHECKS ***".
  --                            Optional, default is false.
  --                            Optional, default is false.
  --
  --
  --   force                    If true, forces the simulation to stop using an
  --   force_stop               If true, forces the simulation to stop using an
  --                            assert failure statement. Use this option only
  --                            assert failure statement. Use this option only
  --                            if the normal way of stopping the simulation
  --                            if the normal way of stopping the simulation
  --                            doesn't work (see below).
  --                            doesn't work (see below).
  --                            Optional, default is false.
  --                            Optional, default is false.
  --
  --
  -- The testbench should be designed so that all clocks stop when endsim()
  -- The testbench should be designed so that all clocks stop when endsim()
  -- sets the signal pltbs.stop_sim to '1'. This should stop the simulator.
  -- sets the signal pltbs.stop_sim to '1'. This should stop the simulator.
  -- In some cases that doesn't work, then set the force argument to true, which
  -- In some cases that doesn't work, then set the force_stop argument to true,
  -- causes a false assert failure, which should stop the simulator.
  -- which causes a false assert failure, which should stop the simulator.
  -- Scripts searching transcript logs for errors and failures, should ignore
  -- Scripts searching transcript logs for errors and failures, should ignore
  -- the failure with "--- FORCE END OF SIMULATION ---" as part of the report.
  -- the failure with "--- FORCE END OF SIMULATION ---" as part of the report.
  --
  --
  -- NOTE:
  -- NOTE:
  -- The end-of-simulation messages and success/fail messages are not only
  -- The end-of-simulation messages and success/fail messages are not only
Line 610... Line 617...
  ----------------------------------------------------------------------------
  ----------------------------------------------------------------------------
  procedure endsim(
  procedure endsim(
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
    signal   pltbs              : out   pltbs_t;
    signal   pltbs              : out   pltbs_t;
    constant show_success_fail  : in    boolean := false;
    constant show_success_fail  : in    boolean := false;
    constant force              : in    boolean := false
    constant force_stop         : in    boolean := false
  ) is
  ) is
    variable timestamp : time;
    variable timestamp : time;
  begin
  begin
    timestamp := now;
    timestamp := now;
    if C_PLTBUTILS_USE_STD_ENDSIM_MSG then
    if C_PLTBUTILS_USE_STD_ENDSIM_MSG then
Line 629... Line 636...
    printv(pltbv.test_name, "END OF SIMULATION");
    printv(pltbv.test_name, "END OF SIMULATION");
    pltbv.test_name_len := 17;
    pltbv.test_name_len := 17;
    pltbv.stop_sim      := '1';
    pltbv.stop_sim      := '1';
    pltbs_update(pltbv, pltbs);
    pltbs_update(pltbv, pltbs);
    wait for C_WAIT_BEFORE_STOP_TIME;
    wait for C_WAIT_BEFORE_STOP_TIME;
    if force then
    if force_stop then
      if C_PLTBUTILS_USE_STD_STOPSIM then
      if C_PLTBUTILS_USE_STD_STOPSIM then
        stopsim(now);
        stopsim(now);
      end if;
      end if;
      if C_PLTBUTILS_USE_CUSTOM_STOPSIM then
      if C_PLTBUTILS_USE_CUSTOM_STOPSIM then
        custom_stopsim(now);
        custom_stopsim(now);
Line 936... Line 943...
  procedure print2(
  procedure print2(
    signal   s                  : out   string;
    signal   s                  : out   string;
    constant txt                : in    string
    constant txt                : in    string
  ) is
  ) is
  begin
  begin
    print(true, s, txt);
    print2(true, s, txt);
  end procedure print2;
  end procedure print2;
 
 
  procedure print2(
  procedure print2(
    constant active             : in    boolean;
    constant active             : in    boolean;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 956... Line 963...
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
    signal   pltbs              : out   pltbs_t;
    signal   pltbs              : out   pltbs_t;
    constant txt                : in    string
    constant txt                : in    string
  ) is
  ) is
  begin
  begin
    print(true, pltbv, pltbs, txt);
    print2(true, pltbv, pltbs, txt);
  end procedure print2;
  end procedure print2;
 
 
  ----------------------------------------------------------------------------
  ----------------------------------------------------------------------------
  -- waitclks
  -- waitclks
  --
  --
Line 1059... Line 1066...
  -- Examples:
  -- Examples:
  -- waitsig(wr_en, '1', sys_clk, pltbv, pltbs);
  -- waitsig(wr_en, '1', sys_clk, pltbv, pltbs);
  -- waitsig(rd_en,   1, sys_clk, pltbv, pltbs, true);
  -- waitsig(rd_en,   1, sys_clk, pltbv, pltbs, true);
  -- waitclks(full, '1', sys_clk, pltbv, pltbs, true, 1 ms);
  -- waitclks(full, '1', sys_clk, pltbv, pltbs, true, 1 ms);
  ----------------------------------------------------------------------------
  ----------------------------------------------------------------------------
 
  -- waitsig integer, clocked
  procedure waitsig(
  procedure waitsig(
    signal   s                  : in    integer;
    signal   s                  : in    integer;
    constant value              : in    integer;
    constant value              : in    integer;
    signal   clk                : in    std_logic;
    signal   clk                : in    std_logic;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 1080... Line 1088...
    if now >= v_timeout_time then
    if now >= v_timeout_time then
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
    end if;
    end if;
  end procedure waitsig;
  end procedure waitsig;
 
 
 
  -- waitsig std_logic, clocked
  procedure waitsig(
  procedure waitsig(
    signal   s                  : in    std_logic;
    signal   s                  : in    std_logic;
    constant value              : in    std_logic;
    constant value              : in    std_logic;
    signal   clk                : in    std_logic;
    signal   clk                : in    std_logic;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 1101... Line 1110...
    if now >= v_timeout_time then
    if now >= v_timeout_time then
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
    end if;
    end if;
  end procedure waitsig;
  end procedure waitsig;
 
 
 
  -- waitsig std_logic against integer, clocked
  procedure waitsig(
  procedure waitsig(
    signal   s                  : in    std_logic;
    signal   s                  : in    std_logic;
    constant value              : in    integer;
    constant value              : in    integer;
    signal   clk                : in    std_logic;
    signal   clk                : in    std_logic;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 1125... Line 1135...
    else
    else
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
    end if;
    end if;
  end procedure waitsig;
  end procedure waitsig;
 
 
 
  -- waitsig std_logic_vector, clocked
  procedure waitsig(
  procedure waitsig(
    signal   s                  : in    std_logic_vector;
    signal   s                  : in    std_logic_vector;
    constant value              : in    std_logic_vector;
    constant value              : in    std_logic_vector;
    signal   clk                : in    std_logic;
    signal   clk                : in    std_logic;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 1146... Line 1157...
    if now >= v_timeout_time then
    if now >= v_timeout_time then
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
    end if;
    end if;
  end procedure waitsig;
  end procedure waitsig;
 
 
 
  -- waitsig std_logic_vector against integer, clocked
  procedure waitsig(
  procedure waitsig(
    signal   s                  : in    std_logic_vector;
    signal   s                  : in    std_logic_vector;
    constant value              : in    integer;
    constant value              : in    integer;
    signal   clk                : in    std_logic;
    signal   clk                : in    std_logic;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 1161... Line 1173...
  begin
  begin
    waitsig(s, std_logic_vector(to_unsigned(value, s'length)), clk,
    waitsig(s, std_logic_vector(to_unsigned(value, s'length)), clk,
            pltbv, pltbs, falling, timeout);
            pltbv, pltbs, falling, timeout);
  end procedure waitsig;
  end procedure waitsig;
 
 
 
  -- waitsig unsigned, clocked
  procedure waitsig(
  procedure waitsig(
    signal   s                  : in    unsigned;
    signal   s                  : in    unsigned;
    constant value              : in    unsigned;
    constant value              : in    unsigned;
    signal   clk                : in    std_logic;
    signal   clk                : in    std_logic;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 1182... Line 1195...
    if now >= v_timeout_time then
    if now >= v_timeout_time then
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
    end if;
    end if;
  end procedure waitsig;
  end procedure waitsig;
 
 
 
  -- waitsig unsigned against integer, clocked
  procedure waitsig(
  procedure waitsig(
    signal   s                  : in    unsigned;
    signal   s                  : in    unsigned;
    constant value              : in    integer;
    constant value              : in    integer;
    signal   clk                : in    std_logic;
    signal   clk                : in    std_logic;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 1197... Line 1211...
  begin
  begin
    waitsig(s, to_unsigned(value, s'length), clk,
    waitsig(s, to_unsigned(value, s'length), clk,
            pltbv, pltbs, falling, timeout);
            pltbv, pltbs, falling, timeout);
  end procedure waitsig;
  end procedure waitsig;
 
 
 
  -- waitsig signed, clocked
  procedure waitsig(
  procedure waitsig(
    signal   s                  : in    signed;
    signal   s                  : in    signed;
    constant value              : in    signed;
    constant value              : in    signed;
    signal   clk                : in    std_logic;
    signal   clk                : in    std_logic;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 1218... Line 1233...
    if now >= v_timeout_time then
    if now >= v_timeout_time then
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
      pltbutils_error("waitsig() timeout", pltbv, pltbs);
    end if;
    end if;
  end procedure waitsig;
  end procedure waitsig;
 
 
 
  -- waitsig signed against integer, clocked
  procedure waitsig(
  procedure waitsig(
    signal   s                  : in    signed;
    signal   s                  : in    signed;
    constant value              : in    integer;
    constant value              : in    integer;
    signal   clk                : in    std_logic;
    signal   clk                : in    std_logic;
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
Line 1233... Line 1249...
  begin
  begin
    waitsig(s, to_signed(value, s'length), clk,
    waitsig(s, to_signed(value, s'length), clk,
            pltbv, pltbs, falling, timeout);
            pltbv, pltbs, falling, timeout);
  end procedure waitsig;
  end procedure waitsig;
 
 
 
  -- waitsig std_logic, unclocked
 
  procedure waitsig(
 
    signal   s                  : in    std_logic;
 
    constant value              : in    std_logic;
 
    variable pltbv              : inout pltbv_t;
 
    signal   pltbs              : out   pltbs_t;
 
    constant timeout            : in    time    := C_PLTBUTILS_TIMEOUT
 
  ) is
 
  begin
 
    if s /= value then
 
      wait until s = value for timeout;
 
      if s /= value then
 
        pltbutils_error("waitsig() timeout", pltbv, pltbs);
 
      end if;
 
    end if;
 
  end procedure waitsig;
 
 
  ----------------------------------------------------------------------------
  ----------------------------------------------------------------------------
  -- check
  -- check
  --
  --
  -- procedure check(
  -- procedure check(
  --   constant rpt             : in    string;
  --   constant rpt             : in    string;
Line 1518... Line 1551...
  --
  --
  -- function to_ascending(
  -- function to_ascending(
  --  constant s                  : signed
  --  constant s                  : signed
  -- ) return signed;
  -- ) return signed;
  --
  --
  -- Converts a signal or variable to ascending range ("to-range").
  -- Converts a vector to ascending range ("to-range").
  -- The argument s can have ascending or descending range.
  -- The argument s can have ascending or descending range.
 
  -- E.g. an argument defined as a std_logic_vector(3 downto 1) 
 
  -- will be returned as a std_logic_vector(1 to 3).
 
  --
 
  -- Arguments: 
 
  --   s             Constant, signal or variable to convert
 
  --
 
  -- Return value:   Converted value
 
  --
 
  -- Examples:
 
  -- ascending_sig <= to_ascending(descending_sig);
 
  -- ascending_var := to_ascending(descending_var);
  ----------------------------------------------------------------------------
  ----------------------------------------------------------------------------
  function to_ascending(
  function to_ascending(
    constant s                  : std_logic_vector
    constant s                  : std_logic_vector
  ) return std_logic_vector is
  ) return std_logic_vector is
    variable r : std_logic_vector(s'low to s'high);
    variable r : std_logic_vector(s'low to s'high);
Line 1569... Line 1613...
  --
  --
  -- function to_descending(
  -- function to_descending(
  --  constant s                  : signed
  --  constant s                  : signed
  -- ) return signed;
  -- ) return signed;
  --
  --
  -- Converts a signal or variable to descending range ("downto-range").
  -- Converts a vector to descending range ("downto-range").
  -- The argument s can have ascending or descending range.
  -- The argument s can have ascending or descending range.
 
  -- E.g. an argument defined as a std_logic_vector(1 to 3) 
 
  -- will be returned as a std_logic_vector(3 downto 1).
 
  --
 
  -- Arguments: 
 
  --   s             Constant, signal or variable to convert
 
  --
 
  -- Return value:   Converted value
 
  --
 
  -- Examples:
 
  -- descending_sig <= to_descending(ascending_sig);
 
  -- descending_var := to_descending(ascending_var);
  ----------------------------------------------------------------------------
  ----------------------------------------------------------------------------
  function to_descending(
  function to_descending(
    constant s                  : std_logic_vector
    constant s                  : std_logic_vector
  ) return std_logic_vector is
  ) return std_logic_vector is
    variable r : std_logic_vector(s'high downto s'low);
    variable r : std_logic_vector(s'high downto s'low);
Line 1625... Line 1680...
  --  constant s                  : signed;
  --  constant s                  : signed;
  --  constant prefix             : string := "";
  --  constant prefix             : string := "";
  --  constant postfix            : string := ""
  --  constant postfix            : string := ""
  -- ) return string;
  -- ) return string;
  --
  --
  -- Converts a signal to a string in hexadecimal format.
  -- Converts a vector to a string in hexadecimal format.
  -- An optional prefix can be specified, e.g. "0x".
  -- An optional prefix can be specified, e.g. "0x", as well as a suffix.
  --
  --
  -- The signal can have ascending range ( "to-range" ) or descending range
  -- The input argument can have ascending range ( "to-range" ) or descending range
  -- ("downto-range").
  -- ("downto-range"). There is no vector length limitation.
  --
  --
  -- hxstr is a wrapper function for hstr in txt_util.
  -- Arguments: 
  -- hstr only support std_logic_vector with descending range.
  --   s             Constant, signal or variable to convert
 
  --
 
  -- Return value:   Converted value
  --
  --
  -- Examples:
  -- Examples:
  -- print("value=" & hxstr(s));
  -- print("value=" & hxstr(s));
  -- print("value=" & hxstr(s, "0x"));
  -- print("value=" & hxstr(s, "0x"));
 
  -- print("value=" & hxstr(s, "16#", "#"));
  ----------------------------------------------------------------------------
  ----------------------------------------------------------------------------
  function hxstr(
  function hxstr(
    constant s                  : std_logic_vector;
    constant s                  : std_logic_vector;
    constant prefix             : string := "";
    constant prefix             : string := "";
    constant postfix            : string := ""
    constant postfix            : string := ""
  ) return string is
  ) return string is
  begin
    variable hexstr             : string(1 to (s'length+3)/4);
    return prefix & hstr(to_descending(s)) & postfix;
    variable nibble_aligned_s   : std_logic_vector(((s'length+3)/4)*4-1 downto 0) := (others => '0');
 
    variable nibble             : std_logic_vector(3 downto 0);
 
  begin
 
    nibble_aligned_s(s'length-1 downto 0) := to_descending(s);
 
    for i in 0 to nibble_aligned_s'high/4 loop
 
      nibble := nibble_aligned_s(4*i + 3 downto 4*i);
 
      case nibble is
 
        when "0000" => hexstr(hexstr'high-i) := '0';
 
        when "0001" => hexstr(hexstr'high-i) := '1';
 
        when "0010" => hexstr(hexstr'high-i) := '2';
 
        when "0011" => hexstr(hexstr'high-i) := '3';
 
        when "0100" => hexstr(hexstr'high-i) := '4';
 
        when "0101" => hexstr(hexstr'high-i) := '5';
 
        when "0110" => hexstr(hexstr'high-i) := '6';
 
        when "0111" => hexstr(hexstr'high-i) := '7';
 
        when "1000" => hexstr(hexstr'high-i) := '8';
 
        when "1001" => hexstr(hexstr'high-i) := '9';
 
        when "1010" => hexstr(hexstr'high-i) := 'A';
 
        when "1011" => hexstr(hexstr'high-i) := 'B';
 
        when "1100" => hexstr(hexstr'high-i) := 'C';
 
        when "1101" => hexstr(hexstr'high-i) := 'D';
 
        when "1110" => hexstr(hexstr'high-i) := 'E';
 
        when "1111" => hexstr(hexstr'high-i) := 'F';
 
        when "UUUU" => hexstr(hexstr'high-i) := 'U';
 
        when "XXXX" => hexstr(hexstr'high-i) := 'X';
 
        when "ZZZZ" => hexstr(hexstr'high-i) := 'Z';
 
        when "WWWW" => hexstr(hexstr'high-i) := 'W';
 
        when "LLLL" => hexstr(hexstr'high-i) := 'L';
 
        when "HHHH" => hexstr(hexstr'high-i) := 'H';
 
        when "----" => hexstr(hexstr'high-i) := '-';
 
        when others => hexstr(hexstr'high-i) := '?';
 
        -- TODO: handle vectors where nibble_aligned_s'length > a'length and the highest nibble are all equal characters such as "XXX"
 
      end case;
 
    end loop;
 
    return prefix & hexstr & postfix;
  end function hxstr;
  end function hxstr;
 
 
  function hxstr(
  function hxstr(
    constant s                  : unsigned;
    constant s                  : unsigned;
    constant prefix             : string := "";
    constant prefix             : string := "";
    constant postfix            : string := ""
    constant postfix            : string := ""
  ) return string is
  ) return string is
  begin
  begin
    return prefix & hstr(to_descending(std_logic_vector(s))) & postfix;
    return hxstr(std_logic_vector(s), prefix, postfix);
  end function hxstr;
  end function hxstr;
 
 
  function hxstr(
  function hxstr(
    constant s                  : signed;
    constant s                  : signed;
    constant prefix             : string := "";
    constant prefix             : string := "";
    constant postfix            : string := ""
    constant postfix            : string := ""
  ) return string is
  ) return string is
  begin
  begin
    return prefix & hstr(to_descending(std_logic_vector(s))) & postfix;
    return hxstr(std_logic_vector(s), prefix, postfix);
  end function hxstr;
  end function hxstr;
 
 
  ----------------------------------------------------------------------------
  ----------------------------------------------------------------------------
  -- pltbutils internal procedure(s), called from other pltbutils procedures.
  -- pltbutils internal procedures, called from other pltbutils procedures.
  -- Do not to call this/these from user's code.
  -- Do not to call these from user's code.
  -- This/these procedures are undocumented in the specification on purpose.
  -- These procedures are undocumented in the specification on purpose.
  ----------------------------------------------------------------------------
  ----------------------------------------------------------------------------
  procedure pltbs_update(
  procedure pltbs_update(
    variable pltbv              : inout pltbv_t;
    variable pltbv              : inout pltbv_t;
    signal   pltbs              : out   pltbs_t
    signal   pltbs              : out   pltbs_t
  ) is
  ) is

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.