From 517c24dbfee4fa151ecb81bb7bff6ef2faee5267 Mon Sep 17 00:00:00 2001 From: Natanael Adityasatria Date: Sun, 20 Sep 2015 20:07:56 +0200 Subject: [PATCH] Completed ex03c and some makefiles --- mart/ex03/Makefile | 102 ++++++++++++++++++++++++++++++++++--- mart/ex03/ex03c1.c | 69 +++++++++++++++++++++++++ mart/ex03/ex03c2.c | 68 +++++++++++++++++++++++++ mart/ex03/explanations.txt | 4 +- mart/ex06/Makefile | 102 ++++++++++++++++++++++++++++++++++--- mart/ex07/Makefile | 102 ++++++++++++++++++++++++++++++++++--- 6 files changed, 426 insertions(+), 21 deletions(-) create mode 100644 mart/ex03/ex03c1.c create mode 100644 mart/ex03/ex03c2.c diff --git a/mart/ex03/Makefile b/mart/ex03/Makefile index bbbff1d..68fbc7a 100644 --- a/mart/ex03/Makefile +++ b/mart/ex03/Makefile @@ -1,9 +1,99 @@ -CFLAGS=$(shell xeno-config --xeno-cflags) -lnative -lrtdk -LDFLAGS=$(shell xeno-config --xeno-ldflags) +###### CONFIGURATION ###### -BINARIES=$(addprefix ex03,a b c) +### List of applications to be build +APPLICATIONS = ex03a ex03b ex03c1 ex03c2 -all: $(BINARIES) +### Note: to override the search path for the xeno-config script, use "make XENO=..." -clean: - $(RM) -v $(BINARIES) *.o + +### 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 diff --git a/mart/ex03/ex03c1.c b/mart/ex03/ex03c1.c new file mode 100644 index 0000000..3efd3f2 --- /dev/null +++ b/mart/ex03/ex03c1.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include +RT_TASK demo_task; +RT_SEM semGlobal; + +void demo(void *arg) +{ + rt_sem_p(&semGlobal, 0); + + 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 \n", curtaskinfo.name); + + rt_sem_v(&semGlobal); +} + +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); + + /* create semaphore */ + rt_sem_create(&semGlobal,"semaphore",0,S_PRIO); + + 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); + } + + rt_sem_v(&semGlobal); +} \ No newline at end of file diff --git a/mart/ex03/ex03c2.c b/mart/ex03/ex03c2.c new file mode 100644 index 0000000..799dee5 --- /dev/null +++ b/mart/ex03/ex03c2.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include +RT_TASK demo_task; +RT_SEM semGlobal; + +void demo(void *arg) +{ + RT_TASK *curtask; + RT_TASK_INFO curtaskinfo; + + // inquire current task + curtask=rt_task_self(); + rt_task_inquire(curtask,&curtaskinfo); + + rt_sem_p(&semGlobal,TM_INFINITE); + + // print task name + int num = * (int *)arg; + 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); + + /* create semaphore */ + rt_sem_create(&semGlobal,"semaphore",0,S_PRIO); + + 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); + } + + rt_sem_broadcast(&semGlobal); + +} \ No newline at end of file diff --git a/mart/ex03/explanations.txt b/mart/ex03/explanations.txt index 941a767..5ae580a 100644 --- a/mart/ex03/explanations.txt +++ b/mart/ex03/explanations.txt @@ -10,6 +10,4 @@ line up in the queue again. This goes on, tasks taking turns, till the tasks are finished. 3c. -rt_sem_v doesn't work because they are released and the first one will get the -lock. rt_sem_broadcast works because all tasks are released at the same time -and the priority is then the next measure of who goes first. +Using semaphore, we can start task that has higher priority than the others. As we can see from the output, the order of the task is based on its priority. diff --git a/mart/ex06/Makefile b/mart/ex06/Makefile index 6eaf467..42b17b3 100644 --- a/mart/ex06/Makefile +++ b/mart/ex06/Makefile @@ -1,9 +1,99 @@ -CFLAGS=$(shell xeno-config --xeno-cflags) -lnative -lrtdk -LDFLAGS=$(shell xeno-config --xeno-ldflags) +###### CONFIGURATION ###### -BINARIES=$(addprefix ex06,a b c d) +### List of applications to be build +APPLICATIONS = ex06a ex06b ex06c ex06d -all: $(BINARIES) +### Note: to override the search path for the xeno-config script, use "make XENO=..." -clean: - $(RM) -v $(BINARIES) *.o + +### 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 diff --git a/mart/ex07/Makefile b/mart/ex07/Makefile index 8a98192..56be179 100644 --- a/mart/ex07/Makefile +++ b/mart/ex07/Makefile @@ -1,9 +1,99 @@ -CFLAGS=$(shell xeno-config --xeno-cflags) -lnative -lrtdk -LDFLAGS=$(shell xeno-config --xeno-ldflags) +###### CONFIGURATION ###### -BINARIES=$(addprefix ex07,a b c) +### List of applications to be build +APPLICATIONS = ex07a ex07b ex07c -all: $(BINARIES) +### Note: to override the search path for the xeno-config script, use "make XENO=..." -clean: - $(RM) -v $(BINARIES) *.o + +### 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 -- 2.20.1