LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   timer_settime can't work (https://www.linuxquestions.org/questions/linux-software-2/timer_settime-cant-work-768389/)

hmtsai 11-11-2009 06:11 AM

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;
}

fpmurphy 11-12-2009 09:05 AM

What error are you getting?

hmtsai 11-12-2009 08:24 PM

Quote:

Originally Posted by fpmurphy (Post 3754274)
What error are you getting?

I can't see any error. I run the process, but I can't see any timeout message.


All times are GMT -5. The time now is 10:06 AM.