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