Initializing an array of records in VHDL
Asked Answered
C

2

9

I have an record defined as follows

type ifx_t is
record
  data                        : std_logic_vector(127 downto 0);
  address                     : std_logic_vector (19 downto 0); 
  WrReq                       : std_logic;-- 
  RdReq                       : std_logic; --
end record;
type Array_ifx_t is array (0 to 2) of ifx_t;

And I have to initialize an instance of this array of records and I have tried the following way and it doesn't work

signal pair_in       : Array_ifx_t:= (others =>((others =>'0'),(others=>'0'),'0','0')); 

Kindly help.

Carnegie answered 17/12, 2013 at 9:27 Comment(4)
What tool are you using and what error message do you see ? It works fine in ModelSim compile.Tame
In this the error message is "Formal <pair_in> has no actual or default value" and the code is complied in "ISim Simulator: Behavioral Check Syntax".Carnegie
Just tried ISim 14.6 (nt64), which passes "Behavioral Check Syntax" run without errors. Maybe the error is due to some relation with other code. You could try to cut the module down to only entity, architecture, and the code above, and then see if passes. Otherwise, please post the entire cut down module here.Tame
The issue was due to not mapping the port where pair_in was supposed to.Carnegie
T
9

As said in the comment, ModelSim work when compiling the code from question with ModelSim. However, other tools may be more strict about using a typed value for elements in Array_ifx_t.

For a typed assign and use of named record elements, which I think gives getter overview and avoid mistakes by position references, you can make the initialization with:

constant IFX_T_0S : ifx_t := (data => (others =>'0'),
                              address => (others=>'0'),
                              WrReq => '0',
                              RdReq => '0');

signal pair_in : Array_ifx_t:= (others => IFX_T_0S);
Tame answered 17/12, 2013 at 9:52 Comment(4)
Thanks for the reply. Still its not working. The error message is "Formal <pair_in> has no actual or default value"Carnegie
The clue is the word "Formal" ... there's code you're not telling us about, a port or procedure parameter somewhere called "pair_in" which isn't properly connected to this signal (or otherwise initialised. Find that and add it to the question.Kalahari
And it sounds like a) There isn't a default expression where pair_in is declared as a "formal port or formal generic of a design entity, a block statement, or a formal parameter of a subprogram" (LRM glossary for formal) and it's not driven. Are you using the name pair_in in more than one place?Ewald
The issue was due to not mapping the port where pair_in was supposed to.Carnegie
E
2

My initial reaction to seeing the aggregate in your default value for pair_in was that there were too many 'others', so I independently wrote one using the record type declaration itself:

library ieee;
use ieee.std_logic_1164.all;

package some_record is

    type ifx_t is
    record
      data                        : std_logic_vector(127 downto 0);
      address                     : std_logic_vector (19 downto 0); 
      WrReq                       : std_logic;-- 
      RdReq                       : std_logic; --
    end record;
    type Array_ifx_t is array (0 to 2) of ifx_t;
    -- positional association in an aggregate used for initialization:
    signal pair_in:    ifx_t := ((others => '0'), (others => '0'),'0','0');
end package;

And this analyzed successfully. An aggregate has two types of association, positional or named. The above default value expression is positional. With a named association:

signal pair_in:    ifx_t := -- named association of record elements:
                           (
                             data => (others => '0'), 
                             address => (others =>'0'), 
                             WrReq => '0',
                             RdReq => '0'
                           );

You'll notice this bears an uncanny resemblance to the value expression found in Morten's accepted answer's constant declaration, and actually tells the story of compatibility for an aggregate expression.

An aggregate compatible with a record type contains a value expression that is compatible with each element of the record type. This is done for the array elements data and address by providing aggregates for their default values, while WrReq and RdReq are provided with their default values directly.

The extra others statement found in the original attempt would have been appropriate had pair_in been a composite type comprised of an array comprised of ifx_t record type elements.

The LRM (e.g. IEEE Std 1076-1993) has a section on Expressions, a subsection on Aggregates with a further subsection on Record aggregates.

There's also a section on Types, a subsection on Composite types, with a further subsection on Record types.

Ewald answered 17/12, 2013 at 19:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.