/*-=-=-=-=-=-=-=-=-=-=-=- 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.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#ifndef _JOINTINTERFACE_H_
#define _JOINTINTERFACE_H_

/* --- Address offsets for functional groups of utilities. */
/* MS Use default address if none is specified in site.conf file */
#ifndef TRC004_BASE
#define TRC004_BASE             0x300
#endif

#define ENC_INDEX_BASE          0x0000
#define STATUS_REG              0x000C
#define ENC_COUNT_BASE          0x0010
#define ADC_VALUE               0x001C
#define ADC_START               0x001E
#define ENC_LOAD_BASE           0x0020
#define ADC_MUX_SELECT          0x002C
#define DISCRETE_REG            0x002E
#define DAC_BASE                0x0030

/* --- Masks for the status register. */
#define CALIB_MASK              0x0040
#define ADC_STAT_MASK           0x4000
#define POWER_ON_MASK		0x8000

/* --- Masks for the discrete register. */
#define POWER_BIT               0x0001
#define HAND_OPEN_BIT           0x0002
#define HAND_CLOSED_BIT         0x0004
#define SPARE_PIO_START         0x0008
#define CALIB_BIT               0x0040
#define JT6_OVRFLO_BIT          0x0080
#define ADC_MASK_BIT            0x4000
#define JT1_INDEX_BIT		0x0100
#define ALL_INDEX_BITS		0x3F00

/* --- Reciprocal of DAC gain (gain is set by resistors) */
#define DAC_BITS_PER_VOLT       -204.8
#define DAC_MAX_CNT		0x0BFF
#define DAC_MIN_CNT		0x0400

typedef enum {  TORQUE,         /* W torque to a single joint motor */
                TORQUE6,        /* W torques to all joint motors */
                VOLTAGE,        /* W voltage to a single joint motor */
                POSITION,       /* R/W position of a single joint */
                POSITION6,      /* R/W position of all joints */
                STATUS,         /* R/W discrete status/control bits */
                POT,            /* R ADC value */
		POT6,           /* R all ADC values */
		INDEX,		/* R one index register */
		INDEX6,		/* R all index registers */
		POWER,		/* R/W the ARM POWER ENABLE bit */
		INDEX_BIT,      /* R/W an index mask bit */
		ALL_INDEX_BTS,	/* R/W all index mask bits */
		CLR_INDEX_BIT,	/* clear an index mask bit */
		CLR_INDEX_BITS,	/* clear all index mask bits */
		CLR_ADC_BIT,	/* clear A/D done mask bit */
                ARB             /* Output to arbitrary address */
	     } ioOptionsT;

#define		I_OK		0
#define		I_ERR		-1
#define		I_BAD_OPTION	-2

short pumaDacWr(short val, short chan);
short pumaEncWr(short val, short chan);
short pumaDesWr(short val);
short pumaEncRd(short chan);
short pumaIndRd(short chan);
short pumaPotRd(short chan, short discrete);
short pumaDesRd( void );
short pumaControl(short option, short discrete, short chan, short *val);
short pumaStatus(short option, short chan, short *val);

#endif
