problem in POSIX timer - VxWorks

This is a discussion on problem in POSIX timer - VxWorks ; Hello everyone, I am trying to use a POSIX timer in an RTP(I use vxworks 6.4). The task which sets the timer stays in infinite loop and after timer is expired the handler funcion will be called . The problem ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: problem in POSIX timer

  1. problem in POSIX timer

    Hello everyone,

    I am trying to use a POSIX timer in an RTP(I use vxworks 6.4). The
    task which sets the timer stays in infinite loop and after timer is
    expired the handler funcion will be called . The problem is ; the
    timer handler function is not interrupting; it only works after the
    timer caller task finishes ( i.e.after i kill the task which stays in
    infinite loop from the shell, the timer handler works).Below is my
    code. The main function is in fact the main function of an RTP.I want
    the handler function to work just when the timer expires. What is the
    problem with the code ? Thanks in advance.



    void main()
    {
    printf("main:hello\n");
    if ((taskSpawn("t1",200,0,2000,(FUNCPTR)task1,0,0,0,0,0,0,0,0,0,0))==
    ERROR)
    printf("error while creating task 1 \n");

    }

    void func(int signo)

    {
    printf("timer has expired");

    }
    void task1(void)
    {
    timer_t timerid;
    struct sigevent event;

    struct itimerspec itime;
    struct sigaction act;




    event.sigev_value.sival_int = 0;
    event.sigev_notify = SIGEV_SIGNAL;
    event.sigev_signo = SIGALRM;


    act.sa_handler = func;
    act.sa_flags = 0;



    itime.it_value.tv_sec = 5;
    itime.it_value.tv_nsec = 0;
    itime.it_interval.tv_sec = 0;
    itime.it_interval.tv_nsec = 0;



    if (sigaction(SIGALRM,&act,NULL) == ERROR)
    printf("error while calling sigaction\n");



    if(timer_create(CLOCK_REALTIME,&event,&timerid) == ERROR)
    printf("error in timer creation\n");



    printf("task1 : hello \n");



    if( timer_settime(timerid, 0, &itime, NULL)== ERROR)
    printf("error while starting the timer\n");



    for(;
    {
    }

    }


  2. Re: problem in POSIX timer

    On Jul 22, 12:31 pm, tsip...@gmail.com wrote:
    > Hello everyone,
    >
    > I am trying to use a POSIX timer in an RTP(I use vxworks 6.4). The
    > task which sets the timer stays in infinite loop and after timer is
    > expired the handler funcion will be called . The problem is ; the
    > timer handler function is not interrupting; it only works after the
    > timer caller task finishes ( i.e.after i kill the task which stays in
    > infinite loop from the shell, the timer handler works).Below is my
    > code. The main function is in fact the main function of an RTP.I want
    > the handler function to work just when the timer expires. What is the
    > problem with the code ? Thanks in advance.
    >
    > void main()
    > {
    > printf("main:hello\n");
    > if ((taskSpawn("t1",200,0,2000,(FUNCPTR)task1,0,0,0,0,0,0,0,0,0,0))==
    > ERROR)
    > printf("error while creating task 1 \n");
    >
    > }
    >
    > void func(int signo)
    >
    > {
    > printf("timer has expired");
    >
    > }
    >
    > void task1(void)
    > {
    > timer_t timerid;
    > struct sigevent event;
    >
    > struct itimerspec itime;
    > struct sigaction act;
    >
    > event.sigev_value.sival_int = 0;
    > event.sigev_notify = SIGEV_SIGNAL;
    > event.sigev_signo = SIGALRM;
    >
    > act.sa_handler = func;
    > act.sa_flags = 0;
    >
    > itime.it_value.tv_sec = 5;
    > itime.it_value.tv_nsec = 0;
    > itime.it_interval.tv_sec = 0;
    > itime.it_interval.tv_nsec = 0;
    >
    > if (sigaction(SIGALRM,&act,NULL) == ERROR)
    > printf("error while calling sigaction\n");
    >
    > if(timer_create(CLOCK_REALTIME,&event,&timerid) == ERROR)
    > printf("error in timer creation\n");
    >
    > printf("task1 : hello \n");
    >
    > if( timer_settime(timerid, 0, &itime, NULL)== ERROR)
    > printf("error while starting the timer\n");
    >
    > for(;
    > {
    > }
    >
    > }

    Hi There,

    One thing that I see that might be causing you problems your busy
    loop. You are putting your task into a busy loop and when your timer
    goes off it might not have a high enough priority to run. so rather
    then just doing for (; do:


    > if( timer_settime(timerid, 0, &itime, NULL)== ERROR)
    > printf("error while starting the timer\n");


    do
    {
    if ( semTake (someSemId, WAIT_FOREVER) == ERROR)
    return;
    printf ("loop\n");
    } while(1);

    and then in your func() do this:

    void func(int signo)

    {
    printf("timer has expired");
    semGive(someSemId);
    }

    you could also do something like this:
    for(;
    taskDelay(1);

    It does not mater what you do just make sure you give up the CPU. If
    you are running this test from an RTP there should be no problems with
    this....

    P.S it is good to see someone running vxWorks 6.4

    Joe


+ Reply to Thread