Subversion Repositories f9daq

Rev

Rev 264 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
188 f9daq 1
#include <ansi_c.h>
2
#include "CAENV965.h"
3
#include "CAENV965_DEF.h"
4
 
5
#ifdef SISVME
6
#include "sisvme_dll.h"
7
#endif
8
#ifdef WIENVME
9
#include "wienvme_dll.h"
10
#endif
11
 
12
static unsigned long ModuleAddress[10];
13
 
14
int _VI_FUNC V965_map (int ModuleNumber, unsigned long ModuleOffset, int print)
15
{
16
  int i;
17
  unsigned short geo, fw, ah, al;
18
 
19
  ModuleAddress[ModuleNumber] = ModuleOffset;
20
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_FW, &fw);
21
  geo = 0;
22
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_CRN, &geo);
23
  for (i=0;i<32;i++)
24
    VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_THM + 2*i, &geo);
25
  geo = ModuleNumber;
26
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_GEO, &geo);
27
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_GEO, &geo);
28
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_ADH, &ah);
29
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_ADL, &al);
30
  if (print) {
31
    printf("firmware = %d.%d\n", (fw>>8)&0xff, fw&0xff);
32
    printf("geo      = %d\n", geo&0x1f );
33
    printf("addr         = 0x%04X0000\n", (ah<<8)|(al&0xff));
34
  }
35
  return 0;
36
}
37
 
38
 
39
int _VI_FUNC V965_init (int ModuleNumber, unsigned short ped)
40
{
41
  unsigned short dum16;
42
 
43
  dum16= 0x80;
44
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS1, &dum16);
45
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC1, &dum16);
46
  dum16= ped;
47
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_PED, &dum16);
48
  dum16= 0x5000;
49
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16);
50
  dum16= 0x4;
51
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16);
52
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC2, &dum16);
53
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_ECR, &dum16);
54
 
55
  printf ( "Module %d initialized!\n", ModuleNumber ) ;
56
  return 0;
57
}
58
 
59
int _VI_FUNC V965_clear (int ModuleNumber)
60
{
61
 
62
  unsigned short dum16;
63
 
64
  dum16= 0x4;
65
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16);
66
  VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC2, &dum16);
67
 
68
  return 0;
69
 
70
}
71
 
72
int _VI_FUNC V965_status (int ModuleNumber)
73
{
74
  unsigned short dum16;
75
 
76
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_SR1, &dum16);
77
 
78
  return (int)dum16;
79
}
80
 
81
int _VI_FUNC V965_status2 (int ModuleNumber)
82
{
83
 
84
  unsigned short dum16;
85
 
86
  VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_SR2, &dum16);
87
 
88
  return (int)dum16;
89
}
90
 
91
int _VI_FUNC V965_read (int ModuleNumber, unsigned long whereto[])
92
{
93
  int status, ndata, i;
94
 
95
  ndata = 0;
96
 
97
  do {
98
    VME_A24D32_R(ModuleAddress[ModuleNumber] + CAENV965_OB, &whereto[ndata]);
99
    i=(whereto[ndata]>>25)&0x3;
100
    if (i<3) ndata++;
101
  } while (i<2);
102
 
103
  return ndata;  
104
}