2
votes

I'm developing a small embedded system on an ARM microcontroller WITHOUT AN OPERATING SYSTEM. It has several different types of interrupts occurring (button presses, A to D conversion, timer - etc.) and just a single thread running.

I want to have a FIFO queue of events to process where each interrupt service routine adds it's event to the queue and the main (and only) thread removes the events from the queue to process. Clearly accessing the queue data structure in the interrupt service routine is dangerous, but a spinlock will cause deadlock since if the main thread has the lock and an interrupt occurs, the ISR will wait forever for the lock.

Of course, I know already that I can disable interrupts while the main thread is messing around with the queue, but this is not ideal.

What is the best way to proceed here?

Thanks A

1

1 Answers

0
votes

If you can get away with a fixed-size ring queue, you don't need anything complicated (I assume interrupts are disabled in the ISR) because there is just one reader — your kernel thread — which updates the tail pointer, and one writer — ISR — which updates the head pointer. Otherwise use Load Linked/Store Conditional instructions to implement a lock-free queue.