Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get System Time with millisecond accuracy

77 views
Skip to first unread message

wegie

unread,
Aug 3, 2001, 9:52:08 AM8/3/01
to
Can anyone please tell me how I can get the system time
including milliseconds on OS9?

10 millisecond resolution would suffice.

Cheers

Wegie

Peter Seed

unread,
Aug 3, 2001, 10:36:07 AM8/3/01
to
#include <time.h>
#include <types.h>
...
time_t timeNow;
u_int32 ticks;
u_int32 hundredths;

error = _os_getime (&timeNow, &ticks);
/* ticks contains the ticks per second in the MS 16 bits, the number of
ticks THIS second in the LS 16 bits */
/* So, assuming a 100Hz ticker.. Otherwise, do your own thing. */
hundredths = ticks & 0xffff ;


wegie wrote in message <62075fc3.01080...@posting.google.com>...

Allen Huffman

unread,
Aug 4, 2001, 6:12:14 PM8/4/01
to
wegie wrote:
>
> Can anyone please tell me how I can get the system time
> including milliseconds on OS9?

OS-9, by default, uses clock ticks. This is configurable on your
system, but the default is usually 100 ticks per second or 1000 ticks
per second (from Microware). My home OS-9 system runs 200 ticks per second.

Calls work in clock ticks by default:

/* sleep for 3 ticks */
count = 3;
_os_sleep( &count, &sig ); /* &sig not available on 68K version */

If you run 100 ticks per second, 1 tick is 10ms, but you cannot rely on
that. Your minimum should be TWO ticks (your SLICE value). Context
switches can happen at any moment, not just on tick boundries, so a
process could have used 95% of a tick then gone to sleep -- the nextg
process in line takes over on that current tick so if it used "1 tick"
it would be using the remaining 5% of that tick.

Rule of thumb: "(n-1) where n=system slice value" is the time you can
rely on getting if you are qualified to be in the CPU.

Default of a 100/second OS-9 system is a slice value of 2. So, if I get
in the CPU I can get (n-1) ticks (always 1 tick plus whatever was left
over from the previous tick, maybe the whole thing maybe not).

If you want 10ms timing, you will either need to use an external timer
interrupt (the only RELIABLE way to do this on any operating system), or
set your system ticker to at least 200/second ticks and then use a value
of "2" which would mean 10ms.

/* timed alarm */
_os_alarm_cycle( &alarmID, 2, 500 );
/* send signal 500 ever 2 clock ticks until I shut it off */

That gives you software timing of 2 ticks, but if other more important
processes are in the CPU, you won't be able to respond to the signal
until your task is back in the CPU. If you have a higher priority and
are waiting for the signal, you will preempt whoever is running and take
over immediately:

_os_setpt( myprocessID, 65535 ); /* I'm king of the world! */

while ( 1 ) {
count = 0;
_os_sleep( &count, &sig ); /* sleep "forever" */
/* when my signal/alarm came in, I woke up and preempted whoever
was in the CPU since I was running at 65535 and they were
probably at a much lower priority */
/* do my critical stuff, or maybe I want to be nice and lower
my priority back down before I do it so I don't hog the CPU */
/* when done, I can go back to my wait loop */
}
--
Over 20,000 digital pics from Disney, Theme Parks, and Ren Fests!
Visit http://www.AtTheFaire.com or http://www.DisneyFans.com
(Supporter of the Renaissance Foundation -/- http://renfound.org)

Allen Huffman

unread,
Aug 4, 2001, 6:13:23 PM8/4/01
to
Also, you can use system globals to see the current 32-bit system tick value:


_os_getsys( ...get d_ticks... );
/* the current tick is "here" */

/* do something... */

_os_getsys( ...get d_ticks again );
/* subtract and now you know how long it took, within a tick */

Noel

unread,
Aug 9, 2001, 8:21:54 PM8/9/01
to
Peter, Allen

Thanks very much for your assistance.

I won't be able to try your suggestions for a coupla weeks, as I'm on
holiday.

However, I'll try them as soon as I return.

Thanks for just now

Regards

Wegie

wegie <stewart...@ingenco.co.uk> wrote in message
news:62075fc3.01080...@posting.google.com...

dsu...@gmail.com

unread,
Feb 19, 2018, 12:16:43 PM2/19/18
to
what is the type of error here??

Allan R. Batteiger

unread,
Feb 19, 2018, 5:26:23 PM2/19/18
to
dsu...@gmail.com wrote in
news:ff2152e4-95ce-434e...@googlegroups.com:
Which verison of OS-9 ? Which CPU ?

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

Allen Huffman

unread,
Feb 19, 2018, 8:24:20 PM2/19/18
to
On Monday, February 19, 2018 at 11:16:43 AM UTC-6, dsu...@gmail.com wrote:
> On Friday, 3 August 2001 16:36:07 UTC+2, Peter Seed wrote:
> > #include <time.h>
> > #include <types.h>

> > error = _os_getime (&timeNow, &ticks);

> what is the type of error here??

"error_code" from <types.h> in the Ultra-C compiler.

kaosengr

unread,
Feb 23, 2018, 8:17:23 AM2/23/18
to
On Monday, February 19, 2018 at 4:26:23 PM UTC-6, Allan Batteiger wrote:
>
> > On Friday, 3 August 2001 16:36:07 UTC+2, Peter Seed wrote:
> >> #include <time.h>
> >> #include <types.h>
> >> ...
> >> time_t timeNow;
> >> u_int32 ticks;
> >> u_int32 hundredths;
> >>
> >> error = _os_getime (&timeNow, &ticks);
> >> /* ticks contains the ticks per second in the MS 16 bits, the number
> >> of ticks THIS second in the LS 16 bits */
> >> /* So, assuming a 100Hz ticker.. Otherwise, do your own thing. */
> >> hundredths = ticks & 0xffff ;
> >>
> >>
> >> wegie wrote in message
> >>
> >> >Can anyone please tell me how I can get the system time
> >> >including milliseconds on OS9?
> >> >
> >> >10 millisecond resolution would suffice.
> >> >
> >> >Cheers
> >> >
> >> >Wegie
> >
> > what is the type of error here??
> >
>
> Which verison of OS-9 ? Which CPU ?
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus

The error_code returned will be 0 if no error occurred. The OS9 Technical Reference manual has a section on processing the returned error_code value.

For reading the time, hopefully, no error occurs, 0 returned, thus the value can be ignored.
0 new messages