source: drsdaq/VME/struck/sis1100/V2.02/test/irqtest_ngf.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: 3.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
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;
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 irq_mask; 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 vme_write(p, ngf_base, 0x201c, 0); /* reset */
98 vme_write(p, ngf_base, 0x2030, 0); /* reset sequencer */
99 vme_write(p, ngf_base, 0x2038, 0); /* clear seq. command flag */
100 ngf_status(p);
101 vme_write(p, ngf_base, 0x2020, 0); /* start sequencer */
102 vme_write(p, ngf_base, 0x2010, 0x977); /* irq level */
103 vme_write(p, ngf_base, 0x2014, 0xff); /* irq mask */
104 ngf_status(p);
105 vme_write(p, ngf_base, 0x10000+0x68, 0); /* set seq. command flag */
106 ngf_status(p);
107
108 sigsuspend(&old_mask);
109 fprintf(stderr, "after suspend\n");
110
111 irqget.irq_mask=0xffff;
112 irqget.immediate_ack=0;
113 if (ioctl(p, SIS1100_IRQ_GET, &irqget)<0) {
114 fprintf(stderr, "ioctl(SIS3100_IRQ_GET): %s\n", strerror(errno));
115 return 1;
116 }
117 printf("got level 0x%x vector 0x%x\n", irqget.irq_mask, irqget.vector);
118
119 vme_write(p, ngf_base, 0x2038, 0); /* clear seq. command flag */
120 ngf_status(p);
121
122 irqack.irq_mask=irqget.irq_mask;
123 if (ioctl(p, SIS1100_IRQ_ACK, &irqack)<0) {
124 fprintf(stderr, "ioctl(SIS3100_IRQ_ACK): %s\n", strerror(errno));
125 return 1;
126 }
127 sigaction(SIGUSR1, &old_action, 0);
128
129 close(p);
130 return 0;
131}
132/****************************************************************************/
133/****************************************************************************/
Note: See TracBrowser for help on using the repository browser.