WHEN Z => CASE s(i) IS WHEN H => result := H; WHEN L => result := L; WHEN X => result := X; WHEN OTHERS => NULL; END CASE; WHEN L => CASE s(i) IS WHEN H => result := X; WHEN X => result := X; WHEN OTHERS => NULL; END CASE; WHEN H => CASE s(i) IS WHEN L => result := X; WHEN X => result := X; WHEN OTHERS =>
Driver Values Initial Value Z H Z Z H Resultant Value Figure 5-2
Four State Resolution with Two Values.
NULL; END CASE; WHEN X => result := X; END CASE; END LOOP; RETURN result; END resolve; END fourpack;
The input argument is an unconstrained array of the driver-base type,fourval. The resolution function examines all of the values of the drivers passed in argument s one at a time and returns a single value of fourvaltype to be scheduled as the signal value.
Variable resultis initialized to a Zvalue to take care of the case of zero drivers for the signal. In this case, the loop is never executed, and the result value returned is the initialization value. It is also a good idea to initialize the result value to the weakest value of the value system to allow overwriting by stronger values.
If a nonzero number of drivers exists for the signal being resolved, then the loop is executed once for each driver value passed in argument s. Each driver value is compared with the current value stored in variable result. If the new value is stronger according to the rules outlined earlier, then the current result is updated with the new value.
Let’s look at some example driver values to see how this works. Assuming that argument scontained the driver values shown in Figure 5-2, what would the result be?
Driver Values Initial Value H Z L Z H H Resultant Value X Figure 5-3
Four State Resolution with Three Values.
Because there are two drivers, the loop is executed twice. The first time through, the loop variable result contains the initial value Z. The first driver value is also a Zvalue. Value Zcompared with value Zproduces a resulting value Z.
The next iteration through the loop retrieves the next driver value, which is H. The value H compared with value Z returns value H. The function therefore returns the value Has the resolved value of the signal. Another case is shown in Figure 5-3. In this example, there are three drivers, and the resolution function executes the loop three times. In the first iteration of the loop, the initial value of result (Z) is compared with the first driver value (H). The value His assigned to result. In the next iteration, result (H) is compared with the second driver (Z). The value H remains in resultbecause the value Zis weaker. Finally, the last itera- tion result (H) is compared with the last driver value (L). Because these values are of the same strength, the value X is assigned to result. The value Xis returned from the function as the resolved value for the signal.
NINE-VALUE RESOLUTION FUNCTION Some simulators use
more complex types to represent the value of a signal. For instance, what might a resolution function look like for a nine-value system, typical of most workstation-based simulators in use currently? Following are the nine values in the value system:
Z0, Z1, ZX, R0, R1, RX, F0, F1, FX
weakest---strongest
The system consists of three strengths and three logic values. The three strengths represent the following:
■ Z—High impedance strength, few hundred k of resistance ■ R—Resistive, few k of resistance
■ F—Forcing, few ohms of resistance
The three logic levels are represented as follows: ■ 0—Logical 0 or false
■ 1—Logical 1 or true
■ X—Logical unknown
The nine states are described as follows: ■ Z0—High-impedance 0 ■ Z1—High-impedance 1 ■ ZX—High-impedance unknown ■ R0—Resistive 0 ■ R1—Resistive 1 ■ RX—Resistive unknown ■ F0—Forcing 0 ■ F1—Forcing 1 ■ FX—Forcing unknown
A few simple rules can be used to define how the resolution function should work:
—Strongest strength always wins.
—If strengths are the same and values are different, return same strength but Xvalue.
Following are the type declarations needed for the value system: PACKAGE ninepack IS
TYPE strength IS (Z, R, F); TYPE nineval IS ( Z0, Z1, ZX, TYPE nineval IS ( R0, R1, RX, TYPE nineval IS ( F0, F1, FX );
TYPE ninevaltab IS ARRAY(nineval’LOW TO nineval’HIGH) OF nineval;
TYPE strengthtab IS ARRAY(strength’LOW TO strength’HIGH) OF nineval;
FUNCTION resolve9( s: ninevalvec) RETURN nineval;
END ninepack;
The package body contains the resolution function (package bodies are discussed near the end of this chapter).
PACKAGE BODY ninepack IS
FUNCTION resolve9( s: ninevalvec) RETURN nineval IS VARIABLE result: nineval;
CONSTANT get_strength : ninevaltab := (Z, --Z0 Z, --Z1 Z, --ZX R, --R0 R, --R1 R, --RX F, --F0 F, --F1 F); --FX
CONSTANT x_tab : strengthtab := (ZX, --Z
RX, --R FX); --F BEGIN
IF s’LENGTH = 0 THEN RETURN ZX; END IF; result := s(0);