Forum Discussion
Altera_Forum
Honored Contributor
12 years agoReading binary files is typical for simulation (Modelsim), eg., see lfsr_tb.vhd in this tutorial:
http://www.ovro.caltech.edu/~dwh/correlator/pdf/lfsr_tutorial.pdf http://www.ovro.caltech.edu/~dwh/correlator/pdf/lfsr_tutorial_src.zip Here's the relevant code snippets:
-- File parameters
subtype byte_t is character;
type binary_file_t is file of byte_t;
file binary_file : binary_file_t;
variable status : file_open_status;
variable byte : byte_t;
...
-- Open the file
file_open(status, binary_file, PRBS_FILE_NAME, READ_MODE);
assert status = OPEN_OK
report "File open for read failed!"
severity failure;
-- Read the data
index := 0;
while not endfile(binary_file) loop
-- Read a byte
read(binary_file, byte);
-- Serialize
if (index + 8 < PRBS_LENGTH) then
prbs_sequence(index+7 downto index)
:= to_slv(character'pos(byte), 8);
index := index + 8;
else
-- Convert the last bits
prbs_sequence(PRBS_LENGTH-1 downto index)
:= to_slv(character'pos(byte),
PRBS_LENGTH-index);
exit;
end if;
end loop;
file_close(binary_file);
For synthesis, the use of file I/O will be more restrictive, eg., you might be able to use it to initialize a signal. What are you trying to do? If you need the binary data at run time, would a RAM (or ROM) component be more appropriate? Cheers, Dave