Fixed comedi_get_cmd_generic_timed() by adding a chanlist_len
parameter. Old version is still available in library, thanks to the magic of the version_script.
This commit is contained in:
parent
d11d8a69be
commit
c1082cee65
14 changed files with 89 additions and 53 deletions
|
@ -202,7 +202,7 @@ int main(int argc, char *argv[])
|
|||
* This prepares a command in a pretty generic way. We ask the
|
||||
* library to create a stock command that supports periodic
|
||||
* sampling of data, then modify the parts we want. */
|
||||
int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsigned period_nanosec, comedi_cmd *cmd)
|
||||
int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsigned scan_period_nanosec, comedi_cmd *cmd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -211,7 +211,7 @@ int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsign
|
|||
/* This comedilib function will get us a generic timed
|
||||
* command for a particular board. If it returns -1,
|
||||
* that's bad. */
|
||||
ret = comedi_get_cmd_generic_timed(dev, subdevice,cmd, period_nanosec);
|
||||
ret = comedi_get_cmd_generic_timed(dev, subdevice, cmd, n_chan, scan_period_nanosec);
|
||||
if(ret<0){
|
||||
printf("comedi_get_cmd_generic_timed failed\n");
|
||||
return ret;
|
||||
|
@ -220,8 +220,6 @@ int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsign
|
|||
/* Modify parts of the command */
|
||||
cmd->chanlist = chanlist;
|
||||
cmd->chanlist_len = n_chan;
|
||||
|
||||
cmd->scan_end_arg = n_chan;
|
||||
if(cmd->stop_src == TRIG_COUNT) cmd->stop_arg = n_scan;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -150,7 +150,7 @@ void probe_max_1chan(comedi_t *it,int s)
|
|||
char buf[100];
|
||||
|
||||
printf(" command fast 1chan:\n");
|
||||
if(comedi_get_cmd_generic_timed(it,s,&cmd,1)<0){
|
||||
if(comedi_get_cmd_generic_timed(it, s, &cmd, 1, 1)<0){
|
||||
printf(" not supported\n");
|
||||
}else{
|
||||
printf(" start: %s %d\n",
|
||||
|
|
|
@ -120,11 +120,11 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsigned period_nanosec, comedi_cmd *cmd)
|
||||
int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsigned scan_period_nanosec, comedi_cmd *cmd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = comedi_get_cmd_generic_timed(dev, subdevice, cmd, period_nanosec);
|
||||
ret = comedi_get_cmd_generic_timed(dev, subdevice, cmd, n_chan, scan_period_nanosec);
|
||||
if(ret<0){
|
||||
comedi_perror("comedi_get_cmd_generic_timed\n");
|
||||
return ret;
|
||||
|
@ -132,8 +132,6 @@ int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsign
|
|||
|
||||
cmd->chanlist = chanlist;
|
||||
cmd->chanlist_len = n_chan;
|
||||
cmd->scan_end_arg = n_chan;
|
||||
|
||||
if(cmd->stop_src == TRIG_COUNT) cmd->stop_arg = n_scan;
|
||||
|
||||
return 0;
|
||||
|
|
11
doc/funcref
11
doc/funcref
|
@ -891,15 +891,18 @@ Retval: int
|
|||
Param: comedi_t * device
|
||||
Param: unsigned int subdevice
|
||||
Param: comedi_cmd * command
|
||||
Param: unsigned int period_ns
|
||||
Param: unsigned int chanlist_len
|
||||
Param: unsigned int scan_period_ns
|
||||
Description:
|
||||
The command capabilities of the subdevice indicated by the parameters
|
||||
device and subdevice are probed, and the results placed in the
|
||||
command structure pointed to by the parameter command. The command
|
||||
structure pointed to by the parameter command is modified to be a
|
||||
valid command that can be used as a parameter to comedi_command().
|
||||
The command measures samples at a rate that corresponds to the
|
||||
period period_ns. The rate is adjusted to a rate that the device
|
||||
valid command that can be used as a parameter to comedi_command()
|
||||
(after the command has been assigned a valid chanlist array).
|
||||
The command measures scans consisting of chanlist_len channels
|
||||
at a scan rate that corresponds to the
|
||||
period scan_period_ns. The rate is adjusted to a rate that the device
|
||||
can handle. If sucessful, 0 is returned, otherwise -1.
|
||||
|
||||
Function: comedi_cancel -- stop streaming input/output in progress
|
||||
|
|
|
@ -164,7 +164,7 @@ int comedi_sv_measure(comedi_sv_t *it,double *data);
|
|||
int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice,
|
||||
comedi_cmd *cmd);
|
||||
int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice,
|
||||
comedi_cmd *cmd,unsigned int ns);
|
||||
comedi_cmd *cmd, unsigned chanlist_len, unsigned scan_period_ns);
|
||||
int comedi_cancel(comedi_t *it,unsigned int subdevice);
|
||||
int comedi_command(comedi_t *it,comedi_cmd *cmd);
|
||||
int comedi_command_test(comedi_t *it,comedi_cmd *cmd);
|
||||
|
|
80
lib/cmd.c
80
lib/cmd.c
|
@ -78,11 +78,13 @@ int _comedi_get_cmd_src_mask(comedi_t *it,unsigned int subd,comedi_cmd *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int __generic_timed(comedi_t *it,unsigned int s,
|
||||
comedi_cmd *cmd, unsigned int ns)
|
||||
static int __generic_timed(comedi_t *it, unsigned s,
|
||||
comedi_cmd *cmd, unsigned chanlist_len, unsigned scan_period_ns)
|
||||
{
|
||||
int ret;
|
||||
unsigned convert_period_ns;
|
||||
|
||||
if(chanlist_len < 1) return -EINVAL;
|
||||
ret = comedi_get_cmd_src_mask(it,s,cmd);
|
||||
if(ret<0)return ret;
|
||||
|
||||
|
@ -99,35 +101,35 @@ static int __generic_timed(comedi_t *it,unsigned int s,
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* Potential bug: there is a possibility that the source mask may
|
||||
* have * TRIG_TIMER set for both convert_src and scan_begin_src,
|
||||
* but they may not be supported together. */
|
||||
if(cmd->convert_src&TRIG_TIMER){
|
||||
if(cmd->scan_begin_src&TRIG_FOLLOW){
|
||||
cmd->convert_src = TRIG_TIMER;
|
||||
cmd->convert_arg = ns;
|
||||
cmd->scan_begin_src = TRIG_FOLLOW;
|
||||
cmd->scan_begin_arg = 0;
|
||||
}else{
|
||||
cmd->convert_src = TRIG_TIMER;
|
||||
cmd->convert_arg = ns;
|
||||
cmd->scan_begin_src = TRIG_TIMER;
|
||||
cmd->scan_begin_arg = ns;
|
||||
}
|
||||
}else if(cmd->convert_src & TRIG_NOW &&
|
||||
cmd->scan_begin_src & TRIG_TIMER)
|
||||
convert_period_ns = (scan_period_ns + chanlist_len / 2) / chanlist_len;
|
||||
if((cmd->convert_src & TRIG_TIMER) &&
|
||||
(cmd->scan_begin_src & TRIG_FOLLOW))
|
||||
{
|
||||
cmd->convert_src = TRIG_TIMER;
|
||||
cmd->convert_arg = convert_period_ns;
|
||||
cmd->scan_begin_src = TRIG_FOLLOW;
|
||||
cmd->scan_begin_arg = 0;
|
||||
}else if((cmd->convert_src & TRIG_NOW) &&
|
||||
(cmd->scan_begin_src & TRIG_TIMER))
|
||||
{
|
||||
cmd->convert_src = TRIG_NOW;
|
||||
cmd->convert_arg = 0;
|
||||
cmd->scan_begin_src = TRIG_TIMER;
|
||||
cmd->scan_begin_arg = ns;
|
||||
cmd->scan_begin_arg = scan_period_ns;
|
||||
}else if((cmd->convert_src & TRIG_TIMER) &&
|
||||
(cmd->scan_begin_src & TRIG_TIMER))
|
||||
{
|
||||
cmd->convert_src = TRIG_TIMER;
|
||||
cmd->convert_arg = convert_period_ns;
|
||||
cmd->scan_begin_src = TRIG_TIMER;
|
||||
cmd->scan_begin_arg = scan_period_ns;
|
||||
}else{
|
||||
COMEDILIB_DEBUG(3,"comedi_get_cmd_generic_timed: can't do timed?\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->scan_end_src = TRIG_COUNT;
|
||||
cmd->scan_end_arg = 1;
|
||||
cmd->scan_end_arg = chanlist_len;
|
||||
|
||||
if(cmd->stop_src&TRIG_COUNT){
|
||||
cmd->stop_src=TRIG_COUNT;
|
||||
|
@ -140,7 +142,7 @@ static int __generic_timed(comedi_t *it,unsigned int s,
|
|||
return -1;
|
||||
}
|
||||
|
||||
cmd->chanlist_len = 1;
|
||||
cmd->chanlist_len = chanlist_len;
|
||||
|
||||
ret=comedi_command_test(it,cmd);
|
||||
COMEDILIB_DEBUG(3,"comedi_get_cmd_generic_timed: test 1 returned %d\n",ret);
|
||||
|
@ -156,8 +158,8 @@ static int __generic_timed(comedi_t *it,unsigned int s,
|
|||
return -1;
|
||||
}
|
||||
|
||||
EXPORT_ALIAS_DEFAULT(_comedi_get_cmd_generic_timed,comedi_get_cmd_generic_timed,0.7.18);
|
||||
int _comedi_get_cmd_generic_timed(comedi_t *it,unsigned int subd,comedi_cmd *cmd,
|
||||
EXPORT_ALIAS_VER(_comedi_get_cmd_generic_timed_obsolete,comedi_get_cmd_generic_timed,0.7.18);
|
||||
int _comedi_get_cmd_generic_timed_obsolete(comedi_t *it,unsigned int subd,comedi_cmd *cmd,
|
||||
unsigned int ns)
|
||||
{
|
||||
subdevice *s;
|
||||
|
@ -175,7 +177,35 @@ int _comedi_get_cmd_generic_timed(comedi_t *it,unsigned int subd,comedi_cmd *cmd
|
|||
if(!s->cmd_timed)
|
||||
s->cmd_timed = malloc(sizeof(comedi_cmd));
|
||||
|
||||
ret = __generic_timed(it,subd,s->cmd_timed,ns);
|
||||
ret = __generic_timed(it, subd, s->cmd_timed, 1, ns);
|
||||
if(ret<0){
|
||||
s->cmd_mask_errno = errno;
|
||||
return -1;
|
||||
}
|
||||
*cmd=*s->cmd_timed;
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_ALIAS_DEFAULT(_comedi_get_cmd_generic_timed,comedi_get_cmd_generic_timed,0.9.0);
|
||||
int _comedi_get_cmd_generic_timed(comedi_t *it, unsigned subd, comedi_cmd *cmd,
|
||||
unsigned chanlist_len, unsigned scan_period_ns)
|
||||
{
|
||||
subdevice *s;
|
||||
int ret;
|
||||
|
||||
if(!valid_subd(it,subd)) return -1;
|
||||
|
||||
s = it->subdevices + subd;
|
||||
|
||||
if(s->cmd_timed_errno){
|
||||
errno = s->cmd_mask_errno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!s->cmd_timed)
|
||||
s->cmd_timed = malloc(sizeof(comedi_cmd));
|
||||
|
||||
ret = __generic_timed(it, subd, s->cmd_timed, chanlist_len, scan_period_ns);
|
||||
if(ret<0){
|
||||
s->cmd_mask_errno = errno;
|
||||
return -1;
|
||||
|
|
|
@ -92,3 +92,8 @@ v0.8.0 {
|
|||
comedi_mark_buffer_written;
|
||||
comedi_to_physical;
|
||||
} v0.7.20;
|
||||
|
||||
v0.9.0 {
|
||||
global:
|
||||
comedi_get_cmd_generic_timed;
|
||||
} v0.8.0;
|
||||
|
|
|
@ -506,6 +506,8 @@ int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan,
|
|||
unsigned int bit);
|
||||
int comedi_dio_bitfield(comedi_t *it,unsigned int subd,
|
||||
unsigned int write_mask, unsigned int *INOUT);
|
||||
int comedi_dio_bitfield2(comedi_t *it, unsigned int subd,
|
||||
unsigned int write_mask, unsigned int *INOUT, unsigned base_channel);
|
||||
|
||||
/* slowly varying stuff */
|
||||
int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan);
|
||||
|
@ -517,7 +519,7 @@ int comedi_sv_measure(comedi_sv_t *it,double *data);
|
|||
int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice,
|
||||
comedi_cmd *INOUT);
|
||||
int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice,
|
||||
comedi_cmd *INOUT,unsigned int ns);
|
||||
comedi_cmd *INOUT, unsigned chanlist_len, unsigned int scan_period_ns);
|
||||
int comedi_cancel(comedi_t *it,unsigned int subdevice);
|
||||
int comedi_command(comedi_t *it,comedi_cmd *cmd);
|
||||
int comedi_command_test(comedi_t *it,comedi_cmd *INOUT);
|
||||
|
|
|
@ -82,7 +82,7 @@ int test_cmd_probe_fast_1chan(void)
|
|||
}
|
||||
|
||||
printf("command fast 1chan:\n");
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice, &cmd, 1, 1)<0){
|
||||
printf(" not supported\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ int test_cmd_read_fast_1chan(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
|
||||
if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){
|
||||
printf(" not supported\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ int test_cmd_write_fast_1chan(void)
|
|||
static const int num_samples = 100000;
|
||||
int num_bytes;
|
||||
int wc;
|
||||
|
||||
|
||||
if((flags & SDF_LSAMPL))
|
||||
{
|
||||
num_bytes = num_samples * sizeof(lsampl_t);
|
||||
|
@ -177,7 +177,7 @@ int test_cmd_write_fast_1chan(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
|
||||
if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){
|
||||
printf(" not supported\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ int test_cmd_write_fast_1chan(void)
|
|||
total += ret;
|
||||
if(verbose)printf("write %d %d\n",ret,total);
|
||||
}
|
||||
|
||||
|
||||
ret = comedi_internal_trigger(device, subdevice, 0);
|
||||
if(ret<0){
|
||||
perror("E: comedi_inttrig");
|
||||
|
@ -323,11 +323,11 @@ char *tobinary(char *s,int bits,int n)
|
|||
{
|
||||
int bit=1<<n;
|
||||
char *t=s;
|
||||
|
||||
|
||||
for(;bit;bit>>=1)
|
||||
*t++=(bits&bit)?'1':'0';
|
||||
*t=0;
|
||||
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ static int get_chunks_per_length(int length)
|
|||
int ret;
|
||||
int chunks=0;
|
||||
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
|
||||
if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){
|
||||
printf(" not supported\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ static int do_continuous(int multiplier)
|
|||
unsigned long total_secs = 0;
|
||||
struct timeval tv,start_tv;
|
||||
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice, &cmd, 1, 1)<0){
|
||||
printf(" not supported\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ int test_cmd_start_inttrig(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
|
||||
if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){
|
||||
printf(" not supported\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ int test_mmap(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
|
||||
if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){
|
||||
printf("E: comedi_get_cmd_generic_timed failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ int test_mmap(void)
|
|||
printf("E: %p still mapped\n",adr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(buf);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -35,7 +35,7 @@ int test_read_select(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
|
||||
if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){
|
||||
printf("E: comedi_get_cmd_generic_timed failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue