Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
9 years ago

Using Package Constant within another Package

I have a Package file (System_Config) that defines a set of system Constants used drive generics and signal widths in various VHDL files in a project. A second Package file (Channel_Config) defines a set of channel Constants derived from System_Config. Note that the ultimate goal is to generate the System_Config Package via script and automate builds targeting multiple systems.

Using the Package Constants from any project VHDL file via "use work.Channel_Config.all" and "use work.System_Config.all" works fine. Rolling the two separate packages into and single Config Package works fine. However, having Channel_Config read a constant (say NUM_CHANNELS) from System_Config throws an error that NUM_CHANNELS is undefined. Is there a know issue with a Package using a Constant from a another Package?

For Example:

system_config_package.vhd:


library ieee;use ieee.std_logic_1164.all; 
use ieee.numeric_std.all;
------------------------------------------------------------------------------
-- Package Declaration -------------------------------------------------------
------------------------------------------------------------------------------
package System_Config_Package is
   ------------------------------------------------------------------------------
   -- System Constants -----------------------------------------------------
   ------------------------------------------------------------------------------
   constant SYSTEM_TYPE   : integer := 200;
   constant NUM_CHANNELS  : integer := 32;
end package System_Config_Package;

channel_config_package.vhd:


library ieee;
use ieee.std_logic_1164.all; 
use ieee.numeric_std.all;
library work;
use work.System_Config_Package.all;
------------------------------------------------------------------------------
-- Package Declaration -------------------------------------------------------
------------------------------------------------------------------------------
package Channel_Config_Package is
   ------------------------------------------------------------------------------
   -- Constants -----------------------------------------------------------------
   ------------------------------------------------------------------------------
   -- Data Arrays
   type SomeDataArray   is array(0 to NUM_CHANNELS-1) of unsigned(11 downto 0);
   ------------------------------------------------------------------------------
   -- Functions -----------------------------------------------------------------
   ------------------------------------------------------------------------------
   function ADC_CHANNEL_MAP(AdcNumber:integer; AdcChannel:integer) return integer;
end package Channel_Config_Package;
------------------------------------------------------------------------------
-- Package Body --------------------------------------------------------------
------------------------------------------------------------------------------
package body Channel_Config_Package is
   ------------------------------------------------------------------------------
   -- System Channel Mapping ----------------------------------------------------
   ------------------------------------------------------------------------------
   -- Map ADC input channels to real channels
   function ADC_CHANNEL_MAP(AdcNumber:integer; AdcChannel:integer) return integer is
       variable DChannel : integer range 0 to NUM_CHANNELS-1;
   begin
....<SOME CALCS HERE BASED ON SYSTEM_TYPE>....
       -- Return Channel Number based on System Type
       return(DChannel);
   end function ADC_CHANNEL_MAP;
end package body Channel_Config_Package ;

This results in the following error:

Error (10482): VHDL error at Channel_Config_Package.vhd(17): object "NUM_CHANNELS" is used but not declared

I would rather not roll everything into Channel_Config_Package, as it is rather large. I would like the build script to generate the only Constants that would change between builds.

Thanks,

Aaron

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This should work no problem (and compiled just fine for me). Have you compiled the correct file? have you got the compile order correct?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for verifying Tricky, I assume this is something small in my build parameters. How do I verify compilation order? (I have been living in another vendors tool for a while) Here is what I have checked:

    1) Both files are in the file list with correct filename

    2) System_Config_Package is listed ahead of Channel_Config_Package in the .qsf file (and GUI file list)

    3) When compilation starts, the log shows System_Config_Package being read before Channel_Config_Package

    The error is thrown in the log immediately after all the project files are read in the listed order. Obviously Channel_Config_Package the first file that has anything to elaborate.

    I'm sure I am missing something.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Another thing of note: I just noticed in the Quartus GUI that while the files show up in the "Files" list, they are not shown "Design Units" in the Project Navigator. All other Design Units from other .vhd files (including other packages) are list there under "work".

    EDIT: This was the tip-off, and always check your example code matches your actual project code. Channel_Config_Package was being called recursively in System_Config_Package due to a cut-and-paste error, causing Quartus to fail to elaborate both.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Just edited the post above with the answer.

    Thanks again Tricky.