Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#include <stdlib.h>
#include <stdio.h>
#include "CAENV262.h"
#include "CAENV262_DEF.h"
#include "vme.h"


static unsigned int ModuleAddress[10];
static unsigned short  m_OutputMaskEcl;
static unsigned short  m_OutputMaskLevel;
static unsigned short  m_InputMaskLevel;
int _VI_FUNC V262_Map (int ModuleNumber,
                         unsigned long ModuleOffset, int dprint)
{
  unsigned short vsr, mmt, fix;
  printf("CAEN V262 offset = 0x%08x print=%d\n", ModuleOffset, dprint);
  ModuleAddress[ModuleNumber] =  ModuleOffset;
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV262_FIX, &fix);
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV262_MMT, &mmt);
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV262_VSR, &vsr);
  //if (dprint !=0) {
    printf("CAEN V262 offset = 0x%08x\n", ModuleOffset);
    printf("CAEN V262 fixed code = 0x%04x\n", fix);
    printf("CAEN V262 manufacturer number = %i\n", MANUFACTURER(mmt));
    printf("CAEN V262 module type = %i\n", MODULE_TYPE(mmt));
    printf("CAEN V262 version = %i\n", VERSION(vsr));
    printf("CAEN V262 serial no. = %i\n", SERIAL(vsr));
  //}
  if ((fix != CAEN_FIX_CODE) || (mmt != CAENV262_MMT_VALUE)) return -1;
  return 0;
}

int _VI_FUNC V262_Init (int ModuleNumber)
{
  m_OutputMaskEcl=0;
  m_OutputMaskLevel=0;

  V262_MaskOut(ModuleNumber,CAENV262_NIMOUT,m_OutputMaskLevel);
  V262_MaskOut(ModuleNumber,CAENV262_ECLOUT,m_OutputMaskEcl);

 
  m_InputMaskLevel = V262_MaskIn(ModuleNumber);
 
  printf("V262_init : value of NIM inputs=%02x\n",m_InputMaskLevel);

  return 0;
}


int _VI_FUNC V262_MaskOut(int ModuleNumber, unsigned long shft, unsigned short mask)
{
VME_A24D16_W(ModuleAddress[ModuleNumber] + shft,mask);
return 0;
}



unsigned short _VI_FUNC V262_MaskIn(int ModuleNumber)
{
unsigned long mask=0;
VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV262_NIMIN,&mask);
//printf("V262_MaskIn %04x\n", mask);
return mask;
}


int _VI_FUNC V262_LevelInput(int ModuleNumber, int input)
{
  if((input < 0) || (input > 3)) return 0;
  return (V262_MaskIn(ModuleNumber) & (1<<input));
}

int _VI_FUNC V262_PulseOutput(int ModuleNumber, int output)
{
  if((output < 0) || (output > 3)) return -1;
  return V262_MaskOut(ModuleNumber,CAENV262_SHPOUT, 1 << output);
}


int _VI_FUNC V262_LevelOutput(int ModuleNumber, int output, int level)
{
  if((output < 0) || (output > 3)) return -1;
  if (level) m_OutputMaskLevel |= (1 << output);
  else m_OutputMaskLevel &= ~(1 << output);
  return V262_MaskOut(ModuleNumber,CAENV262_NIMOUT, m_OutputMaskLevel );
}

int _VI_FUNC V262_EclOutput(int ModuleNumber, int output, int level)
{
  if((output < 0) || (output > 16)) return -1;
  if (level) m_OutputMaskEcl |= (1 << output);
  else m_OutputMaskEcl &= ~(1 << output);
  return V262_MaskOut(ModuleNumber,CAENV262_ECLOUT, m_OutputMaskEcl );
}