0
\$\begingroup\$

When running a simulation of a testbench involving a user-defined resolved data-type, I get an error report of the form:

"** Fatal: (vsim-3734) Index value 1 is out of range 0 to 1"

, followed by simulated time and location in testbench source code. The offending data type is a custom resolved type, used to represent the equivalent of STD_Logic for Real variables. The type is employed for simulating things like open-collector drivers, pull-up resistors, etc. driving a variable carrying a real value that represents voltage on a wire. I am pretty sure that the fatal error occurs within the type's resolution function, but cannot figure out the error mechanism. Has anyone come across something similar? The custom data type is as follows:

LIBRARY IEEE; USE IEEE.std_logic_1164.all;

USE IEEE.std_logic_ARITH.all;

USE IEEE.std_logic_UNSIGNED.all;

PACKAGE Tbench_pkg IS

--=====================================================================
--  Definitions for a resolved REAL data type, to be used strictly
--  for behavioral simulations of analog networks.
--=====================================================================
--
TYPE R_Strength_t IS    (RU, RS, RW, RZ, RX);
--
TYPE U_Real IS RECORD
    rval        : REAL;
    strength    : R_Strength_t;
END RECORD;
--
TYPE U_Real_Vector IS ARRAY(NATURAL RANGE <>) OF U_Real;
TYPE Strngth_Tbl_t IS ARRAY(R_Strength_t, R_Strength_t) OF R_Strength_t;
SUBTYPE ix_t IS NATURAL RANGE 0 TO 2;
TYPE VSel_Tbl_t IS ARRAY(R_Strength_t, R_Strength_t) OF ix_t;
-- Resolution Truth Table                RU  RS  RW  RZ  RX
CONSTANT RR_Table   : Strngth_Tbl_t := ((RU, RX, RX, RU, RX),   -- RU
                                        (RX, RX, RS, RS, RX),   -- RS
                                        (RX, RS, RX, RW, RX),   -- RW
                                        (RU, RS, RW, RZ, RX),   -- RZ
                                        (RX, RX, RX, RX, RX));  -- RX
-- Real Value Selection Table           RU RS RW RZ RX
CONSTANT VS_Table   : VSel_Tbl_t    := ((0, 0, 1, 1, 0),    -- RU
                                        (0, 0, 1, 1, 0),    -- RS
                                        (2, 2, 0, 1, 2),    -- RW
                                        (2, 2, 2, 0, 2),    -- RZ
                                        (0, 0, 1, 1, 0));   -- RX
FUNCTION rresolved(r : U_Real_Vector) RETURN U_Real;
--
SUBTYPE R_Real IS rresolved U_Real;
TYPE R_Real_Vector IS ARRAY (NATURAL RANGE <>) OF R_Real;
--

END Tbench_pkg;

PACKAGE BODY Tbench_pkg IS

FUNCTION rresolved(r : U_Real_Vector) RETURN U_Real IS
--
VARIABLE rtv    : U_Real    := (0.0, RZ);
VARIABLE raux   : REAL      := 0.0;
VARIABLE ix     : ix_t      := 0;
--
BEGIN
    IF (r'LENGTH = 1) THEN
        RETURN r(r'LOW);
    ELSE
        FOR i IN r'RANGE LOOP
            ix := VS_Table(rtv.strength, r(i).strength);
            CASE ix IS
                WHEN 0 =>
                    raux := (rtv.rval + r(i).rval)*0.5;
                WHEN 1 =>
                    raux := rtv.rval;
                WHEN 2 =>
                    raux := r(i).rval;
            END CASE;
            rtv.rval     := raux;
            rtv.strength := RR_Table(rtv.strength, r(i).strength);
        END LOOP;
        RETURN rtv;
    END IF;
END FUNCTION rresolved;

END Tbench_pkg;

\$\endgroup\$
2
  • \$\begingroup\$ Put together a minimal complete compilable example which reproduces the error. As it is, it's just a guessing game and I can't even guess which line produced the error. \$\endgroup\$ – user_1818839 Mar 24 '20 at 22:31
  • \$\begingroup\$ I will try to reproduce it with something smaller than the actual testbench that produces the error, because it is too large to include here (a few thousand lines of code across a dozen source files). It also contains non-disclosable information, so I am in a bit of a spot here. \$\endgroup\$ – Frank_GR Mar 24 '20 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.