#include <ansi_c.h>
//#include <stdlib.h>
//#include <stdio.h>
#include "CAENV814.h"
#include "CAENV814_DEF.h"
#include "wienvme_dll.h"
static unsigned int ModuleAddress[10];
static unsigned short m_OutputMaskEcl;
static unsigned short m_OutputMaskLevel;
static unsigned short m_InputMaskLevel;
int V814_map (int ModuleNumber,
unsigned long ModuleOffset, int print)
{
unsigned short vsr, mmt, fix;
ModuleAddress[ModuleNumber] = ModuleOffset;
VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV814_FIX, &fix);
VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV814_MMT, &mmt);
VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV814_VSR, &vsr);
if (print) {
printf("CAEN V814 fixed code = 0x%04x\n", fix
);
printf("CAEN V814 manufacturer number = %i\n", MANUFACTURER
(mmt
));
printf("CAEN V814 module type = %i\n", MODULE_TYPE
(mmt
));
printf("CAEN V814 version = %i\n", VERSION
(vsr
));
printf("CAEN V814 serial no. = %i\n", SERIAL
(vsr
));
}
if ((fix != CAEN_FIX_CODE) || (mmt != CAENV814_MMT_VALUE)) return -1;
return 0;
}
int V814_init (int ModuleNumber, unsigned int threshold, unsigned int width, unsigned int mask)
{
int ch;
V814_SetWidth( ModuleNumber, width);
for ( ch=0;ch<16;ch++) V814_SetThreshold(ModuleNumber, ch, threshold);
V814_SetEnable( ModuleNumber, mask);
V814_SetMajority( ModuleNumber, 0);
//printf("V814_init : value of threshold =%d\n", threshold);
//printf("V814_init : value of output width=%d\n", width);
//printf("V814_init : channels enabled mask=%04x\n", mask);
return 0;
}
int V814_SetThreshold(int ModuleNumber, unsigned long channel, unsigned short threshold)
{
VME_A24D16_W(ModuleAddress[ModuleNumber] + channel* 0x2,&threshold);
return 0;
}
int V814_SetEnable(int ModuleNumber, unsigned short mask)
{
VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV814_INH,&mask);
return 0;
}
int V814_SetWidth(int ModuleNumber, unsigned short wdt)
{
VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV814_WDT0,&wdt);
VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV814_WDT1,&wdt);
return 0;
}
int V814_SetMajority(int ModuleNumber, unsigned short majlev)
{
unsigned short maj=(int)((majlev*50.-25.)/4.);
VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV814_MAJ,&maj);
return 0;
}
int V814_TestPulse(int ModuleNumber)
{
unsigned short maj=0;
VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV814_TST,&maj);
return 0;
}