OpenCores
URL https://opencores.org/ocsvn/tdm/tdm/trunk

Subversion Repositories tdm

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 4 to Rev 5
    Reverse comparison

Rev 4 → Rev 5

/trunk/code/MEM_PKG.VHD
0,0 → 1,200
-------------------------------------------------------------------------------
-- Title : Memory Package
-- Project : Memory Cores
-------------------------------------------------------------------------------
-- File : mem_pkg.vhd
-- Author : Jamil Khatib <khatib@ieee.org>
-- Organization: OpenIPCore Project
-- Created : 2000/02/29
-- Last update: 2001/03/20
-- Platform :
-- Simulators : Modelsim 5.2EE / Windows98, NC-Sim/Linux
-- Synthesizers: Leonardo / Windows98
-- Target : Flex10K
-- Dependency : ieee.std_logic_1164
-- utility.tools_pkg
-------------------------------------------------------------------------------
-- Description: Memory Package
-------------------------------------------------------------------------------
-- Copyright (c) 2000 Jamil Khatib
--
-- This VHDL design file is an open design; you can redistribute it and/or
-- modify it and/or implement it under the terms of the Openip General Public
-- License as it is going to be published by the OpenIPCore Organization and
-- any coming versions of this license.
-- You can check the draft license at
-- http://www.openip.org/oc/license.html
 
-------------------------------------------------------------------------------
-- Revisions :
-- Revision Number : 1
-- Version : 0.1
-- Date : 29th Feb 2000
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : Created
--
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Revisions :
-- Revision Number : 2
-- Version : 0.2
-- Date : 29th Mar 2000
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : Memory components are added.
--
-------------------------------------------------------------------------------
-- Revisions :
-- Revision Number : 3
-- Version : 0.3
-- Date : 12 Jan 2001
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : Memory components updated
--
-------------------------------------------------------------------------------
-- Revisions :
-- Revision Number : 4
-- Version : 0.31
-- Date : 11 March 2001
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : FIFO component added
--
-------------------------------------------------------------------------------
-- Revisions :
-- Revision Number : 5
-- Version : 0.5
-- Date : 16 April 2001
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : WISHBONE components added
--
-------------------------------------------------------------------------------
-- $Log: not supported by cvs2svn $
-- Revision 1.1 2001/04/27 19:17:45 khatib
-- First stable release
--
-- Revision 1.4 2001/04/16 20:14:35 jamil
-- WishBone components added
--
-- Revision 1.3 2001/03/20 19:39:32 jamil
-- tools pkg bug fixed
--
-- Revision 1.2 2001/03/11 21:22:55 jamil
-- FIFO component added
--
-------------------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
 
library utility;
use utility.tools_pkg.all;
 
package mem_pkg is
 
constant ADD_WIDTH : integer := 8; -- Address width
constant WIDTH : integer := 4; -- Data width
-------------------------------------------------------------------------------
component dpmem_ent
generic (
USE_RESET : boolean;
USE_CS : boolean;
DEFAULT_OUT : std_logic;
CLK_DOMAIN : integer;
ADD_WIDTH : integer;
WIDTH : integer);
port (
W_clk : in std_logic;
R_clk : in std_logic;
reset : in std_logic;
W_add : in std_logic_vector(add_width -1 downto 0);
R_add : in std_logic_vector(add_width -1 downto 0);
Data_In : in std_logic_vector(WIDTH - 1 downto 0);
Data_Out : out std_logic_vector(WIDTH -1 downto 0);
WR : in std_logic;
RE : in std_logic);
end component;
-------------------------------------------------------------------------------
COMPONENT wb_dpmem
GENERIC (
ADD_WIDTH : INTEGER;
WIDTH : INTEGER;
CLK_DOMAIN : INTEGER);
PORT (
CLK_I_1 : IN STD_LOGIC;
CLK_I_2 : IN STD_LOGIC;
ADR_I_1 : IN STD_LOGIC_VECTOR(ADD_WIDTH-1 DOWNTO 0);
ADR_I_2 : IN STD_LOGIC_VECTOR(ADD_WIDTH-1 DOWNTO 0);
DAT_O : OUT STD_LOGIC_VECTOR(WIDTH -1 DOWNTO 0);
DAT_I : IN STD_LOGIC_VECTOR(WIDTH -1 DOWNTO 0);
WE_I_1 : IN STD_LOGIC;
WE_I_2 : IN STD_LOGIC;
ACK_O_1 : OUT STD_LOGIC;
ACK_O_2 : OUT STD_LOGIC;
STB_I_1 : IN STD_LOGIC;
STB_I_2 : IN STD_LOGIC);
END COMPONENT;
-------------------------------------------------------------------------------
component Spmem_ent
generic (
USE_RESET : boolean;
USE_CS : boolean;
DEFAULT_OUT : std_logic;
OPTION : integer;
ADD_WIDTH : integer;
WIDTH : integer);
port (
cs : std_logic;
clk : in std_logic;
reset : in std_logic;
add : in std_logic_vector(add_width -1 downto 0);
Data_In : in std_logic_vector(WIDTH -1 downto 0);
Data_Out : out std_logic_vector(WIDTH -1 downto 0);
WR : in std_logic);
end component;
 
