?? corepwm_pkg.vhd
字號:
variable vs: std_logic;
variable tnow: integer;
variable DISP_CORRECT: boolean;
constant uline_str2: string(1 to 77) :=
"_____________________________________________________________________________";
constant pound_str2: string(1 to 77) :=
"#############################################################################";
begin
DISP_CORRECT:= false;
tnow := NOW / 1 ns;
nomatch := false;
if (d /= to_stdulogic(v)) then
nomatch := true;
end if;
vs := to_stdulogic(v);
if (nomatch) then
printf(" ");
printf("%s",fmt(pound_str2));
printf("ERROR!!! Mismatch on signal %s",fmt(sig_name));
printf("At time: %0d ns",fmt(tnow));
printf("Expected value was: 0x%0x, observed value is: 0x%0x",
fmt(vs)&fmt(d));
printf("%s",fmt(pound_str2));
printf(" ");
ERRCNT := ERRCNT + 1;
elsif (DISP_CORRECT) then
printf("%s",fmt(uline_str2)); printf(" ");
printf("CORRECT: match on signal %s",fmt(sig_name));
printf("At time: %0d ns",fmt(tnow));
printf("Expected value was: 0x%0x, observed value is: 0x%0x",
fmt(vs)&fmt(d));
end if;
end checksig;
------------------------------------------------------------------------
-- Check value of signal (expected output) & print message if mis-match
-- (vector version)
------------------------------------------------------------------------
procedure checksig (
d: std_logic_vector;
sig_name: string;
v: bit_vector;
ERRCNT: inout integer) is
variable nomatch: boolean;
variable tnow: integer;
variable v_copy: bit_vector(d'range);
variable vs: std_logic_vector(d'range);
variable DISP_CORRECT: boolean;
constant uline_str2: string(1 to 77) :=
"_____________________________________________________________________________";
constant pound_str2: string(1 to 77) :=
"#############################################################################";
begin
DISP_CORRECT:= false;
-- DISP_CORRECT:= true;
tnow := NOW / 1 ns;
v_copy := v;
nomatch := false;
for i in d'range loop
vs(i) := to_stdulogic(v_copy(i));
end loop;
for i in d'range loop
if (d(i) /= vs(i)) then
nomatch := true;
end if;
end loop;
if (nomatch) then
printf(" ");
printf("%s",fmt(pound_str2));
printf("ERROR!!! Mismatch on signal %s",fmt(sig_name));
printf("At time: %0d ns",fmt(tnow));
printf("Expected value was: 0x%0x, observed value is: 0x%0x",
fmt(vs)&fmt(d));
printf("%s",fmt(pound_str2));
printf(" ");
ERRCNT := ERRCNT + 1;
elsif (DISP_CORRECT) then
printf("%s",fmt(uline_str2)); printf(" ");
printf("CORRECT: match on signal %s",fmt(sig_name));
printf("At time: %0d ns",fmt(tnow));
printf("Expected value was: 0x%0x, observed value is: 0x%0x",
fmt(vs)&fmt(d));
end if;
end checksig;
-- small function to convert std_logic and std_logic_vector to integer
-- Note: only good for vectors < 32 bits!
function sl2int (s: std_logic_vector) return integer is
variable i: integer;
begin
i := 0;
for j in s'range loop
if (s(j) = '1') then
i := i + (2 ** j);
end if;
end loop;
return i;
end sl2int;
function sl2int (s: std_logic) return integer is
variable i: integer;
begin
if (s = '1') then
i := 1;
else
i := 0;
end if;
return i;
end sl2int;
-- small function to convert integer to std_logic_vector
function int2slv (val: in integer; len: in integer) return std_logic_vector is
variable rtn : std_logic_vector(len-1 downto 0) := (others => '0');
variable num : integer := val;
variable r : integer;
begin
for i in 0 to len-1 loop
r := num rem 2;
num := num/2;
if (r = 1) then
rtn(i) := '1';
else
rtn(i) := '0';
end if;
end loop;
return(rtn);
end int2slv;
-- small function to convert std_logic values to either 'X','0','1', or 'Z'
function sl2x01z(s: std_logic) return std_logic is
variable sl: std_logic;
begin
case s is
when 'U' => sl:= 'X';
when 'X' => sl:= 'X';
when '0' => sl:= '0';
when '1' => sl:= '1';
when 'Z' => sl:= 'Z';
when 'W' => sl:= 'X';
when 'L' => sl:= '0';
when 'H' => sl:= '1';
when '-' => sl:= 'X';
when others => sl:= 'X';
end case;
return sl;
end sl2x01z;
-- small function to convert vlog values (string) to either 'X','0','1', or 'Z'
--function vlg2x01z(s: character) return std_logic is
function vlg2x01z(s: string(1 to 1)) return std_logic is
variable sl: std_logic;
begin
case s is
when "x" => sl:= 'X';
when "0" => sl:= '0';
when "1" => sl:= '1';
when "z" => sl:= 'Z';
when others => sl:= 'X';
end case;
return sl;
end vlg2x01z;
-- small function to convert std_logic_vector values to 'X','0','1', or 'Z'
function slv2x01z(s: std_logic_vector) return std_logic_vector is
variable sl: std_logic;
variable slv: std_logic_vector(s'range);
begin
for i in s'range loop
slv(i):= sl2x01z(s(i));
end loop;
return slv;
end slv2x01z;
---------------------------------------------------------------------
-- small function to convert hex character to std_logic values
function hex2sl(s: character) return std_logic is
variable sl: std_logic;
begin
case s is
when '0' => sl:= '0';
when '1' => sl:= '1';
when '2' => sl:= 'L';
when '3' => sl:= 'H';
when '4' => sl:= 'W';
when '5' => sl:= 'Z';
when '6' => sl:= 'U';
when '7' => sl:= 'X';
when '8' => sl:= '-';
when others => sl:= 'X';
end case;
return sl;
end hex2sl;
-- small function to convert hex string to std_logic_vector values
function hexv2slv(s: string) return std_logic_vector is
variable sl: std_logic;
variable c: character;
variable slv: std_logic_vector(s'range);
begin
for i in s'range loop
slv(i):= hex2sl(s(i));
end loop;
return slv;
end hexv2slv;
-- small function to convert hex character to std_logic values
function ev2sl(e: evbit) return std_logic is
variable sl: std_logic;
begin
case e is
when '0' => sl:= '0';
when '1' => sl:= '1';
when '2' => sl:= 'L';
when '3' => sl:= 'H';
when '4' => sl:= 'W';
when '5' => sl:= 'Z';
when '6' => sl:= 'U';
when '7' => sl:= 'X';
when '8' => sl:= '-';
when others => sl:= 'X';
end case;
return sl;
end ev2sl;
-- small function to convert hex string to std_logic_vector values
function evv2slv(e: evbyte) return std_logic_vector is
variable sl: std_logic;
variable slv: std_logic_vector(7 downto 0);
begin
for i in 7 downto 0 loop
slv(i):= ev2sl(e(i));
end loop;
return slv;
end evv2slv;
-- small function to convert character to evbit
function to_evbit(c: character) return evbit is
variable e: evbit;
begin
case c is
when '0' => e:= '0';
when '1' => e:= '1';
when '2' => e:= '2';
when '3' => e:= '3';
when '4' => e:= '4';
when '5' => e:= '5';
when '6' => e:= '6';
when '7' => e:= '7';
when '8' => e:= '8';
when others => e:= '7';
end case;
return e;
end to_evbit;
---------------------------------------------------------------------
-- small function to do hex numbers for std_logic_vector
function hx (b: bit_vector)
return std_logic_vector is
begin
return to_stdlogicvector(b);
end;
---------------------------------------------------------------------
-- Emulate task of cpu writing data to peripheral (IP macro)
---------------------------------------------------------------------
procedure cpu_wr (
constant addr: in bit_vector(7 downto 0);
constant d: in bit_vector(7 downto 0);
signal clk: in std_logic;
signal a: out std_logic_vector (7 downto 0);
signal do: out std_logic_vector (7 downto 0);
signal sel: out std_logic;
signal wr: out std_logic;
signal en: out std_logic
) is
begin
wait until clk = '0';
a <= to_stdlogicvector(addr(7 downto 0));
sel <= '1';
wr <= '1';
en <= '0';
do <= to_stdlogicvector(d);
wait until clk = '1';
wait until clk = '0';
en <= '1';
wait until clk = '1';
wait until clk = '0';
a <= (others => '0');
sel <= '0';
wr <= '0';
en <= '0';
do <= (others => '0');
wait until clk = '0';
wait until clk = '1';
wait until clk = '0';
end cpu_wr;
---------------------------------------------------------------------
-- Emulate task of cpu reading data from peripheral (IP macro)
---------------------------------------------------------------------
procedure cpu_rd (
-- only 2 LSB bits used out of 8 legacy
-- constant addr: in bit_vector(7 downto 0);
constant addr: in bit_vector(7 downto 0);
constant d: in bit_vector(7 downto 0);
signal clk: in std_logic;
signal a: out std_logic_vector (7 downto 0);
signal di: in std_logic_vector (7 downto 0);
signal sel: out std_logic;
signal wr: out std_logic;
signal en: out std_logic;
simerrors: inout integer
) is
variable dvar: std_logic_vector(7 downto 0);
begin
wait until clk = '0';
a <= to_stdlogicvector(addr(7 downto 0));
sel <= '1';
wr <= '0';
en <= '0';
wait until clk = '1';
wait until clk = '0';
en <= '1';
wait until clk = '1';
wait until clk = '0';
dvar := di;
checksig(dvar,"CPU Data Bus",d,simerrors);
a <= (others => '0');
sel <= '0';
wr <= '0';
en <= '0';
wait until clk = '0';
wait until clk = '1';
wait until clk = '0';
end cpu_rd;
end corepwm_pkg;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -