Skip to content. | Skip to navigation

Personal tools

lcu/io.h

lcu/io.h

lcu/io.h

/////////////////////////////////////////////////////////////////////////////
// IO.H
//
//  Last updated: 4/24/2005
//
//  Part of the source code for the Remote M3 Program
//
//  This file contains several low level I/O routines.
/////////////////////////////////////////////////////////////////////////////

#define COMB 0 // COMB: = Port 0, hooked up to PC at control room
#define COMA 1 // COMA: = Port 1, hooked up to M3 cell DGHs
// Serial communication constants (To Host)
char Address = 'J';  	// Address of this computer (should be J)
char Prompt = ':';   	// Prompt character (should be :)
char Response = '~'; 	// Response to host computer character (should be ~)
int Host = COMB;
int Guest = COMA;

// Analog and digital IO variables
// Notes:
//

// Global variables

// Flags for the Stepper Driver power states.
int StepperPowerFlag = 0; // nonzero = Power on to Tilt steppers

// Analog I/O variables and constants

// For analog averaging (number of readings to average):
#define AnalogReadCount 4

// History of raw data reads for each of the four analog channels
long AnalogHistory[4][AnalogReadCount];
// Number of raw data read for each of the four analog channels
int AnalogHistoryCount[4];

// Current analog data
double AnalogData[4];

// All 24 digital IO channel names
char DigIONames[24][40] = {
// PA-0
  "Tilt Direction A","Tilt Direction B","Tilt Direction C",
  "Tilt Current",
  "Tilt Power",
  "Tilt Brakes",
  "UNUSED","UNUSED",
// PB-0
  "Tilt Moni A","Tilt Moni B","Tilt Moni C",
  "UNUSED","UNUSED","UNUSED","UNUSED","UNUSED",
// PC-0
  "Tilt Step A","Tilt Step B","Tilt Step C",
  "M3 Air","M3 Vacuum",
  "UNUSED","UNUSED","UNUSED"};

/////////////////////////////////////////////////////////////////////////////
// SystemReset - Software based system reset function
void SystemReset();
// Perform a hardware reset on the system.

/////////////////////////////////////////////////////////////////////////////
// InitPorts - Function to configure the serial port parameters and install
// the serial interrupt driver
void InitPorts();

/////////////////////////////////////////////////////////////////////////////
// RespondToHost - Transmit a string to the upstream host computer on COMB:
void RespondToHost(char* message);
// Send a message to the Host computer (upstream).
// The string "message" is transmitted.
// This routine automatically adds the correct Response and
// Address characters to the beginning of the string.

/////////////////////////////////////////////////////////////////////////////
// VerifyChecksum: Verifies that the checksum in a string is correct
int VerifyChecksum(char* s);
// Returns a zero if the string's checksum is OK, and a 1 if not.
// Note that this routine expects a full message, i.e.
//  ":JdataCC\r" where data is the body of the message, and CC is the
//  checksum.

/////////////////////////////////////////////////////////////////////////////
// RespondToHostWithChecksum: Add a hex checksum + CR to string and send
void RespondToHostWithChecksum(char* s);
// Calculates the Shec-checksum for a string, and sends the
// string to the host computer

/////////////////////////////////////////////////////////////////////////////
// COMTerminal - opens a simple terminal with a com port
void COMTerminal(int Port);
// This routine acts as a simple terminal to a com port.
// It displays received characters, and transmits typed characters.
// Hitting ESC ends the terminal session.

/////////////////////////////////////////////////////////////////////////////
// InitHardwareIO - Initialize low-level I/O interfaces
void InitHardwareIO();
// Initialize the 82C55 digital I/O chip and the MAX197 A/D chip

/////////////////////////////////////////////////////////////////////////////
// CloseHardwareIO - Shut down all low-level I/O interfaces
void CloseHardwareIO();

/////////////////////////////////////////////////////////////////////////////
// ReadAllAnalog - Query the Maxim MAX127 DAS for updated values
void ReadAllAnalog();
// Read all analog channels and store in the global analog variables

/////////////////////////////////////////////////////////////////////////////
// SetDigBit - Set a bit on the 82C55 digital I/O chip
void SetDigBit(int bit);
// "bit" is from 0 to 23

/////////////////////////////////////////////////////////////////////////////
// ClrDigBit - Clear a bit on the 82C55 digital I/O chip
void ClrDigBit(int bit);
// "bit" is from 0 to 23

/////////////////////////////////////////////////////////////////////////////
// GetDigBit - Get a bit on the 82C55 digital I/O chip
int GetDigBit(int bit);
// "bit" is from 0 to 23
// Returns a 0 or 1 if bit "bit" is cleared or set

/////////////////////////////////////////////////////////////////////////////
// SetStepperPhase - Set a steppers motor phase before motor current-on
void SetStepperPhase(int StepBit,int DirBit,int MonBit,int MonSteps);
// StepBit,DirBit,MonBit: the digital I/O bits for Step, Direction, and
// phase for the stepper whose phase needs to be set.  MonSteps is the
// number of steps to send to the driver before enabling current to the
// motor, a number from -9 to 9

/////////////////////////////////////////////////////////////////////////////
// StepperPowerOn - Turn power on to steppers after setting motor phases
int StepperPowerOn();
// Turn on power to Tilt Steppers.  This routine
// sets the motor phases correctly (with current to the motors off) before
// enabling current to the motors to avoid power-on jerks.
// If StepperPowerOn returns a 1, call StepperPowerOnStage2 one second later.

/////////////////////////////////////////////////////////////////////////////
// StepperPowerOnStage2 - Set motor phases
void StepperPowerOnStage2();

/////////////////////////////////////////////////////////////////////////////
// StepperPowerOff - Turn off power to Tilt Steppers
void StepperPowerOff(int MotionOK);
// Turns power off to steppers if nothing is using the steppers
// If MotionOK = 0, power will not be turned off if
// Tilts are moving.

/////////////////////////////////////////////////////////////////////////////
// StepperPowerOffNow - Turn off power to Tilt Steppers
void StepperPowerOffNow();
// Turn off power to steppers in an emergency

Generated by GNU Enscript 1.6.5.2.
Document Actions