source: drsdaq/VME/struck/sis1100/V2.02/test/linkirqtest.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.5 KB
Line 
1#define _GNU_SOURCE
2#include <stdio.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <string.h>
6#include <sys/types.h>
7#include <unistd.h>
8#include <fcntl.h>
9#include <sys/mman.h>
10#include <sys/ioctl.h>
11#include <signal.h>
12
13#include "dev/pci/sis1100_var.h"
14
15/****************************************************************************/
16static void sighnd(int sig)
17{
18 fprintf(stderr, "got sig %d\n", sig);
19}
20/****************************************************************************/
21int main(int argc, char* argv[])
22{
23 int p;
24 struct sigaction action;
25 struct sis1100_irq_ctl irqctl;
26 struct sis1100_irq_get irqget;
27 struct sis1100_irq_ack irqack;
28 sigset_t mask, old_mask;
29
30 if (argc!=2)
31 {
32 fprintf(stderr, "usage: %s path\n", argv[0]);
33 return 1;
34 }
35
36 sigemptyset(&mask);
37 sigaddset(&mask, SIGUSR1);
38 sigaddset(&mask, SIGUSR2);
39 sigprocmask(SIG_BLOCK, &mask, &old_mask);
40
41 if ((p=open(argv[1], O_RDWR, 0))<0) return 1;
42
43 action.sa_handler=sighnd;
44 sigemptyset(&action.sa_mask);
45 action.sa_flags=0;
46 sigaction(SIGUSR1, &action, 0);
47 sigaction(SIGUSR2, &action, 0);
48
49 irqctl.irq_mask=0;
50 irqctl.signal=SIGUSR1;
51 if (ioctl(p, SIS1100_IRQ_CTL, &irqctl)<0) {
52 fprintf(stderr, "ioctl(SIS1100_IRQ_CTL): %s\n", strerror(errno));
53 return 1;
54 }
55
56 while (1) {
57 u_int32_t io_bits;
58
59 sigsuspend(&old_mask);
60
61 irqget.irq_mask=0;
62 irqget.immediate_ack=0;
63 if (ioctl(p, SIS1100_IRQ_GET, &irqget)<0) {
64 fprintf(stderr, "ioctl(SIS1100_IRQ_GET): %s\n", strerror(errno));
65 return 1;
66 }
67 switch (irqget.remote_status) {
68 case -1:
69 printf("Link down\n");
70 io_bits=(3<<26) | (1<<23);
71 ioctl(p, SIS1100_FRONT_IO, &io_bits);
72 break;
73 case 1:
74 printf("Link up\n");
75 io_bits=(3<<10) | (1<<7);
76 ioctl(p, SIS1100_FRONT_IO, &io_bits);
77 break;
78 default:
79 printf("ERROR: got irqs=%08x, remote_status=%d\n",
80 irqget.irqs, irqget.remote_status);
81 }
82 irqack.irq_mask=irqget.irqs;
83 if (ioctl(p, SIS1100_IRQ_ACK, &irqack)<0) {
84 fprintf(stderr, "ioctl(SIS1100_IRQ_ACK): %s\n", strerror(errno));
85 return 1;
86 }
87 }
88
89 close(p);
90 return 0;
91}
92/****************************************************************************/
93/****************************************************************************/
Note: See TracBrowser for help on using the repository browser.