Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > file handle

Reply
Thread Tools

file handle

 
 
FP
Guest
Posts: n/a
 
      04-11-2008
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?
 
Reply With Quote
 
 
 
 
FP
Guest
Posts: n/a
 
      04-14-2008
On Apr 11, 2:45*pm, Jonathan Bromley <(E-Mail Removed)>
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
> (E-Mail Removed)://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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Package to handle table text render (handle space or tab betweenthe columns) ? =?ISO-8859-1?Q?KLEIN_St=E9phane?= Python 3 10-06-2006 08:46 AM
Possible to handle web requests without an ASPX page? i.e. have DLL handle request. jdlwright@shaw.ca ASP .Net 2 05-31-2005 05:42 PM
how to handle command line output(not terminal handle) Leon Python 2 11-04-2004 05:16 AM
File Handle Reading Blues: Rereading a File Handle for Input Dietrich Perl 1 07-22-2004 10:02 AM
File pointer to file handle Apollyon C Programming 5 05-02-2004 11:35 AM



Advertisments