5

I want to be able to specify a number of channels as a generic and use this to specify the range of an array containing further parameters. When compiling, my Aldec compile tell me that 'num_chan' cannot be referenced until the interface list is complete.

Does anyone know a way to achieve this?

ENTITY deframer IS
    generic (
      num_chan : integer                      := 2;            
      ch_low   : int_arr(num_chan-1 downto 0) := (  1, 189);   
      ch_hi    : int_arr(num_chan-1 downto 0) := (127, 189));
1
  • 2
    Note that the language allows you to use unconstrained arrays here. If you are doing synthesis, your synthesis tool may not - you will have to try it. Commented Jan 30, 2014 at 23:45

1 Answer 1

5

In VHDL-2002 (and earlier), a formal generic declared within a given generic list can't be used to declared other generics in that list, which is the reason for the error you see.

In VHDL-2008 that is possible, so if the required tools support VHDL-2008 and that feature ("Referencing generics in generic lists"), then you can indicate to the tools that VHDL-2008 is used.

A solution for VHDL-2002, is to make the ch_low and ch_hi arrays large enough to accommodate any value of num_chan, and then fill the unused with a dummy value, like (assuming num_chan is at most 10, using -1 as dummy value):

generic(
  num_chan : integer            := 2;
  ch_low   : int_arr_t(1 to 10) := (  1, 189, others => -1);
  ch_hi    : int_arr_t(1 to 10) := (127, 189, others => -1));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.