Message-ID: <20061005135710.35700.qmail@domain.hid> Date: Thu, 5 Oct 2006 06:57:10 -0700 (PDT) From: mani bhatti In-Reply-To: <451A9C64.7040802@domain.hid> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1512227822-1160056630=:35465" Content-Transfer-Encoding: 8bit Subject: [Xenomai-help] Problem with Aperiodic xenomai tasks List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: xenomai-help --0-1512227822-1160056630=:35465 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable HI=20 I want to have two tasks in xenomai the pariodic task and the non pariodic = tasks which is signalled by the pariodic task.The problem is that if i mak= e one thread pariodic and the other one non pariodic then the pariodic thre= ad never runs after specific time period and only non pariodic thread appea= rs .The code for tasks is given below.I would be very thankful if please s= ome one figure out what wrong i am doing.Thanks void zaehler1_task(void *cookie){ int ret; ret =3D rt_task_set_periodic(NULL, TM_NOW, rt_timer= _ns2ticks(task_period_ns1)); if (ret) { printf("error while set periodic, code %d\n",ret); return; } while(!end){ ret =3D rt_task_set_mode(0, T_RRB, NULL); if (ret) { printf("error while rt_task_set_mode, code %d\n",re= t); return; } ret =3D rt_task_wait_period(); printf("T1:Start\n"); if (ret) { printf("error while rt_task_wait_period, code %d\n",ret); return; } rt_mutex_lock(&threadmutex,TM_INFINITE); count1++; printf("T1:Ende:%d\n", count1); =20 if(count1=3D=3D15) =20 { rt_cond_signal(&cond); } =20 rt_mutex_unlock(&threadmutex); } } void zaehler2_task(void *cookie){ int ret; =20 long ii; long jj; double a; while(!end){ rt_mutex_lock(&threadmutex,TM_INFINITE); rt_cond_wait(&cond,&threadmutex,TM_INFINITE); printf("\t\tT2:Start\n"); count2++; printf("\t\tT2:Ende:%d\n", count2++); rt_mutex_unlock(&threadmutex); } } int main(int argc, char *argv[]) { int err, ret; printf("start\n"); // install signal handler signal(SIGTERM, clean_exit); =20 signal(SIGINT, clean_exit); =20 // start timer ret =3D rt_timer_start(TM_ONESHOT); switch (ret) { case 0: printf("Mit dem Fahrrad nich inn ersten Wagen\n\n"); break; case -EBUSY: printf("timer is running\n"); break; case -ENOSYS: printf("can't start timer\n"); return ret; } rt_cond_create(&cond,NULL); /* create zaehler1_task */ err =3D rt_task_create(&zaehler1_task_ptr,"Zaehler_1",STACK_SIZE,STD_PR= IO1,0); /* create zaehler2_task */ err =3D rt_task_create(&zaehler2_task_ptr,"Zaehler_2",STACK_SIZE,STD_PR= IO2,0); /* start zaehler1_task */ err =3D rt_task_start(&zaehler1_task_ptr,&zaehler1_task,NULL); /* start zaehler2_task */ err =3D rt_task_start(&zaehler2_task_ptr,&zaehler2_task,NULL); // wait for signal & return of signal handler pause(); fflush(NULL); return 0; } Jan Kiszka wrote: mani bhatti wrote: > Thanks Jan for your reply > Actually the semaphore and mutexes stuff you have referred to i have > already grounds for them.The only problem i have is please some body > tell me that i dont want to make a thread periodic i,e i dont want to > call a thread after periodic time interval i wanted it to make it > aperiodic like threads in C++ are scheduled by scheduler byitself This has nothing to do with C++, rather with the class library you are used to. > and sleep on waiting condition with out any specific time interval > and wake only when signalled from pariodic thread. I hope you > understand my point.Thanks a lot . Let's try it differently: thread_a() { rt_task_set_periodic(...); while (1) { rt_task_wait_period(NULL); /* do some work */ if (I_should_trigger_thread_b) rt_sem_v(&sem); } } thread_b() { while (1) { rt_sem_p(&sem, TM_INFINITE); /* so some other work */ } } Again, read up what the services are exactly doing or you will be lost once you have to modify things only slightly. Jan =09 --------------------------------- How low will we go? Check out Yahoo! Messenger=92s low PC-to-Phone call ra= tes. --0-1512227822-1160056630=:35465 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable HI
I want to have two tasks in xenomai the pariodic task and the non pa= riodic tasks which is signalled by the pariodic task.The problem is that&nb= sp; if i make one thread pariodic and the other one non pariodic then the p= ariodic thread never runs after specific time period and only non pariodic = thread appears .The code for tasks  is given below.I would be very tha= nkful if please some one  figure out what wrong i am doing.Thanks
<= br>void zaehler1_task(void *cookie){
      = ;  int ret;
    ret =3D rt_task_set_periodic(NULL, T= M_NOW,           &nb= sp;         rt_timer_ns2ticks(task_= period_ns1));
        if (ret) {
&= nbsp;           &nbs= p;   printf("error while set periodic, code %d\n",ret);
          = ;      return;
     &= nbsp;  }
        while(!end){            &n= bsp;   ret =3D rt_task_set_mode(0, T_RRB, NULL);
  &= nbsp;           &nbs= p; if (ret) {
         &nbs= p;            &= nbsp; printf("error while rt_task_set_mode, code %d\n",ret);
  = ;            &n= bsp;         return;
  = ;            &n= bsp; }
           &nb= sp;    ret =3D rt_task_wait_period();
   =              pr= intf("T1:Start\n");

        =         if (ret) {
   =             &nb= sp; printf("error while rt_task_wait_period, code %d\n",ret);
 &nbs= p;            &= nbsp;   return;
       &nbs= p;        }
    &= nbsp;      rt_mutex_lock(&threadmutex,TM_INFIN= ITE);
           count= 1++;
           printf("T1:Ende:%d\n", count1);
   
  &nb= sp;       if(count1=3D=3D15)  &nbs= p; 
          { = rt_cond_signal(&cond); } 
      = ;      rt_mutex_unlock(&threadmutex);
 = ;         }
}
void zaehler2_t= ask(void *cookie){
    int ret;   
&nb= sp;   long ii;
    long jj;
  &nbs= p; double a;
    while(!end){
    =          rt_mutex_lock(&threadmutex,= TM_INFINITE);
         &nbs= p;   rt_cond_wait(&cond,&threadmutex,TM_INFINITE);
&nb= sp;            printf("\t\tT2:Start\n");
       &nb= sp;     count2++;
     &nb= sp;       printf("\t\tT2:Ende:%d\n", count2++= );
            rt= _mutex_unlock(&threadmutex);
      &nb= sp;  }
}
int main(int argc, char *argv[]) {
   = ; int err, ret;
    printf("start\n");
  &nb= sp; // install signal handler
    signal(SIGTERM, clean_e= xit);   
    signal(SIGINT, clean_exit);&= nbsp;  
    // start timer
  &nbs= p; ret =3D rt_timer_start(TM_ONESHOT);
    switch (ret) {=
        case 0:    &n= bsp;  printf("Mit dem Fahrrad nich inn ersten Wagen\n\n");
 &n= bsp;               &= nbsp;    break;
        cas= e -EBUSY:  printf("timer is running\n");
     &= nbsp;            &nb= sp;   break;
        case -ENOSY= S: printf("can't start timer\n");
        =             &nb= sp; return ret;
    }

    rt_cond_c= reate(&cond,NULL);
        /* cre= ate zaehler1_task */
    err =3D rt_task_create(&zaeh= ler1_task_ptr,"Zaehler_1",STACK_SIZE,STD_PRIO1,0);
    /*= create zaehler2_task */
    err =3D rt_task_create(&= zaehler2_task_ptr,"Zaehler_2",STACK_SIZE,STD_PRIO2,0);

  &= nbsp; /* start zaehler1_task */
    err =3D rt_task_start(&zaehler1= _task_ptr,&zaehler1_task,NULL);

    /* start zaeh= ler2_task */
    err =3D rt_task_start(&zaehler2_task= _ptr,&zaehler2_task,NULL);

    // wait for signal= & return of signal handler
    pause();
 &nb= sp;  fflush(NULL);
    return 0;
}



Jan Kiszka <jan.kiszka@domain.hid> wrote: mani bhatti wrote:
> Thanks Jan for= your reply
> Actually the semaphore and mutexes stuff you have refer= red to i have
> already grounds for them.The only problem i have is p= lease some body
> tell me that i dont want to make a thread periodic = i,e i dont want to
> call a thread after periodic time interval i wan= ted it to make it
> aperiodic like threads in C++ are scheduled by scheduler byitse= lf

This has nothing to do with C++, rather with the class library yo= u are
used to.

> and sleep on waiting condition with out any s= pecific time interval
> and wake only when signalled from pariodic= thread. I hope you
> understand my point.Thanks a lot .

Let's= try it differently:

thread_a()
{
rt_task_set_periodic(...);<= br> while (1) {
rt_task_wait_period(NULL);
/* do some work */
= if (I_should_trigger_thread_b)
rt_sem_v(&sem);
}
}
thread_b()
{
while (1) {
rt_sem_p(&sem, TM_INFINITE);
= /* so some other work */
}
}

Again, read up what the servic= es are exactly doing or you will be lost
once you have to modify things = only slightly.

Jan



How low will we go? Check out Yahoo! Messenger=92s low PC-to-Phone call rates. --0-1512227822-1160056630=:35465--