Record Definition in Package Body

OP #7510317
Lesenswert?

Moin in die Runde,

Ich habe eine Konstante in einem Package, die aber erst in einer Funktion, in Abhängigkeit einer anderen Konstante, im Package Body initialisiert wird. Mit dieser Konstanten will ich im selben Package für ein Record einen Vector constrainen. Als Beispiel ungefähr so :

1
 library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4

5
package test_pkg is
6

7
   ----------------------------------------------------------------------------   
8
   constant test_big_vect_c : boolean := true;
9
   constant test_bits_c     : natural;  -- init below in function
10
   function init_test_bits_f return natural;
11

12
   type test_record is record
13
      test1       : std_logic;
14
      test_vector : std_logic_vector(test_bits_c-1 downto 0);
15
   end record;
16

17
end package;
18

19
package body test_pkg is
20

21
   function init_test_bits_f return natural is
22
   begin
23
      if test_big_vect_c then
24
         return 64;
25
      else
26
         return 32;                     -- @suppress "Dead code"
27
      end if;
28
   end function;
29

30
   constant test_bits_c : natural := init_test_bits_f;
31

32
end package body;

Leider geht das nicht, da die Konstante erst im Body festgelegt wird. Den Record im Body definieren geht auch nicht. Subtypes im Body habe ich auch schon vergeblich probiert.

hat vielleicht noch jemand eine simple Idee auf die ich gerade nicht komme?

Viele Grüße in die Runde

#7510421
Lesenswert?

also so ungefähr:

1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4

5
package test_pkg is
6
    package inner_test_pkg is
7
        constant test_big_vect_c : boolean := false;
8
        constant test_bits_c     : natural;  -- init below in function
9
        function init_test_bits_f return natural;
10
    end package inner_test_pkg;
11

12
    constant test_big_vect_c : boolean := true;
13
    type test_record is record
14
       test1       : std_logic;
15
       test_vector : std_logic_vector(inner_test_pkg.test_bits_c - 1 downto 0);
16
    end record;
17
end package;
18

19
package body test_pkg is
20
    package body inner_test_pkg is
21
        function init_test_bits_f return natural is
22
        begin
23
        if test_big_vect_c then
24
            return 64;
25
        else
26
            return 32;                     -- @suppress "Dead code"
27
        end if;
28
        end function;
29

30
        constant test_bits_c : natural := init_test_bits_f;
31
    end package body inner_test_pkg;
32

33
end package body;

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren