aboutsummaryrefslogtreecommitdiff
path: root/tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/mail/main.cpp
diff options
context:
space:
mode:
authorJun Wako <[email protected]>2015-04-24 16:26:14 +0900
committerJun Wako <[email protected]>2015-04-24 16:26:14 +0900
commit1fe4406f374291ab2e86e95a97341fd9c475fcb8 (patch)
tree1be0e16b4b07b5a31ea97ec50a9eb13a288c3d27 /tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/mail/main.cpp
parenta20ef7052c6e937d2f7672dd59456e55a5c08296 (diff)
downloadqmk_firmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.tar.gz
qmk_firmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.zip
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
b9e0ea0 Merge commit '7fa9d8bdea3773d1195b04d98fcf27cf48ddd81d' as 'tool/mbed/mbed-sdk' 7fa9d8b Squashed 'tool/mbed/mbed-sdk/' content from commit 7c21ce5 git-subtree-dir: tmk_core git-subtree-split: b9e0ea08cb940de20b3610ecdda18e9d8cd7c552
Diffstat (limited to 'tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/mail/main.cpp')
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/mail/main.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/mail/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/mail/main.cpp
new file mode 100644
index 0000000000..105d3eafbf
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/rtos/mbed/mail/main.cpp
@@ -0,0 +1,75 @@
+#include "mbed.h"
+#include "test_env.h"
+#include "rtos.h"
+
+typedef struct {
+ float voltage; /* AD result of measured voltage */
+ float current; /* AD result of measured current */
+ uint32_t counter; /* A counter value */
+} mail_t;
+
+#define CREATE_VOLTAGE(COUNTER) (COUNTER * 0.1) * 33
+#define CREATE_CURRENT(COUNTER) (COUNTER * 0.1) * 11
+#define QUEUE_SIZE 16
+#define QUEUE_PUT_DELAY 100
+
+/*
+ * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
+ * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
+ * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
+ */
+#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
+ #define STACK_SIZE DEFAULT_STACK_SIZE/4
+#else
+ #define STACK_SIZE DEFAULT_STACK_SIZE
+#endif
+
+Mail<mail_t, QUEUE_SIZE> mail_box;
+
+void send_thread (void const *argument) {
+ static uint32_t i = 10;
+ while (true) {
+ i++; // fake data update
+ mail_t *mail = mail_box.alloc();
+ mail->voltage = CREATE_VOLTAGE(i);
+ mail->current = CREATE_CURRENT(i);
+ mail->counter = i;
+ mail_box.put(mail);
+ Thread::wait(QUEUE_PUT_DELAY);
+ }
+}
+
+int main (void) {
+ MBED_HOSTTEST_TIMEOUT(20);
+ MBED_HOSTTEST_SELECT(default_auto);
+ MBED_HOSTTEST_DESCRIPTION(Mail messaging);
+ MBED_HOSTTEST_START("RTOS_6");
+
+ Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE);
+ bool result = true;
+ int result_counter = 0;
+
+ while (true) {
+ osEvent evt = mail_box.get();
+ if (evt.status == osEventMail) {
+ mail_t *mail = (mail_t*)evt.value.p;
+ const float expected_voltage = CREATE_VOLTAGE(mail->counter);
+ const float expected_current = CREATE_CURRENT(mail->counter);
+ // Check using macros if received values correspond to values sent via queue
+ bool expected_values = (expected_voltage == mail->voltage) &&
+ (expected_current == mail->current);
+ result = result && expected_values;
+ const char *result_msg = expected_values ? "OK" : "FAIL";
+ printf("%3d %.2fV %.2fA ... [%s]\r\n", mail->counter,
+ mail->voltage,
+ mail->current,
+ result_msg);
+ mail_box.free(mail);
+ if (result == false || ++result_counter == QUEUE_SIZE) {
+ break;
+ }
+ }
+ }
+ MBED_HOSTTEST_RESULT(result);
+ return 0;
+}