 /**********************************  espdwarf.h  *******************************
 * $Source: /home/cvs/ESP/gen2/software/msp430/dwarves/espdwarf.h,v $
 *  Copyright (C) 2003 MBARI
 *
 *  MBARI Proprietary Information. All rights reserved.
 * $Id: espdwarf.h,v 1.16 2004/11/11 05:26:09 brent Exp $
 *
 * shared definitions for espdwarf components
 *
 *****************************************************************************/

#ifndef espdwarf_h
#define espdwarf_h

#include "types.h"
#include "trapservo.h"
#define NSERVO   2   //# of servo channels
#define NROTARY  4   //# of rotary valves

// Software timers (each decriments TIMERHZ counts/second)
enum timerIndex {   //allocate and name interval timers
  dcoTimer,         //adjust DCO frequency to compensate for temperature change
  servoTimer,
  valveTimer,
  heaterTimer,
  gripperTimer,
  NTIMERS   //number of interval timers
};

enum debugMask {  //debugging code enable mask
  debugCmds   = 0x01,    //parse ASCII test commands input on debug port
  debugI2C    = 0x02,    //verbose debugging output for I2C operations
  debugEnc    = 0x04,    //" for motor/encoder operations
  debugValve  = 0x08,    //" for rotary valve operations
  debugTemp   = 0x10,    //" for temperature sensor operations
  debugHeatPWM= 0x20,     //" for heater pwm operations
  debugPressure  = 0x40
};

extern enum debugMask debugFlag;

// Operation complete mask for communication between background and servos

extern uint16 opComplete;

//bit field offsets within opComplete (from LSB)
#define rotationOp   0                 //four rotation operation complete flags
#define servoOp      NROTARY           //two servo operation complete flags
#define thermalOp    (NSERVO+NROTARY)  //one thermal operation complete flag
#define gripOp         (NSERVO+NROTARY+1)//two gripper operation complete flag
//the MSB must be zero

#define rvalve0 1
#define servo0 (rvalve0<<NROTARY)
#define thermal (servo0 << NSERVO)
#define grip (thermal<<1)

#define opCompleted(offset, channel)  set16(opComplete, 1<<((channel)+offset))
#define opServiced(offset, channel) clear16(opComplete, 1<<((channel)+offset))


void putDebugNewLine (void);

void putDebugString (char *string);

void putDebugLine (char *line);

void reportErr (const char *errTxt, ...);
void checkServoStatus(MotorChannel *mcChan);




#define I2CadrSWmask (DCORSWS & 0xf)   //address selection switches
                                    //note that zero is the address of the host
#define debugParse   (DCORSWS & 0x10)  //enable parsing commands from debug port
#define debugVerbose (DCORSWS & 0x20)  //enable verbose reporting on debug port

#define baseI2Cadr  0x10    //added to addrsws to yield node's I2C address

#endif
