common.vhd
来自「SDRAM IPCore控制程序源代码。 请问有无usb原码」· VHDL 代码 · 共 86 行
VHD
86 行
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
package common is
constant YES : std_logic := '1';
constant NO : std_logic := '0';
constant HI : std_logic := '1';
constant LO : std_logic := '0';
constant ONE : std_logic := '1';
constant ZERO : std_logic := '0';
-- convert a Boolean to a std_logic
function boolean2stdlogic(b : in boolean) return std_logic;
-- find the base-2 logarithm of a number
function log2(v : in natural) return natural;
-- select one of two integers based on a Boolean
function int_select(s : in boolean; a : in integer; b : in integer) return integer;
-- select one of two reals based on a Boolean
function real_select(s : in boolean; a : in real; b : in real) return real;
end package common;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
package body common is
-- convert a Boolean to a std_logic
function boolean2stdlogic(b : in boolean) return std_logic is
variable s : std_logic;
begin
if b then
s := '1';
else
s := '0';
end if;
return s;
end function boolean2stdlogic;
-- find the base 2 logarithm of a number
function log2(v : in natural) return natural is
variable n : natural;
variable logn : natural;
begin
n := 1;
for i in 0 to 128 loop
logn := i;
exit when (n >= v);
n := n * 2;
end loop;
return logn;
end function log2;
-- select one of two integers based on a Boolean
function int_select(s : in boolean; a : in integer; b : in integer) return integer is
begin
if s then
return a;
else
return b;
end if;
return a;
end function int_select;
-- select one of two reals based on a Boolean
function real_select(s : in boolean; a : in real; b : in real) return real is
begin
if s then
return a;
else
return b;
end if;
return a;
end function real_select;
end package body common;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?