finished ex09a
authorroot <root@xenomailinux.localdomain>
Wed, 23 Sep 2015 14:39:33 +0000 (16:39 +0200)
committerroot <root@xenomailinux.localdomain>
Wed, 23 Sep 2015 14:39:33 +0000 (16:39 +0200)
mart/ex09/Makefile [new file with mode: 0644]
mart/ex09/ex09a1.c [new file with mode: 0644]
mart/ex09/ex09a2.c [new file with mode: 0644]
mart/ex09/explanations.txt [new file with mode: 0644]

diff --git a/mart/ex09/Makefile b/mart/ex09/Makefile
new file mode 100644 (file)
index 0000000..8826d35
--- /dev/null
@@ -0,0 +1,11 @@
+CFLAGS=$(shell xeno-config --xeno-cflags)
+LDFLAGS=$(shell xeno-config --xeno-ldflags)\
+       -lnative -lrtdk -Xlinker -rpath\
+       -Xlinker $(shell xeno-config --libdir)
+
+BINARIES=ex09a1 ex09a2
+
+all: $(BINARIES)
+
+clean:
+       $(RM) -v $(BINARIES)
diff --git a/mart/ex09/ex09a1.c b/mart/ex09/ex09a1.c
new file mode 100644 (file)
index 0000000..fdd2f28
--- /dev/null
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <native/task.h>
+#include <native/timer.h>
+#include <native/intr.h>
+
+#include <rtdk.h>
+
+#define KBDIRQ 1
+
+RT_TASK task;
+
+void keyboard_handler(void *arg)
+{
+       RT_INTR intr;
+       rt_intr_create(&intr, "keyboard handler", KBDIRQ, I_PROPAGATE);
+       int keypresses = 0;
+       while(1){
+               rt_printf("#Keypresses: %d\n", keypresses += rt_intr_wait(&intr, TM_INFINITE));
+       }
+}
+
+int main(int argc, char* argv[])
+{
+       /* Perform auto-init of rt_print buffers if the task doesn't do so */
+       rt_print_auto_init(1);
+
+       /* Avoids memory swapping for this program */
+       mlockall(MCL_CURRENT | MCL_FUTURE);
+
+       rt_task_create(&task, "task", 0, 50, 0);
+       rt_task_start(&task, &keyboard_handler, 0);
+
+       rt_printf("CRTL+C to stop\n");
+       pause();
+}
diff --git a/mart/ex09/ex09a2.c b/mart/ex09/ex09a2.c
new file mode 100644 (file)
index 0000000..bac6c53
--- /dev/null
@@ -0,0 +1,57 @@
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <native/task.h>
+#include <native/timer.h>
+#include <native/intr.h>
+
+#include <rtdk.h>
+
+#define KBDIRQ 1
+
+RT_TASK task;
+RT_TASK dummy_task;
+
+void dummy_task_function(void *arg)
+{
+       int i;
+       while(1){
+               rt_task_sleep(1e7); //let linux system have time to kill the program
+               rt_printf("Dummy task spinning\n");
+               rt_timer_spin(1e9);
+               rt_printf("Dummy task stopped\n");
+       }
+}
+
+void keyboard_handler(void *arg)
+{
+       RT_INTR intr;
+       RT_TASK *ctask;
+       RT_TASK_INFO ctaskinfo;
+       ctask = rt_task_self();
+       rt_intr_create(&intr, "keyboard handler", KBDIRQ, I_PROPAGATE);
+       int keypresses = 0;
+       while(1){
+               rt_printf("#Keypresses: %d\n", keypresses += rt_intr_wait(&intr, TM_INFINITE));
+               rt_task_inquire(ctask, &ctaskinfo);
+               rt_printf("Prio: %d\n", ctaskinfo.cprio);
+       }
+}
+
+int main(int argc, char* argv[])
+{
+       rt_print_auto_init(1);
+
+       mlockall(MCL_CURRENT | MCL_FUTURE);
+
+       rt_task_create(&task, "task", 0, 50, 0);
+       rt_task_create(&dummy_task, "dummy_task", 0, 51, 0);
+
+       rt_task_start(&task, &keyboard_handler, 0);
+       rt_task_start(&dummy_task, &dummy_task_function, 0);
+
+       rt_printf("CRTL+C to stop\n");
+       pause();
+}
diff --git a/mart/ex09/explanations.txt b/mart/ex09/explanations.txt
new file mode 100644 (file)
index 0000000..54b14f3
--- /dev/null
@@ -0,0 +1,7 @@
+9a1.
+The program just prints the number of keypresses
+
+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.