fdhwlib
2.0.25
|
00001 /*************************************************************************** 00002 00003 Pbus.h - description 00004 00005 begin : Thu Jun 29 2000 00006 copyright : (C) 2000 by Andreas Kopmann 00007 email : kopmann@hpe.fzk.de 00008 ***************************************************************************/ 00009 00010 00011 #if defined (_MSC_VER) && (_MSC_VER >= 1000) 00012 #pragma once 00013 #endif 00014 #ifndef _INC_PBUS_3911814503CA_INCLUDED 00015 #define _INC_PBUS_3911814503CA_INCLUDED 00016 00017 00018 #define PBUS_VER 110 00019 #define PBUS_VERSION "1.10" 00020 //#define PBUS_VCLASS 00021 00022 //-----programm switches----- 00023 // choose only one of these modes 00024 //#define PBUS_SIM // enable a protocol of the rw access, do nothing 00025 //#define PBUS_TEST // test of process synchronization and mEnable 00026 //#define PBUS_DIRECT // direct hw access 00027 //#define PBUS_IP // access to the hw via ip connection 00028 00029 #define PBUS_MODE_SIM 0 00030 #define PBUS_MODE_TEST 1 00031 #define PBUS_MODE_DIRECT 2 00032 #define PBUS_MODE_IP 3 00033 #define PBUS_MODE_DMA 4 00034 #define PBUS_MODE_FAST 5 00035 #define PBUS_MODE_1394 6 00036 #define PBUS_MODE_DYN 7 00037 #define PBUS_MODE_PCI 8 00038 #define PBUS_MODE_PCIDMA 9 00039 #define PBUS_MODE_TEMPLATE 99 00040 00041 // For compatibility reasons 00042 #define SIM PBUS_MODE_SIM 00043 #define TEST PBUS_MODE_TEST 00044 #define DIRECT PBUS_MODE_DIRECT 00045 #define IP PBUS_MODE_IP 00046 #define DMA PBUS_MODE_DMA 00047 #define FAST PBUS_MODE_FAST 00048 00049 00050 // Select the appropriate mode in the project file 00051 // don't change the header file. This will cause recompilation 00052 // of nearly all files!!! 00053 // Linux: 00054 //#define PBUS_MODE SIM 00055 //#define PBUS_MODE TEST 00056 //#define PBUS_MODE IP 00057 //#define PBUS_MODE DIRECT 00058 00059 // default value 00060 #ifndef PBUS_MODE 00061 #define PBUS_MODE PBUS_MODE_SIM 00062 #endif 00063 00064 #if defined PBUS_MODE && (PBUS_MODE == PBUS_MODE_SIM) 00065 #define PBUS_SIM 00066 #endif 00067 00068 00069 #if defined PBUS_MODE && (PBUS_MODE == PBUS_MODE_TEST) 00070 #define PBUS_DIRECT 00071 #define PBUS_TEST 00072 #endif 00073 00074 #if defined PBUS_MODE && (PBUS_MODE == PBUS_MODE_DIRECT) 00075 #define PBUS_DIRECT 00076 #endif 00077 00078 #if defined PBUS_MODE && (PBUS_MODE == PBUS_MODE_IP) 00079 #define PBUS_IP 00080 #endif 00081 00082 #if defined PBUS_MODE && (PBUS_MODE == PBUS_MODE_1394) 00083 #define PBUS_1394 00084 #endif 00085 00086 #if defined PBUS_MODE && (PBUS_MODE == PBUS_MODE_DYN) 00087 #define PBUS_DYN 00088 #endif 00089 00090 #if defined PBUS_MODE && (PBUS_MODE == PBUS_MODE_PCI) 00091 #define PBUS_PCI 00092 #endif 00093 00094 #if defined PBUS_MODE && (PBUS_MODE == PBUS_MODE_PCIDMA) 00095 #define PBUS_PCIDMA 00096 #endif 00097 00098 #if defined PBUS_MODE && (PBUS_MODE == PBUS_MODE_TEMPLATE) 00099 #define PBUS_TEMPLATE 00100 #endif 00101 00102 00103 //#define PBUS_FAST // use the increment mode in readBlock 00104 // To use this function an apropriate flt 00105 // design is required! 00106 00107 //#undef PBUS_STATE // report pbus states 00108 //#define PBUS_STATE 00109 00110 #ifdef __GNUC__ 00111 //#if defined __GNUC__ && (PBUS_MODE != PBUS_MODE_1394) 00112 // Also the fire wire interface will need the semaphores 00113 // Otherwise we can't keep control of bitwise manipulation 00114 // of regiserts!!! 00115 #ifdef __linux__ 00116 #define PBUS_DLL_EXT "so" 00117 #define USE_SEMAPHORE // remove this for no semas 00118 #endif 00119 #ifdef __APPLE__ 00120 #define PBUS_DLL_EXT "dynlib" 00121 #define USE_SEMAPHORE 00122 #endif 00123 #endif 00124 00125 00126 #ifdef PBUS_SIM 00127 #define PBUS_MODE_TXT "Simulation Mode" 00128 #define PBUS_LIB "Sim" 00129 //#define USE_EXT_SIM 00130 #undef USE_ME 00131 #ifdef __GNUC__ 00132 #define USE_SHM 00133 // #undef USE_SEMAPHORE 00134 #else // Windows 00135 #undef USE_SEMAPHORE 00136 #endif 00137 #endif 00138 00139 00140 #ifdef PBUS_DIRECT 00141 #ifdef __linux__ 00142 #define LINUX // the microEnable lib need this 00143 #endif 00144 00145 #ifdef PBUS_TEST 00146 #define PBUS_MODE_TXT "MicroEnable Test Mode (without FD hardware)" 00147 #define PBUS_LIB "Test" 00148 #define USE_EXT_SIM 00149 #else 00150 #ifdef PBUS_DMA 00151 #define PBUS_MODE_TXT "Direct connection via microEnable" 00152 #define PBUS_LIB "DMA" 00153 #else 00154 #ifdef PBUS_FAST 00155 #define PBUS_MODE_TXT "Direct connection via microEnable" 00156 #define PBUS_LIB "Fast" 00157 #else 00158 #define PBUS_MODE_TXT "Direct connection via microEnable" 00159 #define PBUS_LIB "Direct" 00160 #endif 00161 #endif 00162 #endif 00163 #define USE_ME 00164 #endif 00165 00166 #ifdef PBUS_IP 00167 #define PBUS_MODE_TXT "IP connection" 00168 #define PBUS_LIB "Proxy" 00169 //#undef USE_SEMAPHORE 00170 #ifdef __GNUC__ 00171 //#define USE_SEMAPHORE // needed to blPbus::initPbusock parent and child process, if both 00172 // use the same socket connection!? 00173 #undef USE_SEMAPHORE 00174 #endif 00175 00176 #ifdef WIN32 // Windows Proxy Implementation flags 00177 // The windows socket implementation needs synchronization 00178 // to be thread safe !!! 00179 00180 #define USE_MFC_LOCAL_SYNC // the class semaphores does not work?! 00181 #endif 00182 00183 #undef USE_ME 00184 #endif // end of PBUS_IP 00185 00186 00187 #ifdef PBUS_1394 00188 #define PBUS_MODE_TXT "Direct connection via IEEE1394" 00189 #define PBUS_LIB "1394" 00190 #endif 00191 00192 #ifdef PBUS_DYN 00193 #define PBUS_MODE_TXT "Dynamic loading of the Pbus library" 00194 #define PBUS_LIB "Dyn" 00195 #endif 00196 00197 #ifdef PBUS_PCI 00198 #define PBUS_MODE_TXT "Direct connection via SLT-PCI interface" 00199 #define PBUS_LIB "PCI" 00200 #endif 00201 00202 #ifdef PBUS_PCIDMA 00203 #define PBUS_MODE_TXT "Direct connection via SLT-PCI interface, DMA enabled" 00204 #define PBUS_LIB "PCIDMA" 00205 #endif 00206 00207 #ifdef PBUS_TEMPLATE 00208 #define PBUS_MODE_TXT "Template for other Pbus libraries" 00209 #define PBUS_LIB "Template" 00210 #endif 00211 00212 // Test switches 00213 //#define USE_SEMAPHORE 00214 //#define USE_MFC_LOCAL_SYNC 00215 00216 //#define EXCEPTIONS 00217 00218 00219 00220 //----------includes------------ 00221 #ifdef USE_MFC_LOCAL_SYNC 00222 #include <afxmt.h> 00223 class CMutex; 00224 #endif 00225 00226 00227 #include <cstdio> 00228 #include <ctime> 00229 00230 #include <iostream> 00231 #include <string> 00232 #include <stdexcept> 00233 00234 #if HAVE_STDINT_H 00235 #include <stdint.h> 00236 #else 00237 //almost all systems have this; if not, define int32_t and uint32_t -tb- 00238 #endif 00239 00240 #include <akutil/akinifile.h> 00241 #include <akutil/procDuration.h> 00242 00243 #ifdef PBUS_IP 00244 #include <akutil/simplesocket.h> 00245 //#define PBUS_IP_BLOCK 250 // long words, 00246 // optimized for FLT_PAGE_SIZE = 1000 00247 // means two calls per block !? 00248 #endif 00249 00250 #ifdef USE_ME 00251 #include <menable.h> 00252 #endif 00253 00254 //#ifdef PBUS_1394 00255 //#include <libraw1394/raw1394.h> 00256 //#include <libraw1394/csr.h> 00257 // 00258 //#define PBUS1394_MAXPORTS 16 00259 //#endif 00260 00261 #ifdef PBUS_DYN 00262 #include <dlfcn.h> 00263 #endif 00264 00265 #include <Pbus/MicroEnableError.h> 00266 #include <Pbus/PbusError.h> 00267 00268 00269 #ifdef PBUS_VCLASS 00270 class MicroEnableVersion; 00271 class PbusVersion; 00272 #endif 00273 00274 class PbusImp; 00275 00484 class Pbus 00485 { 00486 public: 00487 00488 00489 00490 00510 static int init(const char * inifile = "FE.ini", int host = 0); 00511 00522 static int free(int host = 0); 00523 00524 00526 int reset(); 00527 00530 unsigned long getState(); 00531 00535 unsigned long getState(unsigned long addr); 00536 00541 int get(std::string item, std::string *value); 00542 00544 int set(std::string item, std::string value); 00545 00546 00550 unsigned long read(unsigned long addr); 00551 00554 void write(unsigned long addr, unsigned long data); 00555 00569 int readBlock(unsigned long addr, unsigned long * data, 00570 unsigned long n, unsigned long incr=1); 00571 00572 00573 00579 void writeBlock(unsigned long addr, unsigned long * data, 00580 unsigned long n, unsigned long incr=1); 00581 00582 00583 00587 void clearBlock(unsigned long addr, unsigned long data, 00588 unsigned long n, unsigned long incr=1); 00589 00591 void readRegisterBlock(unsigned long addr, unsigned long *data, 00592 unsigned long nPix, unsigned long incrPix, 00593 unsigned long nSlots=0, unsigned long incrSlots=0); 00594 00595 00606 void writeBits(unsigned long addr, unsigned long data, unsigned long mask, 00607 int shift); 00608 00609 00611 void setBitsToHigh(unsigned long addr, unsigned long mask); 00612 00614 void setBitsToLow(unsigned long addr, unsigned long mask); 00615 00616 00618 int waitForIR(int timeout = 0); 00619 00623 int checkIR(); 00624 00626 unsigned long getIRvector(); 00627 00636 int getIRorigin(unsigned long irvector); 00637 00638 00639 00651 void stop(); 00652 00654 void cont(); 00655 00656 00657 #ifdef PBUS_VCLASS 00658 void displayVersion(FILE *fout); 00659 #endif 00660 00661 const char * getVersion(); 00662 00663 const char * getMode(); 00664 00677 int getModeId(); 00678 00679 00680 #ifdef PBUS_VCLASS 00681 PbusVersion * getPbusVersion(); 00682 #endif 00683 00688 static int sltVersion; 00689 00695 static int fltVersion; 00696 00699 static void selectTelescope(int id); 00700 00703 static int getTelescope(); 00704 00708 static int getNTelescopes(); 00709 00710 00712 static bool isAvailable(); 00713 00721 static bool isConnected(int id=0); 00722 00723 00727 unsigned long simReadIRvector(); 00728 00734 void simWriteIRvector(unsigned long vector); 00735 00736 00737 static void setDebugLevel(int level); 00738 00739 public: // Members 00740 00743 static void debugMsg(const char *msg, ...); 00744 00745 private: 00746 00748 static bool pImpAvailable; 00749 00752 static bool pImpConnected; 00753 00754 00755 #ifdef PBUS_VCLASS 00756 static PbusVersion * pver; 00757 #endif 00758 00759 00760 #ifdef PBUS_DYN 00761 00762 static void *dllHandle; 00763 00765 //static Pbus *pPbusDll; 00766 #endif 00767 00768 00769 //protected: 00770 public: 00772 static PbusImp *pImp; 00773 00774 }; 00775 00776 00777 #endif /* _INC_PBUS_3911814503CA_INCLUDED */ 00778