Hi All,
I am working on Coldfire m5272c3 with uClinux version 2.6.17-uc1.
When I try to use the high resolution timer, I found that sometimes the program works well
but sometimes the timer will expire after double inteval time than the inteval time I have set
by using librt apis(timer_create, timer_settime).
Does anyone can help me?
Thank you very much!
PS: I have attached my program which is using the librt as bellow
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <sys/limits.h>
#include <time.h>
#include <sys/signal.h>
#include <sys/errno.h>
#define FAILURE -1
#define ABS TIMER_ABSTIME
#define REL 0
sig_handler();
void timeaddval();
/*
* Control Structure for Timer Examples
*/
struct timer_definitions {
int type; /* Absolute or Relative Timer */
struct sigevent evp; /* Event structure */
struct itimerspec timeout; /* Timer interval */
};
/*
* Initialize timer_definitions array for use in example as follows:
*
* type, { sigev_value, sigev_signo }, { it_iteration, it_value }
*/
struct timer_definitions timer_values[TIMERS] = {
{ ABS, {0,SIGALRM}, {0,0, 3,0} },
{ ABS, {0,SIGUSR1}, {0,500000000, 2,0} },
{ REL, {0,SIGUSR2}, {0,0, 5,0} }
};
timer_t timerid;
volatile int usr1;
sigset_t mask;
main()
{
int status;
int clock_id = CLOCK_REALTIME;
struct sigaction sig_act;
struct timespec current_time;
struct sigevent evp;
struct itimerspec timeout;
evp.sigev_value = 0;
evp.sigev_signo = SIGUSR1;
timeout.it_value.tv_sec = 2;
timeout.it_value.tv_nsec = 0;
timeout.it_interval.tv_sec = 3;
timeout.it_interval.tv_nsec = 0;
/*
* Initialize the sigaction structure for the handler.
*/
sigemptyset(&mask);
sig_act.sa_handler = (void *)sig_handler;
sig_act.sa_flags = 0;
sigemptyset(&sig_act.sa_mask);
usr1 = 0;
status = timer_create(clock_id, &evp,
&timerid);
if (status == -1) {
perror("timer_create");
exit(-1);
}
sigaction(evp.sigev_signo, &sig_act, 0);
status = clock_gettime(CLOCK_REALTIME, ¤t_time);
timeaddval(&timeout.it_value, ¤t_time);
status = timer_settime(timerid, TIMER_ABSTIME, &timeout, NULL);
if (status == -1) {
perror("timer_settime failed: ");
exit(-1);
}
}
/*
* Handle Timer expiration.
*/
sig_handler(signo)
int signo;
{
if(signo = SIGUSR1)
printf("timer expired\n");
return;
}
/*
* Add two timevalues: t1 = t1 + t2
*/
void timeaddval(t1, t2)
struct timespec *t1, *t2;
{
t1->tv_sec += t2->tv_sec;
t1->tv_nsec += t2->tv_nsec;
if (t1->tv_nsec < 0) {
t1->tv_sec--;
t1->tv_nsec += 1000000000;
}
if (t1->tv_nsec >= 1000000000) {
t1->tv_sec++;
t1->tv_nsec -= 1000000000;
}
}
ÏÖÔÚ¹ºÂò21CNÆóÒµÓÊÏä,¼´¿ÉÓÃ100Ôª»»5000Ôª!
¡º°åЬÁªÃË¡»ÍƳöÂò°åЬËͰ®ÐĻ£¬·²¹ºÎïÂú250¼´ËÍ·µ20!
_______________________________________________ uClinux-dev mailing list [email protected] http://mailman.uclinux.org/mailman/listinfo/uclinux-dev This message was resent by [email protected] To unsubscribe see: http://mailman.uclinux.org/mailman/options/uclinux-dev
