Ask board which load register will be used next, since it might have
authorFrank Mori Hess <fmhess@speakeasy.net>
Mon, 8 Jan 2007 15:09:37 +0000 (15:09 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Mon, 8 Jan 2007 15:09:37 +0000 (15:09 +0000)
changed since the last time it was set by the driver.

comedi/drivers/ni_tio.c

index 525205626659678bb07184f297d7fdf7dfed280c..c23dd994f08f55638b542a456a1300905e112e2f 100644 (file)
@@ -646,6 +646,11 @@ static inline unsigned Gi_Armed_Bit(unsigned counter_index)
        if(counter_index % 2) return G1_Armed_Bit;
        return G0_Armed_Bit;
 }
+static inline unsigned Gi_Next_Load_Source_Bit(unsigned counter_index)
+{
+       if(counter_index % 2) return G1_Next_Load_Source_Bit;
+       return G0_Next_Load_Source_Bit;
+}
 
 /* joint reset register bits */
 static inline unsigned Gi_Reset_Bit(unsigned counter_index)
@@ -1870,27 +1875,34 @@ int ni_tio_rinsn(struct ni_gpct *counter,
        return 0;
 }
 
+static unsigned ni_tio_next_load_register(struct ni_gpct *counter)
+{
+       const unsigned bits = counter->read_register(counter, NITIO_Gxx_Status_Reg(counter->counter_index));
+
+       if(bits & Gi_Next_Load_Source_Bit(counter->counter_index))
+       {
+               return NITIO_Gi_LoadB_Reg(counter->counter_index);
+       }else
+       {
+               return NITIO_Gi_LoadA_Reg(counter->counter_index);
+       }
+}
+
 int ni_tio_winsn(struct ni_gpct *counter,
        comedi_insn *insn,
        lsampl_t * data)
 {
        const unsigned channel = CR_CHAN(insn->chanspec);
        const unsigned command_reg = NITIO_Gi_Command_Reg(counter->counter_index);
-       const unsigned mode_reg = NITIO_Gi_Mode_Reg(counter->counter_index);
        unsigned load_reg;
 
        if(insn->n < 1) return 0;
        switch(channel)
        {
        case 0:
-               /* don't disturb load source select, just use whichever load register is already selected. */
-               if(counter->regs[mode_reg] & Gi_Load_Source_Select_Bit)
-               {
-                       load_reg = NITIO_Gi_LoadB_Reg(counter->counter_index);
-               }else
-               {
-                       load_reg = NITIO_Gi_LoadA_Reg(counter->counter_index);
-               }
+               /* Unsafe if counter is armed.  Should probably check status and return -EBUSY if armed. */
+               /* Don't disturb load source select, just use whichever load register is already selected. */
+               load_reg = ni_tio_next_load_register(counter);
                counter->write_register(counter, data[0], load_reg);
                counter->write_register(counter, counter->regs[command_reg] | Gi_Load_Bit, command_reg);
                /* restore state of load reg to whatever the user set last set it to */