How easy is it to read files that are not text into VHDL test benches?
Not wildly difficult, but somewhat messy.
does it require writing of new libraries to handle different file
types?
In practice, no; you can treat just about any file as a
FILE OF CHARACTER and read the byte stream. The VHDL
standard does not mandate this behaviour, but it works
in all simulators I've ever met. Characters can be
easily converted to/from their 0-255 integer equivalent
using CHARACTER'POS and CHARACTER'VAL attribute-functions.
Or is it simpler to just have the IO put into a text file if possible?
Yes, much simpler. Use an external utility (C, Perl, Tcl, you choose)
to map your binary file formats to/from some VHDL-friendly text form.
~~~~~~~~~~~~~~~~~~~~~~
To get you started, here are my does-it-work-in-my-simulator
test programs for binary files:
------1. Write out a 256-byte binary file containing the byte
------ values 0 to 255 in ascending order.
entity binfile is end;
architecture b of binfile is
begin
process
type charfile is file of character;
file f: charfile;
begin
file_open(f, "junk.bin", write_mode);
for i in character loop
write(f, i);
end loop;
file_close(f);
wait;
end process;
end;
-----2. Read a binary file and display its contents byte-wise
----- on the console
use std.textio.all;
entity readfile is end;
architecture f of readfile is
type UnixFile is file of character;
file Src: UnixFile;
begin
ReadBytes : process
variable c: character; -- char read from the file
variable L: line; -- used for displaying output
begin
file_open(Src, "testfile", READ_MODE);
while not endfile(Src) loop
-- Get the next byte
read(Src, c);
-- See what we got: first as a character...
write(L, character'IMAGE(c), field=>5, justified=>LEFT);
-- and then as its ASCII code in decimal:
write(L, character'POS(c), field=>3, justified=>RIGHT);
writeline(OUTPUT, L);
end loop;
wait;
end process;
end;
--
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 address removed)
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.