[patch] Add support for unused counter on Advantech PCI1710

Hi,

this patch adds another subdevice (type 6, counter) to adv_pci1710.c, which can
be controlled via the insn interface.

The code is only enabled on the 1710 board series because that is the only
one i had to test.

To set the counter configuration (this has to be done at least once before
the counter is actually used) :

lsampl_t mode_and_flags;
insn[0].insn=INSN_CONFIG;
insn[0].n=1;
insn[0].data=&mode_and_flags;
insn[0].subdev=4;
insn[0].chanspec = 0;

where mode_and_flag is an integer between 0 and 5 (on of the six modes of
the Intel 82C54) plus three optinal flags:

0x08 BCD instead of binary counting.
0x10 external clock source (default is internal 1MHz source)
0x20 Wait for update of internal couter state after write.
     Setting this may be DANGEROUS, because with some modes
     the internal value is not update until after a trigger
     on the CNT0_GATE, and the current code has no timeout.
     This will lock up your PC and very bad things may happen.

As an example, for mode 3 (square wave mode) with external clock source, set:
mode_and_flag = 3 | 0x10;


To write a new value to the counter (0 <= x <= 65535):

lsampl_t value = x;
insn[0].insn=INSN_WRITE;
insn[0].n=1;
insn[0].data=&value;
insn[0].subdev=4;
insn[0].chanspec = 0;


To read the current value from the counter (which will be latched before the
read so the counting is not disturbed):

lsampl_t value;
insn[0].insn=INSN_READ;
insn[0].n=1;
insn[0].data=&value;
insn[0].subdev=4;
insn[0].chanspec = 0;

If you also need the counter status:

lsampl_t data[2];
insn[0].insn=INSN_READ;
insn[0].n=2;
insn[0].data=data;
insn[0].subdev=4;
insn[0].chanspec = 0;

data[0] will contain the counter value and data[1] the status (see status read-back
mode of the i82C54 or PCI-1710 manual).
Both will be latched befor read so this command does not disturb the count.


I have tested this code with my 1710 card and i believe it works, but as
this is my first attempt at hacking a driver any comment (regarding
conventions, style or whatever) is very welcome.

thanks,

Nils

Received on 2003-11-13Z14:29:04