comedi_register_callback issues

I could not find any working examples with comedi_register_callback :-(

The realtime examples on the comedi website seem to be
rather old and do crash the system like my own program. :-(

Unfortunately there seems to be no documentation, if there is any
please let me know......

So any example code regarding this issue would be very very helpful :-)
I am sick of rebooting the machine every time I try some different values.

Ciao,
 Dominic

RTLINUX 3.1 / kernel 2.4.18 / latest stable comedi(lib) / ni_pcimio driver

P.S. A periodic thread calling comedi_data_read does work though...


Source:
-------------------------------------------------------------------------------
/*
 * Dominic Hillenbrand August 2002 
 * Universität Kaiserslautern
 *
 */

#include <rtl.h>
#include <rtl_fifo.h>
#include <rtl_debug.h>
#include <rtl_sched.h>
#include <rtl_sync.h>

#include <linux/comedi.h>
#include <linux/comedilib.h>

#define DHX_KHZ_TO_NANO(khz) (1.0/khz*1000000)
#define DHX_ENTER rtl_printf("enter %s\n", __PRETTY_FUNCTION__);
#define DHX_LEAVE rtl_printf("leave %s\n", __PRETTY_FUNCTION__);
#define DHX_DEBUG(cmd) cmd
#define BUFSIZE 1024

int do_cmd(void);

comedi_t *device;

unsigned int aref = AREF_GROUND;
unsigned int subdevice=0;
unsigned int channel;
unsigned int range;

sampl_t data;
static volatile int i=0;


int callback(unsigned int flag,void *arg)
{
        i++;
        //DHX_ENTER
        //rtl_printf("data %d\n", data);
    //DHX_LEAVE
        return 0;
}

int init_module(void)
{
        int ret;
          
        DHX_ENTER

        printk("comedi_open\n");
        device = comedi_open("/dev/comedi0");
        if (device==NULL) goto cleanup;

        printk("comedi_lock\n");
        ret = comedi_lock(device,subdevice);
        if (ret<0) goto cleanup;

        printk("register\n");
        ret = comedi_register_callback(device,subdevice,COMEDI_CB_EOS,callback,NULL); 
    if (ret<0) goto cleanup;
                
        
        printk("do_cmd\n");
        ret = do_cmd();
        if (ret<0) goto cleanup;
        


        
    DHX_LEAVE
        return 0;
cleanup:
        DHX_DEBUG(rtl_printf("comedi cannot be invoked\n"));
        DHX_LEAVE
        return -1;
}


void cleanup_module(void)
{
        int ret;
        
        DHX_ENTER
        
        printk("comedi_cancel\n");
        ret = comedi_cancel(device,subdevice);
        if (ret!=0) goto cleanup;

        printk("comedi_unlock\n");
        ret = comedi_unlock(device,subdevice);
        if (ret!=0) goto cleanup;
    
        printk("comedi_close\n");
    comedi_close(device);
        rtl_printf("%d=i\n",i);
        DHX_LEAVE
        return;
        
cleanup:
        DHX_DEBUG(rtl_printf("comedi shutdown failed\n"));
          comedi_close(device);
        DHX_LEAVE
}


int do_cmd(void)
{
        int ret;

        comedi_cmd cmd;
        unsigned int chanlist[1];

        cmd.subdev = subdevice;
        cmd.flags = TRIG_WAKE_EOS;

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

        cmd.scan_begin_src = TRIG_TIMER;
        cmd.scan_begin_arg = 500000;

        cmd.convert_src = TRIG_TIMER;
        cmd.convert_arg = 500000;

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

        cmd.stop_src = TRIG_NONE;
        cmd.stop_arg = 0;

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

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

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

    printk("comedi_test 1\n");
        ret = comedi_command_test(device,&cmd);
        //if (ret<0) goto cleanup;
    
        cmd.chanlist = chanlist;
        cmd.chanlist_len = 1;
        cmd.data=&data;
        cmd.data_len=sizeof(sampl_t);

    printk("comedi_test 2\n");
        ret = comedi_command_test(device,&cmd);
        if (ret<0) goto cleanup;
        
        cmd.chanlist = chanlist;
        cmd.chanlist_len = 1;
        cmd.data=&data;
        cmd.data_len=sizeof(sampl_t);

        printk("comedi_command\n");
        ret = comedi_command(device,&cmd);
        if (ret<0) goto cleanup;
    
        return ret;
cleanup:        
        DHX_DEBUG(rtl_printf("do_cmd problems :-(\n"));
        return ret;
}

Received on 2002-08-13Z16:57:16