From: Frank Mori Hess Date: Mon, 8 Jan 2007 15:09:37 +0000 (+0000) Subject: Ask board which load register will be used next, since it might have X-Git-Tag: r0_7_74~119 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fc6b31f2e55a3b5b885fa893ebde1f3105566220;p=comedi.git Ask board which load register will be used next, since it might have changed since the last time it was set by the driver. --- diff --git a/comedi/drivers/ni_tio.c b/comedi/drivers/ni_tio.c index 52520562..c23dd994 100644 --- a/comedi/drivers/ni_tio.c +++ b/comedi/drivers/ni_tio.c @@ -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 */