How to make custom types visible in other .vhd modules

L

Lango

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.
 
L

Lango

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;
 
A

Andy

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;
 
L

Lango

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top