how do protect data when handling multiple interrupts that access the same data

Status
Not open for further replies.

jrdarrah

Well-known member
I'm working on an application that will use two timer interrupts. The main one will operate faster to do the real work, the slower one will poll external input to feed information into the work process. The problem I see is if the data is changed by the slow timer interrupt while the fast timer interrupt is using it I can see the possibility of data corruption. Is there a way for the fast loop to tell the slow loop, wait a bit before changing the data? I'm just starting to read up on interrupts so the method may be there I just haven't found it. One idea I had was to flip a bit in GIPOR0 during the period needed to finish processing the data and flip it off afterward. The slow interrupt would have to wait until the bit goes off. Timing in the slow interrupt isn't critical. Thanks for pointing me along to an answer
 
What happens to the slow interrupt if it is triggered when interrupts are disabled inside the fast loop or vice versa? Will it make note of the interrupt pending so when interrupts are re-enabled that it proceeds to do its function?
 
What happens to the slow interrupt if it is triggered when interrupts are disabled inside the fast loop or vice versa?
A new interrupt can't start while interrupts are disabled. An interrupt pending flag will be set.
Will it make note of the interrupt pending so when interrupts are re-enabled that it proceeds to do its function?
Yes.

You can configure the interrupt priority. Higher priority interrupts can interrupt lower priority interrupts. Lower priority interrupts can't interrupt higher priority ones.

You generally shouldn't disable interrupts for a long period of time. Do your processing in local data structures and once you are finished, disable interrupts and update the global state.
 
Status
Not open for further replies.
Back
Top