Re: RTAI and comedi: leaving real time?

On Mon, 2007-05-21 at 09:42 +0000, L.C. Karssen wrote:
> On Sun, 2007-05-13 at 23:37 +0200, Paolo Mantegazza wrote:
> > L.C. Karssen writes: 
> > 
> > > Hi list, 
> > > 
> > > Excuse me for sending this message to both the Comedi and the RTAI list,
> > > but I'm not sure where the problem is. 
> > > 
> > > I'm trying to control an NI-DAQ PCI-6024E card with comedi and RTAI. 
> > > I'm running RTAI in periodic mode. 
> 
> > You are using too an old RTAI version. You should upgrade, so you'll get a 
> > first warning esplicitely, with the syscall number, following if it is just 
> > a first episode or it continues afterward by checking the related count 
> > using proc/rtai/scheduler. 
> I did a fresh install of Slackware 11.0 with RTAI 3.5 and comedi CVS of
> May 14th (it says 0.7.73 when loading the modules). I followed the
> instructions on installling RTAI and comedi from the RTAI-Lab tutorial. 
> 
> When I run my program now I get the following dmesg entry:
> LXRT CHANGED MODE (SYSCALL), PID = 8122, SYSCALL = 54.
> 
> 
> > 
> > In any case if it is signalled so it happened for sure, i.e. your code 
> > called Linux after being made hard real time. 
> Below is the function in my program that does the RT work. After going
> to hard real time I basically only use comedi_dio_bitfield() and
> comedi_do_insn() to clock out bits that are stored in an array of
> structs. After writing one set of bits to DIO and both AO's the program
> should wait for the period (typically ~15us) and then clock out the next
> entry in the array. I don't see where I make a Linux system call (but
> I'm not 100% what a system call is).

With only the following lines in the for loop of my hard realtime
function I get 156 syscalls, exactly the number of rows in my array. 
So each call to comedi_dio_bitfield() gives my a syscall (having only
the line "dio_bits = data_arr[i].DIO;" and the call to
rt_task_wait_period() in the for loop does not generate a syscall). 

for (i=0; i<options->n_rows; i++)
{
  /* Prepare and write digital data. */
  dio_bits = data_arr[i].DIO;
  comedi_dio_bitfield(comedi_dev, dio_subdev, dio_mask, &dio_bits);
  rt_task_wait_period();
}

I thought comedi and RTAI worked together. Or should I somehow use
RT-enabled comedi functions?

> 

> 
> Any help is appreciated!
> 
> 
> Lennart.
> 
> 
> int do_comedi(struct data_struct *options)
> {
>     comedi_t *comedi_dev = options->device;
>     unsigned int ao_subdev  = options->AO_subdevice;  // Analog Output
>     unsigned int dio_subdev = options-> DIO_subdevice; // Digital IO
>     int range=0; // AO has only one range: 10V -> -10V
>     comedi_insn insn;
>     lsampl_t data;
>     unsigned int dio_bits;
>     int aref = AREF_GROUND;
>     unsigned int dio_mask = 0xFFFFFFFF; // Tells which DIO bits are to
> be flipped (all).
> 
>     int period;
>     struct bits *data_arr = options->bitsarr;
>     
>     RT_TASK* task;
>     int priority=0;
>     int stack_size=4096;
>     int msg_size=0;
>     
>     int i;
> 
>     /* Prepare the AO instruction as much as possible. Later, in real
> time
>      *  we'll only fill in the data sample. */
>     insn.insn = INSN_WRITE;
>     insn.n = 1;
>     insn.subdev = ao_subdev;
> 
>     /* A better scheduler than linux' one */
>     struct sched_param mysched;
>     
>     /* We don't want to be swapped out the mem */
>     mlockall (MCL_CURRENT | MCL_FUTURE);
>     /* Allow nonroot users hard realtime access */
>     rt_allow_nonroot_hrt();
> 
>     /* Initialise Scheduler as SCHED_FIFO. Greatly improves scheduler!
> */ 
>     mysched.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1;
>     if( sched_setscheduler( 0, SCHED_FIFO, &mysched ) == -1 ) 
>     {
> 	fprintf(stderr, "Error in setting the Scheduler!\n");
> 	exit(1);
>     }
>     
>     /* Register this thread as a RT task. As long as it's
>        not switched to hard_real_time, it's still a normal process and
>        can do all normal things */
>     task = rt_task_init(nam2num("do_comedi"), priority, stack_size,
> msg_size);
> 
>     // Set mode to periodic. Other option is 'oneshot'
>     rt_set_periodic_mode();
>     period = (int) nano2count((RTIME)options->period*1000);
> 
>     start_rt_timer(period);
> 
>     // Switch to hard realtime mode
>     rt_make_hard_real_time();
> 
>     // Start scheduler 
>     rt_task_make_periodic(task, rt_get_time() + period, period);
>     
>     
>     for (i=0; i<options->n_rows; i++)
>     {
> 	
> 	/* Prepare and write digital data. */
> 	dio_bits = data_arr[i].DIO;
> 	comedi_dio_bitfield(comedi_dev, dio_subdev, dio_mask, &dio_bits);
> 
> 	/* Prepare and write AO data */
> 	data = data_arr[i].AO0;
> 	insn.data = &data;
> 	insn.chanspec = CR_PACK(0, range, aref);
> 	if(comedi_do_insn(comedi_dev, &insn)<0)
> 	{
> 	    comedi_perror("/dev/comedi0");
> 	    exit(1);
> 	}
> 
> 	data = data_arr[i].AO1;
> 	insn.data = &data;
> 	insn.chanspec = CR_PACK(1, range, aref);
> 	if(comedi_do_insn(comedi_dev, &insn)<0)
> 	{
> 	    comedi_perror("/dev/comedi0");
> 	    exit(1);
> 	}
> 	rt_task_wait_period();
>     }
> 
>     rt_make_soft_real_time();
> 
> #ifdef DEBUG
>     printf("We're back in soft realtime.\n");
> #endif
>     
>     // Stop timer
>     stop_rt_timer();
> 
>     // Unregister RT task
>     rt_task_delete(task);
> 
>     // Unlock mem
>     munlockall();
> 
>     return 0;
> }
> 
> 
> > 
> > Paolo. 
> > 
> > > Lennart.
> > > -- 
> > > *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
> > > L.C. Karssen
> > > Department of Physics and Astronomy
> > > Faculty of Science
> > > Utrecht University
> > > Princetonplein 1
> > > 3584 CC  Utrecht
> > > The Netherlands 
> > > 
> > > tel.: +31 (0)30-253-2208
> > > fax.: +31 (0)30-253-7468
> > > e-mail: L.C.Karssen_at_phys.uu.nl
> > > www: http://www1.phys.uu.nl/wwwaoud
> > > -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 
> > > 
> > > 
> > > _______________________________________________
> > > RTAI mailing list
> > > RTAI_at_rtai.org
> > > https://mail.rtai.org/cgi-bin/mailman/listinfo/rtai
> >  
-- 
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
L.C. Karssen
Department of Physics and Astronomy
Faculty of Science
Utrecht University
Princetonplein 1
3584 CC  Utrecht
The Netherlands

tel.: +31 (0)30-253-2208
fax.: +31 (0)30-253-7468
e-mail: L.C.Karssen_at_phys.uu.nl
www: http://www1.phys.uu.nl/wwwaoud
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

Received on 2007-05-21Z12:42:56