1 |
2 |
rpaley_yid |
-- $Author: rpaley_yid $
|
2 |
|
|
-- $Date: 2003-01-14 21:48:10 $
|
3 |
|
|
-- $Header: /home/marcus/revision_ctrl_test/oc_cvs/cvs/single_port/VHDL/pkg_image.vhd,v 1.1.1.1 2003-01-14 21:48:10 rpaley_yid Exp $
|
4 |
|
|
-- $Locker
|
5 |
|
|
-- $Revision: 1.1.1.1 $
|
6 |
|
|
-- $State: Exp $
|
7 |
|
|
|
8 |
|
|
-- Copyright (c) 1997 Ben Cohen. All rights reserved.
|
9 |
|
|
-- This model can be used in conjunction with the Kluwer Academic books
|
10 |
|
|
-- "VHDL Coding Styles and Methodologies", ISBN: 0-7923-9598-0
|
11 |
|
|
-- "VHDL Amswers to Frequently Asked Questions", Kluwer Academic
|
12 |
|
|
-- by Ben Cohen. email: vhdlcohen@aol.com
|
13 |
|
|
--
|
14 |
|
|
-- This source file for the Image Package
|
15 |
|
|
-- may be used and distributed without restriction provided
|
16 |
|
|
-- that this copyright statement is not removed from the file
|
17 |
|
|
-- and that any derivative work contains this copyright notice.
|
18 |
|
|
--
|
19 |
|
|
--
|
20 |
|
|
-- Original Author: Ben Cohen
|
21 |
|
|
-- Description:
|
22 |
|
|
-- Convert VHDL types to string for printing. This is especially useful when
|
23 |
|
|
-- compiling with VHDL-87
|
24 |
|
|
|
25 |
|
|
---------------------------------------------------------------
|
26 |
|
|
LIBRARY IEEE;
|
27 |
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
28 |
|
|
USE IEEE.STD_LOGIC_TEXTIO.ALL;
|
29 |
|
|
USE IEEE.NUMERIC_STD.ALL;
|
30 |
|
|
|
31 |
|
|
LIBRARY STD;
|
32 |
|
|
USE STD.TEXTIO.ALL;
|
33 |
|
|
|
34 |
|
|
package pkg_image is
|
35 |
|
|
function Image(In_Image : Time) return String;
|
36 |
|
|
function Image(In_Image : Bit) return String;
|
37 |
|
|
function Image(In_Image : Bit_Vector) return String;
|
38 |
|
|
function Image(In_Image : Integer) return String;
|
39 |
|
|
function Image(In_Image : Real) return String;
|
40 |
|
|
function Image(In_Image : Std_uLogic) return String;
|
41 |
|
|
function Image(In_Image : Std_uLogic_Vector) return String;
|
42 |
|
|
function Image(In_Image : Std_Logic_Vector) return String;
|
43 |
|
|
function Image(In_Image : Signed) return String;
|
44 |
|
|
function Image(In_Image : UnSigned) return String;
|
45 |
|
|
|
46 |
|
|
function HexImage(InStrg : String) return String;
|
47 |
|
|
function HexImage(In_Image : Bit_Vector) return String;
|
48 |
|
|
function HexImage(In_Image : Std_uLogic_Vector) return String;
|
49 |
|
|
function HexImage(In_Image : Std_Logic_Vector) return String;
|
50 |
|
|
function HexImage(In_Image : Signed) return String;
|
51 |
|
|
function HexImage(In_Image : UnSigned) return String;
|
52 |
|
|
|
53 |
|
|
function DecImage(In_Image : Bit_Vector) return String;
|
54 |
|
|
function DecImage(In_Image : Std_uLogic_Vector) return String;
|
55 |
|
|
function DecImage(In_Image : Std_Logic_Vector) return String;
|
56 |
|
|
function DecImage(In_Image : Signed) return String;
|
57 |
|
|
function DecImage(In_Image : UnSigned) return String;
|
58 |
|
|
end pkg_image;
|
59 |
|
|
|
60 |
|
|
package body pkg_image is
|
61 |
|
|
function Image(In_Image : Time) return String is
|
62 |
|
|
variable L : Line; -- access type
|
63 |
|
|
variable W : String(1 to 14) := (others => ' ');
|
64 |
|
|
-- Long enough to hold a time string
|
65 |
|
|
begin
|
66 |
|
|
-- the WRITE procedure creates an object with "NEW".
|
67 |
|
|
-- L is passed as an output of the procedure.
|
68 |
|
|
Std.TextIO.WRITE(L, in_image);
|
69 |
|
|
-- Copy L.all onto W
|
70 |
|
|
W(L.all'range) := L.all;
|
71 |
|
|
Deallocate(L);
|
72 |
|
|
return W;
|
73 |
|
|
end Image;
|
74 |
|
|
|
75 |
|
|
function Image(In_Image : Bit) return String is
|
76 |
|
|
variable L : Line; -- access type
|
77 |
|
|
variable W : String(1 to 3) := (others => ' ');
|
78 |
|
|
begin
|
79 |
|
|
Std.TextIO.WRITE(L, in_image);
|
80 |
|
|
W(L.all'range) := L.all;
|
81 |
|
|
Deallocate(L);
|
82 |
|
|
return W;
|
83 |
|
|
end Image;
|
84 |
|
|
|
85 |
|
|
function Image(In_Image : Bit_Vector) return String is
|
86 |
|
|
variable L : Line; -- access type
|
87 |
|
|
variable W : String(1 to In_Image'length) := (others => ' ');
|
88 |
|
|
begin
|
89 |
|
|
Std.TextIO.WRITE(L, in_image);
|
90 |
|
|
W(L.all'range) := L.all;
|
91 |
|
|
Deallocate(L);
|
92 |
|
|
return W;
|
93 |
|
|
end Image;
|
94 |
|
|
|
95 |
|
|
function Image(In_Image : Integer) return String is
|
96 |
|
|
variable L : Line; -- access type
|
97 |
|
|
variable W : String(1 to 32) := (others => ' ');
|
98 |
|
|
-- Long enough to hold a time string
|
99 |
|
|
begin
|
100 |
|
|
Std.TextIO.WRITE(L, in_image);
|
101 |
|
|
W(L.all'range) := L.all;
|
102 |
|
|
Deallocate(L);
|
103 |
|
|
return W;
|
104 |
|
|
end Image;
|
105 |
|
|
|
106 |
|
|
function Image(In_Image : Real) return String is
|
107 |
|
|
variable L : Line; -- access type
|
108 |
|
|
variable W : String(1 to 32) := (others => ' ');
|
109 |
|
|
-- Long enough to hold a time string
|
110 |
|
|
begin
|
111 |
|
|
Std.TextIO.WRITE(L, in_image);
|
112 |
|
|
W(L.all'range) := L.all;
|
113 |
|
|
Deallocate(L);
|
114 |
|
|
return W;
|
115 |
|
|
end Image;
|
116 |
|
|
|
117 |
|
|
function Image(In_Image : Std_uLogic) return String is
|
118 |
|
|
variable L : Line; -- access type
|
119 |
|
|
variable W : String(1 to 3) := (others => ' ');
|
120 |
|
|
begin
|
121 |
|
|
IEEE.Std_Logic_Textio.WRITE(L, in_image);
|
122 |
|
|
W(L.all'range) := L.all;
|
123 |
|
|
Deallocate(L);
|
124 |
|
|
return W;
|
125 |
|
|
end Image;
|
126 |
|
|
|
127 |
|
|
function Image(In_Image : Std_uLogic_Vector) return String is
|
128 |
|
|
variable L : Line; -- access type
|
129 |
|
|
variable W : String(1 to In_Image'length) := (others => ' ');
|
130 |
|
|
begin
|
131 |
|
|
IEEE.Std_Logic_Textio.WRITE(L, in_image);
|
132 |
|
|
W(L.all'range) := L.all;
|
133 |
|
|
Deallocate(L);
|
134 |
|
|
return W;
|
135 |
|
|
end Image;
|
136 |
|
|
|
137 |
|
|
function Image(In_Image : Std_Logic_Vector) return String is
|
138 |
|
|
variable L : Line; -- access type
|
139 |
|
|
variable W : String(1 to In_Image'length) := (others => ' ');
|
140 |
|
|
begin
|
141 |
|
|
IEEE.Std_Logic_TextIO.WRITE(L, In_Image);
|
142 |
|
|
W(L.all'range) := L.all;
|
143 |
|
|
Deallocate(L);
|
144 |
|
|
return W;
|
145 |
|
|
end Image;
|
146 |
|
|
|
147 |
|
|
function Image(In_Image : Signed) return String is
|
148 |
|
|
begin
|
149 |
|
|
return Image(Std_Logic_Vector(In_Image));
|
150 |
|
|
end Image;
|
151 |
|
|
|
152 |
|
|
function Image(In_Image : UnSigned) return String is
|
153 |
|
|
begin
|
154 |
|
|
return Image(Std_Logic_Vector(In_Image));
|
155 |
|
|
end Image;
|
156 |
|
|
|
157 |
|
|
function HexImage(InStrg : String) return String is
|
158 |
|
|
subtype Int03_Typ is Integer range 0 to 3;
|
159 |
|
|
variable Result : string(1 to ((InStrg'length - 1)/4)+1) :=
|
160 |
|
|
(others => '0');
|
161 |
|
|
variable StrTo4 : string(1 to Result'length * 4) :=
|
162 |
|
|
(others => '0');
|
163 |
|
|
variable MTspace : Int03_Typ; -- Empty space to fill in
|
164 |
|
|
variable Str4 : String(1 to 4);
|
165 |
|
|
variable Group_v : Natural := 0;
|
166 |
|
|
begin
|
167 |
|
|
MTspace := Result'length * 4 - InStrg'length;
|
168 |
|
|
StrTo4(MTspace + 1 to StrTo4'length) := InStrg; -- padded with '0'
|
169 |
|
|
Cnvrt_Lbl : for I in Result'range loop
|
170 |
|
|
Group_v := Group_v + 4; -- identifies end of bit # in a group of 4
|
171 |
|
|
Str4 := StrTo4(Group_v - 3 to Group_v); -- get next 4 characters
|
172 |
|
|
case Str4 is
|
173 |
|
|
when "0000" => Result(I) := '0';
|
174 |
|
|
when "0001" => Result(I) := '1';
|
175 |
|
|
when "0010" => Result(I) := '2';
|
176 |
|
|
when "0011" => Result(I) := '3';
|
177 |
|
|
when "0100" => Result(I) := '4';
|
178 |
|
|
when "0101" => Result(I) := '5';
|
179 |
|
|
when "0110" => Result(I) := '6';
|
180 |
|
|
when "0111" => Result(I) := '7';
|
181 |
|
|
when "1000" => Result(I) := '8';
|
182 |
|
|
when "1001" => Result(I) := '9';
|
183 |
|
|
when "1010" => Result(I) := 'A';
|
184 |
|
|
when "1011" => Result(I) := 'B';
|
185 |
|
|
when "1100" => Result(I) := 'C';
|
186 |
|
|
when "1101" => Result(I) := 'D';
|
187 |
|
|
when "1110" => Result(I) := 'E';
|
188 |
|
|
when "1111" => Result(I) := 'F';
|
189 |
|
|
when others => Result(I) := 'X';
|
190 |
|
|
end case; -- Str4
|
191 |
|
|
end loop Cnvrt_Lbl;
|
192 |
|
|
|
193 |
|
|
return Result;
|
194 |
|
|
end HexImage;
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
function HexImage(In_Image : Bit_Vector) return String is
|
198 |
|
|
begin
|
199 |
|
|
return HexImage(Image(In_Image));
|
200 |
|
|
end HexImage;
|
201 |
|
|
|
202 |
|
|
function HexImage(In_Image : Std_uLogic_Vector) return String is
|
203 |
|
|
begin
|
204 |
|
|
return HexImage(Image(In_Image));
|
205 |
|
|
end HexImage;
|
206 |
|
|
|
207 |
|
|
function HexImage(In_Image : Std_Logic_Vector) return String is
|
208 |
|
|
begin
|
209 |
|
|
return HexImage(Image(In_Image));
|
210 |
|
|
end HexImage;
|
211 |
|
|
|
212 |
|
|
function HexImage(In_Image : Signed) return String is
|
213 |
|
|
begin
|
214 |
|
|
return HexImage(Image(In_Image));
|
215 |
|
|
end HexImage;
|
216 |
|
|
|
217 |
|
|
function HexImage(In_Image : UnSigned) return String is
|
218 |
|
|
begin
|
219 |
|
|
return HexImage(Image(In_Image));
|
220 |
|
|
end HexImage;
|
221 |
|
|
|
222 |
|
|
function DecImage(In_Image : Bit_Vector) return String is
|
223 |
|
|
variable In_Image_v : Bit_Vector(In_Image'length downto 1) := In_Image;
|
224 |
|
|
begin
|
225 |
|
|
if In_Image'length > 31 then
|
226 |
|
|
assert False
|
227 |
|
|
report "Number too large for Integer, clipping to 31 bits"
|
228 |
|
|
severity Warning;
|
229 |
|
|
return Image(To_Integer
|
230 |
|
|
(Unsigned(To_StdLogicVector
|
231 |
|
|
(In_Image_v(31 downto 1)))));
|
232 |
|
|
else
|
233 |
|
|
return Image(To_Integer(Unsigned(To_StdLogicVector(In_Image))));
|
234 |
|
|
end if;
|
235 |
|
|
end DecImage;
|
236 |
|
|
|
237 |
|
|
function DecImage(In_Image : Std_uLogic_Vector) return String is
|
238 |
|
|
variable In_Image_v : Std_uLogic_Vector(In_Image'length downto 1)
|
239 |
|
|
:= In_Image;
|
240 |
|
|
begin
|
241 |
|
|
if In_Image'length > 31 then
|
242 |
|
|
assert False
|
243 |
|
|
report "Number too large for Integer, clipping to 31 bits"
|
244 |
|
|
severity Warning;
|
245 |
|
|
return Image(To_Integer(Unsigned(In_Image_v(31 downto 1))));
|
246 |
|
|
else
|
247 |
|
|
return Image(To_Integer(Unsigned(In_Image)));
|
248 |
|
|
end if;
|
249 |
|
|
end DecImage;
|
250 |
|
|
|
251 |
|
|
function DecImage(In_Image : Std_Logic_Vector) return String is
|
252 |
|
|
variable In_Image_v : Std_Logic_Vector(In_Image'length downto 1)
|
253 |
|
|
:= In_Image;
|
254 |
|
|
begin
|
255 |
|
|
if In_Image'length > 31 then
|
256 |
|
|
assert False
|
257 |
|
|
report "Number too large for Integer, clipping to 31 bits"
|
258 |
|
|
severity Warning;
|
259 |
|
|
return Image(To_Integer(Unsigned(In_Image_v(31 downto 1))));
|
260 |
|
|
else
|
261 |
|
|
return Image(To_Integer(Unsigned(In_Image)));
|
262 |
|
|
end if;
|
263 |
|
|
end DecImage;
|
264 |
|
|
|
265 |
|
|
function DecImage(In_Image : Signed) return String is
|
266 |
|
|
variable In_Image_v : Signed(In_Image'length downto 1) := In_Image;
|
267 |
|
|
begin
|
268 |
|
|
if In_Image'length > 31 then
|
269 |
|
|
assert False
|
270 |
|
|
report "Number too large for Integer, clipping to 31 bits"
|
271 |
|
|
severity Warning;
|
272 |
|
|
return Image(To_Integer(In_Image_v(31 downto 1)));
|
273 |
|
|
else
|
274 |
|
|
return Image(To_Integer(In_Image));
|
275 |
|
|
end if;
|
276 |
|
|
end DecImage;
|
277 |
|
|
|
278 |
|
|
function DecImage(In_Image : UnSigned) return String is
|
279 |
|
|
variable In_Image_v : UnSigned(In_Image'length downto 1) := In_Image;
|
280 |
|
|
begin
|
281 |
|
|
if In_Image'length > 31 then
|
282 |
|
|
assert False
|
283 |
|
|
report "Number too large for Integer, clipping to 31 bits"
|
284 |
|
|
severity Warning;
|
285 |
|
|
return Image(To_Integer(In_Image_v(31 downto 1)));
|
286 |
|
|
else
|
287 |
|
|
return Image(To_Integer(In_Image));
|
288 |
|
|
end if;
|
289 |
|
|
end DecImage;
|
290 |
|
|
|
291 |
|
|
end pkg_image;
|
292 |
|
|
|
293 |
|
|
-- $Log: not supported by cvs2svn $
|
294 |
|
|
-- Revision 1.1 2003/01/14 17:48:44 Default
|
295 |
|
|
-- Initial revision
|
296 |
|
|
--
|
297 |
|
|
-- Revision 1.1 2002/12/24 18:07:50 Default
|
298 |
|
|
-- Initial revision
|
299 |
|
|
--
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
|