Hello VHDL experts.
I have the following problem. In a test environment I have to simulate many
sources that drives data into a system.(e.g. many ports connected into a network switch).
I have an ASCII file representing a stream of data coming from each source.
The files are like FIFO each line represent a data unit and has a unique time stamp attached. The data units are presented one after the other according to the time stamp.
The lines in the files are already sorted according to the time stamp of the lines.
Since the files may be very long, up to 100k lines each, and they are numbered, up to 40 files. I don't want to read them all in the beginning of the simulation and have a lot of memory taken.
The problem is that if i use a function/procedure that gets the file name as a string
and then reads the lines this function reopens the file at the first line. The real issue is not the line number, but the fact that this Unix process ( the simulation) takes a file handler from the Unix every time it reads the file, very soon i get
"too many open files" from the Unix.
The vhdl code is similar to the following :
In a package used by the main program there is the following function.
function read_cell_file(fname :string) return traffic_cell_fifo is
file port_file : text is in fname;
variable l_cell : line;
variable good : boolean;
variable int_fifo : traffic_cell_fifo;
begin
if not endfile(port_file) then
for i in 0 to 1 loop
------------------------------------------------ read heading line
readline(port_file, l_cell);
.....
end loop;
end if;
return int_fifo;
end read_cell_file;
In the main program .
fill_cell_fifo: process(read_file,add,start)
variable fname : string(1 to 13);
variable num : string (1 to 2);
begin
if(read_file'event and read_file = 1) then
if start = 0 then
fname := "t_port_" & to_string(add) & ".txt" ;
traffic_fifo(add) <= read_cell_file(fname);
end if;
end if;
end process;
I would appriciate any comments on how this problam may be solved.
Thanks in advance.
eli.
*****************************************************************
* Eli Baruch. Email : e...@scorpio.com *
* Scorpio Communications Phone : 972-3-5339654 ext 109 *
* Asic group Fax : 972-3-5339518 *
* 1c Yoni Netanyahu st. *
* Or Yehuda 60250 *
* P.O.Box 564, Israel *
*****************************************************************
e...@Scorpio.Com (Eli Baruch) writes:
> The real issue is not the line number, but the fact that this Unix
> process ( the simulation) takes a file handler from the Unix every
> time it reads the file, very soon i get "too many open files" from
> the Unix.
>
> The vhdl code is similar to the following :
>
> In a package used by the main program there is the following function.
>
> function read_cell_file(fname :string) return traffic_cell_fifo is
> file port_file : text is in fname;
[...]
> begin
[...]
> end read_cell_file;
>
>
> In the main program .
>
> fill_cell_fifo: process(read_file,add,start)
> variable fname : string(1 to 13);
> variable num : string (1 to 2);
> begin
> if(read_file'event and read_file = 1) then
> if start = 0 then
> fname := "t_port_" & to_string(add) & ".txt" ;
> traffic_fifo(add) <= read_cell_file(fname);
> end if;
> end if;
> end process;
> I would appriciate any comments on how this problam may be solved.
You don't say what simulator you are using (though I can guess).
If you have a 1076-93 compatible VHDL simulator, this problem must not
occur. The file will be closed each time the function exits: it must
be, because that is what the spec says.
Unfortunately, 1076-87 doesn't specify anything about when files are
opened and closed, and some simulators are incredibly brain-dead about
this. I think that Vsystems is pretty sensible, and I would be
suprised if it is giving you this problem. My experiences with
Vantage have been that it always does the opposite of what I want when
the spec doesn't specify what to do. For example, it opens output
files in append mode. It wouldn't suprise me if it doesn't close
files at the end of subroutines either.
Martin.
Your Problem is that in the function read_cell_file, you create the handler of
the file you want to read. There are two problems with this. The first one is
you need to read all the file when you call your function because when you open
a file in VHDL you are at the first line of your file and you open a file at
each call of the function. The second one is your problem because the handlers
are not destroy before the end of the simulation.
The Solution i can offer to you is valuable if you know how many files you have
two read during a simulation.
The main idea is you must give the file handler to your function instead of the
file name so before you must have create the handlers of all your files. the
solution is:
-The files are always the sames and so you have just to
declare n handlers associate to n files and so your
main program must contain:
fill_cell_fifo: process(read_file,add,start)
file port1 : text is in "channel_1";
file port2 : text is in "channel_2";
...
file port40 : text is in "channel_40";
variable num : string (1 to 2);
begin
if(read_file'event and read_file = 1) then
if start = 0 then
case add is
when 1 =>
traffic_fifo(add)<= read_cell_file(port1);
when 2 =>
traffic_fifo(add)<= read_cell_file(port2);
...
end if;
end if;
end process;
instead of declaring n file handlers you can try with an array of File handlers
but i have never tried and so I can not be sure it is a good solution. if the
file are not always the same you must have a process which set the name of all
the file in an array of string(file names) and in your main process you must
write for exemple : File port1 : Text is in Name(1).
Please, excuse my poor english.
Eric Venditti.