LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-11-2009, 06:11 AM   #1
hmtsai
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Rep: Reputation: 0
timer_settime can't work


Hello,

I need a timer. I use timer_settime and timer_create to crate a timer. It works on the fodera 10. But it can't work on my embedded board. Below is my code. Can you give me a suggestion?

#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <errno.h>
#include <string.h>


timer_t OSTimer1;

int timerFlag = 1;
void GmTimerCallBack(sigval_t data)
{
int ID = data.sival_int;
printf("timerID %d timer out\n", ID);
timerFlag = 0;
}

int GmTimerStart(int msec)
{
struct sigevent se;
struct itimerspec ts, ots;
int count;


memset(&se, 0, sizeof(se));
se.sigev_notify = SIGEV_THREAD;
se.sigev_notify_function = GmTimerCallBack;
se.sigev_value.sival_int = 1;

if(timer_create(CLOCK_REALTIME, &se, &OSTimer1) != 0)
{
printf("Create Timer Error[%d]: %s\n", count, strerror(errno));
return -1;
}

/*ts.it_value.tv_sec = 0;
ts.it_value.tv_nsec = 100000000;*/
ts.it_interval.tv_sec = msec/1000;
ts.it_interval.tv_nsec = (msec%1000)*1000000;
ts.it_value = ts.it_interval;

if(timer_settime(OSTimer1, 0, &ts, &ots) != 0)
{
printf("Set Timer Error[%d]: %s\n", count, strerror(errno));
return -1;
}
return 1;
}

void GmTimerStop(int id)
{
int res;

res = timer_delete(OSTimer1);
if(res != 0)
printf("Stop Delete Timer Error[%d]: %s\n", id, strerror(errno));
}

int main()
{
int timer;
timer = GmTimerStart(5000);
while(timerFlag);
GmTimerStop(timer);
return 0;
}
 
Old 11-12-2009, 09:05 AM   #2
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

Rep: Reputation: 62
What error are you getting?
 
Old 11-12-2009, 08:24 PM   #3
hmtsai
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by fpmurphy View Post
What error are you getting?
I can't see any error. I run the process, but I can't see any timeout message.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
With PCI bridge TI PCI2050, VT6212's EHCI can't work(time out), but its UHCI can work thisway.diy Linux - Kernel 0 10-23-2009 09:32 PM
can't make ethernet on laptop work, wireless and usb work fine ubuntu 8.10 rz1988 Linux - Newbie 10 01-13-2009 02:21 PM
Getting a touch screen to work, must get PCI serial device to work first sternocera Linux - Hardware 2 10-03-2008 06:23 AM
I have AD authentication work, how do i make SSH PAM work in RHEL4? epmd Red Hat 0 09-19-2007 06:04 PM
FALCONS EYE (nethack) FAILS ON STARTUP, use to work, wont work even after reinstall roorings Linux - Software 0 10-08-2003 10:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration