cli and sti inconsistency.

Hi,

I'm having an issue where I use cli and sti to mask all interrupts, but occasionally the interrupts seem to be magically reactivated, interrupts are serviced (when they shouldn't be) and my program crashes usually with an excause error.

If I look at the stack I see that my code (that's guarded by cli and sti) is there on the stack, but it's jumped to service an interrupt (usually an i2s with DMA, or i2c with DMA).

I was thinking that it might be a timing issue so I put in a check like below. It never gets stuck in the while loops which leads me to believe the interrrupts are masked. It also takes a long time for the problem to occur - It runs for 1-20 minutes without issue which makes me think there's some very specific timing thing that has to occur. Without the cli/sti guard it will crash in a second or two.

Here's some example of cli/sti code I'm using.

void get_heap_space( void ){

unsigned int imask = cli();

csync();

ssync();

if ( *pIMASK & 0xFFC0 ) {

while ( 1 ) {}

}

int space =  heap_space_unused(0);

if ( *pIMASK & 0xFFC0 ) {

while ( 1 ) {}

}

csync();

ssync();

sti ( imask );

}

When a problem occurs and I look at the stack in the example above, it's left the the heap space lib function somewhere in the middle to service an interrupt.

Thanks in advance,

J