13 #include <skeluser_ioctl.h>
14 #include <icv196vmelib.h>
15 #include <general_both.h>
18 /* #include "icv196vmeP.h"*/
19 /* #include "/u/dscps/rtfclty/gpsynchrolib.h" */
20 //#define addr = 0x00500000
21 //#define Evtsrce_icv196 2
24 #define ICV_nboards 8 /* MAX allowed modules */
27 static int service_fd
= 0;
28 static int synchro_fd
= 0;
31 extern int snprintf(char *str
, size_t size
, const char *format
, ...);
34 static int module
= 0;
35 static int old_module
= 0;
37 static char choice
[10];
39 static void transmit_data(int fd
, struct gpfd
*gpfd
);
41 void get_input(char *ch
, int *inp
)
45 printf(" +--------------------------------------------------------------+\n");
46 printf(" | 0: exit |\n");
47 printf(" | 1: test |\n");
48 printf(" | 2: change the ICV board being accessed (current board: %d) |\n", module
);
49 printf(" | 3: read interrupt enable mask |\n");
50 printf(" | 4: read module info (VME address, interr. vect. etc.) |\n");
51 printf(" | 5: read handle info (lines connected to by a user) |\n");
52 printf(" | 6: read group |\n");
53 printf(" | 7: write group |\n");
54 printf(" | 8: set I/O direction (does not concern interrupts) |\n");
55 printf(" | 9: read I/O direction (does not concern interrupts) |\n");
56 printf(" | 10: read all interrupt counters |\n");
57 printf(" | 11: read all reenable flags |\n");
58 printf(" | 12/13: set/clear reenable flag |\n");
59 printf(" | 14/15: enable/disable line |\n");
60 printf(" | 16: read an event (enable interrupt line first) |\n");
61 printf(" | 17/18: configure blocking (default)/nonblocking read |\n");
63 printf(" | Nb: functions 12-18 automatically connect to interrupt-line |\n");
64 printf(" +--------------------------------------------------------------+\n\n");
67 getchar(); /* eat up \n */
69 for (p
= ch
; *p
!= '\0'; p
++)
70 if (!isdigit((int)*p
)) {
76 if ((*inp
< 0) || (*inp
> 16))
77 printf("input not correct\n");
80 int main(int argc
, char *argv
[], char *envp
[])
82 int retval
, i
, j
, dir
, stat
, grp_nr
, grp_mask
= 1;
83 char buff
[50] = { 0 } , line
[10];
84 int status
[icv_ModuleNb
][icv_LineNb
] = { { 0 } };
85 int input
, count
, size
;
88 struct icv196T_Service arg
;
89 struct icv196T_UserLine arg2
;
90 struct icv196T_ModuleInfo arg3
[icv_ModuleNb
];
91 struct icv196T_HandleInfo arg4
;
92 struct icv196T_ModuleInfo
*Info_P
;
93 struct icv196T_HandleLines
*Info_H
;
95 service_fd
= icv196_get_handle();
97 fprintf(stderr
, "Can't get library handle...\n");
101 synchro_fd
= service_fd
; /* TODO */
104 get_input(choice
, &input
);
111 struct gpfd
*gpfd
= open_gpf(NULL
);
113 printf("\n\n<enter> to continue"); getchar();
117 if (!load_gpf(gpfd
)) {
118 printf("No data loaded from gnuplot file\n");
119 printf("\n\n<enter> to continue"); getchar();
123 if (!do_conv_gp_file(gpfd
, 1))
124 printf("Failed to create converted file\n");
126 printf("Converted file ready\n");
128 transmit_data(service_fd
, gpfd
);
129 printf("\n\n<enter> to continue"); getchar();
134 printf("number of module to be accessed ?\n" );
136 module
= atoi(board
);
137 if ((module
< 0) || (module
>= ICV_nboards
)) {
138 printf("board number out of range\n");
144 arg
.module
= (unsigned char) module
;
145 if ((retval
= ioctl(service_fd
, ICVVME_intenmask
, &arg
)) < 0) {
146 perror("could not do ioctl\n");
149 stat
= (unsigned short)arg
.data
[0];
150 printf("STATUS OF INTERRUPT LINES ON BOARD NR. %d: ( 0 = disabled, 1 = enabled )\n", module
);
151 for (i
= 0; i
<= 15; i
++) {
152 printf("line %2d: %2d ", i
, stat
& grp_mask
);
154 if (((i
+1) % 4) == 0 && i
!= 0)
161 if ((retval
= ioctl(service_fd
, ICVVME_getmoduleinfo
, Info_P
)) < 0) {
162 perror("could not do ioctl\n");
166 for (i
= 0; i
< icv_ModuleNb
; i
++, Info_P
++) {
167 printf("MODULE INFO FOR MODULE NR. %d:\n", i
);
168 if (!Info_P
->ModuleFlag
) {
169 printf("module not installed\n\n");
173 printf("module base address: 0x%lx\n", Info_P
->ModuleInfo
.base
);
174 printf("module address space size in bytes: %ld\n",
175 Info_P
->ModuleInfo
.size
);
176 printf("module interrupt vectors:\n");
178 for (j
= 0; j
< icv_LineNb
; j
++) {
179 printf("line %2d:%d ", j
, Info_P
->ModuleInfo
.vector
);
181 if (((j
+1) % 6) == 0 && j
!= 0)
186 printf("module interrupt levels:\n");
188 for (j
= 0; j
< icv_LineNb
; j
++) {
189 printf("line %2d:%d ", j
, Info_P
->ModuleInfo
.level
);
190 if (((j
+1) % 6) == 0 && j
!= 0)
198 Info_H
= (struct icv196T_HandleLines
*)&(arg4
.handle
[0]);
199 for (i
= 0; i
< SkelDrvrCLIENT_CONTEXTS
; i
++, Info_H
++) {
201 for (j
= 0; j
< ICV_LogLineNb
; j
++) {
202 Info_H
-> lines
[j
].group
= 0xff;
203 Info_H
-> lines
[j
].index
= 0xff;
207 if ((retval
= ioctl(service_fd
, ICVVME_gethandleinfo
, &arg4
)) < 0) {
208 perror("could not do ioctl\n");
212 Info_H
= (struct icv196T_HandleLines
*)&(arg4
.handle
[0]);
214 for (i
= 1; i
< SkelDrvrCLIENT_CONTEXTS
; i
++, Info_H
++) {
215 printf("HANDLE INFO FOR HANDLE NR. %d: ", i
);
217 printf("handle not used\n\n");
220 printf("used by process pid: %d\n", Info_H
-> pid
);
221 printf("lines connected :");
223 for (j
= 0; Info_H
-> lines
[j
].group
!= 0xff; j
++) {
224 printf("[modul %2d, line %2d] ", Info_H
-> lines
[j
].group
,
225 Info_H
-> lines
[j
].index
);
226 if (((j
+1) % 3) == 0 && j
!= 0)
233 case 6: /* read from the group */
235 short *val
= (short*)buff
;
236 memset(buff
, 0, sizeof(buff
));
237 printf("Group index to read [0 - 11] --> ");
238 scanf("%d", &grp_nr
); getchar();
241 printf("Data size in bytes to read [1 - 2] --> ");
242 scanf("%d", &size
); getchar();
246 retval
= icv196_read_channel(service_fd
, module
, grp_nr
, size
, buff
);
250 printf("0x%hx\n", *val
);
252 printf("\n\n<enter> to continue"); getchar();
255 case 7: /* write into the group */
256 memset(buff
, 0, sizeof(buff
));
257 printf("Group index to write [0 - 11] --> ");
258 scanf("%d", &grp_nr
); getchar();
261 printf("Data size (in bytes) to write [1 - 2] --> ");
262 scanf("%d", &size
); getchar();
267 printf("Data to write in hex (byte) --> ");
269 printf("Data to write in hex (word) --> ");
271 scanf("%hx", (short*)buff
); getchar();
273 if (icv196_write_channel(service_fd
, module
, grp_nr
, size
, buff
))
277 printf("\n\n<enter> to continue"); getchar();
281 printf("Group index to be set [0 - 11] -> ");
282 scanf("%d", &grp_nr
); getchar();
284 printf("Direction [0 -- input, 1 -- output] -> ");
285 scanf("%d", &dir
); getchar();
287 if (icv196_init_channel(service_fd
, module
, grp_nr
, 1, dir
))
291 printf("\n\n<enter> to continue"); getchar();
294 memset(&arg
, 0, sizeof(arg
));
297 if (ioctl(service_fd
, ICVVME_readio
, &arg
) < 0) {
298 perror("could not do ioctl\n");
302 printf("I/O groups direction on module#%d"
303 " (0:input, 1:output)\n", module
);
304 for (i
= 0; i
<= 11; i
++) {
305 printf("group[%2d] %2d\n", i
, dir
& 1);
308 printf("\n\n<enter> to continue"); getchar();
311 arg
.module
= (unsigned char) module
;
312 if ((retval
= ioctl(service_fd
, ICVVME_intcount
, &arg
)) < 0) {
313 printf("retval = %d \n ", retval
);
314 perror("could not do ioctl\n");
317 printf("INTERRUPT COUNTER VALUES ON BOARD NR. %d:\n", module
);
318 for (i
= 0; i
< ICV_nln
; i
++) {
319 printf("line %2d: %3ld ", i
, arg
.data
[i
]);
320 if (((i
+1) % 4) == 0 && i
!= 0)
326 arg
.module
= (unsigned char) module
;
327 if ((retval
= ioctl(service_fd
, ICVVME_reenflags
, &arg
)) < 0) {
328 perror("could not do ioctl\n");
331 printf("REENABLE INTERRUPT FLAGS ON BOARD NR. %d: ( 1 = reenable on, 2 = reenable off )\n", module
);
332 for (i
= 0; i
< ICV_nln
; i
++) {
333 printf("line %2d: %2ld", i
, arg
.data
[i
]);
334 if (((i
+1) % 4) == 0 && i
!= 0)
340 printf("line index to access\n");
341 printf("on module#%d\n", module
);
342 printf("[0 -- 15] --> ");
343 scanf("%s", line
); getchar();
346 if (!WITHIN_RANGE(0, i
, icv_LineNb
-1)) {
347 printf("line number out of range\n");
350 if (!status
[module
][i
]) {
351 icv196_connect(synchro_fd
, module
, i
, 0);
352 status
[module
][i
] = synchro_fd
;
354 synchro_fd
= status
[module
][i
];
357 if ((retval
= ioctl(synchro_fd
, ICVVME_setreenable
, &arg2
)) < 0) {
358 perror("could not do ioctl\n");
363 printf("number of line to access \n" );
364 printf("on module nr. %d ? \n", module
);
368 if ((i
< 0) || (i
>= icv_LineNb
)) {
369 printf("line number out of range\n");
372 if (status
[module
][i
] == 0) {
373 icv196_connect(synchro_fd
, module
, i
, 0);
374 status
[module
][i
] = synchro_fd
;
376 synchro_fd
= status
[module
][i
];
379 if ((retval
= ioctl(synchro_fd
, ICVVME_clearreenable
, &arg2
)) < 0) {
380 perror("could not do ioctl\n");
385 printf("Line index to access on module#%d\n", module
);
386 printf("[0 -- 15] --> ");
387 scanf("%s", line
); getchar();
390 if (!WITHIN_RANGE(0, i
, icv_LineNb
-1)) {
391 printf("idx out of range\n");
396 if (status
[module
][i
] == 0) {
397 icv196_connect(synchro_fd
, module
, i
, 0);
398 status
[module
][i
] = synchro_fd
;
400 synchro_fd
= status
[module
][i
];
405 if (ioctl(synchro_fd
, ICVVME_enable
, &arg2
) < 0)
406 perror("ICVVME_enable ioctl failed");
409 printf("number of line to access \n" );
410 printf("on module nr. %d ? \n", module
);
414 if ((i
< 0) || (i
>= icv_LineNb
)) {
415 printf("line number out of range\n");
418 if (status
[module
][i
] == 0) {
419 icv196_connect(synchro_fd
, module
, i
, 0);
420 status
[module
][i
] = synchro_fd
;
422 synchro_fd
= status
[module
][i
];
425 if ((retval
= ioctl(synchro_fd
, ICVVME_disable
, &arg2
)) < 0) {
426 perror("could not do ioctl\n");
432 printf("no line to read from\n");
435 memset(buff
, 0, sizeof(buff
));
437 if ((retval
= read(synchro_fd
, buff
, count
)) < 0) {
438 perror("could not read\n");
441 printf("EVENTS READ:\n");
444 printf("no events read\n");
448 for (i
= 0; i
< 8; i
++, evt
++) {
450 printf("evt. nr. %2d: 0x%lx ", i
, *evt
);
451 if (((i
+1) % 2) == 0 && i
!= 0)
458 printf("number of line to access \n" );
459 printf("on module nr. %d ? \n", module
);
463 if ((i
< 0) || (i
>= icv_LineNb
)) {
464 printf("line number out of range\n");
467 if (status
[module
][i
] == 0) {
468 icv196_connect(synchro_fd
, module
, i
, 0);
469 status
[module
][i
] = synchro_fd
;
471 synchro_fd
= status
[module
][i
];
474 if ((retval
= ioctl(synchro_fd
, ICVVME_wait
, &arg2
)) < 0) {
475 perror("could not do ioctl\n");
480 printf("number of line to access \n" );
481 printf("on module nr. %d ? \n", module
);
485 if ((i
< 0) || (i
>= icv_LineNb
)) {
486 printf("line number out of range\n");
489 if (status
[module
][i
] == 0) {
490 icv196_connect(synchro_fd
, module
, i
, 0);
491 status
[module
][i
] = synchro_fd
;
493 synchro_fd
= status
[module
][i
];
496 if ((retval
= ioctl(synchro_fd
, ICVVME_nowait
, &arg2
)) < 0) {
497 perror("could not do ioctl\n");
502 printf("input not correct\n");
505 } while (input
!= 0);
507 for (i
= 0; i
< icv_ModuleNb
; i
++)
508 for (j
= 0; j
< icv_LineNb
; j
++)
509 if (status
[i
][j
] != 0) icv196_disconnect(synchro_fd
, i
, j
);
511 if (icv196_put_handle(service_fd
))
517 static int init_group(int fd
, int *grp
, int dir
)
552 printf("Will initialize 2 subgroups of group %d: %d && %d\n",
553 *grp
, mt
[*grp
-1][0], mt
[*grp
-1][1]);
556 if (icv196_init_channel(fd
, module
, mt
[*grp
-1][1], 2, dir
)) {
557 printf("Failed to init group %d\n", *grp
);
561 *grp
= mt
[*grp
-1][1];
567 * @brief Test to transmit 2byte long data
575 static void transmit_data(int fd
, struct gpfd
*gpfd
)
578 char buff
[50] = { 0 }, *ptr
;
579 short *bptr
= (short*) buff
;
580 int wr_grp
, rd_grp
, rval
[2], i
;
581 short wv
; /* saved written value */
584 printf("Group index to write into [1 -- 6] (0 -- abort) --> ");
585 scanf("%d", &wr_grp
); getchar();
590 if (!(WITHIN_RANGE(1, wr_grp
, 6))) {
591 printf("Wrong write group\n");
624 printf("Group index to read from [%d, %d] (0 -- abort) --> ",
626 scanf("%d", &rd_grp
); getchar();
631 if (rd_grp
!= rval
[0] && rd_grp
!= rval
[1]) {
632 printf("Wrong read group\n");
637 if (!init_group(fd
, &wr_grp
, 1) ||
638 !init_group(fd
, &rd_grp
, 0))
641 //printf("Actual Groups: write %d read %d\n", wr_grp, rd_grp);
643 /* set new file name for read data */
644 ptr
= rindex(gpfd
->gpfn
, '.');
645 snprintf(ptr
, 4, ".rd");
647 for (i
= 0; i
< gpfd
->elam
; i
++) {
648 wv
= *bptr
= gpfd
->gpv
[i
].conv
;
650 if (icv196_write_channel(fd
, module
, wr_grp
, 2, buff
)) {
651 printf("icv196_write_channel() failed\n");
655 usleep(500); /* delay for HW to do the job */
657 if (icv196_read_channel(fd
, module
, rd_grp
, 2, buff
) < 0) {
658 printf("icv196_read_channel() failed\n");
661 usleep(500); /* delay for HW to do the job */
663 /* safe received values and put them in the file */
664 gpfd
->gpv
[i
].conv
= *bptr
;
665 //printf("Write 0x%hx Read back 0x%hx\n", wv, *bptr);
668 do_conv_gp_file(gpfd
, 0);
669 printf("Received data saved in %s file\n", gpfd
->gpfn
);