0
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include "TaskManager.h"
|
|
5 #include "Func.h"
|
|
6 #include "main.h"
|
|
7
|
|
8 extern void task_init(void);
|
|
9
|
|
10 static int count = 10;
|
|
11
|
|
12 extern TaskManager *manager;
|
|
13
|
|
14 extern void queueInfoTest(int count);
|
|
15
|
|
16 static QueueInfo<TaskQueue> *mainPool = new QueueInfo<TaskQueue>() ;
|
|
17
|
|
18 const char *usr_help_str = "Usage: ./hello [-cpu spe_num] [-count N]\n\
|
|
19 -cpu Number of SPE (default 1) \n\
|
|
20 -count Number of task is print \"Hello, World!!\"";
|
|
21
|
|
22 int
|
|
23 init(int argc, char **argv)
|
|
24 {
|
|
25 for (int i = 1; argv[i]; ++i) {
|
|
26 if (strcmp(argv[i], "-count") == 0) {
|
|
27 count = atoi(argv[++i]);
|
|
28 }
|
|
29
|
|
30 }
|
|
31
|
|
32 return 0;
|
|
33 }
|
|
34
|
|
35 Queues queues;
|
|
36
|
|
37 static void
|
|
38 repeat(SchedTask *s, void *arg, void *dm)
|
|
39 {
|
|
40 static int count = 4;
|
|
41 QueuePtr q = (QueuePtr) arg;
|
|
42 TaskManager *manager = q->m;
|
|
43
|
|
44 if (count-->0) {
|
|
45 HTask *t = manager->create_task(HELLO_TASK);
|
|
46 t->set_post(repeat, arg, 0);
|
|
47 t->set_param(0,(memaddr)q->i);
|
|
48 t->set_param(1,(memaddr)arg);
|
|
49 t->spawn();
|
|
50
|
|
51 printf("[PPE] Create Task : Hello count=%d id=%d\n\n",count, q->i);
|
|
52 } else {
|
|
53 printf("[PPE] End Task : Hello id=%d\n\n", q->i);
|
|
54 }
|
|
55 }
|
|
56
|
|
57 void
|
|
58 hello_init(TaskManager *manager)
|
|
59 {
|
|
60
|
|
61 if (count >MAX_QUEUE) return;
|
|
62
|
|
63 queues.m = manager;
|
|
64 queues.i = 0;
|
|
65 for (int i = 0; i < MAX_QUEUE; i++) {
|
|
66 QueueInfo<TaskQueue> *q = new QueueInfo<TaskQueue>(mainPool) ;
|
|
67 // QueueInfo<TaskQueue> *q = new QueueInfo<TaskQueue>() ; // wrong
|
|
68 queues.q[i] = q;
|
|
69 }
|
|
70
|
|
71 for (int i = 0; i < count; i++) {
|
|
72 /**
|
|
73 * Create Task
|
|
74 * create_task(Task ID);
|
|
75 */
|
|
76 HTask *hello = manager->create_task(HELLO_TASK);
|
|
77
|
|
78 /**
|
|
79 * Select CPU
|
|
80 * SPE_0, SPE_1, SPE_2, SPE_3, SPE_4, SPE_5, SPE_ANY
|
|
81 * if you do not call this, execute PPE.
|
|
82 */
|
|
83 hello->set_cpu(SPE_ANY);
|
|
84
|
|
85 /**
|
|
86 * Set 32bits parameter
|
|
87 * add_param(32bit parameter);
|
|
88 */
|
|
89 QueuePtr q = (QueuePtr) manager->allocate(sizeof(Queues));
|
|
90
|
|
91 q->i = i;
|
|
92 q->m = manager;
|
|
93 for (int j = 0; j < MAX_QUEUE; j++) {
|
|
94 q->q[j] = queues.q[j];
|
|
95 }
|
|
96
|
|
97 hello->set_param(0,(memaddr)i);
|
|
98 hello->set_param(1,(memaddr)&queues);
|
|
99 hello->set_post(repeat, (void*) &queues, 0);
|
|
100
|
|
101 hello->spawn();
|
|
102 }
|
|
103 }
|
|
104
|
|
105 int
|
|
106 TMmain(TaskManager *manager, int argc, char *argv[])
|
|
107 {
|
|
108 if (init(argc, argv) < 0) {
|
|
109 return -1;
|
|
110 }
|
|
111 if (count<2) count = 2;
|
|
112
|
|
113 // Task Register
|
|
114 // ppe/task_init.cc
|
|
115 task_init();
|
|
116
|
|
117 queueInfoTest(count);
|
|
118 hello_init(manager);
|
|
119
|
|
120 return 0;
|
|
121 }
|