Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Generic and constants

Reply
Thread Tools

Generic and constants

 
 
Maki
Guest
Posts: n/a
 
      11-24-2004
Hello all,

In top level description of my processor I have few generic constants. One
of them define how much timers exist in the model.
Timers have two registers: TMR_CFG and TMR_VAL. I keep addresses of these in
separate package as a constant.
How can initialize constants in the package depending of the value of
generic which is in top level file.
I other words I need to generate constants in the package depending on the
value of generic. These constants should be diferent for every timer that is
generated.
Any simple solution for this?

Best regards and thanks.

Maki.

--
Veselic Mladen
Laboratorija Sigma


 
Reply With Quote
 
 
 
 
Nicolas Matringe
Guest
Posts: n/a
 
      11-25-2004
Maki a écrit:
[...]
> I other words I need to generate constants in the package depending on the
> value of generic. These constants should be diferent for every timer that is
> generated.
> Any simple solution for this?


Hello
In my opinion, packages are for constants, not parameters. If you want
your constants to depend on a generic parameter, declare them directly
in your architecture.
Since packages must be compiled/analyzed before being used, you can't
make a constant in the package depend on an entity generic.

--
____ _ __ ___
| _ \_)/ _|/ _ \ Adresse de retour invalide: retirez le -
| | | | | (_| |_| | Invalid return address: remove the -
|_| |_|_|\__|\___/

 
Reply With Quote
 
 
 
 
Paul Uiterlinden
Guest
Posts: n/a
 
      11-25-2004
Maki wrote:
> Hello all,
>
> In top level description of my processor I have few generic constants. One
> of them define how much timers exist in the model.
> Timers have two registers: TMR_CFG and TMR_VAL. I keep addresses of these in
> separate package as a constant.
> How can initialize constants in the package depending of the value of
> generic which is in top level file.


You can't. There is no way constants in a package can be set according
to a value of a generic.

> I other words I need to generate constants in the package depending on the
> value of generic. These constants should be diferent for every timer that is
> generated.
> Any simple solution for this?


As far as I understand the problem, I would declare multiple constants
for each timer (or even an array of constants, making a table). In the
architecture you then choose which constant (or which index into the
array) to use, depending on the value of your generic(s).

Paul.
 
Reply With Quote
 
Neo
Guest
Posts: n/a
 
      11-25-2004
"Maki" <> wrote in message news:<co32mq$m8l$>...
> Hello all,
>
> In top level description of my processor I have few generic constants. One
> of them define how much timers exist in the model.
> Timers have two registers: TMR_CFG and TMR_VAL. I keep addresses of these in
> separate package as a constant.
> How can initialize constants in the package depending of the value of
> generic which is in top level file.
> I other words I need to generate constants in the package depending on the
> value of generic. These constants should be diferent for every timer that is
> generated.
> Any simple solution for this?
>
> Best regards and thanks.
>
> Maki.


You have got yourself into a tough situation, maybe you can try if
shared variables can help you out, but I am not sure.

Neo
 
Reply With Quote
 
Maki
Guest
Posts: n/a
 
      11-25-2004
Thank You for a quick answer
I agree with You on this. But ...
Timer module doesn't "know" if it is being copied with a generate statement.
And how many times. So it can't know address of its registers. Example:

Timers : for i in 0 to n_of_timers - 1 generate
begin
Timer : entity work.FROG1_Timer(rtl)
port map (
clk => clk,
reg_bus => reg_bus,
reg_adr => reg_adr,
reg_rd => reg_rd,
reg_wr => reg_wr,
A => A(i),
B => B(i),
tmr_int => tmr_int_vec(i)
);
end generate;

In the package constants are declared like this:
constant adr_tmr : std_logic_vector(4 downto 0) := "10000";
constant adr_tmr_cfg : std_logic_vector(4 downto 0) := "10001";

So every timer that is copied has the same address for data and cfg
registers.
This is bad. There is no difference between them.
But if I could somehow create array of constants which size depend of
generic parameter, perhaps I could access these constants and make all
timers have diferent address. Which is my goal. By changing one generic
parameter I'm allocating address space for these timers so I can access them
all because their address is diferent.

Maybe this could be achived in some other, simpler way.
Any sugestions?

Thanks,
M.

--
Veselic Mladen
Laboratorija Sigma
"Nicolas Matringe" <> wrote in message
news:...
> Maki a écrit:
> [...]
> > I other words I need to generate constants in the package depending on

the
> > value of generic. These constants should be diferent for every timer

that is
> > generated.
> > Any simple solution for this?

>
> Hello
> In my opinion, packages are for constants, not parameters. If you want
> your constants to depend on a generic parameter, declare them directly
> in your architecture.
> Since packages must be compiled/analyzed before being used, you can't
> make a constant in the package depend on an entity generic.
>
> --
> ____ _ __ ___
> | _ \_)/ _|/ _ \ Adresse de retour invalide: retirez le -
> | | | | | (_| |_| | Invalid return address: remove the -
> |_| |_|_|\__|\___/
>



 
Reply With Quote
 
Maki
Guest
Posts: n/a
 
      11-25-2004
Paul > As far as I understand the problem, I would declare multiple
constants
Paul > for each timer (or even an array of constants, making a table). In
the
Paul > architecture you then choose which constant (or which index into the
Paul > array) to use, depending on the value of your generic(s).

This cross my mind. But do You have an idea how to index the array? I have
only one generic n_of_timers.
Perhaps I can use counter value (i) in generate statement ?

Timers : for i in 0 to n_of_timers - 1 generate
begin
Timer : entity work.FROG1_Timer(rtl)
port map (
clk => clk,
reg_bus => reg_bus,
reg_adr => reg_adr,
reg_rd => reg_rd,
reg_wr => reg_wr,
A => A(i),
B => B(i),
tmr_int => tmr_int_vec(i)
);
end generate;

Somehow I have to pass it to timer entity? Like a generic maybe?
Best regards and thanks,
Maki.


--
Veselic Mladen
Laboratorija Sigma
"Paul Uiterlinden" <> wrote in message
news:co4a28$85a$...
> Maki wrote:
> > Hello all,
> >
> > In top level description of my processor I have few generic constants.

One
> > of them define how much timers exist in the model.
> > Timers have two registers: TMR_CFG and TMR_VAL. I keep addresses of

these in
> > separate package as a constant.
> > How can initialize constants in the package depending of the value of
> > generic which is in top level file.

>
> You can't. There is no way constants in a package can be set according
> to a value of a generic.
>
> > I other words I need to generate constants in the package depending on

the
> > value of generic. These constants should be diferent for every timer

that is
> > generated.
> > Any simple solution for this?

>
> As far as I understand the problem, I would declare multiple constants
> for each timer (or even an array of constants, making a table). In the
> architecture you then choose which constant (or which index into the
> array) to use, depending on the value of your generic(s).
>
> Paul.



 
Reply With Quote
 
Maki
Guest
Posts: n/a
 
      11-25-2004
Neo > You have got yourself into a tough situation, maybe you can try if
Neo > shared variables can help you out, but I am not sure.

Thanks Neo,
But this solution if for synthesis and I'm not sure that shared variables
are synthesisable.

Regards,
Maki
--
Veselic Mladen
Laboratorija Sigma

"Neo" <> wrote in message
news: om...
> "Maki" <> wrote in message

news:<co32mq$m8l$>...
> > Hello all,
> >
> > In top level description of my processor I have few generic constants.

One
> > of them define how much timers exist in the model.
> > Timers have two registers: TMR_CFG and TMR_VAL. I keep addresses of

these in
> > separate package as a constant.
> > How can initialize constants in the package depending of the value of
> > generic which is in top level file.
> > I other words I need to generate constants in the package depending on

the
> > value of generic. These constants should be diferent for every timer

that is
> > generated.
> > Any simple solution for this?
> >
> > Best regards and thanks.
> >
> > Maki.

>
> You have got yourself into a tough situation, maybe you can try if
> shared variables can help you out, but I am not sure.
>
> Neo



 
Reply With Quote
 
Nicolas Matringe
Guest
Posts: n/a
 
      11-25-2004
Maki a écrit:

> Maybe this could be achived in some other, simpler way.
> Any sugestions?


Very easily. Pass your timer number to the timer through a generic
parameter and inside the timer, define a constant base address based on
the generic:

Timers : for i in 0 to n_of_timers - 1 generate
begin
Timer : entity work.FROG1_Timer(rtl)
generic map ( --
tmr_nbr => i) --
port map (
clk => clk,
reg_bus => reg_bus,
reg_adr => reg_adr,
reg_rd => reg_rd,
reg_wr => reg_wr,
A => A(i),
B => B(i),
tmr_int => tmr_int_vec(i)
);
end generate;

 
Reply With Quote
 
Allan Herriman
Guest
Posts: n/a
 
      11-25-2004
On Thu, 25 Nov 2004 11:26:21 +0100, "Maki" <> wrote:

>Thank You for a quick answer
>I agree with You on this. But ...
>Timer module doesn't "know" if it is being copied with a generate statement.
>And how many times. So it can't know address of its registers. Example:
>
> Timers : for i in 0 to n_of_timers - 1 generate
> begin
> Timer : entity work.FROG1_Timer(rtl)
> port map (
> clk => clk,
> reg_bus => reg_bus,
> reg_adr => reg_adr,
> reg_rd => reg_rd,
> reg_wr => reg_wr,
> A => A(i),
> B => B(i),
> tmr_int => tmr_int_vec(i)
> );
> end generate;
>
>In the package constants are declared like this:
>constant adr_tmr : std_logic_vector(4 downto 0) := "10000";
>constant adr_tmr_cfg : std_logic_vector(4 downto 0) := "10001";
>
>So every timer that is copied has the same address for data and cfg
>registers.
>This is bad. There is no difference between them.
>But if I could somehow create array of constants which size depend of
>generic parameter, perhaps I could access these constants and make all
>timers have diferent address. Which is my goal. By changing one generic
>parameter I'm allocating address space for these timers so I can access them
>all because their address is diferent.
>
>Maybe this could be achived in some other, simpler way.
>Any sugestions?


The way I've done this before is to break the address of each register
up into 'base' and 'offset' parts. The constants in the package
define the offsets of each register and the base is passed in as a
generic. The address of each register in the instantiated
architecture is of course (offset + base) or in one rather successful
implementation I used, it was (offset or base).

Regards,
Allan
 
Reply With Quote
 
Paul Uiterlinden
Guest
Posts: n/a
 
      11-25-2004
Maki wrote:
> Paul > As far as I understand the problem, I would declare multiple
> constants
> Paul > for each timer (or even an array of constants, making a table). In
> the
> Paul > architecture you then choose which constant (or which index into the
> Paul > array) to use, depending on the value of your generic(s).
>
> This cross my mind. But do You have an idea how to index the array? I have
> only one generic n_of_timers.
> Perhaps I can use counter value (i) in generate statement ?
>
> Timers : for i in 0 to n_of_timers - 1 generate
> begin
> Timer : entity work.FROG1_Timer(rtl)
> port map (
> clk => clk,
> reg_bus => reg_bus,
> reg_adr => reg_adr,
> reg_rd => reg_rd,
> reg_wr => reg_wr,
> A => A(i),
> B => B(i),
> tmr_int => tmr_int_vec(i)
> );
> end generate;
>
> Somehow I have to pass it to timer entity? Like a generic maybe?


Exactly! Put the counter value of the generate loop in the generic map
and use the generic in the architecture FROG1_Timer(rtl) to index the array.

Timers : for i in 0 to n_of_timers - 1 generate
begin
Timer : entity work.FROG1_Timer(rtl)
generic map(
timer_nr => i
)
port map (
...

Paul.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL - parameterised generic constants janeruth VHDL 1 07-29-2010 01:58 PM
generic interfaces with generic methods Murat Tasan Java 1 02-03-2009 12:17 PM
Problems inserting constants into generic-width pipeline antan951@student.liu.se VHDL 1 06-27-2008 12:00 PM
help with file I/O and generic constants bister VHDL 3 12-31-2007 05:11 AM
Generic class in a non generic class nramnath@gmail.com Java 2 07-04-2006 07:24 AM



Advertisments
 



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 47 48 49 50 51 52 53 54 55 56 57