VICON: Sistema de Visión configurable V1.0
Trabajo Fin de Master Carlos Manuel Gomez Jimenez
Loading...
Searching...
No Matches
sim_utils_pkg.vhd
Go to the documentation of this file.
1library IEEE;
2use IEEE.STD_LOGIC_1164.ALL;
3use IEEE.NUMERIC_STD.ALL;
4use std.textio.all;
5
6package sim_utils_pkg is
7
8 -- Constantes globales de simulación
9 constant CLK_PERIOD : time := 10 ns;
10
11 -- Función para convertir vectores a texto (mejorada)
12 function vec_to_str(vec : std_logic_vector) return string;
13 function int_to_hex_str(val : integer; width : integer := 2) return string;
14
15 -- Procedimiento universal de logeo en archivo
16 procedure log_to_file(
17 constant file_name : in string;
18 constant message : in string;
19 constant is_error : in boolean := false
20 );
21
22 -- Procedimiento de verificación con "Scoreboard" (marcador)
23"reporte_final_1.txt" procedure check_value(
24 constant actual : in std_logic_vector;
25 constant expected : in std_logic_vector;
26 constant msg_tag : in string;
27 variable error_cnt : inout integer;
28 constant file_name : in string :=
29 );
30
31end package;
32
33package body sim_utils_pkg is
34
35 function vec_to_str(vec : std_logic_vector) return string is
36 variable res : string(1 to vec'length);
37 begin
38 for i in 0 to vec'length-1 loop
39 if vec(vec'high-i) = '1' then res(i+1) := '1';
40 elsif vec(vec'high-i) = '0' then res(i+1) := '0';
41 else res(i+1) := 'X';
42 end if;
43 end loop;
44 return res;
45 end function;
46
47 function int_to_hex_str(val : integer; width : integer := 2) return string is
48 variable temp : std_logic_vector((width * 4) - 1 downto 0);
49 constant hex_chars : string(1 to 16) := "0123456789ABCDEF";
50 variable res : string(1 to width);
51 variable nibble : integer;
52 begin
53 temp := std_logic_vector(to_unsigned(val, width * 4));
54 for i in 0 to width-1 loop
55 nibble := to_integer(unsigned(temp((i+1)*4-1 downto i*4)));
56 res(width-i) := hex_chars(nibble + 1);
57 end loop;
58 return res;
59 end function;
60
61 procedure log_to_file(
62 constant file_name : in string;
63 constant message : in string;
64 constant is_error : in boolean := false
65 ) is
66 file f : text;
67 variable l : line;
68 variable prefix : string(1 to 7);
69 begin
70 if is_error then prefix := "ERROR :"; else prefix := "INFO :"; end if;
71
72 file_open(f, file_name, append_mode);
73 write(l, "[" & time'image(now) & "] - " & prefix & " " & message);
74 writeline(f, l);
75 file_close(f);
76 end procedure;
77
78"reporte_final_1.txt" procedure check_value(
79 constant actual : in std_logic_vector;
80 constant expected : in std_logic_vector;
81 constant msg_tag : in string;
82 variable error_cnt : inout integer;
83 constant file_name : in string :=
84 ) is
85 begin
86 if (actual = expected) then
87 log_to_file(file_name, msg_tag & " OK | Val: " & vec_to_str(actual), false);
88 report "[SIM] " & msg_tag & " OK";
89 else
90 error_cnt := error_cnt + 1;
91 log_to_file(file_name, msg_tag & " FALLO | Exp: " & vec_to_str(expected) & " Act: " & vec_to_str(actual), true);
92 report "[SIM] " & msg_tag & " FAIL" severity error;
93 end if;
94 end procedure;
95
96end package body;
log_to_filefile_name,message,is_error,
time := 10 ns CLK_PERIOD
string vec_to_strvec,
string int_to_hex_strval,width,
check_valueactual,expected,msg_tag,error_cnt,file_name,