Sharing memory between multiple applications and FPGA

I would like to allocate buffer in physical memory and share it between two software applications and FPGA:

  • The first application initializes the buffer and the whole device. It also provides some control features.

  • FPGA processes some signals and stores the results in the buffer.

  • The second application retrieves data written by the FPGA for some monitoring and visualizing tasks.

Shared_buffer

While implementing this scheme I’ve faced two issues:

  1. It seems it is not possible to create PynqBuffer object (pynq.buffer Module — Python productivity for Zynq (Pynq)) attached to existing address without new memory allocation.

  2. While destroying the PynqBuffer object allocated memory is automatically deallocated without explicit freebuffer() call and regardless of other objects (including FPGA) using this memory. By the way it is not obvious from the official documentation: pynq.buffer Module — Python productivity for Zynq (Pynq)

As a result:

  • I cannot utilize PynqBuffer in both applications. So I use python mmap instead in the second monitoring application.

  • The first application should hold the PynqBuffer as a global object. Otherwise it will be destroyed by the python garbage collector. In this case both FPGA and monitoring application will lose their shared buffer.

  • In case of exceptions or manual termination of the application holding the buffer other components can crash. When the first application is restarted, it may allocate new (not the same) buffers attached to physical addresses used by other components. This will lead to some other kind of errors. So termination and restart sequences are very strict. Additional synchronization and protection mechanisms are required for stable operation.

What is the intended way for sharing memory between several applications and FPGA?

Is it possible to control buffer memory allocation and deallocation manually in PYNQ? Maybe there are some useful low layer libraries for this case?