Subject: How to access VME modules??
To: None <port-mvme68k@netbsd.org>
From: Giuseppe Pesce <giuseppe.pesce@na.infn.it>
List: port-mvme68k
Date: 05/27/2004 11:39:53
Hi,

I'd like to access a VME module, using a diskless mvme68k (MVME167).
I compiled a new kernel with the INSECURE option as suggested by Henning
and it seems to works fine. This is a part of dmesg:

..............
vmetwo0 at mainbus0 address 0xfff40000: Type 2 VMEchip, scon jumper enabled
vmetwo0: Master#0: 0xffff0000 -> A16:0000-ffff (D32-D8,DS)
vmetwo0: Master#1: 0xf0000000 -> A24:000000-ffffff (D16-D8,DS)
vmetwo0: Master#2: 0xf1000000 -> A32:f1000000-ff7fffff (D16-D8,DS)
vmetwo0: Master#3: 0x02000000 -> A32:02000000-effeffff (D32-D8,DS)
vmetwo0: Master#4: disabled
vmetwo0: Master#5: disabled
vmetwo0: Master#6: disabled
vmetwo0:  Slave#0: disabled
vmetwo0:  Slave#1: 0x00000000 -> A32:00000000-01ffffff (D32-D8,DPUSB6)
vmetwo0:  Slave#2: 0xffe00000 -> A32:ffe00000-ffe1ffff (D32-D8,DPUSB6)
vmetwo0:  Slave#3: 0x00000000 -> A24:000000-ffffff (D32-D8,DPUSB6)
vmetwo0:  Slave#4: disabled
vmetwo0:  Slave#5: disabled
vme0 at vmetwo0
.......

then i tried to use the example Henning gave me similar to those on the
mailing list archive about a discussion between Henning and Steve W.

I can acces the vme module in the bug environment so I'm sure about the base
address of the module.


My code is:

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <inttypes.h>
#include <unistd.h>
#include <sys/mman.h>

volatile uint16_t *A32D16;
volatile unsigned long *pADC;

extern int errno;

#define BASEA24D16 0xf0000000
#define BASEA24D32 0xef000000
#define BASEA32D32 0x02000000
#define _16M        (16<<20)


#define GetData(VME,RAM) (RAM = *(pADC +VME/sizeof(long)));
#define PutData(VME,RAM) (*(A32D32+(VME)/4)=RAM);


#define ADC_BASE    0x02EE0000       // ADC base addr
#define ADC_SIZE    0xFFFF           // ADC register area length in bytes
#define ADC_VERSION 0xFE
#define ADC_MADE    0xFC
#define ADC_SRN     0xFA
#define ADC_RESET   0x14 // reset


int main()
{

   int vmefd = -1;
   size_t adcSize= ADC_SIZE;
   off_t  Offset = ADC_BASE;
   unsigned long int adcData;
   printf("opening /dev/mem...\n");
   if((vmefd = open("/dev/mem", O_RDWR | O_SYNC) < 0)) {
     perror("0:exit....");
     exit(0);
   }

   printf("0:fd = %d pADC=0x%x\n",vmefd,pADC);

   pADC = mmap(NULL,ADC_SIZE,PROT_READ|PROT_WRITE,MAP_PRIVATE,vmefd,ADC_BASE);


   if(pADC==(void *)-1) {
     printf("on exit:ERRNO=%d\n",pADC);
     perror("1:exit....");
     close(vmefd);
     exit(0);
   }
   printf("1:Pointer=0x%x\n",pADC);


   // [access your VME boards here, with the above Get/Put macros]

//GetData(0xfe,adcData);

  munmap((void *)pADC, ADC_SIZE);

   close(vmefd);

   return 0;
}


But the result is:

opening /dev/mem...
0:fd = 0 pADC=0x0
on exit:ERRNO=-1
1:exit....: Invalid argument


I tried with different addresses but with the same result.

What can I do??? Please give me some hints (taking in mind that I'm quite new
to VME world)


Thank you in advance,

peppe






****************************************************************************
Dr. Giuseppe Pesce                      * phone   +39 081 676274
Dipartimento Scienze Fisiche            * fax     +39 081 676346
Universita' di Napoli ''Federico II''   *
Complesso universitario Monte S.Angelo  * e-mail: giuseppe.pesce@na.infn.it
Via Cintia  80126 NAPOLI, ITALY          *
****************************************************************************
                      one man's hell is another man's heaven