Writing & reading same file

N

Niv (KP)

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/
 
Joined
Jun 2, 2009
Messages
23
Reaction score
1
Sure you can do it!!

But I am not very sure if it can be done with the same process!

If you do the writing and the readings in different processes, then it can be done! Just chk it out, I am not 100% sure about this....
 
J

Jonathan Bromley

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top