Mercurial > hg > Members > kono > Cerium
comparison 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 |
comparison
equal
deleted
inserted
replaced
108:6f3b3dd3c095 | 109:5c194c71eca8 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "TaskManager.h" | |
5 #include "Func.h" | |
6 | |
7 extern void task_init(void); | |
8 | |
9 static int *data; | |
10 static int length = DATA_NUM; | |
11 | |
12 char *help_str = "Usage: ./twice [-length data_length]\n \ | |
13 -length Number of data (default DATA_NUM (Func.h))"; | |
14 | |
15 | |
16 void | |
17 print_data(int *data, int size, char *title) | |
18 { | |
19 printf("%s ---\n", title); | |
20 for (int i = 0; i < size; i++) { | |
21 printf("%2d ", data[i]); | |
22 } | |
23 printf("\n"); | |
24 } | |
25 | |
26 /** | |
27 * タスク終了後の data1, data2 の確認 | |
28 */ | |
29 void | |
30 twice_result(void *a) | |
31 { | |
32 print_data(data, length, "after"); | |
33 free(data); | |
34 } | |
35 | |
36 int | |
37 init(int argc, char **argv) | |
38 { | |
39 for (int i = 1; argv[i]; ++i) { | |
40 if (strcmp(argv[i], "-length") == 0) { | |
41 length = atoi(argv[++i]); | |
42 } | |
43 if (strcmp(argv[i], "--help") == 0) { | |
44 printf("%s\n", help_str); | |
45 return -1; | |
46 } | |
47 } | |
48 | |
49 return 0; | |
50 } | |
51 | |
52 void | |
53 twice_init(void) | |
54 { | |
55 HTask *twice; | |
56 | |
57 data = (int*)manager->malloc(sizeof(int)*length); | |
58 | |
59 for (int i = 0; i < length; i++) { | |
60 data[i] = i; | |
61 } | |
62 | |
63 print_data(data, length, "before"); | |
64 | |
65 /** | |
66 * Create Task | |
67 * create_task(Task ID); | |
68 */ | |
69 twice = manager->create_task(TWICE_TASK); | |
70 twice->set_cpu(SPE_ANY); | |
71 | |
72 /** | |
73 * Set of Input Data | |
74 * add_inData(address of input data, size of input data); | |
75 */ | |
76 twice->add_inData(data, sizeof(int)*length); | |
77 | |
78 /** | |
79 * Set of OutPut area | |
80 * add_outData(address of output area, size of output area); | |
81 */ | |
82 twice->add_outData(data, sizeof(int)*length); | |
83 | |
84 /** | |
85 * Set 32bits parameter | |
86 * add_param(32bit parameter); | |
87 */ | |
88 twice->add_param(length); | |
89 | |
90 twice->set_post(twice_result, NULL); | |
91 | |
92 // add Active Queue | |
93 twice->spawn(); | |
94 } | |
95 | |
96 int | |
97 cerium_main(int argc, char *argv[]) | |
98 { | |
99 if (init(argc, argv) < 0) { | |
100 return -1; | |
101 } | |
102 | |
103 // Task Register | |
104 // ppe/task_init.cc | |
105 task_init(); | |
106 | |
107 twice_init(); | |
108 | |
109 return 0; | |
110 } |