summaryrefslogtreecommitdiff
path: root/test_general/ecos/src/mesbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'test_general/ecos/src/mesbox.c')
-rw-r--r--test_general/ecos/src/mesbox.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/test_general/ecos/src/mesbox.c b/test_general/ecos/src/mesbox.c
new file mode 100644
index 0000000000..f7f463f1c1
--- /dev/null
+++ b/test_general/ecos/src/mesbox.c
@@ -0,0 +1,91 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file mesbox.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+
+#define THREAD_STACK_SIZE (20480 / sizeof(int))
+
+int thread_a_stack[THREAD_STACK_SIZE];
+cyg_handle_t thread_a_handle;
+cyg_thread thread_a_obj;
+int thread_b_stack[THREAD_STACK_SIZE];
+cyg_handle_t thread_b_handle;
+cyg_thread thread_b_obj;
+
+cyg_mbox mbox;
+cyg_handle_t mbox_handle;
+
+char transfert_mess[] = "oh what a wonderful mailbox";
+
+//
+// Thread A.
+//
+void thread_a(cyg_addrword_t index)
+{
+ while (1)
+ {
+ // Delay for 5 seconds (10ms * 500ticks).
+ cyg_thread_delay(500);
+
+ // Send a message to Thread B.
+ cyg_mbox_put(mbox_handle, (void *)transfert_mess);
+ }
+}
+
+//
+// Thread B.
+//
+void thread_b(cyg_addrword_t index)
+{
+ char *message;
+
+ while (1)
+ {
+ // Wait for the message.
+ message = (char*) cyg_mbox_get(mbox_handle);
+
+ // Make sure we received the message before attempting
+ // to process it.
+ if ( message != NULL )
+ {
+ // Process the message.
+ diag_printf("Message received : %s\n", message);
+ }
+ }
+}
+
+//
+// Main.
+//
+void cyg_user_start(void)
+{
+ cyg_thread_create(12, thread_a, (cyg_addrword_t) 0,
+ "Thread A", &thread_a_stack, THREAD_STACK_SIZE,
+ &thread_a_handle, &thread_a_obj);
+ cyg_thread_create(13, thread_b, (cyg_addrword_t) 0,
+ "Thread B", &thread_b_stack, THREAD_STACK_SIZE,
+ &thread_b_handle, &thread_b_obj);
+
+ cyg_mbox_create(&mbox_handle, &mbox);
+
+ cyg_thread_resume(thread_a_handle);
+ cyg_thread_resume(thread_b_handle);
+
+ diag_write_string("Starting Scheduler...\n");
+
+ cyg_scheduler_start();
+}
+