/***************************************************************
 * PrTRCDefn.h
 *
 * This files contains constants for TRC004 and TRC006 boards.
 *
 ****************************************************************/

/*
 * modification history
 *----------------------
 *
 * 10/26/97: K.C. Chang: created.
 */

#ifndef _PrTRCDefn_h
#define _PrTRCDefn_h

#include "PrRobotDefn.h"

#ifdef PR_TRC_0
#define TRC_BASE_ADDR                    0x100
#else // PR_TRC_0
#ifdef PR_TRC_1
#define TRC_BASE_ADDR                    0x200
#else // PR_TRC_1
#ifdef PR_TRC_2
#define TRC_BASE_ADDR                    0x240
#endif // PR_TRC_2
#endif // PR_TRC_1
#endif // PR_TRC_0

#define TRC_HAND_CLOSE                   (1<<1)
#define TRC_HAND_OPEN                    (1<<2)

#define TRC_ADDR_SPACE_SIZE              0x40
#define TRC_DISCRETE_OUT_REG             0x2E
#define TRC_DISCRETE_OUT_REG_BITS_MASK   0xFFFF
#define TRC_DISCRETE_OUT_POWER_BIT       0x0001
#define TRC_DISCRETE_OUT_CALIBRATION_BIT 0x0040
#define TRC_STATUS_IN_REG                0x0C
#define TRC_STATUS_IN_REG_BITS_MASK      0xFFFF
#define TRC_STATUS_IN_POWER_BIT          0x0080  //(1<<7)
#define TRC_STATUS_IN_THERMO_MASK        0x3F00
#define TRC_STATUS_IN_CALIBRATION_BIT    0x4000

#define TRC_ENCODER_LAST_CHANNEL  5
#define TRC_ENCODER_CHANNEL_COUNT 6
#define TRC_ENCODER_BIT_COUNT     16
#define TRC_ENCODER_COUNT_BASE    0x0010
#define TRC_ENCODER_LOAD_BASE     0x0020

#define TRC_DAC_CHANNEL_COUNT     8
#define TRC_DAC_BIT_COUNT         12
#define TRC_DAC_BASE_ADDR         0x030
#define TRC_DAC_VOLT_MAX          10.0
#define TRC_DAC_VOLT_MIN          -10.0
#define TRC_DAC_VOLT_RANGE        (TRC_DAC_VOLT_MAX - TRC_DAC_VOLT_MIN)
#define TRC_DAC_VOLT_ZERO         0.0
#define TRC_DAC_BITS_MAX          0x000   //0    --> +10 volts
#define TRC_DAC_BITS_MIN          0xFFF   //4095 --> -10 volts
#define TRC_DAC_BITS_RANGE        (TRC_DAC_BITS_MAX - TRC_DAC_BITS_MIN)
#define TRC_DAC_BITS_ZERO         (-TRC_DAC_BITS_RANGE/2.0) //0x800=2048
#define TRC_DAC_BITS_PER_VOLT     (TRC_DAC_BITS_RANGE/TRC_DAC_VOLT_RANGE)//<0.0

#define TRC_ADC_CHANNEL_COUNT     8
#define TRC_ADC_BIT_COUNT         8
#define TRC_ADC_VOLT_MAX          5.0
#define TRC_ADC_VOLT_MIN          0.0
#define TRC_ADC_VOLT_RANGE        (TRC_ADC_VOLT_MAX - TRC_ADC_VOLT_MIN)
#define TRC_ADC_BITS_MAX          0xFF  // 5.0 volt
#define TRC_ADC_BITS_MIN          0x00  // 0.0 volt
#define TRC_ADC_BITS_RANGE        (TRC_ADC_BITS_MAX - TRC_ADC_BITS_MIN)
#define TRC_ADC_VOLT_PER_BIT      (TRC_ADC_VOLT_RANGE/TRC_ADC_BITS_RANGE)  // > 0.0
#define TRC_ADC_BITS_OFFSET       0x00
#define TRC_ADC_MUX_SELECT        0x2C
#define TRC_ADC_DISCRETE_MASK     0x4000  // mask for the discrete output reg
#define TRC_ADC_STATUS_MASK       0x0040  // mask for the status input reg
#define TRC_ADC_START_PULSE       0x1E
#define TRC_ADC_VALUE             0x1C

#define TRC_DAC_VOLT_OFFSET { (-0.012),\
				(-0.008), \
				  (-0.004), \
				    (-0.009), \
				      (-0.012), \
					(-0.010), \
					  (-0.005), \
					    (-0.010) }

#endif // _PrTRCDefn_h
