source: drsdaq/VME/struck/sis1100/V2.02/test/read_write_driver_a.c@ 23

Last change on this file since 23 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
File size: 1.7 KB
Line 
1#define _GNU_SOURCE
2#include <stdio.h>
3#include <errno.h>
4#include <string.h>
5#include <sys/types.h>
6#include <unistd.h>
7#include <fcntl.h>
8#include <sys/mman.h>
9#include <sys/ioctl.h>
10
11#include "dev/pci/sis1100_var.h"
12
13int p;
14
15/****************************************************************************/
16static void printerror(struct sis1100_vme_req* req, int _errno, int write)
17{
18if (write)
19 printf("vme write 0x%08x to 0x%08x", req->data, req->addr);
20else
21 printf("vme read 0x%08x", req->addr);
22
23printf(": %s", strerror(_errno));
24if (_errno==EIO) printf("; protocoll error 0x%x", req->error);
25printf("\n");
26}
27/****************************************************************************/
28int main(int argc, char* argv[])
29{
30int i;
31struct sis1100_vme_req req;
32u_int32_t base;
33
34if (argc<2)
35 {
36 fprintf(stderr, "usage: %s path\n", argv[0]);
37 return 1;
38 }
39if ((p=open(argv[1], O_RDWR, 0))<0) return 1;
40
41req.size=2; /* driver does not change any field except data */
42req.am=0x9; /* "" */
43
44printf("search for CAEN-Modules:\n");
45for (i=0, base=0; i<10; i++, base+=0x10000) {
46 req.addr=base+0xfa;
47 if (ioctl(p, SIS3100_VME_READ, &req)<0) {
48 printerror(&req, errno, 0);
49 } else {
50 printf("data=0x%08x\n", req.data);
51 if (req.data==0xfaf5) { /* CAEN-Module */
52 u_int16_t type, serial;
53 req.addr=base+0xfc;
54 if (ioctl(p, SIS3100_VME_READ, &req)<0) {
55 printerror(&req, errno, 0); return 1;
56 }
57 type=req.data;
58 req.addr=base+0xfe;
59 if (ioctl(p, SIS3100_VME_READ, &req)<0) {
60 printerror(&req, errno, 0); return 1;
61 }
62 serial=req.data;
63 printf("at 0x%x: type=0x%x; serial=%d\n", base, type, serial&0xfff);
64 }
65 }
66}
67
68close(p);
69return 0;
70}
Note: See TracBrowser for help on using the repository browser.