H~ 9000 Computers Device I/O: User's Guide Device 1/0: User's Guide HP 9000 Computers Flin- HEWLETT a:~ PACKARD HP Part No. 81864-90002 Printed in USA January 1991 First Edition E0191 Notices The information contained in this document is subject to change without notice. Hewlett-Packard makes no warranty of any kind with regard to this manual, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. Hewlett-Packard shall not be liable for errors contained herein or direct, indirect, special, incidental or consequential damages in connection with the furnishing, performance, or use of this material. Warranty. A copy of the specific warranty terms applicable to your Hewlett-Packard product and replacement parts can be obtained from your local Sales and Service Office. Copyright © Hewlett-Packard Company, 1991 This document contains information which is protected by copyright. All rights are reserved. Reproduction, adaptation, or translation without prior written permission is prohibited, except as allowed under the copyright laws. Restricted Rights Legend. Use, duplication or disclosure by the U.S. Government Department of Defense is subject to restrictions as set forth in paragraph (b )(3) (ii) of the Rights in Technical Data and Software clause in FAR 52.227-7013. Printing History New editions of this manual will incorporate all material updated since the previous edition. The manual printing date and part number indicate its current edition. The printing date changes when a new edition is printed. (Minor corrections and updates which are incorporated at reprint do not cause the date to change.) The manual part number changes when extensive technical changes are incorporated. January, 1991 ... Edition 1. This Edition documents material related to device I/O relevant to the 8.X release of HP-UX . • For DIL, it supersedes the "Device I/O Library" part of manual part number 97089-90057, Edition 1, dated September 1989. New information was added regarding the Centronics-compatible Parallel interface . • For HP-HIL, it supersedes the "Using HP-HIL Devices" part of manual part number 97089-90081, Edition 3, dated September 1987. Information regarding use of the Sound Generator (beeper) was added to the HP-HIL part. iii Contents 1. Introduction to Device I/O What is Device I/O? 1-1 What is DIL? .... . 1-1 What is HP-HIL? ... . 1-1 Choosing DIL or HP-HIL 1-2 Part I: DIL 2. Interfacing Concepts Variation Between Computer Systems 2-1 Manual Organization 2-2 DIL Interfacing Subroutines . . . 2-3 Linking DIL Routines . . . . . 2-3 Calling DIL Routines from Pascal 2-3 Calling DIL Routines from FORTRAN 2-4 General Interface Concepts . 2-5 Definition . . . . 2-5 Interface Functions . 2-6 Handshake I/O . . . 2-7 Handshake Output 2-7 Handshake Input 2-7 HP- IB Protocol . . 2-8 The HP-IB Interface 2-9 General Structure . 2-9 Handshake Lines . 2-10 Bus Management Control Lines . 2-13 ATN: The Attention Line .. 2-14 IFC: The Interface Clear Line 2-14 Device I/O Contents-1 REN: The Remote Enable Line . 2-14 EOI: The End or Identify Line . 2-14 SRQ: The Service Request Line 2-15 The GPIO Interface . . . . . . . . 2-15 The Centronics-Compatible Parallel Interface . 2-16 3. General-Purpose Routines Background Basics 3-2 Interface Special Files 3-2 Entity Identifiers (eid) 3-2 Programming Model 3-2 General-Purpose Routines 3-3 Additional Series 300/400 Routines 3-4 Opening Interface Special Files . . 3-4 Closing Interface Special Files 3-6 Low-Level Read/Write Operations 3-7 Example .......... . 3-9 Designing Error Checking Routines 3-10 The errno Variable 3-10 Using errno .... . . 3-10 The errno.h Header File 3-10 Displaying errno 3-10 Error Handlers . 3-11 Resetting Interfaces . 3-12 Locking an Interface . 3-13 Controlling I/O Parameters 3-14 Setting I/O Timeout 3-15 Setting Data Path Width 3-16 Setting Minimum Data Transfer Rate 3-17 Setting the Read Termination Pattern 3-18 Termination on Byte Count 3-18 Termination on Hardware Condition . 3-19 Termination on Data Pattern. . . 3-19 Disabling a Read Termination Pattern 3-22 Determining Why a Read Terminated 3-23 Example .... 3-24 Interrupts . . . . 3-26 HP- IB Interrupts 3-26 Contents-2 Device 1/0 GPIO Interrupts . . . . . . . 3-27 Parallel Interrupts ..... . 3-27 The io_on_interrupt Subroutine. 3-28 The io_interrupt_ctl Subroutine 3-29 4. Controlling the HP-IB Interface Overview of HP-IB Commands 4-2 UNLISTEN 4-4 UNTALK ..... 4-4 DEVICE CLEAR . . 4-5 LOCAL LOCKOUT . 4-5 SERIAL POLL ENABLE 4-5 SERIAL POLL DISABLE 4-5 TRIGGER (Group Execute Trigger) 4-5 SELECTED DEVICE CLEAR . . 4-6 GO TO LOCAL ....... . 4-6 PARALLEL POLL CONFIGURE. 4-6 PARALLEL POLL ENABLE. 4-6 PARALLEL POLL DISABLE 4-6 Overview of HP-IB DIL Routines 4-7 HP-IB: The Computer's Role . 4-8 Ground Rules ..... . 4-8 A vailable Subroutines versus Controller Role 4-8 Bus Citizenship: Surviving Multi-Device/Multi-Process HP-IB 4-10 io_lock and io_ unlock 4-11 io_burst . . . . . . . . . . 4-11 hpib_io . . . . . . . . . . 4-11 Opening the HP-IB Interface File 4-12 Sending HP-IB Commands ... 4-12 Errors While Sending Commands 4-15 Changing Parity on Commands 4-16 Active Controller Role. . . . . . 4-17 Determining Active Controller . 4-18 Setting Up Talkers and Listeners 4-19 Auto-Addressing . . . . . . 4-19 Using hpib_send_cmnd 4-21 Calculating Talk and Listen Addresses . 4-22 An Example Configuration . . . . . . 4-23 Device I/O Contents-3 Remote Control of Devices 4-24 Locking Out Local Control 4-24 Enabling Local Control 4-25 Triggering Devices 4-25 Transferring Data 4-26 Data Output .. 4-26 Data Input ... 4-27 Clearing HP- IB Devices 4-28 Responding to Service Requests . 4-29 Monitoring the SRQ Line 4-29 Processing the Service Request 4-31 Parallel Polling . . . . . . . . 4-32 Configuring Parallel Poll Responses 4-32 Disabling Parallel Poll Responses 4-36 Conducting a Parallel Poll . . . . 4-36 Errors During Parallel Polls 4-38 Waiting For a Parallel Poll Response 4-39 Calculating the mask 4-39 Calculating the sense 4-40 Example ..... . 4-41 Serial Polling . . . . . 4-43 Conducting a Serial Poll 4-43 Errors During Serial Poll . 4-45 Passing Control. . . . . . 4-46 What If Control Is Not Accepted? 4-46 Errors While Passing Control. . 4-47 Controlling the ATN Line . . . . 4-48 Changing the Interface Bus Address 4-48 System Controller Role . . . . 4-49 Determining System Controller 4-49 System Controller's Duties 4-50 hpib_abort . . . . . . . . 4-50 hpib_ren_ctl . . . . . . . 4-51 Errors During hpib_abort and hpib_ren_ctl 4-51 The Computer As a Non-Active Controller 4-53 Checking Controller Status. . . . 4-53 Requesting Service . . . . . . . 4-54 Errors While Requesting Service 4-56 Contents-4 Device I/O Responding to Parallel Polls . . . . . 4-57 Calculating the Response .. . . 4-58 Limitations of hpib_card_ppoILresp 4-58 Error Conditions . . . . . . 4-59 hpib_ppoILresp_ctl . . . . . 4-59 Disabling Parallel-Poll Response 4-60 Accepting Active Control 4-61 Errors While Waiting on Status . 4-63 Determining When You Are Addressed 4-64 Combining I/O Operations into a Single Subroutine Call 4-68 Iodetail: The I/O Operation Template. 4-69 The Mode Component . . . 4-70 The Terminator Component 4-71 The Count Component 4-71 The Buf Component 4-72 Allocating Space . . . . 4-72 Example ....... . 4-73 Locating Errors in Buffered I/O Operations 4-75 5. Controlling the GPIO Interface Interface Configuration 5-1 Creating the GPIO Interface File 5-1 Interface Control Limitations 5-2 Using DIL Subroutines 5-2 Resetting the Interface. . 5-3 Performing Data Transfers 5-4 U sing Status and Control Lines 5-4 Driving CTLO and CTL 1 5-5 Reading STIO and STU . . 5-5 Controlling Data Path Width . 5-6 Controlling Transfer Speed 5-7 GPIO Timeouts 5-7 Burst Transfers . . . . . 5-8 Read Terminations . . . 5-8 Determining Why a Read Operation Terminated 5-8 Specifying a Read Termination Pattern 5-8 Interru pts . . . . . . . . . . . . . . . . . . 5-8 Device I/O Contents~5