Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#include <ansi_c.h>
#include "CAENV830.h"
#include "CAENV830_DEF.h"

#ifdef SISVME
#include "sisvme_dll.h"
#endif
#ifdef WIENVME
#include "wienvme_dll.h"
#endif

static unsigned long ModuleAddress[10];


int _VI_FUNC V830_map (int ModuleNumber, unsigned long ModuleOffset, int print)
{
  unsigned short geo, fw;
  unsigned short boardid1, boardid2, boardid3;
  unsigned short serial1, serial2 ;
 
  ModuleAddress[ModuleNumber] = ModuleOffset;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV830_FW, &fw);
  geo=0;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV830_GEO, &geo);
  VME_A24D16_R(ModuleAddress[ModuleNumber] + 0x4000 + 0x8036 ,&boardid1 ) ;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + 0x4000 + 0x803A,&boardid2 ) ;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + 0x4000 + 0x803E,&boardid3 ) ;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + 0x4000 + 0x8F02, &serial1 ) ;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + 0x4000 + 0x8F06, &serial2 ) ;
  if (print) {
    printf("firmware = %d.%d\n", (fw>>4)&0xF, fw&0xF);
    printf("geo      = %d,%d,%d,%d,%d\n",
            geo>>4&0x1,geo>>3&0x1,geo>>2&0x1,geo>>1&0x1,geo&0x1 );
           
    printf ( "board ID: 0x%02X%02X%02X\n",
              boardid1&0xFF,boardid2&0xFF,boardid3&0xFF) ;
    printf ( "serial #: 0x%02X%02X\n",
              serial1&0xFF,serial2&0xFF) ;
  }
  return 0;
}


int _VI_FUNC V830_init (int ModuleNumber)
{
  unsigned short dum16;
  unsigned int dum32;
  dum16=0xFFFF;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + 0x1120, &dum16); // module reset
  VME_A24D16_W(ModuleAddress[ModuleNumber] + 0x1122,  &dum16); // software clear

  dum16=0;     
  VME_A24D16_W(ModuleAddress[ModuleNumber] + 0x1108, &dum16) ;  // auto reset,beer|periodic trigger
                                                          // 1001|0010
                                                         
  dum32= 2500000;                                                      
  VME_A24D32_W(ModuleAddress[ModuleNumber] + 0x1104, &dum32) ; // period=2.5M*400ns
 
  dum32=0xFFFFFFFF;
  VME_A24D32_W(ModuleAddress[ModuleNumber] + 0x1100, &dum32) ; //enable all channels
 
  printf ( "Module %d initialized!\n", ModuleNumber ) ;
  return 0;
}

int _VI_FUNC V830_clear (int ModuleNumber)
{
  unsigned short dum16=0xFFFF;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + 0x1122,&dum16); // software clear
 
  return 0;
 
}


int _VI_FUNC V830_status (int ModuleNumber)
{

 int status=0; 
 VME_A24D16_W(ModuleAddress[ModuleNumber] + 0x110E, &status); //status reg.
 return status;
}



int _VI_FUNC V830_read (int ModuleNumber, unsigned long whereto[])
{
  int status, ndata;
  int i ;
 
  ndata = 0;
 
//  status = V830_status ( ModuleNumber ) ;
//  if (!(status & 0x1)) return 0; //ce ni dredy

  for ( i=32; --i>0; ) {
   VME_A24D32_R(ModuleAddress[ModuleNumber] + 0x1000 + i*0x4, &whereto[i] ) ;
    //printf ( "%2d - %d\n", i, whereto[i] ) ;
  }
//  V830_init ( ModuleNumber ) ;
 
  return 32;  

}