-lnative -lrtdk -Xlinker -rpath\
-Xlinker $(shell xeno-config --libdir)
-BINARIES=ex09a1 ex09a2
+BINARIES=ex09a1 ex09a2 ex09b
all: $(BINARIES)
{
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));
}
}
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);
}
--- /dev/null
+#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);
+}
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.