• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

isr question

//
// set_timer(ms) will cause timer_isr() to be invoked in the specified
//   amount of time.
//
// start_timer and stop_timer do the expected.
//
// Enable() enables all interrupts, including timer_isr
//
// Why does the delay function never return?
//

int timer_expired;

INTERRUPT void timer_isr(void)
{
   stop_timer();
   timer_expired = TRUE;
}

void delay(int ms)
{
   timer_expired = FALSE;
   set_timer(ms);
   start_timer();
   Enable();

   while (timer_expired == FALSE)
      continue;
}
0
brianpowell
Asked:
brianpowell
  • 5
  • 2
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:


while (timer_expired == FALSE)
      continue;


This is essentially the same as:

while (timer_expired == FALSE) ;


There's nothing in the while() loop to cause it to quit looping.


Kent
0
 
brianpowellAuthor Commented:
thanks i didn't see that.

bp
0
 
PaulCaswellCommented:
Brian,

Actually, it could terminate if 'timer_expired' becomes TRUE through a timer interrupt.

Why the 'B' grade if the question was answered?

Paul
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
brianpowellAuthor Commented:
Paul,

Im at home right now i will elaborate more on it tomarrow.

Its Playoff time! The Pistons will advance.
0
 
brianpowellAuthor Commented:
I thought it was a "Good!" answer.  Maybe I've misinterpreted the grades.  I normally give A "Excellent!" grades for difficult questions with a lot of back and forth with people.
0
 
Kent OlsenData Warehouse Architect / DBACommented:


>>  Actually, it could terminate if 'timer_expired' becomes TRUE through a timer interrupt.

In this case, the program is at the mercy of the optimization.  Declaring timer_expired as 'volatile' should solve it.


Kent

0
 
brianpowellAuthor Commented:
Paul,

'B' means we either didnt give a complete answer or we gave an answer that was merely helpful.

It was a partial answer and got me on the right track and posted quickly.  The second part of the answer came later.

Cordially,

Brian F. Powell
0
 
brianpowellAuthor Commented:
Paul

And thank you for the link.

bp
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now