--------------------------------------------------------------------
|
--------------------------------------------------------------------
|
-- Company : XESS Corp.
|
-- Company : XESS Corp.
|
-- Engineer : Dave Vanden Bout
|
-- Engineer : Dave Vanden Bout
|
-- Creation Date : 05/17/2005
|
-- Creation Date : 05/17/2005
|
-- Copyright : 2005, XESS Corp
|
-- Copyright : 2005, XESS Corp
|
-- Tool Versions : WebPACK 6.3.03i
|
-- Tool Versions : WebPACK 6.3.03i
|
--
|
--
|
-- Description:
|
-- Description:
|
-- Miscellaneous VHDL constants and functions
|
-- Miscellaneous VHDL constants and functions
|
--
|
--
|
-- Revision:
|
-- Revision:
|
-- 1.0.0
|
-- 1.0.0
|
--
|
--
|
-- Additional Comments:
|
-- Additional Comments:
|
-- 1.1.0:
|
-- 1.1.0:
|
-- Added int_select() and real_select functions.
|
-- Added int_select() and real_select functions.
|
-- 1.0.0:
|
-- 1.0.0:
|
-- Initial release.
|
-- Initial release.
|
--
|
--
|
-- License:
|
-- License:
|
-- This code can be freely distributed and modified as long as
|
-- This code can be freely distributed and modified as long as
|
-- this header is not removed.
|
-- this header is not removed.
|
--------------------------------------------------------------------
|
--------------------------------------------------------------------
|
|
|
|
|
|
|
library IEEE;
|
library IEEE;
|
use IEEE.std_logic_1164.all;
|
use IEEE.std_logic_1164.all;
|
use IEEE.numeric_std.all;
|
use IEEE.numeric_std.all;
|
|
|
package common is
|
package common is
|
|
|
constant YES : std_logic := '1';
|
constant YES : std_logic := '1';
|
constant NO : std_logic := '0';
|
constant NO : std_logic := '0';
|
constant HI : std_logic := '1';
|
constant HI : std_logic := '1';
|
constant LO : std_logic := '0';
|
constant LO : std_logic := '0';
|
constant ONE : std_logic := '1';
|
constant ONE : std_logic := '1';
|
constant ZERO : std_logic := '0';
|
constant ZERO : std_logic := '0';
|
-- convert a Boolean to a std_logic
|
-- convert a Boolean to a std_logic
|
function boolean2stdlogic(b : in boolean) return std_logic;
|
function boolean2stdlogic(b : in boolean) return std_logic;
|
-- find the base-2 logarithm of a number
|
-- find the base-2 logarithm of a number
|
function log2(v : in natural) return natural;
|
function log2(v : in natural) return natural;
|
-- select one of two integers based on a Boolean
|
-- select one of two integers based on a Boolean
|
function int_select(s : in boolean; a : in integer; b : in integer) return integer;
|
function int_select(s : in boolean; a : in integer; b : in integer) return integer;
|
-- select one of two reals based on a Boolean
|
-- select one of two reals based on a Boolean
|
function real_select(s : in boolean; a : in real; b : in real) return real;
|
function real_select(s : in boolean; a : in real; b : in real) return real;
|
|
|
end package common;
|
end package common;
|
|
|
|
|
|
|
library IEEE;
|
library IEEE;
|
use IEEE.std_logic_1164.all;
|
use IEEE.std_logic_1164.all;
|
use IEEE.numeric_std.all;
|
use IEEE.numeric_std.all;
|
|
|
|
|
package body common is
|
package body common is
|
|
|
-- convert a Boolean to a std_logic
|
-- convert a Boolean to a std_logic
|
function boolean2stdlogic(b : in boolean) return std_logic is
|
function boolean2stdlogic(b : in boolean) return std_logic is
|
variable s : std_logic;
|
variable s : std_logic;
|
begin
|
begin
|
if b then
|
if b then
|
s := '1';
|
s := '1';
|
else
|
else
|
s := '0';
|
s := '0';
|
end if;
|
end if;
|
return s;
|
return s;
|
end function boolean2stdlogic;
|
end function boolean2stdlogic;
|
|
|
-- find the base 2 logarithm of a number
|
-- find the base 2 logarithm of a number
|
function log2(v : in natural) return natural is
|
function log2(v : in natural) return natural is
|
variable n : natural;
|
variable n : natural;
|
variable logn : natural;
|
variable logn : natural;
|
begin
|
begin
|
n := 1;
|
n := 1;
|
for i in 0 to 128 loop
|
for i in 0 to 128 loop
|
logn := i;
|
logn := i;
|
exit when (n >= v);
|
exit when (n >= v);
|
n := n * 2;
|
n := n * 2;
|
end loop;
|
end loop;
|
return logn;
|
return logn;
|
end function log2;
|
end function log2;
|
|
|
-- select one of two integers based on a Boolean
|
-- select one of two integers based on a Boolean
|
function int_select(s : in boolean; a : in integer; b : in integer) return integer is
|
function int_select(s : in boolean; a : in integer; b : in integer) return integer is
|
begin
|
begin
|
if s then
|
if s then
|
return a;
|
return a;
|
else
|
else
|
return b;
|
return b;
|
end if;
|
end if;
|
return a;
|
return a;
|
end function int_select;
|
end function int_select;
|
|
|
-- select one of two reals based on a Boolean
|
-- select one of two reals based on a Boolean
|
function real_select(s : in boolean; a : in real; b : in real) return real is
|
function real_select(s : in boolean; a : in real; b : in real) return real is
|
begin
|
begin
|
if s then
|
if s then
|
return a;
|
return a;
|
else
|
else
|
return b;
|
return b;
|
end if;
|
end if;
|
return a;
|
return a;
|
end function real_select;
|
end function real_select;
|
|
|
end package body common;
|
end package body common;
|
|
|