-------------------------------------------------------------------------------
COMPONENT WB_spmem
GENERIC (
ADD_WIDTH : INTEGER;
WIDTH : INTEGER;
OPTION : INTEGER);
PORT (
DAT_O : OUT STD_LOGIC_VECTOR(ADD_WIDTH -1 DOWNTO 0);
DAT_I : IN STD_LOGIC_VECTOR(WIDTH -1 DOWNTO 0);
CLK_I : IN STD_LOGIC;
ADR_I : IN STD_LOGIC_VECTOR(ADD_WIDTH -1 DOWNTO 0);
STB_I : IN STD_LOGIC;
WE_I : IN STD_LOGIC;
ACK_O : OUT STD_LOGIC);
END COMPONENT;
-------------------------------------------------------------------------------
component FIFO_ent
generic (
ARCH : integer;
USE_CS : boolean;
DEFAULT_OUT : std_logic;
CLK_DOMAIN : integer;
MEM_CORE : integer;
BLOCK_SIZE : integer;
WIDTH : integer;
DEPTH : integer);
port (
rst_n : in std_logic;
Rclk : in std_logic;
Wclk : in std_logic;
cs : in std_logic;
Din : in std_logic_vector(WIDTH-1 downto 0);
Dout : out std_logic_vector(WIDTH-1 downto 0);
Re : in std_logic;
wr : in std_logic;
UsedCount : out std_logic_vector(log2(DEPTH)-1 downto 0);
RFull : out std_logic;
RHalf_full : out std_logic;
REmpty : out std_logic;
WFull : out std_logic;
WHalf_full : out std_logic;
WEmpty : out std_logic);
end component;
 
end mem_pkg;
 
-------------------------------------------------------------------------------
/trunk/code/SPMEM.VHD
0,0 → 1,378
-------------------------------------------------------------------------------
-- Title : Single port RAM
-- Project : Memory Cores
-------------------------------------------------------------------------------
-- File : spmem.vhd
-- Author : Jamil Khatib (khatib@ieee.org)
-- Organization: OpenIPCore Project
-- Created : 1999/5/14
-- Last update : 2000/12/19
-- Platform :
-- Simulators : Modelsim 5.3XE/Windows98
-- Synthesizers: Leonardo/WindowsNT
-- Target :
-- Dependency : ieee.std_logic_1164,ieee.std_logic_unsigned
-------------------------------------------------------------------------------
-- Description: Single Port memory
-------------------------------------------------------------------------------
-- Copyright (c) 2000 Jamil Khatib
--
-- This VHDL design file is an open design; you can redistribute it and/or
-- modify it and/or implement it after contacting the author
-- You can check the draft license at
-- http://www.opencores.org/OIPC/license.shtml
 
-------------------------------------------------------------------------------
-- Revisions :
-- Revision Number : 1
-- Version : 0.1
-- Date : 12 May 1999
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : Created
-- Known bugs :
-- To Optimze :
-------------------------------------------------------------------------------
-- Revisions :
-- Revision Number : 2
-- Version : 0.2
-- Date : 19 Dec 2000
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : General review
-- Two versions are now available with reset and without
-- Default output can can be defined
-- Known bugs :
-- To Optimze :
-------------------------------------------------------------------------------
-- Revisions :
-- Revision Number : 3
-- Version : 0.3
-- Date : 5 Jan 2001
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : Registered Read Address feature is added to make use of
-- Altera's FPGAs memory bits
-- This feature was added from Richard Herveille's
-- contribution and his memory core
-- Known bugs :
-- To Optimze :
-------------------------------------------------------------------------------
 
 
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
-------------------------------------------------------------------------------
-- Single port Memory core with reset
-- To make use of on FPGA memory bits do not use the RESET option
-- For Altera's FPGA you have to use also OPTION := 1
 
