#include <stdio.h>
#include "newstg.h"
#include "extintf.h"
#include "stgdefs.h"
#include "locsysio.h"
Include dependency graph for newstg.c:
Go to the source code of this file.
Defines | |
#define | __attribute__(x) |
#define | MAX_AXES 8 |
#define | STG_INIT_WAIT 1000 |
#define | STG_ADC_WAIT_USEC 20 |
#define | HOME_0 0x00000001 |
#define | MIN_LIM_0 0x00000002 |
#define | MAX_LIM_0 0x00000004 |
#define | FAULT_0 0x00000008 |
#define | HOME_1 0x00000010 |
#define | MIN_LIM_1 0x00000020 |
#define | MAX_LIM_1 0x00000040 |
#define | FAULT_1 0x00000080 |
#define | HOME_2 0x00000100 |
#define | MIN_LIM_2 0x00000200 |
#define | MAX_LIM_2 0x00000400 |
#define | FAULT_2 0x00000800 |
#define | HOME_3 0x00001000 |
#define | MIN_LIM_3 0x00002000 |
#define | MAX_LIM_3 0x00004000 |
#define | FAULT_3 0x00008000 |
Functions | |
char | __attribute__ ((unused)) ident[]="$Id |
int | stgMotQuit (void) |
int | stgAdcNum (void) |
int | stgAdcStart (int adc) |
void | stgAdcWait (void) |
int | stgAdcRead (int adc, double *volts) |
int | stgDacNum (void) |
int | stgDacWrite (int dac, double volts) |
int | stgDacWriteAll (int max, double *volts) |
unsigned int | stgEncoderIndexModel (void) |
int | stgEncoderSetIndexModel (unsigned int model) |
int | stgEncoderNum (void) |
int | stgEncoderRead (int encoder, double *counts) |
int | stgEncoderReadAll (int max, double *counts) |
int | stgEncoderResetIndex (int encoder) |
int | stgEncoderReadLatch (int encoder, int *flag) |
int | stgEncoderReadLevel (int encoder, int *flag) |
int | stgMaxLimitSwitchRead (int axis, int *flag) |
int | stgMinLimitSwitchRead (int axis, int *flag) |
int | stgHomeSwitchRead (int axis, int *flag) |
int | stgAmpEnable (int axis, int enable) |
int | stgAmpFault (int axis, int *flag) |
int | stgDioInit (const char *stuff) |
int | stgDioQuit (void) |
int | stgDioMaxInputs (void) |
int | stgDioMaxOutputs (void) |
int | stgDioRead (int index, int *value) |
int | stgDioWrite (int index, int value) |
int | stgDioCheck (int index, int *value) |
int | stgDioByteRead (int index, unsigned char *byte) |
int | stgDioShortRead (int index, unsigned short *sh) |
int | stgDioWordRead (int index, unsigned int *word) |
int | stgDioByteWrite (int index, unsigned char byte) |
int | stgDioShortWrite (int index, unsigned short sh) |
int | stgDioWordWrite (int index, unsigned int word) |
int | stgDioByteCheck (int index, unsigned char *byte) |
int | stgDioShortCheck (int index, unsigned short *sh) |
int | stgDioWordCheck (int index, unsigned int *word) |
int | stgAioInit (const char *stuff) |
int | stgAioQuit (void) |
int | stgAioMaxInputs (void) |
int | stgAioMaxOutputs (void) |
int | stgAioStart (int index) |
void | stgAioWait (void) |
int | stgAioRead (int index, double *volts) |
int | stgAioWrite (int index, double volts) |
int | stgAioCheck (int index, double *volts) |
int | stgModel () |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 25 of file newstg.c. 00025 : newstg.c,v 1.6 2001/10/31 20:21:47 wshackle Exp $"; 00026 00027 00028 #if !defined(rtlinux) && !defined(rtai) 00029 #include <stdio.h> 00030 #endif 00031 00032 #include "newstg.h" /* these decls */ 00033 #include "extintf.h" /* EXT_ENCODER_INDEX_MODEL */ 00034 00035 /* base address-- override default at compile time in stg.h, 00036 or at module load time with STG_BASE_ADDRESS=value */ 00037 unsigned short STG_BASE_ADDRESS = DEFAULT_STG_BASE_ADDRESS; 00038 int FIND_STG_BASE_ADDRESS=1; 00039 00040 int STG_IRQ=DEFAULT_STG_IRQ; 00041 00042 #define MAX_AXES 8 00043 00044 #include "stgdefs.h" 00045 00046 /* Implementations of external functions */ 00047 00048 #include "locsysio.h" 00049 00050 /* saved outputs, for stgAioCheck(), since we can't really read outputs */ 00051 static double checkedOutputs[MAX_AXES]; 00052 00053 #define STG_INIT_WAIT 1000 /* usecs to wait after stgMotInit() */ 00054 int stgMotInit(const char * stuff) 00055 { 00056 int t; 00057 00058 /* call STG init, which is the "constructor" */ 00059 ServoToGoConstructor(STG_IRQ); 00060 StopInterrupts(); /* we don't want interrupts */ 00061 00062 /* output 0's to amps */ 00063 for (t = 0; t < GetAxes(); t++) 00064 { 00065 /* write 0 to DACs */ 00066 stgDacWrite(t, 0.0); 00067 } 00068 00069 /* init digital IO directions */ 00070 stgDioInit(0); 00071 00072 /* need to force a wait here-- calls to stgEncoderReadAll() 00073 immediately after this return garbage. Is there status to 00074 poll on for 'ready'? */ 00075 for (t = 0; t < STG_INIT_WAIT; t++) 00076 { 00077 /* do a dummy 1 usec write */ 00078 outb(0x80, 0); 00079 } 00080 00081 return 0; 00082 } |
|
Definition at line 99 of file newstg.c. 00100 { 00101 return GetAxes(); 00102 } |
|
Definition at line 127 of file newstg.c. 00128 { 00129 if (adc < 0 || 00130 adc >= GetAxes()) { 00131 return 0; /* don't care */ 00132 } 00133 00134 *volts = (double) SpinReadADC((unsigned short) adc); 00135 00136 return 0; 00137 } |
|
|
|
Definition at line 118 of file newstg.c. Referenced by main(), and stgAioWait().
00119 { 00120 int t; 00121 00122 for (t = 0; t < STG_ADC_WAIT_USEC; t++) { 00123 outb(0x80, 0); /* 0x80 is historical dummy, 1 usec write */ 00124 } 00125 } |
|
Definition at line 925 of file newstg.c. 00926 { 00927 if (index < 0 || index >= GetAxes()) { 00928 *volts = 0.0; 00929 return 0; 00930 } 00931 00932 /* can't read outputs directly, so return stored value */ 00933 *volts = checkedOutputs[index]; 00934 00935 return 0; 00936 } |
|
Definition at line 884 of file newstg.c. 00885 { 00886 /* nothing need be done */ 00887 return 0; 00888 } |
|
Definition at line 895 of file newstg.c. Referenced by extAioMaxInputs().
00896 { 00897 return 8; /* make sure you have this option */ 00898 } |
|
Definition at line 900 of file newstg.c. Referenced by extAioMaxOutputs().
00901 { 00902 return GetAxes(); 00903 } |
|
Definition at line 890 of file newstg.c. Referenced by extAioQuit(), and main().
00891 { 00892 return 0; 00893 } |
|
Definition at line 915 of file newstg.c. 00916 { 00917 return stgAdcRead(index, volts); 00918 } |
|
Definition at line 905 of file newstg.c. 00906 { 00907 return stgAdcStart(index); 00908 } |
|
Definition at line 910 of file newstg.c. Referenced by extAioWait().
00911 { 00912 stgAdcWait(); 00913 } |
|
Definition at line 920 of file newstg.c. 00921 { 00922 return stgDacWrite(index, volts); 00923 } |
|
Definition at line 531 of file newstg.c. 00532 { 00533 if (axis < 0 || axis >= GetAxes()) 00534 { 00535 return 0; 00536 } 00537 00538 RawDOBitValPort( axis, (unsigned char) enable, 2); /* 2 is port C */ 00539 00540 return 0; 00541 } |
|
Definition at line 544 of file newstg.c. 00545 { 00546 long bits; 00547 int retval = 0; 00548 00549 bits = RawDIAll(); 00550 *flag = 0; 00551 00552 switch (axis) 00553 { 00554 case 0: 00555 if (bits & FAULT_0) 00556 { 00557 *flag = 1; 00558 } 00559 break; 00560 00561 case 1: 00562 if (bits & FAULT_1) 00563 { 00564 *flag = 1; 00565 } 00566 break; 00567 00568 case 2: 00569 if (bits & FAULT_2) 00570 { 00571 *flag = 1; 00572 } 00573 break; 00574 00575 case 3: 00576 if (bits & FAULT_3) 00577 { 00578 *flag = 1; 00579 } 00580 break; 00581 00582 #ifdef STG_8_AXES 00583 case 4: 00584 if (bits & FAULT_4) 00585 { 00586 *flag = 1; 00587 } 00588 break; 00589 00590 case 5: 00591 if (bits & FAULT_5) 00592 { 00593 *flag = 1; 00594 } 00595 break; 00596 00597 #endif 00598 00599 default: 00600 retval = -1; 00601 break; 00602 } 00603 00604 return retval; 00605 } |
|
Definition at line 139 of file newstg.c. Referenced by extDacNum().
00140 { 00141 return GetAxes(); 00142 } |
|
Definition at line 144 of file newstg.c. 00145 { 00146 long lCounts; 00147 00148 if (dac < 0 || 00149 dac >= GetAxes()) 00150 { 00151 return 0; /* don't care */ 00152 } 00153 00154 checkedOutputs[dac] = volts; 00155 00156 // WPS -- Hack: This made little sense to be but this hack seems necessary. 00157 lCounts = (long) (( volts * 0x1FFF) / 20.0); 00158 00159 RawDAC( dac, lCounts); 00160 00161 return 0; 00162 } |
|
Definition at line 164 of file newstg.c. 00165 { 00166 int t; 00167 int smax; 00168 00169 /* clip smax to max supported-- if they want more, ignore */ 00170 if (max > GetAxes()) { 00171 smax = GetAxes(); 00172 } 00173 else { 00174 smax = max; 00175 } 00176 00177 for (t = 0; t < smax; t++) { 00178 if (0 != stgDacWrite(t, volts[t])){ 00179 return -1; 00180 } 00181 } 00182 00183 return 0; 00184 } |
|
Definition at line 853 of file newstg.c. 00854 { 00855 if(byte ==0) 00856 { 00857 return -1; 00858 } 00859 00860 if (index == 0) 00861 { 00862 *byte = RawDIPort(2); 00863 return 0; 00864 } 00865 00866 *byte = 0; 00867 return -1; 00868 } |
|
Definition at line 776 of file newstg.c. 00777 { 00778 if(byte ==0) 00779 { 00780 return -1; 00781 } 00782 *byte = RawDIPort(index); 00783 return 0; 00784 } |
|
Definition at line 829 of file newstg.c. 00830 { 00831 if(index == 0) 00832 { 00833 RawDOBytePort(byte,2); 00834 return 0; 00835 } 00836 00837 return -1; 00838 } |
|
Definition at line 762 of file newstg.c. 00763 { 00764 long port = 2; 00765 long bit_number = index%8; 00766 00767 if(0 == value) 00768 { 00769 return -1; 00770 } 00771 *value = RawDIBitPort(bit_number, port); 00772 return 0; 00773 } |
|
Definition at line 712 of file newstg.c. 00713 { 00714 /* set digital IO bits for A,B input, C output */ 00715 DioDirection2( 0x0C); 00716 00717 return 0; 00718 } |
|
Definition at line 725 of file newstg.c. Referenced by extDioMaxInputs().
00726 { 00727 return 24; 00728 } |
|
Definition at line 730 of file newstg.c. Referenced by extDioMaxOutputs().
00731 { 00732 return 24; 00733 } |
|
Definition at line 720 of file newstg.c. Referenced by extDioQuit(), and main().
00721 { 00722 return 0; 00723 } |
|
Definition at line 735 of file newstg.c. 00736 { 00737 long port = index/8; 00738 long bit_number = index%8; 00739 00740 if(0 == value) 00741 { 00742 return -1; 00743 } 00744 *value = RawDIBitPort(bit_number, port); 00745 00746 return 0; 00747 } |
|
Definition at line 871 of file newstg.c. 00872 { 00873 *sh = 0; 00874 return -1; 00875 } |
|
Definition at line 787 of file newstg.c. 00788 { 00789 unsigned char lo, hi; 00790 00791 if (index == 0) 00792 { 00793 lo = RawDIPort(0); 00794 hi = RawDIPort(1); 00795 00796 *sh = (hi << 8) + lo; 00797 return 0; 00798 } 00799 00800 if (index == 1) 00801 { 00802 lo = RawDIPort(1); 00803 00804 *sh = lo; 00805 return 0; 00806 } 00807 00808 *sh = 0; 00809 return -1; 00810 } |
|
Definition at line 841 of file newstg.c. 00842 { 00843 return -1; 00844 } |
|
Definition at line 878 of file newstg.c. 00879 { 00880 *word = 0; 00881 return -1; 00882 } |
|
|
|
Definition at line 847 of file newstg.c. 00848 { 00849 return -1; 00850 } |
|
Definition at line 750 of file newstg.c. 00751 { 00752 00753 long port = index/8; 00754 long bit_number = index%8; 00755 00756 00757 RawDOBitValPort(port,(value != 0),bit_number); 00758 return 0; 00759 } |
|
Definition at line 186 of file newstg.c. 00187 { 00188 return EXT_ENCODER_INDEX_MODEL_MANUAL; 00189 } |
|
Definition at line 201 of file newstg.c. Referenced by extEncoderNum().
00202 { 00203 return GetAxes(); 00204 } |
|
|
|
Definition at line 223 of file newstg.c. 00224 { 00225 LONGBYTE lbEnc[MAX_AXES]; 00226 int t; 00227 int smax; /* how many we actually have */ 00228 00229 /* clip smax to max supported-- if they want more, give 00230 them zeros */ 00231 if (max > GetAxes()) { 00232 smax = GetAxes(); 00233 } 00234 else { 00235 smax = max; 00236 } 00237 00238 EncoderLatch(); 00239 EncReadAll( lbEnc); 00240 00241 /* fill ours with the actual values */ 00242 for (t = 0; t < smax; t++) { 00243 counts[t] = (double) lbEnc[t].Long; 00244 } 00245 /* and fill the rest with zeros */ 00246 for (t = smax; t < max; t++) { 00247 counts[t] = 0.0; 00248 } 00249 00250 return 0; 00251 } |
|
Definition at line 277 of file newstg.c. 00278 { 00279 00280 if(GetModel() == MODEL1) 00281 { 00282 SelectIndexAxis(encoder); 00283 *flag = IndexPulseLatch(); 00284 } 00285 else 00286 { 00287 *flag = GetIndexLatches(); 00288 *flag = ((*flag & (1 << encoder)) != 0); 00289 } 00290 00291 return 0; 00292 } |
|
Definition at line 295 of file newstg.c. 00296 { 00297 SelectIndexAxis(encoder); 00298 *flag = IndexPulse(); 00299 00300 return 0; 00301 } |
|
Definition at line 253 of file newstg.c. 00254 { 00255 unsigned char latch_mask; 00256 if (encoder < 0 || 00257 encoder >= GetAxes()) 00258 { 00259 return 0; 00260 } 00261 00262 00263 if(GetModel() == MODEL1) 00264 { 00265 SelectIndexAxis( encoder); 00266 ResetIndexLatch(); 00267 } 00268 else 00269 { 00270 latch_mask = 0xFF & ~(1 << encoder); 00271 ResetIndexLatches(0); 00272 } 00273 00274 return 0; 00275 } |
|
Definition at line 191 of file newstg.c. 00192 { 00193 if (model != EXT_ENCODER_INDEX_MODEL_MANUAL) 00194 { 00195 return -1; 00196 } 00197 00198 return 0; 00199 } |
|
Definition at line 467 of file newstg.c. 00468 { 00469 long bits; 00470 int retval = 0; 00471 00472 bits = RawDIAll(); 00473 *flag = 0; 00474 00475 switch (axis) 00476 { 00477 case 0: 00478 if (bits & HOME_0) 00479 { 00480 *flag = 1; 00481 } 00482 break; 00483 00484 case 1: 00485 if (bits & HOME_1) 00486 { 00487 *flag = 1; 00488 } 00489 break; 00490 00491 case 2: 00492 if (bits & HOME_2) 00493 { 00494 *flag = 1; 00495 } 00496 break; 00497 00498 case 3: 00499 if (bits & HOME_3) 00500 { 00501 *flag = 1; 00502 } 00503 break; 00504 00505 #ifdef STG_8_AXES 00506 case 4: 00507 if (bits & HOME_4) 00508 { 00509 *flag = 1; 00510 } 00511 break; 00512 00513 case 5: 00514 if (bits & HOME_5) 00515 { 00516 *flag = 1; 00517 } 00518 break; 00519 00520 #endif 00521 00522 default: 00523 retval = -1; 00524 break; 00525 } 00526 00527 return retval; 00528 } |
|
Definition at line 339 of file newstg.c. 00340 { 00341 long bits; 00342 int retval = 0; 00343 00344 bits = RawDIAll(); 00345 *flag = 0; 00346 00347 switch (axis) 00348 { 00349 case 0: 00350 if (bits & MAX_LIM_0) 00351 { 00352 *flag = 1; 00353 } 00354 break; 00355 00356 case 1: 00357 if (bits & MAX_LIM_1) 00358 { 00359 *flag = 1; 00360 } 00361 break; 00362 00363 case 2: 00364 if (bits & MAX_LIM_2) 00365 { 00366 *flag = 1; 00367 } 00368 break; 00369 00370 case 3: 00371 if (bits & MAX_LIM_3) 00372 { 00373 *flag = 1; 00374 } 00375 break; 00376 00377 #ifdef STG_8_AXES 00378 case 4: 00379 if (bits & MAX_LIM_4) 00380 { 00381 *flag = 1; 00382 } 00383 break; 00384 00385 case 5: 00386 if (bits & MAX_LIM_5) 00387 { 00388 *flag = 1; 00389 } 00390 break; 00391 00392 #endif 00393 00394 default: 00395 retval = -1; 00396 break; 00397 } 00398 00399 return retval; 00400 } |
|
Definition at line 403 of file newstg.c. 00404 { 00405 long bits; 00406 int retval = 0; 00407 00408 bits = RawDIAll(); 00409 *flag = 0; 00410 00411 switch (axis) 00412 { 00413 case 0: 00414 if (bits & MIN_LIM_0) 00415 { 00416 *flag = 1; 00417 } 00418 break; 00419 00420 case 1: 00421 if (bits & MIN_LIM_1) 00422 { 00423 *flag = 1; 00424 } 00425 break; 00426 00427 case 2: 00428 if (bits & MIN_LIM_2) 00429 { 00430 *flag = 1; 00431 } 00432 break; 00433 00434 case 3: 00435 if (bits & MIN_LIM_3) 00436 { 00437 *flag = 1; 00438 } 00439 break; 00440 00441 #ifdef STG_8_AXES 00442 case 4: 00443 if (bits & MIN_LIM_4) 00444 { 00445 *flag = 1; 00446 } 00447 break; 00448 00449 case 5: 00450 if (bits & MIN_LIM_5) 00451 { 00452 *flag = 1; 00453 } 00454 break; 00455 00456 #endif 00457 00458 default: 00459 retval = -1; 00460 break; 00461 } 00462 00463 return retval; 00464 } |
|
Definition at line 938 of file newstg.c. Referenced by main().
00939 { 00940 return GetModel(); 00941 } |
|
Definition at line 84 of file newstg.c. Referenced by extMotQuit(), and main().
00085 { 00086 int t; 00087 00088 for (t = 0; t < GetAxes(); t++) 00089 { 00090 /* write 0's to DACs */ 00091 stgDacWrite(t, 0.0); 00092 } 00093 00094 ServoToGoDestructor(); 00095 00096 return 0; 00097 } |