mvmestd.h

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

Midas DOC Version 1.9.5 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk