From: Natanael Adityasatria Date: Fri, 11 Sep 2015 18:58:32 +0000 (+0200) Subject: Push exercise 1 and 2 X-Git-Tag: assignment2~1^2 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=4289a588f1e0df69461a4366399412f49dc1deea;p=des2015.git Push exercise 1 and 2 --- diff --git a/natanael/ex01/Makefile b/natanael/ex01/Makefile new file mode 100644 index 0000000..861fe99 --- /dev/null +++ b/natanael/ex01/Makefile @@ -0,0 +1,99 @@ +###### CONFIGURATION ###### + +### List of applications to be build +APPLICATIONS = ex01 + +### Note: to override the search path for the xeno-config script, use "make XENO=..." + + +### List of modules to be build +MODULES = ex01 + +### 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 diff --git a/natanael/ex01/ex01.c b/natanael/ex01/ex01.c new file mode 100644 index 0000000..d752548 --- /dev/null +++ b/natanael/ex01/ex01.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include +#include + +#include +RT_TASK demo_task; + +void demo(void *arg) +{ + RT_TASK *curtask; + RT_TASK_INFO curtaskinfo; + + // hello world + rt_printf("Hello World!\n"); + + // inquire current task + curtask=rt_task_self(); + rt_task_inquire(curtask,&curtaskinfo); + + // print task name + rt_printf("Task name : %s \n", curtaskinfo.name); +} + +int main(int argc, char* argv[]) +{ + char str[10] ; + + // Perform auto-init of rt_print buffers if the task doesn't do so + rt_print_auto_init(1); + + // Lock memory : avoid memory swapping for this program + mlockall(MCL_CURRENT|MCL_FUTURE); + + rt_printf("start task\n"); + + /* + * Arguments: &task, + * name, + * stack size (0=default), + * priority, + * mode (FPU, start suspended, ...) + */ + sprintf(str,"hello"); + rt_task_create(&demo_task, str, 0, 50, 0); + + /* + * Arguments: &task, + * task function, + * function argument + */ + rt_task_start(&demo_task, &demo, 0); +} \ No newline at end of file diff --git a/natanael/ex01/ex01b.c b/natanael/ex01/ex01b.c new file mode 100644 index 0000000..f2953cd --- /dev/null +++ b/natanael/ex01/ex01b.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#include +#include + +#include +#include +RT_TASK demo_task; + +void demo(void *arg) +{ + RT_TASK *curtask; + RT_TASK_INFO curtaskinfo; + int retval; + + // hello world + rt_printf("Hello World!\n"); + + // inquire current task + // below is commented and makes error + // curtask=rt_task_self(); + retval = rt_task_inquire(curtask,&curtaskinfo); + + /* send error message */ + if (retval < 0 ) + { + rt_printf("Sending error %d : %s\n",-retval,strerror(-retval)); + } else { + rt_printf("taskOne sent message to taskTwo\n"); + } + + // print task name + rt_printf("Task name : %s \n", curtaskinfo.name); + +} + +int main(int argc, char* argv[]) +{ + char str[10] ; + + // Perform auto-init of rt_print buffers if the task doesn't do so + rt_print_auto_init(1); + + // Lock memory : avoid memory swapping for this program + mlockall(MCL_CURRENT|MCL_FUTURE); + + rt_printf("start task\n"); + + /* + * Arguments: &task, + * name, + * stack size (0=default), + * priority, + * mode (FPU, start suspended, ...) + */ + sprintf(str,"hello"); + rt_task_create(&demo_task, str, 0, 50, 0); + + /* + * Arguments: &task, + * task function, + * function argument + */ + rt_task_start(&demo_task, &demo, 0); +} \ No newline at end of file diff --git a/natanael/ex02/Explanation ex02.txt b/natanael/ex02/Explanation ex02.txt new file mode 100644 index 0000000..e3502bf --- /dev/null +++ b/natanael/ex02/Explanation ex02.txt @@ -0,0 +1,22 @@ +DES group members: +Natanael Adityasatria 4417992 +Mart Lubbers + +2a +The output describes the first task is the task that is first executed by the syntax rt_task_start. So the task order is ordered from the source code's order (in this case: inside loop, the lowest counter will be run first) + +2b +The output describes that we can pass the integer argument that belongs to the task. In addition to the task name (string), the task can also has an integer value. + +2c +There is no differences in the output with the exercise 2b. +The order is the same as in exercise 2b. +From the source code, this is because we put each of tasks in a loop. +So the first task created and the first task started in the loop will +be run first time. For the next loop, it will create and start the +next task. So it is like the matter of the code order not the task +priority. + +2d +It is because we use Sleep of 1 second then the loop(while) will be run every one second. All tasks have the same priority, but each of tasks has different periods. +The first task that has period of 1 will be run every seconds while the task that has period of 2 will be run once in two seconds. In addition, the task that has period of 3 will be run once in three seconds. \ No newline at end of file diff --git a/natanael/ex02/Makefile b/natanael/ex02/Makefile new file mode 100644 index 0000000..d039644 --- /dev/null +++ b/natanael/ex02/Makefile @@ -0,0 +1,99 @@ +###### CONFIGURATION ###### + +### List of applications to be build +APPLICATIONS = ex02 + +### Note: to override the search path for the xeno-config script, use "make XENO=..." + + +### List of modules to be build +MODULES = ex02 + +### 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 diff --git a/natanael/ex02/ex02.c b/natanael/ex02/ex02.c new file mode 100644 index 0000000..e3ecdc8 --- /dev/null +++ b/natanael/ex02/ex02.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include +#include + +#include +RT_TASK demo_task; + +void demo(void *arg) +{ + RT_TASK *curtask; + RT_TASK_INFO curtaskinfo; + + // inquire current task + curtask=rt_task_self(); + rt_task_inquire(curtask,&curtaskinfo); + + // print task name + rt_printf("Task name : %s \n", curtaskinfo.name); +} + +int main(int argc, char* argv[]) +{ + char str[10] ; + int i; + + // Perform auto-init of rt_print buffers if the task doesn't do so + rt_print_auto_init(1); + + // Lock memory : avoid memory swapping for this program + mlockall(MCL_CURRENT|MCL_FUTURE); + + rt_printf("start task\n"); + + for (i=0; i<5; i++) + { + /* + * Arguments: &task, + * name, + * stack size (0=default), + * priority, + * mode (FPU, start suspended, ...) + */ + sprintf(str,"hello-%d",i); + rt_task_create(&demo_task, str, 0, 50, 0); + /* + * Arguments: &task, + * task function, + * function argument + */ + rt_task_start(&demo_task, &demo, 0); + } + +} \ No newline at end of file diff --git a/natanael/ex02/ex02b.c b/natanael/ex02/ex02b.c new file mode 100644 index 0000000..d598b82 --- /dev/null +++ b/natanael/ex02/ex02b.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +#include +#include + +#include +RT_TASK demo_task; + +void demo(void *arg) +{ + RT_TASK *curtask; + RT_TASK_INFO curtaskinfo; + + // inquire current task + curtask=rt_task_self(); + rt_task_inquire(curtask,&curtaskinfo); + + // print task name + int num = * (int *)arg; + rt_printf("Task name : %s - Argument %d \n", curtaskinfo.name,num); +} + +int main(int argc, char* argv[]) +{ + char str[10] ; + int i; + + // Perform auto-init of rt_print buffers if the task doesn't do so + rt_print_auto_init(1); + + // Lock memory : avoid memory swapping for this program + mlockall(MCL_CURRENT|MCL_FUTURE); + + rt_printf("start task\n"); + + for (i=0; i<5; i++) + { + /* + * Arguments: &task, + * name, + * stack size (0=default), + * priority, + * mode (FPU, start suspended, ...) + */ + sprintf(str,"hello-%d",i); + rt_task_create(&demo_task, str, 0, 50, 0); + /* + * Arguments: &task, + * task function, + * function argument + */ + rt_task_start(&demo_task, &demo, &i); + } + +} \ No newline at end of file diff --git a/natanael/ex02/ex02c.c b/natanael/ex02/ex02c.c new file mode 100644 index 0000000..9411d1b --- /dev/null +++ b/natanael/ex02/ex02c.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +#include +#include + +#include +RT_TASK demo_task; + +void demo(void *arg) +{ + RT_TASK *curtask; + RT_TASK_INFO curtaskinfo; + + // inquire current task + curtask=rt_task_self(); + rt_task_inquire(curtask,&curtaskinfo); + + // print task name + int num = * (int *)arg; + rt_printf("Task name : %s - Argument %d \n", curtaskinfo.name,num); +} + +int main(int argc, char* argv[]) +{ + char str[10] ; + int i; + + // Perform auto-init of rt_print buffers if the task doesn't do so + rt_print_auto_init(1); + + // Lock memory : avoid memory swapping for this program + mlockall(MCL_CURRENT|MCL_FUTURE); + + rt_printf("start task\n"); + + for (i=0; i<5; i++) + { + /* + * Arguments: &task, + * name, + * stack size (0=default), + * priority, + * mode (FPU, start suspended, ...) + */ + sprintf(str,"hello-%d",i); + rt_task_create(&demo_task, str, 0, 50+i, 0); + + /* + * Arguments: &task, + * task function, + * function argument + */ + rt_task_start(&demo_task, &demo, &i); + } + +} \ No newline at end of file diff --git a/natanael/ex02/ex02d.c b/natanael/ex02/ex02d.c new file mode 100644 index 0000000..f54ded3 --- /dev/null +++ b/natanael/ex02/ex02d.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#include +#include + +#include +RT_TASK demo_task; + +void demo(void *arg) +{ + sleep(1); + RT_TASK *curtask; + RT_TASK_INFO curtaskinfo; + // Read system clock + RTIME period = 1e9; + + // inquire current task + curtask=rt_task_self(); + rt_task_inquire(curtask,&curtaskinfo); + + // determine the period + int num = * (int *)arg; + period*=num; + rt_task_set_periodic(NULL,TM_NOW,period); + + while(1){ + // print task name + rt_printf("Task name : %s - Period %d \n", curtaskinfo.name,num); + rt_task_wait_period(NULL); + } +} + +int main(int argc, char* argv[]) +{ + char str[10] ; + int i; + int periods[3]; + + // Perform auto-init of rt_print buffers if the task doesn't do so + rt_print_auto_init(1); + + // Lock memory : avoid memory swapping for this program + mlockall(MCL_CURRENT|MCL_FUTURE); + + rt_printf("start task\n"); + + for (i=0; i<3; i++) + { + /* + * Arguments: &task, + * name, + * stack size (0=default), + * priority, + * mode (FPU, start suspended, ...) + */ + sprintf(str,"hello-%d",i); + periods[i]=i+1; + rt_task_create(&demo_task, str, 0, 50, 0); + + /* + * Arguments: &task, + * task function, + * function argument + */ + rt_task_start(&demo_task, &demo, &periods[i]); + } + rt_printf("end program by CTRL-C\n"); + pause(); +} \ No newline at end of file