Forum: FPGA, VHDL & Co. VHDL Daten aus Datei


von Wiplash4 (Gast)


Lesenswert?

Hallo
Folgendes SetUp: Ich habe eine Testbench und eine Datei mit Signal 
werten.
Die Testbench soll die Daten aus der Datei entnehmen und sie den 
Signalen zuweisen. Dabei sollen eventuelle Kommentare und Tabs aus der 
Datei gefiltert werden. DIe Inputdatei sieht aus wie folgt:

## op_a
#  Step  Val
  1  1
  2  1
  3  0
  4  1
  5  1
  6  0
  7  1
  8  1
  9  0
  10  1
  11  1
  12  0
  13  1
  14  1
  15  0
  16  1
  17  1
  18  0
  19  1
  20  1
  21  0
  22  1
  23  1
  24  0
# ob_b
#  Step  Val
  1  1
  2  1
  3  0
  4  1
  5  1
  6  0
  7  1
  8  1
  9  0
  10  1
  11  1
  12  0
  13  1
  14  1
  15  0
  16  1
  17  1
  18  0
  19  1
  20  1
  21  0
  22  1
  23  1
  24  0

# carry_in
#  Step  Val
  1  1
  2  1
  3  0
  4  1
  5  1
  6  0
  7  1
  8  1
  9  0
  10  1
  11  1
  12  0
  13  1
  14  1
  15  0
  16  1
  17  1
  18  0
  19  1
  20  1
  21  0
  22  1
  23  1
  24  0

Die einzig wichtigen Werten sind dabei die Werte unter Val! Der Rest 
soll via VHDL verworfen werden.

Weiss jemand wie?

von zephyr (Gast)


Lesenswert?

Stichwort: textio

Hier ein kleines Beispiel:
1
LIBRARY ieee;
2
USE ieee.std_logic_1164.all;
3
USE ieee.std_logic_arith.all;
4
USE ieee.std_logic_textio.all;                            -- Bibliotheken für TextIO / FileIO
5
USE std.textio.all;
6
7
ENTITY FileIO IS
8
  PORT(
9
    Start_fh         : OUT std_logic;                     -- Startet den FH, sobald alle Signale anliegen ( Sys_Clk abhängig ) -> DL_transmit_start
10
    Done_fh          : IN  std_logic;                     -- Rückmeldung von FH, dass dessen Signale anliegen ( Sys_Clk ) -> DL_frame_arrive
11
    DLL_err          : IN  std_logic;                     -- Fehler auf DLL Ebene
12
    Sys_Clk          : IN  std_logic;                     -- Clock
13
    
14
    IO_Addr_fh       : OUT std_logic_vector(4 downto 0);  -- Parameter Addr
15
    IO_Data_fh_write : OUT std_logic_vector(7 downto 0);  -- Schreibdaten
16
    IO_Data_fh_read  : IN  std_logic_vector(7 downto 0);  -- Lesedaten
17
    IO_DL_Channel_fh : OUT std_logic_vector(1 downto 0);  -- DLL Channel
18
    IO_DL_ftype_fh   : OUT std_logic_vector(1 downto 0);  -- Frame Type
19
    DL_Event_fh      : IN  std_logic;                     -- DLL Event im Slave FH aufgetreten
20
    RW_fh            : OUT std_logic                      -- RW_CMD
21
    );
22
END FileIO ;
23
24
--
25
ARCHITECTURE behaviour OF FileIO IS
26
BEGIN
27
  main : PROCESS
28
  
29
  PROCEDURE read_file IS
30
  
31
    VARIABLE break : boolean := false;                    -- Zur Ausgabe von Fehlermeldung, wenn Datei nicht lesbar
32
    VARIABLE space : character;                           -- Leerzeichen
33
    VARIABLE lin   : line;
34
    VARIABLE nr    : string(1 to 2);                      -- Zeilen-Nummer
35
    VARIABLE cmd   : string(1 to 2);                      -- CMD
36
    VARIABLE addr  : std_logic_vector(4 downto 0);        -- Addresse
37
    VARIABLE data  : std_logic_vector(7 downto 0);        -- Daten
38
    
39
    FILE input_file : text;
40
    
41
    BEGIN
42
      file_open(input_file, "fileio_test_input.txt", read_mode);
43
      
44
      WHILE(endfile(input_file) = false) LOOP
45
        readline(input_file, lin);
46
        read(lin, nr, break);
47
        ASSERT break REPORT "Error reading input file!";
48
        IF(nr(1 to 2) /= "--") THEN
49
          read(lin, space);
50
          read(lin, cmd);
51
          read(lin, space);
52
          hread(lin, addr);
53
          read(lin, space);
54
          hread(lin, data);
55
          
56
          CASE cmd IS
57
            WHEN "wr"   => RW_fh <= '1';             
