-- Copyright © 1993 by McGraw-Hill, Inc. and Zainalabedin Navabi
-- FIGURE 5.15
-- BASIC UTILITIES PACKAGE DECLERATION :
PACKAGE basic_utilities IS
TYPE integers IS ARRAY (0 TO 12) OF INTEGER;
FUNCTION fgl (w, x, gl : BIT) RETURN BIT;
FUNCTION feq (w, x, eq : BIT) RETURN BIT;
PROCEDURE bin2int (bin : IN BIT_VECTOR; int : OUT INTEGER);
PROCEDURE int2bin (int : IN INTEGER; bin : OUT BIT_VECTOR);
PROCEDURE apply_data (
SIGNAL target : OUT BIT_VECTOR (3 DOWNTO 0);
CONSTANT values : IN integers; CONSTANT period : IN TIME);
END basic_utilities;
--
-- BASIC UTILITIES PACKAGE BODY :
PACKAGE BODY basic_utilities IS
FUNCTION fgl (w, x, gl : BIT) RETURN BIT IS
BEGIN
RETURN (w AND gl) OR (NOT x AND gl) OR (w AND NOT x);
END fgl;
FUNCTION feq (w, x, eq : BIT) RETURN BIT IS
BEGIN
RETURN (w AND x AND eq) OR (NOT w AND NOT x AND eq);
END feq;
PROCEDURE bin2int (bin : IN BIT_VECTOR; int : OUT INTEGER) IS
VARIABLE result: INTEGER;
BEGIN
result := 0;
FOR i IN 0 TO (bin'LENGTH - 1) LOOP
IF bin(i) = '1' THEN
result := result + 2**i;
END IF;
END LOOP;
int := result;
END bin2int;
PROCEDURE int2bin (int : IN INTEGER; bin : OUT BIT_VECTOR) IS
VARIABLE tmp : INTEGER;
VARIABLE buf : BIT_VECTOR (bin'RANGE);
BEGIN
tmp := int;
FOR i IN 0 TO (bin'LENGTH - 1) LOOP
IF (tmp MOD 2 = 1) THEN
bin (i) := '1';
ELSE bin (i) := '0';
END IF;
tmp := tmp / 2;
END LOOP;
END int2bin;
PROCEDURE apply_data (
SIGNAL target : OUT BIT_VECTOR (3 DOWNTO 0);
CONSTANT values : IN integers; CONSTANT period : IN TIME)
IS
VARIABLE buf : BIT_VECTOR (3 DOWNTO 0);
BEGIN
FOR i IN 0 TO 12 LOOP
int2bin (values(i), buf);
target <= TRANSPORT buf AFTER i * period;
END LOOP;
END apply_data;
END basic_utilities;
--