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 4575 2009-10-02 07:07:23Z 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  initialized;         /**< 1 if VME interface initialized */
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 idx 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 idx);
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 unsigned int 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, unsigned int 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   int EXPRT mvme_interrupt_generate(MVME_INTERFACE *mvme, int level, int vector, void *info);
00332   int EXPRT mvme_interrupt_attach(MVME_INTERFACE *mvme, int level, int vector,
00333                                   void (*isr)(int, void*, void *), void *info);
00334   int EXPRT mvme_interrupt_detach(MVME_INTERFACE *mvme, int level, int vector, void *info);
00335   int EXPRT mvme_interrupt_enable(MVME_INTERFACE *mvme, int level, int vector, void *info);
00336   int EXPRT mvme_interrupt_disable(MVME_INTERFACE *mvme, int level, int vector, void *info);
00337   
00338 #ifdef __cplusplus
00339 }
00340 #endif
00341 
00342 /**dox***************************************************************/
00343 /** @} */ /* end of mvmestdfunctionh */
00344 /**dox***************************************************************/
00345 /** @} */ /* end of mvmestdinclude */
00346 
00347 #endif // MVMESTD_H

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