0
|
1 #ifndef INCLUDED_HTASK
|
|
2 #define INCLUDED_HTASK
|
|
3
|
|
4 #include "base.h"
|
|
5 #include "types.h"
|
|
6 #include "Task.h"
|
|
7 #include "TaskQueue.h"
|
|
8 #include "QueueInfo.h"
|
|
9 #include <stdio.h>
|
|
10
|
|
11 class TaskManagerImpl;
|
|
12 class SchedTask;
|
|
13
|
|
14 typedef void (*PostFunction)(SchedTask *s, void *read, void *write);
|
|
15
|
|
16 extern QueueInfo<TaskQueue>* taskQueuePool;
|
|
17
|
|
18 /*!
|
|
19 @class
|
|
20
|
|
21 @brief
|
|
22
|
|
23 Cerium の Task で、spawn() でキューに格納されて順次実行される。
|
|
24 cpu の指定があれば並列に実行される。
|
|
25 特定の Task を待ち合わせる事が可能。
|
|
26 Task の入出力は dma などで copy される。
|
|
27 */
|
|
28
|
|
29 #include "SimpleTask.h"
|
|
30
|
|
31 class HTask : public SimpleTask {
|
|
32 public:
|
|
33 BASE_NEW_DELETE(HTask);
|
|
34
|
|
35 QueueInfo<TaskQueue> *wait_me; // List of task waiting for me
|
|
36 QueueInfo<TaskQueue> *wait_i; // List of task for which I am waiting
|
|
37 PostFunction post_func;
|
|
38 void *post_arg1;
|
|
39 void *post_arg2;
|
|
40 CPU_TYPE cpu_type;
|
|
41 TaskManagerImpl *mimpl;
|
|
42
|
|
43 HTask *waiter;
|
|
44 HTask *next;
|
|
45 HTask *prev;
|
|
46
|
|
47 struct {
|
|
48 unsigned no_auto_free:1; // bit 0 auto free flag (0 .. auto, 1 manual)
|
|
49 } flag;
|
|
50
|
|
51 void spawn();
|
|
52 void wait_for(HTask *);
|
|
53 void set_cpu(CPU_TYPE type);
|
|
54 void set_post(PostFunction func, void *read, void *write);
|
|
55 Task *create_task_array(int task_id, int num_task, int num_param, int num_inData, int num_outData);
|
|
56 Task *next_task_array(int task_id, Task *t);
|
|
57 void spawn_task_array(Task *t);
|
|
58
|
|
59 HTask *init(int cmd, memaddr rbuf, int rs, memaddr wbuf, int ws) {
|
|
60 init(cmd);
|
|
61 set_input(rbuf, rs);
|
|
62 set_output(wbuf, ws);
|
|
63 return this;
|
|
64 }
|
|
65
|
|
66 void initOnce() {
|
|
67 wait_me = new QueueInfo<TaskQueue>(taskQueuePool);
|
|
68 wait_i = new QueueInfo<TaskQueue>(taskQueuePool);
|
|
69 }
|
|
70
|
|
71 void freeOnce() {
|
|
72 delete wait_me;
|
|
73 delete wait_i;
|
|
74 }
|
|
75
|
|
76 private:
|
|
77
|
|
78 int param_index;
|
|
79 int in_index;
|
|
80 int out_index;
|
|
81
|
|
82 // compatibility
|
|
83 public: // functions
|
|
84 void add_inData_t(memaddr addr, int size) {
|
|
85 Task *t = (Task*)rbuf;
|
|
86 t->set_inData_t(in_index++, addr,size);
|
|
87 }
|
|
88 void add_outData_t(memaddr addr, int size) {
|
|
89 Task *t = (Task*)rbuf;
|
|
90 t->set_outData_t(out_index++, addr,size);
|
|
91 }
|
|
92 void set_inData_t(int index, memaddr addr, int size) {
|
|
93 #ifdef EARLY_TOUCH
|
|
94 if ((unsigned long)addr&0xf) {
|
|
95 printf("inData is not aligned. command = %d, index = %d, addr = 0x%lx, size = %d\n",
|
|
96 command, index, (unsigned long)addr, size);
|
|
97 }
|
|
98 char *p = (char *)addr; char b = *p;
|
|
99 p = (char *)(addr+size-1); b += *p;
|
|
100 #endif
|
|
101 Task *t = (Task*)rbuf;
|
|
102 t->set_inData_t(index, addr,size);
|
|
103 }
|
|
104 void set_outData_t(int index, memaddr addr, int size) {
|
|
105 #ifdef EARLY_TOUCH
|
|
106 if ((unsigned long)addr&0xf) {
|
|
107 printf("inData is not aligned. command = %d, index = %d, addr = 0x%lx, size = %d\n",
|
|
108 command, index, (unsigned long)addr, size);
|
|
109 }
|
|
110 char *p = (char *)addr; char b = *p;
|
|
111 p = (char *)(addr+size-1); b += *p;
|
|
112 #endif
|
|
113 Task *t = (Task*)rbuf;
|
|
114 t->set_outData_t(index, addr,size);
|
|
115 }
|
|
116 void add_param_t(memaddr param) {
|
|
117 Task *t = (Task*)rbuf;
|
|
118 t->set_param_t(param_index++, param);
|
|
119 }
|
|
120 void set_param_t(int index, memaddr param) {
|
|
121 if (command==TaskArray1) {
|
|
122 Task *t = (Task*)rbuf;
|
|
123 t->set_param_t(index, param);
|
|
124 } else {
|
|
125 this->param = param;
|
|
126 }
|
|
127 }
|
|
128
|
|
129 void no_auto_free() {
|
|
130 flag.no_auto_free = 1;
|
|
131 }
|
|
132 void auto_free() {
|
|
133 flag.no_auto_free = 0;
|
|
134 }
|
|
135
|
|
136 void init() {
|
|
137 next = prev = NULL;
|
|
138 waiter = NULL;
|
|
139 }
|
|
140
|
|
141 void init(int cmd) {
|
|
142 command = cmd;
|
|
143 param_index = 0;
|
|
144 in_index = 0;
|
|
145 out_index = 0;
|
|
146 flag.no_auto_free = 0;
|
|
147 self = (memaddr) this;
|
|
148
|
|
149 post_func = NULL;
|
|
150 mimpl = NULL;
|
|
151 cpu_type = CPU_PPE;
|
|
152 }
|
|
153 #define add_param(param) add_param_t((memaddr)(param))
|
|
154 #define set_param(index,param) set_param_t(index, (memaddr) (param))
|
|
155
|
|
156 #define add_inData(addr, size) \
|
|
157 add_inData_t((memaddr)(addr), (size));
|
|
158 #define add_outData(addr, size) \
|
|
159 add_outData_t((memaddr)(addr), (size));
|
|
160
|
|
161
|
|
162 } __attribute__ ((aligned (DEFAULT_ALIGNMENT)));
|
|
163
|
|
164 typedef HTask* HTaskPtr;
|
|
165
|
|
166 #endif
|