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

Subversion Repositories single_port

[/] [single_port/] [trunk/] [VHDL/] [pkg_image.vhd] - Diff between revs 2 and 15

Only display areas with differences | Details | Blame | View Log

Rev 2 Rev 15
-- $Author: rpaley_yid $
-- $Author: rpaley_yid $
-- $Date: 2003-01-14 21:48:10 $
-- $Date: 2003-01-14 21:48:10 $
-- $Header: /home/marcus/revision_ctrl_test/oc_cvs/cvs/single_port/VHDL/pkg_image.vhd,v 1.1.1.1 2003-01-14 21:48:10 rpaley_yid Exp $
-- $Header: /home/marcus/revision_ctrl_test/oc_cvs/cvs/single_port/VHDL/pkg_image.vhd,v 1.1.1.1 2003-01-14 21:48:10 rpaley_yid Exp $
-- $Locker
-- $Locker
-- $Revision: 1.1.1.1 $
-- $Revision: 1.1.1.1 $
-- $State: Exp $
-- $State: Exp $
 
 
-- Copyright (c) 1997 Ben Cohen.   All rights reserved.
-- Copyright (c) 1997 Ben Cohen.   All rights reserved.
-- This model can be used in conjunction with the Kluwer Academic books
-- This model can be used in conjunction with the Kluwer Academic books
-- "VHDL Coding Styles and Methodologies", ISBN: 0-7923-9598-0
-- "VHDL Coding Styles and Methodologies", ISBN: 0-7923-9598-0
-- "VHDL Amswers to Frequently Asked Questions", Kluwer Academic
-- "VHDL Amswers to Frequently Asked Questions", Kluwer Academic
--    by Ben Cohen.                       email: vhdlcohen@aol.com
--    by Ben Cohen.                       email: vhdlcohen@aol.com
--   
--   
-- This source file for the Image Package
-- This source file for the Image Package
-- may be used and distributed without restriction provided
-- may be used and distributed without restriction provided
-- that this copyright statement is not removed from the file
-- that this copyright statement is not removed from the file
-- and that any derivative work contains this copyright notice.
-- and that any derivative work contains this copyright notice.
--
--
--
--
-- Original Author: Ben Cohen
-- Original Author: Ben Cohen
-- Description: 
-- Description: 
-- Convert VHDL types to string for printing. This is especially useful when 
-- Convert VHDL types to string for printing. This is especially useful when 
-- compiling with VHDL-87             
-- compiling with VHDL-87             
 
 
---------------------------------------------------------------
---------------------------------------------------------------
LIBRARY IEEE;
LIBRARY IEEE;
  USE IEEE.STD_LOGIC_1164.ALL;
  USE IEEE.STD_LOGIC_1164.ALL;
  USE IEEE.STD_LOGIC_TEXTIO.ALL;
  USE IEEE.STD_LOGIC_TEXTIO.ALL;
  USE IEEE.NUMERIC_STD.ALL;
  USE IEEE.NUMERIC_STD.ALL;
 
 
LIBRARY STD;
LIBRARY STD;
  USE STD.TEXTIO.ALL;
  USE STD.TEXTIO.ALL;
 
 
package pkg_image is
package pkg_image is
  function Image(In_Image : Time) return String;
  function Image(In_Image : Time) return String;
  function Image(In_Image : Bit) return String;
  function Image(In_Image : Bit) return String;
  function Image(In_Image : Bit_Vector) return String;
  function Image(In_Image : Bit_Vector) return String;
  function Image(In_Image : Integer) return String;
  function Image(In_Image : Integer) return String;
  function Image(In_Image : Real) return String;
  function Image(In_Image : Real) return String;
  function Image(In_Image : Std_uLogic) return String;
  function Image(In_Image : Std_uLogic) return String;
  function Image(In_Image : Std_uLogic_Vector) return String;
  function Image(In_Image : Std_uLogic_Vector) return String;
  function Image(In_Image : Std_Logic_Vector) return String;
  function Image(In_Image : Std_Logic_Vector) return String;
  function Image(In_Image : Signed) return String;
  function Image(In_Image : Signed) return String;
  function Image(In_Image : UnSigned) return String;
  function Image(In_Image : UnSigned) return String;
 
 
  function HexImage(InStrg  : String) return String;
  function HexImage(InStrg  : String) return String;
  function HexImage(In_Image : Bit_Vector) return String;
  function HexImage(In_Image : Bit_Vector) return String;
  function HexImage(In_Image : Std_uLogic_Vector) return String;
  function HexImage(In_Image : Std_uLogic_Vector) return String;
  function HexImage(In_Image : Std_Logic_Vector) return String;
  function HexImage(In_Image : Std_Logic_Vector) return String;
  function HexImage(In_Image : Signed) return String;
  function HexImage(In_Image : Signed) return String;
  function HexImage(In_Image : UnSigned) return String;
  function HexImage(In_Image : UnSigned) return String;
 
 
  function DecImage(In_Image : Bit_Vector) return String;
  function DecImage(In_Image : Bit_Vector) return String;
  function DecImage(In_Image : Std_uLogic_Vector) return String;
  function DecImage(In_Image : Std_uLogic_Vector) return String;
  function DecImage(In_Image : Std_Logic_Vector) return String;
  function DecImage(In_Image : Std_Logic_Vector) return String;
  function DecImage(In_Image : Signed) return String;
  function DecImage(In_Image : Signed) return String;
  function DecImage(In_Image : UnSigned) return String;
  function DecImage(In_Image : UnSigned) return String;
