-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_utility.vhd
70 lines (54 loc) · 2 KB
/
package_utility.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
--****************************************************************
--** MODEL : package_utility **
--** COMPANY : Cypress Semiconductor **
--** REVISION: 1.0 Created new package utility model **
--** **
--****************************************************************
Library ieee,work;
Use ieee.std_logic_1164.all;
Use IEEE.Std_Logic_Arith.all;
Use IEEE.std_logic_TextIO.all;
Library Std;
Use STD.TextIO.all;
Package package_utility is
FUNCTION convert_string( S: in STRING) RETURN STD_LOGIC_VECTOR;
FUNCTION conv_integer1(S : STD_LOGIC_VECTOR) RETURN INTEGER;
End; -- package package_utility
Package body package_utility is
------------------------------------------------------------------------------------------------
--Converts string into std_logic_vector
------------------------------------------------------------------------------------------------
FUNCTION convert_string(S: in STRING) RETURN STD_LOGIC_VECTOR IS
VARIABLE result : STD_LOGIC_VECTOR(S'RANGE);
BEGIN
FOR i IN S'RANGE LOOP
IF S(i) = '0' THEN
result(i) := '0';
ELSIF S(i) = '1' THEN
result(i) := '1';
ELSIF S(i) = 'X' THEN
result(i) := 'X';
ELSE
result(i) := 'Z';
END IF;
END LOOP;
RETURN result;
END convert_string;
------------------------------------------------------------------------------------------------
--Converts std_logic_vector into integer
------------------------------------------------------------------------------------------------
FUNCTION conv_integer1(S : STD_LOGIC_VECTOR) RETURN INTEGER IS
VARIABLE result : INTEGER := 0;
BEGIN
FOR i IN S'RANGE LOOP
IF S(i) = '1' THEN
result := result + (2**i);
ELSIF S(i) = '0' THEN
result := result;
ELSE
result := 0;
END IF;
END LOOP;
RETURN result;
END conv_integer1;
end package_utility;