?
Solved

creating a timer in useing C lang.

Posted on 2007-07-29
6
Medium Priority
?
333 Views
Last Modified: 2011-09-20
I want to create a timer using C.  It would start by a decision such as if ( 1 -- 1) {start timer}.
It would be represented as mnutes and seconds,  10:00 down to 00:00 and then reset.
0
Comment
Question by:DanFlyBoy
  • 4
  • 2
6 Comments
 
LVL 13

Expert Comment

by:josgood
ID: 19589303
A few questions:
1)  Does this need to be portable?
2)  If not, what operating system are you using?
3)  What resolution do you need?  
4)  Is this a simple example program or do you have other threads running?
0
 
LVL 13

Expert Comment

by:josgood
ID: 19589315
If you are running Windows, then
    http://msdn2.microsoft.com/en-us/library/ms644900.aspx
is a good reference.
0
 

Author Comment

by:DanFlyBoy
ID: 19589375
The operating system is VXWorks, runnung on a power pc processor.  I am using c as the lanugauge.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Expert Comment

by:josgood
ID: 19589382
I'm afraid someone else will need to help.  Sorry.
0
 

Author Comment

by:DanFlyBoy
ID: 19589400
the code should be like a stopwatch, once decsion is made to start timer, it should count down like a stop watch froom 10:00 to 0.  Time will be displayed on screen.
0
 
LVL 13

Accepted Solution

by:
josgood earned 750 total points
ID: 19589442
You may already know all about this...No offense intended.

http://www.slac.stanford.edu/exp/glast/flight/sw/vxdocs/vxworks/ref/libIndex.htm
gives the VxWorks API, and one page titled "timerLib", which is
http://www.slac.stanford.edu/exp/glast/flight/sw/vxdocs/vxworks/ref/timerLib.html#top
describes a function which may do it for you.  That is "timerConnect", which lets you specify a function to be executed when the timer goes off.  You can use "timer_settime" to set the timer interval.

You might do something like

void myFunc(timer_t timerid, int arg) {
   /* update your stopwatch display */
  /* remember to set a flag when the stopwatch goes to zero */
}

int timerNumber = 1;
const struct itimerspec timerSpec = /* whatever is 1 second*/;
int myTimer = timer_connect(timerNumber,myFunc,0)
int result = timer_settime(myTimer,~TIMER_ABSTIME,&timerSpec,NULL);
while (/*stopwatch hasn't gone zero) {
   /* do something */
}

That's about the best I can do.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question