3
support functions for commands
5
COMEDILIB - Linux Control and Measurement Device Interface Library
6
Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
8
This library is free software; you can redistribute it and/or
9
modify it under the terms of the GNU Lesser General Public
10
License as published by the Free Software Foundation, version 2.1
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public
19
License along with this library; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27
#include <sys/ioctl.h>
36
#include "libinternal.h"
39
EXPORT_ALIAS_DEFAULT(_comedi_get_cmd_src_mask,comedi_get_cmd_src_mask,0.7.18);
40
int _comedi_get_cmd_src_mask(comedi_t *it,unsigned int subd,comedi_cmd *cmd)
45
if(!valid_subd(it,subd))return -1;
47
s=it->subdevices+subd;
49
if(s->cmd_mask_errno){
50
errno = s->cmd_mask_errno;
57
mask = malloc(sizeof(comedi_cmd));
59
memset(mask,0,sizeof(*cmd));
63
mask->start_src = TRIG_ANY;
64
mask->scan_begin_src = TRIG_ANY;
65
mask->convert_src = TRIG_ANY;
66
mask->scan_end_src = TRIG_ANY;
67
mask->stop_src = TRIG_ANY;
71
ret = comedi_command_test(it,mask);
73
s->cmd_mask_errno = errno;
81
static int __generic_timed(comedi_t *it,unsigned int s,
82
comedi_cmd *cmd, unsigned int ns)
86
ret = comedi_get_cmd_src_mask(it,s,cmd);
89
__comedi_errno = ENOTSUPPORTED;
91
if(cmd->start_src&TRIG_NOW){
92
cmd->start_src=TRIG_NOW;
94
}else if(cmd->start_src&TRIG_INT){
95
cmd->start_src=TRIG_INT;
98
COMEDILIB_DEBUG(3,"can't find good start_src\n");
102
/* Potential bug: there is a possibility that the source mask may
103
* have * TRIG_TIMER set for both convert_src and scan_begin_src,
104
* but they may not be supported together. */
105
if(cmd->convert_src&TRIG_TIMER){
106
if(cmd->scan_begin_src&TRIG_FOLLOW){
107
cmd->convert_src = TRIG_TIMER;
108
cmd->convert_arg = ns;
109
cmd->scan_begin_src = TRIG_FOLLOW;
110
cmd->scan_begin_arg = 0;
112
cmd->convert_src = TRIG_TIMER;
113
cmd->convert_arg = ns;
114
cmd->scan_begin_src = TRIG_TIMER;
115
cmd->scan_begin_arg = ns;
117
}else if(cmd->convert_src & TRIG_NOW &&
118
cmd->scan_begin_src & TRIG_TIMER)
120
cmd->convert_src = TRIG_NOW;
121
cmd->convert_arg = 0;
122
cmd->scan_begin_src = TRIG_TIMER;
123
cmd->scan_begin_arg = ns;
125
COMEDILIB_DEBUG(3,"comedi_get_cmd_generic_timed: can't do timed?\n");
129
cmd->scan_end_src = TRIG_COUNT;
130
cmd->scan_end_arg = 1;
132
if(cmd->stop_src&TRIG_COUNT){
133
cmd->stop_src=TRIG_COUNT;
135
}else if(cmd->stop_src&TRIG_NONE){
136
cmd->stop_src=TRIG_NONE;
139
COMEDILIB_DEBUG(3,"comedi_get_cmd_generic_timed: can't find a good stop_src\n");
143
cmd->chanlist_len = 1;
145
ret=comedi_command_test(it,cmd);
146
COMEDILIB_DEBUG(3,"comedi_get_cmd_generic_timed: test 1 returned %d\n",ret);
149
ret=comedi_command_test(it,cmd);
150
COMEDILIB_DEBUG(3,"comedi_get_cmd_generic_timed: test 2 returned %d\n",ret);
152
if(ret==4 || ret==0){
159
EXPORT_ALIAS_DEFAULT(_comedi_get_cmd_generic_timed,comedi_get_cmd_generic_timed,0.7.18);
160
int _comedi_get_cmd_generic_timed(comedi_t *it,unsigned int subd,comedi_cmd *cmd,
166
if(!valid_subd(it,subd))return -1;
168
s=it->subdevices+subd;
170
if(s->cmd_timed_errno){
171
errno = s->cmd_mask_errno;
176
s->cmd_timed = malloc(sizeof(comedi_cmd));
178
ret = __generic_timed(it,subd,s->cmd_timed,ns);
180
s->cmd_mask_errno = errno;