Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > reading files in vhdl

Reply
Thread Tools

reading files in vhdl

 
 
paris
Guest
Posts: n/a
 
      04-21-2004
hi guys,

im having some trouble with reading from a file, actually the thing is the
opening part.
the problem is that i "dont" know the name of the file to read before
compiling, that is because i've a "configuration" file where i give
commands, one of them being the name of the "input" file.

i know i could use a function, but that only works when i've a small amount
of data to read, cause otherwise, storing a HUGE array slows down the
simulation, without saying that modelsim tells me that i has not enough
memory and will start paging to disk and after a while it says that i got
completely out of memory.

Simulation works perfect if i read one line (of the input file) at the time,
but that means that the filename has to be written on the code (at least
that's how i've been doing, by using ' file fp : TEXT is in "input.dat"; ')

now i need to open an arbitrary file, so i tried "file_open(fp,
filenameString, READ_MODE);" the problem is that somehow it doesnt work, as
it seems that if i open the file in one process (i have to open the file
just once and read it till the end of the file at every rising_edge(clk), so
that's two processes). It doesnt work cause it seems that the file is
"closed" outside the process it was opened (i think i even read about that
issue).

Also i cant find "file_open" declaration.

i also tried with a process like this: (im at home now, so i dont have the
real sources, but i cant sleep so im writing to ask for help please)

process
begin

if (filenameString /= nothing) then
file_open(fp, filenameString, READ_MODE);

while (not endfile(fp)) loop
wait until rising_edge(clk);
read(fp, data);
etc, etc
end loop;
file_close(fp);
end if;
end process;

that didnt work either, im not sure if it was because of the file_open part
(i also did a check on the opening, it was succesful) or because the process
get in an infinite loop, modelsim just stop responding (i think that endfile
might return false if the file is not open, giving rise to the infinite
loop, but the loop would at least be "waiting" for "clk" and it would
actually read the data, but that doesnt happen). The file might get closed
once "out" the process (like when another process gets executed) or
something, i have no clue...

do any of you knows or have faced already this kind of situation? namely,
reading a file whose name's specified after compilation (by another file)
line by line (that is, not using a function to read a whole chunk of data
and storing it in an array)

any comments will be appreciated, thanks



Paris




 
Reply With Quote
 
 
 
 
Jim Lewis
Guest
Posts: n/a
 
      04-21-2004
Paris,
None of your solutions are that far away fronm working.

> i know i could use a function, but that only works when i've a small amount
> of data to read, cause otherwise, storing a HUGE array slows down the
> simulation, without saying that modelsim tells me that i has not enough
> memory and will start paging to disk and after a while it says that i got
> completely out of memory.

You could use a procedure and never exit.
Pass out one set of data values on every clock.


> now i need to open an arbitrary file, so i tried "file_open(fp,
> filenameString, READ_MODE);" the problem is that somehow it doesnt work, as
> it seems that if i open the file in one process (i have to open the file
> just once and read it till the end of the file at every rising_edge(clk), so
> that's two processes). It doesnt work cause it seems that the file is
> "closed" outside the process it was opened (i think i even read about that
> issue).

I am guessing that your file handle declaration is in the process and
not the architecture. If the file handle declaration were in the
architecture, I suspect that this would work. With your file handle
declaration in a process, only the process that declares the file handle
can see it.


> Also i cant find "file_open" declaration.

It is built into the language.

> i also tried with a process like this: (im at home now, so i dont have the
> real sources, but i cant sleep so im writing to ask for help please)
>
> process
> begin
>
> if (filenameString /= nothing) then
> file_open(fp, filenameString, READ_MODE);
>
> while (not endfile(fp)) loop
> wait until rising_edge(clk);
> read(fp, data);
> etc, etc
> end loop;
> file_close(fp);


else
wait ;

> end if;
> end process;

This can work too, however, when filenameString = nothing,
then the process goes into an infinite loop.
If filenameString = nothing means do nothing forever,
add an else branch with a wait statement in it as shown
above.


Cheers,
Jim

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
Jim Lewis
Director of Training private.php?do=newpm&u=
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~

 
Reply With Quote
 
 
 
 
jtw
Guest
Posts: n/a
 
      04-23-2004
If you need to open an arbitrary file (like I often want to do), define it
as a generic, with a default value. When you call the simulator (I've
worked with Modelsim doing this), provide the generic as part of the call.
E.g., vsim tb_config -ggeneric1=generic1value ... (other options.)

Then you can set up a script (or batch file) with whatever value you need
for the generic-- or just manually type in every time you run it.

Jason
"paris" <> wrote in message
news:c64kuc$ut8$...
> hi guys,
>
> im having some trouble with reading from a file, actually the thing is the
> opening part.
> the problem is that i "dont" know the name of the file to read before
> compiling, that is because i've a "configuration" file where i give
> commands, one of them being the name of the "input" file.
>
> i know i could use a function, but that only works when i've a small

amount
> of data to read, cause otherwise, storing a HUGE array slows down the
> simulation, without saying that modelsim tells me that i has not enough
> memory and will start paging to disk and after a while it says that i got
> completely out of memory.
>
> Simulation works perfect if i read one line (of the input file) at the

time,
> but that means that the filename has to be written on the code (at least
> that's how i've been doing, by using ' file fp : TEXT is in "input.dat";

')
>
> now i need to open an arbitrary file, so i tried "file_open(fp,
> filenameString, READ_MODE);" the problem is that somehow it doesnt work,

as
> it seems that if i open the file in one process (i have to open the file
> just once and read it till the end of the file at every rising_edge(clk),

so
> that's two processes). It doesnt work cause it seems that the file is
> "closed" outside the process it was opened (i think i even read about that
> issue).
>
> Also i cant find "file_open" declaration.
>
> i also tried with a process like this: (im at home now, so i dont have the
> real sources, but i cant sleep so im writing to ask for help please)
>
> process
> begin
>
> if (filenameString /= nothing) then
> file_open(fp, filenameString, READ_MODE);
>
> while (not endfile(fp)) loop
> wait until rising_edge(clk);
> read(fp, data);
> etc, etc
> end loop;
> file_close(fp);
> end if;
> end process;
>
> that didnt work either, im not sure if it was because of the file_open

part
> (i also did a check on the opening, it was succesful) or because the

process
> get in an infinite loop, modelsim just stop responding (i think that

endfile
> might return false if the file is not open, giving rise to the infinite
> loop, but the loop would at least be "waiting" for "clk" and it would
> actually read the data, but that doesnt happen). The file might get closed
> once "out" the process (like when another process gets executed) or
> something, i have no clue...
>
> do any of you knows or have faced already this kind of situation? namely,
> reading a file whose name's specified after compilation (by another file)
> line by line (that is, not using a function to read a whole chunk of data
> and storing it in an array)
>
> any comments will be appreciated, thanks
>
>
>
> Paris
>
>
>
>



 
Reply With Quote
 
Ajeetha Kumari
Guest
Posts: n/a
 
      04-23-2004
Hi,
I used to do some thing similar, but then I figured out yet another
easier way (atleast I find so). I refernce to a file named say
"image_data.txt" inside my TB. Using a script around my simulator, I
use UNIX links to simulate multiple images, infact you could do some
thing like:


ln -s image_0.txt image_data.txt
run
# End of 1 sim with image_0
reset
rm -f image_data.txt
ln -s image_1.txt image_data.txt
run
# Second simulation with image 1!!

I did this using NCSIM - FYI.

HTH,
Ajeetha,
http://www.noveldv.com
Co-Author: Using PSL/SUGAR for Formal and Dynamic Verification 2nd
Edition.

"jtw" <wrightjt @hotmail.invalid> wrote in message news:<h21ic.54437$. com>...
> If you need to open an arbitrary file (like I often want to do), define it
> as a generic, with a default value. When you call the simulator (I've
> worked with Modelsim doing this), provide the generic as part of the call.
> E.g., vsim tb_config -ggeneric1=generic1value ... (other options.)
>
> Then you can set up a script (or batch file) with whatever value you need
> for the generic-- or just manually type in every time you run it.
>
> Jason
>

 
Reply With Quote
 
Sajan
Guest
Posts: n/a
 
      04-24-2004
ENTITY EX_TOP IS
generic (
outfilep_string : string :="results/CDAC_OUT.txt";
inpfilen_string : string :="data/CDAC_IN.txt"
);
PORT(
AVDD : IN real;
AVDD_REF : IN real;
AVSS : IN real;
AVSS_REF : IN real;
--input port list
CDAC_OUTN : OUT real:= 0.0;
CDAC_OUTP : OUT real:= 0.0
);
end;

The idea is to make the file as generic(here i have a default value
for the files). Then during instantiation you can change the name of
the file as per your requirement. By this the idea is to have multiple
testcases which actually feed different input data and dump out
different output files.
I hope this helps

Best Regards,
Sajan.



"paris" <> wrote in message news:<c64kuc$ut8$>...
> hi guys,
>
> im having some trouble with reading from a file, actually the thing is the
> opening part.
> the problem is that i "dont" know the name of the file to read before
> compiling, that is because i've a "configuration" file where i give
> commands, one of them being the name of the "input" file.
>
> i know i could use a function, but that only works when i've a small amount
> of data to read, cause otherwise, storing a HUGE array slows down the
> simulation, without saying that modelsim tells me that i has not enough
> memory and will start paging to disk and after a while it says that i got
> completely out of memory.
>
> Simulation works perfect if i read one line (of the input file) at the time,
> but that means that the filename has to be written on the code (at least
> that's how i've been doing, by using ' file fp : TEXT is in "input.dat"; ')
>
> now i need to open an arbitrary file, so i tried "file_open(fp,
> filenameString, READ_MODE);" the problem is that somehow it doesnt work, as
> it seems that if i open the file in one process (i have to open the file
> just once and read it till the end of the file at every rising_edge(clk), so
> that's two processes). It doesnt work cause it seems that the file is
> "closed" outside the process it was opened (i think i even read about that
> issue).
>
> Also i cant find "file_open" declaration.
>
> i also tried with a process like this: (im at home now, so i dont have the
> real sources, but i cant sleep so im writing to ask for help please)
>
> process
> begin
>
> if (filenameString /= nothing) then
> file_open(fp, filenameString, READ_MODE);
>
> while (not endfile(fp)) loop
> wait until rising_edge(clk);
> read(fp, data);
> etc, etc
> end loop;
> file_close(fp);
> end if;
> end process;
>
> that didnt work either, im not sure if it was because of the file_open part
> (i also did a check on the opening, it was succesful) or because the process
> get in an infinite loop, modelsim just stop responding (i think that endfile
> might return false if the file is not open, giving rise to the infinite
> loop, but the loop would at least be "waiting" for "clk" and it would
> actually read the data, but that doesnt happen). The file might get closed
> once "out" the process (like when another process gets executed) or
> something, i have no clue...
>
> do any of you knows or have faced already this kind of situation? namely,
> reading a file whose name's specified after compilation (by another file)
> line by line (that is, not using a function to read a whole chunk of data
> and storing it in an array)
>
> any comments will be appreciated, thanks
>
>
>
> Paris

 
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
reading binary files in vhdl. Use of read in a function. gfandango VHDL 1 02-10-2009 08:18 AM
VHDL-2002 vs VHDL-93 vs VHDL-87? afd VHDL 1 03-23-2007 09:33 AM
UnauthorizedAccessException when reading XML files (no problem when reading other file-types) blabla120@gmx.net ASP .Net 0 09-15-2006 02:08 PM
multiD-vhdl: Multi Dimensional Arrays (allowing generics on each dimension) for VHDL (including ports) albert.neu@gmail.com VHDL 2 03-21-2006 04:05 PM
what's the difference between VHDL 93 CONCATENATION and VHDL 87 CONCATENATION? walala VHDL 3 09-18-2003 04:17 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57