Subversion Repositories f9daq

Rev

Rev 89 | Details | Compare with Previous | 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
#include <utility.h>
8
 
9
static unsigned long ModuleAddress[10];
121 f9daq 10
static float timeout = 0.01;
89 f9daq 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
{    
121 f9daq 21
  uint32_t ultmp=0;
89 f9daq 22
 
121 f9daq 23
  VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_RST, ultmp);
89 f9daq 24
 
25
  return;
26
};
27
 
28
void _VI_FUNC  V288_Init (int ModuleNumber)
29
{
30
  V288_Reset(ModuleNumber);
31
 
32
  return;
33
}    
121 f9daq 34
 
89 f9daq 35
int _VI_FUNC V288_Send (int ModuleNumber,int slaveid,int nbuf,unsigned short *buf)
36
{
37
  int i;
121 f9daq 38
  uint32_t ultmp,ulstat;
89 f9daq 39
 
121 f9daq 40
  ultmp=0x00000001;
89 f9daq 41
  while (1){
121 f9daq 42
    VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_BUF, ultmp);
89 f9daq 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){
121 f9daq 49
    VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_BUF, ultmp);
89 f9daq 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){
121 f9daq 57
      VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_BUF, ultmp);
89 f9daq 58
      VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
59
      if (ulstat & 1) Delay(0.1); else break;
60
    }
61
  }
62
 
63
  while (1){
121 f9daq 64
    VME_A24D16_W(ModuleAddress[ModuleNumber]+V288_TX, ultmp);
89 f9daq 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;
121 f9daq 75
  uint32_t ecode,ulstat;
89 f9daq 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){
121 f9daq 86
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_BUF, &ecode);
87
    buf[i]=(unsigned short) ecode;
89 f9daq 88
    VME_A24D16_R(ModuleAddress[ModuleNumber]+V288_STATUS, &ulstat);
89
    if (ulstat & 1) break;
90
    i++;
91
  }
92
 
93
  return i;
94
}  
95