2
\$\begingroup\$

I want to read input values from a file and store them in an array

I have defined a custom array type in a package as :

TYPE qit IS ('0', '1', 'Z', 'X');
...
Type qitArray IS Array(Natural Range <>) OF qit;

and I have a procedure defined as :

Procedure ReadFromFile(Signal Output : OUT qitArray; File_Name : IN String; Delay : Time);

In Test Bench, I have declared a qitArray signal and I have passed it to procedure as parameter like this :

 Constant Input_FName : String := "input_file.txt";
 ...
 Signal Output : qitArray;
Begin
  ReadFromFile(Output, Input_FName, 20 ns);
  ...
End;

there is no compile error on the package file, but when I want to compile Test Bench, an error says :

Array type of "Output" does not have an index constraint

The array length is unknown

How can I use an unknown-length array type ( or dynamic array ) as parameter in a procedure ?

\$\endgroup\$
2
  • \$\begingroup\$ You cannot have arrays of unknown size. It's a hardware description language, everything has a size. So figure out what's the maximum size of your array. Either use one of your 4 values as empty/unused or define a fivths value or return a second parameter size/length like in C. \$\endgroup\$
    – Paebbels
    Commented May 1, 2016 at 17:09
  • \$\begingroup\$ Could you provide an example of your input file and clarify which characteristics of it will vary? (e.g., number of lines, length of each line, etc.) \$\endgroup\$
    – rick
    Commented May 3, 2016 at 21:29

1 Answer 1

1
\$\begingroup\$

Your procedure is fine, it can accept any size qitArray. But when you declare your signal in your test bench, which you later pass to the procedure, it has to have a well defined length.

\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.