type/subtype definition in entity

Discussion in 'VHDL' started by zhangpei@gmail.com, Apr 17, 2007.

  1. Guest

    I want to define a type related to entity generics, like an array in
    the following codes. But It seems I have no places to put those
    subtype/type statements in the entity. I can not use package to define
    those subtype/type since there are related to entity generics.

    Any solution or idea?

    Thanks a lot,

    Z
    04/16/07

    ===============
    library IEEE;
    use IEEE.std_logic_1164.all;
    use IEEE.std_logic_arith.all;
    use IEEE.std_logic_unsigned.all;

    entity ir is
    -- Here is not correct
    -- subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    -- type MY_UNSIGNED_VECTOR is array(natural range<>) of
    MY_UNSIGNED;
    generic (
    EL_SIZE : POSITIVE := 16;
    EL_COUNT : POSITIVE := 8
    );
    -- Here is not correct either
    -- subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    -- type MY_UNSIGNED_VECTOR is array(natural range<>) of
    MY_UNSIGNED;
    port (
    val_b : out MY_UNSIGNED_VECTOR (0 to EL_COUNT-1);
    clk_i : in std_logic
    ...
    );
    end ir;
    , Apr 17, 2007
    #1
    1. Advertising

  2. Alan Fitch Guest

    wrote:
    > I want to define a type related to entity generics, like an array in
    > the following codes. But It seems I have no places to put those
    > subtype/type statements in the entity. I can not use package to define
    > those subtype/type since there are related to entity generics.
    >
    > Any solution or idea?
    >
    > Thanks a lot,
    >
    > Z
    > 04/16/07
    >
    > ===============
    > library IEEE;
    > use IEEE.std_logic_1164.all;
    > use IEEE.std_logic_arith.all;
    > use IEEE.std_logic_unsigned.all;
    >
    > entity ir is
    > -- Here is not correct
    > -- subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > -- type MY_UNSIGNED_VECTOR is array(natural range<>) of
    > MY_UNSIGNED;
    > generic (
    > EL_SIZE : POSITIVE := 16;
    > EL_COUNT : POSITIVE := 8
    > );
    > -- Here is not correct either
    > -- subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > -- type MY_UNSIGNED_VECTOR is array(natural range<>) of
    > MY_UNSIGNED;
    > port (
    > val_b : out MY_UNSIGNED_VECTOR (0 to EL_COUNT-1);
    > clk_i : in std_logic
    > ...
    > );
    > end ir;
    >


    Hi Z,

    you must put the declarations in a package, e.g.

    library ieee;
    use ieee.std_logic_arith.all; -- prefer numeric_std, it's a standard
    package mytypes is
    subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    type MY_UNSIGNED_VECTOR is array(natural range<>) of MY_UNSIGNED;

    end package mytypes;


    Of course you then don't have access to the generic. So you need to
    fix the generic size using a constant or the subtype itself, e.g.

    package mytypes is
    constant EL_SIZE : positive := 10;
    subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    type MY_UNSIGNED_VECTOR is array(natural range<>) of MY_UNSIGNED;

    end package mytypes;

    You must make the package visible in front of the entity of course, e.g.

    library mylib;
    use mylib.mytypes.all;
    library ieee;
    ....

    entity...

    assuming you compiled the package into library 'mytypes'

    Does that help?

    In Accellera VHDL2006 you can have package generics, which would be a
    neater solution - but your tools must have 2006 support.

    regards
    Alan

    --
    Alan Fitch
    Doulos
    http://www.doulos.com
    Alan Fitch, Apr 17, 2007
    #2
    1. Advertising

  3. Andy Guest

    Right now, there isn't a good way to handle what you want, exactly. As
    Alan said, Accellera's 2006 std has the ability to invoke packages
    with generics, which would do what you want.

    For now, I would do one of two things:

    First, the package for this entity could use a constant from another
    package (a higher level project package) to get the sizes. BTW,
    whenever I create packages that have typedefs, etc for an entity, I
    them at the top of the same file that has the entity/arch in it. That
    way, if you've compiled the entity/arch, you've also compiled the
    package necessary to use it. I also often define a record type to hold
    all the generics for the entity in that package. That way handling all
    the generics up through the hierarchy gets easier. Higher level
    packages for higher level entities reference the lower level entities'
    packages' generic record definitions, and so on, all the way to the
    top. So adding a new parameter for a lower level entity means adding
    it only to the entity/arch/package that needs it, and to the top level
    where it gets set. It gets automatically plumbed through all the
    levels in between.

    The second method would be to pack the entire array into one long SLV
    (can be an unconstrained port). Then you can pass generics into the
    entity that allow you to recompose the array from the SLV (or
    decompose the array to drive the port). Not the prettiest solution,
    but it works.

    Hope this helps,

    Andy

    On Apr 17, 4:46 am, Alan Fitch <> wrote:
    > wrote:
    > > I want to define a type related to entity generics, like an array in
    > > the following codes. But It seems I have no places to put those
    > > subtype/type statements in the entity. I can not use package to define
    > > those subtype/type since there are related to entity generics.

    >
    > > Any solution or idea?

    >
    > > Thanks a lot,

    >
    > > Z
    > > 04/16/07

    >
    > > ===============
    > > library IEEE;
    > > use IEEE.std_logic_1164.all;
    > > use IEEE.std_logic_arith.all;
    > > use IEEE.std_logic_unsigned.all;

    >
    > > entity ir is
    > > -- Here is not correct
    > > -- subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > > -- type MY_UNSIGNED_VECTOR is array(natural range<>) of
    > > MY_UNSIGNED;
    > > generic (
    > > EL_SIZE : POSITIVE := 16;
    > > EL_COUNT : POSITIVE := 8
    > > );
    > > -- Here is not correct either
    > > -- subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > > -- type MY_UNSIGNED_VECTOR is array(natural range<>) of
    > > MY_UNSIGNED;
    > > port (
    > > val_b : out MY_UNSIGNED_VECTOR (0 to EL_COUNT-1);
    > > clk_i : in std_logic
    > > ...
    > > );
    > > end ir;

    >
    > Hi Z,
    >
    > you must put the declarations in a package, e.g.
    >
    > library ieee;
    > use ieee.std_logic_arith.all; -- prefer numeric_std, it's a standard
    > package mytypes is
    > subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > type MY_UNSIGNED_VECTOR is array(natural range<>) of MY_UNSIGNED;
    >
    > end package mytypes;
    >
    > Of course you then don't have access to the generic. So you need to
    > fix the generic size using a constant or the subtype itself, e.g.
    >
    > package mytypes is
    > constant EL_SIZE : positive := 10;
    > subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > type MY_UNSIGNED_VECTOR is array(natural range<>) of MY_UNSIGNED;
    >
    > end package mytypes;
    >
    > You must make the package visible in front of the entity of course, e.g.
    >
    > library mylib;
    > use mylib.mytypes.all;
    > library ieee;
    > ...
    >
    > entity...
    >
    > assuming you compiled the package into library 'mytypes'
    >
    > Does that help?
    >
    > In Accellera VHDL2006 you can have package generics, which would be a
    > neater solution - but your tools must have 2006 support.
    >
    > regards
    > Alan
    >
    > --
    > Alan Fitch
    > Douloshttp://www.doulos.com
    Andy, Apr 17, 2007
    #3
  4. Guest

    Thanks a lot for your useful suggestion and informations, Alan and
    Andy.

    Accellera VHDL 2006 ( which will be VHDL 2007 with minor changes?)
    looks perfect for my need.

    http://www.synthworks.com/papers/vhdl_accellera_lewis_marlug_2006_bw.pdf

    type std_logic_matrix is array (natural range <>) of
    std_logic_vector ;
    -- constraining in declaration
    signal A : std_logic_matrix(7 downto 0)(5 downto 0) ;

    entity e is
    port (
    A : std_logic_matrix(7 downto 0)(5 downto 0) ;
    .. . .
    ) ;

    That makes VHDL more like C for 2-dimensional arrays.

    Anyway, I will use other method to implement my needs.

    Z

    On Apr 17, 6:09 am, Andy <> wrote:
    > Right now, there isn't a good way to handle what you want, exactly. As
    > Alan said, Accellera's 2006 std has the ability to invoke packages
    > with generics, which would do what you want.
    >
    > For now, I would do one of two things:
    >
    > First, the package for this entity could use a constant from another
    > package (a higher level project package) to get the sizes. BTW,
    > whenever I create packages that have typedefs, etc for an entity, I
    > them at the top of the same file that has the entity/arch in it. That
    > way, if you've compiled the entity/arch, you've also compiled the
    > package necessary to use it. I also often define a record type to hold
    > all the generics for the entity in that package. That way handling all
    > the generics up through the hierarchy gets easier. Higher level
    > packages for higher level entities reference the lower level entities'
    > packages' generic record definitions, and so on, all the way to the
    > top. So adding a new parameter for a lower level entity means adding
    > it only to the entity/arch/package that needs it, and to the top level
    > where it gets set. It gets automatically plumbed through all the
    > levels in between.
    >
    > The second method would be to pack the entire array into one long SLV
    > (can be an unconstrained port). Then you can pass generics into the
    > entity that allow you to recompose the array from the SLV (or
    > decompose the array to drive the port). Not the prettiest solution,
    > but it works.
    >
    > Hope this helps,
    >
    > Andy
    >
    > On Apr 17, 4:46 am, Alan Fitch <> wrote:
    >
    > > wrote:
    > > > I want to define a type related to entity generics, like an array in
    > > > the following codes. But It seems I have no places to put those
    > > > subtype/type statements in the entity. I can not use package to define
    > > > those subtype/type since there are related to entity generics.

    >
    > > > Any solution or idea?

    >
    > > > Thanks a lot,

    >
    > > > Z
    > > > 04/16/07

    >
    > > > ===============
    > > > library IEEE;
    > > > use IEEE.std_logic_1164.all;
    > > > use IEEE.std_logic_arith.all;
    > > > use IEEE.std_logic_unsigned.all;

    >
    > > > entity ir is
    > > > -- Here is not correct
    > > > -- subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > > > -- type MY_UNSIGNED_VECTOR is array(natural range<>) of
    > > > MY_UNSIGNED;
    > > > generic (
    > > > EL_SIZE : POSITIVE := 16;
    > > > EL_COUNT : POSITIVE := 8
    > > > );
    > > > -- Here is not correct either
    > > > -- subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > > > -- type MY_UNSIGNED_VECTOR is array(natural range<>) of
    > > > MY_UNSIGNED;
    > > > port (
    > > > val_b : out MY_UNSIGNED_VECTOR (0 to EL_COUNT-1);
    > > > clk_i : in std_logic
    > > > ...
    > > > );
    > > > end ir;

    >
    > > Hi Z,

    >
    > > you must put the declarations in a package, e.g.

    >
    > > library ieee;
    > > use ieee.std_logic_arith.all; -- prefer numeric_std, it's a standard
    > > package mytypes is
    > > subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > > type MY_UNSIGNED_VECTOR is array(natural range<>) of MY_UNSIGNED;

    >
    > > end package mytypes;

    >
    > > Of course you then don't have access to the generic. So you need to
    > > fix the generic size using a constant or the subtype itself, e.g.

    >
    > > package mytypes is
    > > constant EL_SIZE : positive := 10;
    > > subtype MY_UNSIGNED is unsigned(EL_SIZE-1 downto 0);
    > > type MY_UNSIGNED_VECTOR is array(natural range<>) of MY_UNSIGNED;

    >
    > > end package mytypes;

    >
    > > You must make the package visible in front of the entity of course, e.g.

    >
    > > library mylib;
    > > use mylib.mytypes.all;
    > > library ieee;
    > > ...

    >
    > > entity...

    >
    > > assuming you compiled the package into library 'mytypes'

    >
    > > Does that help?

    >
    > > In Accellera VHDL2006 you can have package generics, which would be a
    > > neater solution - but your tools must have 2006 support.

    >
    > > regards
    > > Alan

    >
    > > --
    > > Alan Fitch
    > > Douloshttp://www.doulos.com
    , Apr 18, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samuel van Laere

    Entity Name or Entity Number?

    Samuel van Laere, Feb 24, 2007, in forum: HTML
    Replies:
    4
    Views:
    1,629
    Jukka K. Korpela
    Feb 24, 2007
  2. tonyfai

    Subtype of User-Defined Type?

    tonyfai, Dec 6, 2007, in forum: VHDL
    Replies:
    0
    Views:
    458
    tonyfai
    Dec 6, 2007
  3. Pierre Yves
    Replies:
    2
    Views:
    483
    Pierre Yves
    Jan 10, 2008
  4. markla
    Replies:
    1
    Views:
    545
    Steven Cheng
    Oct 6, 2008
  5. valtih1978

    defines both a type and a subtype

    valtih1978, Nov 13, 2012, in forum: VHDL
    Replies:
    4
    Views:
    359
    valtih1978
    Nov 15, 2012
Loading...

Share This Page