* 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;
/* 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;
/* 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;
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",
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;
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;
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
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);
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;
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;
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);
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;
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;
comedi_mark_buffer_written;
comedi_to_physical;
} v0.7.20;
+
+v0.9.0 {
+ global:
+ comedi_get_cmd_generic_timed;
+} v0.8.0;
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);
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);
}
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;
}
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;
}
static const int num_samples = 100000;
int num_bytes;
int wc;
-
+
if((flags & SDF_LSAMPL))
{
num_bytes = num_samples * sizeof(lsampl_t);
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;
}
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");
{
int bit=1<<n;
char *t=s;
-
+
for(;bit;bit>>=1)
*t++=(bits&bit)?'1':'0';
*t=0;
-
+
return s;
}
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;
}
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;
}
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;
}
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;
}
printf("E: %p still mapped\n",adr);
}
}
-
+
free(buf);
return 0;
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;
}