source: drsdaq/VME/struck/sis1100/V2.02/test/iotest.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: 4.0 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
14int ngf_base=0xe00000;
15
16#define SFI_W(info, x, v) (((sfi_w)(info)->base)->x=H2SFI(v))
17#define SEQ_W(info, x, v) SFI_W(info, seq[x], v)
18
19/****************************************************************************/
20static int vme_read(int p, int base, int addr)
21{
22 int res;
23 struct sis1100_vme_req req;
24
25 req.size=4;
26 req.am=0x9;
27 req.addr=base+addr;
28 res=ioctl(p, SIS3100_VME_READ, &req);
29 if (res)
30 printf("vme read 0x%08x: res=%s, error=0x%x\n",
31 req.addr, strerror(errno), req.error);
32 return req.data;
33}
34/****************************************************************************/
35static void vme_write(int p, int base, int addr, int data)
36{
37 int res;
38 struct sis1100_vme_req req;
39
40 req.size=4;
41 req.am=0x9;
42 req.addr=base+addr;
43 req.data=data;
44 res=ioctl(p, SIS3100_VME_WRITE, &req);
45 if (res)
46 printf("vme write 0x%08x, 0x%08x: res=%s, error=0x%x\n",
47 req.addr, req.data, strerror(errno), req.error);
48}
49/****************************************************************************/
50static void ngf_status(int p)
51{
52 printf("===============\n");
53 printf("[2020] = %04X\n", vme_read(p, ngf_base, 0x2020)&0xffff);
54}
55/****************************************************************************/
56volatile int idx, irq, irqcount=0;
57
58static void sighnd(int sig)
59{
60 irq++; irqcount++;
61 fprintf(stderr, "got sig %d\n", sig);
62}
63/****************************************************************************/
64int main(int argc, char* argv[])
65{
66 int p, i;
67 struct sigaction action, old_action;
68 struct sis1100_irq_ctl irqctl;
69 struct sis1100_irq_get irqget;
70 struct sis1100_irq_ack irqack;
71 sigset_t mask, old_mask;
72
73 if (argc!=2)
74 {
75 fprintf(stderr, "usage: %s path\n", argv[0]);
76 return 1;
77 }
78
79 if ((p=open(argv[1], O_RDWR, 0))<0) return 1;
80
81 action.sa_handler=sighnd;
82 sigemptyset(&action.sa_mask);
83 action.sa_flags=0;
84 sigaction(SIGUSR1, &action, &old_action);
85
86 sigemptyset(&mask);
87 sigaddset(&mask, SIGUSR1);
88 sigprocmask(SIG_BLOCK, &mask, &old_mask);
89
90 irqctl.irq_mask=0xffff; /* ALL IRQs; just for fun */
91 irqctl.signal=SIGUSR1;
92 if (ioctl(p, SIS1100_IRQ_CTL, &irqctl)<0) {
93 fprintf(stderr, "ioctl(SIS3100_IRQ_CTL): %s\n", strerror(errno));
94 return 1;
95 }
96
97 for (i=0; i<7; i++) {
98 int v;
99 v=0xff0000;
100 if (ioctl(p, SIS1100_FRONT_IO, &v)) {
101 fprintf(stderr, "ioctl(SIS1100_FRONT_IO): %s\n", strerror(errno));
102 return 1;
103 }
104 v=1<<i;
105 if (ioctl(p, SIS1100_FRONT_IO, &v)) {
106 fprintf(stderr, "ioctl(SIS1100_FRONT_IO): %s\n", strerror(errno));
107 return 1;
108 }
109 v=0;
110 if (ioctl(p, SIS1100_FRONT_IO, &v)) {
111 fprintf(stderr, "ioctl(SIS1100_FRONT_IO): %s\n", strerror(errno));
112 return 1;
113 }
114 printf("%d: 0x%08x\n", i, v);
115 }
116
117
118 sigsuspend(&old_mask);
119 fprintf(stderr, "after suspend\n");
120
121 irqget.irq_mask=0xffff;
122 irqget.immediate_ack=0;
123 if (ioctl(p, SIS1100_IRQ_GET, &irqget)<0) {
124 fprintf(stderr, "ioctl(SIS3100_IRQ_GET): %s\n", strerror(errno));
125 return 1;
126 }
127 printf("got level 0x%x vector 0x%x\n", irqget.irq_mask, irqget.vector);
128
129 vme_write(p, ngf_base, 0x2038, 0); /* clear seq. command flag */
130 ngf_status(p);
131
132 irqack.irq_mask=irqget.irq_mask;
133 if (ioctl(p, SIS1100_IRQ_ACK, &irqack)<0) {
134 fprintf(stderr, "ioctl(SIS3100_IRQ_ACK): %s\n", strerror(errno));
135 return 1;
136 }
137 sigaction(SIGUSR1, &old_action, 0);
138
139 close(p);
140 return 0;
141}
142/****************************************************************************/
143/****************************************************************************/
Note: See TracBrowser for help on using the repository browser.