Page 1 of 1

1 == 1 is FALSE in interrupt handler?

Posted: Tue Jan 14, 2014 10:39 am
by ucasano
Hi, I am experiencing a strange behaviour in evaluating conditional expressions like 1 == 1 in interrupt handler.

Precisely, inside Dma Rx handler I am using for I2S, I have the following:


static void I2SDmaRxInterrupt(SPIDriver* spip, uint32_t flags)
{
if(spip == &SPID3)
{
serv++;
if(flags == 16) {
/* inside code */
}
}
}

Here flags is 16... but the code inside never gets executed.
serv is incremented to 1.

What could it be?
the flags == 16 is really what I ended using, after trying (flags & DMA_FLAG_TC/HT ecc...).

Thanks.
-g

Re: 1 == 1 is FALSE in interrupt handler?

Posted: Tue Jan 14, 2014 12:38 pm
by Giovanni
The problem is that flags is a mask of bits, comparing with a constant is not correct. You may place a breakpoint in the ISR and follow the execution step by step in order to understand what happens. Compiling using -O0 is a good idea while debugging.

Giovanni

Re: 1 == 1 is FALSE in interrupt handler?

Posted: Tue Jan 14, 2014 4:57 pm
by ucasano
That's right, but flags is still a unsigned integer 32 bit type, and if its value is 16 decimal, compared to 16 decimal constant should give TRUE.

I tried step by step for two days, observing if flags values changes inside the ISR: nothing. I will try -O0...

Thanks.
-g

Re: 1 == 1 is FALSE in interrupt handler?

Posted: Sat Jan 18, 2014 10:42 am
by ucasano
Hi,

I have tried recompiling code with the -O0 option enabled: the interrupt handler never gets executed!
If I reset the default -O2 option, the interrupt handler gets executed just once, with the problem I already discussed.

So, What did happen when I tried the -O0 option? Code size is about twice the original code... Why the interrupt handler never gets executed?

-g

Re: 1 == 1 is FALSE in interrupt handler?

Posted: Sat Jan 18, 2014 10:49 am
by Giovanni
-O0 disables optimization so the code is larger but easier to debug.

I don't have a solution to your problem, the context is not clear, there are lots of things that could prevent the ISR to be triggered.

Giovanni