s526: backwards compatible change for INSN_CONFIG_GPCT_QUADRATURE_ENCODER
authorIan Abbott <abbotti@mev.co.uk>
Mon, 29 Apr 2013 12:19:56 +0000 (13:19 +0100)
committerIan Abbott <abbotti@mev.co.uk>
Mon, 29 Apr 2013 12:19:56 +0000 (13:19 +0100)
For INSN_CONFIG_GPCT_QUADRATURE_ENCODER, if insn->n < 2, use the fixed
counter mode register value that was in use before 2009-08-07, otherwise
read the counter mode register value from data[1].

Also, for INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR and
INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR, return an error if insn->n < 5.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
comedi/drivers/s526.c

index 3fa19f65af9c8188ac16ba1710e66cd009d0fbef..160c557923b682a212d927a9b8a3a0f1224aa759 100644 (file)
@@ -567,7 +567,22 @@ static int s526_gpct_insn_config(comedi_device * dev, comedi_subdevice * s,
 
 #if 1
                // Set Counter Mode Register
-               cmReg.value = data[1] & 0xFFFF;
+               if (insn->n < 2) {
+                       /* old configuration for backwards compatibility */
+                       cmReg.reg.coutSource = 0;       // out RCAP
+                       cmReg.reg.coutPolarity = 0;     // Polarity inverted
+                       cmReg.reg.autoLoadResetRcap = 0;        // Auto load disabled
+                       cmReg.reg.hwCtEnableSource = 2; // NOT RCAP
+                       cmReg.reg.ctEnableCtrl = 1;     // 1: Software,  >1 : Hardware
+                       cmReg.reg.clockSource = 3;      // x4
+                       cmReg.reg.countDir = 0; // up
+                       cmReg.reg.countDirCtrl = 0;     // quadrature
+                       cmReg.reg.outputRegLatchCtrl = 0;       // latch on read
+                       cmReg.reg.preloadRegSel = 0;    // PR0
+                       cmReg.reg.reserved = 0;
+               } else {
+                       cmReg.value = data[1] & 0xFFFF;
+               }
 
 //                      printk("s526: Counter Mode register=%x\n", cmReg.value);
                outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel));
@@ -633,6 +648,10 @@ static int s526_gpct_insn_config(comedi_device * dev, comedi_subdevice * s,
                   data[4]: Conter Control Register
                 */
                printk("s526: GPCT_INSN_CONFIG: Configuring SPG\n");
+               if (insn->n < 5) {
+                       printk("s526: Error: SPG data too short\n");
+                       return -EINVAL;
+               }
                devpriv->s526_gpct_config[subdev_channel].app =
                        SinglePulseGeneration;
 
@@ -678,6 +697,10 @@ static int s526_gpct_insn_config(comedi_device * dev, comedi_subdevice * s,
                   data[4]: Conter Control Register
                 */
                printk("s526: GPCT_INSN_CONFIG: Configuring PTG\n");
+               if (insn->n < 5) {
+                       printk("s526: Error: PTG data too short\n");
+                       return -EINVAL;
+               }
                devpriv->s526_gpct_config[subdev_channel].app =
                        PulseTrainGeneration;