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 "../comedidev.h"
24 #include "comedi_fc.h"
26 static void increment_scan_progress(struct comedi_subdevice
*subd
,
27 unsigned int num_bytes
)
29 struct comedi_async
*async
= subd
->async
;
30 unsigned int scan_length
= cfc_bytes_per_scan(subd
);
32 async
->scan_progress
+= num_bytes
;
33 if (async
->scan_progress
>= scan_length
) {
34 async
->scan_progress
%= scan_length
;
35 async
->events
|= COMEDI_CB_EOS
;
39 /* Writes an array of data points to comedi's buffer */
40 unsigned int cfc_write_array_to_buffer(struct comedi_subdevice
*subd
,
41 void *data
, unsigned int num_bytes
)
43 struct comedi_async
*async
= subd
->async
;
49 retval
= comedi_buf_write_alloc(async
, num_bytes
);
50 if (retval
!= num_bytes
) {
51 dev_warn(subd
->device
->class_dev
, "comedi: buffer overrun\n");
52 async
->events
|= COMEDI_CB_OVERFLOW
;
56 comedi_buf_memcpy_to(async
, 0, data
, num_bytes
);
57 comedi_buf_write_free(async
, num_bytes
);
58 increment_scan_progress(subd
, num_bytes
);
59 async
->events
|= COMEDI_CB_BLOCK
;
63 EXPORT_SYMBOL_GPL(cfc_write_array_to_buffer
);
65 unsigned int cfc_read_array_from_buffer(struct comedi_subdevice
*subd
,
66 void *data
, unsigned int num_bytes
)
68 struct comedi_async
*async
= subd
->async
;
73 num_bytes
= comedi_buf_read_alloc(async
, num_bytes
);
74 comedi_buf_memcpy_from(async
, 0, data
, num_bytes
);
75 comedi_buf_read_free(async
, num_bytes
);
76 increment_scan_progress(subd
, num_bytes
);
77 async
->events
|= COMEDI_CB_BLOCK
;
81 EXPORT_SYMBOL_GPL(cfc_read_array_from_buffer
);
83 unsigned int cfc_handle_events(struct comedi_device
*dev
,
84 struct comedi_subdevice
*subd
)
86 unsigned int events
= subd
->async
->events
;
91 if (events
& (COMEDI_CB_EOA
| COMEDI_CB_ERROR
| COMEDI_CB_OVERFLOW
))
92 subd
->cancel(dev
, subd
);
94 comedi_event(dev
, subd
);
98 EXPORT_SYMBOL_GPL(cfc_handle_events
);
100 MODULE_AUTHOR("Frank Mori Hess <fmhess@users.sourceforge.net>");
101 MODULE_DESCRIPTION("Shared functions for Comedi low-level drivers");
102 MODULE_LICENSE("GPL");
104 static int __init
comedi_fc_init_module(void)
109 static void __exit
comedi_fc_cleanup_module(void)
113 module_init(comedi_fc_init_module
);
114 module_exit(comedi_fc_cleanup_module
);