defined generic inline functions for writing/reading a data point to/from comedi...
authorFrank Mori Hess <fmhess@speakeasy.net>
Sun, 10 Jun 2001 20:32:53 +0000 (20:32 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Sun, 10 Jun 2001 20:32:53 +0000 (20:32 +0000)
include/linux/comedidev.h

index cc8aecd8f4a9ee136e18ddeb5eaf2d73e3708143..62a73237c72599dc9bd0fda3acf5d3d6ec145351 100644 (file)
@@ -286,6 +286,46 @@ static inline int alloc_private(comedi_device *dev,int size)
        return 0;
 }
 
+// writes a data point to comedi's buffer, used for input
+static inline void comedi_buf_put(comedi_async *async, sampl_t x)
+{
+
+       *(sampl_t *)(async->data + async->buf_int_ptr) = x;
+       async->buf_int_ptr += sizeof(sampl_t);
+       if(async->buf_int_ptr >= async->data_len){
+               async->buf_int_ptr = 0;
+               async->events |= COMEDI_CB_EOBUF;
+       }
+       if(++async->cur_chan >= async->cur_chanlist_len){
+               async->cur_chan = 0;
+               async->events |= COMEDI_CB_EOS;
+       }
+       async->buf_int_count += sizeof(sampl_t);
+}
+
+/* Reads a data point from comedi's buffer, used for output.
+ * returns signed int so error can be returned as negative. */
+static inline int comedi_buf_get(comedi_async *async)
+{
+       sampl_t data;
+
+       if(async->buf_int_count == async->buf_user_count)
+               return -EAGAIN;
+
+       data = *(sampl_t *)(async->data + async->buf_int_ptr);
+       async->buf_int_ptr += sizeof(sampl_t);
+       if(async->buf_int_ptr >= async->data_len){
+               async->buf_int_ptr = 0;
+               async->events |= COMEDI_CB_EOBUF;
+       }
+       if(++async->cur_chan >= async->cur_chanlist_len){
+               async->cur_chan = 0;
+               async->events |= COMEDI_CB_EOS;
+       }
+       async->buf_int_count += sizeof(sampl_t);
+
+       return data;
+}
 
 #ifdef LINUX_V20
 extern struct symbol_table comedi_syms;