Subversion Repositories f9daq

Rev

Rev 5 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include <stdlib.h>
#include <stdio.h>
#include "CAENV965.h"
#include "CAENV965_DEF.h"
#include "vme.h"

static unsigned long ModuleAddress[10];

int _VI_FUNC V965_map (int ModuleNumber, unsigned long ModuleOffset, int print)
{
  int i;
  unsigned short geo, fw, ah, al;
        if (print) {
                printf("CAEN V965_map \n");
        }
  ModuleAddress[ModuleNumber] = ModuleOffset;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_FW, &fw);
  geo = 0;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_CRN, &geo);
  for (i=0;i<32;i++)
    VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_THM + 2*i, &geo);
  geo = ModuleNumber+1;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_GEO, &geo);
  geo = 0;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_GEO, &geo);
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_ADH, &ah);
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_ADL, &al);
  if (print) {
    printf("CAEN V965 offset = 0x%08x\n", ModuleOffset);
    printf(" V965_map firmware = %d.%d\n", (fw>>8)&0xff, fw&0xff);
    printf(" V965_map geo      = %d\n", geo&0x1f );
    printf(" V965_map addr       = 0x%04X0000\n", (ah<<8)|(al&0xff));
  }
 
  return 0;
}


int _VI_FUNC V965_init (int ModuleNumber, unsigned short ped)
{
  unsigned short dum16;
 
  dum16= 0x80;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS1, &dum16);
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC1, &dum16);
  dum16= ped;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_PED, &dum16);
  dum16= 0x5000;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16);
  dum16= 0x4;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16);
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC2, &dum16);
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_ECR, &dum16);
 
  printf ( " V965_init Module %d initialized!\n", ModuleNumber ) ;
  return 0;
}

int _VI_FUNC V965_clear (int ModuleNumber)
{

  unsigned short dum16;
 
  dum16= 0x4;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16);
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC2, &dum16);
  printf("V965_clear\n");
  return 0;
 
}

int _VI_FUNC V965_status (int ModuleNumber)
{
  unsigned short dum16;

  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_SR1, &dum16);
  //printf("*%d\n",dum16);
  return (int)dum16;
}

int _VI_FUNC V965_status2 (int ModuleNumber)
{

  unsigned short dum16;

  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_SR2, &dum16);
 
  return (int)dum16;
}

int _VI_FUNC V965_read (int ModuleNumber, unsigned long whereto[],int len)
{
  int status, ndata, i;
 
  ndata = 0;
 
  do {
    if (ndata>=len) {
          printf("ERROR V965_read: Increase storage size: ndata=%d\n",ndata);
          break;
    }
    VME_A24D32_R(ModuleAddress[ModuleNumber] + CAENV965_OB, &whereto[ndata]);
    i=(whereto[ndata]>>25)&0x3;
    if (i<3) ndata++;
  } while (i<2);
  return ndata;  
}