Subversion Repositories f9daq

Rev

Rev 188 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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