• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • 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
IT Degree with Certifications Included

Aspire to become a network administrator, network security analyst, or computer and information systems manager? Make the most of your experience as an IT professional by earning your B.S. in Network Operations and Security.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

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