From: root Date: Wed, 23 Sep 2015 13:46:08 +0000 (+0200) Subject: finished #8 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=71e186ae9f5f58d519a421eb46e6bd652966ee22;p=des2015.git finished #8 --- diff --git a/mart/ex07/ex07a b/mart/ex07/ex07a new file mode 100755 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 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 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 index 0000000..a04ea30 --- /dev/null +++ b/mart/ex08/Makefile @@ -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 index 0000000..8932358 --- /dev/null +++ b/mart/ex08/ex08a.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include + +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 index 0000000..7ea309a --- /dev/null +++ b/mart/ex08/ex08b.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include + +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(); +}