Writing & reading same file

N

Niv (KP)

Guest
In my testbench, is it possible to write to a file, then read that
file, then write to the file again, then read the file again, etc etc.
It doesn't matter if the file is re-opened and destrots the previous
data written.

Seem to be having trouble doing this.

i.e. in my tb, unit 1 writes several lines of binary data (as text) to
file A, then unit 2 needs to read this file A before it then writes
out other data to file B.

This is then repeated several times/
 
On Mon, 13 Sep 2010 06:29:59 -0700 (PDT), "Niv (KP)" wrote:

In my testbench, is it possible to write to a file, then read that
file, then write to the file again, then read the file again, etc etc.
It doesn't matter if the file is re-opened and destrots the previous
data written.

Seem to be having trouble doing this.

i.e. in my tb, unit 1 writes several lines of binary data (as text) to
file A, then unit 2 needs to read this file A before it then writes
out other data to file B.
hi Kevin

Did you close file A before attempting to re-open and then
read from it? (Of course this requires using the -93
form of file declaration, and FILE_OPEN and FILE_CLOSE
procedures.)

When you write new data to a file, I don't think there is
any guarantee of that file's contents until it's closed.

While we're thinking about this, it's worth mentioning
that you need to be very careful when multiple processes
access the same file. The file is in effect a shared
variable with no kind of interlock or scheduling, so it
is quite easy to get indeterminacy - one of the very few
places this can happen in VHDL. Unless you have really
huge amounts of data (many tens of megabytes) it may be
better to use shared variables of protected type.
--
Jonathan Bromley
 
On 9/13/2010 1:05 PM, Jonathan Bromley wrote:
On Mon, 13 Sep 2010 06:29:59 -0700 (PDT), "Niv (KP)" wrote:

In my testbench, is it possible to write to a file, then read that
file, then write to the file again, then read the file again, etc etc.
It doesn't matter if the file is re-opened and destrots the previous
data written.

Seem to be having trouble doing this.

i.e. in my tb, unit 1 writes several lines of binary data (as text) to
file A, then unit 2 needs to read this file A before it then writes
out other data to file B.

hi Kevin

Did you close file A before attempting to re-open and then
read from it? (Of course this requires using the -93
form of file declaration, and FILE_OPEN and FILE_CLOSE
procedures.)

When you write new data to a file, I don't think there is
any guarantee of that file's contents until it's closed.

While we're thinking about this, it's worth mentioning
that you need to be very careful when multiple processes
access the same file. The file is in effect a shared
variable with no kind of interlock or scheduling, so it
is quite easy to get indeterminacy - one of the very few
places this can happen in VHDL. Unless you have really
huge amounts of data (many tens of megabytes) it may be
better to use shared variables of protected type.
And if you do, it may be better to use a protected type as a wrapper
around that file to manage transactions against it.

--
Rob Gaddi, Highland Technology
Email address is currently out of order
 

Welcome to EDABoard.com

Sponsor

Back
Top