58
                           IO_Data_fh_write <= data;
59
            WHEN "rd"   => RW_fh <= '0';               
60
            WHEN OTHERS => NULL;
61
          END CASE;
62
          
63
          IO_Addr_fh <= addr;
64
          
65
          WAIT UNTIL Sys_Clk'EVENT AND Sys_Clk = '1';     
66
          Start_fh <= '1';
67
          WAIT FOR 20ns;
68
          Start_fh <= '0';
69
        END IF;
70
      END LOOP;
71
      file_close(input_file);
72
    END read_file;
73
    
74
END ARCHITECTURE behaviour;

Die Eingabe-Datei hatte dabei das folgende Format.

--*-----------------------------------------------------------*
--* Format-Beispiel:                                          *
--*                                                           *
--* 53 wr 1C AA 2 0                                           *
--*  |  |  |  | | |                                           *
--*  +--------------> Nr. der Testzeile bzw. "--" als Kennung *
--*     |  |  | | |     für einen Kommentar                   *
--*     +-----------> CMD-Code (wr = write, rd = read)        *
--*        +--------> Paramter-Addr. (5 Bit)                  *
--*           +-----> Datenwert (8 Bit), bei wr der zu        *
--*             | |     schreibende Wert, bei rd der          *
--*             | |     erwartete Wert                        *
--*             +---> DL-Channel                              *
--*               +-> Frame Type                              *
--*************************************************************
00 wr 01 55 1 0
01 rd 01 55 1 0
02 wr 0E AC 1 0
03 rd 14 DC 1 0

Gruß zephyr

von The D. (wiplash4)


Lesenswert?

Hey.
Danke Ihnen fuer die Antwort...

von The D. (wiplash4)


Lesenswert?

Noch eine Frage: Wie kann man eine Datei lesen um in die gleiche Datei 
zu schreiben?

# Eingabedatum Ausgabedatum
  in0          out0

Wobei in0 gelesen wird, dann macht VHDL etwas und dann schreibt VHDL 
out0 in die Reihe von AUsgabedatum.

von Wiplash (Gast)


Lesenswert?

ranju@ins_amba:/srv/GHDL_training$ ghdl -a --ieee=synopsys FILE_IO.vhdl
FILE_IO.vhdl:32:24: no declaration for "print"
FILE_IO.vhdl:32:30: no declaration for "out_file"
FILE_IO.vhdl:33:24: no declaration for "print"
FILE_IO.vhdl:33:30: no declaration for "out_file"
FILE_IO.vhdl:36:53: no declaration for "lin"
FILE_IO.vhdl:38:39: no declaration for "break"
FILE_IO.vhdl:40:35: no declaration for "nr"
FILE_IO.vhdl:41:45: no declaration for "lin"
FILE_IO.vhdl:41:50: no declaration for "piece"
FILE_IO.vhdl:42:48: no declaration for "to_std_logic"
FILE_IO.vhdl:43:45: no declaration for "lin"
FILE_IO.vhdl:43:50: no declaration for "piece"
FILE_IO.vhdl:44:48: no declaration for "to_std_logic"
FILE_IO.vhdl:45:45: no declaration for "lin"
FILE_IO.vhdl:45:50: no declaration for "piece"
FILE_IO.vhdl:46:48: no declaration for "to_std_logic"
FILE_IO.vhdl:47:45: no declaration for "lin"
FILE_IO.vhdl:47:50: no declaration for "piece"
FILE_IO.vhdl:48:52: no declaration for "to_std_logic"
FILE_IO.vhdl:49:55: no declaration for "piece"
FILE_IO.vhdl:50:40: port "summe" can't be assigned
FILE_IO.vhdl:50:49: no declaration for "chr"
FILE_IO.vhdl:51:55: no declaration for "piece"
FILE_IO.vhdl:52:40: port "carry_out" can't be assigned
FILE_IO.vhdl:52:53: no declaration for "chr"
FILE_IO.vhdl:53:55: no declaration for "piece"
FILE_IO.vhdl:23:26:warning: procedure "read_file" is never referenced
/usr/lib/ghdl/bin/ghdl: compilation error


Das kam dabei raus.
Ach und wie stellt man synopsis automatisch ein?
Gruesse

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Wiplash schrieb:
> Das kam dabei raus.
Wobei?
Welchen Quelltext hast du wie und mit welchen Versionen damit übersetzt?

Ranjeet Kuruvilla schrieb:
> Noch eine Frage: Wie kann man eine Datei lesen um in die gleiche Datei
> zu schreiben?
Datei zum Lesen öffen.
Datei komplett einlesen.
Datei schliessen.
Datei zum Überschreiben öffnen.
Datei komplett neu überschreiben.
Datei schliessen.

von Wiplash (Gast)


Lesenswert?

Hallo

