From 5ab5b5dbfc4a019ce7a181fdbff6b13a58a6b917 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Tue, 17 Oct 2006 16:11:35 +0000 Subject: [PATCH] Fixed insn_rw_emulate_bits() for reads when channel is >= 32. I don't 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/comedi/drivers.c b/comedi/drivers.c index 6b8d0c0e..ae82fc87 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -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; -- 2.26.2