Discussion:
How to calculate a tick value?.
(too old to reply)
Santa
2003-07-13 22:25:42 UTC
Permalink
I 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.

Does anybody have any idea, where can I find the newsgroup for Nucleus
OS. Thanks.
Bob Bradley
2003-07-14 01:31:11 UTC
Permalink
Post by Santa
I 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).
Claudio Potenza
2003-07-14 17:31:55 UTC
Permalink
Post by Bob Bradley
Post by Santa
I 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.
Please note that 'taskDelay(1)' will give you a delay ANYWHERE between
0 (zero) and the time corresponding to 1 tick.

'taskDelay(n)' in fact means: wait until the next 'n' system clock
interrupts have elapsed.
So, if you happen to call it with 'n'=1 and just one instant before
the system clock interrupt itself arrives, the interval your task
really waits could be very short.

Note also that using 'nanosleep()' or 'select()' does NOT give you any
better precision: while with those you can express the time in
nanosecond, the real granularity will be that of the system clock (as
clearly stated in the vxWorks reference manual!).

Rakesh
2003-07-14 01:59:46 UTC
Permalink
better to get from CPU rather than OS. What CPU are you wroking on?
Post by Santa
I 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.
Does anybody have any idea, where can I find the newsgroup for Nucleus
OS. Thanks.
Sudhakar Shenoy
2003-07-14 04:51:47 UTC
Permalink
Hello,
The number of ticks per second is a configurable thing. you can
set this value by using the get & set tick count functions. These
functions can be found in the tickLib.
The syntax in short is as follows :-
void tickSet
(
ULONG ticks /* new time in ticks */
)

ULONG tickGet (void)

U can use these functions to set the delay of ur choice.

I think the similar thing will be available on Nucleus OS as well.
Not sure about it. Also i dont know the newsgroup for the same.
Regards,
Sudhakar Shenoy.
Post by Santa
I 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.
Does anybody have any idea, where can I find the newsgroup for Nucleus
OS. Thanks.
Continue reading on narkive:
Loading...