Page 1 of 1

Wait for specific amount of time

Posted: Sat May 28, 2011 9:57 pm
by Nessphoro
Hello again,

In my wait function I want to wait for a specific amount of ticks.
void timer_wait(unsigned int t)
{
unsigned long long eticks=timer_ticks+t;
while(eticks>timer_ticks);
}

So I call this function and pass in lets say 18 (I didn't change the default PIC frequency)

As I see the IRQ is working and it increments timer_ticks

But nothing happens in wait. Kernel just gets stuck in an infinite lock.

So I tried to change the code to this to see if while works
void timer_wait(unsigned int t)
{
unsigned long long eticks=timer_ticks+t;
while(eticks>timer_ticks)
{
printf("Tick\n");
}
}
Okay I add this and it magically starts to work. I change it back again, and it doesn't.

Any thought on what might be wrong?

Re: Wait for specific amount of time

Posted: Sat May 28, 2011 10:02 pm
by Brendan
Hi,
Nessphoro wrote:Okay I add this and it magically starts to work. I change it back again, and it doesn't.

Any thought on what might be wrong?
Did you declare "timer_ticks" as volatile? If you didn't the compiler probably caches "timer_ticks" in a register.


Cheers,

Brendan

Re: Wait for specific amount of time

Posted: Sat May 28, 2011 10:05 pm
by Nessphoro
You're right sir, I didn't.

It works now.

Thanks