comedi_range *rng;
int ret;
int size;
+ int num_samples;
sampl_t *map;
/* peak-to-peak amplitude, in DAC units (i.e., 0-4095) */
double amplitude;
perror("mmap");
exit(1);
}
- write_waveform(map, size / sizeof(sampl_t), amplitude, offset, maxdata);
+ num_samples = size / sizeof(sampl_t);
+ write_waveform(map, num_samples, amplitude, offset, maxdata);
if(msync(map, size, MS_SYNC) < 0)
{
perror("msync");
exit(1);
}
- if(comedi_mark_buffer_written(dev, subdevice, size) < 0)
+ printf("marking %i samples as written\n", num_samples);
+ ret = comedi_mark_buffer_written(dev, subdevice, size);
+ if(ret < 0)
{
comedi_perror("comedi_mark_buffer_written");
exit(1);
}
ret = comedi_internal_trigger(dev, subdevice, 0);
if(ret<0){
- comedi_perror("comedi_internal_trigger\n");
+ comedi_perror("comedi_internal_trigger");
exit(1);
}
- while(1){
+ while(1)
+ {
int bytes_marked = comedi_get_buffer_contents(dev,subdevice);
- if(bytes_marked < 1)
+ if(bytes_marked < 0)
{
comedi_perror("comedi_get_buffer_contents");
exit(1);
}
int bytes_unmarked = size - bytes_marked;
- // this keeps comedi from reporting a buffer underrun
- if(comedi_mark_buffer_written(dev, subdevice, bytes_unmarked) < 0)
+ if(bytes_unmarked > 0)
{
- comedi_perror("comedi_mark_buffer_written");
- exit(1);
- }
+ // this keeps comedi from reporting a buffer underrun
+ if(comedi_mark_buffer_written(dev, subdevice, bytes_unmarked) < 0)
+ {
+ comedi_perror("comedi_mark_buffer_written");
+ exit(1);
+ }
+ printf("marked %i more samples as written\n", bytes_unmarked / sizeof(sampl_t));
+ }else
+ usleep(10000);
}
return 0;
}
unsigned int subdevice;
unsigned int bytes_read;
- unsigned int buf_int_ptr;
- unsigned int buf_user_ptr;
- unsigned int buf_int_count;
- unsigned int buf_user_count;
+ unsigned int buf_write_ptr;
+ unsigned int buf_read_ptr;
+ unsigned int buf_write_count;
+ unsigned int buf_read_count;
unsigned int bytes_written;
comedi_bufinfo bi;
memset(&bi, 0, sizeof(bi));
+ bi.subdevice = subdev;
bi.bytes_read = bytes;
ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, (unsigned long)&bi);
__comedi_errno = errno;
if(__comedi_errno == EPIPE)__comedi_errno = EBUF_OVR;
- return bi.buf_int_count - bi.buf_user_count;
+ return bi.buf_write_count - bi.buf_read_count;
}
EXPORT_ALIAS_DEFAULT(_comedi_mark_buffer_written,comedi_mark_buffer_written,0.7.23);
comedi_bufinfo bi;
memset(&bi, 0, sizeof(bi));
+ bi.subdevice = subdev;
bi.bytes_written = bytes;
ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, (unsigned long)&bi);
__comedi_errno = errno;
if(__comedi_errno == EPIPE)__comedi_errno = EBUF_UNDR;
- return bi.buf_int_count - bi.buf_user_count;
+ return bi.buf_write_count - bi.buf_read_count;
}
EXPORT_ALIAS_DEFAULT(_comedi_get_buffer_offset,comedi_get_buffer_offset,0.7.18);
comedi_bufinfo bi;
memset(&bi, 0, sizeof(bi));
+ bi.subdevice = subdev;
ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, (unsigned long)&bi);
if(ret < 0) return ret;
- return bi.buf_user_ptr;
+ return bi.buf_read_ptr;
}
EXPORT_ALIAS_DEFAULT(_comedi_get_front_count,comedi_get_front_count,0.7.18);
comedi_bufinfo bi;
memset(&bi, 0, sizeof(bi));
+ bi.subdevice = subdev;
ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, (unsigned long)&bi);
if(ret < 0) return ret;
- return bi.buf_int_count;
+ return bi.buf_write_count;
}
unsigned int subdevice;
unsigned int bytes_read;
- unsigned int buf_int_ptr;
- unsigned int buf_user_ptr;
- unsigned int buf_int_count;
- unsigned int buf_user_count;
+ unsigned int buf_write_ptr;
+ unsigned int buf_read_ptr;
+ unsigned int buf_write_count;
+ unsigned int buf_read_count;
unsigned int bytes_written;