source: drsdaq/VME/struck/sis1100/sis1100/V1.0/wuestner_test/pipeline1.c@ 23

Last change on this file since 23 was 23, checked in by ogrimm, 16 years ago
leftovers from last commit
File size: 2.9 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, int seq, int debug)
30{
31 struct sis1100_pipe pipe;
32
33 pipe.num=listlen;
34 pipe.list=list;
35 pipe.data=data;
36 pipe.debug=debug;
37 pipe.sequence=seq;
38
39 if (ioctl(p, SIS1100_PIPE, &pipe)<0) {
40 printf("ioctl(SIS1100_PIPE): %s\n", strerror(errno));
41 return -1;
42 }
43 if (pipe.error) printf("error=0x%x\n", pipe.error);
44 return 0;
45}
46
47volatile int stop=0;
48
49static void hand(int sig)
50{
51printf("signal %d\n", sig);
52stop=1;
53}
54
55int main(int argc, char* argv[])
56{
57 int num, loopcount, i, j, *data;
58 int *comp, comp_valid, dot, debug;
59 struct sigaction act;
60
61 if (argc<5)
62 {
63 fprintf(stderr, "usage: %s path reqcount loopcount debug\n", argv[0]);
64 return 1;
65 }
66 if ((p=open(argv[1], O_RDWR, 0))<0) {
67 perror("open");
68 return 1;
69 }
70
71 num=atoi(argv[2]);
72 loopcount=atoi(argv[3]);
73 debug=atoi(argv[4]);
74
75 act.sa_handler=hand;
76 sigemptyset(&act.sa_mask);
77 act.sa_flags=0;
78 sigaction(SIGINT, &act, 0);
79 sigaction(SIGQUIT, &act, 0);
80
81 printf("listlen=%d; loopcount=%d\n", num, loopcount);
82
83 list=(struct sis1100_pipelist*)malloc(num*sizeof(struct sis1100_pipelist));
84 data=(u_int32_t*)malloc(num*sizeof(u_int32_t));
85 comp=(u_int32_t*)malloc(num*sizeof(u_int32_t));
86 comp_valid=0;
87
88 if (!data || !list || !comp) {
89 printf("malloc: %s\n", strerror(errno));
90 return 1;
91 }
92 for (i=0; i<num; i++) list[i]=listent;
93 if (!debug)
94 for (i=0; i<num; i++) data[i]=0x12345678; /* just for test */
95 dot=10000/num;
96 for (j=0; j<loopcount; j++) {
97 if (stop || (pipeline_read(p, list, num, data, j, debug)<0)) goto raus;
98 if (!debug) {
99 if (comp_valid) {
100 for (i=0; i<num; i++) {
101 if (comp[i]!=data[i]) printf("[%d] %08x-->%08x\n",
102 i, comp[i], data[i]);
103 }
104 } else {
105 for (i=0; i<num; i++) comp[i]=data[i];
106 comp_valid=1;
107 }
108 }
109 if ((j%dot)==0) {printf("."); fflush(stdout);}
110 }
111raus:
112 printf("tranferred %d words\n", j*num);
113 /*
114 for (i=0; i<num; i++)
115 printf("[%2d] %x: %08x\n", i, list[i].addr, swap_int(data[i])&0xffff);
116 */
117 close(p);
118 return 0;
119}
Note: See TracBrowser for help on using the repository browser.