Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Creating realtime threads with QNX6.3.2: (6 Items)
   
Creating realtime threads with QNX6.3.2  
Dear Sir
I have recently purchased QNX6.3.2. I am unable to create three realtime threads - 250 microseconds, 1 millisecond and 1
 second. They have to be periodic. The least i am able to get is i millisecond and no lesser than that. Can somebody 
help me.
Re: Creating realtime threads with QNX6.3.2  
> Dear Sir
> I have recently purchased QNX6.3.2. I am unable to create three realtime 
> threads - 250 microseconds, 1 millisecond and 1 second. They have to be 
> periodic. The least i am able to get is i millisecond and no lesser than that.
>  Can somebody help me.

The millisecond seems to be the default ticksize of your system.
you can change that with ClockPeriod() :

http://www.qnx.com/developers/docs/6.3.2/neutrino/lib_ref/c/clockperiod.html

Thread creation is more or less expensive, do You mean you want to do something periodicly out of 3 threads ?
So you can use the timer concept to achive this.
This would be starting point:
http://www.qnx.com/developers/docs/6.3.2/neutrino/lib_ref/t/timer_create.html


Hope this helps.
Jeevan
Re: Creating realtime threads with QNX6.3.2  
Hi
I am using a 800 MHz PIII SBC with QNXNeutrino6.3.2. I need 250 microseconds thread for which I am unable to program the
 clock with microseconds resolution
Though I programmed 10 microseconds, but the resolution is around 9.219 microseconds and the calculations go haywire 
with this amount of drift.
I have given the code below. Kindly help me.
Shyamala

/* Thread1 is expected to run every 250us ,thread2 every 500us and thread3 every 1sec and all the 3 threads should 
perennially run.*/

#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/neutrino.h>
#include <pthread.h>
#include <sched.h>
#include <sys/time.h>
#include <sys/siginfo.h>
#include <sys/wait.h>
// diamond driver includes
#include "dscud.h"

float cosval[80],sinval[80];

DSCADSCAN adscan;
DSCB dscb; int i=0;
int j=0;
int j1=0;
int j2=0;
float vol;
void sampling(void);
void measurand(void);
extern float Vr1;
pthread_mutex_t mutex;
void *T1(void *ignored) {      struct timespec ts;
       struct itimerspec tsr;
    struct sched_param p;
   clock_gettime(CLOCK_REALTIME,&ts);

      p.sched_priority=20;
  pthread_setschedparam(pthread_self(),SCHED_FIFO,&p);
   while(1)
{
   pthread_mutex_lock(&mutex);
    sampling();
    pthread_mutex_unlock(&mutex);
   ts.tv_nsec =250000;
   ts.tv_sec =0;
clock_nanosleep(CLOCK_REALTIME,NULL,&ts,NULL);
   if (j==0) {dscDIOOutputBit(dscb,1,0,1);j=1;}
   else {dscDIOOutputBit(dscb,1,0,0);j=0;}
   }
return (void *)0;
}

void *T2(void *ignored)    // 1 msec Thread for calculatig the measurands and Protection functions
{      struct timespec ts1;
   clock_gettime(CLOCK_REALTIME,&ts1);
   while(1)
   {       measurand();
delay(1);
       if (j1==0) {dscDIOOutputBit(dscb,1,1,1);j1=1;}
       else {dscDIOOutputBit(dscb,1,1,0);
j1=0;}
   }
return (void *)0;
}


void *T3(void *ignored)  {   //FILE *fp1;
     while(1)
   {         sleep(5);
       printf("%f \n",Vr1);
      if (j2==0) {
dscDIOOutputBit(dscb,1,2,1);j2=1;}
      else {dscDIOOutputBit(dscb,1,2,0);j2=0;}

         }
     return (void *)0;
}

