gefvme.h File Reference

Go to the source code of this file.

Functions

char * gefvme_get_a16 (MVME_INTERFACE *mvme)
char * gefvme_get_a24 (MVME_INTERFACE *mvme)
char * gefvme_get_a32 (MVME_INTERFACE *mvme, mvme_addr_t vmeaddr, int size)
void gefvme_set_dma_debug (int debug)
void gefvme_set_dma_channel (int channel)
int gefvme_read_dma (MVME_INTERFACE *mvme, void *dst, mvme_addr_t vme_addr, int nbytes)
int gefvme_read_dma_multiple (MVME_INTERFACE *mvme, int nseg, void *dstaddr[], const mvme_addr_t vmeaddr[], int nbytes[])


Function Documentation

char* gefvme_get_a16 ( MVME_INTERFACE mvme  ) 

return pointer to memory-mapped VME A16 address space

Definition at line 266 of file gefvme.c.

00267 {
00268   char* addr;
00269   int status = gefvme_openWindow(mvme, MVME_AM_A16, 0, 0x10000, NULL, &addr);
00270   if (status != MVME_SUCCESS)
00271     return NULL;
00272   return addr;
00273 }

char* gefvme_get_a24 ( MVME_INTERFACE mvme  ) 

return pointer to memory-mapped VME A24 address space

Definition at line 275 of file gefvme.c.

00276 {
00277   char* addr;
00278   int status = gefvme_openWindow(mvme, MVME_AM_A24, 0, 0x1000000, NULL, &addr);
00279   if (status != MVME_SUCCESS)
00280     return NULL;
00281   return addr;
00282 }

char* gefvme_get_a32 ( MVME_INTERFACE mvme,
mvme_addr_t  vmeaddr,
int  size 
)

return pointer to memory-mapped VME A32 address space. Unlike A16 and A24, all of A32 cannot be all memory-mapped at once, so one has to map it one piece at a time. There is a limited number of available mappings

int gefvme_read_dma ( MVME_INTERFACE mvme,
void *  dst,
mvme_addr_t  vme_addr,
int  nbytes 
)

run a single dma read operation. (note: data read through the tsi148 will have the wrong endianness and has to be byte-swapped by the user)

Definition at line 564 of file gefvme.c.

Referenced by mvme_read().

00565 {
00566   int i;
00567   vmeDmaPacket_t vmeDma;
00568   char* ptr;
00569   int xerrno;
00570   int bytesRead;
00571 
00572   makeDmaPacket(&vmeDma, mvme->blt_mode, mvme->am, vme_addr, dst, n_bytes);
00573   xerrno = runDma(gefvme_dma_channel, &vmeDma);
00574 
00575   if (0)
00576     {
00577       uint32_t *ptr = (uint32_t*)dst;
00578       int i;
00579       printf("dst %p\n", dst);
00580       for (i=0; i<10; i++)
00581         printf("dst[%d] = 0x%08x\n", i, ptr[i]);
00582     }
00583   
00584   if (0)
00585     {
00586       printf("mvme_read_dma: DMA status:\n");
00587       printf("  requested %d bytes\n", n_bytes);
00588       printf("  vmeDmaToken: %d\n", vmeDma.vmeDmaToken);
00589       printf("  vmeDmaWait:  %d\n", vmeDma.vmeDmaWait);
00590       printf("  vmeDmaStartTick: %d\n", vmeDma.vmeDmaStartTick);
00591       printf("  vmeDmaStopTick: %d\n", vmeDma.vmeDmaStopTick);
00592       printf("  vmeDmaElapsedTime: %d\n", vmeDma.vmeDmaElapsedTime);
00593       printf("  vmeDmaStatus: %d\n", vmeDma.vmeDmaStatus);
00594       printf("  byte count: %d\n", vmeDma.byteCount);
00595       //assert(!"Crash here!");
00596     }
00597 
00598   bytesRead = vmeDma.srcAddr - vme_addr;
00599 
00600   //printf("mvme_read_dma: DMA %6d of %6d bytes from 0x%08x, status 0x%08x, byteCount %d, srcAddr 0x%08x, dstAddr 0x%08x\n", n_bytes, bytesRead, vme_addr, vmeDma.vmeDmaStatus, vmeDma.byteCount, vmeDma.srcAddr, vmeDma.dstAddr);
00601   
00602   if (xerrno < 0) {
00603     fprintf(stderr,"gefvme_read_dma: ioctl(VME_IOCTL_START_DMA) errno %d (%s)\n", -xerrno, strerror(-xerrno));
00604     return MVME_ACCESS_ERROR;
00605   }
00606 
00607   if (vmeDma.vmeDmaStatus != 0x02000000) {
00608     //*((uint32_t*)dst) = 0xdeadbeef;
00609     printf("mvme_read_dma: DMA error, read %6d out of %6d bytes from 0x%08x, status 0x%08x, srcAddr 0x%08x, dstAddr 0x%08x\n", bytesRead, n_bytes, vme_addr, vmeDma.vmeDmaStatus, vmeDma.srcAddr, vmeDma.dstAddr);
00610     fprintf(stderr,"mvme_read_dma: ioctl(VME_IOCTL_START_DMA) returned vmeDmaStatus 0x%08x\n", vmeDma.vmeDmaStatus);
00611     return MVME_ACCESS_ERROR;
00612   }
00613   
00614   if (bytesRead!=0 && bytesRead!=n_bytes) {
00615     printf("mvme_read_dma: DMA %6d of %6d bytes from 0x%08x, status 0x%08x, srcAddr 0x%08x, dstAddr 0x%08x\n", n_bytes, bytesRead, vme_addr, vmeDma.vmeDmaStatus, vmeDma.srcAddr, vmeDma.dstAddr);
00616     fprintf(stderr,"mvme_read_dma: ioctl(VME_IOCTL_START_DMA) returned byteCount %d while requested read of %d bytes\n", bytesRead, n_bytes);
00617     return MVME_ACCESS_ERROR;
00618   }
00619 
00620   if (0)
00621     {
00622       int i;
00623       uint32_t *p32 = (uint32_t*)dst;
00624       for (i=0; i<10; i++)
00625         printf("dma at %d is 0x%08x\n", i, p32[i]);
00626     }
00627   
00628   ptr = (char*)dst;
00629   for (i=0; i<n_bytes; i+=4) {
00630     char tmp;
00631     tmp = ptr[i+0];
00632     ptr[i+0] = ptr[i+3];
00633     ptr[i+3] = tmp;
00634     tmp = ptr[i+1];
00635     ptr[i+1] = ptr[i+2];
00636     ptr[i+2] = tmp;
00637   }
00638     
00639   return MVME_SUCCESS;
00640 }

