source: drsdaq/VME/struck/sis1100/V2.02/test/pipeline1.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#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#include <signal.h>
11
12#include "dev/pci/sis1100_var.h"
13
14#define swap_int(x) ((((x)>>24)&0x000000ff) |\
15 (((x)>> 8)&0x0000ff00) |\
16 (((x)<< 8)&0x00ff0000) |\
17 (((x)<<24)&0xff000000))
18
19#define swap_short(x) ((((x)>>8)&0x000000ff) |\
20 (((x)<<8)&0x0000ff00))
21
22int p;
23
24struct sis1100_pipelist listent={0x03010000, 0x09, 0x200fc, 0};
25
26struct sis1100_pipelist* list;
27
28static int pipeline_read(int p, struct sis1100_pipelist* list, int listlen,
29 u_int32_t* data)
30{
31 struct sis1100_pipe pipe;
32
33 pipe.num=listlen;
34 pipe.list=list;
35 pipe.data=data;
36
37 if (ioctl(p, SIS1100_PIPE, &pipe)<0) {
38 printf("ioctl(SIS1100_PIPE): %s\n", strerror(errno));
39 return -1;
40 }
41 if (pipe.error) printf("error=0x%x\n", pipe.error);
42 return 0;
43}
44
45volatile int stop=0;
46
47static void hand(int sig)
48{
49printf("signal %d\n", sig);
50stop=1;
51}
52
53int main(int argc, char* argv[])
54{
55 int num, loopcount, i, j, *data;
56 int *comp, comp_valid, dot, debug;
57 struct sigaction act;
58
59 if (argc<5)
60 {
61 fprintf(stderr, "usage: %s path reqcount loopcount debug\n", argv[0]);
62 return 1;
63 }
64 if ((p=open(argv[1], O_RDWR, 0))<0) {
65 perror("open");
66 return 1;
67 }
68
69 num=atoi(argv[2]);
70 loopcount=atoi(argv[3]);
71 debug=atoi(argv[4]);
72
73 act.sa_handler=hand;
74 sigemptyset(&act.sa_mask);
75 act.sa_flags=0;
76 sigaction(SIGINT, &act, 0);
77 sigaction(SIGQUIT, &act, 0);
78
79 printf("listlen=%d; loopcount=%d\n", num, loopcount);
80
81 list=(struct sis1100_pipelist*)malloc(num*sizeof(struct sis1100_pipelist));
82 data=(u_int32_t*)malloc(num*sizeof(u_int32_t));
83 comp=(u_int32_t*)malloc(num*sizeof(u_int32_t));
84 comp_valid=0;
85
86 if (!data || !list || !comp) {
87 printf("malloc: %s\n", strerror(errno));
88 return 1;
89 }
90 for (i=0; i<num; i++) list[i]=listent;
91 if (!debug)
92 for (i=0; i<num; i++) data[i]=0x12345678; /* just for test */
93 dot=10000/num;
94 for (j=0; j<loopcount; j++) {
95 if (stop || (pipeline_read(p, list, num, data)<0)) goto raus;
96 if (!debug) {
97 if (comp_valid) {
98 for (i=0; i<num; i++) {
99 if (comp[i]!=data[i]) printf("[%d] %08x-->%08x\n",
100 i, comp[i], data[i]);
101 }
102 } else {
103 for (i=0; i<num; i++) comp[i]=data[i];
104 comp_valid=1;
105 }
106 }
107 if ((j%dot)==0) {printf("."); fflush(stdout);}
108 }
109raus:
110 printf("tranferred %d words\n", j*num);
111 /*
112 for (i=0; i<num; i++)
113 printf("[%2d] %x: %08x\n", i, list[i].addr, swap_int(data[i])&0xffff);
114 */
115 close(p);
116 return 0;
117}
Note: See TracBrowser for help on using the repository browser.