DSP56F807 - Mutual exclusion using IPL 0 masking

Started by Aaron Needles October 30, 2002
I need a mutual exclusion mechanism that allows access to two
global variables as an atomic unit. To prevent code within an ISR
from accessing one of the variables during this short period, I would
like to mask IPL 0 interrupts while I access the pair and then unmask
IPL 0 interrupts again when done. I would also like to put this code
into a function that automatically determines if masking is already
in affect (SR bit $0200 is set) so that the IPL 0 mask in the SR can
be restored to its original state. This would allow the function to
be called from inside or outside ISRs without the user keeping track
of IPL 0 masking.
Is it possible to use a BFSET instruction to set the IPL 0 mask
bit in the SR and then test whether this bit was actually changed?
This would then allow me to restore the mask after my "critical
section" of code. So far I have not been suscessful in my attempts
to do this, so I am wondering if anyone has a mechanism like this
I am using an up to date version of Metrowerks with the 56F807