ex09 done with lpt
authordopefishh <mart@martlubbers.net>
Fri, 25 Sep 2015 11:04:29 +0000 (13:04 +0200)
committerdopefishh <mart@martlubbers.net>
Fri, 25 Sep 2015 11:04:29 +0000 (13:04 +0200)
mart/ex09/Makefile
mart/ex09/ex09a1.c
mart/ex09/ex09a2.c
mart/ex09/ex09b.c [new file with mode: 0644]
mart/ex09/explanations.txt

index 8826d35..690a5d1 100644 (file)
@@ -3,7 +3,7 @@ LDFLAGS=$(shell xeno-config --xeno-ldflags)\
        -lnative -lrtdk -Xlinker -rpath\
        -Xlinker $(shell xeno-config --libdir)
 
-BINARIES=ex09a1 ex09a2
+BINARIES=ex09a1 ex09a2 ex09b
 
 all: $(BINARIES)
 
index fdd2f28..faa29fe 100644 (file)
@@ -17,9 +17,10 @@ void keyboard_handler(void *arg)
 {
        RT_INTR intr;
        rt_intr_create(&intr, "keyboard handler", KBDIRQ, I_PROPAGATE);
-       int keypresses = 0;
+       int kps = 0;
        while(1){
-               rt_printf("#Keypresses: %d\n", keypresses += rt_intr_wait(&intr, TM_INFINITE));
+               rt_printf("#Kbd interrupt %d\n",
+                kps += rt_intr_wait(&intr, TM_INFINITE));
        }
 }
 
index bac6c53..b702176 100644 (file)
@@ -32,9 +32,9 @@ void keyboard_handler(void *arg)
        RT_TASK_INFO ctaskinfo;
        ctask = rt_task_self();
        rt_intr_create(&intr, "keyboard handler", KBDIRQ, I_PROPAGATE);
-       int keypresses = 0;
+       int kps = 0;
        while(1){
-               rt_printf("#Keypresses: %d\n", keypresses += rt_intr_wait(&intr, TM_INFINITE));
+               rt_printf("Kbd interrupts: %d\n", kps += rt_intr_wait(&intr, TM_INFINITE));
                rt_task_inquire(ctask, &ctaskinfo);
                rt_printf("Prio: %d\n", ctaskinfo.cprio);
        }
diff --git a/mart/ex09/ex09b.c b/mart/ex09/ex09b.c
new file mode 100644 (file)
index 0000000..f7e37a5
--- /dev/null
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/io.h>
+
+#include <native/task.h>
+#include <native/timer.h>
+#include <native/intr.h>
+
+#include <rtdk.h>
+
+#define LPT1IRQ 7
+
+RT_TASK task;
+
+void lpt1_handler(void *arg)
+{
+       RT_INTR intr;
+       rt_intr_create(&intr, "lpt1 handler", LPT1IRQ, 0);
+       int bps = 0;
+       while(1){
+               rt_printf("lpt1 interrupt: %d\n",
+                bps += rt_intr_wait(&intr, TM_INFINITE));
+       }
+}
+
+int main(int argc, char* argv[])
+{
+       rt_print_auto_init(1);
+
+    /* setup lpt1 */
+    ioperm(0x37A, 1, 1);
+    unsigned char byte = inb(0x37A);
+    byte |= 0x10;
+    outb(byte, 0x37A);
+
+       mlockall(MCL_CURRENT | MCL_FUTURE);
+
+       rt_task_create(&task, "task", 0, 50, 0);
+       rt_task_start(&task, &lpt1_handler, 0);
+
+       rt_printf("CRTL+C to stop\n");
+       pause();
+
+    /* break down lpt1 */
+    byte = inb(0x37A);
+    byte &= 0xEF;
+    outb(byte, 0x37A);
+}
index 54b14f3..de218af 100644 (file)
@@ -1,7 +1,10 @@
 9a1.
-The program just prints the number of keypresses
+The program just prints the number of keyboard interrupts, these are interrupts for press, release and hold.
 
 9a2.
 It happens that within the spinning the keyboard handler prints the number of
 keypresses. This is because the priority is set to 257 because it's an
 interrupt handler.
+
+9b.
+The program prints all interrupts, so a different for press and release.