3 * This is a place for code driver writers wish to share between
4 * two or more drivers. fc is short for frank-common.
6 * Author: Frank Mori Hess <fmhess@users.sourceforge.net>
7 * Copyright (C) 2002 Frank Mori Hess
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #include <linux/module.h>
21 #include "../comedidev.h"
23 #include "comedi_fc.h"
25 unsigned int cfc_bytes_per_scan(struct comedi_subdevice *s)
27 struct comedi_cmd *cmd = &s->async->cmd;
28 unsigned int num_samples;
29 unsigned int bits_per_sample;
35 bits_per_sample = 8 * bytes_per_sample(s);
36 num_samples = (cmd->chanlist_len + bits_per_sample - 1) /
40 num_samples = cmd->chanlist_len;
43 return num_samples * bytes_per_sample(s);
45 EXPORT_SYMBOL_GPL(cfc_bytes_per_scan);
47 void cfc_inc_scan_progress(struct comedi_subdevice *s, unsigned int num_bytes)
49 struct comedi_async *async = s->async;
50 unsigned int scan_length = cfc_bytes_per_scan(s);
52 async->scan_progress += num_bytes;
53 if (async->scan_progress >= scan_length) {
54 async->scan_progress %= scan_length;
55 async->events |= COMEDI_CB_EOS;
58 EXPORT_SYMBOL_GPL(cfc_inc_scan_progress);
60 /* Writes an array of data points to comedi's buffer */
61 unsigned int cfc_write_array_to_buffer(struct comedi_subdevice *s,
62 void *data, unsigned int num_bytes)
64 struct comedi_async *async = s->async;
70 retval = comedi_buf_write_alloc(s, num_bytes);
71 if (retval != num_bytes) {
72 dev_warn(s->device->class_dev, "buffer overrun\n");
73 async->events |= COMEDI_CB_OVERFLOW;
77 comedi_buf_memcpy_to(s, 0, data, num_bytes);
78 comedi_buf_write_free(s, num_bytes);
79 cfc_inc_scan_progress(s, num_bytes);
80 async->events |= COMEDI_CB_BLOCK;
84 EXPORT_SYMBOL_GPL(cfc_write_array_to_buffer);
86 unsigned int cfc_read_array_from_buffer(struct comedi_subdevice *s,
87 void *data, unsigned int num_bytes)
92 num_bytes = comedi_buf_read_alloc(s, num_bytes);
93 comedi_buf_memcpy_from(s, 0, data, num_bytes);
94 comedi_buf_read_free(s, num_bytes);
95 cfc_inc_scan_progress(s, num_bytes);
96 s->async->events |= COMEDI_CB_BLOCK;
100 EXPORT_SYMBOL_GPL(cfc_read_array_from_buffer);
102 unsigned int cfc_handle_events(struct comedi_device *dev,
103 struct comedi_subdevice *s)
105 unsigned int events = s->async->events;
110 if (events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW))
113 comedi_event(dev, s);
117 EXPORT_SYMBOL_GPL(cfc_handle_events);
119 static int __init comedi_fc_init_module(void)
123 module_init(comedi_fc_init_module);
125 static void __exit comedi_fc_cleanup_module(void)
128 module_exit(comedi_fc_cleanup_module);
130 MODULE_AUTHOR("Frank Mori Hess <fmhess@users.sourceforge.net>");
131 MODULE_DESCRIPTION("Shared functions for Comedi low-level drivers");
132 MODULE_LICENSE("GPL");