-- GPIB.mesa
   -- Copyright c 1985 by Xerox Corporation.  All rights reserved.
   -- Created for PostCedar5.2 by Neil Gunther, March 22, 1985 
   -- Compiled for Cedar 6.0, September 6, 1985 
   -- Last edited by Neil Gunther, September 26, 1985 11:01:30 am PDT
   -- Tim Diebert for XDE on a Dicentra:  3-Oct-85  9:23:51
-- 
-- 
-- 
-- This interface defines the IEEE 488 General Purpose Interface Bus (GPIB) standard
-- for asynchronous byte serial bit parallel interfacing to instrumentation.  It contains
-- all the standard commands, both universal and selected, and data transfer PROC's.  To
-- keep machine-dependent applications organized, this PUBLIC interface is EXPORTED
-- by the appropriate driver-level implementation which must be bound into the
-- client's configuration. 
-- 

-- IEEE 488 Technical Parameters:
-- 
--    o Maximum transmission length = 20 meters/bus; 2m/device; Star or Linear network.
--    o Maximum number of devices/bus = 15; 1 talker/14 listeners.
--    o Maximum data rate = 1Mbps for short paths; ~300 Kbps typical; device limited.
--    o Signals: 8 data/8 control simultaneously active.
--    o Data Transfer: byte serial bit parallel, asynchronous, with 3-wire handshake.
--    o Only one controller may be active at once. The sytem controller is the master.
-- 
-- For the formal bus specification see: IEEE Standard Digital Interface for Programmable
-- Instrumentation, ANSI/IEEE Std 488-1978 and ANSI/IEEE Std 728-1982.
-- 


GPIB: DEFINITIONS = BEGIN

-- Types and Constants
   -- 
   -- Bus Status
    
   StatusFlag: TYPE = {
      DAV,    -- Data Valid
      NRFD,   -- Not Ready For Data
      NDAC,   -- NOT Data Accepted
      IFC,    -- Interface Cleared
      SRQ,    -- Service Request
      REN,    -- Remote Enable
      EOI,    -- End or Identify
      ATN     -- Attention  [switch Command/Data modes]
    };
   
   StatusVec: TYPE = ARRAY StatusFlag OF BOOL;
   SRQLabels: TYPE = ARRAY StatusFlag OF LONG STRING;
      
   -- Command Group
   -- 
   goToLocal: CHAR = 001C;          -- GTL
   selectedDeviceClear: CHAR = 004C;      -- SDC
   parallelPollConfigure: CHAR = 005C;      -- PPC
   groupExecuteTrigger: CHAR = 010C;      -- GET
   takeControl: CHAR = 011C;         -- TCT
   localLockout: CHAR = 021C;         -- LLO
   devicesClear: CHAR = 024C;         -- DCL
   parallelPollUnconfigure: CHAR = 025C;           -- PPU
   serialPollEnable: CHAR = 030C;         -- SPE
   serialPollDisable: CHAR = 031C;         -- SPD
   parallelPollEnable: SecondaryCommand = 140C;   -- PPE
   parallelPollDisable: SecondaryCommand = 160C;   -- PPD
 
   -- Listen/Talk Address Groups
   
   ListenAddress: TYPE = CHAR [040C..077C];
   UnListen: ListenAddress = 077C;
   TalkAddress: TYPE = CHAR [100C..137C];
   UnTalk: TalkAddress = 137C;
   SecondaryCommand: TYPE = CHAR [100C..177C];
   FORMAT: TYPE = {F0, F1, F2, F3, F4, F5};

   PrimaryAddress: TYPE = CHAR [040C..137C];
   DeviceAddr: TYPE = NAT [0..31); 
--    Bus: CHAR;
   
-- Procedures 
   
   -- Universal commands (all devices whether addressed or not)
   
   Command: PROC [sendMsg: LONG STRING];
   DevicesClear: PROC;
   GoToLocal: PROC;
   GroupExecuteTrigger: PROC;
   InterfaceClear: PROC;
   LocalLockout: PROC;
   RemoteEnable: PROC;
   
   -- Selected Device Commands (only those devices addressed)
   
   SelectedDeviceClear: PROC [device: DeviceAddr];
   SelectedGoToLocal: PROC [device: DeviceAddr];
   SelectedGroupEnableTrigger: PROC [device: DeviceAddr];
   SelectedRemoteEnable: PROC [device: DeviceAddr];
   -- 
   -- Explicit Polling Routines
   
   ParallelPollConfigure: PROC [device: DeviceAddr];
   ParallelPollUnconfigure: PROC;
   SelectedParallelPollConfigure: PROC [device: DeviceAddr];
   SelectedParallelPollUnconfigure: PROC [device: DeviceAddr];
   
   -- Read Specific Devices
   
   PollDevice: PROC [device: DeviceAddr, labels: SRQLabels];
   ReadDevice: PROC [device: DeviceAddr, recvMsg: LONG STRING];  
   ReadOnInterrupt: PROC [device: DeviceAddr, recvMsg: LONG STRING, labels: SRQLabels];
   SelectedReadSerialPoll: PROC [device: DeviceAddr] RETURNS [statusByte: CHAR];
   ReadStatusByte: PROC [device: DeviceAddr] RETURNS [char: CHAR];   
      
   -- Write Specific Devices
   
   WriteDevice: PROC [device: DeviceAddr, sendMsg: LONG STRING];
     -- Sends the string as a whole message.
   WriteDeviceInitial: PROC [device: DeviceAddr, sendMsg: LONG STRING];
     -- Sends the string without the EOI.
   WriteDeviceContinued: PROC [device: DeviceAddr, sendMsg: LONG STRING, last: BOOL];
     -- Sends the string without the initial stuff.
   WriteDeviceBlock: PROC [device: DeviceAddr, lp: LONG POINTER, quadWordCnt: CARDINAL,
     last: BOOL];
     -- Sends the bytes pointed to by lp, the total bytes count must be a multiple of 8.
   
   
   -- Convenience Functions
   
   InitializeController: PROC RETURNS [open: BOOL];
   FinalizeController: PROC;
   
   maxWriteBuffer: NAT = 512+5;
   maxReadBuffer: NAT = 512+5;
   
   END.