Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - type/subtype definition in entity

 
Thread Tools Search this Thread
Old 04-17-2007, 02:32 AM   #1
Default type/subtype definition in entity


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;



zhangpei@gmail.com
  Reply With Quote
Old 04-17-2007, 10:46 AM   #2
Alan Fitch
 
Posts: n/a
Default Re: type/subtype definition in entity
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
  Reply With Quote
Old 04-17-2007, 02:09 PM   #3
Andy
 
Posts: n/a
Default Re: type/subtype definition in entity
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 <alan.fi...@spamtrap.com> wrote:
> zhang...@gmail.com 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
  Reply With Quote
Old 04-18-2007, 12:22 AM   #4
zhangpei@gmail.com
 
Posts: n/a
Default Re: type/subtype definition in entity
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/vhd...ug_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 <jonesa...@comcast.net> 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 <alan.fi...@spamtrap.com> wrote:
>
> > zhang...@gmail.com 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





zhangpei@gmail.com
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Physical sythesis tool PALAC is not supported by Formal Verification tool Conf bbiandov Software 0 12-22-2008 05:25 AM
10 Reasons why HD-DVD and Blu-Ray Have Already Failed Black Locust DVD Video 69 07-01-2006 04:24 AM
Sonic Forges High Definition Authoring Alliance. Allan DVD Video 1 07-13-2005 12:03 AM
High Definition and the future of viewing. Allan DVD Video 3 03-09-2005 12:56 AM
Engineering Certifications Harsha Raghavan A+ Certification 81 08-10-2004 08:25 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46