end pkg_image;
end pkg_image;
 
 
package body pkg_image is
package body pkg_image is
  function Image(In_Image : Time) return String is
  function Image(In_Image : Time) return String is
    variable L : Line;  -- access type
    variable L : Line;  -- access type
    variable W : String(1 to 14) := (others => ' ');
    variable W : String(1 to 14) := (others => ' ');
       -- Long enough to hold a time string
       -- Long enough to hold a time string
  begin
  begin
    -- the WRITE procedure creates an object with "NEW".
    -- the WRITE procedure creates an object with "NEW".
    -- L is passed as an output of the procedure.
    -- L is passed as an output of the procedure.
    Std.TextIO.WRITE(L, in_image);
    Std.TextIO.WRITE(L, in_image);
    -- Copy L.all onto W
    -- Copy L.all onto W
    W(L.all'range) := L.all;
    W(L.all'range) := L.all;
    Deallocate(L);
    Deallocate(L);
    return W;
    return W;
  end Image;
  end Image;
 
 
  function Image(In_Image : Bit) return String is
  function Image(In_Image : Bit) return String is
    variable L : Line;  -- access type
    variable L : Line;  -- access type
    variable W : String(1 to 3) := (others => ' ');
    variable W : String(1 to 3) := (others => ' ');
  begin
  begin
    Std.TextIO.WRITE(L, in_image);
    Std.TextIO.WRITE(L, in_image);
    W(L.all'range) := L.all;
    W(L.all'range) := L.all;
    Deallocate(L);
    Deallocate(L);
    return W;
    return W;
  end Image;
  end Image;
 
 
  function Image(In_Image : Bit_Vector) return String is
  function Image(In_Image : Bit_Vector) return String is
    variable L : Line;  -- access type
    variable L : Line;  -- access type
    variable W : String(1 to In_Image'length) := (others => ' ');
    variable W : String(1 to In_Image'length) := (others => ' ');
  begin
  begin
    Std.TextIO.WRITE(L, in_image);
    Std.TextIO.WRITE(L, in_image);
    W(L.all'range) := L.all;
    W(L.all'range) := L.all;
    Deallocate(L);
    Deallocate(L);
    return W;
    return W;
  end Image;
  end Image;
 
 
  function Image(In_Image : Integer) return String is
  function Image(In_Image : Integer) return String is
    variable L : Line;  -- access type
    variable L : Line;  -- access type
    variable W : String(1 to 32) := (others => ' ');
    variable W : String(1 to 32) := (others => ' ');
     -- Long enough to hold a time string
     -- Long enough to hold a time string
  begin
  begin
    Std.TextIO.WRITE(L, in_image);
    Std.TextIO.WRITE(L, in_image);
    W(L.all'range) := L.all;
    W(L.all'range) := L.all;
    Deallocate(L);
    Deallocate(L);
    return W;
    return W;
  end Image;
  end Image;
 
 
  function Image(In_Image : Real) return String is
  function Image(In_Image : Real) return String is
    variable L : Line;  -- access type
    variable L : Line;  -- access type
    variable W : String(1 to 32) := (others => ' ');
    variable W : String(1 to 32) := (others => ' ');
      -- Long enough to hold a time string
      -- Long enough to hold a time string
  begin
  begin
    Std.TextIO.WRITE(L, in_image);
    Std.TextIO.WRITE(L, in_image);
    W(L.all'range) := L.all;
    W(L.all'range) := L.all;
    Deallocate(L);
    Deallocate(L);
    return W;
    return W;
  end Image;
  end Image;
 
 
  function Image(In_Image : Std_uLogic) return String is
  function Image(In_Image : Std_uLogic) return String is
    variable L : Line;  -- access type
    variable L : Line;  -- access type
    variable W : String(1 to 3) := (others => ' ');
    variable W : String(1 to 3) := (others => ' ');
  begin
  begin
    IEEE.Std_Logic_Textio.WRITE(L, in_image);
    IEEE.Std_Logic_Textio.WRITE(L, in_image);
    W(L.all'range) := L.all;
    W(L.all'range) := L.all;
    Deallocate(L);
    Deallocate(L);
    return W;
    return W;
  end Image;
  end Image;
 
 
  function Image(In_Image : Std_uLogic_Vector) return String is
  function Image(In_Image : Std_uLogic_Vector) return String is
    variable L : Line;  -- access type
    variable L : Line;  -- access type
    variable W : String(1 to In_Image'length) := (others => ' ');
    variable W : String(1 to In_Image'length) := (others => ' ');
  begin
  begin
    IEEE.Std_Logic_Textio.WRITE(L, in_image);
    IEEE.Std_Logic_Textio.WRITE(L, in_image);
    W(L.all'range) := L.all;
    W(L.all'range) := L.all;
    Deallocate(L);
    Deallocate(L);
    return W;
    return W;
  end Image;
  end Image;
 
 
  function Image(In_Image : Std_Logic_Vector) return String is
  function Image(In_Image : Std_Logic_Vector) return String is
    variable L : Line;  -- access type
    variable L : Line;  -- access type
    variable W : String(1 to In_Image'length) := (others => ' ');
    variable W : String(1 to In_Image'length) := (others => ' ');
  begin
  begin
     IEEE.Std_Logic_TextIO.WRITE(L, In_Image);
     IEEE.Std_Logic_TextIO.WRITE(L, In_Image);
     W(L.all'range) := L.all;
     W(L.all'range) := L.all;
     Deallocate(L);
     Deallocate(L);
     return W;
     return W;
  end Image;
  end Image;
 
 
  function Image(In_Image : Signed) return String is
  function Image(In_Image : Signed) return String is
  begin
  begin
    return Image(Std_Logic_Vector(In_Image));
    return Image(Std_Logic_Vector(In_Image));
  end Image;
  end Image;
 
 
  function Image(In_Image : UnSigned) return String is
  function Image(In_Image : UnSigned) return String is
  begin
  begin
    return Image(Std_Logic_Vector(In_Image));
    return Image(Std_Logic_Vector(In_Image));
  end Image;
  end Image;
 
 
  function HexImage(InStrg  : String) return String is
  function HexImage(InStrg  : String) return String is
    subtype Int03_Typ is Integer range 0 to 3;
    subtype Int03_Typ is Integer range 0 to 3;
    variable Result : string(1 to ((InStrg'length - 1)/4)+1) :=
    variable Result : string(1 to ((InStrg'length - 1)/4)+1) :=
        (others => '0');
        (others => '0');
    variable StrTo4 : string(1 to Result'length * 4) :=
    variable StrTo4 : string(1 to Result'length * 4) :=
        (others => '0');
        (others => '0');
    variable MTspace : Int03_Typ;  --  Empty space to fill in
    variable MTspace : Int03_Typ;  --  Empty space to fill in
    variable Str4    : String(1 to 4);
    variable Str4    : String(1 to 4);
    variable Group_v   : Natural := 0;
    variable Group_v   : Natural := 0;
  begin
  begin
    MTspace := Result'length * 4  - InStrg'length;
    MTspace := Result'length * 4  - InStrg'length;
    StrTo4(MTspace + 1 to StrTo4'length) := InStrg; -- padded with '0'
    StrTo4(MTspace + 1 to StrTo4'length) := InStrg; -- padded with '0'
    Cnvrt_Lbl : for I in Result'range loop
    Cnvrt_Lbl : for I in Result'range loop
      Group_v := Group_v + 4;  -- identifies end of bit # in a group of 4 
      Group_v := Group_v + 4;  -- identifies end of bit # in a group of 4 
      Str4 := StrTo4(Group_v - 3 to Group_v); -- get next 4 characters 
      Str4 := StrTo4(Group_v - 3 to Group_v); -- get next 4 characters 
      case Str4 is
      case Str4 is
        when "0000"  => Result(I) := '0';
        when "0000"  => Result(I) := '0';
        when "0001"  => Result(I) := '1';
        when "0001"  => Result(I) := '1';
        when "0010"  => Result(I) := '2';
        when "0010"  => Result(I) := '2';
        when "0011"  => Result(I) := '3';
        when "0011"  => Result(I) := '3';
        when "0100"  => Result(I) := '4';
        when "0100"  => Result(I) := '4';
        when "0101"  => Result(I) := '5';
        when "0101"  => Result(I) := '5';
        when "0110"  => Result(I) := '6';
        when "0110"  => Result(I) := '6';
        when "0111"  => Result(I) := '7';
        when "0111"  => Result(I) := '7';
        when "1000"  => Result(I) := '8';
        when "1000"  => Result(I) := '8';
        when "1001"  => Result(I) := '9';
        when "1001"  => Result(I) := '9';
        when "1010"  => Result(I) := 'A';
        when "1010"  => Result(I) := 'A';
        when "1011"  => Result(I) := 'B';
        when "1011"  => Result(I) := 'B';
        when "1100"  => Result(I) := 'C';
        when "1100"  => Result(I) := 'C';
        when "1101"  => Result(I) := 'D';
        when "1101"  => Result(I) := 'D';
        when "1110"  => Result(I) := 'E';
        when "1110"  => Result(I) := 'E';
        when "1111"  => Result(I) := 'F';
        when "1111"  => Result(I) := 'F';
        when others  => Result(I) := 'X';
        when others  => Result(I) := 'X';
      end case;                          --  Str4
      end case;                          --  Str4
    end loop Cnvrt_Lbl;
    end loop Cnvrt_Lbl;
 
 
    return Result;
    return Result;
  end HexImage;
  end HexImage;
 
 
 
 
  function HexImage(In_Image : Bit_Vector) return String is
  function HexImage(In_Image : Bit_Vector) return String is
  begin
  begin
    return HexImage(Image(In_Image));
    return HexImage(Image(In_Image));
  end HexImage;
  end HexImage;
 
 
  function HexImage(In_Image : Std_uLogic_Vector) return String is
  function HexImage(In_Image : Std_uLogic_Vector) return String is
  begin
  begin
    return HexImage(Image(In_Image));
    return HexImage(Image(In_Image));
  end HexImage;
  end HexImage;
 
 
  function HexImage(In_Image : Std_Logic_Vector) return String is
  function HexImage(In_Image : Std_Logic_Vector) return String is
  begin
  begin
    return HexImage(Image(In_Image));
    return HexImage(Image(In_Image));
  end HexImage;
  end HexImage;
 
 
  function HexImage(In_Image : Signed) return String is
  function HexImage(In_Image : Signed) return String is
  begin
  begin
    return HexImage(Image(In_Image));
    return HexImage(Image(In_Image));
  end HexImage;
  end HexImage;
 
 
  function HexImage(In_Image : UnSigned) return String is
  function HexImage(In_Image : UnSigned) return String is
  begin
  begin
    return HexImage(Image(In_Image));
    return HexImage(Image(In_Image));
  end HexImage;
  end HexImage;
 
 
  function DecImage(In_Image : Bit_Vector) return String is
  function DecImage(In_Image : Bit_Vector) return String is
    variable In_Image_v : Bit_Vector(In_Image'length downto 1) := In_Image;
    variable In_Image_v : Bit_Vector(In_Image'length downto 1) := In_Image;
  begin
  begin
    if In_Image'length > 31 then
    if In_Image'length > 31 then
      assert False
      assert False
        report "Number too large for Integer, clipping to 31 bits"
        report "Number too large for Integer, clipping to 31 bits"
        severity Warning;
        severity Warning;
      return Image(To_Integer
      return Image(To_Integer
                    (Unsigned(To_StdLogicVector
                    (Unsigned(To_StdLogicVector
                        (In_Image_v(31 downto 1)))));
                        (In_Image_v(31 downto 1)))));
    else
    else
      return Image(To_Integer(Unsigned(To_StdLogicVector(In_Image))));
      return Image(To_Integer(Unsigned(To_StdLogicVector(In_Image))));
    end if;
    end if;
  end DecImage;
  end DecImage;
 
 
  function DecImage(In_Image : Std_uLogic_Vector) return String is
  function DecImage(In_Image : Std_uLogic_Vector) return String is
    variable In_Image_v : Std_uLogic_Vector(In_Image'length downto 1)
    variable In_Image_v : Std_uLogic_Vector(In_Image'length downto 1)
                              := In_Image;
                              := In_Image;
  begin
  begin
    if In_Image'length > 31 then
    if In_Image'length > 31 then
      assert False
      assert False
        report "Number too large for Integer, clipping to 31 bits"
        report "Number too large for Integer, clipping to 31 bits"
        severity Warning;
        severity Warning;
       return Image(To_Integer(Unsigned(In_Image_v(31 downto 1))));
       return Image(To_Integer(Unsigned(In_Image_v(31 downto 1))));
    else
    else
        return Image(To_Integer(Unsigned(In_Image)));
        return Image(To_Integer(Unsigned(In_Image)));
    end if;
    end if;
  end DecImage;
  end DecImage;
 
 
  function DecImage(In_Image : Std_Logic_Vector) return String is
  function DecImage(In_Image : Std_Logic_Vector) return String is
    variable In_Image_v : Std_Logic_Vector(In_Image'length downto 1)
    variable In_Image_v : Std_Logic_Vector(In_Image'length downto 1)
                              := In_Image;
                              := In_Image;
  begin
  begin
    if In_Image'length > 31 then
    if In_Image'length > 31 then
      assert False
      assert False
        report "Number too large for Integer, clipping to 31 bits"
        report "Number too large for Integer, clipping to 31 bits"
        severity Warning;
        severity Warning;
       return Image(To_Integer(Unsigned(In_Image_v(31 downto 1))));
       return Image(To_Integer(Unsigned(In_Image_v(31 downto 1))));
    else
    else
        return Image(To_Integer(Unsigned(In_Image)));
        return Image(To_Integer(Unsigned(In_Image)));
    end if;
    end if;
  end DecImage;
  end DecImage;
 
 
  function DecImage(In_Image : Signed) return String is
  function DecImage(In_Image : Signed) return String is
    variable In_Image_v : Signed(In_Image'length downto 1) := In_Image;
    variable In_Image_v : Signed(In_Image'length downto 1) := In_Image;
  begin
  begin
    if In_Image'length > 31 then
    if In_Image'length > 31 then
      assert False
      assert False
        report "Number too large for Integer, clipping to 31 bits"
        report "Number too large for Integer, clipping to 31 bits"
        severity Warning;
        severity Warning;
       return Image(To_Integer(In_Image_v(31 downto 1)));
       return Image(To_Integer(In_Image_v(31 downto 1)));
    else
    else
        return Image(To_Integer(In_Image));
        return Image(To_Integer(In_Image));
    end if;
    end if;
  end DecImage;
  end DecImage;
 
 
  function DecImage(In_Image : UnSigned) return String is
  function DecImage(In_Image : UnSigned) return String is
    variable In_Image_v : UnSigned(In_Image'length downto 1) := In_Image;
    variable In_Image_v : UnSigned(In_Image'length downto 1) := In_Image;
  begin
  begin
    if In_Image'length > 31 then
    if In_Image'length > 31 then
      assert False
      assert False
        report "Number too large for Integer, clipping to 31 bits"
        report "Number too large for Integer, clipping to 31 bits"
        severity Warning;
        severity Warning;
       return Image(To_Integer(In_Image_v(31 downto 1)));
       return Image(To_Integer(In_Image_v(31 downto 1)));
    else
    else
        return Image(To_Integer(In_Image));
        return Image(To_Integer(In_Image));
    end if;
    end if;
  end DecImage;
  end DecImage;
 
 
end pkg_image;
end pkg_image;
 
 
-- $Log: not supported by cvs2svn $
-- $Log: not supported by cvs2svn $
-- Revision 1.1  2003/01/14 17:48:44  Default
-- Revision 1.1  2003/01/14 17:48:44  Default
-- Initial revision
-- Initial revision
--
--
-- Revision 1.1  2002/12/24 18:07:50  Default
-- Revision 1.1  2002/12/24 18:07:50  Default
-- Initial revision
-- Initial revision
--
--
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

powered by: WebSVN 2.1.0

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