00001 #ifndef STG2_H
00002 #define STG2_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __GNUC__
00019 #ifndef __attribute__
00020 #define __attribute__(x)
00021 #endif
00022 #endif
00023
00024
00025 static char __attribute__((unused)) stg_h[] = "$Id: stg2.h,v 1.5 2001/10/30 23:34:05 paul_c Exp $";
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #define DEFAULT_STG_BASE_ADDRESS 0x200
00042 extern unsigned short STG_BASE_ADDRESS;
00043
00044
00045
00046 extern int stgMotInit(const char * stuff);
00047 extern int stgMotQuit(void);
00048
00049 extern int stgDacNum(void);
00050 extern int stgDacWrite(int dac, double volts);
00051 extern int stgDacWriteAll(int max, double * volts);
00052
00053 extern int stgEncoderSetIndexModel(unsigned int model);
00054 extern int stgEncoderNum(void);
00055 extern int stgEncoderRead(int encoder, double * counts);
00056 extern int stgEncoderReadAll(int max, double * counts);
00057 extern int stgEncoderResetIndex(int encoder);
00058 extern int stgEncoderReadLatch(int encoder, int * flag);
00059 extern int stgEncoderReadLevel(int encoder, int * flag);
00060
00061 extern int stgMaxLimitSwitchRead(int axis, int * flag);
00062 extern int stgMinLimitSwitchRead(int axis, int * flag);
00063
00064 extern int stgHomeSwitchRead(int axis, int * flag);
00065
00066 extern int stgAmpEnable(int axis, int enable);
00067 extern int stgAmpFault(int axis, int * fault);
00068
00069 extern int stgDioInit(const char * stuff);
00070 extern int stgDioQuit(void);
00071
00072 extern int stgDioMaxInputs(void);
00073 extern int stgDioMaxOutputs(void);
00074 extern int stgDioRead(int index, int *value);
00075 extern int stgDioWrite(int index, int value);
00076 extern int stgDioCheck(int index, int *value);
00077 extern int stgDioByteRead(int index, unsigned char *byte);
00078 extern int stgDioShortRead(int index, unsigned short *sh);
00079 extern int stgDioWordRead(int index, unsigned int *word);
00080 extern int stgDioByteWrite(int index, unsigned char byte);
00081 extern int stgDioShortWrite(int index, unsigned short sh);
00082 extern int stgDioWordWrite(int index, unsigned int word);
00083 extern int stgDioByteCheck(int index, unsigned char *byte);
00084 extern int stgDioShortCheck(int index, unsigned short *sh);
00085 extern int stgDioWordCheck(int index, unsigned int *word);
00086
00087 extern int stgAioInit(const char * stuff);
00088 extern int stgAioQuit(void);
00089
00090 extern int stgAioMaxInputs(void);
00091 extern int stgAioMaxOutputs(void);
00092 extern int stgAioStart(int index);
00093 extern void stgAioWait(void);
00094 extern int stgAioRead(int index, double *volts);
00095 extern int stgAioWrite(int index, double volts);
00096 extern int stgAioCheck(int index, double *volts);
00097 extern int stgModel(void);
00098
00099 #define STG_SUCCESS 0
00100 #define STG_FAILURE 1
00101
00102 #define NUM_AXIS_IN_SYS 8
00103 #define MAX_AXIS 8
00104
00105 #define CNT0_D 0x00
00106 #define CNT1_D 0x01
00107 #define CNT0_C 0x02
00108 #define CNT1_C 0x03
00109 #define CNT2_D 0x04
00110 #define CNT3_D 0x05
00111 #define CNT2_C 0x06
00112 #define CNT3_C 0x07
00113 #define CNT4_D 0x08
00114 #define CNT5_D 0x09
00115 #define CNT4_C 0x0a
00116 #define CNT5_C 0x0b
00117 #define CNT6_D 0x0c
00118 #define CNT7_D 0x0d
00119 #define CNT6_C 0x0e
00120 #define CNT7_C 0x0f
00121 #define DAC_0 0x10
00122 #define DAC_1 0x12
00123 #define DAC_2 0x14
00124 #define DAC_3 0x16
00125 #define DAC_4 0x18
00126 #define DAC_5 0x1a
00127 #define DAC_6 0x1c
00128 #define DAC_7 0x1e
00129 #define ADC 0x410
00130 #define ADC_0 0x410
00131 #define ADC_1 0x412
00132 #define ADC_2 0x414
00133 #define ADC_3 0x416
00134 #define ADC_4 0x418
00135 #define ADC_5 0x41a
00136 #define ADC_6 0x41c
00137 #define ADC_7 0x41e
00138 #define CNTRL0 0x401
00139 #define DIO_A 0x400
00140 #define DIO_B 0x402
00141 #define DIO_C 0x404
00142 #define DIO_D 0x401
00143 #define PORT_A 0x400
00144 #define PORT_B 0x402
00145 #define PORT_C 0x404
00146 #define PORT_D 0x405
00147 #define INTC 0x405
00148 #define BRDTST 0x403
00149 #define MIO_1 0x406
00150 #define ABC_DIR 0x406
00151 #define MIO_2 0x407
00152 #define D_DIR 0x407
00153 #define ODDRST 0x407
00154 #define TIMER_0 0x408
00155 #define TIMER_1 0x40a
00156 #define TIMER_2 0x40c
00157 #define TMRCMD 0x40e
00158 #define ICW1 0x409
00159 #define ICW2 0x40b
00160 #define OCW1 0x40b
00161 #define OCW2 0x409
00162 #define OCW3 0x409
00163 #define IRRreg 0x409
00164 #define ISR 0x409
00165 #define IDLEN 0x409
00166 #define IMR 0x40b
00167 #define SELDI 0x40b
00168 #define IDL 0x40d
00169 #define CNTRL1 0x40f
00170
00171
00172
00173
00174
00175 #define IXEVN 0x80
00176 #define IXODD 0x40
00177 #define LIXEVN 0x20
00178 #define LIXODD 0x10
00179 #define EOC 0x08
00180 #define TP0 0x04
00181 #define USR_INT 0x02
00182 #define TP2 0x01
00183
00184 #define AUTOZERO 0x80
00185 #define IXLVL 0x40
00186 #define IXS1 0x20
00187 #define IXS0 0x10
00188 #define USRINT 0x08
00189 #define IA2 0x04
00190 #define IA1 0x02
00191 #define IA0 0x01
00192
00193 #define CNTRL0_AZ 0x80
00194 #define CNTRL0_AD2 0x40
00195 #define CNTRL0_AD1 0x20
00196 #define CNTRL0_AD0 0x10
00197 #define CNTRL0_CAL 0x08
00198 #define CNTRL0_IA2 0x04
00199 #define CNTRL0_IA1 0x02
00200 #define CNTRL0_IA0 0x01
00201
00202 #define CNTRL1_WDTOUT 0x80
00203 #define CNTRL1_INT_G2 0x40
00204 #define CNTRL1_INT_T0 0x10
00205 #define CNTRL1_INT_T2 0x20
00206 #define CNTRL1_NOT_SLAVE 0x08
00207 #define CNTRL1_IEN_G2 0x04
00208 #define CNTRL1_IEN_T0 0x01
00209 #define CNTRL1_IEN_T2 0x02
00210
00211 #define BRDTST_EOC 0x08
00212
00213
00214
00215
00216
00217
00218
00219
00220 #define INTR 13
00221 #define INT_MASK 0x20
00222 #define IC_ADD 0x20
00223
00224
00225
00226
00227 #define EOI_5 0x65
00228 #define IC_MASK 0x21
00229
00230 #define IRQSL 0x84
00231
00232
00233
00234
00235
00236
00237
00238 typedef enum { A_dir = 0x01, B_dir = 0x02, C_lo_dir = 0x04,
00239 C_hi_dir = 0x08, C_dir = 0x0c, D_lo_dir = 0x10,
00240 D_hiDir = 0x20, D_dir = 0x30 } eDir_typ;
00241 typedef enum { A_port, B_port, C_port, D_port } ePort_typ;
00242 typedef enum { HomeSwitchFORWARD, HomeSwitchREVERSE } eHomeDir_typ;
00243
00244 #define STG_PORT_A 0x01
00245 #define STG_PORT_B 0x02
00246 #define STG_PORT_C_LO 0x04
00247 #define STG_PORT_C_HI 0x08
00248 #define STG_PORT_C (STG_PORT_C_LO | STG_PORT_C_HI)
00249 #define STG_PORT_D_LO 0x10
00250 #define STG_PORT_D_HI 0x20
00251 #define STG_PORT_D (STG_PORT_D_LO | STG_PORT_D_HI)
00252 #define STG_PORT_INPUT 0
00253 #define STG_PORT_OUTPUT 1
00254
00255
00256 #define A_DIR_BIT 0x10
00257 #define B_DIR_BIT 0x02
00258 #define C_LOW_DIR_BIT 0x01
00259 #define C_HI_DIR_BIT 0x08
00260 #define D_DIR_BIT 0x10
00261 #define D_LOW_DIR_BIT 0x01
00262 #define D_HI_DIR_BIT 0x08
00263
00264
00265 #define _500_MICROSECONDS 500
00266 #define _1_MILLISECOND 1000
00267 #define _2_MILLISECONDS 2000
00268 #define _3_MILLISECONDS 3000
00269 #define _4_MILLISECONDS 4000
00270 #define _5_MILLISECONDS 5000
00271 #define _10_MILLISECONDS 10000
00272 #define _100_MILLISECONDS 100000L
00273 #define _1_SECOND 1000000L
00274 #define MAX_PERIOD -1L
00275
00276 #define NO_BOARD 1
00277 #define BOARD_PRESENT 0
00278
00279 #define MODEL_NO_ID 0
00280 #define MODEL1 1
00281 #define MODEL2 2
00282
00283 typedef union
00284 {
00285 unsigned long all;
00286 struct {unsigned char A, B, C, D;} port;
00287 } IO32;
00288
00289 typedef union
00290 {
00291 long Long;
00292 unsigned char Byte[4];
00293 } LONGBYTE;
00294
00295 typedef union
00296 {
00297 unsigned short Word;
00298 struct {unsigned char high, low;} Byte;
00299 } WORDBYTE;
00300
00301
00302
00303 typedef struct {
00304 unsigned short wBaseAddress;
00305 unsigned short wIrq;
00306 unsigned short wModel;
00307 unsigned short wNoBoardFlag;
00308 unsigned short wAxesInSys;
00309 unsigned short wSaveDirs;
00310 unsigned char byIndexPollAxis;
00311 unsigned char byIndexPulsePolarity;
00312 long lSimDac[MAX_AXIS];
00313 long lSimEnc[MAX_AXIS];
00314 unsigned char byEncHighByte[MAX_AXIS];
00315 unsigned char byOldByte2[MAX_AXIS];
00316 } STG_STRUCT;
00317
00318
00319 extern void ServoToGoConstructor(STG_STRUCT *stg, unsigned short wRequestedIrq);
00320 extern void ServoToGoDestructor(STG_STRUCT *stg);
00321 extern void Initialize(STG_STRUCT *stg, unsigned short wRequestedIrq);
00322 extern void SetIrq(STG_STRUCT *stg, unsigned short wRequestedIrq);
00323 extern unsigned short BaseFind(STG_STRUCT *stg);
00324 extern unsigned short BrdtstOK(STG_STRUCT *stg, unsigned short wBaseAddress);
00325 extern void SetDDir(STG_STRUCT *stg, unsigned short nSwDir);
00326 extern void MotSim(STG_STRUCT *stg);
00327
00328 extern void RawDAC(STG_STRUCT *stg, unsigned short nAxis, long lCounts);
00329 extern void StartADC(STG_STRUCT *stg, unsigned short wAxis);
00330 extern short SpinReadADC(STG_STRUCT *stg, unsigned short wAxis);
00331 extern long ReadADC(STG_STRUCT *stg, unsigned short wAxis, short * counts);
00332 extern void AutoZeroAdc(STG_STRUCT *stg);
00333 extern void DontAutoZeroAdc(STG_STRUCT *stg);
00334 extern void CalADC(STG_STRUCT *stg);
00335 extern void EncoderInit(STG_STRUCT *stg);
00336 extern void EncoderLatch(STG_STRUCT *stg);
00337 extern void EncoderResetAddr(STG_STRUCT *stg);
00338 extern void SetEncoderCounts(STG_STRUCT *stg, unsigned short nAxis, long lCounts);
00339 extern void SelectIndexAxis(STG_STRUCT *stg, unsigned char byAxis, unsigned char byPol);
00340 extern void SelectIndexOrExtLatch(STG_STRUCT *stg, unsigned char bySelectBits);
00341 extern void EnableCounterLatchOnIndexOrExt(STG_STRUCT *stg, unsigned char bySelectBits);
00342 extern short IndexPulse(STG_STRUCT *stg);
00343 extern unsigned short IndexPulseLatch(STG_STRUCT *stg);
00344 extern void ResetIndexLatches(STG_STRUCT *stg, unsigned char byLatchBits);
00345 extern unsigned char CurrentIRR(STG_STRUCT *stg);
00346 extern void ResetIndexLatch(STG_STRUCT *stg);
00347 extern unsigned char GetIndexLatches(STG_STRUCT *stg);
00348 extern unsigned char GetSELDI(STG_STRUCT *stg);
00349 extern unsigned char GetIDLEN(STG_STRUCT *stg);
00350 extern unsigned char GetCNTRL0(STG_STRUCT *stg);
00351 extern unsigned char GetCNTRL1(STG_STRUCT *stg);
00352 extern unsigned char GetBRDTST(STG_STRUCT *stg);
00353 extern void ResetWatchdogLatch(STG_STRUCT *stg);
00354 extern void EncReadAll(STG_STRUCT *stg, LONGBYTE *lbEnc);
00355 extern unsigned long RawDI(STG_STRUCT *stg);
00356 extern void RawDO(STG_STRUCT *stg, unsigned long lOutBits);
00357 extern void RawDOPort(STG_STRUCT *stg, unsigned char byBitNumber, unsigned char bySet0or1, unsigned short nPort);
00358 extern void DioDirection(STG_STRUCT *stg, const unsigned short nSwDir);
00359 extern void StopTimer(STG_STRUCT *stg);
00360 extern void StartInterrupts(STG_STRUCT *stg);
00361 extern void IrqReset(STG_STRUCT *stg);
00362 extern void SelectInterruptPeriod(STG_STRUCT *stg, long lPeriodSelect);
00363 extern void StopInterrupts(STG_STRUCT *stg);
00364 extern unsigned short GetBoardPresence(STG_STRUCT *stg);
00365 extern unsigned short GetAxes(STG_STRUCT *stg);
00366 extern unsigned short GetIrq(STG_STRUCT *stg);
00367 extern unsigned short GetAddr(STG_STRUCT *stg);
00368 extern unsigned short GetModel(STG_STRUCT *stg);
00369 extern void Timer2Delay(STG_STRUCT *stg, unsigned short counts);
00370 extern void StartTimer2TerminalCount(STG_STRUCT *stg, unsigned short count);
00371 extern void StartTimer2RTI(STG_STRUCT *stg, unsigned short count);
00372 extern unsigned short ReadTimer2TerminalCount(STG_STRUCT *stg);
00373 extern short PollTimer2(STG_STRUCT *stg);
00374 extern void MaskTimer2Interrupt(STG_STRUCT *stg);
00375 extern void UnMaskTimer2Interrupt(STG_STRUCT *stg);
00376 extern int AddressInRange(STG_STRUCT *stg, long);
00377
00378 #endif