AMC 68VZ328 software manual Digital I/O Functions

Page 69

Digital I/O Functions

The low level functions used to manipulate the digital I/O points are the system calls open, lseek, read, write, close, and ioctl. The uses of these functions are demonstrated in two simple sample programs,

xor.c and even_parity.c.

open gives access to the digital I/O character device. It takes two parameters, the node for your device in / dev and the mode you wish to open it in. For the digital I/O device, you will want to use the node /dev/io1 and the mode for read and write O_RDWR. This function will return the handle to your device:

handle = open(“/dev/io1”, O_RDWR)

lseek will choose the current I/O point and takes three parameters including the handle, the offset, and a descriptor for how the offset is used (SEEK_SET, SEEK_CUR, SEEK_END). SEEK_SET will position the file pointer to an absolute position in the array of active pins as specified by the value in offset. SEEK_CUR will move relative to the current position by the number in offset. SEEK_END will move the file pointer to the end of the array of active pins. lseek should be used to position the file pointer prior to any read or write operation.

lseek(handle, pin->offset, SEEK_SET)

read will read the value of the current I/O point. It takes three parameters, the handle, the byte(s) for the read information to be stored to, and the number of bytes to be read. This function will only allow you to read from the active pins. Reads can be done as a single pin or in a group of contiguous pins. The result of the read will be 0xFF (high) or 0x00 (low). If the read operation was not successful, then an error will be returned. The example below reads one byte into the state field of the dimm_io structure.

error = read(handle, &(pin->state), 1)

write sets the value of the current I/O point and it also takes three parameters, the handle, the byte(s) that will be written to the output pins, and the number of bytes to be written. Note that only output pins can be written to, and attempting to write to input pins will generate an error. Similar to reading, write operations can be done for a single I/O point or as a contiguous group of pins. Write values are non-zero for high, and zero for low. The example demonstrates writing one byte from the state field of the dimm_io structure. Prior to using this write function, the state (0 or 1) of the pin was specified in the state field.

error = write(handle, &(pin->state), 1)

close will close the digital I/O device and only takes one parameter, the handle for the device. This should be done once the device is no longer needed.

close(handle)

ioctl will configure an I/O point and it will pass control information to the device driver. Each ioctl call takes three parameters, the handle, a descriptor of the desired command, and a pointer to a dimm_io structure:

error = ioctl(handle, DIMM_IO_IOCTL_SET_CONFIG_BY_PORT_BIT, pin) Each of the command descriptors are listed below. If any of them are unsuccessful executing the function, an error will return.

www.amctechcorp.com

69

Image 69
Contents DimmPCITM 68VZ328 Hardware / Software Manual Copyright notice Contact InformationDimmPCITM Software Development Kit NETdimm Developers Kit Quick Start Guide Etc/issue Page This page left intentionally blank Launching Linux at the embedded IntroductionPage System Requirements What’s on the CD?This page left intentionally blank UC68VZ328 Embedded Microcontroller FeaturesCPU Module BackplaneCPU Module Description General DescriptionBackplane Description CPU Architecture ArchitectureMCU Core System MemoryMemory Map Memory Map MemoryLayout of the Flash and Flash Schematic Layout of the Flash Sdram Viewing the Ethernet MAC ID Ethernet ControllerNETdimm Ethernet Schematic IOdimm Digital I/ODigital Output Schematic Analog Output Schematic Analog Input Schematic Digital to Analog Converter Schematic RS-232 WatchdogHighlights Usage LCD Interface LCD SchematicDimmPCITM signals for System Slot DimmPCITM Signal DescriptionsPCI Maximum Ratings Electrical CharacteristicsThis page left intentionally blank Installation Installing the dimmPCI TM SystemBuilder Kit Before beginningConfiguring and compiling the µClinux kernel Customizing the filesystem Creating a ROM imageAccessing your dimmPCI development board via the serial port Accessing the Network Static IPDynamic IP Compiling your own source code Accessing your dimmPCI development board via telnetUsing NFS to streamline the development cycle Home directory/dimmpci/source Method Updating Applications on your dimmPCI moduleThis page left intentionally blank Loader Programming the uC68VZ328Oops Cd /opt/boottools/oops Oops -p /dev/ttyS0 -k kernel.bin Page Page This page left intentionally blank Sample Code AppendixClose the file afterwards fclose filehandle Page Longwatchdogid #include unistd.h #include stdio.h int main void This page left intentionally blank Journalling Flash File System Umount /usr Sbin/mkjffs /dev/flash0 Page This page left intentionally blank Development Tool Chains Normal Usage of the PIC-COFFTool Chain Page This page left intentionally blank Introduction D1 Application NoteKernel and Filesystem Configuration YES Kernel and Filesystem Configuration Flow ChartAvailable Digital I/O Pins List of all available digital I/O pins Dimmio structure description Programming StructureDigital I/O Functions Page In0 In1 In2 In3 In4 In5 In6 In7 Out0 Even Parity Sample ProgramsMknod io1 c 123 Page This page left intentionally blank Abstract D2 Application NoteRequirements Kernel ConfigurationAgain, from the main menu under Network device support Kernel Configuration Flow Chart AtCommandPrompt Filesystem Configuration Cd /opt/filesystem name make clean Make Modifications to ‘rc’ file Filesystem Configuration Flow ChartTesting Host machine ConfigurationPage This page left intentionally blank Application Note Using Multiple NETdimm ModulesInetd based Server & Client Simple Server & ClientPage This page left intentionally blank IOdimm Using Analog and Digital I/O withCd /opt Cp -Rpdx newfs iodimmmfs ADC MAX1203 Category Channel Backplane System Backplane Header Slot Pin Available I/O PinsDigital Inputs and Outputs Functions+ Κ Iodimm/dio Samples/cardspecific/iodimm/dio Page This page left intentionally blank Purpose & basic format of files for oops Using OopsUpload & Flash Download Upload & RunCommon oops program arguments Appendix This page left intentionally blank 104 Licensing, Copyrights & Liability DimmPCITM Software Development Kit DistributionPreamble 106 107 108 109 Appendix How to Apply These Terms to Your New Programs No Warranty111 112 113 This page left intentionally blank 114 References/ Suggested Reading