?? corepwm_pkg.vhd
字號(hào):
fm.f_integer := x;
return(fm);
end fmt;
function fmt ( x : std_logic_vector) return T_FMT is
variable fm : T_FMT;
begin
fm.f_type := VECT;
fm.f_vector(x'length-1 downto 0) := x;
fm.f_length := x'length;
return(fm);
end fmt;
function fmt ( x : string ) return T_FMT is
variable fm : T_FMT;
begin
fm.f_type := STRG;
fm.f_string(x'range) := x;
if x'length+1<MAXSTRLEN then
fm.f_string(x'length+1) := NUL;
end if;
fm.f_length := x'length;
return(fm);
end fmt;
function fmt ( x : std_logic) return T_FMT is
variable fm : T_FMT;
variable x1 : std_logic_vector ( 0 downto 0);
begin
x1(0) := x;
fm.f_type := VECT;
fm.f_vector(x1'length-1 downto 0) := x1;
fm.f_length := x1'length;
return(fm);
end fmt;
---------------------------------------------------------------------------
-- The Main Print Routine
--
procedure printf( str : STRING;
Params : T_FMT_ARRAY ) is
file FSTR : TEXT is out "STD_OUTPUT";
variable ll : LINE;
variable str1,pstr : STRING (1 to MAXSTRLEN);
variable ip,op,pp,iplen : INTEGER;
variable numlen : INTEGER;
variable zeros : BOOLEAN;
variable more : BOOLEAN;
variable intval : INTEGER;
variable vectval: QWORD;
variable len : INTEGER;
variable ftype : T_NUMTYPE;
variable tnow : INTEGER;
begin
iplen := str'length;
ip:=1; op:=0; pp:=params'low;
while ip<= iplen and str(ip)/=NUL loop
if str(ip) = '%' then
more:=TRUE;
numlen:=0; zeros:=FALSE;
while more loop
more:=FALSE;
ip:=ip+1;
ftype := params(pp).f_type;
intval := params(pp).f_integer;
vectval:= params(pp).f_vector;
len := params(pp).f_length;
case str(ip) is
when '0' => ZEROS:=TRUE;
more:=TRUE;
when '1' to '9' =>
numlen:= 10* numlen + character'pos(str(ip))-48;
more := TRUE;
when '%' => pstr := strcopy("%");
when 'd' => case ftype is
when INT => pstr :=
inttostr(intval,10,numlen,zeros);
when VECT => if is01(vectval,len) then
intval:=
conv_integer(vectval(len-1 downto 0));
pstr :=
inttostr(intval,10,numlen,zeros);
end if;
when others => pstr :=
strcopy("INVALID PRINTF d:" & str);
end case;
pp:=pp+1;
when 't' => tnow := NOW / 1 ns;
pstr := inttostr(tnow,10,numlen,zeros);
when 'h' => case ftype is
when INT => pstr :=
inttostr(intval,16,numlen,zeros);
when VECT => if is01(vectval,len) then
intval:=
conv_integer(vectval(len-1 downto 0));
pstr :=
inttostr(intval,16,numlen,zeros);
end if;
when others => pstr :=
strcopy("INVALID PRINTF h:" & str);
end case;
pp:=pp+1;
when 'b' => case ftype is
when INT => vectval := ( others => '0');
vectval(31 downto 0) :=
conv_std_logic_vector(intval,32);
len:=1;
for i in 1 to 31 loop
if vectval(i)='1' then
len:=i;
end if;
end loop;
pstr :=
vecttostr(vectval,len,2,numlen,zeros);
when VECT => pstr :=
vecttostr(vectval,len,2,numlen,zeros);
when others => pstr :=
strcopy("INVALID PRINTF b:" & str);
end case;
pp:=pp+1;
when 'x' => case ftype is
when INT => pstr :=
inttostr(intval,16,numlen,zeros);
when VECT => pstr :=
vecttostr(vectval,len,16,numlen,zeros);
when others => pstr :=
strcopy("INVALID PRINTF x:" & str);
end case;
pp:=pp+1;
when 's' => case ftype is
when STRG => pstr:=params(pp).f_string;
when others => pstr :=
strcopy("INVALID PRINTF s:" & str);
end case;
pp:=pp+1;
when others => pstr := strcopy("ILLEGAL FORMAT");
assert FALSE
report "TEXTIO Processing Problem"
severity FAILURE;
end case;
end loop;
len := strlen(pstr);
for i in 1 to len loop
str1(op+i) := pstr(i);
end loop;
ip:=ip+1;
op:=op+len;
elsif str(ip)='\' then
case str(ip+1) is
when 'n' => str1(op+1):= NUL;
write( ll , str1 );
writeline( FSTR, ll);
op := 0; ip:=ip+1;
str1(op+1) := NUL;
when others =>
end case;
ip:=ip+1;
else
op:=op+1;
str1(op) := str(ip);
ip:=ip+1;
end if;
end loop;
if op>0 then
str1(op+1):=NUL;
write( ll , str1 );
writeline(FSTR, ll);
end if;
end printf;
procedure printf( str : STRING; params : T_FMT ) is
variable f_fmt : T_FMT_ARRAY ( 1 to 1);
begin
f_fmt(1) := params;
printf(str,f_fmt);
end printf;
procedure printf( str : STRING ) is
variable fm : T_FMT_ARRAY ( 1 to 1);
begin
fm(1).f_type := NONE;
printf(str,fm);
end printf;
procedure ifprintf( enable : BOOLEAN;
str : STRING;
Params : T_FMT_ARRAY ) is
begin
if enable then
printf(str,params);
end if;
end ifprintf;
procedure ifprintf( enable : BOOLEAN; str : STRING; params : T_FMT ) is
variable f_fmt : T_FMT_ARRAY ( 1 to 1);
begin
if enable then
f_fmt(1) := params;
printf(str,f_fmt);
end if;
end ifprintf;
procedure ifprintf( enable : BOOLEAN; str : STRING ) is
variable fm : T_FMT_ARRAY ( 1 to 1);
begin
if enable then
fm(1).f_type := NONE;
printf(str,fm);
end if;
end ifprintf;
---------------------------------------------------------------------------
-- The Main Print Routine Replicated to provide printf function
--
procedure fprintf( FSTR : out text;
str : STRING;
Params : T_FMT_ARRAY ) is
variable ll : LINE;
variable str1,pstr : STRING (1 to MAXSTRLEN);
variable ip,op,pp,iplen : INTEGER;
variable numlen : INTEGER;
variable zeros : BOOLEAN;
variable more : BOOLEAN;
variable intval : INTEGER;
variable vectval: QWORD;
variable len : INTEGER;
variable ftype : T_NUMTYPE;
begin
iplen := str'length;
ip:=1; op:=0; pp:=params'low;
while ip<= iplen and str(ip)/=NUL loop
if str(ip) = '%' then
more:=TRUE;
numlen:=0; zeros:=FALSE;
while more loop
more:=FALSE;
ip:=ip+1;
ftype := params(pp).f_type;
intval := params(pp).f_integer;
vectval:= params(pp).f_vector;
len := params(pp).f_length;
case str(ip) is
when '0' => ZEROS:=TRUE;
more:=TRUE;
when '1' to '9' =>
numlen:= 10* numlen + character'pos(str(ip))-48;
more := TRUE;
when '%' => pstr := strcopy("%");
when 'd' => case ftype is
when INT => pstr := inttostr(intval,10,numlen,zeros);
when VECT => if is01(vectval,len) then
intval:= conv_integer(vectval(len-1 downto 0));
pstr := inttostr(intval,10,numlen,zeros);
end if;
when others => pstr := strcopy("INVALID fprintf d:" & str);
end case;
pp:=pp+1;
when 'h' => case ftype is
when INT => pstr := inttostr(intval,16,numlen,zeros);
when VECT => if is01(vectval,len) then
intval:= conv_integer(vectval(len-1 downto 0));
pstr := inttostr(intval,16,numlen,zeros);
end if;
when others => pstr := strcopy("INVALID fprintf h:" & str);
end case;
pp:=pp+1;
when 'b' => case ftype is
when INT => vectval := ( others => '0');
vectval(31 downto 0) := conv_std_logic_vector(intval,32);
len:=1;
for i in 1 to 31 loop
if vectval(i)='1' then
len:=i;
end if;
end loop;
pstr := vecttostr(vectval,len,2,numlen,zeros);
when VECT => pstr := vecttostr(vectval,len,2,numlen,zeros);
when others => pstr := strcopy("INVALID fprintf b:" & str);
end case;
pp:=pp+1;
when 'x' => case ftype is
when INT => pstr := inttostr(intval,16,numlen,zeros);
when VECT => pstr := vecttostr(vectval,len,16,numlen,zeros);
when others => pstr := strcopy("INVALID fprintf x:" & str);
end case;
pp:=pp+1;
when 's' => case ftype is
when STRG => pstr:=params(pp).f_string;
when others => pstr := strcopy("INVALID fprintf s:" & str);
end case;
pp:=pp+1;
when others => pstr := strcopy("ILLEGAL FORMAT");
end case;
end loop;
len := strlen(pstr);
for i in 1 to len loop
str1(op+i) := pstr(i);
end loop;
ip:=ip+1;
op:=op+len;
elsif str(ip)='\' then
case str(ip+1) is
when 'n' => str1(op+1):= NUL;
write( ll , str1 );
writeline( FSTR, ll);
op := 0; ip:=ip+1;
str1(op+1) := NUL;
when others =>
end case;
ip:=ip+1;
else
op:=op+1;
str1(op) := str(ip);
ip:=ip+1;
end if;
end loop;
if op>0 then
str1(op+1):=NUL;
write( ll , str1 );
writeline(FSTR, ll);
end if;
end fprintf;
procedure fprintf( FSTR : out text; str : STRING; params : T_FMT ) is
variable f_fmt : T_FMT_ARRAY ( 1 to 1);
begin
f_fmt(1) := params;
fprintf(fstr,str,f_fmt);
end fprintf;
procedure fprintf( FSTR : out text; str : STRING ) is
variable fm : T_FMT_ARRAY ( 1 to 1);
begin
fm(1).f_type := NONE;
fprintf(fstr,str,fm);
end fprintf;
------------------------------------------------------------------------
-- Check value of signal (expected output) & print message if mis-match
-- (single-bit version)
------------------------------------------------------------------------
procedure checksig (
d: std_logic;
sig_name: string;
v: bit;
ERRCNT: inout integer) is
variable nomatch: boolean;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -