Subversion Repositories f9daq

Rev

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

Rev Author Line No. Line
12 f9daq 1
#include <ctype.h>
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <unistd.h>
5
#include "pcivme_ni.h"
6
#include "wienvme_dll.h"
7
//----------- DEFINES -----------------------------------------------------
8
#define DEVICENAME_LINUX "/dev/vmemm_1"     // a device name 'template' for WINNT
9
 
10
 
11
 
12
int hHandle24, hHandle32, hHandle16;
13
int VMEerrors=0;
14
 
15
void VME_load (char* module_path)
16
{
17
  VMEerrors=0;
18
}
19
 
20
int VME_open (int* hHandle, unsigned char AddMod, char* device_name,
21
                 unsigned short module_number)
22
{
23
  int   result;
24
  char dname[256];
25
/* open a path to a device. */
26
  if (device_name == NULL) sprintf(dname,"%s", DEVICENAME_LINUX);
27
  else sprintf(dname,"%s", device_name);
28
 
29
  result = VMEinit(dname, module_number, AddMod, hHandle);
30
  if (result) {
31
    printf("Can't open interface \"%s\" to VMEMM-module ! err=%d\n", dname, result);
32
    printf("module_number %d, AddMod %d, hHandle %d\n",module_number, AddMod, *hHandle);
33
    exit(-1);
34
  }
35
  return(result);
36
}
37
 
38
int VME_open24 (void)
39
{
40
  return (VME_open (&hHandle24, Std_NoPriv_Data, NULL, 1));
41
}
42
 
43
int VME_open32 (void)
44
{
45
  return (VME_open (&hHandle32, Ext_NoPriv_Data, NULL, 1));
46
}
47
 
48
int VME_open16 (void)
49
{
50
  return (VME_open (&hHandle16, Short_NoPriv, NULL, 1));
51
}
52
 
53
int VME_start (char* module_path)
54
{
55
  VME_load(module_path);
56
  VME_open24();
57
  VME_open32();
58
  VME_open16();
59
  return 0;
60
}
61
 
62
void VME_unload ()
63
{
64
 
65
  return;
66
}
67
 
68
int VME_close (int hHandle)
69
{
70
  int result;
71
 
72
/* close the opened path */
73
  printf("VME_Close at addr=%d\n",hHandle);
74
 
75
  result = VMEclose(hHandle);
76
  if (result) {
77
    printf("Can't close interface!\n");
78
  }
79
  return (result);
80
}
81
 
82
int VME_close24 ()
83
{
84
  return (VME_close (hHandle24));
85
}
86
 
87
int VME_close32 ()
88
{
89
  return (VME_close (hHandle32));
90
}
91
 
92
int VME_close16 ()
93
{
94
  return (VME_close (hHandle16));
95
}
96
 
97
 
98
int VME_stop ()
99
{
100
  VME_close24();
101
  VME_close32();
102
  VME_close16();
103
  VME_unload();
104
 
105
  return 0;
106
}
107
 
108
int VME_reset ()
109
{
110
  int result;
111
 
112
/* close the opened path */
113
  result = VMEreset(hHandle16);
114
  if (result) {
115
    printf("Can't reset interface A16!\n");
116
  }
117
  result = VMEreset(hHandle24);
118
  if (result) {
119
    printf("Can't reset interface A24!\n");
120
  }
121
  result = VMEreset(hHandle32);
122
  if (result) {
123
    printf("Can't reset interface A32!\n");
124
  }
125
  return (result);
126
}
127
 
128
int VME_read8 (int hHandle, unsigned long n, unsigned long at, void* buff)
129
{
130
  int result;
131
 
132
/* D8 read */
133
  result = VMEread(hHandle, at, 1, n, buff);
134
  if (result) {
135
    VMEerrors++;
136
    printf("D8 read at 0x%lX failed!\n", at);
137
  }
138
//  printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff);
139
  return (result);
140
}
141
 
