summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorAllan Stephens <allan.stephens@windriver.com>2016-10-21 10:02:50 -0500
committerAnas Nashif <nashif@linux.intel.com>2016-10-25 00:10:36 +0000
commit0c31ed273e499e49f08950ae184b782b22d35b14 (patch)
tree2a71d54b73c53e412a8aa8541e33994f5f038cba /samples
parentf4ba3b1d5d5b5b20cade4e96cefe9c9ed6e3ac1e (diff)
unified/test: Adapt C++ sample application
Microkernel and nanokernel tests now use customized source code to eliminate use of MICROKERNEL and NANOKERNEL config options. Change-Id: Ic3617df34487911af1607ab46f469c5e1212d3f7 Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/cpp_synchronization/microkernel/src/main.cpp150
-rw-r--r--samples/cpp_synchronization/microkernel/testcase.ini2
-rw-r--r--samples/cpp_synchronization/nanokernel/Makefile1
-rw-r--r--samples/cpp_synchronization/nanokernel/src/Makefile1
-rw-r--r--samples/cpp_synchronization/nanokernel/src/main.cpp168
-rw-r--r--samples/cpp_synchronization/nanokernel/testcase.ini2
6 files changed, 182 insertions, 142 deletions
diff --git a/samples/cpp_synchronization/microkernel/src/main.cpp b/samples/cpp_synchronization/microkernel/src/main.cpp
index 0bd82c3d6..bb7870674 100644
--- a/samples/cpp_synchronization/microkernel/src/main.cpp
+++ b/samples/cpp_synchronization/microkernel/src/main.cpp
@@ -35,8 +35,6 @@ public:
#define SLEEPTIME 500
#define SLEEPTICKS (SLEEPTIME * sys_clock_ticks_per_sec / 1000)
-#ifdef CONFIG_MICROKERNEL
-
/*
* Microkernel version of C++ synchronization demo has two tasks that utilize
* semaphores and sleeps to take turns printing a greeting message at
@@ -54,7 +52,11 @@ public:
*/
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();
@@ -67,7 +69,13 @@ public:
/*
* @brief task_semaphore basic constructor
*/
-task_semaphore::task_semaphore(): _sema_internal(__K_SEMAPHORE_DEFAULT)
+#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;
@@ -155,139 +163,3 @@ 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);
}
-
-#else /* CONFIG_NANOKERNEL */
-
-/*
- * 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();
- }
-}
-
-#endif /* CONFIG_MICROKERNEL || CONFIG_NANOKERNEL */
diff --git a/samples/cpp_synchronization/microkernel/testcase.ini b/samples/cpp_synchronization/microkernel/testcase.ini
index 77dfec4fb..b5343f5eb 100644
--- a/samples/cpp_synchronization/microkernel/testcase.ini
+++ b/samples/cpp_synchronization/microkernel/testcase.ini
@@ -1,5 +1,5 @@
[test]
build_only = true
-tags = apps
+tags = apps unified_capable
kernel = micro
filter = ZEPHYR_GCC_VARIANT != "issm"
diff --git a/samples/cpp_synchronization/nanokernel/Makefile b/samples/cpp_synchronization/nanokernel/Makefile
index ed5f0362e..6fe47af43 100644
--- a/samples/cpp_synchronization/nanokernel/Makefile
+++ b/samples/cpp_synchronization/nanokernel/Makefile
@@ -1,6 +1,5 @@
KERNEL_TYPE = nano
BOARD ?= qemu_x86
-SOURCE_DIR = $(ZEPHYR_BASE)/samples/cpp_synchronization/microkernel/src/
CONF_FILE = prj.conf
diff --git a/samples/cpp_synchronization/nanokernel/src/Makefile b/samples/cpp_synchronization/nanokernel/src/Makefile
new file mode 100644
index 000000000..00066e156
--- /dev/null
+++ b/samples/cpp_synchronization/nanokernel/src/Makefile
@@ -0,0 +1 @@
+obj-y = main.o
diff --git a/samples/cpp_synchronization/nanokernel/src/main.cpp b/samples/cpp_synchronization/nanokernel/src/main.cpp
new file mode 100644
index 000000000..e28e1f97d
--- /dev/null
+++ b/samples/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/cpp_synchronization/nanokernel/testcase.ini b/samples/cpp_synchronization/nanokernel/testcase.ini
index a1fa5b670..943ef7859 100644
--- a/samples/cpp_synchronization/nanokernel/testcase.ini
+++ b/samples/cpp_synchronization/nanokernel/testcase.ini
@@ -1,4 +1,4 @@
[test]
build_only = true
-tags = apps
+tags = apps unified_capable
filter = ZEPHYR_GCC_VARIANT != "issm"