- From: Pecenin <mpecenin_at_yahoo.com.br>
- Date: Thu, 21 Jul 2005 14:02:14 -0300 (ART)
Yes, it work. I use the test below.
Thanks a lot!!!
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/comedi.h>
#include <linux/comedilib.h>
const char *dev_path = "/dev/comedi0";
comedi_t *dev = NULL;
unsigned int subd = 0;
void *ptr = NULL;
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 = 10000000;
cmd.convert_src = TRIG_TIMER;
cmd.convert_arg = 0;
cmd.scan_end_src = TRIG_COUNT;
cmd.scan_end_arg = 1;
cmd.stop_src = TRIG_COUNT;
cmd.stop_arg = 1000000000;
cmd.chanlist = chanlist;
cmd.chanlist_len = 1;
chanlist[0] = CR_PACK(0,0,0);
cmd.data=0;
cmd.data_len=0;
ret = comedi_command_test(dev,&cmd);
printk("command test returned %d\n",ret);
cmd.chanlist = chanlist;
cmd.chanlist_len = 1;
cmd.data=0;
cmd.data_len=0;
ret = comedi_command_test(dev,&cmd);
printk("command test returned %d\n",ret);
cmd.chanlist = chanlist;
cmd.chanlist_len = 1;
cmd.data=0;
cmd.data_len=0;
ret = comedi_command(dev,&cmd);
printk("command returned %d\n",ret);
return ret;
}
int callback(unsigned int i,void *arg)
{
int ret, ofs;
ofs = comedi_get_buffer_offset(dev, subd);
ret = comedi_get_buffer_contents(dev, subd);
rt_printk("sample: %d\n", *(sampl_t *)(ptr + ofs));
ret = comedi_mark_buffer_read(dev, subd,
sizeof(sampl_t));
return 0;
}
int init_module(void)
{
int ret;
dev = comedi_open(dev_path);
printk("comedi_open: %d\n",(int)dev);
ret = comedi_lock(dev,subd);
printk("comedi_lock: %d\n",ret);
ret = comedi_map(dev, subd, &ptr);
printk("comedi_map ret: %d, ptr: %d\n", ret,
(int)ptr);
comedi_register_callback(dev,subd,COMEDI_CB_EOS,callback,NULL);
do_cmd();
return 0;
}
void cleanup_module(void)
{
int ret;
ret = comedi_cancel(dev,subd);
printk("comedi_cancel: %d\n",ret);
ret = comedi_unmap(dev, subd);
printk("comedi_unmap ret: %d\n", ret);
ret = comedi_unlock(dev,subd);
printk("comedi_unlock: %d\n",ret);
ret = comedi_close(dev);
printk("comedi_close: %d\n", ret);
}
Pecenin
--- Andrés Cascallana Alvarez
<acascallana_at_simulare.com> escreveu:
> This code snippet is from a kernel module where 16
> bits samples are being
> adquired. I think that i got that from the
> mailing-list.
> On this example, a callback function is called each
> time an adquisition
> ends.That is done with comedi_register_callback()
> on init_module() before
> launching the comedi command, with the COMEDI_CB_EOS
> flag.
> I hope this helps.
> Regards,
>
> Andrés
>
>
//--------------------------------------------------------------------------
> -------------
> Global variables:
>
> comedi_t *dispositivo_comedi;
> void *map, *front;
>
>
//--------------------------------------------------------------------------
> -------------
> On init_module() :
>
> dispositivo_comedi =
> comedi_open(datablocks->comediai.device);
> if (dispositivo_comedi==NULL)
> {
> printk("Error en comedi_open.\n");
> return -1;
> }
>
> ret=comedi_map(dispositivo_comedi,0,&map); // Call
> comedi_unmap() on
> cleanup_module()
> if( ret < 0 )
> {
> printk("Error en mmap.\n");
> return -1;
> }
>
> front = (void *)comedi_get_buf_head_pos
> (dispositivo_comedi, 0);
>
>
//--------------------------------------------------------------------------
> -------------
> On the callback:
>
>
ret=comedi_get_buffer_contents(dispositivo_comedi,0);
> if (ret==-1)
> rt_printk("callback: Error en
> comedi_get_buffer_contents:
> %s\n",comedi_strerror(ret));
>
> if (ret!=-1)
> {
> front =
> comedi_get_buffer_offset(dispositivo_comedi, 0);
>
> for (i=0;i<ret/2;i++)
> {
> sample = *((lsampl_t *)(map + front + i*2));
> rt_printk("%04x ",sample);
> }
>
> rt_printk("\n");
>
>
>
ret=comedi_mark_buffer_read(dispositivo_comedi,0,ret);
> if (ret==-1)
> rt_printk("callback: Error en
> comedi_get_buffer_contents:
> %s\n",comedi_strerror(ret));
> }
>
>
> _______________________________________________
> comedi mailing list
> comedi_at_comedi.org
>
https://cvs.comedi.org/cgi-bin/mailman/listinfo/comedi
>
_______________________________________________________
Yahoo! Acesso Grátis - Internet rápida e grátis.
Instale o discador agora! http://br.acesso.yahoo.com/
Received on 2005-07-21Z16:02:14