Generic and constants

M

Maki

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

Nicolas Matringe

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

Paul Uiterlinden

Maki said:
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.
 
N

Neo

Maki said:
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
 
M

Maki

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 said:
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 -
|_| |_|_|\__|\___/
 
M

Maki

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

Maki

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
 
N

Nicolas Matringe

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

Allan Herriman

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
 
P

Paul Uiterlinden

Maki said:
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.
 
M

Maki

Dear Paul,

I have pass as generic value and with litlle conversion from natural
everything compiles fine.
Thank You very much for Your help it is appriciated.

Best regards,
M.
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top