NAME

ibuf - read digital input buffer

SYNOPSIS

#include <inbfr_p.h>
#include <stdio_p.h>
#include <signal_p.h>

FD dopen (path)
char *path;

int dclose (fildes)
FD fildes;

int dread (fildes, input)
FD fildes;
unsigned *input;

int dioctl (fildes, cmd, arg) FD fildes;
int cmd;
unsigned arg;

DESCRIPTION

dopen disables the digital input interrupt, clears the interrupt flag, clears other control words (see dioctl ), and returns a file descriptor to be used to read, control, and close the device. path points to a string "/dev/ib X " where X is the minor device number of the 16-bit input buffer, as specified in the configuration.

dread stores the 16-bit digital input value in the address passed as input and returns 0.

dioctl is used to read selected bits of the input buffer or to enable and disable the automatic collection of input buffer values under interrupt control.

If cmd is IB_GETB then if the bit number specified in arg is set dioctl returns 1; if the bit number is clear dioctl returns 0. arg ranges from 1 (high order bit) to 16 (low order bit).

When the argument cmd is SETP, then the values specified in the structure inbfr_cs pointed to by the argument arg are used to control the digital input buffer. This structure is defined in inbfr_p.h:

struct inbfr_cs {
  unsigned  flags;
  unsigned  mask;
  int       count;
  unsigned  *ubuf;
  int       *index;
  unsigned  *tbuf;
};
The arguments in inbfr_cs provide control information for collecting multiple digital input values and clock times and storing them in user-supplied arrays.

The flags field is used to enable or disable interrupts. It is set to IENABLE to enable interrupts or to !IENABLE to to disable interrupts.

mask is a 16 bit value used to specify which bits generate interrupts when they change state. The high order bit in mask maps on to input 1; the low order bit maps on to input 16. If the value of mask is 0160000, for example, then if interrupts are enabled, input channels 1, 2, and 3 will interrupt each time they change state.

count is the number of input values to read and store in the user supplied buffer beginning at the address passed as ubuf. index is the address of an index for keeping track of the last position filled in the user buffer. The user should initially set the index to -1 to start storing at the first position in the buffer. The user may change the value of the index at any time. When the index becomes greater than count interrupts are disabled.

tbuf is the address of a buffer for storing the time at which a new input value is received. The clock must be initialized and started independently (see progrmbl_clk(4P) ). If tbuf is NULL then times are not collected.

The flags can also specify two other bits of information. If set to LONG then the clock values are stored in a long rather than unsigned array. Normally, a 16 bit value is stored in the user buffer ubuf, with each set bit indicating a digital input bit ttat is asserted. If flags is set to BIT then the value stored in the ubuf is a bit identification number with the status of that bit indicated by the sign of the number. For example, if the interrupt was generated by bit 5 turning off, then -5 is stored. The flags field may be set to any combination of IENABLE, LONG, and BIT or'ed together.

When there is a digital input interrupt (an input bit has changed state and the interrupt flag is enabled), the signal SIGIB is sent with the file descriptor and the 16-bit digital input value. If BIT has been set by a call to dioctl, the bit number and status is passed rather than the 16-bit digital input value.

When the argument cmd is GETP, dioctl returns the values of the control information in the structure inbfr_cs pointed to by the argument arg. The flag field, in addition to being set to IENABLE, LONG, or BIT, may be set to IB_FLAG indicating that the interrupt bit is set in the control status word. The other fields in structure inbfr_cs return values that were set by a previous SETP command.

dclose disables the digital input interrupt, clears the interrupt flag, clears other control information, and returns 0.

FILES

/dev/ibX path name for digital input X.

SEE ALSO

progrmbl_clk(4P) , signal(2F) , ibuf(3U)

DIAGNOSTICS

If dopen is invoked with an illegal minor device number, it returns -1. if dclose, dread, or dioctl are passed illegal descriptors, a value of -1 is returned. If dioctl is passed an illegal cmd argument, a value of -1 is returned. If the command to dioctl is IB_GETB and the argument is not a number between 1 and 16 a value of -1 is returned. If the command to dioctl is SETP and arg.count is greater than 0, but either arg.index or arg.ubuf is NULL, then -1 is returned.