summaryrefslogtreecommitdiff
path: root/samples/legacy
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2016-11-02 10:27:39 -0400
committerAnas Nashif <nashif@linux.intel.com>2016-11-02 22:05:29 +0000
commit21a0c5973a8c367cbe3f3b374552c2f9e7352e42 (patch)
tree31b647d2498dd3395a7279fbcb0b788e0f98f245 /samples/legacy
parent886677c3dea424c4c4ef18a6925c4b01ba944ac5 (diff)
samples: cpp synchronization: move to legacy/
Change-Id: I7cc7842238c9e7cca00b45171d90026abfd4e00d Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Diffstat (limited to 'samples/legacy')
-rw-r--r--samples/legacy/cpp_synchronization/microkernel/Makefile6
-rw-r--r--samples/legacy/cpp_synchronization/microkernel/README.txt52
-rw-r--r--samples/legacy/cpp_synchronization/microkernel/prj.conf3
-rw-r--r--samples/legacy/cpp_synchronization/microkernel/prj.mdef11
-rw-r--r--samples/legacy/cpp_synchronization/microkernel/sample.tc15
-rw-r--r--samples/legacy/cpp_synchronization/microkernel/src/Makefile1
-rw-r--r--samples/legacy/cpp_synchronization/microkernel/src/main.cpp165
-rw-r--r--samples/legacy/cpp_synchronization/microkernel/testcase.ini5
-rw-r--r--samples/legacy/cpp_synchronization/nanokernel/Makefile6
-rw-r--r--samples/legacy/cpp_synchronization/nanokernel/README.txt51
-rw-r--r--samples/legacy/cpp_synchronization/nanokernel/prj.conf2
-rw-r--r--samples/legacy/cpp_synchronization/nanokernel/sample.tc5
-rw-r--r--samples/legacy/cpp_synchronization/nanokernel/src/Makefile1
-rw-r--r--samples/legacy/cpp_synchronization/nanokernel/src/main.cpp168
-rw-r--r--samples/legacy/cpp_synchronization/nanokernel/testcase.ini4
15 files changed, 495 insertions, 0 deletions
diff --git a/samples/legacy/cpp_synchronization/microkernel/Makefile b/samples/legacy/cpp_synchronization/microkernel/Makefile
new file mode 100644
index 000000000..0d56ce66d
--- /dev/null
+++ b/samples/legacy/cpp_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/cpp_synchronization/microkernel/README.txt b/samples/legacy/cpp_synchronization/microkernel/README.txt
new file mode 100644
index 000000000..6c03c9a19
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/microkernel/README.txt
@@ -0,0 +1,52 @@
+Title: C++ Synchronization
+
+Description:
+
+The sample project illustrates usage of pure virtual class, member
+functions with different types of arguments, global objects constructor
+invocation.
+
+A simple application 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:
+
+task_a: Hello World!
+task_b: Hello World!
+task_a: Hello World!
+task_b: Hello World!
+task_a: Hello World!
+task_b: Hello World!
+task_a: Hello World!
+task_b: Hello World!
+task_a: Hello World!
+task_b: Hello World!
+
+<repeats endlessly>
diff --git a/samples/legacy/cpp_synchronization/microkernel/prj.conf b/samples/legacy/cpp_synchronization/microkernel/prj.conf
new file mode 100644
index 000000000..2a189d969
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/microkernel/prj.conf
@@ -0,0 +1,3 @@
+CONFIG_STDOUT_CONSOLE=y
+CONFIG_COMPILER_OPT="-O0"
+CONFIG_CPLUSPLUS=y
diff --git a/samples/legacy/cpp_synchronization/microkernel/prj.mdef b/samples/legacy/cpp_synchronization/microkernel/prj.mdef
new file mode 100644
index 000000000..faeb7159b
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/microkernel/prj.mdef
@@ -0,0 +1,11 @@
+% Application : C++ demo
+
+% TASK NAME PRIO ENTRY STACK GROUPS
+% ==================================
+ TASK TASKA 7 task_a 2048 [EXE]
+ TASK TASKB 7 task_b 2048 [EXE]
+
+% SEMA NAME
+% =============
+ SEMA TASKASEM
+ SEMA TASKBSEM
diff --git a/samples/legacy/cpp_synchronization/microkernel/sample.tc b/samples/legacy/cpp_synchronization/microkernel/sample.tc
new file mode 100644
index 000000000..c70d5754c
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/microkernel/sample.tc
@@ -0,0 +1,15 @@
+# @testcase dynamic
+# d2000 have not enough RAM for this
+# _ctb: there are no configs
+# arduino_101_sss, quark_se_sss_ctb: task_arch.h not found -> micro not supported
+# @targets \
+# board:(?!quark_d2000_crb) \
+# board:(?!quark_se_sss_ctb) \
+# board:(?!quark_se_c1000_ss_devboard) \
+# board:(?!quark_se_sss_dvp) \
+# board:(?!quark_se_sss_emu) \
+# board:(?!quark_se_ctb) \
+# board:(?!arduino_101_sss) \
+#
+# @eval console-rx %(console)s:5 task_a: Hello World!
+# @eval console-rx %(console)s:5 task_b: Hello World!
diff --git a/samples/legacy/cpp_synchronization/microkernel/src/Makefile b/samples/legacy/cpp_synchronization/microkernel/src/Makefile
new file mode 100644
index 000000000..00066e156
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/microkernel/src/Makefile
@@ -0,0 +1 @@
+obj-y = main.o
diff --git a/samples/legacy/cpp_synchronization/microkernel/src/main.cpp b/samples/legacy/cpp_synchronization/microkernel/src/main.cpp
new file mode 100644
index 000000000..bb7870674
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/microkernel/src/main.cpp
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2015-2016 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.
+ */
+
+/**
+ * @file C++ Synchronization demo. Uses basic C++ functionality.
+ */
+
+#include <stdio.h>
+
+/**
+ * @class semaphore the basic pure virtual semaphore class
+ */
+class semaphore {
+public:
+ virtual int wait(void) = 0;
+ virtual int wait(int timeout) = 0;
+ virtual void give(void) = 0;
+};
+
+/* specify delay between greetings (in ms); compute equivalent in ticks */
+
+#define SLEEPTIME 500
+#define SLEEPTICKS (SLEEPTIME * sys_clock_ticks_per_sec / 1000)
+
+/*
+ * Microkernel version of C++ synchronization demo has two tasks that utilize
+ * semaphores and sleeps to take turns printing a greeting message at
+ * a controlled rate.
+ */
+
+#include <zephyr.h>
+
+/*
+ * @class task_semaphore
+ * @brief miscrokernel task semaphore
+ *
+ * Class derives from the pure virtual semaphore class and
+ * implements it's methods for the microkernel semaphore
+ */
+class task_semaphore: public semaphore {
+protected:
+#ifdef CONFIG_KERNEL_V2
+ struct k_sem _sema_internal;
+#else
+ struct _k_sem_struct _sema_internal;
+#endif
+ ksem_t sema;
+public:
+ task_semaphore();
+ virtual ~task_semaphore() {}
+ virtual int wait(void);
+ virtual int wait(int timeout);
+ virtual void give(void);
+};
+
+/*
+ * @brief task_semaphore basic constructor
+ */
+#ifdef CONFIG_KERNEL_V2
+task_semaphore::task_semaphore():
+ _sema_internal(K_SEM_INITIALIZER(_sema_internal, 0, UINT32_MAX))
+#else
+task_semaphore::task_semaphore():
+ _sema_internal(__K_SEMAPHORE_DEFAULT)
+#endif
+{
+ printf("Create semaphore %p\n", this);
+ sema = (ksem_t)&_sema_internal;
+}
+
+/*
+ * @brief wait for a semaphore
+ *
+ * Test a semaphore to see if it has been signaled. If the signal
+ * count is greater than zero, it is decremented.
+ *
+ * @return RC_OK on success, RC_FAIL on error
+ */
+int task_semaphore::wait(void)
+{
+ return task_sem_take(sema, TICKS_UNLIMITED);
+}
+
+/*
+ * @brief wait for a semaphore within a specified timeout
+ * Test a semaphore to see if it has been signaled. If the signal
+ * count is greater than zero, it is decremented. The function
+ * waits for the specified timeout
+ *
+ * @param timeout the specified timeout in ticks
+ *
+ * @return RC_OK on success, RC_FAIL on error or RC_TIME on timeout
+ */
+int task_semaphore::wait(int timeout)
+{
+ return task_sem_take(sema, timeout);
+}
+
+/**
+ *
+ * @brief Signal a semaphore
+ *
+ * This routine signals the specified semaphore.
+ *
+ * @return N/A
+ */
+void task_semaphore::give(void)
+{
+ task_sem_give(sema);
+}
+
+/*
+ *
+ * @param taskname task identification string
+ * @param mySem task's own semaphore
+ * @param otherSem other task's semaphore
+ *
+ */
+void hello_loop(const char *taskname,
+ task_semaphore& my_sem,
+ task_semaphore& other_sem)
+{
+ while (1) {
+ my_sem.wait();
+
+ /* say "hello" */
+ printf("%s: Hello World!\n", taskname);
+
+ /* wait a while, then let other task have a turn */
+ task_sleep(SLEEPTICKS);
+ other_sem.give();
+ }
+}
+
+/* two tasks synchronization semaphores */
+task_semaphore sem_a;
+task_semaphore sem_b;
+
+extern "C" void task_a(void)
+{
+ /* taskA gives its own semaphore, allowing it to say hello right away */
+ sem_a.give();
+
+ /* invoke routine that allows task to ping-pong hello messages with taskB */
+ hello_loop(__FUNCTION__, sem_a, sem_b);
+}
+
+extern "C" void task_b(void)
+{
+ /* invoke routine that allows task to ping-pong hello messages with taskA */
+ hello_loop(__FUNCTION__, sem_b, sem_a);
+}
diff --git a/samples/legacy/cpp_synchronization/microkernel/testcase.ini b/samples/legacy/cpp_synchronization/microkernel/testcase.ini
new file mode 100644
index 000000000..b5343f5eb
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/microkernel/testcase.ini
@@ -0,0 +1,5 @@
+[test]
+build_only = true
+tags = apps unified_capable
+kernel = micro
+filter = ZEPHYR_GCC_VARIANT != "issm"
diff --git a/samples/legacy/cpp_synchronization/nanokernel/Makefile b/samples/legacy/cpp_synchronization/nanokernel/Makefile
new file mode 100644
index 000000000..6fe47af43
--- /dev/null
+++ b/samples/legacy/cpp_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/cpp_synchronization/nanokernel/README.txt b/samples/legacy/cpp_synchronization/nanokernel/README.txt
new file mode 100644
index 000000000..e6a61b901
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/nanokernel/README.txt
@@ -0,0 +1,51 @@
+Title: C++ Synchronization
+
+Description:
+The sample project illustrates usage of pure virtual class, member
+functions with different types of arguments, global objects constructor
+invocation.
+
+A simple application 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!
+fiber_entry: Hello World!
+main: Hello World!
+fiber_entry: Hello World!
+main: Hello World!
+fiber_entry: Hello World!
+main: Hello World!
+fiber_entry: Hello World!
+main: Hello World!
+fiber_entry: Hello World!
+
+<repeats endlessly>
diff --git a/samples/legacy/cpp_synchronization/nanokernel/prj.conf b/samples/legacy/cpp_synchronization/nanokernel/prj.conf
new file mode 100644
index 000000000..fdd50ca0f
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/nanokernel/prj.conf
@@ -0,0 +1,2 @@
+CONFIG_STDOUT_CONSOLE=y
+CONFIG_CPLUSPLUS=y
diff --git a/samples/legacy/cpp_synchronization/nanokernel/sample.tc b/samples/legacy/cpp_synchronization/nanokernel/sample.tc
new file mode 100644
index 000000000..91a8ae2ab
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/nanokernel/sample.tc
@@ -0,0 +1,5 @@
+# @testcase dynamic
+#
+# @eval console-rx %(console)s:20 Create semaphore
+# @eval console-rx %(console)s:20 main: Hello World!
+# @eval console-rx %(console)s:20 fiber_entry: Hello World!
diff --git a/samples/legacy/cpp_synchronization/nanokernel/src/Makefile b/samples/legacy/cpp_synchronization/nanokernel/src/Makefile
new file mode 100644
index 000000000..00066e156
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/nanokernel/src/Makefile
@@ -0,0 +1 @@
+obj-y = main.o
diff --git a/samples/legacy/cpp_synchronization/nanokernel/src/main.cpp b/samples/legacy/cpp_synchronization/nanokernel/src/main.cpp
new file mode 100644
index 000000000..e28e1f97d
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/nanokernel/src/main.cpp
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2015-2016 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.
+ */
+
+/**
+ * @file C++ Synchronization demo. Uses basic C++ functionality.
+ */
+
+#include <stdio.h>
+
+/**
+ * @class semaphore the basic pure virtual semaphore class
+ */
+class semaphore {
+public:
+ virtual int wait(void) = 0;
+ virtual int wait(int timeout) = 0;
+ virtual void give(void) = 0;
+};
+
+/* specify delay between greetings (in ms); compute equivalent in ticks */
+
+#define SLEEPTIME 500
+#define SLEEPTICKS (SLEEPTIME * sys_clock_ticks_per_sec / 1000)
+
+/*
+ * Nanokernel version of C++ synchronization demo has a task and a fiber that
+ * utilize semaphores and timers to take turns printing a greeting message at
+ * a controlled rate.
+ */
+
+#include <nanokernel.h>
+#include <arch/cpu.h>
+
+#define STACKSIZE 2000
+
+char __stack fiber_stack[STACKSIZE];
+
+/*
+ * @class nano_semaphore
+ * @brief nano semaphore
+ *
+ * Class derives from the pure virtual semaphore class and
+ * implements it's methods for the nanokernel semaphore
+ */
+class nano_semaphore: public semaphore {
+protected:
+ struct nano_sem _sema_internal;
+public:
+ nano_semaphore();
+ virtual ~nano_semaphore() {}
+ virtual int wait(void);
+ virtual int wait(int timeout);
+ virtual void give(void);
+};
+
+/*
+ * @brief nano_semaphore basic constructor
+ */
+nano_semaphore::nano_semaphore()
+{
+ printf("Create semaphore %p\n", this);
+ nano_sem_init(&_sema_internal);
+}
+
+/*
+ * @brief wait for a semaphore
+ *
+ * Test a semaphore to see if it has been signaled. If the signal
+ * count is greater than zero, it is decremented.
+ *
+ * @return 1 when semaphore is available
+ */
+int nano_semaphore::wait(void)
+{
+ nano_sem_take(&_sema_internal, TICKS_UNLIMITED);
+ return 1;
+}
+
+/*
+ * @brief wait for a semaphore within a specified timeout
+ *
+ * Test a semaphore to see if it has been signaled. If the signal
+ * count is greater than zero, it is decremented. The function
+ * waits for timeout specified
+ *
+ * @param timeout the specified timeout in ticks
+ *
+ * @return 1 if semaphore is available, 0 if timed out
+ */
+int nano_semaphore::wait(int timeout)
+{
+ return nano_sem_take(&_sema_internal, timeout);
+}
+
+/**
+ *
+ * @brief Signal a semaphore
+ *
+ * This routine signals the specified semaphore.
+ *
+ * @return N/A
+ */
+void nano_semaphore::give(void)
+{
+ nano_sem_give(&_sema_internal);
+}
+
+/* task and fiber synchronization semaphores */
+nano_semaphore nano_sem_fiber;
+nano_semaphore nano_sem_task;
+
+void fiber_entry(void)
+{
+ struct nano_timer timer;
+ uint32_t data[2] = {0, 0};
+
+ nano_timer_init(&timer, data);
+
+ while (1) {
+ /* wait for task to let us have a turn */
+ nano_sem_fiber.wait();
+
+ /* say "hello" */
+ printf("%s: Hello World!\n", __FUNCTION__);
+
+ /* wait a while, then let task have a turn */
+ nano_fiber_timer_start(&timer, SLEEPTICKS);
+ nano_fiber_timer_test(&timer, TICKS_UNLIMITED);
+ nano_sem_task.give();
+ }
+}
+
+void main(void)
+{
+ struct nano_timer timer;
+ uint32_t data[2] = {0, 0};
+
+ task_fiber_start(&fiber_stack[0], STACKSIZE,
+ (nano_fiber_entry_t) fiber_entry, 0, 0, 7, 0);
+
+ nano_timer_init(&timer, data);
+
+ while (1) {
+ /* say "hello" */
+ printf("%s: Hello World!\n", __FUNCTION__);
+
+ /* wait a while, then let fiber have a turn */
+ nano_task_timer_start(&timer, SLEEPTICKS);
+ nano_task_timer_test(&timer, TICKS_UNLIMITED);
+ nano_sem_fiber.give();
+
+ /* now wait for fiber to let us have a turn */
+ nano_sem_task.wait();
+ }
+}
diff --git a/samples/legacy/cpp_synchronization/nanokernel/testcase.ini b/samples/legacy/cpp_synchronization/nanokernel/testcase.ini
new file mode 100644
index 000000000..943ef7859
--- /dev/null
+++ b/samples/legacy/cpp_synchronization/nanokernel/testcase.ini
@@ -0,0 +1,4 @@
+[test]
+build_only = true
+tags = apps unified_capable
+filter = ZEPHYR_GCC_VARIANT != "issm"