Post by SantaI have to write a sleep routine, to sleep fro 10ms, how can I know the
value of tick?. Can simebody suggest me, to calculate the tick. Is it
OS dependent?. Since the same code is going to make work on VxWorks as
well as Nucleus too. Thanks in advance.
For VxWorks, you can call sysClkRateGet() to get the number of ticks in
a second and divide that by 100 to 10ms. Keep in mind that the tick rate
may not be an even multiple of 10ms (you'll need to round up to get at
least 10ms...dividing will truncate down). For example, on one platform
I developed for, sysClkRateGet() was 60 so 60 / 100 is 0.6, which turns
into 0 due to integer truncation and you'd need to round up to 1, which
gives about 17ms.
An alternative is to use select to delay by specifying no descriptors to
wait for and using a timeout. This may be better or worse depending on
the implementation though:
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 10000; // 10ms = 10,000 microseconds
select( 0, NULL, NULL, NULL, &tv );
If you need exact timing, you may need to use whatever hardware timer is
available, assuming it provides the needed accuracy. For example, on
PowerPC, you can use the timebase registers to wait for a period of time
with reasonable accuracy (assuming a stable clock). This is what I do
for very short timing delays where normal delay/blocking primitives are
inadequate (e.g. to wait 100 microseconds for a signal to ramp up).