4 This is a place for code driver writers wish to share between
5 two or more drivers. These functions are meant to be used only
6 by drivers, they are NOT part of the kcomedilib API!
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.
25 #include "../comedidev.h"
27 /* Writes an array of data points to comedi's buffer */
28 extern unsigned int cfc_write_array_to_buffer(struct comedi_subdevice *subd,
30 unsigned int num_bytes);
32 static inline unsigned int cfc_write_to_buffer(struct comedi_subdevice *subd,
35 return cfc_write_array_to_buffer(subd, &data, sizeof(data));
38 static inline unsigned int cfc_write_long_to_buffer(struct comedi_subdevice
39 *subd, unsigned int data)
41 return cfc_write_array_to_buffer(subd, &data, sizeof(data));
44 extern unsigned int cfc_read_array_from_buffer(struct comedi_subdevice *subd,
46 unsigned int num_bytes);
48 extern unsigned int cfc_handle_events(struct comedi_device *dev,
49 struct comedi_subdevice *subd);
51 static inline unsigned int cfc_bytes_per_scan(struct comedi_subdevice *subd)
60 bits_per_sample = 8 * bytes_per_sample(subd);
61 num_samples = (subd->async->cmd.chanlist_len +
62 bits_per_sample - 1) / bits_per_sample;
65 num_samples = subd->async->cmd.chanlist_len;
68 return num_samples * bytes_per_sample(subd);
72 * cfc_check_trigger_src() - trivially validate a comedi_cmd trigger source
73 * @src: pointer to the trigger source to validate
74 * @flags: bitmask of valid TRIG_* for the trigger
76 * This is used in "step 1" of the do_cmdtest functions of comedi drivers
77 * to vaildate the comedi_cmd triggers. The mask of the @src against the
78 * @flags allows the userspace comedilib to pass all the comedi_cmd
79 * triggers as TRIG_ANY and get back a bitmask of the valid trigger sources.
81 static inline int cfc_check_trigger_src(unsigned int *src, unsigned int flags)
83 unsigned int orig_src = *src;
85 *src = orig_src & flags;
86 if (*src == TRIG_INVALID || *src != orig_src)
92 * cfc_check_trigger_is_unique() - make sure a trigger source is unique
93 * @src: the trigger source to check
95 static inline int cfc_check_trigger_is_unique(unsigned int src)
97 /* this test is true if more than one _src bit is set */
98 if ((src & (src - 1)) != 0)
104 * cfc_check_trigger_arg_is() - trivially validate a trigger argument
105 * @arg: pointer to the trigger arg to validate
106 * @val: the value the argument should be
108 static inline int cfc_check_trigger_arg_is(unsigned int *arg, unsigned int val)
118 * cfc_check_trigger_arg_min() - trivially validate a trigger argument
119 * @arg: pointer to the trigger arg to validate
120 * @val: the minimum value the argument should be
122 static inline int cfc_check_trigger_arg_min(unsigned int *arg,
133 * cfc_check_trigger_arg_max() - trivially validate a trigger argument
134 * @arg: pointer to the trigger arg to validate
135 * @val: the maximum value the argument should be
137 static inline int cfc_check_trigger_arg_max(unsigned int *arg,
147 #endif /* _COMEDI_FC_H */