Rev 264 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include <ansi_c.h>
#ifdef WIENVME
#include "wienvme_dll.h"
#define VME_START(NODE) WIENVME_VME_START((NODE))
#define VME_STOP() WIENVME_VME_STOP()
#define VME_RESET() WIENVME_VME_RESET()
#define VME_A24D8_R(VME,DATA) WIENVME_VME_A24D8_R((VME),(DATA))
#define VME_A24D16_R(VME,DATA) WIENVME_VME_A24D16_R((VME),(DATA))
#define VME_A24D32_R(VME,DATA) WIENVME_VME_A24D32_R((VME),(DATA))
#define VME_A24D8_W(VME,DATA) WIENVME_VME_A24D8_W((VME),(DATA))
#define VME_A24D16_W(VME,DATA) WIENVME_VME_A24D16_W((VME),(DATA))
#define VME_A24D32_W(VME,DATA) WIENVME_VME_A24D32_W((VME),(DATA))
#define VME_A32D8_R(VME,DATA) WIENVME_VME_A32D8_R((VME),(DATA))
#define VME_A32D16_R(VME,DATA) WIENVME_VME_A32D16_R((VME),(DATA))
#define VME_A32D32_R(VME,DATA) WIENVME_VME_A32D32_R((VME),(DATA))
#define VME_A32D8_W(VME,DATA) WIENVME_VME_A32D8_W((VME),(DATA))
#define VME_A32D16_W(VME,DATA) WIENVME_VME_A32D16_W((VME),(DATA))
#define VME_A32D32_W(VME,DATA) WIENVME_VME_A32D32_W((VME),(DATA))
#else
#include "vme.h"
#endif
#include "CAENV965.h"
#include "CAENV965_DEF.h"
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
;
}