00001 /********************************************************************* 00002 00003 Name: mvmestd.h 00004 Created by: Stefan Ritt 00005 00006 Cotents: Midas VME standard routines (MVMESTD) supplying an 00007 abstract layer to all supported VME interfaces. 00008 00009 $Id: mvmestd.h 2753 2005-10-07 14:55:31Z ritt $ 00010 00011 *********************************************************************/ 00012 00013 /**dox***************************************************************/ 00014 /** @file mvmestd.h 00015 The Midas VME include file 00016 */ 00017 00018 /** @defgroup mvmestdinclude Midas VME standard 00019 */ 00020 /** @defgroup mvmestdfunctionh VME Functions (mvme_xxx) 00021 */ 00022 00023 /**dox***************************************************************/ 00024 /** @addtogroup mvmestdinclude 00025 * 00026 * @{ */ 00027 00028 /**dox***************************************************************/ 00029 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00030 00031 /*---- replacements if not running under MIDAS ---------------------*/ 00032 00033 #ifndef MIDAS_TYPE_DEFINED 00034 #define MIDAS_TYPE_DEFINED 00035 00036 typedef unsigned short int WORD; 00037 00038 #ifdef __alpha 00039 typedef unsigned int DWORD; 00040 #else 00041 typedef unsigned long int DWORD; 00042 #endif 00043 00044 #define SUCCESS 1 00045 00046 #endif /* MIDAS_TYPE_DEFINED */ 00047 00048 /* make functions under WinNT dll exportable */ 00049 #if defined(_MSC_VER) && defined(MIDAS_DLL) 00050 #define EXPRT __declspec(dllexport) 00051 #else 00052 #define EXPRT 00053 #endif 00054 00055 /**dox***************************************************************/ 00056 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 00057 00058 /*---- status codes ------------------------------------------------*/ 00059 00060 #define MVME_SUCCESS 1 00061 #define MVME_NO_INTERFACE 2 00062 #define MVME_NO_CRATE 3 00063 #define MVME_UNSUPPORTED 4 00064 #define MVME_INVALID_PARAM 5 00065 #define MVME_NO_MEM 6 00066 #define MVME_ACCESS_ERROR 7 00067 00068 /*---- types -------------------------------------------------------*/ 00069 00070 typedef unsigned long mvme_addr_t; 00071 typedef unsigned long mvme_size_t; 00072 00073 /*---- constants ---------------------------------------------------*/ 00074 00075 /** 00076 data modes 00077 */ 00078 #define MVME_DMODE_D8 1 /**< D8 */ 00079 #define MVME_DMODE_D16 2 /**< D16 */ 00080 #define MVME_DMODE_D32 3 /**< D32 */ 00081 #define MVME_DMODE_D64 4 /**< D64 */ 00082 #define MVME_DMODE_RAMD16 5 /**< RAM memory of VME adapter */ 00083 #define MVME_DMODE_RAMD32 6 /**< RAM memory of VME adapter */ 00084 #define MVME_DMODE_LM 7 /**< local memory mapped to VME */ 00085 00086 #define MVME_DMODE_DEFAULT MVME_DMODE_D32 00087 00088 /* block transfer modes */ 00089 00090 #define MVME_BLT_NONE 1 /**< normal programmed IO */ 00091 #define MVME_BLT_BLT32 2 /**< 32-bit block transfer */ 00092 #define MVME_BLT_MBLT64 3 /**< multiplexed 64-bit block transfer */ 00093 #define MVME_BLT_2EVME 4 /**< two edge block transfer */ 00094 #define MVME_BLT_2ESST 5 /**< two edge source synchrnous transfer */ 00095 #define MVME_BLT_BLT32FIFO 6 /**< FIFO mode, don't increment address */ 00096 #define MVME_BLT_MBLT64FIFO 7 /**< FIFO mode, don't increment address */ 00097 #define MVME_BLT_2EVMEFIFO 8 /**< two edge block transfer with FIFO mode */ 00098 00099 /* vme bus address modifiers */ 00100 00101 #define MVME_AM_A32_SB (0x0F) /**< A32 Extended Supervisory Block */ 00102 #define MVME_AM_A32_SP (0x0E) /**< A32 Extended Supervisory Program */ 00103 #define MVME_AM_A32_SD (0x0D) /**< A32 Extended Supervisory Data */ 00104 #define MVME_AM_A32_NB (0x0B) /**< A32 Extended Non-Privileged Block */ 00105 #define MVME_AM_A32_NP (0x0A) /**< A32 Extended Non-Privileged Program */ 00106 #define MVME_AM_A32_ND (0x09) /**< A32 Extended Non-Privileged Data */ 00107 #define MVME_AM_A32_SMBLT (0x0C) /**< A32 Multiplexed Block Transfer (D64) */ 00108 #define MVME_AM_A32_NMBLT (0x08) /**< A32 Multiplexed Block Transfer (D64) */ 00109 00110 #define MVME_AM_A32 MVME_AM_A32_SD 00111 #define MVME_AM_A32_D64 MVME_AM_A32_SMBLT 00112 00113 #define MVME_AM_A24_SB (0x3F) /**< A24 Standard Supervisory Block Transfer */ 00114 #define MVME_AM_A24_SP (0x3E) /**< A24 Standard Supervisory Program Access */ 00115 #define MVME_AM_A24_SD (0x3D) /**< A24 Standard Supervisory Data Access */ 00116 #define MVME_AM_A24_NB (0x3B) /**< A24 Standard Non-Privileged Block Transfer */ 00117 #define MVME_AM_A24_NP (0x3A) /**< A24 Standard Non-Privileged Program Access */ 00118 #define MVME_AM_A24_ND (0x39) /**< A24 Standard Non-Privileged Data Access */ 00119 #define MVME_AM_A24_SMBLT (0x3C) /**< A24 Multiplexed Block Transfer (D64) */ 00120 #define MVME_AM_A24_NMBLT (0x38) /**< A24 Multiplexed Block Transfer (D64) */ 00121 00122 #define MVME_AM_A24 MVME_AM_A24_SD 00123 #define MVME_AM_A24_D64 MVME_AM_A24_SMBLT 00124 00125 #define MVME_AM_A16_SD (0x2D) /**< A16 Short Supervisory Data Access */ 00126 #define MVME_AM_A16_ND (0x29) /**< A16 Short Non-Privileged Data Access */ 00127 00128 #define MVME_AM_A16 MVME_AM_A16_SD 00129 00130 #define MVME_AM_DEFAULT MVME_AM_A32 00131 00132 /*---- interface structure -----------------------------------------*/ 00133 00134 #define MAX_CRATE 10 /**< maximum number of crates */ 00135 00136 typedef struct { 00137 int handle; /**< internal handle */ 00138 int index; /**< index of interface 0..n */ 00139 void *info; /**< internal info structure */ 00140 int am; /**< Address modifier */ 00141 int dmode; /**< Data mode (D8,D16,D32,D64) */ 00142 int blt_mode; /**< Block transfer mode */ 00143 void *table; /**< Optional table for some drivers */ 00144 } MVME_INTERFACE; 00145 00146 /*---- function declarations ---------------------------------------*/ 00147 00148 /* make functions callable from a C++ program */ 00149 #ifdef __cplusplus 00150 extern "C" { 00151 #endif 00152 00153 /**dox***************************************************************/ 00154 /** @addtogroup mvmestdfunctionh 00155 * 00156 * @{ */ 00157 00158 /********************************************************************/ 00159 /** VME open 00160 The code below summarize the use of most of the mvme calls included in this 00161 interface. 00162 \code 00163 #include "vmicvme.h" // or other VME interface driver. 00164 00165 int main () { 00166 int i, status, vmeio_status, data; 00167 MVME_INTERFACE *myvme; 00168 00169 // Open VME channel 00170 status = mvme_open(&myvme, 0); 00171 00172 // Reset VME 00173 // Under VMIC reboot CPU!! 00174 // status = mvme_sysreset(myvme); 00175 00176 // Setup AM 00177 status = mvme_set_am(myvme, MVME_AM_A24_ND); 00178 00179 // Setup Data size 00180 status = mvme_set_dmode(myvme, MVME_DMODE_D32); 00181 00182 // Read VMEIO status 00183 status = mvme_read(myvme, &vmeio_status, 0x78001C, 4); 00184 printf("VMEIO status : 0x%x\n", vmeio_status); 00185 00186 // Write Single value 00187 mvme_write_value(myvme, 0x780010, 0x3); 00188 00189 // Read Single Value 00190 printf("Value : 0x%x\n", mvme_read_value(myvme, 0x780018)); 00191 00192 // Write to the VMEIO in latch mode 00193 for (i=0;i<10000;i++) { 00194 data = 0xF; 00195 status = mvme_write(myvme, 0x780010, &data, 4); 00196 data = 0x0; 00197 status = mvme_write(myvme, 0x780010, &data, 4); 00198 } 00199 00200 // Close VME channel 00201 status = mvme_close(myvme); 00202 return 1; 00203 } 00204 \endcode 00205 @param **vme user VME pointer to the interface 00206 @param index interface number should be used to distingush multiple VME 00207 interface access within the same program. 00208 @return status MVME_SUCCESS, MVME_NO_INTERFACE, MVME_INVALID_PARAM, MVME_ACCESS_ERROR 00209 */ 00210 int EXPRT mvme_open(MVME_INTERFACE **vme, int index); 00211 00212 /********************************************************************/ 00213 /** 00214 Close and release ALL the opened VME channel. 00215 See example in @ref mvme_open() 00216 @param *vme VME structure. 00217 @return MVME_SUCCESS, MVME_ACCESS_ERROR 00218 */ 00219 int EXPRT mvme_close(MVME_INTERFACE *vme); 00220 00221 /********************************************************************/ 00222 /** 00223 VME bus reset. 00224 Effect of the VME bus reset is dependent of the type of VME interface used. 00225 See example in @ref mvme_open() 00226 @param *vme VME structure. 00227 @return MVME_SUCCESS, MVME_ACCESS_ERROR 00228 */ 00229 int EXPRT mvme_sysreset(MVME_INTERFACE *vme); 00230 00231 /********************************************************************/ 00232 /** 00233 Read from VME bus. 00234 Implementation of the read can include automatic DMA transfer based on the 00235 size of the data. See example in @ref mvme_open() 00236 @param *vme VME structure 00237 @param *dst destination pointer 00238 @param vme_addr source address (VME location). 00239 @param n_bytes requested transfer size. 00240 @return MVME_SUCCESS 00241 */ 00242 int EXPRT mvme_read(MVME_INTERFACE *vme, void *dst, mvme_addr_t vme_addr, mvme_size_t n_bytes); 00243 00244 /********************************************************************/ 00245 /** 00246 Read single data from VME bus. 00247 Useful for register access. See example in @ref mvme_open() 00248 @param *vme VME structure 00249 @param vme_addr source address (VME location). 00250 @return MVME_SUCCESS 00251 */ 00252 DWORD EXPRT mvme_read_value(MVME_INTERFACE *vme, mvme_addr_t vme_addr); 00253 00254 /********************************************************************/ 00255 /** 00256 Write data to VME bus. 00257 Implementation of the write can include automatic DMA transfer based on the 00258 size of the data. See example in @ref mvme_open() 00259 @param *vme VME structure 00260 @param vme_addr source address (VME location). 00261 @param *src source array 00262 @param n_bytes size of the array in bytes 00263 @return MVME_SUCCESS 00264 */ 00265 int EXPRT mvme_write(MVME_INTERFACE *vme, mvme_addr_t vme_addr, void *src, mvme_size_t n_bytes); 00266 00267 /********************************************************************/ 00268 /** 00269 Write single data to VME bus. 00270 Useful for register access. See example in @ref mvme_open() 00271 @param *vme VME structure 00272 @param vme_addr source address (VME location). 00273 @param value Value to be written to the VME bus 00274 @return MVME_SUCCESS 00275 */ 00276 int EXPRT mvme_write_value(MVME_INTERFACE *vme, mvme_addr_t vme_addr, DWORD value); 00277 00278 /********************************************************************/ 00279 /** 00280 Set Address Modifier. 00281 @param *vme VME structure 00282 @param am address modifier 00283 @return MVME_SUCCESS 00284 */ 00285 int EXPRT mvme_set_am(MVME_INTERFACE *vme, int am); 00286 00287 /********************************************************************/ 00288 /** 00289 Get Address Modifier. 00290 @param *vme VME structure 00291 @param *am returned address modifier 00292 @return MVME_SUCCESS 00293 */ 00294 int EXPRT mvme_get_am(MVME_INTERFACE *vme, int *am); 00295 00296 /********************************************************************/ 00297 /** 00298 Set Data mode. 00299 @param *vme VME structure 00300 @param dmode Data mode 00301 @return MVME_SUCCESS 00302 */ 00303 int EXPRT mvme_set_dmode(MVME_INTERFACE *vme, int dmode); 00304 00305 /********************************************************************/ 00306 /** 00307 Get current Data mode. 00308 @param *vme VME structure 00309 @param *dmode returned address modifier 00310 @return MVME_SUCCESS 00311 */ 00312 int EXPRT mvme_get_dmode(MVME_INTERFACE *vme, int *dmode); 00313 00314 /********************************************************************/ 00315 /** 00316 Set Block Transfer mode. 00317 @param *vme VME structure 00318 @param mode BLT mode 00319 @return MVME_SUCCESS 00320 */ 00321 int EXPRT mvme_set_blt(MVME_INTERFACE *vme, int mode); 00322 00323 /********************************************************************/ 00324 /** 00325 Get current Data mode. 00326 @param *vme VME structure 00327 @param *mode returned BLT mode 00328 @return MVME_SUCCESS 00329 */ 00330 int EXPRT mvme_get_blt(MVME_INTERFACE *vme, int *mode); 00331 00332 #ifdef __cplusplus 00333 } 00334 #endif 00335 00336 /**dox***************************************************************/ 00337 /** @} */ /* end of mvmestdfunctionh */ 00338 /**dox***************************************************************/ 00339 /** @} */ /* end of mvmestdinclude */