3
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include "FifoTaskManagerImpl.h"
|
47
|
5 #include "types.h"
|
109
|
6 #include "error.h"
|
3
|
7
|
109
|
8 FifoTaskManagerImpl::~FifoTaskManagerImpl(void)
|
|
9 {
|
|
10 delete mailManager;
|
|
11 delete scheduler;
|
|
12 delete bufferManager;
|
|
13 }
|
|
14
|
|
15 /**
|
|
16 * MailManager �� PPE �������塼��ȤΥ���
|
|
17 * FifoScheduler �� PPE ¦�Υ������塼��
|
|
18 * BufferManager �� Task��TaskList �ʤɤΥ������(���ؤʤ��Ȥ��Ƥʤ���
|
|
19 */
|
3
|
20 void
|
|
21 FifoTaskManagerImpl::init(void)
|
|
22 {
|
109
|
23 mailManager = new MailManager();
|
|
24 mailManager->init(20);
|
|
25
|
|
26 scheduler = new MainScheduler();
|
|
27 scheduler->init();
|
|
28 scheduler->set_mailManager(mailManager);
|
194
|
29 scheduler->id = 0;
|
42
|
30
|
58
|
31 bufferManager = new BufferManager;
|
|
32 bufferManager->init();
|
109
|
33
|
|
34 mainTaskList = bufferManager->create_taskList();
|
|
35 }
|
|
36
|
|
37 /**
|
|
38 * ����� CellTaskManagerImpl ����ƤФ�롣
|
|
39 * BufferManager �϶��ѤǻȤ��Τǰ����ˡ�
|
|
40 * CellTaskManagerImpl �� FifoTaskManagerImpl ��Ʊ����
|
|
41 * ��Υǡ����˥��������������(����)�ʤ��ΤǤ���Ǥ�k
|
|
42 */
|
|
43 void
|
|
44 FifoTaskManagerImpl::init(MainScheduler *_sched, BufferManager *buff)
|
|
45 {
|
|
46 mailManager = new MailManager();
|
|
47 mailManager->init(20);
|
|
48
|
|
49 //scheduler = new MainScheduler();
|
|
50 scheduler = _sched;
|
|
51 scheduler->init();
|
|
52 scheduler->set_mailManager(mailManager);
|
|
53
|
|
54 bufferManager = buff;
|
|
55
|
|
56 mainTaskList = bufferManager->create_taskList();
|
|
57 }
|
|
58
|
|
59 /**
|
|
60 * �������塼����Ϥ� TaskList ��������롣
|
|
61 *
|
|
62 * @return �¹ԥ������ꥹ��
|
|
63 *
|
|
64 * ActiveTaskQueue (��¸�����������Ѥ�) �Υ�������
|
|
65 * �¹ԥ������ꥹ�Ȥ������
|
|
66 */
|
|
67 TaskListPtr
|
|
68 FifoTaskManagerImpl::get_runTaskList(void)
|
|
69 {
|
|
70 TaskListPtr list, list_top;
|
|
71 TaskQueuePtr queue;
|
|
72 TaskQueuePtr d;
|
|
73 HTaskPtr htask; // HTask (PPE �ˤ���)
|
|
74 TaskPtr task; // Task (SPE ������ Task)
|
|
75
|
|
76 queue = activeTaskQueue;
|
|
77 if (queue == NULL) {
|
|
78 return NULL;
|
|
79 }
|
|
80
|
|
81 // PPE ¦�Ǽ¹Ԥ���� TaskList
|
|
82 list_top = mainTaskList;
|
|
83
|
|
84 // list_top->clear() �Ȥ��������������⤷���
|
|
85 list_top = bufferManager->clear_taskList(list_top);
|
|
86 list = list_top;
|
|
87
|
|
88 while (queue) {
|
|
89 htask = (HTaskPtr)queue->task;
|
|
90 d = queue;
|
|
91 queue = queue->next;
|
|
92
|
|
93 task = &list->tasks[list->length++];
|
|
94
|
|
95 #if 0
|
|
96 task->command = htask->command;
|
|
97 task->inData = htask->inData;
|
|
98 task->outData = htask->outData;
|
|
99 task->self = (unsigned int)htask;
|
|
100 #else
|
|
101 memcpy(task, htask, sizeof(Task));
|
|
102 #endif
|
|
103
|
|
104 if (list->length >= TASK_MAX_SIZE) {
|
|
105 TaskListPtr newList = bufferManager->create_taskList();
|
|
106 list_top = TaskListInfo::append(list_top, newList);
|
|
107 list = newList;
|
|
108 }
|
|
109
|
|
110 bufferManager->free_taskQueue(d);
|
|
111 }
|
|
112
|
|
113 activeTaskQueue = NULL;
|
|
114 mainTaskList = list_top;
|
|
115
|
|
116 return list_top;
|
|
117 }
|
|
118
|
|
119
|
|
120 void
|
|
121 FifoTaskManagerImpl::run(void)
|
|
122 {
|
|
123 TaskListPtr list;
|
|
124 MailQueuePtr mail;
|
|
125
|
|
126 list = get_runTaskList();
|
|
127
|
|
128 do {
|
|
129 // list ��¹Ԥ���
|
|
130 mail = schedule(list);
|
|
131
|
|
132 // mail �ˤϡ�ppe scheduler ����� mail ������
|
|
133 mail_check(mail);
|
|
134
|
|
135 // ��¸�ط�������������Τϼ¹Բ�ǽ���塼��
|
|
136 wakeup_waitTask();
|
|
137 list = get_runTaskList();
|
|
138 } while (list);
|
|
139 }
|
|
140
|
|
141 /**
|
|
142 * @param [list] �¹ԥ������ꥹ��
|
|
143 * @return FifoScheduler ������
|
|
144 *
|
|
145 * [Tasklist] -> [��ʼ] -> scheduler->run ��ȴ����
|
|
146 */
|
|
147 MailQueuePtr
|
|
148 FifoTaskManagerImpl::schedule(TaskListPtr list)
|
|
149 {
|
|
150 MailQueuePtr list_mail; // task list
|
|
151 MailQueuePtr sentinel; // ��ʼ
|
|
152 MailQueuePtr in_mail_list = NULL;
|
|
153 MailQueuePtr out_mail_list = NULL;
|
|
154
|
|
155 // TaskList �Υ��ɥ쥹
|
|
156 list_mail = mailManager->create((unsigned int)list);
|
|
157 in_mail_list = MailManager::append_mailQueue(in_mail_list, list_mail);
|
|
158
|
|
159 // EXIT_COMMAND (��ʼŪ�ʰ�̣��)
|
|
160 sentinel = mailManager->create(MY_SPE_COMMAND_EXIT);
|
|
161 in_mail_list = MailManager::append_mailQueue(in_mail_list, sentinel);
|
|
162
|
|
163 // scheduler �ϼ�����ä����˼¹Ԥ���
|
|
164 scheduler->send_mailList(in_mail_list);
|
|
165 scheduler->run();
|
|
166 out_mail_list = scheduler->recv_mailList();
|
|
167
|
|
168 return out_mail_list;
|
|
169 }
|
|
170
|
|
171 /**
|
|
172 * PPE Scheduler ����Υ�������å�����
|
|
173 *
|
|
174 * @param [mail_list]
|
|
175 * PPE ¦��ư�� Scheduler ����Υ��ꥹ��
|
|
176 * ��λ���� Task �䡢����¾(���Ϥޤ��������Ƥʤ�����)�ξ������äƤ�
|
|
177 *
|
|
178 * @return Scheduler �����˼¹Ԥ��� Task List
|
|
179 * NULL �ʤ����ƤΥ��������¹Խ�λ�����Ȥ�������
|
|
180 */
|
|
181 void
|
|
182 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list)
|
|
183 {
|
|
184 MailQueuePtr q = mail_list;
|
|
185 MailQueuePtr d;
|
|
186 unsigned int data;
|
|
187
|
|
188 while (q) {
|
|
189 data = q->data;
|
|
190
|
|
191 /**
|
|
192 * MY_SPE_STATUS_READY: SPE �����äƤ� Task ���ƽ�λ
|
|
193 * MY_SPE_NOP: �ä˰�̣�Τʤ����ޥ��
|
|
194 * ����ʳ�����λ����������(PPE�ˤ���Τǥ��ɥ쥹
|
|
195 *
|
|
196 * MY_SPE_NOP �� 0 �ʤΤǡ�
|
|
197 * ���Τ褦�� data > MY_SPE_NOP �Ȥ����Ƥ��ޤ���
|
|
198 * ���ܤǤ褯�狼��ʤ������ʤ�ǡ�ľ�������Ȥ����Ǥ���������
|
|
199 */
|
|
200 if (data == MY_SPE_STATUS_READY) {
|
|
201 __debug_ppe("mail_check(): Task List finish\n");
|
|
202 } else if (data > MY_SPE_NOP) {
|
|
203 __debug_ppe("mail_check(): recv from 0x%x\n", data);
|
|
204 check_task_finish((HTaskPtr)data);
|
|
205 }
|
|
206
|
|
207 d = q;
|
|
208 q = q->next;
|
|
209
|
|
210 mailManager->free(d);
|
|
211 }
|
3
|
212 }
|
|
213
|
14
|
214 void
|
109
|
215 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list, TaskQueuePtr *wait)
|
14
|
216 {
|
109
|
217 waitTaskQueue = *wait;
|
|
218 mail_check(mail_list);
|
14
|
219 }
|
|
220
|
109
|
221 void*
|
|
222 FifoTaskManagerImpl::allocate(int size)
|
|
223 {
|
|
224 return malloc(size);
|
|
225 }
|
|
226
|
|
227 /**
|
|
228 * ���������Ȥ�����
|
|
229 * Abstract Factory Pattern
|
|
230 * �Ȥ����餷����
|
|
231 */
|
|
232 #ifdef __CERIUM_FIFO__
|
|
233 TaskManagerImpl*
|
3
|
234 create_impl(int num)
|
|
235 {
|
|
236 return new FifoTaskManagerImpl();
|
|
237 }
|
109
|
238 #endif // __CERIUM_FIFO__
|