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; } |
What error are you getting?
|
Quote:
|
All times are GMT -5. The time now is 10:06 AM. |