diff example/basic/main.cc @ 109:5c194c71eca8

Cerium cvs version
author gongo@gendarme.local
date Wed, 12 Nov 2008 17:39:33 +0900
parents
children 465a871f4c07
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/basic/main.cc	Wed Nov 12 17:39:33 2008 +0900
@@ -0,0 +1,110 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "TaskManager.h"
+#include "Func.h"
+
+extern void task_init(void);
+
+static int *data;
+static int length = DATA_NUM;
+
+char *help_str = "Usage: ./twice [-length data_length]\n \
+  -length  Number of data (default DATA_NUM (Func.h))";
+
+
+void
+print_data(int *data, int size, char *title)
+{
+    printf("%s ---\n", title);
+    for (int i = 0; i < size; i++) {
+	printf("%2d ", data[i]);
+    }
+    printf("\n");
+}
+
+/**
+ * タスク終了後の data1, data2 の確認
+ */
+void
+twice_result(void *a)
+{
+    print_data(data, length, "after");
+    free(data);
+}
+
+int
+init(int argc, char **argv)
+{
+    for (int i = 1; argv[i]; ++i) {
+        if (strcmp(argv[i], "-length") == 0) {
+            length = atoi(argv[++i]);
+        }
+        if (strcmp(argv[i], "--help") == 0) {
+            printf("%s\n", help_str);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+void
+twice_init(void)
+{
+    HTask *twice;
+
+    data = (int*)manager->malloc(sizeof(int)*length);
+
+    for (int i = 0; i < length; i++) {
+	data[i] = i;
+    }
+
+    print_data(data, length, "before");
+
+    /**
+     * Create Task
+     *   create_task(Task ID);
+     */ 
+    twice = manager->create_task(TWICE_TASK);
+    twice->set_cpu(SPE_ANY);
+    
+    /**
+     * Set of Input Data
+     *   add_inData(address of input data, size of input data);
+     */
+    twice->add_inData(data, sizeof(int)*length);
+
+    /**
+     * Set of OutPut area
+     *   add_outData(address of output area, size of output area);
+     */
+    twice->add_outData(data, sizeof(int)*length);
+
+    /**
+     * Set 32bits parameter
+     *   add_param(32bit parameter);
+     */
+    twice->add_param(length);
+
+    twice->set_post(twice_result, NULL);
+
+    // add Active Queue
+    twice->spawn();    
+}
+
+int
+cerium_main(int argc, char *argv[])
+{
+    if (init(argc, argv) < 0) {
+	return -1;
+    }
+
+    // Task Register
+    //   ppe/task_init.cc
+    task_init();
+
+    twice_init();
+
+    return 0;
+}