cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
markus.offergeld
Explorer
Explorer
6,030 Views
Registered: ‎02-28-2011

Interrupts not working during while loop

I recently switched from EDK 9.2 to 12.3.

 

I have an issue during while loops which will never finish (this happens in an application directly in EDK or in my written driver)

here is the scenario (pseudo code):

 

i have a volatile global var loop and main function where it say like this:

 

loop = 1;

while (loop) {

//do nothing

}

 

and I have an ISR which sets the global var loop to 0.

 

runing the code will result in a never ending loop, even though the interrupt for that ISR is working.

 

now if i change the code to:

 

loop = 1;

while (loop) {

print("\r");

}

 

and i have a the same ISR. It suddently works?!

 

I have the same code with 9.2 with same interrupt priorities as well and it is working there without that printf.

I have the same issue with a linux driver which polls a register until it is 0. The register is set to 0 after interrupt acknowledge. When i add a printk to the polling it work otherwise microblaze hangs forever in the polling

I am sure that in Interrupts are enabled, but it seems that the interrupts can't get through.

 

Are there any big changes in interrupt handling since 9.2?

Or does someone have an idea whats causing this?

 

0 Kudos
3 Replies
gszakacs
Professor
Professor
6,027 Views
Registered: ‎08-14-2007

Probably you're running into an optimization "feature."  If you don't declare "loop"

volatile, the compiler can ignore what goes on outside the loop and optimize the

code to hang forever.

 

-- Gabor

-- Gabor
0 Kudos
markus.offergeld
Explorer
Explorer
5,991 Views
Registered: ‎02-28-2011

the optimization issue makes sense. I have see other strange behaviors with the code. For example some code parts would not be executed anymore after a change somewhere else.
It might be indeed possible that the compiler "optimizes it away".

I solved this problem by not using an interrupt in that particular case, because i don't need one.
0 Kudos
gszakacs
Professor
Professor
5,985 Views
Registered: ‎08-14-2007

You could check if this was in fact an optimization problem by looking at the

generated assembler code to see if the loop variable is being

re-read inside the loop.

 

When I made my initial post I missed your statement:

 

i have a volatile global var loop and main function where it say like this:

 

So at that point I thought maybe you had overlooked the volatile issue.

 

There's still the possibility that the issue had to do with interrupt enables,

for example the print function could have a side effect of enabling

interrupts globally.

 

I've also run into problems using a volatile pointer in interrupts.

For example the interrupt routine returns a pointer to a buffer.

The main thread sets the pointer to NULL and then loops

waiting for the pointer to become non-NULL.  That problem

had to do with the declaration:

 

volatile int *bufptr;  // This says the memory pointed to is volatile, but the pointer itself is not.

 

int * volatile bufptr;  // This works with the code described.  The pointer itself is volatile.

 

-- Gabor

-- Gabor
0 Kudos