Re: How to get the sampled values on asynchronous aquisition (kernel space)

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));
 }

Received on 2005-07-20Z13:35:17