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

How to get the system time on Vxworks.

4,786 views
Skip to first unread message

Venkat Emani

unread,
Dec 17, 1998, 3:00:00 AM12/17/98
to

Greetings Folks,

I would appreciate if someone can help me in the following regard.

I am trying to get the system time from within the program.

My code looks like this:


#include <time.h>
........

time_t tm Time = time(NULL) ;

struct tm * tmp = localtime(&tmTime) ;

.....

I thought tmTime should contain the no. of seconds from Jan 1st.
1970 ( At least on Solaris and NT it's like that )
However, tmTime is set to the no. of seconds elapsed since the
card was booted last. ( Which meant if I run it
in 5 minutes after booting my MC card, tmTime was being set to 5 *
60 = 300 . As a result the localtime() routine
sets the time to Jan 1st 1970 , 00:05:00 which was n't what I
wanted.

Please let me know how I can get the system Time .

My apologies if this question was previously answered. Please point me
to that.

Thanks,

Ven.


Daniel Wong

unread,
Dec 18, 1998, 3:00:00 AM12/18/98
to
You need to initialize your system time from the board's Real Time
Clock. Most SBCs have one. I don't know of a standard VxWorks function
that reads the RTC. Check your board documentation for specifics.
Check www.dejanews.com and search on this newsgroup for sample code
recently posted.

Basically: 1. Read the RTC time
2. Set the system clock (try clock_settime() )

I only know how I do this for the MVME 2604 board. Should be very
similar for many of the Moto boards since they use the same or similar
RTC chip.

This approach will be as accurate as your RTC [not very]. See postings
in comp.protocols.time.ntp newsgroup _iff_ you need more accurate
(to << 1 sec) time and have access to an ntp server.

HTH

Dan Wong

--
Daniel Wong Principal System Engineer
Lockheed Martin Ocean Radar and Sensor Systems
Electronics Park EP7-333 Syracuse, NY 13090
(315)456-2162 [FAX (315)456-1430]
------------------------------------------------------------------------
Blessed is the man who always fears the Lord,
but he who hardens his heart falls into trouble. -- Proverbs 28:14

Suresh Gopalakrishna

unread,
Dec 23, 1998, 3:00:00 AM12/23/98
to
Hey Guys,

This is how it works, there is a clock_gettime() func in VxWorks, which gets
current time of the clock.
The code looks like below,

struct timespec time_val;
clock_gettime(CLOCK_REALTIME, &time_val);
time_in_seconds=time_val.tv_sec;

So finally you get the time in secs. For setting the clock, there is
clock_settime().

The synopsis is as follows :

int clock_gettime(clockid_t clock_id, struct timespec * tp)
here clockid is always CLOCK_REALTIME --> for VxWorks,
Same for settime also.

Hope this helps for you,

Suresh,

0 new messages