diff options
author | Anas Nashif <anas.nashif@intel.com> | 2016-11-02 10:26:28 -0400 |
---|---|---|
committer | Anas Nashif <nashif@linux.intel.com> | 2016-11-02 22:05:29 +0000 |
commit | 886677c3dea424c4c4ef18a6925c4b01ba944ac5 (patch) | |
tree | 69fe9ebd400338602310d247c90e1b063391d88b /samples/legacy | |
parent | 269d38bcda0af0383dfeb911627b98a3bcbcbcdb (diff) |
samples: synchronization: move to legacy/
Change-Id: I72d6fcba0c747e27c0e9cb9fade7abcf8bd077bc
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Diffstat (limited to 'samples/legacy')
14 files changed, 298 insertions, 0 deletions
diff --git a/samples/legacy/synchronization/microkernel/Makefile b/samples/legacy/synchronization/microkernel/Makefile new file mode 100644 index 000000000..0d56ce66d --- /dev/null +++ b/samples/legacy/synchronization/microkernel/Makefile @@ -0,0 +1,6 @@ +MDEF_FILE = prj.mdef +KERNEL_TYPE = micro +BOARD ?= qemu_x86 +CONF_FILE = prj.conf + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/samples/legacy/synchronization/microkernel/README.txt b/samples/legacy/synchronization/microkernel/README.txt new file mode 100644 index 000000000..289b4a53e --- /dev/null +++ b/samples/legacy/synchronization/microkernel/README.txt @@ -0,0 +1,48 @@ +Title: Synchronisation + +Description: + +A simple application that demonstates basic sanity of the microkernel. +Two tasks (A and B) take turns printing a greeting message to the console, +and use sleep requests and semaphores to control the rate at which messages +are generated. This demonstrates that microkernel scheduling, communication, +and timing are operating correctly. + +-------------------------------------------------------------------------------- + +Building and Running Project: + +This microkernel project outputs to the console. It can be built and executed +on QEMU as follows: + + make qemu + +-------------------------------------------------------------------------------- + +Troubleshooting: + +Problems caused by out-dated project information can be addressed by +issuing one of the following commands then rebuilding the project: + + make clean # discard results of previous builds + # but keep existing configuration info +or + make pristine # discard results of previous builds + # and restore pre-defined configuration info + +-------------------------------------------------------------------------------- + +Sample Output: + +taskA: Hello World! +taskB: Hello World! +taskA: Hello World! +taskB: Hello World! +taskA: Hello World! +taskB: Hello World! +taskA: Hello World! +taskB: Hello World! +taskA: Hello World! +taskB: Hello World! + +<repeats endlessly> diff --git a/samples/legacy/synchronization/microkernel/prj.conf b/samples/legacy/synchronization/microkernel/prj.conf new file mode 100644 index 000000000..8b042db54 --- /dev/null +++ b/samples/legacy/synchronization/microkernel/prj.conf @@ -0,0 +1 @@ +CONFIG_STDOUT_CONSOLE=y diff --git a/samples/legacy/synchronization/microkernel/prj.mdef b/samples/legacy/synchronization/microkernel/prj.mdef new file mode 100644 index 000000000..e533210f1 --- /dev/null +++ b/samples/legacy/synchronization/microkernel/prj.mdef @@ -0,0 +1,11 @@ +% Application : Hello demo + +% TASK NAME PRIO ENTRY STACK GROUPS +% ================================== + TASK TASKA 7 taskA 1024 [EXE] + TASK TASKB 7 taskB 1024 [EXE] + +% SEMA NAME +% ============= + SEMA TASKASEM + SEMA TASKBSEM diff --git a/samples/legacy/synchronization/microkernel/sample.tc b/samples/legacy/synchronization/microkernel/sample.tc new file mode 100644 index 000000000..cb6df9d4f --- /dev/null +++ b/samples/legacy/synchronization/microkernel/sample.tc @@ -0,0 +1,10 @@ +# @testcase dynamic + +# @targets \ +# board:(?!arduino_101_sss) \ +# board:(?!minnowboard) \ +# board:(?!quark_d2000_crb) \ +# board:(?!quark_se_c1000_ss_devboard) \ +# +# @eval console-rx %(console)s:10 taskA: Hello World from %(bsp)s! +# @eval console-rx %(console)s:10 taskB: Hello World from %(bsp)s! diff --git a/samples/legacy/synchronization/microkernel/src/Makefile b/samples/legacy/synchronization/microkernel/src/Makefile new file mode 100644 index 000000000..00066e156 --- /dev/null +++ b/samples/legacy/synchronization/microkernel/src/Makefile @@ -0,0 +1 @@ +obj-y = main.o diff --git a/samples/legacy/synchronization/microkernel/src/main.c b/samples/legacy/synchronization/microkernel/src/main.c new file mode 100644 index 000000000..821bcf94b --- /dev/null +++ b/samples/legacy/synchronization/microkernel/src/main.c @@ -0,0 +1,69 @@ +/* hello.c - Hello World demo */ + +/* + * Copyright (c) 2012-2014 Wind River Systems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <zephyr.h> +#include <misc/printk.h> + +/* + * Microkernel version of hello world demo has two tasks that utilize + * semaphores and sleeps to take turns printing a greeting message at + * a controlled rate. + */ + + +/* specify delay between greetings (in ms); compute equivalent in ticks */ + +#define SLEEPTIME 500 +#define SLEEPTICKS (SLEEPTIME * sys_clock_ticks_per_sec / 1000) + +/* + * + * @param taskname task identification string + * @param mySem task's own semaphore + * @param otherSem other task's semaphore + * + */ +void helloLoop(const char *taskname, ksem_t mySem, ksem_t otherSem) +{ + while (1) { + task_sem_take(mySem, TICKS_UNLIMITED); + + /* say "hello" */ + printk("%s: Hello World from %s!\n", taskname, CONFIG_ARCH); + + /* wait a while, then let other task have a turn */ + task_sleep(SLEEPTICKS); + task_sem_give(otherSem); + } +} + +void taskA(void) +{ + /* taskA gives its own semaphore, allowing it to say hello right away */ + task_sem_give(TASKASEM); + + /* invoke routine that allows task to ping-pong hello messages with taskB */ + helloLoop(__func__, TASKASEM, TASKBSEM); +} + +void taskB(void) +{ + /* invoke routine that allows task to ping-pong hello messages with taskA */ + helloLoop(__func__, TASKBSEM, TASKASEM); +} + diff --git a/samples/legacy/synchronization/microkernel/testcase.ini b/samples/legacy/synchronization/microkernel/testcase.ini new file mode 100644 index 000000000..3cd15265e --- /dev/null +++ b/samples/legacy/synchronization/microkernel/testcase.ini @@ -0,0 +1,4 @@ +[test] +build_only = true +tags = apps +kernel = micro diff --git a/samples/legacy/synchronization/nanokernel/Makefile b/samples/legacy/synchronization/nanokernel/Makefile new file mode 100644 index 000000000..6fe47af43 --- /dev/null +++ b/samples/legacy/synchronization/nanokernel/Makefile @@ -0,0 +1,6 @@ +KERNEL_TYPE = nano +BOARD ?= qemu_x86 +CONF_FILE = prj.conf + + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/samples/legacy/synchronization/nanokernel/README.txt b/samples/legacy/synchronization/nanokernel/README.txt new file mode 100644 index 000000000..8a5b9dc97 --- /dev/null +++ b/samples/legacy/synchronization/nanokernel/README.txt @@ -0,0 +1,48 @@ +Title: Synchronisation + +Description: + +A simple application that demonstrates basic sanity of the nanokernel. +The background task and a fiber take turns printing a greeting message to the +console, and use timers and semaphores to control the rate at which messages +are generated. This demonstrates that nanokernel scheduling, communication, +and timing are operating correctly. + +-------------------------------------------------------------------------------- + +Building and Running Project: + +This nanokernel project outputs to the console. It can be built and executed +on QEMU as follows: + + make qemu + +-------------------------------------------------------------------------------- + +Troubleshooting: + +Problems caused by out-dated project information can be addressed by +issuing one of the following commands then rebuilding the project: + + make clean # discard results of previous builds + # but keep existing configuration info +or + make pristine # discard results of previous builds + # and restore pre-defined configuration info + +-------------------------------------------------------------------------------- + +Sample Output: + +main: Hello World! +fiberEntry: Hello World! +main: Hello World! +fiberEntry: Hello World! +main: Hello World! +fiberEntry: Hello World! +main: Hello World! +fiberEntry: Hello World! +main: Hello World! +fiberEntry: Hello World! + +<repeats endlessly> diff --git a/samples/legacy/synchronization/nanokernel/prj.conf b/samples/legacy/synchronization/nanokernel/prj.conf new file mode 100644 index 000000000..b2a4ba591 --- /dev/null +++ b/samples/legacy/synchronization/nanokernel/prj.conf @@ -0,0 +1 @@ +# nothing here diff --git a/samples/legacy/synchronization/nanokernel/src/Makefile b/samples/legacy/synchronization/nanokernel/src/Makefile new file mode 100644 index 000000000..b666967fd --- /dev/null +++ b/samples/legacy/synchronization/nanokernel/src/Makefile @@ -0,0 +1 @@ +obj-y += main.o diff --git a/samples/legacy/synchronization/nanokernel/src/main.c b/samples/legacy/synchronization/nanokernel/src/main.c new file mode 100644 index 000000000..ab9cda71a --- /dev/null +++ b/samples/legacy/synchronization/nanokernel/src/main.c @@ -0,0 +1,88 @@ +/* main.c - Synchronisation demo */ + +/* + * Copyright (c) 2012-2014 Wind River Systems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <zephyr.h> +#include <misc/printk.h> + + +/* + * Nanokernel version of hello world demo has a task and a fiber that utilize + * semaphores and timers to take turns printing a greeting message at + * a controlled rate. + */ + + +/* specify delay between greetings (in ms); compute equivalent in ticks */ + +#define SLEEPTIME 500 +#define SLEEPTICKS (SLEEPTIME * sys_clock_ticks_per_sec / 1000) + +#define STACKSIZE 2000 + +char __stack fiberStack[STACKSIZE]; + +struct nano_sem nanoSemTask; +struct nano_sem nanoSemFiber; + +void fiberEntry(void) +{ + struct nano_timer timer; + uint32_t data[2] = {0, 0}; + + nano_sem_init(&nanoSemFiber); + nano_timer_init(&timer, data); + + while (1) { + /* wait for task to let us have a turn */ + nano_fiber_sem_take(&nanoSemFiber, TICKS_UNLIMITED); + + /* say "hello" */ + printk("%s: Hello World!\n", __func__); + + /* wait a while, then let task have a turn */ + nano_fiber_timer_start(&timer, SLEEPTICKS); + nano_fiber_timer_test(&timer, TICKS_UNLIMITED); + nano_fiber_sem_give(&nanoSemTask); + } +} + +void main(void) +{ + struct nano_timer timer; + uint32_t data[2] = {0, 0}; + + task_fiber_start(&fiberStack[0], STACKSIZE, + (nano_fiber_entry_t) fiberEntry, 0, 0, 7, 0); + + nano_sem_init(&nanoSemTask); + nano_timer_init(&timer, data); + + while (1) { + /* say "hello" */ + printk("%s: Hello World!\n", __func__); + + /* wait a while, then let fiber have a turn */ + nano_task_timer_start(&timer, SLEEPTICKS); + nano_task_timer_test(&timer, TICKS_UNLIMITED); + nano_task_sem_give(&nanoSemFiber); + + /* now wait for fiber to let us have a turn */ + nano_task_sem_take(&nanoSemTask, TICKS_UNLIMITED); + } +} + diff --git a/samples/legacy/synchronization/nanokernel/testcase.ini b/samples/legacy/synchronization/nanokernel/testcase.ini new file mode 100644 index 000000000..8ee37ed2f --- /dev/null +++ b/samples/legacy/synchronization/nanokernel/testcase.ini @@ -0,0 +1,4 @@ +[test] +build_only = true +tags = apps + |