-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebugtools.vhdl
More file actions
93 lines (77 loc) · 2.65 KB
/
debugtools.vhdl
File metadata and controls
93 lines (77 loc) · 2.65 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
library ieee;
use Std.TextIO.all;
use ieee.STD_LOGIC_1164.all;
use ieee.numeric_std.all;
package debugtools is
function to_string(sv: Std_Logic_Vector) return string;
function to_hstring(sv: Std_Logic_Vector) return string;
function to_hstring(sv: unsigned) return string;
function to_std_Logic(L: BOOLEAN) return std_logic;
procedure HWRITE(L:inout LINE; VALUE:in BIT_VECTOR;
JUSTIFIED:in SIDE := RIGHT; FIELD:in WIDTH := 0);
end debugtools;
package body debugtools is
procedure HWRITE(L:inout LINE; VALUE:in BIT_VECTOR;
JUSTIFIED:in SIDE := RIGHT; FIELD:in WIDTH := 0) is
variable quad: bit_vector(0 to 3);
constant ne: integer := (value'length+3)/4;
constant displaybits: integer := ne*4;
constant inputbits: integer := value'length;
constant emptybits: integer := displaybits - inputbits;
variable bv: bit_vector(0 to value'length+4) := (others => '0');
variable s: string(1 to ne);
begin
bv(emptybits to (emptybits+value'length-1)) := value;
for i in 0 to ne-1 loop
quad := bv(4*i to 4*i+3);
case quad is
when x"0" => s(i+1) := '0';
when x"1" => s(i+1) := '1';
when x"2" => s(i+1) := '2';
when x"3" => s(i+1) := '3';
when x"4" => s(i+1) := '4';
when x"5" => s(i+1) := '5';
when x"6" => s(i+1) := '6';
when x"7" => s(i+1) := '7';
when x"8" => s(i+1) := '8';
when x"9" => s(i+1) := '9';
when x"A" => s(i+1) := 'A';
when x"B" => s(i+1) := 'B';
when x"C" => s(i+1) := 'C';
when x"D" => s(i+1) := 'D';
when x"E" => s(i+1) := 'E';
when x"F" => s(i+1) := 'F';
end case;
end loop;
write(L, s, JUSTIFIED, FIELD);
end HWRITE;
function to_string(sv: Std_Logic_Vector) return string is
use Std.TextIO.all;
variable bv: bit_vector(sv'range) := to_bitvector(sv);
variable lp: line;
begin
write(lp, bv);
return lp.all;
end;
function to_hstring(sv: Std_Logic_Vector) return string is
use Std.TextIO.all;
variable bv: bit_vector(sv'range) := to_bitvector(sv);
variable lp: line;
begin
hwrite(lp, bv);
return lp.all;
end;
function to_hstring(sv: unsigned) return string is
use Std.TextIO.all;
begin
return to_hstring(std_logic_vector(sv));
end;
function to_std_Logic(L: BOOLEAN) return std_logic is
begin
if l then
return('1');
else
return('0');
end if;
end function to_std_Logic;
end debugtools;