textio - line als index für array verwenden

Gast #3012552
Lesenswert?

Hallo,

ich habe mal einen neuen Thread erstellt, weil er thematisch nicht mehr 
wirklich in meinen anderen Thread passt.

Ich habe die folgende Datei von stefanvhdl.com etwas modifiziert.
http://www.stefanvhdl.com/vhdl/html/file_read.html

Ziel soll es sein ohne Takt, direkt sequentuell, alle Zeilen in ein 
Array zu schreiben, damit ich es von dort zu meinen Stimuli Registern 
mappen kann.

So wie ich es verstanden habe, wird die Variable l : line automtaisch 
mit jedem loop-Durchlauf hochgezählt, bis end-of-file erreicht ist. Das 
wollte ich ausnutzen um die line-Variable als Index für mein Array zu 
verwenden.
Ein Index kann natürlich nur integer sein. (siehe markierte Zeile 33)

Wie also kann ich line => integer umwandeln und somit mein Vorhaben 
übersichtlich gestalten?
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use std.textio.all;
4
use work.txt_util.all;
5
 
6
entity FILE_READ is
7
  generic ( stim_file:       string  := "sim.dat" );
8
  port(CLK              : in  std_logic;
9
       RST              : in  std_logic;
10
       ...
11
       EOG              : out std_logic);
12
end FILE_READ;
13
    
14
architecture read_from_file of FILE_READ is
15
  
16
  file stimulus: TEXT open read_mode is stim_file;
17

18
  type text_array is array (0 to 5) of std_logic_vector(4 downto 0);
19
  signal sim_text : text_array;
20

21
begin
22
  -- read data and control information from a file
23
  receive_data: process
24
     variable l: line;
25
     variable s: string(y'range);
26
  begin                                       
27
     EOG <= '0';
28
     wait until RST='1';               -- wait for Reset to complete
29
     wait until RST='0';
30
     while not endfile(stimulus) loop  -- read digital data from input file
31
       readline(stimulus, l);      
32
       read(l, s);
33
       ---------------------------------------
34
       sim_text(l) <= to_std_logic_vector(s);   -- Zeile 33
35
       ---------------------------------------
36
     end loop;
37
     print("I@FILE_READ: reached end of "& stim_file);
38
     EOG <= '1';
39
     wait;
40
end process receive_data;
41

42
end read_from_file;

Vielen Dank!
Alex
Gast #3012570
Lesenswert?

Hallo,

ja klar, aber ich dachte ich kann den Wert von line irgendwie verwenden, 
das würde die Sache erheblich vereinfachen und übersichtlicher machen.

So geht es schon:
1
  receive_data: process
2
     variable l     : line;
3
     variable index : integer := 0;
4
     variable s     : string(y'range);
5
  begin                                       
6
     EOG <= '0';
7
     wait until RST='1';               -- wait for Reset to complete
8
     wait until RST='0';
9
     while not endfile(stimulus) loop  -- read digital data from input file
10
       readline(stimulus, l);      
11
       read(l, s);
12
       ---------------------------------------
13
       sim_text(index) <= to_std_logic_vector(s);   -- Zeile 33
14
       ---------------------------------------
15
       index := index +1;
16
     end loop;
17
     print("I@FILE_READ: reached end of "& stim_file);
18
     EOG <= '1';
19
     wait;
20
end process receive_data;

So ist mein Eingabe-File auf maximal 2.147.483.648 Zeilen beschränkt, 
ich hoffe das reicht aus xD
(Firma: www.dossmatik.de) #3013394
Lesenswert?

Es gibt den Typ character das ist eine String mit einer position.
setze s auf den Type character und lese die Zeile in einer Schleife aus.
Mit String in VHDL habe ich auch keine Ahnung aber mit Charakter wird es 
wieder klarer und es hat bis jetzt immer ausgereicht.


ASCII zu integer ibt es nicht. Die Lösung ist die Funktion 
http://www.stefanvhdl.com/vhdl/vhdl/txt_util.vhd



ASCII zu integer ibt es nicht. Bei Stefan

   -- functions to convert strings into other formats
    --------------------------------------------------

    -- converts a character into std_logic
    function to_std_logic(c: character) return std_logic;

    -- converts a string into std_logic_vector
    function to_std_logic_vector(s: string) return std_logic_vector;





Ich habe noch ein Beispiel für dich, wie man hexfiles in einer Testbench 
laden kann. Nur als Anregung.



1
  elsif clk'event and clk='1' then
2
    if not endfile (in_file) then
3
      read(in_file,a);
4
    end if;
5
    data_in<=to_unsigned(character'pos(a),8);--very tricky the conversation
6
  --  wr<='1';
7
 
8
end if;

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