up io error count if not exiting
[tridge/junkcode.git] / irq.c
1 #define __USE_BSD_SIGNAL 1
2
3 #define IRQ 4
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <signal.h>
8 #include <sys/ioctl.h>
9 #include <sys/types.h>
10 #include <fcntl.h>
11 #include <unistd.h>
12
13
14 #define IRQ_SET 1
15 #define IRQ_RELEASE 2
16 #define IRQ_INFO 3
17
18 struct irq_struct
19 {
20   int irq;
21   int process_id;
22   int signal_num;
23   struct file *file;
24   unsigned char *irq_buffer;
25   int buf_start;
26   int buf_count;
27   int buf_size;
28 }
29  setting;
30
31
32 int fioctl(FILE *f,int cmd,void *arg)
33 {
34 return(ioctl(fileno(f),cmd,arg));
35 }
36
37
38 void handler(int irq)
39 {
40 printf("got signal %d\n",irq);
41 }
42
43
44 main()
45 {
46 int fd = open("/dev/irq",O_RDWR);
47 char buf[10];
48 int i;
49 char c = IRQ;
50 for (i=0;i<10;i++)
51   buf[i] = IRQ;
52
53 setting.irq = IRQ;
54 setting.process_id = getpid();
55 setting.signal_num = SIGSEGV;
56 setting.buf_size = 100;
57
58 signal(SIGSEGV,handler);
59
60 printf("ioctl gave %d\n",ioctl(fd,IRQ_SET,&setting));
61
62 printf("irq %d\npid %d\nsig %d\ncount %d\nsize %d\n",
63        setting.irq,
64        setting.process_id,
65        setting.signal_num,
66        setting.buf_count,
67        setting.buf_size);
68
69 c = IRQ;
70 printf("write gave %d\n",write(fd,buf,10));
71
72 printf("info gave %d\n",ioctl(fd,IRQ_INFO,&setting));
73 printf("irq %d\npid %d\nsig %d\ncount %d\nsize %d\n",
74        setting.irq,
75        setting.process_id,
76        setting.signal_num,
77        setting.buf_count,
78        setting.buf_size);
79
80 printf("read gave %d\n",read(fd,&c,1));
81 printf("c is %d\n",(int)c);
82 printf("info gave %d\n",ioctl(fd,IRQ_INFO,&setting));
83 printf("irq %d\npid %d\nsig %d\ncount %d\nsize %d\n",
84        setting.irq,
85        setting.process_id,
86        setting.signal_num,
87        setting.buf_count,
88        setting.buf_size);
89 while (1);
90 }
91
92
93
94