RE: comedi_command and RTLinux

Thanks Ivan, That works but it's not quite what I need/want to do.  I'd
like to set the card up via the comedi_command as one does in user space
in the cmd.c demo but do it in kernel space.  The comedi_command[_test]
calls are in the kernel version's comedilib.h file and the comments say
that they may be called from any priority as long as the subdevice is
locked.  I'm only able to execute the calls from the init_module
routine.  I could learn to live with that if I was able to then obtain
the data the card had supposedly been collecting.  

So, what I'm trying now from the init_module routine is set up a long
running command, submit it after comedi_command_test returns success,
and then from a real-time thread examine the data_len member of the cmd
struct.  But, the data_len never changes.

Is this the correct way to do this?  Since there aren't any other
command API calls available from the kernel comedilib.h header I was
assuming that I had DMA to the data on the card via the cmd.data member.
Is this correct or am I just totally lost? 

Wondering,
Evan



-----Original Message-----
From: comedi-admin_at_comedi.org [mailto:comedi-admin_at_comedi.org] On Behalf
Of Ivan Raikov
Sent: Friday, November 22, 2002 7:02 PM
To: Evan Carey
Cc: comedi_at_comedi.org
Subject: Re: comedi_command and RTLinux


        The following code works with Linux 2.4.19, NI 6052 board, and
RT-Linux 3.1 patched with the "unofficial" 2.4.19 patch. I'm probably
going to test it with RTL 3.2 sometime this weekend.

        I haven't provided the board initialization code here, since
it's a little more hairy, but I can send you that too, if you like.
        

/* 
   Performs a read from an analog channel of the data acquisition
   board. The value returned is the return status of the Comedi read
   instruction (0 for success).

   Arguments have the following meaning:

   comedi_t *handle  --  the device handle, as returned by comedi_open 
   int ai_subdev     --  the index of a subdevice capable of reading
                         data; this index can be obtained through
                         comedi_find_subdevice_by_type 
   int channel       --  channel that we are interested of acquiring
                         through (number of channels is obtainable
                         through comedi_get_n_channels)
   
*/
inline int do_in_insn (comedi_t *handle, int ai_subdev, int channel)
{
    comedi_insn insn;

    memset(&insn, 0, sizeof(insn));

    insn.insn = INSN_READ;
    // we want to obtain one sample
    insn.n = 1;
    // sets a pointer to the buffer where we'll be storing the
    // acquired samples 
    insn.data = (lsampl_t *)data_in;
    // set the subdevice to read from
    insn.subdev = ai_subdev;
    // sets the channels, the range, and the analog reference
    insn.chanspec = CR_PACK(channel, comedi_ai_range, AREF_GROUND);

    // performs the instruction
    return comedi_do_insn (handle, &insn);
}

/* 
   Performs a write to an analog channel of the data acquisition
   board. The value returned is the return status of the Comedi write
   instruction (0 for success).

   Arguments have the following meaning:

   comedi_t *handle  --  the device handle, as returned by comedi_open 
   int ao_subdev     --  the index of a subdevice capable of writing
                         data; this index can be obtained through
                         comedi_find_subdevice_by_type 

   int channel       -- channel that we are interested of writing to
                         (number of channels is obtainable through
                         comedi_get_n_channels)
*/

inline int do_out_insn (comedi_t *handle, int ao_subdev, int channel)
{
    comedi_insn insn;
    
     memset(&insn, 0, sizeof(insn)); 
     
     insn.insn = INSN_WRITE; 
     // we want to write one sample
     insn.n = 1; 
     // sets a pointer to the buffer containing the data to be written 
     insn.data = (lsampl_t *)data_out; 
     // sets the subdevice to write to
     insn.subdev = ao_subdev; 
     // sets the channels, the range, the analog reference
     insn.chanspec = CR_PACK(channel, comedi_ao_range, AREF_GROUND); 

     // performs the instruction
     return comedi_do_insn (handle, &insn); 
}


"Evan Carey" <ecarey_at_zyvex.com> writes:

> Does anyone have an example of using the comedi_command and
> comedi_command_test from a RTLinux real-time thread that they would
mind
> sharing?  I'm having no luck with it.  When I attempt
> comedi_command_test from a rt thread my machine just locks up.  Is
this
> possible?  A bad idea? Or what?
> 
> I thought I saw someone ask this once before in this group but I never
> saw a reply to it.
> 
> Thanks,
> Evan
> 

-- 
Ivan Raikov
337466 Georgia Tech Station, Atlanta, GA 30332-1750

_______________________________________________
comedi mailing list
comedi_at_comedi.org
https://cvs.comedi.org/cgi-bin/mailman/listinfo/comedi

Received on 2002-11-26Z17:23:20