Hier der QUelltext

LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_textio.all;                            -- 
Bibliotheken für TextIO / FileIO
USE std.textio.all;

ENTITY FileIO IS
  PORT(
    CLK         : IN  std_logic;                     -- Clock
    STEP    : OUT std_logic;                     -- RW_CMD
    OP_A    : OUT std_logic;
    OP_B    : OUT std_logic;
    CARRY_IN    : OUT std_logic;                     -- RW_CMD
    SUMME      : IN std_logic;                      -- RW_CMD
    CARRY_OUT   : IN std_logic                      -- RW_CMD
   );
END ENTITY;

ARCHITECTURE behaviour OF FileIO IS
BEGIN
  main: PROCESS

    PROCEDURE read_file IS
      VARIABLE lin_in    : line;    -- Zeile von Datei
      VARIABLE lin_out  : line;    -- Zeile in Datei
      FILE input_file   : text; -- Input
      FILE output_file   : text; -- Output

    BEGIN
      file_open(input_file, "Input.piece.log", read_mode); -- Open a 
file for reading the file.
      file_open(output_file, "Output.piece.log", write_mode); -- Open a 
file for reading the file.
      print(out_file, "## Output piece for all signals\n");
      print(out_file, "#\tStep\tsumme\tcarry_out");

      WHILE(endfile(input_file) = false) LOOP
        readline(input_file, lin); -- Read the line and save it in lin

        ASSERT break REPORT "Error reading input file!";

        IF(nr(1 to 2) /= "#") THEN -- If the line opens with # or ##, 
than skip the line!
          read(lin, piece); -- HIGH or LOW
          STEP <= to_std_logic(piece);
          read(lin, piece); -- Tab between left and step
          OP_A <= to_std_logic(piece);
          read(lin, piece); -- Tab between step and val
          OP_B <= to_std_logic(piece);
          read(lin, piece); -- Tab between step and val
          CARRY_IN <= to_std_logic(piece);
          write(lin_out, piece & "\t");
          SUMME <= chr(piece);
          write(lin_out, piece & "\n");
          CARRY_OUT <= chr(piece);
          write(lin_out, piece & "\n");
        ELSE NULL;
        END IF;

        writeline(output_file, lin_out);

      END LOOP;
      file_close(input_file);
      file_close(output_file);

    END PROCEDURE;
    begin
    end process;

END ARCHITECTURE;


Dieser Queltext wurde verwendet.

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Lass mich raten:
Du hast das alles irgendwoher ZUSAMMENKOPIERT (z.B. von 
http://www.stefanvhdl.com/vhdl/html/file_write.html) und nicht im 
Mindesten eine Ahnung, was du da tust. Richtig?

Das print z.B. ist nicht in den Packages definiert, die du eingebunden 
hast. Es ist eine Funktion im txt_util Package, das dort erwähnt wird:
Beitrag "Re: Rechnen im Hex-Dezimalsystem mit Dezimalanzeige"
Und dort herunter zu laden ist:
http://www.stefanvhdl.com/vhdl/vhdl/txt_util.vhd

Aber ich schlage vor, du fängst einfach mal dort an:
http://www.stefanvhdl.com/vhdl/html/index.html
Und versuchst zu VERSTEHEN, was du da gerade machst.

von Ranjeet Kuruvilla (Gast)


Lesenswert?

Joa... dieser Quellcode wurde oben aufgefuehrt. Aber du bist mit deinem 
Raten nicht weit entfernt:), obwohl ich schon weiss, was die einzelnen 
Funktionen tun und mit VHDL arbeite ich regelmaessig, aber FileIO ist 
mir vollkommen fremd.

Andere Frage: wo werden diese Packages installiert?

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Ranjeet Kuruvilla schrieb:
> Andere Frage: wo werden diese Packages installiert?
Die werden nicht installiert, sondern sind Teil deines Projekts. Sie 
müssen also mitcompiliert werden.

von Ranjeet Kuruvilla (Gast)


Lesenswert?

Ja, aber wie? Das sind Probleme die ich noch nicht hatte...

von René D. (Firma: www.dossmatik.de) (dose)


Lesenswert?

Ranjeet Kuruvilla schrieb:
> Ja, aber wie? Das sind Probleme die ich noch nicht hatte...

Du nutzt GHDL!?

Die schnelle Variante, alle Dateien in ein Verzeichnis packen.
Alle VHDL Dateien in GHDL importieren und mit zwei weiteren Aufrufe 
durchstarten.



ghdl -i *.vhd

ghdl -m -g  --warn-unused --ieee=synopsys tb_vga

ghdl -r tb_vga --disp-tree=inst --stop-time=20000ns --wave=vga.ghw


Siehe auch in
http://www.dossmatik.de/ghdl/ghdl_unisim.pdf

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.