142
int VME_read16 (int hHandle, unsigned long n, unsigned long at, void* buff)
143
{
144
  int result;
145
 
146
/* D16 read */
147
  result = VMEread(hHandle, at, 2, n, buff);
148
  if (result) {
149
    VMEerrors++;
150
    printf("D16 read at 0x%lX failed!\n", at);
151
  }
152
//  printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff);
153
  return (result);
154
}
155
 
156
int VME_read32 (int hHandle, unsigned long n, unsigned long at, void* buff)
157
{
158
  int result;
159
 
160
/* D32 read */
161
  result = VMEread(hHandle, at, 4, n, buff);
162
  if (result) {
163
    VMEerrors++;
164
    printf("D32 read at 0x%lX failed!\n", at);
165
  }
166
  //printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff);
167
  return (result);
168
}
169
 
170
int VME_write8 (int hHandle, unsigned long n, unsigned long at, void* buff)
171
{
172
  int result;
173
 
174
/* D8 write */
175
  result = VMEwrite(hHandle, at, 1, n, buff);
176
  if (result) {
177
    VMEerrors++;
178
    printf("D8 write at 0x%lX failed!\n", at);
179
  }
180
  return (result);
181
}
182
 
183
int VME_write16 (int hHandle, unsigned long n, unsigned long at, void* buff)
184
{
185
  int result;
186
 
187
/* D16 write */
188
  result = VMEwrite(hHandle, at, 2, n, buff);
189
  if (result) {
190
    VMEerrors++;
191
    printf("D16 write at 0x%lX failed!\n", at);
192
  }
193
  return (result);
194
}
195
 
196
int VME_write32 (int hHandle, unsigned long n, unsigned long at, void* buff)
197
{
198
  int result;
199
 
200
/* D32 write */
201
  result = VMEwrite(hHandle, at, 4, n, buff);
202
  if (result) {
203
    VMEerrors++;
204
    printf("D32 write at 0x%lX failed!\n", at);
205
  }
206
  //printf("D32 write at 0x%X buff=0x%X\n", at,((int*) buff)[0]);
207
  return (result);
208
}
209
 
210
 
211
#ifdef MAIN
212
int GetHandle(int w){
213
switch (w){
214
case 16: return hHandle16;
215
case 24: return hHandle24;
216
case 32: return hHandle24;
217
 
218
}
219
return 24;
220
}
221
 
222
int main(int argc, char **argv){
223
 unsigned long address=0x32100000, value;
224
 unsigned char modifier=24;
225
 int hHandle, result=0;
226
 int width=4;
227
 int c;
228
 
229
       opterr = 0;
230
       VME_start(NULL);
231
       while ((c = getopt (argc, argv, "a:w:rm:osd:")) != -1)
232
         switch (c)
233
           {
234
          case 's':
235
            VME_reset();
236
            break;             // reset
237
          case 'a':
238
            address  =  strtoul (optarg,NULL,0);
239
            break;             // address
240
          case 'm':
241
            modifier = strtoul (optarg,NULL,0);
242
            break;             // modifier
243
          case 'd':
244
            width    = strtoul (optarg,NULL,0);
245
            printf("Width= %d\n",width);
246
            break;             // data width
247
          case 'w':
248
             value = strtoul (optarg,NULL,0);
249
             hHandle = GetHandle(modifier);
250
             result = VMEwrite(hHandle, address, width, 1, &value);
251
             if (result) printf("A%d D%d write at 0x%lX failed! result=%d err=%d\n", modifier, width*8, address, result, GetLastError(hHandle));
252
             break;            // write
253
          case 'r':
254
           hHandle = GetHandle(modifier);
255
           result = VMEread(hHandle, address, width, 1, &value);
256
           if (result) printf("A%d D%d read at 0x%lX failed! result=%d err=%d\n", modifier,width*8, address, result, GetLastError(hHandle));
257
           break;              // read
258
           default:
259
             printf("Unknown command %c\n",c);
260
           }
261
 
262
      VME_stop();
263
}
264
#endif