--- /dev/null
+ex9a1
+From the output, we can see that the keyboard press will trigger the interupt and the counter will increase every keyboard press.
+
+ex9a2
+The dummy task has a higher priority than the task which handle the interupt. But when the interupt is trigged, it will run the interupt first as the urgency and it become priority 257.
+
+ex9b
--- /dev/null
+###### CONFIGURATION ######
+
+### List of applications to be build
+APPLICATIONS = ex09a1 ex09a2 ex09b
+
+### Note: to override the search path for the xeno-config script, use "make XENO=..."
+
+
+### List of modules to be build
+MODULES =
+
+### Note: to override the kernel source path, use "make KSRC=..."
+
+
+
+###### USER SPACE BUILD (no change required normally) ######
+ifeq ($(KERNELRELEASE),)
+ifneq ($(APPLICATIONS),)
+
+### Default Xenomai installation path
+XENO ?= /usr/xenomai
+
+XENOCONFIG=$(shell PATH=$(XENO):$(XENO)/bin:$(PATH) which xeno-config 2>/dev/null)
+
+### Sanity check
+ifeq ($(XENOCONFIG),)
+all::
+ @echo ">>> Invoke make like this: \"make XENO=/path/to/xeno-config\" <<<"
+ @echo
+endif
+
+
+CC=$(shell $(XENOCONFIG) --cc)
+
+CFLAGS=$(shell $(XENOCONFIG) --xeno-cflags) $(MY_CFLAGS)
+
+LDFLAGS=$(shell $(XENOCONFIG) --xeno-ldflags) $(MY_LDFLAGS) -lnative
+
+# This includes the library path of given Xenomai into the binary to make live
+# easier for beginners if Xenomai's libs are not in any default search path.
+LDFLAGS+=-Xlinker -rpath -Xlinker $(shell $(XENOCONFIG) --libdir)
+
+LDFLAGS+= -lrtdk
+
+all:: $(APPLICATIONS)
+
+clean::
+ $(RM) $(APPLICATIONS) *.o
+
+endif
+endif
+
+
+
+###### SPECIAL TARGET RULES ######
+rtprint: rtprint.c
+ $(CC) $(CFLAGS) $? $(LDFLAGS) -lrtdk -o $@
+
+
+
+###### KERNEL MODULE BUILD (no change required normally) ######
+ifneq ($(MODULES),)
+
+### Default to sources of currently running kernel
+KSRC ?= /lib/modules/$(shell uname -r)/build
+
+OBJS := ${patsubst %, %.o, $(MODULES)}
+CLEANMOD := ${patsubst %, .%*, $(MODULES)}
+PWD := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
+
+### Kernel 2.6
+ifeq ($(findstring 2.6,$(KSRC)),2.6)
+
+obj-m := $(OBJS)
+EXTRA_CFLAGS := -I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/posix $(ADD_CFLAGS)
+
+all::
+ $(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules
+
+### Kernel 2.4
+else
+
+ARCH ?= $(shell uname -i)
+INCLUDE := -I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/compat -I$(KSRC)/include/xenomai/posix
+CFLAGS += $(shell $(MAKE) -s -C $(KSRC) CC=$(CC) ARCH=$(ARCH) SUBDIRS=$(PWD) modules) $(INCLUDE)
+
+all:: $(OBJS)
+
+endif
+
+## Target for capturing 2.4 module CFLAGS
+modules:
+ @echo "$(CFLAGS)"
+
+clean::
+ $(RM) $(CLEANMOD) *.o *.ko *.mod.c Module*.symvers
+ $(RM) -R .tmp*
+
+endif
\ No newline at end of file
--- /dev/null
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <native/intr.h>
+#include <sys/io.h>
+#include <native/task.h>
+
+RT_INTR keypress;
+RT_TASK key_isr;
+#define KEYBOARD_IRQ 1
+
+void key_handler(void *arg)
+{
+ int count = 0;
+ int nr_interrupts_waiting;
+ while(1) {
+ rt_printf("%d\n",count++);
+ nr_interrupts_waiting = rt_intr_wait(&keypress,TM_INFINITE);
+ if (nr_interrupts_waiting>0)
+ {
+ }
+ }
+}
+
+//startup code
+void startup()
+{
+ rt_intr_create(&keypress, NULL, KEYBOARD_IRQ, I_PROPAGATE);
+
+ rt_task_create(&key_isr, NULL,0,50,0);
+ rt_task_start(&key_isr, &key_handler, NULL);
+}
+
+void init_xenomai() {
+ /* Avoids memory swapping for this program */
+ mlockall(MCL_CURRENT|MCL_FUTURE);
+
+ /* Perform auto-init of rt_print buffers if the task doesn't do so */
+ rt_print_auto_init(1);
+}
+
+int main(int argc, char* argv[])
+{
+ printf("\nType CTRL-C to end this program\n\n" );
+
+ // code to set things to run xenomai
+ init_xenomai();
+
+ //startup code
+ startup();
+
+ // wait for CTRL-c is typed to end the program
+ pause();
+}
\ No newline at end of file
--- /dev/null
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <native/intr.h>
+#include <sys/io.h>
+#include <native/task.h>
+
+RT_INTR keypress;
+RT_TASK key_isr;
+RT_TASK dummy;
+#define KEYBOARD_IRQ 1
+
+void key_handler(void *arg)
+{
+ int count = 0;
+ int nr_interrupts_waiting;
+
+ RT_TASK *curtask;
+ RT_TASK_INFO curtaskinfo;
+
+ while(1) {
+ //rt_printf("%d\n",count++);
+ nr_interrupts_waiting = rt_intr_wait(&keypress,TM_INFINITE);
+ if (nr_interrupts_waiting>0)
+ {
+ // inquire current task
+ curtask=rt_task_self();
+ rt_task_inquire(curtask,&curtaskinfo);
+ rt_printf("Current priority of handler task: %d \n", curtaskinfo.cprio);
+ }
+ }
+}
+
+void dummy_task(void *arg) {
+ while(1) { rt_printf("Sleeping\n");
+ rt_task_sleep(2e9);
+ rt_printf("Spinning\n");
+ rt_timer_spin(3e9);
+ }
+}
+
+//startup code
+void startup()
+{
+ rt_intr_create(&keypress, NULL, KEYBOARD_IRQ, I_PROPAGATE);
+
+ rt_task_create(&key_isr, NULL,0,50,0);
+ rt_task_start(&key_isr, &key_handler, NULL);
+
+ // Higher priority
+ rt_task_create(&dummy, NULL,0,53,0);
+ rt_task_start(&dummy, &dummy_task, NULL);
+}
+
+void init_xenomai() {
+ /* Avoids memory swapping for this program */
+ mlockall(MCL_CURRENT|MCL_FUTURE);
+
+ /* Perform auto-init of rt_print buffers if the task doesn't do so */
+ rt_print_auto_init(1);
+}
+
+int main(int argc, char* argv[])
+{
+ printf("\nType CTRL-C to end this program\n\n" );
+
+ // code to set things to run xenomai
+ init_xenomai();
+
+ //startup code
+ startup();
+
+ // wait for CTRL-c is typed to end the program
+ pause();
+}
\ No newline at end of file