I have a peripheral that is plugged into my Raspberry Pi via GPIO. Works great. However there is a caveat.
The peripheral can only process one thing at a time. (has a FIFO, and interrupt).
This works fine except with MQTT, its asyncronous so what happens is if a command comes in at "just" the right time, it can interrupt another routine or reenter the already running routine thats using the peripheral and this causes a crash with the peripheral becuase now something got injected in between something else.
So I need some way to delegate access to the peripheral so that only one thing at a time can access it, but, at the same time, no requests are lost. This is where I am getting confused and running into problems.
I could simply do InUse = True or False. But, this doesn't work because of 1) A race condition can occur if multiple subs are wanting access and waiting/sleeping, and 2) if something is already using it, it could lose the request because if its in-use already, it wont process.
I could use a wait for InUse = true, but if another call comes in while on top of that call, I cant "stack up" the data/requests for the use of peripheral.
Any ideas? Thanks.
The peripheral can only process one thing at a time. (has a FIFO, and interrupt).
This works fine except with MQTT, its asyncronous so what happens is if a command comes in at "just" the right time, it can interrupt another routine or reenter the already running routine thats using the peripheral and this causes a crash with the peripheral becuase now something got injected in between something else.
So I need some way to delegate access to the peripheral so that only one thing at a time can access it, but, at the same time, no requests are lost. This is where I am getting confused and running into problems.
I could simply do InUse = True or False. But, this doesn't work because of 1) A race condition can occur if multiple subs are wanting access and waiting/sleeping, and 2) if something is already using it, it could lose the request because if its in-use already, it wont process.
I could use a wait for InUse = true, but if another call comes in while on top of that call, I cant "stack up" the data/requests for the use of peripheral.
Any ideas? Thanks.