Skip to content. | Skip to navigation

Personal tools

io.h

io.h

io.h

/////////////////////////////////////////////////////////////////////////////
// IO.H
//
//  Last updated: 2/18/2003
//
//  Part of the source code for the M3 Program
//
//  This file contains several low level I/O routines.
/////////////////////////////////////////////////////////////////////////////

// Serial communication constants (To Host)
char Address;  	// Address of this computer (should be ?)
char Prompt;   	// Prompt character (should be ?)
char Response; 	// Response to host computer character (should be ?)
int Host = 0;  	// Host = COM1: = Port 0
int Guest = 1; 	// Downstream systems = COM2: = Port 1

// Analog and digital IO variables
// Notes:
//
// 	PCM-UIO48A:
// 	Address: 0x230  IRQ: 5
//
// 	Mesa 4A22:
// 	Address: 0x220
//
//  - Mesa: Input 0 is TILT LVDT C, Input 1 is TILT LVDT B,
//          Input 2 is TILT LVDT A, and Input 3 is +12VDC
//  - Mesa: You have to run "4A22DRVR 220 9 61"
//          followed by "4A22DCFG ST 61" before running the M3 program
//          to start Mesa's analog I/O device driver

// Global variables

// Parallel port address
int PARPORT;
// Parallel port value
byte PARVALUE;

// Flags for the Stepper Driver power states.
int StepperPowerFlag = 0; 		// nonzero = Power on to M3 Turret, ADC Turret, and Tilt steppers
int StepperTime;							// Used to delay stepper power on
int ADCStepperPowerFlag = 0;  // nonzero = Power on to ADC A and B steppers
int ADCStepperTime;						// Used to delay stepper power on

// Analog I/O variables and constants

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

// 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];

//////////////////
// y=ax+b values for external calibration process (analog\digital converter card Mesa 4A22) // where x is the direct readout
// from the card, this value will be scaled to obtain a new analog
// input signal y.
float a[3],b[3];

// Structure for communication with the Mesa anolog I/O TSR
struct TMESAInfo
{
	byte FunctionNumber;
	byte ReturnCode;
	byte Status;
	word PointerOffset;
	word PointerSegment;
	dword Data;
	byte Channel;
	byte Range;
} *MESAInfo;

// Variables for communicating with the Mesa real-mode interrupt
TRMInfo* mesarmi;              // Real mode interrupt structure
word mesasegment,mesaselector; // Used to point to real mode buffers

// Current analog data
double AnalogData[4];

// All 48 digital IO channel names
char DigIONames[48][40] = {
// P0-0
	"UNUSED","M3 Vacuum","M3 Air","ADC Moni B",
	"ADC Direction B","ADC Step B","ADC Moni A","ADC Direction A",
// P1-0
	"ADC Step A","ADC Turret Moni","ADC Turret Direction","ADC Turret Step",
	"M3 Turret Moni","M3 Turret Direction","M3 Turret Step","Tilt Moni C",
// P2-0
	"Tilt Direction C","Tilt Step C","Tilt Moni B","Tilt Direction B",
	"Tilt Step B","Tilt Moni A","Tilt Direction A",	"Tilt Step A",
// P3-0
	"M3 Turret Index A","M3 Turret Index B","M3 Turret Index C","ADC Turret Index",
	"ADC Index A","ADC Index B","M3 Turret Forward Limit","M3 Turret Reverse Limit",
// P4-0
	"ADC Turret Reverse Limit","ADC Turret Forward Limit","M3 Turret Ball In Limit","ADC Turret Ball In Limit",
	"ADC Turret Pin Out Limit","ADC Turret Pin Out","ADC Turret Pin In Limit","ADC Turret Pin In",
// P5-0
	"M3 Turret Pin Out Limit","M3 Turret Pin Out","M3 Turret Pin In Limit","M3 Turret Pin In",
	"M3 Flip Down Limit","M3 Flip Down","M3 Flip Up Limit","M3 Flip Up"};

/////////////////////////////////////////////////////////////////////////////
// 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 COM1:
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.
//  ":HdataCC\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 (TCS)

/////////////////////////////////////////////////////////////////////////////
// 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 MESA analog card, digital IO card, and parallel port

/////////////////////////////////////////////////////////////////////////////
// CloseHardwareIO - Shut down all low-level I/O interfaces
void CloseHardwareIO();
// Halt analog card driver

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

/////////////////////////////////////////////////////////////////////////////
// MesaInterrupt - Call the real-mode Mesa analog driver interrupt
void MesaInterrupt();
// Set the fields of MESAInfo appropriately, and call this routine.
// Results are in the MESAInfo structure.

/////////////////////////////////////////////////////////////////////////////
// SetParBit - Set a bit on the parallel port
void SetParBit(int bit);
// "bit" is from 0 to 7

/////////////////////////////////////////////////////////////////////////////
// ClrParBit - Clear a bit on the parallel port
void ClrParBit(int bit);
// "bit" is from 0 to 7

/////////////////////////////////////////////////////////////////////////////
// GetParBit - Get a bit on the parallel port
int GetParBit(int bit);
// "bit" is from 0 to 7
// Returns a 0 or 1 if bit "bit" is cleared or set on the parallel port.
// (Note that this doesn't actually read the parallel port, it just
// returns what has already been written.  There are only parallel port
// outputs in the M3 design, no inputs.

/////////////////////////////////////////////////////////////////////////////
// SetDigBit - Set a bit on the UIO48 digital IO card
void SetDigBit(int bit);
// "bit" is from 1 to 48

/////////////////////////////////////////////////////////////////////////////
// Clear a bit on the UIO48 digital IO card
void ClrDigBit(int bit);
// "bit" is from 1 to 48

/////////////////////////////////////////////////////////////////////////////
// Get a bit on the UIO48 digital IO card
int GetDigBit(int bit);
// "bit" is from 1 to 48
// 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 M3 Turret, ADC Turret, and 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 M3 Turret, ADC Turret, and 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 M3 Turret,
// ADC Turret, or Tilts are moving.

/////////////////////////////////////////////////////////////////////////////
// StepperPowerOffNow - Turn off power to M3 Turret, ADC Turret, and Tilt Steppers
void StepperPowerOffNow();
// Turn off power to steppers in an emergency

/////////////////////////////////////////////////////////////////////////////
// ADCStepperPowerOn - Turn on power to ADC A and B after setting motor phases
int ADCStepperPowerOn();
// Similar to StepperPowerOn

/////////////////////////////////////////////////////////////////////////////
// ADCStepperPowerOnStage2 - Set ADC A and B motor phases
void ADCStepperPowerOnStage2();

/////////////////////////////////////////////////////////////////////////////
// ADCStepperPowerOff - Turn off power to ADC A + B
void ADCStepperPowerOff(int MotionOK);
// Turns power off to steppers if nothing is using the steppers
// If MotionOK = 0, power will not be turned off if ADCA or ADCB are moving.

/////////////////////////////////////////////////////////////////////////////
// ADCStepperPowerOffNow - Turn off power to ADC A + B
void ADCStepperPowerOffNow();
// Turn off power to steppers in an emergency

Generated by GNU Enscript 1.6.5.2.
Document Actions