entity Spmem_ent is
generic ( USE_RESET : boolean := false; -- use system reset
USE_CS : boolean := false; -- use chip select signal
DEFAULT_OUT : std_logic := '1'; -- Default output
OPTION : integer := 1; -- 1: Registered read Address(suitable
-- for Altera's FPGAs
-- 0: non registered read address
ADD_WIDTH : integer := 3;
WIDTH : integer := 8);
 
port (
cs : std_logic; -- chip select
clk : in std_logic; -- write clock
reset : in std_logic; -- System Reset
add : in std_logic_vector(add_width -1 downto 0); -- Address
Data_In : in std_logic_vector(WIDTH -1 downto 0); -- input data
Data_Out : out std_logic_vector(WIDTH -1 downto 0); -- Output Data
WR : in std_logic); -- Read Write Enable
end Spmem_ent;
 
 
 
-------------------------------------------------------------------------------
-- This Architecture was tested on the ModelSim 5.2EE
-- The test vectors for model sim is included in vectors.do file
 
 
architecture spmem_beh of Spmem_ent is
 
 
 
type data_array is array (integer range <>) of std_logic_vector(WIDTH-1 downto 0);
-- Memory Type
signal data : data_array(0 to (2** add_width-1) ); -- Local data
 
 
-- FLEX/APEX devices require address to be registered with inclock for read operations
-- This signal is used only when OPTION = 1
signal regA : std_logic_vector( (add_width -1) downto 0);
procedure init_mem(signal memory_cell : inout data_array ) is
begin
 
for i in 0 to (2** add_width-1) loop
memory_cell(i) <= (others => '0');
end loop;
 
end init_mem;
 
begin -- spmem_beh
-------------------------------------------------------------------------------
-- Non Registered Read Address
-------------------------------------------------------------------------------
NON_REG : if OPTION = 0 generate
-------------------------------------------------------------------------------
-- Clocked Process with Reset
-------------------------------------------------------------------------------
Reset_ENABLED : if USE_RESET = true generate
-------------------------------------------------------------------------------
CS_ENABLED : if USE_CS = true generate
process (clk, reset)
 
begin -- PROCESS
-- activities triggered by asynchronous reset (active low)
 
if reset = '0' then
data_out <= (others => DEFAULT_OUT);
init_mem ( data);
 
-- activities triggered by rising edge of clock
elsif clk'event and clk = '1' then
if CS = '1' then
if WR = '0' then
data(conv_integer(add)) <= data_in;
data_out <= (others => DEFAULT_OUT);
else
data_out <= data(conv_integer(add));
end if;
else
data_out <= (others => DEFAULT_OUT);
end if;
 
end if;
 
end process;
end generate CS_ENABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
CS_DISABLED : if USE_CS = false generate
process (clk, reset)
 
 
begin -- PROCESS
-- activities triggered by asynchronous reset (active low)
 
if reset = '0' then
data_out <= (others => DEFAULT_OUT);
init_mem ( data);
 
-- activities triggered by rising edge of clock
elsif clk'event and clk = '1' then
if WR = '0' then
data(conv_integer(add)) <= data_in;
data_out <= (others => DEFAULT_OUT);
else
data_out <= data(conv_integer(add));
end if;
 
end if;
 
end process;
end generate CS_DISABLED;
 
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
end generate Reset_ENABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Clocked Process without Reset
-------------------------------------------------------------------------------
Reset_DISABLED : if USE_RESET = false generate
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
CS_ENABLED : if USE_CS = true generate
process (clk)
begin -- PROCESS
 
-- activities triggered by rising edge of clock
if clk'event and clk = '1' then
if cs = '1' then
if WR = '0' then
data(conv_integer(add)) <= data_in;
data_out <= (others => DEFAULT_OUT);
else
data_out <= data(conv_integer(add));
end if;
else
data_out <= (others => DEFAULT_OUT);
end if;
 
 
end if;
 
end process;
end generate CS_ENABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
CS_DISABLED : if USE_CS = false generate
process (clk)
begin -- PROCESS
 
-- activities triggered by rising edge of clock
if clk'event and clk = '1' then
if WR = '0' then
data(conv_integer(add)) <= data_in;
data_out <= (others => DEFAULT_OUT);
else
data_out <= data(conv_integer(add));
end if;
 
end if;
 
end process;
end generate CS_DISABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
end generate Reset_DISABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
end generate NON_REG;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
REG: if OPTION = 1 generate
-------------------------------------------------------------------------------
-- Clocked Process with Reset
-------------------------------------------------------------------------------
Reset_ENABLED : if USE_RESET = true generate
-------------------------------------------------------------------------------
CS_ENABLED : if USE_CS = true generate
process (clk, reset)
 
begin -- PROCESS
-- activities triggered by asynchronous reset (active low)
 
if reset = '0' then
data_out <= (others => DEFAULT_OUT);
init_mem ( data);
 
-- activities triggered by rising edge of clock
elsif clk'event and clk = '1' then
 
regA <= add;
if CS = '1' then
if WR = '0' then
data(conv_integer(add)) <= data_in;
data_out <= (others => DEFAULT_OUT);
else
data_out <= data(conv_integer(regA));
end if;
else
data_out <= (others => DEFAULT_OUT);
end if;
 
end if;
 
end process;
end generate CS_ENABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
CS_DISABLED : if USE_CS = false generate
process (clk, reset)
 
 
begin -- PROCESS
-- activities triggered by asynchronous reset (active low)
 
if reset = '0' then
data_out <= (others => DEFAULT_OUT);
init_mem ( data);
 
-- activities triggered by rising edge of clock
elsif clk'event and clk = '1' then
regA <= add;
if WR = '0' then
data(conv_integer(add)) <= data_in;
data_out <= (others => DEFAULT_OUT);
else
data_out <= data(conv_integer(regA));
end if;
 
end if;
 
end process;
end generate CS_DISABLED;
 
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
end generate Reset_ENABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Clocked Process without Reset
-------------------------------------------------------------------------------
Reset_DISABLED : if USE_RESET = false generate
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
CS_ENABLED : if USE_CS = true generate
process (clk)
begin -- PROCESS
 
-- activities triggered by rising edge of clock
if clk'event and clk = '1' then
 
regA <= add;
if cs = '1' then
if WR = '0' then
data(conv_integer(add)) <= data_in;
data_out <= (others => DEFAULT_OUT);
else
data_out <= data(conv_integer(regA));
end if;
else
data_out <= (others => DEFAULT_OUT);
end if;
 
 
end if;
 
end process;
end generate CS_ENABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
CS_DISABLED : if USE_CS = false generate
process (clk)
begin -- PROCESS
 
-- activities triggered by rising edge of clock
if clk'event and clk = '1' then
regA <= add;
if WR = '0' then
data(conv_integer(add)) <= data_in;
data_out <= (others => DEFAULT_OUT);
else
data_out <= data(conv_integer(regA));
end if;
 
end if;
 
end process;
end generate CS_DISABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
end generate Reset_DISABLED;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
end generate REG;
 
end spmem_beh;
-------------------------------------------------------------------------------
/trunk/code/tools_pkg.vhd
0,0 → 1,367
-------------------------------------------------------------------------------
-- Title : Tools Package
-- Project : Utility library
-------------------------------------------------------------------------------
-- File : tools.vhd
-- Author : Jamil Khatib (khatib@ieee.org)
-- Organization: OpenIPCore Project
-- Created : 2000/11/02
-- Last update : 2000/11/02
-- Platform :
-- Simulators : Modelsim 5.3XE/Windows98
-- Synthesizers:
-- Target :
-- Dependency : ieee.std_logic_1164
-- ieee.std_logic_arith
-- ieee.std_logic_unsigned
--
-------------------------------------------------------------------------------
-- Description: This package contains set of usefull functions and procedures
-------------------------------------------------------------------------------
-- Copyright (c) 2000 Jamil Khatib
--
-- This VHDL design file is an open design; you can redistribute it and/or
-- modify it and/or implement it after contacting the author
-- You can check the draft license at
-- http://www.opencores.org/OIPC/license.shtml
 
-------------------------------------------------------------------------------
-- Revisions :
-- Revision Number : 1
-- Version : 0.1
-- Date : 2nd Nov 2000
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : Created
--
---------- Revisions :
-- Revision Number : 2
-- Version : 0.2
-- Date : 14 Nov 2000
-- Modifier : Jamil Khatib (khatib@ieee.org)
-- Desccription : Shift functions and int_2_slv are added
-------------------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
 
 
package tools_pkg is
-------------------------------------------------------------------------------
-- Types
 
-- Memory arraye type of std_logic_vector
-- type std_memory_array_typ is array (integer range <>) of std_logic_vector(5 downto 0); --integer range <>);
 
