initial skeleton ex11
authorMart Lubbers <mart@martlubbers.net>
Thu, 8 Oct 2015 18:35:16 +0000 (20:35 +0200)
committerMart Lubbers <mart@martlubbers.net>
Thu, 8 Oct 2015 18:35:16 +0000 (20:35 +0200)
mart/ex11/ex11.c

index e69de29..a9fd350 100644 (file)
@@ -0,0 +1,54 @@
+#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
+#define TESTSAMPLES 20
+
+RT_TASK task;
+RTIME times[SAMPLES];
+
+void taskf(void *arg)
+{
+       //Register as interrupt handler
+       RT_INTR intr;
+       rt_intr_create(&intr, NULL, LPT1IRQ, 0);
+
+       //Measure average time of the clock
+       RTIME dur = rt_timer_read();
+       unsigned int i;
+       for(i = 0; i<TESTSAMPLES; i++){
+               rt_intr_wait(&intr, TM_INFINITE);
+       }
+       dur = rt_timer_read() / TESTSAMPLES;
+       rt_printf("%d interrupts: average time: %.2f\n", TESTSAMPLES, dur);
+
+       //Do the magic
+       while(1){
+               rt_intr_wait(&intr, TM_INFINITE);
+       }
+}
+
+int main(int argc, char* argv[])
+{
+       rt_print_auto_init(1);
+       mlockall(MCL_CURRENT | MCL_FUTURE);
+
+       // Get permission to write to parallel port
+       ioperm(0x37A, 1, 1);
+       ioperm(0x378, 1, 1);
+       outb(inb(0x37A) | 0x10, 0x37A);
+
+       rt_task_create(&task, NULL, 0, 50, 0);
+       rt_task_start(&task, &taskf, 0);
+
+       pause();
+}