source: drsdaq/VME/struck/sis1100/V2.02/examples/irqs/link_irq/linkirqtest.c@ 23

Last change on this file since 23 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
  • Property svn:executable set to *
File size: 2.7 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 if (ioctl(p, SIS3100_FRONT_IO, 0xef)<0) {
37 perror("SIS3100_FRONT_IO");
38 return -1;
39 }
40
41
42 sigemptyset(&mask);
43 sigaddset(&mask, SIGUSR1);
44 sigaddset(&mask, SIGUSR2);
45 sigprocmask(SIG_BLOCK, &mask, &old_mask);
46
47 if ((p=open(argv[1], O_RDWR, 0))<0) return 1;
48
49 action.sa_handler=sighnd;
50 sigemptyset(&action.sa_mask);
51 action.sa_flags=0;
52 sigaction(SIGUSR1, &action, 0);
53 sigaction(SIGUSR2, &action, 0);
54
55 irqctl.irq_mask=0;
56 irqctl.signal=SIGUSR1;
57 if (ioctl(p, SIS1100_IRQ_CTL, &irqctl)<0) {
58 fprintf(stderr, "ioctl(SIS1100_IRQ_CTL): %s\n", strerror(errno));
59 return 1;
60 }
61
62 while (1) {
63 u_int32_t io_bits;
64
65 sigsuspend(&old_mask);
66
67 irqget.irq_mask=0;
68 irqget.immediate_ack=0;
69 if (ioctl(p, SIS1100_IRQ_GET, &irqget)<0) {
70 fprintf(stderr, "ioctl(SIS1100_IRQ_GET): %s\n", strerror(errno));
71 return 1;
72 }
73 switch (irqget.remote_status) {
74 case -1:
75 printf("Link down\n");
76 io_bits=(3<<26) | (1<<23);
77 ioctl(p, SIS1100_FRONT_IO, &io_bits);
78 break;
79 case 1:
80 printf("Link up\n");
81 io_bits=(3<<10) | (1<<7);
82 ioctl(p, SIS1100_FRONT_IO, &io_bits);
83 break;
84 default:
85 printf("ERROR: got irqs=%08x, remote_status=%d\n",
86 irqget.irqs, irqget.remote_status);
87 }
88 irqack.irq_mask=irqget.irqs;
89 if (ioctl(p, SIS1100_IRQ_ACK, &irqack)<0) {
90 fprintf(stderr, "ioctl(SIS1100_IRQ_ACK): %s\n", strerror(errno));
91 return 1;
92 }
93 }
94
95 close(p);
96 return 0;
97}
98/****************************************************************************/
99/****************************************************************************/
Note: See TracBrowser for help on using the repository browser.