int gefvme_read_dma_multiple ( MVME_INTERFACE mvme,
int  nseg,
void *  dstaddr[],
const mvme_addr_t  vmeaddr[],
int  nbytes[] 
)

run a chained dma read operation: each dma segment has it's own vme source address, length and memory destination address. (note: data read through the tsi148 will have the wrong endianness and has to be byte-swapped by the user)

Definition at line 418 of file gefvme.c.

00419 {
00420   int i;
00421   int xerrno;
00422   vmeDmaPacket_t pkt[nseg];
00423   for (i=0; i<nseg; i++)
00424     {
00425       if (gefvme_dma_debug)
00426         printf("packet %p+%d, blt %d, am 0x%x, vmeaddr 0x%x, dstaddr %p, nbytes %d\n",  pkt+i, sizeof(vmeDmaPacket_t), mvme->blt_mode, mvme->am, vmeaddr[i], dstaddr[i], nbytes[i]);
00427       makeDmaPacket(pkt+i, mvme->blt_mode, mvme->am, vmeaddr[i], dstaddr[i], nbytes[i]);
00428       pkt[i].pNextPacket = pkt+i+1;
00429     }
00430   pkt[nseg-1].pNextPacket = NULL;
00431 
00432   xerrno = runDma(gefvme_dma_channel, pkt);
00433 
00434   if (xerrno < 0) {
00435     fprintf(stderr,"gefvme_read_dma_multiple: ioctl(VME_IOCTL_START_DMA) errno %d (%s)\n", -xerrno, strerror(-xerrno));
00436     return MVME_ACCESS_ERROR;
00437   }
00438 
00439   if (pkt[0].vmeDmaStatus != 0x02000000) {
00440     fprintf(stderr,"mvme_read_dma_multiple: ioctl(VME_IOCTL_START_DMA) returned vmeDmaStatus 0x%08x\n", pkt[0].vmeDmaStatus);
00441     return MVME_ACCESS_ERROR;
00442   }
00443   
00444   return MVME_SUCCESS;
00445 }

void gefvme_set_dma_channel ( int  channel  ) 

select which one of the 2 tsi148 dma channels to use

Definition at line 412 of file gefvme.c.

00413 {
00414   assert(channel>=0 && channel<=1);
00415   gefvme_dma_channel = channel;
00416 }

void gefvme_set_dma_debug ( int  debug  ) 

set gefvme DMA debug level: 0=off, >0=write more and more stuff into the system log

Definition at line 407 of file gefvme.c.

00408 {
00409   gefvme_dma_debug = debug;
00410 }


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