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)
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 */