Fixed insn_rw_emulate_bits() for reads when channel is >= 32. I don't
authorFrank Mori Hess <fmhess@speakeasy.net>
Tue, 17 Oct 2006 16:11:35 +0000 (16:11 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Tue, 17 Oct 2006 16:11:35 +0000 (16:11 +0000)
like this new scheme, instead I think I'm going support >= 32 dio channels
by making the insn chanspec specify a base channel for the dio bitmask.

comedi/drivers.c

index 6b8d0c0e037674d1f8ebad7ea78b9c9991a02eba..ae82fc8709af4df83cc0081aaacb00dff3f31572 100644 (file)
@@ -359,6 +359,7 @@ static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s,
 
        chan = CR_CHAN(insn->chanspec);
        const unsigned num_bitfields = (chan + channels_per_bitfield) / channels_per_bitfield;
+       const unsigned array_offset = 2 * (num_bitfields - 1);
        lsampl_t new_data[2 * num_bitfields];
        memset(new_data, 0, sizeof(new_data));
        memset(&new_insn, 0, sizeof(new_insn));
@@ -371,7 +372,6 @@ static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s,
        {
                if(!(s->subdev_flags & SDF_WRITABLE))
                        return -EINVAL;
-               const unsigned array_offset = 2 * (num_bitfields - 1);
                new_data[array_offset] = 1 << (chan % channels_per_bitfield); /* mask */
                new_data[array_offset + 1] = data[0] ? (1 << (chan % channels_per_bitfield)) : 0; /* bits */
        }
@@ -380,7 +380,7 @@ static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s,
        if(ret<0)return ret;
 
        if(insn->insn == INSN_READ){
-               data[0] = (new_data[1]>>chan)&1;
+               data[0] = (new_data[array_offset + 1] >> (chan % channels_per_bitfield)) & 1;
        }
 
        return 1;