2 comedi/drivers/comedi_fc.c
4 This is a place for code driver writers wish to share between
5 two or more drivers. fc is short
8 Author: Frank Mori Hess <fmhess@users.sourceforge.net>
9 Copyright (C) 2002 Frank Mori Hess
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
22 #include <linux/module.h>
23 #include "../comedidev.h"
25 #include "comedi_fc.h"
27 static void increment_scan_progress(struct comedi_subdevice *subd,
28 unsigned int num_bytes)
30 struct comedi_async *async = subd->async;
31 unsigned int scan_length = cfc_bytes_per_scan(subd);
33 async->scan_progress += num_bytes;
34 if (async->scan_progress >= scan_length) {
35 async->scan_progress %= scan_length;
36 async->events |= COMEDI_CB_EOS;
40 /* Writes an array of data points to comedi's buffer */
41 unsigned int cfc_write_array_to_buffer(struct comedi_subdevice *subd,
42 void *data, unsigned int num_bytes)
44 struct comedi_async *async = subd->async;
50 retval = comedi_buf_write_alloc(async, num_bytes);
51 if (retval != num_bytes) {
52 dev_warn(subd->device->class_dev, "comedi: buffer overrun\n");
53 async->events |= COMEDI_CB_OVERFLOW;
57 comedi_buf_memcpy_to(async, 0, data, num_bytes);
58 comedi_buf_write_free(async, num_bytes);
59 increment_scan_progress(subd, num_bytes);
60 async->events |= COMEDI_CB_BLOCK;
64 EXPORT_SYMBOL_GPL(cfc_write_array_to_buffer);
66 unsigned int cfc_read_array_from_buffer(struct comedi_subdevice *subd,
67 void *data, unsigned int num_bytes)
69 struct comedi_async *async = subd->async;
74 num_bytes = comedi_buf_read_alloc(async, num_bytes);
75 comedi_buf_memcpy_from(async, 0, data, num_bytes);
76 comedi_buf_read_free(async, num_bytes);
77 increment_scan_progress(subd, num_bytes);
78 async->events |= COMEDI_CB_BLOCK;
82 EXPORT_SYMBOL_GPL(cfc_read_array_from_buffer);
84 unsigned int cfc_handle_events(struct comedi_device *dev,
85 struct comedi_subdevice *subd)
87 unsigned int events = subd->async->events;
92 if (events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW))
93 subd->cancel(dev, subd);
95 comedi_event(dev, subd);
99 EXPORT_SYMBOL_GPL(cfc_handle_events);
101 MODULE_AUTHOR("Frank Mori Hess <fmhess@users.sourceforge.net>");
102 MODULE_DESCRIPTION("Shared functions for Comedi low-level drivers");
103 MODULE_LICENSE("GPL");
105 static int __init comedi_fc_init_module(void)
110 static void __exit comedi_fc_cleanup_module(void)
114 module_init(comedi_fc_init_module);
115 module_exit(comedi_fc_cleanup_module);