1/* 2 * comedi_fc.h 3 * This is a place for code driver writers wish to share between 4 * two or more drivers. These functions are meant to be used only 5 * by drivers, they are NOT part of the kcomedilib API! 6 * 7 * Author: Frank Mori Hess <fmhess@users.sourceforge.net> 8 * Copyright (C) 2002 Frank Mori Hess 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 */ 20 21#ifndef _COMEDI_FC_H 22#define _COMEDI_FC_H 23 24#include "../comedidev.h" 25 26unsigned int cfc_bytes_per_scan(struct comedi_subdevice *); 27void cfc_inc_scan_progress(struct comedi_subdevice *, unsigned int num_bytes); 28 29/* Writes an array of data points to comedi's buffer */ 30unsigned int cfc_write_array_to_buffer(struct comedi_subdevice *, 31 void *data, unsigned int num_bytes); 32 33static inline unsigned int cfc_write_to_buffer(struct comedi_subdevice *s, 34 unsigned short data) 35{ 36 return cfc_write_array_to_buffer(s, &data, sizeof(data)); 37}; 38 39static inline unsigned int cfc_write_long_to_buffer(struct comedi_subdevice *s, 40 unsigned int data) 41{ 42 return cfc_write_array_to_buffer(s, &data, sizeof(data)); 43}; 44 45unsigned int cfc_read_array_from_buffer(struct comedi_subdevice *, 46 void *data, unsigned int num_bytes); 47 48unsigned int cfc_handle_events(struct comedi_device *, 49 struct comedi_subdevice *); 50 51/** 52 * cfc_check_trigger_src() - trivially validate a comedi_cmd trigger source 53 * @src: pointer to the trigger source to validate 54 * @flags: bitmask of valid TRIG_* for the trigger 55 * 56 * This is used in "step 1" of the do_cmdtest functions of comedi drivers 57 * to vaildate the comedi_cmd triggers. The mask of the @src against the 58 * @flags allows the userspace comedilib to pass all the comedi_cmd 59 * triggers as TRIG_ANY and get back a bitmask of the valid trigger sources. 60 */ 61static inline int cfc_check_trigger_src(unsigned int *src, unsigned int flags) 62{ 63 unsigned int orig_src = *src; 64 65 *src = orig_src & flags; 66 if (*src == TRIG_INVALID || *src != orig_src) 67 return -EINVAL; 68 return 0; 69} 70 71/** 72 * cfc_check_trigger_is_unique() - make sure a trigger source is unique 73 * @src: the trigger source to check 74 */ 75static inline int cfc_check_trigger_is_unique(unsigned int src) 76{ 77 /* this test is true if more than one _src bit is set */ 78 if ((src & (src - 1)) != 0) 79 return -EINVAL; 80 return 0; 81} 82 83/** 84 * cfc_check_trigger_arg_is() - trivially validate a trigger argument 85 * @arg: pointer to the trigger arg to validate 86 * @val: the value the argument should be 87 */ 88static inline int cfc_check_trigger_arg_is(unsigned int *arg, unsigned int val) 89{ 90 if (*arg != val) { 91 *arg = val; 92 return -EINVAL; 93 } 94 return 0; 95} 96 97/** 98 * cfc_check_trigger_arg_min() - trivially validate a trigger argument 99 * @arg: pointer to the trigger arg to validate 100 * @val: the minimum value the argument should be 101 */ 102static inline int cfc_check_trigger_arg_min(unsigned int *arg, 103 unsigned int val) 104{ 105 if (*arg < val) { 106 *arg = val; 107 return -EINVAL; 108 } 109 return 0; 110} 111 112/** 113 * cfc_check_trigger_arg_max() - trivially validate a trigger argument 114 * @arg: pointer to the trigger arg to validate 115 * @val: the maximum value the argument should be 116 */ 117static inline int cfc_check_trigger_arg_max(unsigned int *arg, 118 unsigned int val) 119{ 120 if (*arg > val) { 121 *arg = val; 122 return -EINVAL; 123 } 124 return 0; 125} 126 127#endif /* _COMEDI_FC_H */ 128