-- Memory arraye type of std_ulogic_vector
-- type stdu_memory_array_typ is array (integer range <>) of std_ulogic_vector(integer range <>);
 
-- Sign magnitude numbers based on std_logic_vector (The msb represents the sign)
type SIGN_MAG_typ is array (natural range <>) of std_logic;
 
 
-----------------------------------------------------------------------------
-- Functions
 
 
function Log2( input : integer ) return integer; -- log2 functions
 
function slv_2_int ( SLV : std_logic_vector) return integer; --
--std_logic_vector
--to integer
 
function "+"(A, B : SIGN_MAG_typ) return SIGN_MAG_typ; -- sign_magnitude addition
 
function "-"(A, B : SIGN_MAG_typ) return SIGN_MAG_typ; -- sign_magnitude
-- subtraction (
-- based on
-- complement operations)
function LeftShift (
InReg : std_logic_vector; -- Input Register
ShSize : std_logic_vector) -- Shift Size
return std_logic_vector;
 
 
function RightShift (
InReg : std_logic_vector; -- Input register
ShSize : std_logic_vector) -- Shift Size
return std_logic_vector;
 
function int_2_slv (val, SIZE : integer) return std_logic_vector;
 
-----------------------------------------------------------------------------
end tools_pkg;
 
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
package body tools_pkg is
 
