Altera_Forum
Honored Contributor
9 years agoUsing 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