Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#include <ansi_c.h>
#include "CAENV462.h"
#include "CAENV462_DEF.h"

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

static unsigned long ModuleAddress[10];

int _VI_FUNC V462_map (int ModuleNumber,
                        unsigned long ModuleOffset, int print)
{
  unsigned short vsr, mmt, fix;
 
  ModuleAddress[ModuleNumber] = ModuleOffset;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV462_FIX,&fix);
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV462_MMT,&mmt);
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV462_VSR,&vsr);
  if (print) {
    printf("fixed code = 0x%04x\n", fix);
    printf("manufacturer number = %i\n", MANUFACTURER(mmt));
    printf("module type = %i\n", MODULE_TYPE(mmt));
    printf("version = %i\n", VERSION(vsr));
    printf("serial no. = %i\n", SERIAL(vsr));
  }
  if ((fix != FIX_CODE) || (mmt != CAENV462_MMT_VALUE)) return 1;
  return 0;
}

int _VI_FUNC V462_set0 (int ModuleNumber, int time)
{
  int i;
  unsigned int status;
  union {
    unsigned short lsbmsb[2];
    unsigned long bcd;
  } set;
 
  if ((time > 99999999) || (time < 0)) time = 0;
  set.bcd = 0;
  for (i=0;i<32;i+=4) {
    set.bcd |= (time % 10) << i;
    time = time / 10;
  }

 
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV462_MSB0, &set.lsbmsb[1]);
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV462_LSB0, &set.lsbmsb[0]);
 
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV462_CSR, &status);
  return (status & CAENV462_STATUS);
}

int _VI_FUNC V462_set1 (int ModuleNumber, int time)
{
  int i;
  unsigned int status;
  union {
    unsigned short lsbmsb[2];
    unsigned long bcd;
  } set;
 
  if ((time > 99999999) || (time < 0)) time = 0;
  set.bcd = 0;
  for (i=0;i<32;i+=4) {
    set.bcd |= (time % 10) << i;
    time = time / 10;
  }

  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV462_MSB1, &set.lsbmsb[1]);
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV462_LSB1, &set.lsbmsb[0]);
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV462_CSR, &status);
  return ( status & CAENV462_STATUS );
 
}

int _VI_FUNC V462_start0 (int ModuleNumber)
{
  unsigned int status;
  unsigned short dum16=   CAENV462_START0;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV462_CSR,  &dum16 );
 
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV462_CSR, &status);
  return ( status & CAENV462_STATUS );
}


int _VI_FUNC V462_start1 (int ModuleNumber)
{
  unsigned int status;
  unsigned short dum16=   CAENV462_START1;
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV462_CSR,  &dum16 );
 
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV462_CSR, &status);
  return ( status & CAENV462_STATUS );
}




int _VI_FUNC V462_status (int ModuleNumber)
{
  unsigned int status;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV462_CSR, &status);
  return (status & CAENV462_STATUS );
}