This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Re: In trouble of timer operations


> From: ariga masahiro [mailto:ariga@link-lab.co.jp]
>
> Forgive my ignorance,but please teach me more.
> If I like to insert exactly, say 20msec, delay how should I write
> program ?

You can't delay _exactly_ 20ms, you can only delay with an accuracy of 10ms.
Calling cyg_thread_delay(2) would delay more than 10ms but no more than
20ms.

Delays are implemented by a timer interrupt, which is happening all the
time, every 10ms, like the ticking of a clock, whether you're using it for
anything or not. When you call cyg_thread_delay(2), it puts the thread to
sleep, and sets its sleep count to 2 ticks. The next timer interrupt happens
between 0 and 10ms later, and decrements the sleep count for the thread to
1. The timer interrupt occurs 10ms later, decrements the sleep count to 0,
and wakes up the thread.

If you need perfectly accurate delays, while other threads and interrupts
are running, you can't do it, not with any RTOS. If you need somewhat more
accuracy, like 1ms accuracy, you can change the timer interrupt to run at
1KHz, and then call cyg_thread_delay(20) for a 20ms delay. That will give
you a delay that's more than 19ms but no more than 20ms. If you make the
timer interrupt run at 10KHz, you have 100us resolution. But the faster you
run the timer interrupt, the more of the CPU time will be wasted on timer
interrupts.

--

Ciao,               Paul D. DeRocco
Paul                mailto:pderocco@ix.netcom.com


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]