Record initialisieren

#1635464
Lesenswert?

Hi,

gibt es eine einfache Möglichkeit folgende Signale
in einem Rutsch alle auf den Wert '0' zu initialisieren?`
1
   type diag_typ is record 
2
      gap : std_logic;
3
      preamble : std_logic;
4
      data : std_logic;
5
      fcs : std_logic;
6
   end record;
7
   signal sdiag: diag_typ;

So geht es leider nicht:
1
   signal sdiag: diag_typ := (others => '0');

Danke im voraus,
Matthias
Moderator (Firma: Titel) Persönliche Seite #1635601
Lesenswert?

Du könntest ein Package anlegen, das die Recorddefinition enthält, dann 
kannst du den others-Trick machen. Obe dein gesamtes Design dann aber 
noch lesbar ist, das mußt du selber entscheiden...
1
library ieee;
2
use ieee.std_logic_1164.all;
3

4
package diag_comp is 
5
   type diag_typ is record 
6
      gap      : std_logic;
7
      preamble : std_logic;
8
      data     : std_logic;
9
      fcs      : std_logic;
10
   end record;
11
end package;
12

13

14
library IEEE;
15
use IEEE.STD_LOGIC_1164.ALL;
16
use IEEE.NUMERIC_STD.ALL;
17
use work.diag_comp.all;
18

19
entity RecordInit is
20
    Port (clk  : in  STD_LOGIC;
21
          data : out STD_LOGIC);
22
end RecordInit;
23

24
architecture Behavioral of RecordInit is
25
  signal sdiag: diag_typ := (others=>'0');     -- oder 
26
  signal sdiag: diag_typ := ('0','0','0','0'); -- alternativ
27
begin
28
  data <= sdiag.data; 
29
end Behavioral;

Und spätestens, wenn z.B. sowas drinsteht:
1
library ieee;
2
use ieee.std_logic_1164.all;
3

4
package diag_comp is 
5
   type diag_typ is record 
6
      gap      : std_logic;
7
      preamble : std_logic;
8
      data     : std_logic_vector(3 downto 0);
9
      fcs      : std_logic;
10
   end record;
11
end package;
Dann gilt wieder die Handschlagregel:
1
  signal sdiag: diag_typ := (data=>(others=>'0'), others=>'0');
2
  -- oder
3
  signal sdiag: diag_typ := ('0','0',(others=>'0'),'0');
Moderator (Firma: Titel) Persönliche Seite #1635621
Lesenswert?

Ich habe mir mal ein neues unberührtes Projekt angelegt und das Ganze 
genauer angeschaut: es klappt problemlos.
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.NUMERIC_STD.ALL;
4

5
entity RecordInit is
6
    Port (clk  : in  STD_LOGIC;
7
          gap  : in  STD_LOGIC;
8
          data : out STD_LOGIC);
9
end RecordInit;
10

11
architecture Behavioral of RecordInit is
12
   type diag_typ is record 
13
      gap : std_logic;
14
      preamble : std_logic;
15
      data : std_logic;
16
      fcs : std_logic;
17
   end record;
18
   signal sdiag: diag_typ := (others=>'0');
19
begin
20
  sdiag.gap  <= gap when rising_edge(clk); 
21
  sdiag.data <= sdiag.gap when rising_edge(clk); 
22
  data       <= sdiag.data when rising_edge(clk); 
23
end Behavioral;

Nur wenn sich im Record ein Vektor befindet, muß Hand angelegt werden:
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.NUMERIC_STD.ALL;
4

5
entity RecordInit is
6
    Port (clk  : in  STD_LOGIC;
7
          gap  : in  STD_LOGIC;
8
          data : out STD_LOGIC);
9
end RecordInit;
10

11
architecture Behavioral of RecordInit is
12
   type diag_typ is record 
13
      gap : std_logic;
14
      preamble : std_logic;
15
      data : std_logic_vector(3 downto 0);
16
      fcs : std_logic;
17
   end record;
18
   signal sdiag: diag_typ := (data=>(others=>'0'), others=>'0');
19
--  oder
20
--  signal sdiag: diag_typ := ('0','0',(others=>'0'),'0');
21
begin
22
  sdiag.gap     <= gap when rising_edge(clk); 
23
  sdiag.data(0) <= sdiag.gap when rising_edge(clk); 
24
  data          <= sdiag.data(0) when rising_edge(clk); 
25
end Behavioral;
Gast #1635687
Lesenswert?

Bei mir gibt es zu jeder Typdefinition gleich eine Defaultkonstante:
1
   type diag_typ is record 
2
      gap : std_logic;
3
      preamble : std_logic;
4
      data : std_logic_vector(3 downto 0);
5
      fcs : std_logic;
6
   end record;
7
   default_diag_constant : diag_typ :=(
8
      gap      => '0',
9
      preamble => '0',
10
      data     => (others <= '0'),
11
      fcs      => '0'
12
   );
13
...
14
   signal sdiag: diag_typ := default_diag_constant;

Falls man den Typ mal erweitert, muss man nicht gleich den ganzen Code 
anfassen und hoffen, das man alle Initialisierungen erwischt hat.

Duke
#1637115
Lesenswert?

Nachtrag:

Dies funktioniert auch mit verschachtelten Records in undefinierten 
Arrays :-)
1
   type data_typ is record
2
      data : bit_vector(7 downto 0);        -- data
3
      valid : bit;                          -- data_valid
4
      error : bit;                          -- data_error
5
   end record;
6
   constant default_data_typ_constant : data_typ :=(
7
      data     => (others => '0'),
8
      valid    => '0',
9
      error    => '0'
10
   );
11
   type frame_of_data_typ is array (natural range <>) of data_typ;
12

13
   -- Tx Data, Data_valid and underrun record
14
   type frame_typ is record
15
      data_columns : frame_of_data_typ(0 to C_MAX_FRAMELENGTH-1);
16
      bad_frame : boolean;                   
17
      framelength : natural;
18
      gap : natural;
19
   end record;
20
   constant default_frame_typ_const : frame_typ :=(
21
      data_columns => (others => default_data_typ_constant),
22
      bad_frame => false,
23
      framelength => 0,
24
      gap => 0
25
   );

Matthias

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren