Subversion Repositories f9daq

Rev

Rev 12 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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