mmap works for output waveforms now.
authorFrank Mori Hess <fmhess@speakeasy.net>
Sun, 23 Jan 2005 03:11:30 +0000 (03:11 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Sun, 23 Jan 2005 03:11:30 +0000 (03:11 +0000)
demo/ao_mmap.c
include/comedi.h
lib/buffer.c
swig/comedi.i

index 1646c764b4dc270a91b25c88aeab47c094ae4949..f4b65d9aa5879849874f563b4aa95058043f21ed 100644 (file)
@@ -76,6 +76,7 @@ int main(int argc, char *argv[])
        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;
@@ -148,36 +149,45 @@ int main(int argc, char *argv[])
                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;
 }
index f344656cbb1b0f2a0a22dc860c94bee0a2603918..a22c2b203cef1156f6e383aac2673e5d7a47887b 100644 (file)
@@ -389,10 +389,10 @@ struct comedi_bufinfo_struct{
        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;
 
index b197c3eb5f16e3a96d53c250fe8d7c9c9146da18..a3d70b3a1f19fcb2a4fc1e6f8b3d52d2e6188920 100644 (file)
@@ -81,11 +81,12 @@ int _comedi_mark_buffer_read(comedi_t *it, unsigned int subdev, unsigned int byt
        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);
@@ -95,11 +96,12 @@ int _comedi_mark_buffer_written(comedi_t *it, unsigned int subdev, unsigned int
        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);
@@ -109,9 +111,10 @@ int _comedi_get_buffer_offset(comedi_t *it, unsigned int subdev)
        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);
@@ -121,8 +124,9 @@ int _comedi_get_front_count(comedi_t *it, unsigned int subdev)
        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;
 }
 
index f1046923b7a4ceeb9d557b4596d3220f84208242..c1bba4463d81122b41cc17c30f48eff45fe159ed 100644 (file)
@@ -362,10 +362,10 @@ struct comedi_bufinfo_struct{
        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;