FD dopen (path)
char *path;
int dclose(fildes)
FD files;
int dread (fildes, pbfr)
FD fildes;
unsigned *pbfr;
int dioctl (fildes, cmd, arg)
FD fildes;
int cmd;
struct ad_cs *arg;
ac_start (fildes)
FD fildes;
ac_xstart (fildes)
FD fildes;
dclose clears all control flags (start conversion, end of conversion, and external start), sets the maximum sample count to 0, clears all interrupt control pointers, and returns 0.
dread reads the analog-to-digital converted value under program control mode (interrupts disabled). It starts the analog-to-digital conversion for the channel specified in fildes and waits until the end of conversion flag or error flag is set. It then reads the converted value, storing it in the address passed as pbfr and returns 0.
dioctl serves to set and inspect the control status register of the analog-to-digital converter board and to supply and report the values of pointers and control information for collecting single or multiple samples from single or multiple channels under interrupt control.
When the argument cmd is SETP, then the values specified in the structure ad_cs pointed to by the argument arg is used to control the analog-to-digital converter. This structure is defined in adc_p.h
struct ad_cs { unsigned ac_flags; int ac_scnt; int *ac_index; int *ac_ch; int **ac_vec; int *ac_errcnt; };The ad_flags field of the argument structure contains several bits which program the analog-to-digital converter. The symbolic values are defined in atod_p.h and are relevant to the user include:
FLG_ERR 0100000 error flag (R) FLG_EOC 0000200 end of conversion flag (R) AC_IENABLE 0000100 enable interrupt on eoc (R/W) AC_XSTART 0000002 enable external start sigbal (R/W) AD_STARTC 0000001 start conversion (W)These bits are used to read the error flag and the end of conversion flag, to enable and disable the end of conversion interrupt and the external start conversion signal, and to start a conversion. dioctl sets the control status register according to ad_flags.
The other arguments in ad_cs provide additional control information for collecting multiple samples from one or more channels and storing the values in user-supplied arrays. ac_ch provides a pointer to an array of channel numbers while ac_vec is a pointer to an array of vectors (one for each channel) for storing converted values. The last item in both the channel array and the vector array must be 0. Note: all channels in the list must reside on the same analog-to-digital converter board, while fildes should refer to one channel on that board. ac_scnt specifies the maximum number of samples to collect and ac_index is the address of an index for keeping track of the last position filled in the storage arrays. The user should initially set the index to -1 to start storing at the first item in the storage array. The user may change the value of the index at any time. When the index becomes greater than or equal to ac_scnt interrupts are disabled and sampling stops. ac_errcnt is the address of an error count that will be incremented each time a conversion error occurs (this will happen if a new conversion is started before reading the value from the previoous conversion). dioctl clears the error count.
If ac_scnt equals 0 and ac_index, ac_ch, and ac_vec each equal NULL then dioctl will disregard these arguments and will copy the channel number specified in fildes into the control status register along with ac_flags.
When the argument cmd is GETP, then the control-status register is stored in the ac_flags field of the argument structure and the remaining fields return the current values of the maximum sample count and the index, channel, vector, and error count pointers.
dioctl returns a value of 0 when the call is successful.
ac_xstart is a macro that enables the external start flag AC_XSTART allowing analog-to-digital conversions to be controlled by an external oscillator. If the device has been programmed (via a previous call to dioctl ) to store converted values in user-supplied arrays under interrupt control, each time the device receives a start signal, several actions take place. The index is incremented, a conversion is performed for each channel specified by ac_ch, the results are stored in the supplied vectors supplied through ac_vec, and the signal SIGADC is sent with the file descriptor for the first channel in the list and the value of the index. The user may choose to ignore this signal or may write a signal routine to do special processing on the samples or change the value of the index. In either case, before calling ac_xstart a call to signal(2P) must occur.
Invoking the macro ac_start sets the start conversion flag AC_STARTC to begin a single conversion for the channel specified by fildes in the last call to dioctl. If the AC_EOC interrupt flag is enabled, then when the conversion is complete the signal SIGADC is sent with the file descriptor and the converted value. The user must supply a routine to catch this signal and obtain the converted value.