summaryrefslogtreecommitdiff
path: root/cesar/test_general/ecos/src/two_thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/test_general/ecos/src/two_thread.c')
-rw-r--r--cesar/test_general/ecos/src/two_thread.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/cesar/test_general/ecos/src/two_thread.c b/cesar/test_general/ecos/src/two_thread.c
new file mode 100644
index 0000000000..d99f5dec87
--- /dev/null
+++ b/cesar/test_general/ecos/src/two_thread.c
@@ -0,0 +1,79 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file two_thread.c
+ * \brief test program with only two threads
+ * \ingroup
+ *
+ * this is a test program to check eCos well work
+ */
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+
+#define THREAD_STACK_SIZE (4096 / sizeof(int))
+
+int thread_a_stack[THREAD_STACK_SIZE];
+int thread_b_stack[THREAD_STACK_SIZE];
+cyg_handle_t thread_a_handle;
+cyg_handle_t thread_b_handle;
+cyg_thread thread_a_obj;
+cyg_thread thread_b_obj;
+
+//
+// Thread A.
+//
+void thread_a(cyg_addrword_t index)
+{
+ unsigned int my_counter = 0;
+ while(1)
+ {
+ diag_printf("A: ct=%d\n",my_counter);
+ my_counter++;
+
+ // Delay for 5 seconds (10ms * 500ticks).
+ cyg_thread_delay(500);
+ }
+}
+
+//
+// Thread B.
+//
+void thread_b(cyg_addrword_t index)
+{
+ unsigned int my_counter = 0;
+ while(1)
+ {
+ diag_printf("B: ct=%d\n",my_counter);
+ my_counter++;
+
+ // Delay for 2 seconds (10ms * 200ticks).
+ cyg_thread_delay(200);
+ }
+}
+
+//
+// Main.
+//
+void cyg_user_start(void)
+{
+
+ cyg_thread_create(12, thread_a, (cyg_addrword_t) 0,
+ "Thread B", &thread_a_stack, THREAD_STACK_SIZE,
+ &thread_a_handle, &thread_a_obj);
+ cyg_thread_create(12, thread_b, (cyg_addrword_t) 0,
+ "Thread A", &thread_b_stack, THREAD_STACK_SIZE,
+ &thread_b_handle, &thread_b_obj);
+
+ cyg_thread_resume(thread_a_handle);
+ cyg_thread_resume(thread_b_handle);
+ diag_write_string("scheduler starting...\n");
+
+ cyg_scheduler_start();
+}
+