Generic and constants

Discussion in 'VHDL' started by Maki, Nov 24, 2004.

  1. Maki

    Maki Guest

    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
     
    Maki, Nov 24, 2004
    #1
    1. Advertising

  2. 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 -
    |_| |_|_|\__|\___/
     
    Nicolas Matringe, Nov 25, 2004
    #2
    1. Advertising

  3. 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.
     
    Paul Uiterlinden, Nov 25, 2004
    #3
  4. Maki

    Neo Guest

    "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
     
    Neo, Nov 25, 2004
    #4
  5. Maki

    Maki Guest

    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 -
    > |_| |_|_|\__|\___/
    >
     
    Maki, Nov 25, 2004
    #5
  6. Maki

    Maki Guest

    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.
     
    Maki, Nov 25, 2004
    #6
  7. Maki

    Maki Guest

    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:...
    > "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
     
    Maki, Nov 25, 2004
    #7
  8. 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;
     
    Nicolas Matringe, Nov 25, 2004
    #8
  9. 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
     
    Allan Herriman, Nov 25, 2004
    #9
  10. 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.
     
    Paul Uiterlinden, Nov 25, 2004
    #10
  11. Maki

    Maki Guest

    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.

    --
    Veselic Mladen
    Laboratorija Sigma
    "Paul Uiterlinden" <> wrote in message
    news:co4ji0$ogc$...
    > 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.
     
    Maki, Nov 25, 2004
    #11
  12. Maki

    Maki Guest

    Thank You all. That's a solution I was looking for.

    Best regards,
    Maki

    --
    Veselic Mladen
    Laboratorija Sigma

    "Nicolas Matringe" <> wrote in message
    news:...
    > 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;
    >
     
    Maki, Nov 25, 2004
    #12
    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. Murat Tasan
    Replies:
    1
    Views:
    8,073
    Chaitanya
    Feb 3, 2009
  2. Replies:
    2
    Views:
    448
  3. bister
    Replies:
    3
    Views:
    659
    bister
    Dec 31, 2007
  4. Replies:
    1
    Views:
    465
  5. janeruth
    Replies:
    1
    Views:
    982
    janeruth
    Jul 29, 2010
Loading...

Share This Page