callback technique question & comedi_command bug(?)

Currently I do issue a comedi_command & comedi_register_callback
everytime the callback is called.
How can I avoid it? Since I think it's going to cut down
performance.


KComedilib will crash if I change cmd.stop_arg from
10 to 1.
2 is fine, but this reduces the sampling rate by one
half.


cmd.scan_end_src = TRIG_COUNT;
cmd.scan_end_arg = 1;

cmd.stop_src = TRIG_COUNT;
cmd.stop_arg = 10;


Ok. Last question ;-)
Can I use comedi_command to issue a asynchronous write?
Currently I use comedi_data_write.

Ciao,
 Dominic

/*
 * Dominic Hillenbrand August 2002 
 * Universität Kaiserslautern
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/comedi.h>
#include <linux/comedilib.h>
#include <rtl.h>
  
#define BUFSIZE 1

comedi_t *dev;
int subd=0;
int subdevice_ao;

sampl_t data[BUFSIZE];
int callback(unsigned int i,void *arg);

int do_cmd(void)
{
        int ret;

        comedi_cmd cmd;
        unsigned int chanlist[1];

        cmd.subdev = subd;
        cmd.flags = 0;

        cmd.start_src = TRIG_NOW;
        cmd.start_arg = 0;

        cmd.scan_begin_src = TRIG_TIMER;
        cmd.scan_begin_arg = 100000;

        cmd.convert_src = TRIG_TIMER;
        cmd.convert_arg = 100000;

        cmd.scan_end_src = TRIG_COUNT;
        cmd.scan_end_arg = 1;

        cmd.stop_src = TRIG_COUNT;
        cmd.stop_arg = 10;

        cmd.chanlist = chanlist;
        cmd.chanlist_len = 1;

        chanlist[0] = CR_PACK(0,0,0);

        cmd.data=data;
        cmd.data_len=BUFSIZE*sizeof(sampl_t);

        ret = comedi_command_test(dev,&cmd);
        //printk("command test returned %d\n",ret);

        cmd.chanlist = chanlist;
        cmd.chanlist_len = 1;
        cmd.data=data;
        cmd.data_len=BUFSIZE*sizeof(sampl_t);

        ret = comedi_command_test(dev,&cmd);
        //printk("command test returned %d\n",ret);
        if(ret)return ret;

        cmd.chanlist = chanlist;
        cmd.chanlist_len = 1;
        cmd.data=data;
        cmd.data_len=BUFSIZE*sizeof(sampl_t);
        
        // this used to crash if done after do_cmd in main like
        // in the comedi realtime examples!!!!!!!!!!
        comedi_register_callback(dev,subd,COMEDI_CB_EOS,callback,NULL);

        ret = comedi_command(dev,&cmd);
        //printk("command returned %d\n",ret);

        return ret;
}




static int counter = 0;

int callback(unsigned int i,void *arg)
{
        
        comedi_data_write(dev,subdevice_ao,0,0,AREF_GROUND, data[0]>>4);
        //rtl_printf("who's yer daddy? %d\n",counter);
        counter++;
        do_cmd();

        return 0;
}

int init_module(void)
{
        
        int ret;
        
        printk("Comedi real-time example #1\n");

        dev = comedi_open("/dev/comedi0");
        printk("comedi_open: %d\n",ret);

        ret = comedi_lock(dev,subd);
        printk("comedi_lock: %d\n",ret);
        
        subdevice_ao=comedi_find_subdevice_by_type(dev,COMEDI_SUBD_AO,0);
        
        do_cmd();
        
        return 0;
        
}


void cleanup_module(void)
{
        int ret;

        ret = comedi_cancel(dev,subd);
        printk("comedi_cancel: %d\n",ret);

        ret = comedi_unlock(dev,subd);
        printk("comedi_unlock: %d\n",ret);

        comedi_close(dev);
        printk("comedi_close:\n");        
}





______________________________________________________________________________
Jetzt testen fur 1 Euro! Ihr All-in-one-Paket! 
https://digitaledienste.web.de/Club/formular/?mc=021106

Received on 2002-08-21Z05:24:32