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 |
|
---|
13 | #define swap_int(x) ((((x)>>24)&0x000000ff) |\
|
---|
14 | (((x)>> 8)&0x0000ff00) |\
|
---|
15 | (((x)<< 8)&0x00ff0000) |\
|
---|
16 | (((x)<<24)&0xff000000))
|
---|
17 | #define swap_short(x) ((((x)>>8)&0x000000ff) |\
|
---|
18 | (((x)<<8)&0x0000ff00))
|
---|
19 |
|
---|
20 | /****************************************************************************/
|
---|
21 | static int read_local(int p, u_int32_t offs, u_int32_t* data)
|
---|
22 | {
|
---|
23 | struct sis1100_ctrl_reg reg;
|
---|
24 |
|
---|
25 | reg.offset=offs;
|
---|
26 | if (ioctl(p, SIS1100_CONTROL_READ, ®)<0)
|
---|
27 | {
|
---|
28 | fprintf(stderr, "ioctl(SIS1100_CONTROL_READ, offs=0x%x): %s\n",
|
---|
29 | offs, strerror(errno));
|
---|
30 | return -1;
|
---|
31 | }
|
---|
32 | *data=reg.val;
|
---|
33 | return 0;
|
---|
34 | }
|
---|
35 | /****************************************************************************/
|
---|
36 | static int write_local(int p, u_int32_t offs, u_int32_t data)
|
---|
37 | {
|
---|
38 | struct sis1100_ctrl_reg reg;
|
---|
39 |
|
---|
40 | reg.offset=offs;
|
---|
41 | reg.val=data;
|
---|
42 | if (ioctl(p, SIS1100_CONTROL_WRITE, ®)<0)
|
---|
43 | {
|
---|
44 | fprintf(stderr, "ioctl(SIS1100_CONTROL_WRITE, offs=0x%x): %s\n",
|
---|
45 | offs, strerror(errno));
|
---|
46 | return -1;
|
---|
47 | }
|
---|
48 | return 0;
|
---|
49 | }
|
---|
50 | /****************************************************************************/
|
---|
51 | /* !!! hier ist alles D16 */
|
---|
52 | static int vme_read(int p, u_int32_t addr, u_int16_t* val)
|
---|
53 | {
|
---|
54 | u_int32_t head, be, error, _val;
|
---|
55 |
|
---|
56 | if (addr&2) {
|
---|
57 | be=0xc;
|
---|
58 | addr&=~2;
|
---|
59 | } else
|
---|
60 | be=0x3;
|
---|
61 |
|
---|
62 |
|
---|
63 | head=(be<<24)|0x010802; /* remote space 1, am, start with address */
|
---|
64 | if (write_local(p, 0x80, head)<0) return -1; /* t_hdr */
|
---|
65 | if (write_local(p, 0x84, 9)<0) return -1; /* t_am */
|
---|
66 | if (write_local(p, 0x88, addr)<0) return -1; /* t_adl */
|
---|
67 |
|
---|
68 | do {
|
---|
69 | if(read_local(p, 0xac, &error)<0) return -1; /* prot_error */
|
---|
70 | } while (error==0x005); /* deadlock */
|
---|
71 |
|
---|
72 | if (error) {
|
---|
73 | printf("vme_read 0x%08x: err=0x%x\n", addr, error);
|
---|
74 | return -1;
|
---|
75 | }
|
---|
76 | if (read_local(p, 0xa0, &_val)<0) return -1; /* tc_dal */
|
---|
77 | *val=swap_int(_val);
|
---|
78 | return 0;
|
---|
79 | }
|
---|
80 | /****************************************************************************/
|
---|
81 | static int vme_write(int p, u_int32_t addr, u_int16_t val)
|
---|
82 | {
|
---|
83 | u_int32_t head, be, error, _val;
|
---|
84 |
|
---|
85 | _val=swap_int(val);
|
---|
86 | if (addr&2) {
|
---|
87 | be=0xc;
|
---|
88 | addr&=~2;
|
---|
89 | } else
|
---|
90 | be=0x3;
|
---|
91 | head=(be<<24)|0x010c02; /* remote space 1, am, write, start with address */
|
---|
92 | if (write_local(p, 0x80, head)<0) return -1; /* t_hdr */
|
---|
93 | if (write_local(p, 0x84, 9)<0) return -1; /* t_am */
|
---|
94 | if (write_local(p, 0x90, _val)<0) return -1; /* t_dal */
|
---|
95 | if (write_local(p, 0x88, addr)<0) return -1; /* t_adl */
|
---|
96 |
|
---|
97 | do {
|
---|
98 | error=read_local(p, 0xac, &error); /* prot_error */
|
---|
99 | } while (error==0x005); /* deadlock */
|
---|
100 |
|
---|
101 | if (error) {
|
---|
102 | printf("vme_write 0x%08x: err=0x%x\n", addr, error);
|
---|
103 | return -1;
|
---|
104 | }
|
---|
105 | return 0;
|
---|
106 | }
|
---|
107 | /****************************************************************************/
|
---|
108 | int main(int argc, char* argv[])
|
---|
109 | {
|
---|
110 | int p;
|
---|
111 | int i;
|
---|
112 | u_int32_t base;
|
---|
113 | u_int16_t data;
|
---|
114 |
|
---|
115 | if (argc<2)
|
---|
116 | {
|
---|
117 | fprintf(stderr, "usage: %s path\n", argv[0]);
|
---|
118 | return 1;
|
---|
119 | }
|
---|
120 | if ((p=open(argv[1], O_RDWR, 0))<0) return 1;
|
---|
121 |
|
---|
122 | printf("search for CAEN-Modules:\n");
|
---|
123 | for (i=0, base=0; i<10; i++, base+=0x10000) {
|
---|
124 | if (vme_read(p, base+0xfa, &data)==0) { /* kein Fehler */
|
---|
125 | if (data==0xfaf5) { /* CAEN-Module */
|
---|
126 | u_int16_t type, serial;
|
---|
127 | if (vme_read(p, base+0xfc, &type)<0) return -1;
|
---|
128 | if (vme_read(p, base+0xfe, &serial)<0) return -1;
|
---|
129 | printf("at 0x%x: type=0x%x; serial=%d\n", base, type, serial&0xfff);
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | close(p);
|
---|
136 | return 0;
|
---|
137 | }
|
---|