I/O Functions
The low level functions used to manipulate the I/O channels are the system calls open, lseek, read, write, close, and ioctl. The I/O channels are accessed through 3 character drivers for the digital I/O, ADC, and DAC. The uses of these functions are demonstrated in the sample programs fir.c, xor_iodimm.c, and even_parity_iodimm.c.
Digital Inputs and Outputs
For the digital input and output pins, each channel corresponds to one byte, where channel 0 is the 0th byte, channel 1 is the 1st byte, etc. The device can be accessed by a handle to the node /dev/io0 for both read and write. When writing to the pin, 0 will be low (0V) and
Specific to the digital outputs, there are ioctl calls to pass control information to the device driver. Each ioctl call takes three parameters, the handle, a descriptor of the desired command, and an integer, though in some cases the integer is ignored.
result=ioctl(handle, PIC_SETUP0, PIC_SETUP_PUSH_PULL)
Each of the command descriptors are listed below. If any of them are unsuccessful executing the function, an error will return. Please note that the PWM channels are currently not supported. Both PWM0 and PWM1 cannot be used at the same time since PWM0 is connected to the
DAC_POWER_DOWN should be used to power down the DAC once it is no longer needed. Note that the argument is ignored for this ioctl call.
PIC_SETUP0, PIC_SETUP1, PIC_SETUP2, PIC_SETUP3 will configure each digital out channel according to the integer specified in the argument. Each of the argument values are described below.
PIC_SETUP_LO_SIDE will configure an output pin as a
Analog I/O
For both the ADC and the DAC, each channel corresponds to 2 bytes, such that channel 0 is the 0th and 1st bytes, channel 1 is the 2nd and 3rd bytes, etc. The data in the bytes is binary encoded, in little endian format where the least significant bit is at the lower offset in the file. Values that can be written or read from the channels are unipolar from 0 to 4095, corresponding to 0 to 4.095V, thus there is 1mV per count. lseek should be used to move around the file to access I/O channels. For both reads and writes, as few as 1 or as many as all analog I/O channels can be accessed at once.
www.amctechcorp.com | 93 |