VHDL Programming

(C. Jardin) #1

Subprograms and Packages 125


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);

FOR i IN s’RANGE LOOP
IF get_strength(result) < get_strength(s(i)) THEN
result := s(i);

ELSIF get_strength(result) = get_strength(s(i)) THEN
IF result /= s(i) THEN
result := x_tab(get_strength(result));
END IF;

END IF;
END LOOP;
RETURN result;

END resolve9;
END ninepack;

The package ninepackdeclares a number of types used in this example,
including some array types to make the resolution function easier to
Free download pdf