[
KLOE Online Software ] [ Previous ] [ Index ] [ Bottom ]

VME Access Library Routines

This page describes briefly the use of the VME access library and the library routines available.


Index


How to use the VME access library

The following sample progam is used to describe the routines needed. You can use the hyperlinks to get a more detailed description of the routine. The lines marked with 1,2,3,4 must exist for each VME channel defined.

/* vme_test.c, a simple Vme Access Example */
#include "stdio.h"

/* 1. Include the Vme header file to define
**    function prototypes and property names.
*/
#include "Vme.h"

#define VME_ADDRESS 0x10000000 /* VME address to map */
#define VME_SIZE    0x100000   /* VME space to map */
#define VME_AM      0x09       /* VME address modifier */
#define VME_OFFSET  0x100      /* VME offset from base */

main ()
{
  int cid, data, count, on=1, blt_am=0x0b;
  int *vme_ptr;
  char buffer[100];

  /* 2. Open a VME channel 
  */
  cid = VmeOpenChannel("Example");

  /* -> Define VME specific properties (if needed)
  */
  (void)VmeSetProp(cid, Vme_SET_READ_PREFETCH, &on); 

  /* 3. Define and map VME address space
  */
  vme_ptr=(int *)VmeMapAddress(cid,VME_ADDRESS,VME_SIZE,VME_AM);

  /* - > Do VME read/write using the pointer (if supported)
  **    Note: not possible with the DEC AXPvme board !
  */
  *vme_ptr = 0xBEEFFACE;  /* VME A32/D32 write */
  data = *vme_ptr;        /* VME A32/D32 read */

  /* -> Define properties for VME copy (if needed)
  */
  (void)VmeSetProp(cid, Vme_SET_COPY_AM, &blt_am); 

  /* -> Do VME copy from and to user memory
  */
  count = VmeRead (cid, VME_OFFSET, (char *)buffer, 100);
  count = VmeWrite(cid, VME_OFFSET, (char *)buffer, 100);

  /* 4. Close VME channel and free resources
  */
  (void)VmeCloseChannel(cid);
}
    

VME access routines description


int VmeOpenChannel( char *channel_name )
Description:
Open a VME channel with name channel_name.
Return value:
Channel identification >=0 in case of success and -1 in case of error.
Errors:
Only possible case: no channel free.
Example(s):
if ( (cid = VmeOpenChannel("Example")) < 0 )
  {
    printf("VmeOpenChannel() failed!\n");
    exit(1);
  }
        

int VmeCloseChannel( int cid )
Description:
Close the VME channel with channel id cid.
Return value:
0 in case of success and -1 in case of error.
Errors:
Example(s):
if ( VmeCloseChannel(cid) < 0 )
  {
    printf("VmeCloseChannel() failed!\n");
  }
        

void* VmeMapAddress( int cid, unsigned int vme_addr, int vme_size, int vme_am )
Description:
Map VME address space at VME address vme_addr of size vme_size and with VME address modifier vme_am. The returned pointer can then be used to make VME read/write access.
cid is the channel id returned by VmeOpenChannel()

Important Note Not all VME CPUs support transparent VME access via pointer like the DEC AXPvme boards. Use VmeRead or VmeWrite instead. But this routine must always be called!

Return value:
Pointer to mapped VME address space in in case of success and NULL in case of error.
Errors:
various ...
Example(s):
int *ptr;
...
ptr = (int *)VmeMapAddress(cid,0xE0000000,0x100000,0x09);
if ( ptr == NULL )
  {
    printf("VmeMapAddress() failed!\n");
    exit(1);
  }
        

int VmeSetProp( int cid, int prop, void* value )
Description:
Set the value(s) of property number prop to value. This is a simple method to set properties (or options) for the specified channel. The properties are defined as macros in Vme.h. Click here to get the list of available properties.
cid is the channel id returned by VmeOpenChannel()
Return value:
0 in case of success and -1 in case of error.
Errors:
various ...
Example(s):
int blt = 0x0B; /* BLT D32 */
...

if ( VmeSetProp( cid, Vme_SET_COPY_AM, (int *)&blt) < 0 )
  {
    printf("VmeSetProp() failed!\n");
    exit(1);
  }
        

int VmeGetProp( int cid, int prop, void* value )
Description:
Reverse routine of VmeSetProp(). Not implemented so far !
Return value:
Errors:
Example(s):

int VmeRead ( int cid, int offset, void* buffer, int length ) int VmeWrite( int cid, int offset, void* buffer, int length )
Description:
Performs VME read and write operations e.g. copies length bytes between memory buffer and VME space at offset offset (in bytes) from the VME base address specified in VmeMapAddress(). The type of VME transfer must be defined calling VmeSetProp() previously:
Vme_SET_COPY_AM    : VME address modifier 
Vme_SET_COPY_DTYPE : Data type D8, D16 or D32
Vme_SET_COPY_FIFO  : Do not increment VME address
          
The address modifier defines, if the transfer is done in VME block mode (if available) or not.
cid is the channel id returned by VmeOpenChannel()
Return value:
Bytes transfered in case of success and -1 in case of error.
Errors:
various ...
Example(s):
int blt = 0x0B; /* BLT D32 */
char buffer[100];
...

if ( VmeSetProp( cid, Vme_SET_COPY_AM, (int *)&blt) < 0 )
  exit(1);

cnt = VmeRead( cid, 0x10, (char *)buffer, 100);
if ( cnt < 0)  
  {
    printf("VmeRead() failed!\n");
    exit(1);
  }
        

[ KLOE Online Software ] [ Previous ] [ Index ] [ Top ]

Suggestions, comments or questions? Please contact:


28/3/96