#include <ansi_c.h>
#include "CAENV965.h"
#include "CAENV965_DEF.h"
#ifdef SISVME
#include "sisvme_dll.h"
#endif
#ifdef WIENVME
#include "wienvme_dll.h"
#endif
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;
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;
VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_GEO, &geo);
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("firmware = %d.%d\n", (fw
>>8)&0xff, fw
&0xff);
printf("geo = %d\n", geo
&0x1f );
printf("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 ( "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);
return 0;
}
int _VI_FUNC V965_status (int ModuleNumber)
{
unsigned short dum16;
VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_SR1, &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 status, ndata, i;
ndata = 0;
do {
VME_A24D32_R(ModuleAddress[ModuleNumber] + CAENV965_OB, &whereto[ndata]);
i=(whereto[ndata]>>25)&0x3;
if (i<3) ndata++;
} while (i<2);
return ndata;
}