0
|
1 #include <stdio.h>
|
|
2 #include <malloc.h>
|
|
3 #include <spu_intrinsics.h>
|
|
4 #include <spu_mfcio.h>
|
|
5 #include "SpeSentry.h"
|
|
6 #include "MailCommand.h"
|
|
7 #include "Dma.h"
|
|
8 #include "Run.h"
|
|
9
|
|
10 void*
|
|
11 fix_type(send_params_t *send_params, void* buff)
|
|
12 {
|
|
13
|
|
14 char *p;
|
|
15 p = (char*)buff;
|
|
16 p = p + sizeof(send_params_head_t);
|
|
17
|
|
18 send_params->head = (send_params_head_t*)buff;
|
|
19 send_params->buff = p;
|
|
20
|
|
21 }
|
|
22
|
|
23 void*
|
|
24 allocate(int size)
|
|
25 {
|
|
26
|
|
27 int alignment = 16;
|
|
28 return memalign(alignment, size);
|
|
29
|
|
30 }
|
|
31
|
|
32 send_params_t
|
|
33 task_allocate(int size)
|
|
34 {
|
|
35
|
|
36 if (size % 16) {
|
|
37 //printf("allocate size is not multiple of 16\n");
|
|
38 }
|
|
39
|
|
40 char *buff;
|
|
41 send_params_t send_params;
|
|
42
|
|
43 void *head;
|
|
44 head = memalign(16, size);
|
|
45
|
|
46 buff = (char*)head;
|
|
47 buff = buff + sizeof(send_params_head_t);
|
|
48
|
|
49 send_params.head = (send_params_head_t*)head;
|
|
50 send_params.buff = buff;
|
|
51
|
|
52 return send_params;
|
|
53
|
|
54 }
|
|
55
|
|
56 int
|
|
57 main(unsigned long long spe, unsigned long long argp, unsigned long long envp)
|
|
58 {
|
|
59
|
|
60 uint32_t data;
|
|
61 int buff_num = 2;
|
|
62 int dma_wait_time = 0;
|
|
63
|
|
64 int in_tag[buff_num];
|
|
65 int out_tag[buff_num];
|
|
66
|
|
67 in_tag[0] = 0;
|
|
68 in_tag[1] = 1;
|
|
69
|
|
70 out_tag[0] = 2;
|
|
71 out_tag[1] = 3;
|
|
72
|
|
73 int head_tag = 4;
|
|
74
|
|
75 send_params_head_t *head = (send_params_head_t*)allocate(sizeof(send_params_head_t));
|
|
76 send_params_t *send_params = (send_params_t*)allocate(sizeof(send_params_t));
|
|
77 void *input_buff[buff_num];
|
|
78 void *output_buff[buff_num];
|
|
79
|
|
80 int cur;
|
|
81
|
|
82 spu_write_out_mbox(WANT_DATA);
|
|
83
|
|
84 while(1) {
|
|
85
|
|
86 //mail check start
|
|
87 if(spu_stat_in_mbox()) {
|
|
88
|
|
89 data = spu_read_in_mbox();
|
|
90
|
|
91 if (data == SPE_RUN_END) {
|
|
92
|
|
93 break;
|
|
94
|
|
95 } else {
|
|
96
|
|
97 //printf("[SPE] data %p\n",data);
|
|
98
|
|
99 dma_get(head, data, sizeof(send_params_head_t), head_tag);
|
|
100 dma_wait(head_tag);
|
|
101
|
|
102 input_buff[0] = allocate(head->next_task_size);
|
|
103
|
|
104 dma_get(input_buff[0], head->next_task, head->next_task_size, in_tag[0]);
|
|
105 dma_wait(in_tag[0]);
|
|
106
|
|
107 fix_type(send_params,input_buff[0]);
|
|
108
|
|
109 cur = 0;
|
|
110
|
|
111 while(1) {
|
|
112
|
|
113 input_buff[cur^1] = allocate(send_params->head->next_task_size);
|
|
114 dma_get(input_buff[cur^1], send_params->head->next_task, send_params->head->next_task_size, in_tag[cur^1]);
|
|
115
|
|
116 void *in = send_params->buff;
|
|
117
|
|
118 //printf("hoge");
|
|
119 output_buff[cur] = allocate(send_params->head->size_out);
|
|
120 int data_length = send_params->head->size_out;
|
|
121
|
|
122
|
|
123 //task********************************************
|
|
124
|
|
125 run(in,output_buff[cur],data_length);
|
|
126
|
|
127 //end*********************************************
|
|
128
|
|
129 dma_put(output_buff[cur], send_params->head->ea_out, send_params->head->size_out, out_tag[cur]);
|
|
130
|
|
131 free(input_buff[cur]);
|
|
132
|
|
133 dma_wait(in_tag[cur^1]);
|
|
134 dma_wait(out_tag[cur^1]);
|
|
135 //printf("hoge");
|
|
136
|
|
137 free(output_buff[cur^1]);
|
|
138
|
|
139 cur ^= 1;
|
|
140
|
|
141 fix_type(send_params,input_buff[cur]);
|
|
142
|
|
143 if ((unsigned long)send_params->head->next_task == 0) {
|
|
144 break;
|
|
145 }
|
|
146
|
|
147 }//while
|
|
148
|
|
149
|
|
150
|
|
151
|
|
152 void *in = send_params->buff;
|
|
153
|
|
154 //printf("hoge");
|
|
155 output_buff[cur] = allocate(send_params->head->size_out);
|
|
156 int data_length = send_params->head->size_out;
|
|
157
|
|
158
|
|
159 //task********************************************
|
|
160
|
|
161 run(in,output_buff[cur],data_length);
|
|
162
|
|
163 //end*********************************************
|
|
164
|
|
165 dma_put(output_buff[cur], send_params->head->ea_out, send_params->head->size_out, out_tag[cur]);
|
|
166
|
|
167 free(input_buff[cur]);
|
|
168
|
|
169 dma_wait(out_tag[cur] | out_tag[cur^1] );
|
|
170 free(output_buff[cur]);
|
|
171 free(output_buff[cur^1]);
|
|
172
|
|
173
|
|
174
|
|
175 spu_write_out_mbox(WANT_DATA);
|
|
176 //printf("[SPE] send mail\n");
|
|
177
|
|
178 }//if
|
|
179 }//if
|
|
180 //mail check end
|
|
181
|
|
182
|
|
183 }//while
|
|
184
|
|
185
|
|
186 return 0;
|
|
187
|
|
188 }
|
|
189
|
|
190
|
|
191 /*end*/
|