Subversion Repositories f9daq

Rev

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

Rev Author Line No. Line
89 f9daq 1
#include <ansi_c.h>
2
#include "CAENV288.h"
3
#include "CAENV288_DEF.h"
4
 
5
 
6
#include "vme.h"
7
 
8
#include <utility.h>
9
 
10
static unsigned long ModuleAddress[10];
11
 
12
void _VI_FUNC  V288_Map (int ModuleNumber, unsigned long ModuleOffset)
13
{
14
  ModuleAddress[ModuleNumber] = ModuleOffset;
15
 
16
  return;
17
}
18
 
19
void _VI_FUNC  V288_Reset(int ModuleNumber)
20
{    
21
  unsigned short ultmp=0;
22
 
23
  VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_RST, &ultmp);
24
 
25
  return;
26
};
27
 
28
void _VI_FUNC  V288_Init (int ModuleNumber)
29
{
30
  V288_Reset(ModuleNumber);
31
 
32
  return;
33
}    
34
 
35
int _VI_FUNC V288_Send (int ModuleNumber,int slaveid,int nbuf,unsigned short *buf)
36
{
37
  int i;
38
  unsigned short ultmp,ulstat;
39
 
40
  ultmp=0x0001;
41
  while (1){
42
    VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_BUF, &ultmp);
43
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
44
    if (ulstat & 1) Delay(0.1); else break;
45
  }
46
 
47
  ultmp=slaveid;
48
  while (1){
49
    VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_BUF, &ultmp);
50
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
51
    if (ulstat & 1) Delay(0.1); else break;
52
  }
53
 
54
  for (i=0;i<nbuf;i++){
55
    ultmp=buf[i];
56
    while (1){
57
      VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_BUF, &ultmp);
58
      VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
59
      if (ulstat & 1) Delay(0.1); else break;
60
    }
61
  }
62
 
63
  while (1){
64
    VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_TX, &ultmp);
65
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
66
    if (ulstat & 1) Delay(0.1); else break;
67
  }
68
 
69
  return 0;
70
}  
71
 
72
int _VI_FUNC V288_Receive(int ModuleNumber,int nbuf,unsigned short *buf)
73
{
74
  int i;
75
  unsigned short ecode,ulstat;
76
 
77
  while (1){
78
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_BUF, &ecode);
79
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
80
    if (ulstat & 1) Delay(0.1); else break;
81
  }
82
  if (ecode) return 1;
83
 
84
  i=0;
85
  while (i<nbuf){
86
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_BUF, &buf[i]);
87
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
88
    if (ulstat & 1) break;
89
    i++;
90
  }
91
 
92
  return i;
93
}  
94