binaryio

extras/binaryio.vhdl

Dependencies

None

Description

This package provides procedures to perform general purpose binary I/O on files. The number of bytes read or written is controlled by the width of array passed to the procedures. An endianness parameter determines the byte order. These procedures do not handle packed binary data. Reading and writing arrays that are not multiples of 8 in length will consume or produce additional padding bits in the file. Sign extension is performed when writing padded signed arrays.

Example usage

file fh  : octet_file open read_mode is "foo.bin";
file fh2 : octet_file open write_mode is "out.bin";
signal uword : unsigned(15 downto 0);
signal sword : signed(19 downto 0);
...
read(fh, little_endian, uword); -- read 16 bits from two octets
read(fh, big_endian, sword);    -- read 20 bits from three octets
...
write(fh2, little_endian, uword);
write(fh2, big_endian, sword);

Types

binaryio.octet_file

File of 8-bit bytes.

binaryio.endianness

Endianness of multi-byte words.

  • little-endian = least significant octet first : 1234, 123, etc.
  • big-endian = most significant octet first : 4321, 321, etc.

Subprograms

binaryio.read (Fh : octet_file; Octet_order : endianness; Word : out unsigned)
Read binary data into an unsigned vector.
Parameters:
  • Fh (None octet_file) – File handle
  • Octet_order (None endianness) – Endianness of the octets
  • Word (out unsigned) – Data read from the file
binaryio.read (Fh : octet_file; Octet_order : endianness; Word : out signed)
Read binary data into a signed vector.
Parameters:
  • Fh (None octet_file) – File handle
  • Octet_order (None endianness) – Endianness of the octets
  • Word (out signed) – Data read from the file
binaryio.write (Fh : octet_file; Octet_order : endianness; Word : unsigned)
Write an unsigned vector to a file.
Parameters:
  • Fh (None octet_file) – File handle
  • Octet_order (None endianness) – Endianness of the octets
  • Word (None unsigned) – Data to write into the file
binaryio.write (Fh : octet_file; Octet_order : endianness; Word : signed)
Write a signed vector to a file.
Parameters:
  • Fh (None octet_file) – File handle
  • Octet_order (None endianness) – Endianness of the octets
  • Word (None signed) – Data to write into the file. Will be sign extended if not a multiple of 8-bits.