Added const qualifiers to some char* return values. Added new
experimental comedi_dio_bitfield2() function which works with > 32 channels. Only works properly with ni_65xx currently. Will post a request for review by any interested parties to list before I bother making the rest of the drivers work with it.
This commit is contained in:
parent
4ccca1c790
commit
34b9800e40
6 changed files with 82 additions and 51 deletions
36
doc/funcref
36
doc/funcref
|
@ -804,18 +804,38 @@ Param: comedi_t * device
|
|||
Param: unsigned int subdevice
|
||||
Param: unsigned int write_mask
|
||||
Param: unsigned int * bits
|
||||
Status: deprecated
|
||||
Description:
|
||||
The function comedi_dio_bitfield() allows multiple channels to
|
||||
be read simultaneously from a digital input or digital I/O device.
|
||||
The parameter write_mask and the value pointed to by bits
|
||||
This function is deprecated. Use comedi_dio_bitfield2() instead.
|
||||
|
||||
Function: comedi_dio_bitfield2 -- read/write multiple digital channels
|
||||
Retval: int
|
||||
Param: comedi_t * device
|
||||
Param: unsigned int subdevice
|
||||
Param: unsigned int write_mask
|
||||
Param: unsigned int * bits
|
||||
Param: unsigned int base_channel
|
||||
Description:
|
||||
The function comedi_dio_bitfield2() allows multiple channels to
|
||||
be read or written together on a digital input, output,
|
||||
or configurable digital I/O device.
|
||||
The parameter <parameter>write_mask</parameter>
|
||||
and the value pointed to by <parameter>bits</parameter>
|
||||
are interpreted as bit fields, with the least significant bit
|
||||
representing channel 0. For each bit in write_mask that is
|
||||
set to 1, the cooresponding bit in *bits is written to the digital
|
||||
representing channel <parameter>base_channel</parameter>.
|
||||
For each bit in <parameter>write_mask</parameter> that is
|
||||
set to 1, the cooresponding bit in <parameter>*bits</parameter>
|
||||
is written to the digital
|
||||
output channel. After writing all the output channels, each
|
||||
channel is read, and the result placed in the approprate bits in
|
||||
*bits. The result of reading an output channel is undefined.
|
||||
It is not possible to access channels greater than 31 using this
|
||||
function.
|
||||
<parameter>*bits</parameter>. The result of
|
||||
reading an output channel is the last
|
||||
value written to the output channel.
|
||||
|
||||
All the channels may not be read or written at the exact same time.
|
||||
For example, the driver may need to sequentially write to
|
||||
several ports in order to set all the digital channels specified
|
||||
by the <parameter>write_mask</parameter>.
|
||||
|
||||
Function: comedi_sv_init -- slowly-varying inputs
|
||||
Retval: int
|
||||
|
|
|
@ -82,8 +82,8 @@ enum comedi_oor_behavior comedi_set_global_oor_behavior(enum comedi_oor_behavior
|
|||
int comedi_get_n_subdevices(comedi_t *it);
|
||||
#define COMEDI_VERSION_CODE(a,b,c) (((a)<<16) | ((b)<<8) | (c))
|
||||
int comedi_get_version_code(comedi_t *it);
|
||||
char *comedi_get_driver_name(comedi_t *it);
|
||||
char *comedi_get_board_name(comedi_t *it);
|
||||
const char *comedi_get_driver_name(comedi_t *it);
|
||||
const char *comedi_get_board_name(comedi_t *it);
|
||||
int comedi_get_read_subdevice(comedi_t *dev);
|
||||
int comedi_get_write_subdevice(comedi_t *dev);
|
||||
|
||||
|
@ -147,8 +147,8 @@ int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int chan,
|
|||
unsigned int *bit);
|
||||
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 *bits);
|
||||
int comedi_dio_bitfield2(comedi_t *it,unsigned int subd,
|
||||
unsigned int write_mask, unsigned int *bits, unsigned int base_channel);
|
||||
|
||||
/* slowly varying stuff */
|
||||
int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan);
|
||||
|
@ -188,6 +188,8 @@ int comedi_timed_1chan(comedi_t *it,unsigned int subdev,unsigned int chan,
|
|||
unsigned int n_samples,double *data);
|
||||
int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,
|
||||
unsigned int chan);
|
||||
int comedi_dio_bitfield(comedi_t *it,unsigned int subd,
|
||||
unsigned int write_mask, unsigned int *bits);
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -181,8 +181,9 @@ char* _comedi_get_default_calibration_path( comedi_t *dev )
|
|||
{
|
||||
struct stat file_stats;
|
||||
char *file_path;
|
||||
char *board_name, *temp;
|
||||
char *driver_name;
|
||||
const char *temp;
|
||||
char *board_name;
|
||||
const char *driver_name;
|
||||
|
||||
if( fstat( comedi_fileno( dev ), &file_stats ) < 0 )
|
||||
{
|
||||
|
|
73
lib/dio.c
73
lib/dio.c
|
@ -41,7 +41,7 @@ int _comedi_dio_config(comedi_t *it,unsigned int subdev,unsigned int chan,unsign
|
|||
|
||||
if(!valid_chan(it,subdev,chan))
|
||||
return -1;
|
||||
|
||||
|
||||
s=it->subdevices+subdev;
|
||||
if(s->type!=COMEDI_SUBD_DIO)
|
||||
return -1;
|
||||
|
@ -52,7 +52,7 @@ int _comedi_dio_config(comedi_t *it,unsigned int subdev,unsigned int chan,unsign
|
|||
if(it->has_insnlist_ioctl){
|
||||
comedi_insn insn;
|
||||
lsampl_t data;
|
||||
|
||||
|
||||
memset(&insn,0,sizeof(insn));
|
||||
insn.insn = INSN_CONFIG;
|
||||
insn.n = 1;
|
||||
|
@ -86,17 +86,17 @@ int _comedi_dio_get_config(comedi_t *it,unsigned int subdev, unsigned int chan,
|
|||
comedi_insn insn;
|
||||
lsampl_t data[2];
|
||||
int retval;
|
||||
|
||||
|
||||
if(!valid_chan(it,subdev,chan))
|
||||
return -1;
|
||||
|
||||
|
||||
s=it->subdevices+subdev;
|
||||
if(s->type!=COMEDI_SUBD_DIO)
|
||||
return -1;
|
||||
|
||||
if(it->has_insnlist_ioctl == 0)
|
||||
return -1;
|
||||
|
||||
|
||||
memset(&insn,0,sizeof(insn));
|
||||
insn.insn = INSN_CONFIG;
|
||||
insn.n = sizeof(data) / sizeof(data[0]);
|
||||
|
@ -130,7 +130,7 @@ int _comedi_dio_read(comedi_t *it,unsigned int subdev,unsigned int chan,
|
|||
if(it->has_insnlist_ioctl){
|
||||
comedi_insn insn;
|
||||
lsampl_t data;
|
||||
|
||||
|
||||
memset(&insn,0,sizeof(insn));
|
||||
insn.insn = INSN_READ;
|
||||
insn.n = 1;
|
||||
|
@ -170,7 +170,7 @@ int _comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan,
|
|||
|
||||
if(!valid_chan(it,subdev,chan))
|
||||
return -1;
|
||||
|
||||
|
||||
s = it->subdevices+subdev;
|
||||
if(s->type!=COMEDI_SUBD_DIO &&
|
||||
s->type!=COMEDI_SUBD_DO)
|
||||
|
@ -179,7 +179,7 @@ int _comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan,
|
|||
if(it->has_insnlist_ioctl){
|
||||
comedi_insn insn;
|
||||
lsampl_t data;
|
||||
|
||||
|
||||
memset(&insn,0,sizeof(insn));
|
||||
insn.insn = INSN_WRITE;
|
||||
insn.n = 1;
|
||||
|
@ -208,60 +208,67 @@ int _comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan,
|
|||
}
|
||||
}
|
||||
|
||||
EXPORT_ALIAS_DEFAULT(_comedi_dio_bitfield,comedi_dio_bitfield,0.7.18);
|
||||
int _comedi_dio_bitfield(comedi_t *it,unsigned int subdev,unsigned int mask,unsigned int *bits)
|
||||
EXPORT_ALIAS_DEFAULT(_comedi_dio_bitfield2,comedi_dio_bitfield2,0.7.23);
|
||||
int _comedi_dio_bitfield2(comedi_t *it, unsigned int subdev, unsigned int mask, unsigned int *bits, unsigned base_channel)
|
||||
{
|
||||
int ret;
|
||||
unsigned int m,bit;
|
||||
subdevice *s;
|
||||
|
||||
if(!valid_subd(it,subdev))
|
||||
if(!valid_subd(it, subdev))
|
||||
return -1;
|
||||
|
||||
s=it->subdevices+subdev;
|
||||
s = it->subdevices + subdev;
|
||||
|
||||
if(s->type!=COMEDI_SUBD_DIO && s->type!=COMEDI_SUBD_DO &&
|
||||
s->type!=COMEDI_SUBD_DI)
|
||||
if(s->type != COMEDI_SUBD_DIO && s->type != COMEDI_SUBD_DO &&
|
||||
s->type != COMEDI_SUBD_DI)
|
||||
return -1;
|
||||
|
||||
if(s->has_insn_bits){
|
||||
if(s->has_insn_bits)
|
||||
{
|
||||
comedi_insn insn;
|
||||
lsampl_t data[2];
|
||||
|
||||
|
||||
memset(&insn,0,sizeof(insn));
|
||||
|
||||
insn.insn = INSN_BITS;
|
||||
insn.chanspec = base_channel;
|
||||
insn.n = 2;
|
||||
insn.data = data;
|
||||
insn.subdev = subdev;
|
||||
|
||||
data[0]=mask;
|
||||
data[1]=*bits;
|
||||
data[0] = mask;
|
||||
data[1] = *bits;
|
||||
|
||||
ret = comedi_do_insn(it,&insn);
|
||||
ret = comedi_do_insn(it, &insn);
|
||||
|
||||
if(ret<0)return ret;
|
||||
if(ret < 0) return ret;
|
||||
|
||||
*bits = data[1];
|
||||
|
||||
return 0;
|
||||
}else{
|
||||
unsigned int i,n_chan;
|
||||
|
||||
n_chan=comedi_get_n_channels(it,subdev);
|
||||
if(n_chan>32)n_chan=32;
|
||||
for(i=0,m=1;i<n_chan;i++,m<<=1){
|
||||
if(mask&m){
|
||||
bit=(*bits&m)?1:0;
|
||||
ret=comedi_dio_write(it,subdev,i,bit);
|
||||
unsigned i;
|
||||
for(i = 0, m = 1; i < 32; ++i, m <<= 1)
|
||||
{
|
||||
if(mask & m)
|
||||
{
|
||||
bit = (*bits & m) ? 1 : 0;
|
||||
ret = comedi_dio_write(it, subdev, base_channel + i, bit);
|
||||
}else{
|
||||
ret=comedi_dio_read(it,subdev,i,&bit);
|
||||
if(bit) *bits|=m;
|
||||
else (*bits)&=~m;
|
||||
ret = comedi_dio_read(it, subdev, base_channel + i, &bit);
|
||||
if(bit) *bits |= m;
|
||||
else (*bits) &= ~m;
|
||||
}
|
||||
if(ret<0)return ret;
|
||||
if(ret < 0) return ret;
|
||||
}
|
||||
return (int)n_chan;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
EXPORT_ALIAS_DEFAULT(_comedi_dio_bitfield,comedi_dio_bitfield,0.7.18);
|
||||
int _comedi_dio_bitfield(comedi_t *it, unsigned int subdev, unsigned int mask, unsigned int *bits)
|
||||
{
|
||||
return _comedi_dio_bitfield2(it, subdev, mask, bits, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ int _comedi_get_version_code(comedi_t *it)
|
|||
}
|
||||
|
||||
EXPORT_ALIAS_DEFAULT(_comedi_get_driver_name,comedi_get_driver_name,0.7.18);
|
||||
char* _comedi_get_driver_name(comedi_t *it)
|
||||
const char* _comedi_get_driver_name(comedi_t *it)
|
||||
{
|
||||
if(!valid_dev(it))
|
||||
return NULL;
|
||||
|
@ -63,7 +63,7 @@ char* _comedi_get_driver_name(comedi_t *it)
|
|||
}
|
||||
|
||||
EXPORT_ALIAS_DEFAULT(_comedi_get_board_name,comedi_get_board_name,0.7.18);
|
||||
char* _comedi_get_board_name(comedi_t *it)
|
||||
const char* _comedi_get_board_name(comedi_t *it)
|
||||
{
|
||||
if(!valid_dev(it))
|
||||
return NULL;
|
||||
|
@ -88,13 +88,13 @@ int _comedi_get_subdevice_flags(comedi_t *it,unsigned int subd)
|
|||
if(!valid_dev(it))
|
||||
return -1;
|
||||
s = malloc(sizeof(comedi_subdinfo) * it->n_subdevices);
|
||||
if(s == NULL)
|
||||
if(s == NULL)
|
||||
{
|
||||
__comedi_errno = errno;
|
||||
return -1;
|
||||
}
|
||||
ret = comedi_ioctl(it->fd, COMEDI_SUBDINFO, (unsigned long)s);
|
||||
if(ret < 0)
|
||||
if(ret < 0)
|
||||
{
|
||||
free(s);
|
||||
return -1;
|
||||
|
|
|
@ -84,6 +84,7 @@ v0.7.20 {
|
|||
v0.7.23 {
|
||||
global:
|
||||
comedi_from_physical;
|
||||
comedi_dio_bitfield2;
|
||||
comedi_dio_get_config;
|
||||
comedi_get_hardcal_converter;
|
||||
comedi_get_softcal_converter;
|
||||
|
|
Loading…
Add table
Reference in a new issue