-----------------------------------------------------------------------------
function Log2(
input : integer ) -- input number
return integer is
variable temp, log : integer;
begin
 
assert input /= 0
report "Error : function missuse : log2(zero)"
severity failure;
temp := input;
log := 0;
while (temp /= 0) loop
temp := temp/2;
log := log+1;
end loop;
return log;
end log2;
-------------------------------------------------------------------------------
 
-- function LOG2(COUNT:INTEGER) return INTEGER is -- COUNT should be >0 variable TEMP:INTEGER;
-- variable TEMP : integer;
-- variable cnt : integer;
-- begin
-- cnt := COUNT;
--
-- TEMP:=0;
-- while COUNT>1 loop
-- TEMP:=TEMP+1;
-- cnt:=cnt/2;
-- end loop;
-- return TEMP;
-- end log2;
-------------------------------------------------------------------------------
function slv_2_int (
SLV : std_logic_vector) -- std_logic_vector to convert
return integer is
 
variable Result : integer := 0; -- conversion result
 
begin
for i in SLV'range loop
Result := Result * 2; -- shift the variable to left
case SLV(i) is
when '1' | 'H' => Result := Result + 1;
when '0' | 'L' => Result := Result + 0;
when others => null;
end case;
end loop;
 
return Result;
end;
-------------------------------------------------------------------------------
function "+"(A, B : SIGN_MAG_typ) return SIGN_MAG_typ is
variable VA, VB, VR : unsigned(A'length - 1 downto 0);
-- include the overflow bit
 
variable SA, SB, SR : std_logic;
variable TMP, RES : SIGN_MAG_typ(A'length - 1 downto 0);
 
variable casevar : std_logic_vector(1 downto 0);
variable std_tmp : std_logic_vector(A'length - 1 downto 0) := (others => '0');
 
begin
 
assert A'length = B'length
report "Error : length mismatch"
severity failure;
 
 
TMP := A;
SA := TMP(A'length - 1);
VA := '0' & unsigned(TMP(A'length - 2 downto 0));
TMP := B;
SB := TMP(B'length - 1);
VB := '0' & unsigned(TMP(B'length - 2 downto 0));
 
casevar := SA & SB;
case casevar is
when "00" |"11" =>
 
VR := VA + VB;
SR := SA;
 
when "01" =>
 
VR := VA - VB;
SR := VR(VR'length - 1);
 
if SR = '1' then
std_tmp(VR'length -2 downto 0) := std_logic_vector(VR(VR'length -2 downto 0));
std_tmp := not std_tmp;
 
VR(VR'length -2 downto 0) := unsigned(std_tmp(VR'length -2 downto 0));
 
VR(VR'length -2 downto 0) := VR(VR'length -2 downto 0) +1;
 
end if;
 
 
when "10" =>
VR := VB - VA;
SR := VR(VR'length - 1);
 
if SR = '1' then
std_tmp(VR'length -2 downto 0) := std_logic_vector(VR(VR'length -2 downto 0));
std_tmp := not std_tmp;
 
VR(VR'length -2 downto 0) := unsigned(std_tmp(VR'length -2 downto 0));
 
VR(VR'length -2 downto 0) := VR(VR'length -2 downto 0) +1;
 
end if;
 
when others => null;
end case;
 
 
RES := SIGN_MAG_typ(SR & VR(VR'length -2 downto 0));
 
return RES;
end "+";
 
-------------------------------------------------------------------------------
-- function "+"(A, B: SIGN_MAG) return SIGN_MAG is
-- variable VA, VB, VR: UNSIGNED(A'length - 2 downto 0);
-- variable SA, SB, SR: STD_LOGIC;
-- variable TMP, RES: SIGN_MAG(A'length - 1 downto 0);
--begin
-- assert A'length = B'length
-- report "Error"
-- severity FAILURE;
-- TMP := A;
-- SA := TMP(A'length - 1);
-- VA := UNSIGNED(TMP(A'length - 2 downto 0));
-- TMP := B;
-- SB := TMP(B'length - 1);
-- VB := UNSIGNED(TMP(B'length - 2 downto 0));
-- if (SA = SB) then
-- VR := VA + VB;
-- SR := SA;
-- elsif (VA >= VB) then
-- VR := VA - VB;
-- SR := SA;
-- else
-- VR := VB - VA;
-- SR := SB;
-- end if;
-- RES := SIGN_MAG(SR & VR);
-- return RES;
--end "+";
-------------------------------------------------------------------------------
function "-"(A, B : SIGN_MAG_typ) return SIGN_MAG_typ is
variable TMP : SIGN_MAG_typ(A'length - 1 downto 0);
begin
assert A'length = B'length
report "Error : length mismach"
severity failure;
TMP := B;
TMP(B'length - 1) := not TMP(B'length - 1);
return A + TMP;
end "-";
 
-------------------------------------------------------------------------------
-- purpose: combinational left shift register
function LeftShift (
InReg : std_logic_vector; -- Input Register
ShSize : std_logic_vector) -- Shift Size
return std_logic_vector is
 
constant REGSIZE : integer := InReg'length; -- Register Size
variable VarReg : std_logic_vector(InReg'length -1 downto 0);
-- Local storage for shifter
constant SHIFTSIZE : integer := log2(InReg'length); -- Shift size
begin
 
VarReg := inReg;
 
for i in 0 to SHIFTSIZE -2 loop
 
 
if ShSize(i) = '1' then
 
VarReg(REGSIZE -1 downto 0) := VarReg( (REGSIZE-(2**i)-1) downto 0) & ((2**i)-1 downto 0 => '0');
 
end if;
 
end loop; -- i
 
if ShSize(SHIFTSIZE-1) = '1' then
VarReg := (others => '0');
end if;
 
return VarReg;
 
end LeftShift;
 
-------------------------------------------------------------------------------
-- purpose: combinational Right shift register
function RightShift (
InReg : std_logic_vector; -- Input register
ShSize : std_logic_vector) -- Shift Size
return std_logic_vector is
 
constant REGSIZE : integer := InReg'length; -- Register Size
variable VarReg : std_logic_vector(InReg'length -1 downto 0);
-- Local storage for shifter
constant SHIFTSIZE : integer := log2(InReg'length); -- Shift size
 
begin -- RightShift
 
 
 
 
VarReg := inReg;
 
for i in 0 to SHIFTSIZE -2 loop
 
 
if ShSize(i) = '1' then
 
VarReg(REGSIZE -1 downto 0) := (REGSIZE-1 downto REGSIZE-(2**i) => '0') & VarReg(REGSIZE -1 downto (2**i));
 
end if;
 
end loop; -- i
 
if ShSize(SHIFTSIZE-1) = '1' then
VarReg := (others => '0');
end if;
 
return VarReg;
 
 
end RightShift;
-------------------------------------------------------------------------------
-- purpose: Integer to Std_logic_vector conversion
function int_2_slv (val, SIZE : integer) return std_logic_vector is
variable result : std_logic_vector(SIZE-1 downto 0);
variable l_val : integer := val;
begin
 
assert SIZE > 1
report "Error : function missuse : in_2_slv(val, negative size)"
severity failure;
 
for i in 0 to result'length-1 loop
 
if (l_val mod 2) = 0 then
 
result(i) := '0';
 
else
result(i) := '1';
 
end if;
 
l_val := l_val/2;
 
end loop;
 
return result;
 
end int_2_slv;
-------------------------------------------------------------------------------
end tools_pkg;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.