From 40e470af43e76292d60e64881c39c554d3ca9e8a Mon Sep 17 00:00:00 2001 From: Hans-Peter Deifel <hpd@hpdeifel.de> Date: Mon, 10 Oct 2016 03:07:04 +0200 Subject: [PATCH] Add examples for presentation --- app/example1/CMakeLists.txt | 7 +++++ app/example1/example1.cc | 49 ++++++++++++++++++++++++++++++++ app/example1/system.oil | 35 +++++++++++++++++++++++ app/example2/CMakeLists.txt | 7 +++++ app/example2/example2.cc | 51 +++++++++++++++++++++++++++++++++ app/example2/system.oil | 35 +++++++++++++++++++++++ app/example3/CMakeLists.txt | 8 ++++++ app/example3/example3.cc | 56 +++++++++++++++++++++++++++++++++++++ app/example3/system.oil | 35 +++++++++++++++++++++++ 9 files changed, 283 insertions(+) create mode 100644 app/example1/CMakeLists.txt create mode 100644 app/example1/example1.cc create mode 100644 app/example1/system.oil create mode 100644 app/example2/CMakeLists.txt create mode 100644 app/example2/example2.cc create mode 100644 app/example2/system.oil create mode 100644 app/example3/CMakeLists.txt create mode 100644 app/example3/example3.cc create mode 100644 app/example3/system.oil diff --git a/app/example1/CMakeLists.txt b/app/example1/CMakeLists.txt new file mode 100644 index 00000000..ce37977f --- /dev/null +++ b/app/example1/CMakeLists.txt @@ -0,0 +1,7 @@ +DOSEK_BINARY( + NAME example1 + SYSTEM_DESC system.oil + LIBS libtest + TEST_ISO + example1.cc +) diff --git a/app/example1/example1.cc b/app/example1/example1.cc new file mode 100644 index 00000000..0e1d4368 --- /dev/null +++ b/app/example1/example1.cc @@ -0,0 +1,49 @@ +/** + * @defgroup apps Applications + * @brief The applications... + */ + +/** + * @file + * @ingroup apps + * @brief Just a simple test application + */ +#include "os.h" +#include "test/test.h" +#include "machine.h" + +DeclareTask(TaskA); +DeclareTask(TaskB); +DeclareTask(TaskC); + +TEST_MAKE_OS_MAIN( StartOS(0) ); + +int readData() { + return 42; +} + +char buf[2]; + +TASK(TaskA) { + int val = readData(); + if (val == '\n') { + buf[1] = '\n'; + ActivateTask(TaskB); + } + buf[0] = (char)val; + TerminateTask(); +} + +TASK(TaskB) { + kout << "TaskB: " << buf << endl; + TerminateTask(); +} + +TASK(TaskC) { + kout << "task c" << endl; + TerminateTask(); +} + +void PreIdleHook() { + ShutdownMachine(); +} diff --git a/app/example1/system.oil b/app/example1/system.oil new file mode 100644 index 00000000..63f370ec --- /dev/null +++ b/app/example1/system.oil @@ -0,0 +1,35 @@ +CPU TestSystem { + + OS TestSystem { + STATUS = STANDARD; + ERRORHOOK = FALSE; + STARTUPHOOK = FALSE; + SHUTDOWNHOOK = FALSE; + PRETASKHOOK = FALSE; + POSTTASKHOOK = FALSE; + }; + + TASK TaskA { + SCHEDULE = FULL; + PRIORITY = 0; + ACTIVATION = 1; + AUTOSTART = TRUE; + }; + + TASK TaskB { + SCHEDULE = FULL; + PRIORITY = 10; + ACTIVATION = 1; + AUTOSTART = FALSE; + }; + + TASK TaskC { + SCHEDULE = FULL; + PRIORITY = 1; + ACTIVATION = 1; + AUTOSTART = FALSE; + }; + + +}; + diff --git a/app/example2/CMakeLists.txt b/app/example2/CMakeLists.txt new file mode 100644 index 00000000..4ebad91f --- /dev/null +++ b/app/example2/CMakeLists.txt @@ -0,0 +1,7 @@ +DOSEK_BINARY( + NAME example2 + SYSTEM_DESC system.oil + LIBS libtest + TEST_ISO + example2.cc +) diff --git a/app/example2/example2.cc b/app/example2/example2.cc new file mode 100644 index 00000000..152b46f7 --- /dev/null +++ b/app/example2/example2.cc @@ -0,0 +1,51 @@ +/** + * @defgroup apps Applications + * @brief The applications... + */ + +/** + * @file + * @ingroup apps + * @brief Just a simple test application + */ +#include "os.h" +#include "test/test.h" +#include "machine.h" + +DeclareTask(TaskA); +DeclareTask(TaskB); +DeclareTask(TaskC); + +TEST_MAKE_OS_MAIN( StartOS(0) ); + +int readData() { + return 42; +} + +TASK(TaskA) { + int val = readData(); + if (val == 42) { + ActivateTask(TaskB); + } else { + ActivateTask(TaskB); + } + + for (val = 0; val < 2; val++) { + ActivateTask(TaskC); + } + TerminateTask(); +} + +TASK(TaskB) { + kout << "TaskB" << endl; + TerminateTask(); +} + +TASK(TaskC) { + kout << "task c" << endl; + TerminateTask(); +} + +void PreIdleHook() { + ShutdownMachine(); +} diff --git a/app/example2/system.oil b/app/example2/system.oil new file mode 100644 index 00000000..63f370ec --- /dev/null +++ b/app/example2/system.oil @@ -0,0 +1,35 @@ +CPU TestSystem { + + OS TestSystem { + STATUS = STANDARD; + ERRORHOOK = FALSE; + STARTUPHOOK = FALSE; + SHUTDOWNHOOK = FALSE; + PRETASKHOOK = FALSE; + POSTTASKHOOK = FALSE; + }; + + TASK TaskA { + SCHEDULE = FULL; + PRIORITY = 0; + ACTIVATION = 1; + AUTOSTART = TRUE; + }; + + TASK TaskB { + SCHEDULE = FULL; + PRIORITY = 10; + ACTIVATION = 1; + AUTOSTART = FALSE; + }; + + TASK TaskC { + SCHEDULE = FULL; + PRIORITY = 1; + ACTIVATION = 1; + AUTOSTART = FALSE; + }; + + +}; + diff --git a/app/example3/CMakeLists.txt b/app/example3/CMakeLists.txt new file mode 100644 index 00000000..5d8b2dfc --- /dev/null +++ b/app/example3/CMakeLists.txt @@ -0,0 +1,8 @@ +DOSEK_BINARY( + NAME example3 + SYSTEM_DESC system.oil + LIBS libtest + TEST_ISO + example3.cc +) + diff --git a/app/example3/example3.cc b/app/example3/example3.cc new file mode 100644 index 00000000..49954837 --- /dev/null +++ b/app/example3/example3.cc @@ -0,0 +1,56 @@ +/** + * @defgroup apps Applications + * @brief The applications... + */ + +/** + * @file + * @ingroup apps + * @brief Just a simple test application + */ +#include "os.h" +#include "test/test.h" + + +DeclareTask(Handler11); +DeclareTask(Handler12); +DeclareTask(Handler13); + +TEST_MAKE_OS_MAIN( StartOS(0) ) + +int a = 0; + +extern "C" void bar() { + test_trace('b'); + ActivateTask(Handler13); +} + +TASK(Handler11) { + a++; + if (a > 3) { + test_trace('1'); + bar(); + } + test_trace('C'); + ChainTask(Handler13); +} + +TASK(Handler12) { + test_trace('2'); + ChainTask(Handler11); +} + +TASK(Handler13) { + test_trace('3'); + if (a < 5) + ActivateTask(Handler12); + Machine::nop(); + TerminateTask(); +} + +void PreIdleHook() { + /* The testcase has finished, check the output */ + test_trace_assert("C32C32C321b3C321b3C3"); + test_finish(); + ShutdownMachine(); +} diff --git a/app/example3/system.oil b/app/example3/system.oil new file mode 100644 index 00000000..762091f4 --- /dev/null +++ b/app/example3/system.oil @@ -0,0 +1,35 @@ +CPU TestSystem { + + OS TestSystem { + STATUS = STANDARD; + ERRORHOOK = FALSE; + STARTUPHOOK = FALSE; + SHUTDOWNHOOK = FALSE; + PRETASKHOOK = FALSE; + POSTTASKHOOK = FALSE; + }; + + TASK Handler11 { + SCHEDULE = FULL; + PRIORITY = 4; + ACTIVATION = 1; + AUTOSTART = TRUE; + }; + + TASK Handler12 { + SCHEDULE = FULL; + PRIORITY = 3; + ACTIVATION = 1; + AUTOSTART = FALSE; + }; + + TASK Handler13 { + SCHEDULE = FULL; + PRIORITY = 5; + ACTIVATION = 1; + AUTOSTART = FALSE; + }; + + +}; + -- GitLab