1 == 1 is FALSE in interrupt handler?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
ucasano
Posts: 57
Joined: Mon Aug 06, 2012 1:05 pm
Has thanked: 1 time

1 == 1 is FALSE in interrupt handler?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post 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
ucasano
Posts: 57
Joined: Mon Aug 06, 2012 1:05 pm
Has thanked: 1 time

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

Post 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
ucasano
Posts: 57
Joined: Mon Aug 06, 2012 1:05 pm
Has thanked: 1 time

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

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post 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
Post Reply