/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd and Vincent Hayward.	    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#include "../h/moper_com.h"
#define  MARKI		1

/* Error condition bits in the arm control register  */

#define  BRAKE_RELEASE	00	/* Error conditionms not reported by */
#define  HARDWARE_FAULT	00	/* the MARKI controller.h */
#define  ENCODERS_OK    00
#define  LIMIT_FAULT    00
#define  E_STOP         00

#define  EXTERN0	01	/* external input/output		*/
#define  EXTERN1	02	/* bit definitions			*/
#define  EXTERN2	04	/*					*/
#define  EXTERN3       010	/*					*/
#define  EXTERN4       020	/*					*/
#define  EXTERN5       040	/*					*/
#define  EXTERN6      0100	/*					*/
#define  EXTERN7      0200	/*					*/
/* #define  ARMPWR      0400	(defined in jointInterface.h) */
#define  OFFL	     01000	/* external low signal to stop the arm	*/
#define  RUN	     02000	/* front panel switch - run bit low	*/
#define  RESTART     04000	/* front panel switch - restart bit low */
#define  EXTRA3    0100000	/* spare I/O bit (not wired)		*/

/* ----- routine to detect hardware failures in the arm ----- */

int encodersOK = ENCODERS_OK;

armError()
{	
	register int acr = GET_ACR();
	extern int pdntEstop;

	if (encodersOK && !(acr & encodersOK))
	 { return (SLE_ENCODERS_E);
	 }
	if (acr & (E_STOP | HARDWARE_FAULT | LIMIT_FAULT | BRAKE_RELEASE))
	 { if (acr & E_STOP)
	    { return (MPR_ESTOP_E);
	    }
	   else if (acr & LIMIT_FAULT)
	    { return (SLE_LIMIT_E);
	    }
	   else if (acr & HARDWARE_FAULT)
	    { return (SLE_POWERAMP_E);
	    }
	   else if (acr & BRAKE_RELEASE)
	    { return (SLE_BRAKES_E);
	    }
	 }
	if (pdntEstop)
	 { return (MPR_ESTOP_E);
	 }
	else
	 { return (0);
	 }
}

/* if 0, INTSCL=log2(NINTER); if 1, INTSCL = 8-log2(NINTER) */
int intsclBias = 0;	
/* no. of bits in potentiometer readings */
int numPotBits = 8;
/* no. of times we have to read each pot to be sure of a good value */
int potRdCnt = 1;
