How to make custom types visible in other .vhd modules

Discussion in 'VHDL' started by Lango, Oct 14, 2009.

  1. Lango

    Lango Guest

    Hello. I'd like to declare a custom type in only one place (such as
    MyTypes.vhd), and then to be able to use it in any module I want
    (other .vhd's). How to do this? Thanks for your help.
     
    Lango, Oct 14, 2009
    #1
    1. Advertising

  2. Lango

    Lango Guest

    On Oct 13, 6:24 pm, Lango <> wrote:
    > Hello.  I'd like to declare a custom type in only one place (such as
    > MyTypes.vhd), and then to be able to use it in any module I want
    > (other .vhd's).  How to do this?  Thanks for your help.


    Got it, save a MyTypes.vhd with a package, as follows:

    library IEEE;
    use IEEE.STD_LOGIC_1164.all;

    package MyTypes is
    type type_name is (<whatever the type values are>);
    end MyTypes;

    package body MyTypes is
    end MyTypes;

    And then, inside any .vhd that you wish that package to be visible,
    write:

    use MyTypes.ALL;
     
    Lango, Oct 14, 2009
    #2
    1. Advertising

  3. Lango wrote:

    > Got it, save a MyTypes.vhd with a package, as follows:


    That's it.
    More proof that posting a question stimulates the brain ;)

    The package body is required for functions and procedures.
    See the package body base_proc here, for example:
    http://mysite.verizon.net/miketreseler/proc_overload.vhd
     
    Mike Treseler, Oct 14, 2009
    #3
  4. Lango

    Andy Guest

    On Oct 13, 11:05 pm, Lango <> wrote:
    > And then, inside any .vhd that you wish that package to be visible,
    > write:
    >
    > use MyTypes.ALL;


    Scoping rules for use statements are not based on files. The
    visibility of a use statement is limited to the next declared unit
    immediately following it within the file. However, other units may
    inherit that visibility. An example:

    use mytypes.all;

    entity bar is
    -- mytypes is visible here directly
    end entity bar;

    architecture foo of bar is
    -- mytypes is visible here only because of
    -- inheritence from the entity bar.
    -- It would still be visible even if this arch
    -- was in a separate file.
    end architecture foo;
     
    Andy, Oct 14, 2009
    #4
  5. Lango

    Lango Guest

    On Oct 14, 6:29 am, Andy <> wrote:
    > On Oct 13, 11:05 pm, Lango <> wrote:
    >
    > > And then, inside any .vhd that you wish that package to be visible,
    > > write:

    >
    > > use MyTypes.ALL;

    >
    > Scoping rules for use statements are not based on files. The
    > visibility of a use statement is limited to the next declared unit
    > immediately following it within the file. However, other units may
    > inherit that visibility. An example:
    >


    Thanks for the tip. I had experienced that I had to repeat the 'use'
    when I declared a second entity in the same .vhd file. It felt weird
    since it is the first language I see that does something like this and
    I ended up putting the 2nd entity in a new file, but at least now I
    know that this is how it is supposed to work.
     
    Lango, Oct 15, 2009
    #5
    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. john
    Replies:
    2
    Views:
    7,218
  2. spamfurnace
    Replies:
    1
    Views:
    2,659
    Scott M.
    May 24, 2004
  3. Patrick Olurotimi Ige
    Replies:
    7
    Views:
    6,024
    Patrick Olurotimi Ige
    Jun 15, 2005
  4. Eli Bendersky
    Replies:
    14
    Views:
    1,097
    Eli Bendersky
    Oct 11, 2008
  5. Jurjen de Groot
    Replies:
    0
    Views:
    323
    Jurjen de Groot
    May 19, 2008
Loading...

Share This Page