1 |
4 |
jclaytons |
-- A package containing various conversion functions useful in testbenches,
|
2 |
|
|
-- especially when used with text file IO in reading and displaying
|
3 |
|
|
-- hexadecimal values.
|
4 |
|
|
--
|
5 |
|
|
-- Author : Bill Grigsby
|
6 |
|
|
-- Modifications by : John Clayton
|
7 |
|
|
--
|
8 |
|
|
|
9 |
|
|
library ieee;
|
10 |
|
|
use ieee.std_logic_1164.all;
|
11 |
|
|
use ieee.numeric_std.all;
|
12 |
|
|
use std.textio.all;
|
13 |
|
|
|
14 |
|
|
package convert_pack is
|
15 |
|
|
|
16 |
|
|
------------------------------------------------------------------------------------
|
17 |
|
|
-- function calls
|
18 |
|
|
------------------------------------------------------------------------------------
|
19 |
|
|
function string_to_integer (in_string : string) return integer ;
|
20 |
|
|
function vector_to_string (in_vector : std_logic_vector) return string ;
|
21 |
|
|
function char_to_bit (in_char : character) return std_logic ;
|
22 |
|
|
function char_to_hex (in_char : character) return std_logic_vector ;
|
23 |
|
|
|
24 |
|
|
function slv2string(in_vector : std_logic_vector; nibbles : natural) return string ; -- Name changed by John Clayton
|
25 |
|
|
function u2string(in_vector : unsigned; nibbles : natural) return string ; -- Added by John Clayton
|
26 |
|
|
function u2asciichar(in_vector : unsigned(7 downto 0)) return character ; -- Added by John Clayton
|
27 |
|
|
function asciichar2u(in_char : character) return unsigned; -- Added by John Clayton
|
28 |
|
|
|
29 |
|
|
function hex_to_ascii(in_vector : std_logic_vector; nibbles : natural) return string ;
|
30 |
|
|
function u2ascii(in_vector : unsigned; nibbles : natural) return string ; -- Added by John Clayton
|
31 |
|
|
function hex_data_wrd(in_vector : std_logic_vector) return string ;
|
32 |
|
|
function hex_data_dblwrd(in_vector : std_logic_vector) return string ;
|
33 |
|
|
function hex_data_dblwrdz(in_vector : std_logic_vector) return string ;
|
34 |
|
|
|
35 |
|
|
function is_hex(c : character) return boolean; -- Added by John Clayton
|
36 |
|
|
function is_std_logic(c : character) return boolean; -- Added by John Clayton
|
37 |
|
|
function is_space(c : character) return boolean; -- Added by John Clayton
|
38 |
|
|
function char2sl(in_char : character) return std_logic; -- Added by John Clayton
|
39 |
|
|
function char2slv(in_char : character) return std_logic_vector;
|
40 |
|
|
function char2u(in_char : character) return unsigned;
|
41 |
|
|
function slv2u(in_a : std_logic_vector) return unsigned; -- Added by John Clayton
|
42 |
|
|
function u2slv(in_a : unsigned) return std_logic_vector; -- Added by John Clayton
|
43 |
|
|
function slv2s(in_a : std_logic_vector) return signed; -- Added by John Clayton
|
44 |
|
|
function s2slv(in_a : signed) return std_logic_vector; -- Added by John Clayton
|
45 |
|
|
function str2u(in_string : string; out_size:integer) return unsigned; -- Added by John Clayton
|
46 |
|
|
function str2s(in_string : string; out_size:integer) return signed; -- Added by John Clayton
|
47 |
|
|
function "**"(in_a : natural; in_b : natural) return natural; -- Added by John Clayton
|
48 |
|
|
function pow_2_u(in_a : natural; out_size:integer) return unsigned; -- Added by John Clayton
|
49 |
|
|
function asr_function(in_vect : signed; in_a : natural) return signed; -- Added by John Clayton
|
50 |
|
|
|
51 |
|
|
function slv_resize(in_vect : std_logic_vector; out_size : integer) return std_logic_vector; -- Added by John Clayton
|
52 |
|
|
function slv_resize_l(in_vect : std_logic_vector; out_size : integer) return std_logic_vector; -- Added by John Clayton
|
53 |
|
|
function slv_resize_se(in_vect : std_logic_vector; out_size : integer) return std_logic_vector; -- Added by John Clayton
|
54 |
|
|
function s_resize(in_vect : signed; out_size : integer) return signed; -- Added by John Clayton
|
55 |
|
|
function s_resize_l(in_vect : signed; out_size : integer) return signed; -- Added by John Clayton
|
56 |
|
|
function s_resize_se(in_vect : signed; out_size : integer) return signed; -- Added by John Clayton
|
57 |
|
|
function u_resize(in_vect : unsigned; out_size : integer) return unsigned; -- Added by John Clayton
|
58 |
|
|
function u_resize_l(in_vect : unsigned; out_size : integer) return unsigned; -- Added by John Clayton
|
59 |
|
|
function u_reverse(in_vect : unsigned) return unsigned; -- Added by John Clayton
|
60 |
|
|
|
61 |
|
|
function u_recursive_parity ( x : unsigned ) return std_logic;
|
62 |
|
|
|
63 |
|
|
------------------------------------------------------------------------------------
|
64 |
|
|
-- procedures
|
65 |
|
|
------------------------------------------------------------------------------------
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
end convert_pack;
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
package body convert_pack is
|
72 |
|
|
|
73 |
|
|
------------------------------------------------------------------------------------
|
74 |
|
|
--
|
75 |
|
|
------------------------------------------------------------------------------------
|
76 |
|
|
--* Title : TEST_PARITY
|
77 |
|
|
--* Filename & Ext : test_parity.vhdl
|
78 |
|
|
--* Author : David Bishop X-66788
|
79 |
|
|
--* Created : 3/18/97
|
80 |
|
|
--* Version : 1.2
|
81 |
|
|
--* Revision Date : 97/04/15
|
82 |
|
|
--* SCCSid : 1.2 04/15/97 test_parity.vhdl
|
83 |
|
|
--* WORK Library : testchip
|
84 |
|
|
--* Mod History :
|
85 |
|
|
--* Description : This is a parity generator which is written recursively
|
86 |
|
|
--* : It is designed to test the ability of Simulation and
|
87 |
|
|
--* : Synthesis tools to check this capability.
|
88 |
|
|
--* Known Bugs :
|
89 |
|
|
--* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
function u_recursive_parity ( x : unsigned ) return std_logic is
|
93 |
|
|
variable Upper, Lower : std_logic;
|
94 |
|
|
variable Half : integer;
|
95 |
|
|
variable BUS_int : unsigned( x'length-1 downto 0 );
|
96 |
|
|
variable Result : std_logic;
|
97 |
|
|
begin
|
98 |
|
|
BUS_int := x;
|
99 |
|
|
if ( BUS_int'length = 1 ) then
|
100 |
|
|
Result := BUS_int ( BUS_int'left );
|
101 |
|
|
elsif ( BUS_int'length = 2 ) then
|
102 |
|
|
Result := BUS_int ( BUS_int'right ) xor BUS_int ( BUS_int'left );
|
103 |
|
|
else
|
104 |
|
|
Half := ( BUS_int'length + 1 ) / 2 + BUS_int'right;
|
105 |
|
|
Upper := u_recursive_parity ( BUS_int ( BUS_int'left downto Half ));
|
106 |
|
|
Lower := u_recursive_parity ( BUS_int ( Half - 1 downto BUS_int'right ));
|
107 |
|
|
Result := Upper xor Lower;
|
108 |
|
|
end if;
|
109 |
|
|
return Result;
|
110 |
|
|
end;
|
111 |
|
|
|
112 |
|
|
------------------------------------------------------------------------------------
|
113 |
|
|
--
|
114 |
|
|
------------------------------------------------------------------------------------
|
115 |
|
|
|
116 |
|
|
function vector_to_string (in_vector : std_logic_vector) return string is
|
117 |
|
|
|
118 |
|
|
variable out_string : string(32 downto 1);
|
119 |
|
|
|
120 |
|
|
begin
|
121 |
|
|
|
122 |
|
|
for i in in_vector'range loop
|
123 |
|
|
if in_vector(i) = '1' then
|
124 |
|
|
out_string(i+1) := '1';
|
125 |
|
|
elsif in_vector(i) = '0' then
|
126 |
|
|
out_string(i+1) := '0';
|
127 |
|
|
else
|
128 |
|
|
assert false
|
129 |
|
|
report " illegal bit vector to bit string"
|
130 |
|
|
severity note;
|
131 |
|
|
end if;
|
132 |
|
|
end loop;
|
133 |
|
|
return out_string;
|
134 |
|
|
|
135 |
|
|
end vector_to_string;
|
136 |
|
|
|
137 |
|
|
------------------------------------------------------------------------------------
|
138 |
|
|
--
|
139 |
|
|
------------------------------------------------------------------------------------
|
140 |
|
|
|
141 |
|
|
function string_to_integer (in_string : string) return integer is
|
142 |
|
|
|
143 |
|
|
variable int : integer := 0;
|
144 |
|
|
begin
|
145 |
|
|
|
146 |
|
|
for j in in_string'range loop
|
147 |
|
|
case in_string(j) is
|
148 |
|
|
when '0' => int := int;
|
149 |
|
|
when '1' => int := int + (1 * 10**(j-1));
|
150 |
|
|
when '2' => int := int + (2 * 10**(j-1));
|
151 |
|
|
when '3' => int := int + (3 * 10**(j-1));
|
152 |
|
|
when '4' => int := int + (4 * 10**(j-1));
|
153 |
|
|
when '5' => int := int + (5 * 10**(j-1));
|
154 |
|
|
when '6' => int := int + (6 * 10**(j-1));
|
155 |
|
|
when '7' => int := int + (7 * 10**(j-1));
|
156 |
|
|
when '8' => int := int + (8 * 10**(j-1));
|
157 |
|
|
when '9' => int := int + (9 * 10**(j-1));
|
158 |
|
|
when others =>
|
159 |
|
|
assert false
|
160 |
|
|
report " illegal character to integer"
|
161 |
|
|
severity note;
|
162 |
|
|
end case;
|
163 |
|
|
end loop;
|
164 |
|
|
return int;
|
165 |
|
|
end string_to_integer;
|
166 |
|
|
|
167 |
|
|
------------------------------------------------------------------------------------
|
168 |
|
|
--
|
169 |
|
|
------------------------------------------------------------------------------------
|
170 |
|
|
|
171 |
|
|
function char_to_bit (in_char : character) return std_logic is
|
172 |
|
|
|
173 |
|
|
variable out_bit : std_logic;
|
174 |
|
|
|
175 |
|
|
begin
|
176 |
|
|
|
177 |
|
|
if (in_char = '1') then
|
178 |
|
|
out_bit := '1';
|
179 |
|
|
elsif (in_char = '0') then
|
180 |
|
|
out_bit := '0';
|
181 |
|
|
else
|
182 |
|
|
assert false
|
183 |
|
|
report "illegal character to bit"
|
184 |
|
|
severity note;
|
185 |
|
|
end if;
|
186 |
|
|
|
187 |
|
|
return out_bit;
|
188 |
|
|
end char_to_bit;
|
189 |
|
|
|
190 |
|
|
------------------------------------------------------------------------------------
|
191 |
|
|
--
|
192 |
|
|
------------------------------------------------------------------------------------
|
193 |
|
|
function char_to_hex (in_char : character) return std_logic_vector is
|
194 |
|
|
|
195 |
|
|
variable out_vec : std_logic_vector(3 downto 0);
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
begin
|
199 |
|
|
case in_char is
|
200 |
|
|
when '0' => out_vec := "0000";
|
201 |
|
|
when '1' => out_vec := "0001";
|
202 |
|
|
when '2' => out_vec := "0010";
|
203 |
|
|
when '3' => out_vec := "0011";
|
204 |
|
|
when '4' => out_vec := "0100";
|
205 |
|
|
when '5' => out_vec := "0101";
|
206 |
|
|
when '6' => out_vec := "0110";
|
207 |
|
|
when '7' => out_vec := "0111";
|
208 |
|
|
when '8' => out_vec := "1000";
|
209 |
|
|
when '9' => out_vec := "1001";
|
210 |
|
|
when 'A' | 'a' => out_vec := "1010";
|
211 |
|
|
when 'B' | 'b' => out_vec := "1011";
|
212 |
|
|
when 'C' | 'c' => out_vec := "1100";
|
213 |
|
|
when 'D' | 'd' => out_vec := "1101";
|
214 |
|
|
when 'E' | 'e' => out_vec := "1110";
|
215 |
|
|
when 'F' | 'f' => out_vec := "1111";
|
216 |
|
|
when others =>
|
217 |
|
|
assert false
|
218 |
|
|
report " illegal character to hex"
|
219 |
|
|
severity note;
|
220 |
|
|
end case;
|
221 |
|
|
return out_vec;
|
222 |
|
|
end char_to_hex;
|
223 |
|
|
|
224 |
|
|
------------------------------------------------------------------------------------
|
225 |
|
|
--
|
226 |
|
|
------------------------------------------------------------------------------------
|
227 |
|
|
|
228 |
|
|
function slv2string(in_vector : std_logic_vector; nibbles : natural) return string is
|
229 |
|
|
variable out_string : string(1 to nibbles);
|
230 |
|
|
variable temp_in_vector : std_logic_vector(4*nibbles-1 downto 0);
|
231 |
|
|
variable vector : std_logic_vector(3 downto 0);
|
232 |
|
|
|
233 |
|
|
begin
|
234 |
|
|
temp_in_vector := in_vector(in_vector'length-1 downto in_vector'length-temp_in_vector'length);
|
235 |
|
|
for i in 1 to nibbles loop
|
236 |
|
|
vector := temp_in_vector((4*(nibbles-i)+3) downto 4*(nibbles-i));
|
237 |
|
|
case vector is
|
238 |
|
|
when "0000" => out_string(i) := '0';
|
239 |
|
|
when "0001" => out_string(i) := '1';
|
240 |
|
|
when "0010" => out_string(i) := '2';
|
241 |
|
|
when "0011" => out_string(i) := '3';
|
242 |
|
|
when "0100" => out_string(i) := '4';
|
243 |
|
|
when "0101" => out_string(i) := '5';
|
244 |
|
|
when "0110" => out_string(i) := '6';
|
245 |
|
|
when "0111" => out_string(i) := '7';
|
246 |
|
|
when "1000" => out_string(i) := '8';
|
247 |
|
|
when "1001" => out_string(i) := '9';
|
248 |
|
|
when "1010" => out_string(i) := 'A';
|
249 |
|
|
when "1011" => out_string(i) := 'B';
|
250 |
|
|
when "1100" => out_string(i) := 'C';
|
251 |
|
|
when "1101" => out_string(i) := 'D';
|
252 |
|
|
when "1110" => out_string(i) := 'E';
|
253 |
|
|
when "1111" => out_string(i) := 'F';
|
254 |
|
|
when others =>
|
255 |
|
|
out_string(i) := 'J';
|
256 |
|
|
assert false
|
257 |
|
|
report " illegal std_logic_vector to string"
|
258 |
|
|
severity note;
|
259 |
|
|
end case;
|
260 |
|
|
end loop;
|
261 |
|
|
return out_string;
|
262 |
|
|
end;
|
263 |
|
|
|
264 |
|
|
------------------------------------------------------------------------------------
|
265 |
|
|
--
|
266 |
|
|
------------------------------------------------------------------------------------
|
267 |
|
|
|
268 |
|
|
function u2string(in_vector : unsigned; nibbles : natural) return string is
|
269 |
|
|
variable out_string : string(1 to nibbles);
|
270 |
|
|
variable temp_in_vector : unsigned(4*nibbles-1 downto 0);
|
271 |
|
|
variable vector : unsigned(3 downto 0);
|
272 |
|
|
|
273 |
|
|
begin
|
274 |
|
|
temp_in_vector := in_vector(in_vector'length-1 downto in_vector'length-temp_in_vector'length);
|
275 |
|
|
for i in 1 to nibbles loop
|
276 |
|
|
vector := temp_in_vector((4*(nibbles-i)+3) downto 4*(nibbles-i));
|
277 |
|
|
case vector is
|
278 |
|
|
when "0000" => out_string(i) := '0';
|
279 |
|
|
when "0001" => out_string(i) := '1';
|
280 |
|
|
when "0010" => out_string(i) := '2';
|
281 |
|
|
when "0011" => out_string(i) := '3';
|
282 |
|
|
when "0100" => out_string(i) := '4';
|
283 |
|
|
when "0101" => out_string(i) := '5';
|
284 |
|
|
when "0110" => out_string(i) := '6';
|
285 |
|
|
when "0111" => out_string(i) := '7';
|
286 |
|
|
when "1000" => out_string(i) := '8';
|
287 |
|
|
when "1001" => out_string(i) := '9';
|
288 |
|
|
when "1010" => out_string(i) := 'A';
|
289 |
|
|
when "1011" => out_string(i) := 'B';
|
290 |
|
|
when "1100" => out_string(i) := 'C';
|
291 |
|
|
when "1101" => out_string(i) := 'D';
|
292 |
|
|
when "1110" => out_string(i) := 'E';
|
293 |
|
|
when "1111" => out_string(i) := 'F';
|
294 |
|
|
when others =>
|
295 |
|
|
out_string(i) := 'U';
|
296 |
|
|
assert false report " illegal unsigned to string" severity note;
|
297 |
|
|
end case;
|
298 |
|
|
end loop;
|
299 |
|
|
return out_string;
|
300 |
|
|
end;
|
301 |
|
|
|
302 |
|
|
------------------------------------------------------------------------------------
|
303 |
|
|
--
|
304 |
|
|
------------------------------------------------------------------------------------
|
305 |
|
|
|
306 |
|
|
function u2asciichar(in_vector : unsigned(7 downto 0)) return character is
|
307 |
|
|
variable out_char : character;
|
308 |
|
|
|
309 |
|
|
begin
|
310 |
|
|
case in_vector is
|
311 |
|
|
when "00001001" => out_char := HT; -- Horizontal Tab
|
312 |
|
|
when "00100000" => out_char := ' ';
|
313 |
|
|
when "00100001" => out_char := '!';
|
314 |
|
|
when "00100010" => out_char := '"';
|
315 |
|
|
when "00100011" => out_char := '#';
|
316 |
|
|
when "00100100" => out_char := '$';
|
317 |
|
|
when "00100101" => out_char := '%';
|
318 |
|
|
when "00100110" => out_char := '&';
|
319 |
|
|
when "00100111" => out_char := ''';
|
320 |
|
|
when "00101000" => out_char := '(';
|
321 |
|
|
when "00101001" => out_char := ')';
|
322 |
|
|
when "00101010" => out_char := '*';
|
323 |
|
|
when "00101011" => out_char := '+';
|
324 |
|
|
when "00101100" => out_char := ',';
|
325 |
|
|
when "00101101" => out_char := '-';
|
326 |
|
|
when "00101110" => out_char := '.';
|
327 |
|
|
when "00101111" => out_char := '/';
|
328 |
|
|
when "00110000" => out_char := '0';
|
329 |
|
|
when "00110001" => out_char := '1';
|
330 |
|
|
when "00110010" => out_char := '2';
|
331 |
|
|
when "00110011" => out_char := '3';
|
332 |
|
|
when "00110100" => out_char := '4';
|
333 |
|
|
when "00110101" => out_char := '5';
|
334 |
|
|
when "00110110" => out_char := '6';
|
335 |
|
|
when "00110111" => out_char := '7';
|
336 |
|
|
when "00111000" => out_char := '8';
|
337 |
|
|
when "00111001" => out_char := '9';
|
338 |
|
|
when "00111010" => out_char := ':';
|
339 |
|
|
when "00111011" => out_char := ';';
|
340 |
|
|
when "00111100" => out_char := '<';
|
341 |
|
|
when "00111101" => out_char := '=';
|
342 |
|
|
when "00111110" => out_char := '>';
|
343 |
|
|
when "00111111" => out_char := '?';
|
344 |
|
|
when "01000000" => out_char := '@';
|
345 |
|
|
when "01000001" => out_char := 'A';
|
346 |
|
|
when "01000010" => out_char := 'B';
|
347 |
|
|
when "01000011" => out_char := 'C';
|
348 |
|
|
when "01000100" => out_char := 'D';
|
349 |
|
|
when "01000101" => out_char := 'E';
|
350 |
|
|
when "01000110" => out_char := 'F';
|
351 |
|
|
when "01000111" => out_char := 'G';
|
352 |
|
|
when "01001000" => out_char := 'H';
|
353 |
|
|
when "01001001" => out_char := 'I';
|
354 |
|
|
when "01001010" => out_char := 'J';
|
355 |
|
|
when "01001011" => out_char := 'K';
|
356 |
|
|
when "01001100" => out_char := 'L';
|
357 |
|
|
when "01001101" => out_char := 'M';
|
358 |
|
|
when "01001110" => out_char := 'N';
|
359 |
|
|
when "01001111" => out_char := 'O';
|
360 |
|
|
when "01010000" => out_char := 'P';
|
361 |
|
|
when "01010001" => out_char := 'Q';
|
362 |
|
|
when "01010010" => out_char := 'R';
|
363 |
|
|
when "01010011" => out_char := 'S';
|
364 |
|
|
when "01010100" => out_char := 'T';
|
365 |
|
|
when "01010101" => out_char := 'U';
|
366 |
|
|
when "01010110" => out_char := 'V';
|
367 |
|
|
when "01010111" => out_char := 'W';
|
368 |
|
|
when "01011000" => out_char := 'X';
|
369 |
|
|
when "01011001" => out_char := 'Y';
|
370 |
|
|
when "01011010" => out_char := 'Z';
|
371 |
|
|
when "01011011" => out_char := '[';
|
372 |
|
|
when "01011100" => out_char := '\';
|
373 |
|
|
when "01011101" => out_char := ']';
|
374 |
|
|
when "01011110" => out_char := '^';
|
375 |
|
|
when "01011111" => out_char := '_';
|
376 |
|
|
when "01100000" => out_char := '`';
|
377 |
|
|
when "01100001" => out_char := 'a';
|
378 |
|
|
when "01100010" => out_char := 'b';
|
379 |
|
|
when "01100011" => out_char := 'c';
|
380 |
|
|
when "01100100" => out_char := 'd';
|
381 |
|
|
when "01100101" => out_char := 'e';
|
382 |
|
|
when "01100110" => out_char := 'f';
|
383 |
|
|
when "01100111" => out_char := 'g';
|
384 |
|
|
when "01101000" => out_char := 'h';
|
385 |
|
|
when "01101001" => out_char := 'i';
|
386 |
|
|
when "01101010" => out_char := 'j';
|
387 |
|
|
when "01101011" => out_char := 'k';
|
388 |
|
|
when "01101100" => out_char := 'l';
|
389 |
|
|
when "01101101" => out_char := 'm';
|
390 |
|
|
when "01101110" => out_char := 'n';
|
391 |
|
|
when "01101111" => out_char := 'o';
|
392 |
|
|
when "01110000" => out_char := 'p';
|
393 |
|
|
when "01110001" => out_char := 'q';
|
394 |
|
|
when "01110010" => out_char := 'r';
|
395 |
|
|
when "01110011" => out_char := 's';
|
396 |
|
|
when "01110100" => out_char := 't';
|
397 |
|
|
when "01110101" => out_char := 'u';
|
398 |
|
|
when "01110110" => out_char := 'v';
|
399 |
|
|
when "01110111" => out_char := 'w';
|
400 |
|
|
when "01111000" => out_char := 'x';
|
401 |
|
|
when "01111001" => out_char := 'y';
|
402 |
|
|
when "01111010" => out_char := 'z';
|
403 |
|
|
when "01111011" => out_char := '{';
|
404 |
|
|
when "01111100" => out_char := '|';
|
405 |
|
|
when "01111101" => out_char := '}';
|
406 |
|
|
when "01111110" => out_char := '~';
|
407 |
|
|
when others =>
|
408 |
|
|
out_char := '*';
|
409 |
|
|
--assert false report " illegal unsigned to ascii character" severity note;
|
410 |
|
|
end case;
|
411 |
|
|
return out_char;
|
412 |
|
|
end;
|
413 |
|
|
|
414 |
|
|
------------------------------------------------------------------------------------
|
415 |
|
|
--
|
416 |
|
|
------------------------------------------------------------------------------------
|
417 |
|
|
|
418 |
|
|
function asciichar2u(in_char : character) return unsigned is
|
419 |
|
|
variable out_vect : unsigned(7 downto 0);
|
420 |
|
|
|
421 |
|
|
begin
|
422 |
|
|
case in_char is
|
423 |
|
|
when HT => out_vect := "00001001";
|
424 |
|
|
when ' ' => out_vect := "00100000";
|
425 |
|
|
when '!' => out_vect := "00100001";
|
426 |
|
|
when '"' => out_vect := "00100010";
|
427 |
|
|
when '#' => out_vect := "00100011";
|
428 |
|
|
when '$' => out_vect := "00100100";
|
429 |
|
|
when '%' => out_vect := "00100101";
|
430 |
|
|
when '&' => out_vect := "00100110";
|
431 |
|
|
when ''' => out_vect := "00100111";
|
432 |
|
|
when '(' => out_vect := "00101000";
|
433 |
|
|
when ')' => out_vect := "00101001";
|
434 |
|
|
when '*' => out_vect := "00101010";
|
435 |
|
|
when '+' => out_vect := "00101011";
|
436 |
|
|
when ',' => out_vect := "00101100";
|
437 |
|
|
when '-' => out_vect := "00101101";
|
438 |
|
|
when '.' => out_vect := "00101110";
|
439 |
|
|
when '/' => out_vect := "00101111";
|
440 |
|
|
when '0' => out_vect := "00110000";
|
441 |
|
|
when '1' => out_vect := "00110001";
|
442 |
|
|
when '2' => out_vect := "00110010";
|
443 |
|
|
when '3' => out_vect := "00110011";
|
444 |
|
|
when '4' => out_vect := "00110100";
|
445 |
|
|
when '5' => out_vect := "00110101";
|
446 |
|
|
when '6' => out_vect := "00110110";
|
447 |
|
|
when '7' => out_vect := "00110111";
|
448 |
|
|
when '8' => out_vect := "00111000";
|
449 |
|
|
when '9' => out_vect := "00111001";
|
450 |
|
|
when ':' => out_vect := "00111010";
|
451 |
|
|
when ';' => out_vect := "00111011";
|
452 |
|
|
when '<' => out_vect := "00111100";
|
453 |
|
|
when '=' => out_vect := "00111101";
|
454 |
|
|
when '>' => out_vect := "00111110";
|
455 |
|
|
when '?' => out_vect := "00111111";
|
456 |
|
|
when '@' => out_vect := "01000000";
|
457 |
|
|
when 'A' => out_vect := "01000001";
|
458 |
|
|
when 'B' => out_vect := "01000010";
|
459 |
|
|
when 'C' => out_vect := "01000011";
|
460 |
|
|
when 'D' => out_vect := "01000100";
|
461 |
|
|
when 'E' => out_vect := "01000101";
|
462 |
|
|
when 'F' => out_vect := "01000110";
|
463 |
|
|
when 'G' => out_vect := "01000111";
|
464 |
|
|
when 'H' => out_vect := "01001000";
|
465 |
|
|
when 'I' => out_vect := "01001001";
|
466 |
|
|
when 'J' => out_vect := "01001010";
|
467 |
|
|
when 'K' => out_vect := "01001011";
|
468 |
|
|
when 'L' => out_vect := "01001100";
|
469 |
|
|
when 'M' => out_vect := "01001101";
|
470 |
|
|
when 'N' => out_vect := "01001110";
|
471 |
|
|
when 'O' => out_vect := "01001111";
|
472 |
|
|
when 'P' => out_vect := "01010000";
|
473 |
|
|
when 'Q' => out_vect := "01010001";
|
474 |
|
|
when 'R' => out_vect := "01010010";
|
475 |
|
|
when 'S' => out_vect := "01010011";
|
476 |
|
|
when 'T' => out_vect := "01010100";
|
477 |
|
|
when 'U' => out_vect := "01010101";
|
478 |
|
|
when 'V' => out_vect := "01010110";
|
479 |
|
|
when 'W' => out_vect := "01010111";
|
480 |
|
|
when 'X' => out_vect := "01011000";
|
481 |
|
|
when 'Y' => out_vect := "01011001";
|
482 |
|
|
when 'Z' => out_vect := "01011010";
|
483 |
|
|
when '[' => out_vect := "01011011";
|
484 |
|
|
when '\' => out_vect := "01011100";
|
485 |
|
|
when ']' => out_vect := "01011101";
|
486 |
|
|
when '^' => out_vect := "01011110";
|
487 |
|
|
when '_' => out_vect := "01011111";
|
488 |
|
|
when '`' => out_vect := "01100000";
|
489 |
|
|
when 'a' => out_vect := "01100001";
|
490 |
|
|
when 'b' => out_vect := "01100010";
|
491 |
|
|
when 'c' => out_vect := "01100011";
|
492 |
|
|
when 'd' => out_vect := "01100100";
|
493 |
|
|
when 'e' => out_vect := "01100101";
|
494 |
|
|
when 'f' => out_vect := "01100110";
|
495 |
|
|
when 'g' => out_vect := "01100111";
|
496 |
|
|
when 'h' => out_vect := "01101000";
|
497 |
|
|
when 'i' => out_vect := "01101001";
|
498 |
|
|
when 'j' => out_vect := "01101010";
|
499 |
|
|
when 'k' => out_vect := "01101011";
|
500 |
|
|
when 'l' => out_vect := "01101100";
|
501 |
|
|
when 'm' => out_vect := "01101101";
|
502 |
|
|
when 'n' => out_vect := "01101110";
|
503 |
|
|
when 'o' => out_vect := "01101111";
|
504 |
|
|
when 'p' => out_vect := "01110000";
|
505 |
|
|
when 'q' => out_vect := "01110001";
|
506 |
|
|
when 'r' => out_vect := "01110010";
|
507 |
|
|
when 's' => out_vect := "01110011";
|
508 |
|
|
when 't' => out_vect := "01110100";
|
509 |
|
|
when 'u' => out_vect := "01110101";
|
510 |
|
|
when 'v' => out_vect := "01110110";
|
511 |
|
|
when 'w' => out_vect := "01110111";
|
512 |
|
|
when 'x' => out_vect := "01111000";
|
513 |
|
|
when 'y' => out_vect := "01111001";
|
514 |
|
|
when 'z' => out_vect := "01111010";
|
515 |
|
|
when '{' => out_vect := "01111011";
|
516 |
|
|
when '|' => out_vect := "01111100";
|
517 |
|
|
when '}' => out_vect := "01111101";
|
518 |
|
|
when '~' => out_vect := "01111110";
|
519 |
|
|
when others =>
|
520 |
|
|
out_vect := "00101010";
|
521 |
|
|
--assert false report " illegal char to unsigned" severity note;
|
522 |
|
|
end case;
|
523 |
|
|
return out_vect;
|
524 |
|
|
end;
|
525 |
|
|
|
526 |
|
|
------------------------------------------------------------------------------------
|
527 |
|
|
--
|
528 |
|
|
------------------------------------------------------------------------------------
|
529 |
|
|
function char2slv (in_char : character) return std_logic_vector is
|
530 |
|
|
|
531 |
|
|
variable out_vec : std_logic_vector(3 downto 0);
|
532 |
|
|
|
533 |
|
|
begin
|
534 |
|
|
case in_char is
|
535 |
|
|
when '0' => out_vec := "0000";
|
536 |
|
|
when '1' => out_vec := "0001";
|
537 |
|
|
when '2' => out_vec := "0010";
|
538 |
|
|
when '3' => out_vec := "0011";
|
539 |
|
|
when '4' => out_vec := "0100";
|
540 |
|
|
when '5' => out_vec := "0101";
|
541 |
|
|
when '6' => out_vec := "0110";
|
542 |
|
|
when '7' => out_vec := "0111";
|
543 |
|
|
when '8' => out_vec := "1000";
|
544 |
|
|
when '9' => out_vec := "1001";
|
545 |
|
|
when 'A' | 'a' => out_vec := "1010";
|
546 |
|
|
when 'B' | 'b' => out_vec := "1011";
|
547 |
|
|
when 'C' | 'c' => out_vec := "1100";
|
548 |
|
|
when 'D' | 'd' => out_vec := "1101";
|
549 |
|
|
when 'E' | 'e' => out_vec := "1110";
|
550 |
|
|
when 'F' | 'f' => out_vec := "1111";
|
551 |
|
|
when others =>
|
552 |
|
|
out_vec := "0000";
|
553 |
|
|
end case;
|
554 |
|
|
return out_vec;
|
555 |
|
|
end char2slv;
|
556 |
|
|
|
557 |
|
|
------------------------------------------------------------------------------------
|
558 |
|
|
--
|
559 |
|
|
------------------------------------------------------------------------------------
|
560 |
|
|
function char2u(in_char : character) return unsigned is
|
561 |
|
|
|
562 |
|
|
variable out_vec : unsigned(3 downto 0);
|
563 |
|
|
|
564 |
|
|
begin
|
565 |
|
|
case in_char is
|
566 |
|
|
when '0' => out_vec := "0000";
|
567 |
|
|
when '1' => out_vec := "0001";
|
568 |
|
|
when '2' => out_vec := "0010";
|
569 |
|
|
when '3' => out_vec := "0011";
|
570 |
|
|
when '4' => out_vec := "0100";
|
571 |
|
|
when '5' => out_vec := "0101";
|
572 |
|
|
when '6' => out_vec := "0110";
|
573 |
|
|
when '7' => out_vec := "0111";
|
574 |
|
|
when '8' => out_vec := "1000";
|
575 |
|
|
when '9' => out_vec := "1001";
|
576 |
|
|
when 'A' | 'a' => out_vec := "1010";
|
577 |
|
|
when 'B' | 'b' => out_vec := "1011";
|
578 |
|
|
when 'C' | 'c' => out_vec := "1100";
|
579 |
|
|
when 'D' | 'd' => out_vec := "1101";
|
580 |
|
|
when 'E' | 'e' => out_vec := "1110";
|
581 |
|
|
when 'F' | 'f' => out_vec := "1111";
|
582 |
|
|
when others =>
|
583 |
|
|
out_vec := "0000";
|
584 |
|
|
end case;
|
585 |
|
|
return out_vec;
|
586 |
|
|
end char2u;
|
587 |
|
|
|
588 |
|
|
------------------------------------------------------------------------------------
|
589 |
|
|
--
|
590 |
|
|
------------------------------------------------------------------------------------
|
591 |
|
|
|
592 |
|
|
function hex_to_ascii(in_vector : std_logic_vector; nibbles : natural) return string is
|
593 |
|
|
variable out_string : string(1 to nibbles);
|
594 |
|
|
variable temp_in_vector : std_logic_vector(4*nibbles-1 downto 0);
|
595 |
|
|
variable vector : std_logic_vector(3 downto 0);
|
596 |
|
|
|
597 |
|
|
begin
|
598 |
|
|
temp_in_vector := in_vector(in_vector'length-1 downto in_vector'length-temp_in_vector'length);
|
599 |
|
|
for i in 1 to nibbles loop
|
600 |
|
|
vector := temp_in_vector((4*(nibbles-i)+3) downto 4*(nibbles-i));
|
601 |
|
|
case vector is
|
602 |
|
|
when "0000" => out_string(i) := '0';
|
603 |
|
|
when "0001" => out_string(i) := '1';
|
604 |
|
|
when "0010" => out_string(i) := '2';
|
605 |
|
|
when "0011" => out_string(i) := '3';
|
606 |
|
|
when "0100" => out_string(i) := '4';
|
607 |
|
|
when "0101" => out_string(i) := '5';
|
608 |
|
|
when "0110" => out_string(i) := '6';
|
609 |
|
|
when "0111" => out_string(i) := '7';
|
610 |
|
|
when "1000" => out_string(i) := '8';
|
611 |
|
|
when "1001" => out_string(i) := '9';
|
612 |
|
|
when "1010" => out_string(i) := 'A';
|
613 |
|
|
when "1011" => out_string(i) := 'B';
|
614 |
|
|
when "1100" => out_string(i) := 'C';
|
615 |
|
|
when "1101" => out_string(i) := 'D';
|
616 |
|
|
when "1110" => out_string(i) := 'E';
|
617 |
|
|
when "1111" => out_string(i) := 'F';
|
618 |
|
|
when others =>
|
619 |
|
|
out_string(i) := 'J';
|
620 |
|
|
assert false
|
621 |
|
|
report " illegal std_logic_vector to string"
|
622 |
|
|
severity note;
|
623 |
|
|
end case;
|
624 |
|
|
end loop;
|
625 |
|
|
return out_string;
|
626 |
|
|
end;
|
627 |
|
|
|
628 |
|
|
------------------------------------------------------------------------------------
|
629 |
|
|
--
|
630 |
|
|
------------------------------------------------------------------------------------
|
631 |
|
|
|
632 |
|
|
function u2ascii(in_vector : unsigned; nibbles : natural) return string is
|
633 |
|
|
variable out_string : string(1 to nibbles);
|
634 |
|
|
variable temp_in_vector : unsigned(4*nibbles-1 downto 0);
|
635 |
|
|
variable vector : unsigned(3 downto 0);
|
636 |
|
|
|
637 |
|
|
begin
|
638 |
|
|
temp_in_vector := in_vector(in_vector'length-1 downto in_vector'length-temp_in_vector'length);
|
639 |
|
|
for i in 1 to nibbles loop
|
640 |
|
|
vector := temp_in_vector((4*(nibbles-i)+3) downto 4*(nibbles-i));
|
641 |
|
|
case vector is
|
642 |
|
|
when "0000" => out_string(i) := '0';
|
643 |
|
|
when "0001" => out_string(i) := '1';
|
644 |
|
|
when "0010" => out_string(i) := '2';
|
645 |
|
|
when "0011" => out_string(i) := '3';
|
646 |
|
|
when "0100" => out_string(i) := '4';
|
647 |
|
|
when "0101" => out_string(i) := '5';
|
648 |
|
|
when "0110" => out_string(i) := '6';
|
649 |
|
|
when "0111" => out_string(i) := '7';
|
650 |
|
|
when "1000" => out_string(i) := '8';
|
651 |
|
|
when "1001" => out_string(i) := '9';
|
652 |
|
|
when "1010" => out_string(i) := 'A';
|
653 |
|
|
when "1011" => out_string(i) := 'B';
|
654 |
|
|
when "1100" => out_string(i) := 'C';
|
655 |
|
|
when "1101" => out_string(i) := 'D';
|
656 |
|
|
when "1110" => out_string(i) := 'E';
|
657 |
|
|
when "1111" => out_string(i) := 'F';
|
658 |
|
|
when others =>
|
659 |
|
|
out_string(i) := 'U';
|
660 |
|
|
assert false report " illegal unsigned to string" severity note;
|
661 |
|
|
end case;
|
662 |
|
|
end loop;
|
663 |
|
|
return out_string;
|
664 |
|
|
end;
|
665 |
|
|
|
666 |
|
|
------------------------------------------------------------------------------------
|
667 |
|
|
--
|
668 |
|
|
------------------------------------------------------------------------------------
|
669 |
|
|
|
670 |
|
|
function hex_data_wrd(in_vector : std_logic_vector) return string is
|
671 |
|
|
variable out_string : string(1 to 8);
|
672 |
|
|
variable temp_in_vector : std_logic_vector(31 downto 0);
|
673 |
|
|
variable vector : std_logic_vector(3 downto 0);
|
674 |
|
|
|
675 |
|
|
begin
|
676 |
|
|
temp_in_vector := in_vector;
|
677 |
|
|
for i in 1 to 8 loop
|
678 |
|
|
vector := temp_in_vector((35-(4*i)) downto (32-(4*i)));
|
679 |
|
|
case vector is
|
680 |
|
|
when "0000" => out_string(i) := '0';
|
681 |
|
|
when "0001" => out_string(i) := '1';
|
682 |
|
|
when "0010" => out_string(i) := '2';
|
683 |
|
|
when "0011" => out_string(i) := '3';
|
684 |
|
|
when "0100" => out_string(i) := '4';
|
685 |
|
|
when "0101" => out_string(i) := '5';
|
686 |
|
|
when "0110" => out_string(i) := '6';
|
687 |
|
|
when "0111" => out_string(i) := '7';
|
688 |
|
|
when "1000" => out_string(i) := '8';
|
689 |
|
|
when "1001" => out_string(i) := '9';
|
690 |
|
|
when "1010" => out_string(i) := 'A';
|
691 |
|
|
when "1011" => out_string(i) := 'B';
|
692 |
|
|
when "1100" => out_string(i) := 'C';
|
693 |
|
|
when "1101" => out_string(i) := 'D';
|
694 |
|
|
when "1110" => out_string(i) := 'E';
|
695 |
|
|
when "1111" => out_string(i) := 'F';
|
696 |
|
|
when others =>
|
697 |
|
|
out_string(i) := 'J';
|
698 |
|
|
assert false
|
699 |
|
|
report " illegal std_logic_vector to string"
|
700 |
|
|
severity note;
|
701 |
|
|
end case;
|
702 |
|
|
end loop;
|
703 |
|
|
return out_string;
|
704 |
|
|
end;
|
705 |
|
|
|
706 |
|
|
------------------------------------------------------------------------------------
|
707 |
|
|
--
|
708 |
|
|
------------------------------------------------------------------------------------
|
709 |
|
|
|
710 |
|
|
function hex_data_dblwrd(in_vector : std_logic_vector) return string is
|
711 |
|
|
variable out_string : string(1 to 16);
|
712 |
|
|
variable temp_in_vector : std_logic_vector(63 downto 0);
|
713 |
|
|
variable vector : std_logic_vector(3 downto 0);
|
714 |
|
|
|
715 |
|
|
begin
|
716 |
|
|
temp_in_vector := in_vector;
|
717 |
|
|
for i in 1 to 16 loop
|
718 |
|
|
vector := temp_in_vector((67-(4*i)) downto (64-(4*i)));
|
719 |
|
|
case vector is
|
720 |
|
|
when "0000" => out_string(i) := '0';
|
721 |
|
|
when "0001" => out_string(i) := '1';
|
722 |
|
|
when "0010" => out_string(i) := '2';
|
723 |
|
|
when "0011" => out_string(i) := '3';
|
724 |
|
|
when "0100" => out_string(i) := '4';
|
725 |
|
|
when "0101" => out_string(i) := '5';
|
726 |
|
|
when "0110" => out_string(i) := '6';
|
727 |
|
|
when "0111" => out_string(i) := '7';
|
728 |
|
|
when "1000" => out_string(i) := '8';
|
729 |
|
|
when "1001" => out_string(i) := '9';
|
730 |
|
|
when "1010" => out_string(i) := 'A';
|
731 |
|
|
when "1011" => out_string(i) := 'B';
|
732 |
|
|
when "1100" => out_string(i) := 'C';
|
733 |
|
|
when "1101" => out_string(i) := 'D';
|
734 |
|
|
when "1110" => out_string(i) := 'E';
|
735 |
|
|
when "1111" => out_string(i) := 'F';
|
736 |
|
|
when others =>
|
737 |
|
|
out_string(i) := 'J';
|
738 |
|
|
assert false
|
739 |
|
|
report " illegal std_logic_vector to string"
|
740 |
|
|
severity note;
|
741 |
|
|
end case;
|
742 |
|
|
end loop;
|
743 |
|
|
return out_string;
|
744 |
|
|
end;
|
745 |
|
|
|
746 |
|
|
------------------------------------------------------------------------------------
|
747 |
|
|
--
|
748 |
|
|
------------------------------------------------------------------------------------
|
749 |
|
|
|
750 |
|
|
function hex_data_dblwrdz(in_vector : std_logic_vector) return string is
|
751 |
|
|
variable out_string : string(1 to 16);
|
752 |
|
|
variable temp_in_vector : std_logic_vector(63 downto 0);
|
753 |
|
|
variable vector : std_logic_vector(3 downto 0);
|
754 |
|
|
|
755 |
|
|
begin
|
756 |
|
|
temp_in_vector := in_vector;
|
757 |
|
|
for i in 1 to 16 loop
|
758 |
|
|
vector := temp_in_vector((67-(4*i)) downto (64-(4*i)));
|
759 |
|
|
case vector is
|
760 |
|
|
when "0000" => out_string(i) := '0';
|
761 |
|
|
when "0001" => out_string(i) := '1';
|
762 |
|
|
when "0010" => out_string(i) := '2';
|
763 |
|
|
when "0011" => out_string(i) := '3';
|
764 |
|
|
when "0100" => out_string(i) := '4';
|
765 |
|
|
when "0101" => out_string(i) := '5';
|
766 |
|
|
when "0110" => out_string(i) := '6';
|
767 |
|
|
when "0111" => out_string(i) := '7';
|
768 |
|
|
when "1000" => out_string(i) := '8';
|
769 |
|
|
when "1001" => out_string(i) := '9';
|
770 |
|
|
when "1010" => out_string(i) := 'A';
|
771 |
|
|
when "1011" => out_string(i) := 'B';
|
772 |
|
|
when "1100" => out_string(i) := 'C';
|
773 |
|
|
when "1101" => out_string(i) := 'D';
|
774 |
|
|
when "1110" => out_string(i) := 'E';
|
775 |
|
|
when "1111" => out_string(i) := 'F';
|
776 |
|
|
when "ZZZZ" => out_string(i) := 'Z';
|
777 |
|
|
when others =>
|
778 |
|
|
out_string(i) := 'J';
|
779 |
|
|
assert false
|
780 |
|
|
report " illegal std_logic_vector to string"
|
781 |
|
|
severity note;
|
782 |
|
|
end case;
|
783 |
|
|
end loop;
|
784 |
|
|
return out_string;
|
785 |
|
|
end;
|
786 |
|
|
|
787 |
|
|
------------------------------------------------------------------------------------
|
788 |
|
|
--
|
789 |
|
|
------------------------------------------------------------------------------------
|
790 |
|
|
-- returns true if the character is a valid hexadecimal character.
|
791 |
|
|
function is_hex(c : character) return boolean is
|
792 |
|
|
begin
|
793 |
|
|
case c is
|
794 |
|
|
when '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
|
795 |
|
|
'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' |
|
796 |
|
|
'e' | 'f' =>
|
797 |
|
|
return(true);
|
798 |
|
|
when others =>
|
799 |
|
|
return(false);
|
800 |
|
|
end case;
|
801 |
|
|
end is_hex;
|
802 |
|
|
|
803 |
|
|
------------------------------------------------------------------------------------
|
804 |
|
|
--
|
805 |
|
|
------------------------------------------------------------------------------------
|
806 |
|
|
-- returns true if the character is a valid hexadecimal character.
|
807 |
|
|
function is_std_logic(c : character) return boolean is
|
808 |
|
|
begin
|
809 |
|
|
case c is
|
810 |
|
|
when '0' | '1' | 'u' | 'U' | 'x' | 'X' | 'z' | 'Z' =>
|
811 |
|
|
return(true);
|
812 |
|
|
when others =>
|
813 |
|
|
return(false);
|
814 |
|
|
end case;
|
815 |
|
|
end is_std_logic;
|
816 |
|
|
|
817 |
|
|
------------------------------------------------------------------------------------
|
818 |
|
|
--
|
819 |
|
|
------------------------------------------------------------------------------------
|
820 |
|
|
-- returns true if the character is whitespace.
|
821 |
|
|
function is_space(c : character) return boolean is
|
822 |
|
|
begin
|
823 |
|
|
case c is
|
824 |
|
|
when ' ' | HT =>
|
825 |
|
|
return(true);
|
826 |
|
|
when others =>
|
827 |
|
|
return(false);
|
828 |
|
|
end case;
|
829 |
|
|
end is_space;
|
830 |
|
|
|
831 |
|
|
------------------------------------------------------------------------------------
|
832 |
|
|
--
|
833 |
|
|
------------------------------------------------------------------------------------
|
834 |
|
|
|
835 |
|
|
function char2sl(in_char : character) return std_logic is
|
836 |
|
|
|
837 |
|
|
variable out_bit : std_logic;
|
838 |
|
|
|
839 |
|
|
begin
|
840 |
|
|
|
841 |
|
|
if (in_char = '1') then
|
842 |
|
|
out_bit := '1';
|
843 |
|
|
elsif (in_char = '0') then
|
844 |
|
|
out_bit := '0';
|
845 |
|
|
elsif (in_char = 'x') then
|
846 |
|
|
out_bit := 'X';
|
847 |
|
|
elsif (in_char = 'X') then
|
848 |
|
|
out_bit := 'X';
|
849 |
|
|
elsif (in_char = 'u') then
|
850 |
|
|
out_bit := 'U';
|
851 |
|
|
elsif (in_char = 'U') then
|
852 |
|
|
out_bit := 'U';
|
853 |
|
|
elsif (in_char = 'z') then
|
854 |
|
|
out_bit := 'Z';
|
855 |
|
|
elsif (in_char = 'Z') then
|
856 |
|
|
out_bit := 'Z';
|
857 |
|
|
else
|
858 |
|
|
assert false
|
859 |
|
|
report "illegal character to std_logic"
|
860 |
|
|
severity note;
|
861 |
|
|
end if;
|
862 |
|
|
|
863 |
|
|
-- Mysteriously, the following code did not work in place of the
|
864 |
|
|
-- above chain of if-elsif-else logic... it seemed to always return '1'.
|
865 |
|
|
-- I cannot tell why. -- John Clayton
|
866 |
|
|
-- case in_char is
|
867 |
|
|
-- when '1' =>
|
868 |
|
|
-- out_bit:= '1';
|
869 |
|
|
-- when '0' =>
|
870 |
|
|
-- out_bit:= '1';
|
871 |
|
|
-- when 'u' | 'U' =>
|
872 |
|
|
-- out_bit:= 'U';
|
873 |
|
|
-- when 'x' | 'X' =>
|
874 |
|
|
-- out_bit:= 'X';
|
875 |
|
|
-- when 'z' | 'Z' =>
|
876 |
|
|
-- out_bit:= 'Z';
|
877 |
|
|
-- when others =>
|
878 |
|
|
-- assert false
|
879 |
|
|
-- report "illegal character to std_logic"
|
880 |
|
|
-- severity note;
|
881 |
|
|
-- end case;
|
882 |
|
|
|
883 |
|
|
return out_bit;
|
884 |
|
|
end char2sl;
|
885 |
|
|
|
886 |
|
|
|
887 |
|
|
|
888 |
|
|
------------------------------------------------------------------------------------
|
889 |
|
|
-- Converts Standard Logic Vectors to Unsigned
|
890 |
|
|
------------------------------------------------------------------------------------
|
891 |
|
|
|
892 |
|
|
function slv2u(in_a : std_logic_vector) return unsigned is
|
893 |
|
|
variable i : natural;
|
894 |
|
|
variable o : unsigned(in_a'length-1 downto 0);
|
895 |
|
|
|
896 |
|
|
begin
|
897 |
|
|
|
898 |
|
|
o := (others=>'0');
|
899 |
|
|
for i in 0 to in_a'length-1 loop
|
900 |
|
|
o(i) := in_a(i);
|
901 |
|
|
end loop;
|
902 |
|
|
|
903 |
|
|
return(o);
|
904 |
|
|
|
905 |
|
|
end;
|
906 |
|
|
|
907 |
|
|
------------------------------------------------------------------------------------
|
908 |
|
|
-- Converts Unsigned to Standard Logic Vector
|
909 |
|
|
------------------------------------------------------------------------------------
|
910 |
|
|
|
911 |
|
|
function u2slv(in_a : unsigned) return std_logic_vector is
|
912 |
|
|
variable i : natural;
|
913 |
|
|
variable o : std_logic_vector(in_a'length-1 downto 0);
|
914 |
|
|
|
915 |
|
|
begin
|
916 |
|
|
|
917 |
|
|
o := (others=>'0');
|
918 |
|
|
for i in 0 to in_a'length-1 loop
|
919 |
|
|
o(i) := in_a(i);
|
920 |
|
|
end loop;
|
921 |
|
|
|
922 |
|
|
return(o);
|
923 |
|
|
|
924 |
|
|
end;
|
925 |
|
|
|
926 |
|
|
------------------------------------------------------------------------------------
|
927 |
|
|
-- Converts Standard Logic Vectors to Signed
|
928 |
|
|
------------------------------------------------------------------------------------
|
929 |
|
|
|
930 |
|
|
function slv2s(in_a : std_logic_vector) return signed is
|
931 |
|
|
variable i : natural;
|
932 |
|
|
variable o : signed(in_a'length-1 downto 0);
|
933 |
|
|
|
934 |
|
|
begin
|
935 |
|
|
|
936 |
|
|
o := (others=>'0');
|
937 |
|
|
for i in 0 to in_a'length-1 loop
|
938 |
|
|
o(i) := in_a(i);
|
939 |
|
|
end loop;
|
940 |
|
|
|
941 |
|
|
return(o);
|
942 |
|
|
|
943 |
|
|
end;
|
944 |
|
|
|
945 |
|
|
------------------------------------------------------------------------------------
|
946 |
|
|
-- Converts Signed to Standard Logic Vector
|
947 |
|
|
------------------------------------------------------------------------------------
|
948 |
|
|
|
949 |
|
|
function s2slv(in_a : signed) return std_logic_vector is
|
950 |
|
|
variable i : natural;
|
951 |
|
|
variable o : std_logic_vector(in_a'length-1 downto 0);
|
952 |
|
|
|
953 |
|
|
begin
|
954 |
|
|
|
955 |
|
|
o := (others=>'0');
|
956 |
|
|
for i in 0 to in_a'length-1 loop
|
957 |
|
|
o(i) := in_a(i);
|
958 |
|
|
end loop;
|
959 |
|
|
|
960 |
|
|
return(o);
|
961 |
|
|
|
962 |
|
|
end;
|
963 |
|
|
|
964 |
|
|
------------------------------------------------------------------------------------
|
965 |
|
|
-- Resizes Standard Logic Vectors, "right justified" i.e. starts at LSB...
|
966 |
|
|
------------------------------------------------------------------------------------
|
967 |
|
|
|
968 |
|
|
function slv_resize(in_vect : std_logic_vector; out_size : integer) return std_logic_vector is
|
969 |
|
|
variable i : integer;
|
970 |
|
|
variable o_vect : std_logic_vector(out_size-1 downto 0);
|
971 |
|
|
|
972 |
|
|
begin
|
973 |
|
|
|
974 |
|
|
o_vect := (others=>'0');
|
975 |
|
|
for i in 0 to in_vect'length-1 loop
|
976 |
|
|
if (i<out_size) then
|
977 |
|
|
o_vect(i) := in_vect(i);
|
978 |
|
|
end if;
|
979 |
|
|
end loop;
|
980 |
|
|
|
981 |
|
|
return(o_vect);
|
982 |
|
|
|
983 |
|
|
end slv_resize;
|
984 |
|
|
|
985 |
|
|
------------------------------------------------------------------------------------
|
986 |
|
|
-- Resizes Standard Logic Vectors, "left justified" i.e. starts at MSB...
|
987 |
|
|
------------------------------------------------------------------------------------
|
988 |
|
|
|
989 |
|
|
function slv_resize_l(in_vect : std_logic_vector; out_size : integer) return std_logic_vector is
|
990 |
|
|
variable i : integer;
|
991 |
|
|
variable j : integer;
|
992 |
|
|
variable o_vect : std_logic_vector(out_size-1 downto 0);
|
993 |
|
|
|
994 |
|
|
begin
|
995 |
|
|
|
996 |
|
|
o_vect := (others=>'0');
|
997 |
|
|
j := out_size-1;
|
998 |
|
|
for i in in_vect'length-1 downto 0 loop
|
999 |
|
|
if (j>=0) then
|
1000 |
|
|
o_vect(j) := in_vect(i);
|
1001 |
|
|
j := j-1;
|
1002 |
|
|
end if;
|
1003 |
|
|
end loop;
|
1004 |
|
|
|
1005 |
|
|
return(o_vect);
|
1006 |
|
|
|
1007 |
|
|
end slv_resize_l;
|
1008 |
|
|
|
1009 |
|
|
------------------------------------------------------------------------------------
|
1010 |
|
|
-- Resizes Standard Logic Vectors, "right justified with sign extension"
|
1011 |
|
|
------------------------------------------------------------------------------------
|
1012 |
|
|
|
1013 |
|
|
function slv_resize_se(in_vect : std_logic_vector; out_size : integer) return std_logic_vector is
|
1014 |
|
|
variable i : integer;
|
1015 |
|
|
variable o_vect : std_logic_vector(out_size-1 downto 0);
|
1016 |
|
|
|
1017 |
|
|
begin
|
1018 |
|
|
|
1019 |
|
|
o_vect := (others=>in_vect(in_vect'length-1));
|
1020 |
|
|
for i in 0 to in_vect'length-1 loop
|
1021 |
|
|
if (i<out_size) then
|
1022 |
|
|
o_vect(i) := in_vect(i);
|
1023 |
|
|
end if;
|
1024 |
|
|
end loop;
|
1025 |
|
|
|
1026 |
|
|
return(o_vect);
|
1027 |
|
|
|
1028 |
|
|
end slv_resize_se;
|
1029 |
|
|
|
1030 |
|
|
------------------------------------------------------------------------------------
|
1031 |
|
|
-- Resizes Signed, "right justified" i.e. starts at LSB...
|
1032 |
|
|
------------------------------------------------------------------------------------
|
1033 |
|
|
|
1034 |
|
|
function s_resize(in_vect : signed; out_size : integer) return signed is
|
1035 |
|
|
variable i : integer;
|
1036 |
|
|
variable o_vect : signed(out_size-1 downto 0);
|
1037 |
|
|
|
1038 |
|
|
begin
|
1039 |
|
|
|
1040 |
|
|
o_vect := (others=>'0');
|
1041 |
|
|
for i in 0 to in_vect'length-1 loop
|
1042 |
|
|
if (i<out_size) then
|
1043 |
|
|
o_vect(i) := in_vect(i);
|
1044 |
|
|
end if;
|
1045 |
|
|
end loop;
|
1046 |
|
|
|
1047 |
|
|
return(o_vect);
|
1048 |
|
|
|
1049 |
|
|
end s_resize;
|
1050 |
|
|
|
1051 |
|
|
------------------------------------------------------------------------------------
|
1052 |
|
|
-- Resizes Signed, "left justified" i.e. starts at MSB...
|
1053 |
|
|
------------------------------------------------------------------------------------
|
1054 |
|
|
|
1055 |
|
|
function s_resize_l(in_vect : signed; out_size : integer) return signed is
|
1056 |
|
|
variable i : integer;
|
1057 |
|
|
variable j : integer;
|
1058 |
|
|
variable o_vect : signed(out_size-1 downto 0);
|
1059 |
|
|
|
1060 |
|
|
begin
|
1061 |
|
|
|
1062 |
|
|
o_vect := (others=>'0');
|
1063 |
|
|
j := out_size-1;
|
1064 |
|
|
for i in in_vect'length-1 downto 0 loop
|
1065 |
|
|
if (j>=0) then
|
1066 |
|
|
o_vect(j) := in_vect(i);
|
1067 |
|
|
j := j-1;
|
1068 |
|
|
end if;
|
1069 |
|
|
end loop;
|
1070 |
|
|
|
1071 |
|
|
return(o_vect);
|
1072 |
|
|
|
1073 |
|
|
end s_resize_l;
|
1074 |
|
|
|
1075 |
|
|
------------------------------------------------------------------------------------
|
1076 |
|
|
-- Resizes Signed, "right justified with sign extension"
|
1077 |
|
|
------------------------------------------------------------------------------------
|
1078 |
|
|
|
1079 |
|
|
function s_resize_se(in_vect : signed; out_size : integer) return signed is
|
1080 |
|
|
variable i : integer;
|
1081 |
|
|
variable o_vect : signed(out_size-1 downto 0);
|
1082 |
|
|
|
1083 |
|
|
begin
|
1084 |
|
|
|
1085 |
|
|
o_vect := (others=>in_vect(in_vect'length-1));
|
1086 |
|
|
for i in 0 to in_vect'length-1 loop
|
1087 |
|
|
if (i<out_size) then
|
1088 |
|
|
o_vect(i) := in_vect(i);
|
1089 |
|
|
end if;
|
1090 |
|
|
end loop;
|
1091 |
|
|
|
1092 |
|
|
return(o_vect);
|
1093 |
|
|
|
1094 |
|
|
end s_resize_se;
|
1095 |
|
|
|
1096 |
|
|
------------------------------------------------------------------------------------
|
1097 |
|
|
-- Resizes Unsigned, "right justified" i.e. starts at LSB...
|
1098 |
|
|
------------------------------------------------------------------------------------
|
1099 |
|
|
|
1100 |
|
|
function u_resize(in_vect : unsigned; out_size : integer) return unsigned is
|
1101 |
|
|
variable i : integer;
|
1102 |
|
|
variable i_vect : unsigned(in_vect'length-1 downto 0);
|
1103 |
|
|
variable o_vect : unsigned(out_size-1 downto 0);
|
1104 |
|
|
|
1105 |
|
|
begin
|
1106 |
|
|
i_vect := in_vect;
|
1107 |
|
|
o_vect := (others=>'0');
|
1108 |
|
|
for i in 0 to in_vect'length-1 loop
|
1109 |
|
|
if (i<out_size) then
|
1110 |
|
|
o_vect(i) := i_vect(i);
|
1111 |
|
|
end if;
|
1112 |
|
|
end loop;
|
1113 |
|
|
|
1114 |
|
|
return(o_vect);
|
1115 |
|
|
|
1116 |
|
|
end u_resize;
|
1117 |
|
|
|
1118 |
|
|
------------------------------------------------------------------------------------
|
1119 |
|
|
-- Resizes Unsigned, "left justified" i.e. starts at MSB...
|
1120 |
|
|
------------------------------------------------------------------------------------
|
1121 |
|
|
|
1122 |
|
|
function u_resize_l(in_vect : unsigned; out_size : integer) return unsigned is
|
1123 |
|
|
variable i : integer;
|
1124 |
|
|
variable j : integer;
|
1125 |
|
|
variable o_vect : unsigned(out_size-1 downto 0);
|
1126 |
|
|
|
1127 |
|
|
begin
|
1128 |
|
|
|
1129 |
|
|
o_vect := (others=>'0');
|
1130 |
|
|
j := out_size-1;
|
1131 |
|
|
for i in in_vect'length-1 downto 0 loop
|
1132 |
|
|
if (j>=0) then
|
1133 |
|
|
o_vect(j) := in_vect(i);
|
1134 |
|
|
j := j-1;
|
1135 |
|
|
end if;
|
1136 |
|
|
end loop;
|
1137 |
|
|
|
1138 |
|
|
return(o_vect);
|
1139 |
|
|
|
1140 |
|
|
end u_resize_l;
|
1141 |
|
|
|
1142 |
|
|
------------------------------------------------------------------------------------
|
1143 |
|
|
-- Bit Reverses the input vector
|
1144 |
|
|
------------------------------------------------------------------------------------
|
1145 |
|
|
|
1146 |
|
|
function u_reverse(in_vect : unsigned) return unsigned is
|
1147 |
|
|
variable i : integer;
|
1148 |
|
|
variable o_vect : unsigned(in_vect'length-1 downto 0);
|
1149 |
|
|
|
1150 |
|
|
begin
|
1151 |
|
|
|
1152 |
|
|
for i in in_vect'length-1 downto 0 loop
|
1153 |
|
|
o_vect(in_vect'length-1-i) := in_vect(i);
|
1154 |
|
|
end loop;
|
1155 |
|
|
|
1156 |
|
|
return(o_vect);
|
1157 |
|
|
|
1158 |
|
|
end u_reverse;
|
1159 |
|
|
|
1160 |
|
|
------------------------------------------------------------------------------------
|
1161 |
|
|
--
|
1162 |
|
|
------------------------------------------------------------------------------------
|
1163 |
|
|
|
1164 |
|
|
function str2u(in_string : string; out_size:integer) return unsigned is
|
1165 |
|
|
|
1166 |
|
|
variable uval : unsigned(out_size-1 downto 0);
|
1167 |
|
|
variable nibble : unsigned(3 downto 0);
|
1168 |
|
|
begin
|
1169 |
|
|
uval := (others=>'0');
|
1170 |
|
|
for j in in_string'range loop
|
1171 |
|
|
uval(uval'length-1 downto 4) := uval(uval'length-5 downto 0);
|
1172 |
|
|
uval(3 downto 0) := char2u(in_string(j));
|
1173 |
|
|
end loop;
|
1174 |
|
|
return uval;
|
1175 |
|
|
end str2u;
|
1176 |
|
|
|
1177 |
|
|
------------------------------------------------------------------------------------
|
1178 |
|
|
--
|
1179 |
|
|
------------------------------------------------------------------------------------
|
1180 |
|
|
|
1181 |
|
|
function str2s(in_string : string; out_size:integer) return signed is
|
1182 |
|
|
|
1183 |
|
|
variable uval : signed(out_size-1 downto 0);
|
1184 |
|
|
variable nibble : signed(3 downto 0);
|
1185 |
|
|
begin
|
1186 |
|
|
uval := (others=>'0');
|
1187 |
|
|
for j in in_string'range loop
|
1188 |
|
|
uval(uval'length-1 downto 4) := uval(uval'length-5 downto 0);
|
1189 |
|
|
uval(3 downto 0) := signed(char2u(in_string(j)));
|
1190 |
|
|
end loop;
|
1191 |
|
|
return uval;
|
1192 |
|
|
end str2s;
|
1193 |
|
|
|
1194 |
|
|
------------------------------------------------------------------------------------
|
1195 |
|
|
-- Power Function for naturals
|
1196 |
|
|
------------------------------------------------------------------------------------
|
1197 |
|
|
|
1198 |
|
|
function "**"(in_a : natural; in_b : natural) return natural is
|
1199 |
|
|
variable i : natural;
|
1200 |
|
|
variable o : natural;
|
1201 |
|
|
|
1202 |
|
|
begin
|
1203 |
|
|
|
1204 |
|
|
-- Coded with a for loop: works in simulation, but Synplify will not synthesize.
|
1205 |
|
|
-- if (in_b=0) then
|
1206 |
|
|
-- o := 1;
|
1207 |
|
|
-- else
|
1208 |
|
|
-- o := in_a;
|
1209 |
|
|
-- if (in_b>1) then
|
1210 |
|
|
-- for i in 2 to in_b loop
|
1211 |
|
|
-- o := o * in_a;
|
1212 |
|
|
-- end loop;
|
1213 |
|
|
-- end if;
|
1214 |
|
|
-- end if;
|
1215 |
|
|
-- return(o);
|
1216 |
|
|
|
1217 |
|
|
if (in_b=0) then
|
1218 |
|
|
o := 1;
|
1219 |
|
|
else
|
1220 |
|
|
o := in_a;
|
1221 |
|
|
i := 1;
|
1222 |
|
|
while (i<in_b) loop
|
1223 |
|
|
o := o * in_a;
|
1224 |
|
|
i := i+1;
|
1225 |
|
|
end loop;
|
1226 |
|
|
end if;
|
1227 |
|
|
return(o);
|
1228 |
|
|
|
1229 |
|
|
end;
|
1230 |
|
|
|
1231 |
|
|
------------------------------------------------------------------------------------
|
1232 |
|
|
-- Function for 2^(natural)
|
1233 |
|
|
------------------------------------------------------------------------------------
|
1234 |
|
|
|
1235 |
|
|
function pow_2_u(in_a : natural; out_size:integer) return unsigned is
|
1236 |
|
|
variable i : natural;
|
1237 |
|
|
variable j : natural;
|
1238 |
|
|
variable o : unsigned(out_size-1 downto 0);
|
1239 |
|
|
|
1240 |
|
|
begin
|
1241 |
|
|
|
1242 |
|
|
j := in_a;
|
1243 |
|
|
o := to_unsigned(1,o'length);
|
1244 |
|
|
for i in 0 to out_size-1 loop
|
1245 |
|
|
if (j>0) then
|
1246 |
|
|
o := o(out_size-2 downto 0) & '0';
|
1247 |
|
|
j := j-1;
|
1248 |
|
|
end if;
|
1249 |
|
|
end loop;
|
1250 |
|
|
return(o);
|
1251 |
|
|
|
1252 |
|
|
end;
|
1253 |
|
|
|
1254 |
|
|
------------------------------------------------------------------------------------
|
1255 |
|
|
-- A sort of "barrel shifter." Produces the ASR by in_a of the input...
|
1256 |
|
|
------------------------------------------------------------------------------------
|
1257 |
|
|
|
1258 |
|
|
function asr_function(in_vect : signed; in_a : natural) return signed is
|
1259 |
|
|
variable i : natural;
|
1260 |
|
|
variable j : natural;
|
1261 |
|
|
variable o_vect : signed(in_vect'length-1 downto 0);
|
1262 |
|
|
|
1263 |
|
|
begin
|
1264 |
|
|
|
1265 |
|
|
o_vect := in_vect;
|
1266 |
|
|
j := in_a;
|
1267 |
|
|
for i in 0 to in_vect'length-1 loop -- Now loop to fill in the actual results
|
1268 |
|
|
if (j>0) then
|
1269 |
|
|
o_vect := o_vect(o_vect'length-1) & o_vect(o_vect'length-1 downto 1);
|
1270 |
|
|
j := j-1;
|
1271 |
|
|
end if;
|
1272 |
|
|
end loop;
|
1273 |
|
|
|
1274 |
|
|
return(o_vect);
|
1275 |
|
|
|
1276 |
|
|
end asr_function;
|
1277 |
|
|
|
1278 |
|
|
------------------------------------------------------------------------------------
|
1279 |
|
|
--
|
1280 |
|
|
------------------------------------------------------------------------------------
|
1281 |
|
|
|
1282 |
|
|
end convert_pack;
|
1283 |
|
|
|
1284 |
|
|
|
1285 |
|
|
|