Update byte for D0
[des2015.git] / natanael / ex10 / ex10d2.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 const RTIME period = 100000;
10 const int nsamples = 10000;
11
12 RT_TASK task;
13 RTIME write_time;
14
15 RT_INTR intr;
16 #define PARPORT_IRQ 7
17 unsigned char byte;
18
19 void enable_interupt()
20 {
21 ioperm(0x37A, 1, 1);
22 byte = inb(0x37A);
23 byte = byte | 0x10; /* hex 10 = 00010000 */
24 outb(byte, 0x37A);
25
26 // enable port D0
27 ioperm(0x378, 1, 1);
28 byte = inb(0x378);
29 byte = byte | 0x01; /* hex 10 = 00010000 */
30 outb(byte, 0x378);
31 }
32
33 void disable_interupt()
34 {
35 byte = inb(0x37A);
36 byte = byte & 0xEF; /* hex EF = binary 11101111 */
37 outb(byte, 0x37A);
38 }
39
40 void send_parallel_port_intrp()
41 {
42 outb(inb(0x378) & 0xFE, 0x378);
43 outb(inb(0x378) | 0x01, 0x378); /* enable interrupt */
44 }
45
46 void do_task(void *arg)
47 {
48 for(;;)
49 {
50 send_parallel_port_intrp();
51
52 rt_intr_wait(&intr,TM_INFINITE);
53 }
54 }
55
56 //startup code
57 void startup()
58 {
59 rt_intr_create(&intr, NULL, PARPORT_IRQ, I_PROPAGATE);
60 enable_interupt();
61
62 rt_task_create(&task, NULL,0,50,0);
63 rt_task_start(&task, &do_task, NULL);
64 }
65
66 void init_xenomai() {
67 /* Avoids memory swapping for this program */
68 mlockall(MCL_CURRENT|MCL_FUTURE);
69
70 /* Perform auto-init of rt_print buffers if the task doesn't do so */
71 rt_print_auto_init(1);
72 }
73
74 int main(int argc, char* argv[])
75 {
76 printf("\nType CTRL-C to end this program\n\n" );
77
78 // code to set things to run xenomai
79 init_xenomai();
80
81 //startup code
82 startup();
83
84 // wait for CTRL-c is typed to end the program
85 pause();
86
87 disable_interupt();
88 }