Using mutex (or lock) in Microblaze?

This is an interesting challenge. There is at present no way to common locking mechanism between the Microblaze and the Python and there are potentially even more issues you need to consider.

The Microblaze’s memory is a true dual-ported RAM which means it’s possible for a writes and reads from both Python and Microblaze to hit the RAM on the same cycle which results in undefined values being read/written.

We worked around this for the IPython Microblaze communication channels by having the control memory locations only be accessed in a single direction - i.e. one 4-byte word that was only written from Python and one 4-byte word that was only written from the Microblaze. The values of the two registers then form two exclusive regions in the rest of the communication buffer so that the same byte is never written two simultaneously. To avoid problems with read/write conflicts we always read the status words twice and only act when the value is stable. This means a single-cycle collision can be detected and ignored.

For your case, you’ll probably need to implement something similar. You can have a look at the Python and C implementations of our stream to see if that helps with designing a lock implementation.

Peter

2 Likes