finished #8
authorroot <root@xenomailinux.localdomain>
Wed, 23 Sep 2015 13:46:08 +0000 (15:46 +0200)
committerroot <root@xenomailinux.localdomain>
Wed, 23 Sep 2015 13:46:08 +0000 (15:46 +0200)
mart/ex07/ex07a [new file with mode: 0755]
mart/ex07/ex07b [new file with mode: 0755]
mart/ex07/ex07c [new file with mode: 0755]
mart/ex08/Makefile [new file with mode: 0644]
mart/ex08/ex08a.c [new file with mode: 0644]
mart/ex08/ex08b.c [new file with mode: 0644]

diff --git a/mart/ex07/ex07a b/mart/ex07/ex07a
new file mode 100755 (executable)
index 0000000..68a345c
Binary files /dev/null and b/mart/ex07/ex07a differ
diff --git a/mart/ex07/ex07b b/mart/ex07/ex07b
new file mode 100755 (executable)
index 0000000..5ba410d
Binary files /dev/null and b/mart/ex07/ex07b differ
diff --git a/mart/ex07/ex07c b/mart/ex07/ex07c
new file mode 100755 (executable)
index 0000000..213cd31
Binary files /dev/null and b/mart/ex07/ex07c differ
diff --git a/mart/ex08/Makefile b/mart/ex08/Makefile
new file mode 100644 (file)
index 0000000..a04ea30
--- /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=$(addprefix ex08,a b)
+
+all: $(BINARIES)
+
+clean:
+       $(RM) -v $(BINARIES)
diff --git a/mart/ex08/ex08a.c b/mart/ex08/ex08a.c
new file mode 100644 (file)
index 0000000..8932358
--- /dev/null
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <native/task.h>
+#include <native/timer.h>
+#include <native/sem.h>
+
+#include <rtdk.h>
+
+static RT_TASK tl;
+static RT_TASK tm;
+static RT_TASK th;
+RTIME timeblock = 1e7;
+RT_SEM sem;
+
+int global = 0;
+
+void t_low(void *arg)
+{
+       int i;
+       for(i = 0; i<3; i++){
+               rt_sem_p(&sem, TM_INFINITE);
+               rt_printf("Low priority task locks semaphore\n");
+               rt_task_sleep(timeblock*3);
+               rt_printf("Low priority task unlocks semaphore\n");
+               rt_sem_v(&sem);
+       }
+       rt_printf(".....Low priority task ends\n");
+}
+
+void t_med(void *arg)
+{
+       rt_task_sleep(timeblock*2);
+       int i;
+       for(i = 0; i<10; i++){
+               rt_printf("Medium task running\n");
+               rt_timer_spin(timeblock);
+       }
+       rt_printf(".....Medium priority task ends\n");
+}
+
+void t_high(void *arg)
+{
+       rt_task_sleep(timeblock*3);
+       int i;
+       for(i = 0; i<3; i++){
+               rt_printf("High priority task tries to locks semaphore\n");
+               rt_sem_p(&sem, TM_INFINITE);
+               rt_printf("High priority task locks semaphore\n");
+               rt_timer_spin(timeblock*3);
+               rt_printf("High priority task unlocks semaphore\n");
+               rt_sem_v(&sem);
+       }
+       rt_printf(".....High priority task ends\n");
+}
+
+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);
+
+       /* create the two tasks */
+       rt_task_create(&tl, "t_low", 0, 49, 0);
+       rt_task_create(&tm, "t_med", 0, 50, 0);
+       rt_task_create(&th, "t_high", 0, 51, 0);
+
+       /* create semaphore and start in blocked mode */
+       rt_sem_create(&sem, "sem", 1, S_PRIO);
+
+       /* start the two tasks */
+       rt_task_start(&tl, &t_low, 0);
+       rt_task_start(&tm, &t_med, 0);
+       rt_task_start(&th, &t_high, 0);
+
+       pause();
+}
diff --git a/mart/ex08/ex08b.c b/mart/ex08/ex08b.c
new file mode 100644 (file)
index 0000000..7ea309a
--- /dev/null
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <native/task.h>
+#include <native/timer.h>
+#include <native/mutex.h>
+
+#include <rtdk.h>
+
+static RT_TASK tl;
+static RT_TASK tm;
+static RT_TASK th;
+RTIME timeblock = 1e7;
+RT_MUTEX mutex;
+
+int global = 0;
+
+void t_low(void *arg)
+{
+       int i;
+       for(i = 0; i<3; i++){
+               rt_mutex_acquire(&mutex, TM_INFINITE);
+               rt_printf("Low priority task locks semaphore\n");
+               rt_task_sleep(timeblock*3);
+               rt_printf("Low priority task unlocks semaphore\n");
+               rt_mutex_release(&mutex);
+       }
+       rt_printf(".....Low priority task ends\n");
+}
+
+void t_med(void *arg)
+{
+       rt_task_sleep(timeblock*2);
+       int i;
+       for(i = 0; i<10; i++){
+               rt_printf("Medium task running\n");
+               rt_timer_spin(timeblock);
+       }
+       rt_printf(".....Medium priority task ends\n");
+}
+
+void t_high(void *arg)
+{
+       rt_task_sleep(timeblock*3);
+       int i;
+       for(i = 0; i<3; i++){
+               rt_printf("High priority task tries to locks semaphore\n");
+               rt_mutex_acquire(&mutex, TM_INFINITE);
+               rt_printf("High priority task locks semaphore\n");
+               rt_timer_spin(timeblock*3);
+               rt_printf("High priority task unlocks semaphore\n");
+               rt_mutex_release(&mutex);
+       }
+       rt_printf(".....High priority task ends\n");
+}
+
+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);
+
+       /* create the two tasks */
+       rt_task_create(&tl, "t_low", 0, 49, 0);
+       rt_task_create(&tm, "t_med", 0, 50, 0);
+       rt_task_create(&th, "t_high", 0, 51, 0);
+
+       /* create semaphore and start in blocked mode */
+       rt_mutex_create(&mutex, "mutex");
+
+       /* start the two tasks */
+       rt_task_start(&tl, &t_low, 0);
+       rt_task_start(&tm, &t_med, 0);
+       rt_task_start(&th, &t_high, 0);
+
+       pause();
+}