int main(void)
{  
   pthread_t thread1, thread2,thread3;
   void *thread_rc;
   pthread_attr_t attr1,attr2,attr3;
   struct _clockperiod hercules;
   DSCCB dsccb;
     DSCADSETTINGS adsettings;
   BYTE confbyte;
     dscInit(DSC_VERSION);
   memset(&dsccb, 0, sizeof(DSCCB));
   dsccb.base_address = 0x240;
   dsccb.int_level = 5;
   dscInitBoard(DSC_HERCEBX, &dsccb, &dscb);
     confbyte=0x1e;
   dscDIOSetConfig(dscb,&confbyte);
     for (i=0;i<80;i++) {
           cosval[i]=0.025*cos(i*0.078571429);sinval[i]=0.025*sin(i*0.078571429);
   }
         memset(&adsettings, 0, sizeof(DSCADSETTINGS));
       adsettings.range = RANGE_10;
       adsettings.polarity = BIPOLAR;
       adsettings.gain = GAIN_1;
       adsettings.load_cal = TRUE;
       adsettings.scan_interval = SCAN_INTERVAL_9;
       dscADSetSettings(dscb, &adsettings);
       memset(&adscan, 0, sizeof(DSCADSCAN));
       adscan.low_channel = 0;
       adscan.high_channel = 0;
           hercules.nsec=10000;
   hercules.fract = 0;
   ClockPeriod(CLOCK_REALTIME,&hercules,NULL,0);
 pthread_attr_init(&attr1);
    pthread_attr_setdetachstate(&attr1,PTHREAD_CREATE_DETACHED);
    pthread_attr_setinheritsched(&attr1,PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&attr1,SCHED_FIFO);
    attr1.param.sched_priority=10;
       pthread_attr_init(&attr2);
    pthread_attr_setdetachstate(&attr2,PTHREAD_CREATE_DETACHED);
    pthread_attr_setinheritsched(&attr2,PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&attr2,SCHED_RR);
    attr2.param.sched_priority=10;
       pthread_attr_init(&attr3);
    pthread_attr_setdetachstate(&attr3,PTHREAD_CREATE_DETACHED);
    pthread_attr_setinheritsched(&attr3,PTHREAD_EXPLICIT_SCHED);
   ...
View Full Message
Re: Creating realtime threads with QNX6.3.2  
> Dear Sir
> I have recently purchased QNX6.3.2. I am unable to create three realtime 
> threads - 250 microseconds, 1 millisecond and 1 second. They have to be 
> periodic. The least i am able to get is i millisecond and no lesser than that.
>  Can somebody help me.


Attached a sample for 250 us, 500 us and 1ms.

Hope this helps.
Jeevan
Attachment: Text rt_threads.c 1.77 KB
Re: Creating realtime threads with QNX6.3.2  
Thank you. It works.
Shyamala

On Tue, Jan 6, 2009 at 4:17 PM, Jeevan Mathew <community-noreply@qnx.com>wrote:

> > Dear Sir
> > I have recently purchased QNX6.3.2. I am unable to create three realtime
> > threads - 250 microseconds, 1 millisecond and 1 second. They have to be
> > periodic. The least i am able to get is i millisecond and no lesser than
> that.
> >  Can somebody help me.
>
>
> Attached a sample for 250 us, 500 us and 1ms.
>
> Hope this helps.
> Jeevan
>
>
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post19425
>
Re: Creating realtime threads with QNX6.3.2  
Hy, i am also trying to create a 250 microsecond task, in my case just toggleing a  gpio pin from a port with out32 
instructions.
The problem is with jitter, when a measure the jitter even a a 1milisecond impulse signal, its huge (average 500 micro-
seconds and the max is sometimes larger than the signal itself). i must be doing something wrong.
I set the clock period to 1 milisecond, set the priority to about 60 (larger than all of the user processes), but still 
the jitter is big, to big for a real time application, remember a want a 250 microsecond task.
I would also like to add that i am using a AT91SAM9260-ek board for my target, and i`m using qnx neutrino 4.
How can i lower that jitter to a normal level?