Skip to main content

reading and writing MIF files

Project description

mif

mif is a Python module to read and write Memory Initialization Files, used by Quartus to interact with memory blocks on Intel FPGAs. They are similar to Intel HEX files, except they support arbitrary memory widths as first-class citizens.

Install via pip:

pip install mif

Use with load / loads and dump / dumps, similar to the json module:

with open('memory.mif') as f:
    mem = mif.load(f)

print(mif.dumps(mem))

The resulting mem is a numpy array of unpacked bits, where the first dimension is the address in memory, and the second are the bits in little-endian order. For example, to access the least significant bit at address 0x12:

mem[0x12][0]

Of course, unpacked bits are sometimes convenient, but very memory ineffecient. To instead load packed bytes (still in little-endian order):

with open('memory.mif') as f:
    width, mem = mif.load(f, packed=True)

print(mif.dumps(mem, width=width))

Note that load now returns an extra width value, since there is otherwise no way to know the exact width of the returned memory if it is not divisible by 8. This can also be provided to dump to force an output width; normally, it is inferred.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mif-0.3.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

mif-0.3-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page