Added ex09b
[des2015.git] / natanael / ex09 / ex09a1.c
1 #include <stdio.h>
2 #include <signal.h>
3 #include <unistd.h>
4 #include <sys/mman.h>
5 #include <native/intr.h>
6 #include <sys/io.h>
7 #include <native/task.h>
8
9 RT_INTR keypress;
10 RT_TASK key_isr;
11 #define PARPORT_IRQ 7
12
13 unsigned char byte;
14
15 void key_handler(void *arg)
16 {
17 int count = 0;
18 int nr_interrupts_waiting;
19 while(1) {
20 rt_printf("%d\n",count++);
21 nr_interrupts_waiting = rt_intr_wait(&keypress,TM_INFINITE);
22 if (nr_interrupts_waiting>0)
23 {
24 }
25 }
26 }
27
28 //startup code
29 void startup()
30 {
31 rt_intr_create(&keypress, NULL, PARPORT_IRQ, I_PROPAGATE);
32 enable_interupt();
33
34 rt_task_create(&key_isr, NULL,0,50,0);
35 rt_task_start(&key_isr, &key_handler, NULL);
36
37 }
38
39 void init_xenomai() {
40 /* Avoids memory swapping for this program */
41 mlockall(MCL_CURRENT|MCL_FUTURE);
42
43 /* Perform auto-init of rt_print buffers if the task doesn't do so */
44 rt_print_auto_init(1);
45 }
46
47 void enable_interupt()
48 {
49 ioperm(0x37A, 1, 1);
50 byte = inb(0x37A);
51 byte = byte | 0x10; /* hex 10 = 00010000 */
52 outb(byte, 0x37A);
53 }
54
55 void disable_interupt()
56 {
57 byte = inb(0x37A);
58 byte = byte & 0xEF; /* hex EF = binary 11101111 */
59 outb(byte, 0x37A);
60 }
61
62 int main(int argc, char* argv[])
63 {
64 printf("\nType CTRL-C to end this program\n\n" );
65
66 // code to set things to run xenomai
67 init_xenomai();
68
69 //startup code
70 startup();
71
72 // wait for CTRL-c is typed to end the program
73 pause();
74
75 disable_interupt();
76 }