file handle

Discussion in 'VHDL' started by FP, Apr 11, 2008.

  1. FP

    FP Guest

    I have written a code in VHDL which will read input from 1 file,
    process it and write output in a different file. I have used 2 file
    handles, 1 for read and write each.

    procedure get
    uses file handle for read
    end procedure get;

    architecture
    begin
    open file
    get command
    close file
    end architecture

    My question is, should file handle be declared as variable or signal.
    Is it 100% ok to use it as a signal.
    I have been using different functions within the procedure which
    modify the file handle. I dont think it should be defined as a signal.

    If defined as a variable then, I am running into problems of opening
    and closing the file. I dont want to open and close the file every
    time i call the procedure.

    Also, I am calling the get procedure more than once.

    Any suggestions?
     
    FP, Apr 11, 2008
    #1
    1. Advertising

  2. FP

    FP Guest

    On Apr 11, 2:45 pm, Jonathan Bromley <>
    wrote:
    > On Fri, 11 Apr 2008 10:55:58 -0700 (PDT), FP wrote:
    > >My question is, should file handle be declared as variable or signal.
    > >Is it 100% ok to use it  as a signal.
    > >I have been using different functions within the procedure which
    > >modify the file handle. I dont think it should be defined as a signal.

    >
    > >If defined as a variable then, I am running into problems of opening
    > >and closing the file.  I dont want to open and close the file every
    > >time i call the procedure.

    >
    > >Also, I am calling the get procedure more than once.

    >
    > A FILE object in VHDL is neither a variable nor a signal.
    >
    > As you've discovered, files generally will be closed when
    > the file object goes out of scope - for example, if you
    > declare it in a procedure, then the file will close when
    > the procedure exits.  So you probably want to declare the
    > file some place where its lifetime will be the life of
    > the simulation.  The declarative region of a process is
    > usually a smart place to put it; you probably don't want
    > more than one process messing with any given file,
    > except possibly INPUT or OUTPUT.  However, you can declare
    > the file in the declarative region of your architecture
    > if you really want it to be accessible to any process.
    >
    > Don't forget you can close any file under program
    > control any time you like, using file_close(F), so you
    > lose little by giving the file object static lifetime.
    >
    > Files can be passed as parameters to procedures, so it's
    > easy to make procedures that read or write a file.
    > Such procedures can go in a package if you wish.  The
    > STD.TEXTIO package is a good example - think about the
    > READLINE and WRITELINE procedures.
    >
    > You can even declare a file in a package if you wish -
    > that's how INPUT and OUTPUT are declared.  That's
    > potentially useful because it means that procedures
    > in the package can be written with no file parameter
    > at all - handy for things like writing to a debug log
    > that is sure to be global to the simulation.
    >
    > Here's a simple example that may help to get you started.
    >
    >   use std.textio.all;
    >   package INT_SCRIBBLER is
    >     procedure SCRIBBLE(file F: text; N: integer);
    >   end package;
    >   package body INT_SCRIBBLER is
    >     procedure SCRIBBLE(file F: text; N: integer) is
    >       variable L: line;
    >     begin
    >       write(L, string'("*** my number is "));
    >       write(L, N);
    >       write(L, string'(" ***"));
    >       writeline(F, L);
    >     end;
    >   end;
    >
    >   use std.textio.all;
    >   use work.INT_SCRIBBLER.all;
    >   entity TEST_INT_SCRIBBLER is end;
    >   architecture A of TEST_INT_SCRIBBLER is
    >   begin
    >     process
    >       file INTFILE: text;
    >       variable X: integer;
    >     begin
    >       file_open(INTFILE, "junk.txt", write_mode);
    >       X := 5;
    >       while X < 20 loop
    >         SCRIBBLE(INTFILE, X);
    >         X := X + 3;
    >       end loop;
    >       file_close(INTFILE);
    >       wait;
    >     end process;
    >   end;
    >
    > Hope this helps
    > --
    > Jonathan Bromley, Consultant
    >
    > DOULOS - Developing Design Know-how
    > VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
    >
    > Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
    > ://www.MYCOMPANY.com
    >
    > The contents of this message may contain personal views which
    > are not the views of Doulos Ltd., unless specifically stated.


    Thank you Jonathan for such a nice expalination. I have solved my
    problem as per your suggestion.
    I opened the file in the process and assigned the value to the
    procedure through one of the paramteres and returned the updated value
    back to the process by making the file handle of type inout. It works
    great.
     
    FP, Apr 14, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dietrich
    Replies:
    1
    Views:
    668
    Joe Smith
    Jul 22, 2004
  2. Apollyon

    File pointer to file handle

    Apollyon, May 2, 2004, in forum: C Programming
    Replies:
    5
    Views:
    964
    CBFalconer
    May 2, 2004
  3. Leon
    Replies:
    2
    Views:
    564
  4. =?ISO-8859-1?Q?KLEIN_St=E9phane?=
    Replies:
    3
    Views:
    475
    hanumizzle
    Oct 6, 2006
  5. loial

    Get file name from file handle

    loial, Feb 17, 2009, in forum: Python
    Replies:
    1
    Views:
    433
Loading...

Share This Page