source: drsdaq/VME/struck/sis1100/V2.02/test/find_sis.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: 2.8 KB
Line 
1#ifdef __linux__
2#define _LARGEFILE_SOURCE
3#define _LARGEFILE64_SOURCE
4#define _FILE_OFFSET_BITS 64
5#define LINUX_LARGEFILE O_LARGEFILE
6#else
7#define LINUX_LARGEFILE 0
8#endif
9
10#define _GNU_SOURCE
11#include <stdio.h>
12#include <errno.h>
13#include <string.h>
14#include <sys/types.h>
15#include <unistd.h>
16#include <stdlib.h>
17#include <fcntl.h>
18#include <sys/ioctl.h>
19
20#include "dev/pci/sis1100_var.h"
21
22struct caen_type {
23 int typ;
24 char* name;
25 char* descr;
26};
27
28struct caen_type caen_types[]={
29 {0x34, "V550", "C-RAMS"}, /* 64k */
30 {0x3c, "V551B", "C-RAMS Sequencer"},
31 {0x48, "V729A", "40 MHz ADC"},
32 {0x12e, "V693", "Multihit TDC"},
33 {0, 0, 0}
34};
35
36/****************************************************************************/
37static int find_caen_name(int typ)
38{
39 int i;
40 for (i=0; caen_types[i].name && caen_types[i].typ!=typ; i++);
41 if (caen_types[i].typ==typ)
42 return i;
43 else
44 return -1;
45}
46/****************************************************************************/
47static int check_sis(int p, u_int32_t addr)
48{
49 u_int32_t _addr;
50 u_int32_t v1;
51 int res, version=0;
52 char* name=0;
53 struct vmespace space;
54
55 space.am=9;
56 space.datasize=4;
57 space.swap=1;
58 space.mapit=0;
59 space.mindmalen=-1;
60
61 if (ioctl(p, SIS1100_SETVMESPACE, &space)<0) {
62 perror("SETVMESPACE");
63 return -1;
64 }
65 _addr=addr+0x4;
66 if (ioctl(p, VME_PROBE, &_addr)<0) {
67 /*perror("VME_PROBE");*/
68 return 0;
69 }
70
71 if (lseek(p, addr+0x4, SEEK_SET)==(off_t)-1) {
72 perror("lseek");
73 return -1;
74 }
75
76 res=read(p, &v1, 4);
77 if (res!=4) {
78 fprintf(stderr, "read 0x%x+0x4: %s\n", addr, strerror(errno));
79 return -1;
80 }
81 switch ((v1>>16)&0xffff) {
82 case 0x3300: name="3300"; version=v1&0xffff; break;
83 case 0x3600: name="3600"; version=(v1>>12)&0xf; break;
84 case 0x3800: name="3800"; version=(v1>>12)&0xf; break;
85 case 0x3801: name="3801"; version=(v1>>12)&0xf; break;
86 }
87
88 if (name) {
89 printf("0x%08x: SIS%s; version %d\n", addr, name, version);
90 }
91 return name!=0;
92}
93/****************************************************************************/
94int main(int argc, char* argv[])
95{
96 u_int32_t addr;
97 int p, num, idx, n, res;
98
99 if (argc<2) {
100 fprintf(stderr, "usage: %s path [num]\n", argv[0]);
101 return 1;
102 }
103 num=argc>2?atoi(argv[2]):65536;
104
105 if ((p=open(argv[1], O_RDWR|LINUX_LARGEFILE, 0))<0) {
106 fprintf(stderr, "open %s: %s\n", argv[1], strerror(errno));
107 return 1;
108 }
109
110 for (addr=0, idx=0, n=0; idx<num; idx++, addr+=0x10000) {
111 res=check_sis(p, addr);
112 if (res<0) return 0;
113 if (res>0) n++;
114 }
115
116 printf("%d module%s found\n", n, n==1?"":"s");
117 close(p);
118 return 0;
119}
Note: See TracBrowser for help on using the repository browser.