1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "../comedidev.h"
28
29#include "comedi_fc.h"
30
31static void increment_scan_progress(struct comedi_subdevice *subd,
32 unsigned int num_bytes)
33{
34 struct comedi_async *async = subd->async;
35 unsigned int scan_length = cfc_bytes_per_scan(subd);
36
37 async->scan_progress += num_bytes;
38 if (async->scan_progress >= scan_length) {
39 async->scan_progress %= scan_length;
40 async->events |= COMEDI_CB_EOS;
41 }
42}
43
44
45unsigned int cfc_write_array_to_buffer(struct comedi_subdevice *subd,
46 void *data, unsigned int num_bytes)
47{
48 struct comedi_async *async = subd->async;
49 unsigned int retval;
50
51 if (num_bytes == 0)
52 return 0;
53
54 retval = comedi_buf_write_alloc(async, num_bytes);
55 if (retval != num_bytes) {
56 printk(KERN_WARNING "comedi: buffer overrun\n");
57 async->events |= COMEDI_CB_OVERFLOW;
58 return 0;
59 }
60
61 comedi_buf_memcpy_to(async, 0, data, num_bytes);
62 comedi_buf_write_free(async, num_bytes);
63 increment_scan_progress(subd, num_bytes);
64 async->events |= COMEDI_CB_BLOCK;
65
66 return num_bytes;
67}
68EXPORT_SYMBOL(cfc_write_array_to_buffer);
69
70unsigned int cfc_read_array_from_buffer(struct comedi_subdevice *subd,
71 void *data, unsigned int num_bytes)
72{
73 struct comedi_async *async = subd->async;
74
75 if (num_bytes == 0)
76 return 0;
77
78 num_bytes = comedi_buf_read_alloc(async, num_bytes);
79 comedi_buf_memcpy_from(async, 0, data, num_bytes);
80 comedi_buf_read_free(async, num_bytes);
81 increment_scan_progress(subd, num_bytes);
82 async->events |= COMEDI_CB_BLOCK;
83
84 return num_bytes;
85}
86EXPORT_SYMBOL(cfc_read_array_from_buffer);
87
88unsigned int cfc_handle_events(struct comedi_device *dev,
89 struct comedi_subdevice *subd)
90{
91 unsigned int events = subd->async->events;
92
93 if (events == 0)
94 return events;
95
96 if (events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW))
97 subd->cancel(dev, subd);
98
99 comedi_event(dev, subd);
100
101 return events;
102}
103EXPORT_SYMBOL(cfc_handle_events);
104
105MODULE_AUTHOR("Frank Mori Hess <fmhess@users.sourceforge.net>");
106MODULE_DESCRIPTION("Shared functions for Comedi low-level drivers");
107MODULE_LICENSE("GPL");
108
109static int __init comedi_fc_init_module(void)
110{
111 return 0;
112}
113
114static void __exit comedi_fc_cleanup_module(void)
115{
116}
117
118module_init(comedi_fc_init_module);
119module_exit(comedi_fc_cleanup_module);
120