Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1664 | pj | 1 | /* |
2 | * Project: REPPOR |
||
3 | * |
||
4 | * |
||
5 | File: $File$ |
||
6 | Last update: $Date: 2004/04/08 |
||
7 | ------------ |
||
8 | **/ |
||
9 | |||
10 | /* |
||
11 | * Copyright (C) 2004 Pankaj Arora,Gangadharan & Arjumand Ara. |
||
12 | * |
||
13 | * This program is free software; you can redistribute it and/or modify |
||
14 | * it. This program is distributed in the hope that it will be useful, |
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
17 | |||
18 | */ |
||
19 | |||
20 | /*--------------------------------------------------------------*/ |
||
21 | /* SIMULATION OF REal time Prey PredatOR--REPPOR */ |
||
22 | /*--------------------------------------------------------------*/ |
||
23 | |||
24 | #include "datastructures.h" |
||
25 | |||
26 | struct Prey chuha; |
||
27 | |||
28 | |||
29 | /*--------------------------------------------------------------*/ |
||
30 | /* Function to draw predator */ |
||
31 | /* Parameters : Old x,y position |
||
32 | New x,y position |
||
33 | Old color |
||
34 | New color |
||
35 | Return : none |
||
36 | /*--------------------------------------------------------------*/ |
||
37 | |||
38 | void draw_saamp(int oldx, int oldy,int newx,int newy,int oldcolor, int newcolor) |
||
39 | { |
||
40 | sem_wait(&grx_mutex); |
||
41 | grx_disc(oldx, oldy, RAD, oldcolor); |
||
42 | grx_disc(newx, newy, RAD, newcolor); |
||
43 | sem_post(&grx_mutex); |
||
44 | } |
||
45 | |||
46 | /*--------------------------------------------------------------*/ |
||
47 | /* Function to draw prey */ |
||
48 | /* Parameters : Old x,y position |
||
49 | New x,y position |
||
50 | Return : none |
||
51 | /*--------------------------------------------------------------*/ |
||
52 | |||
53 | void draw_prey(int oldx,int oldy,int newx, int newy) |
||
54 | { |
||
55 | sem_wait(&grx_mutex); |
||
56 | grx_circle(oldx,oldy,PREY_RAD, GREEN); |
||
57 | grx_circle(newx, newy, PREY_RAD, BLACK); |
||
58 | sem_post(&grx_mutex); |
||
59 | } |
||
60 | /*--------------------------------------------------------------*/ |
||
61 | /* Function to genearte a random number between a given range*/ |
||
62 | /* Parameters : Minimum of range |
||
63 | Maximun of range |
||
64 | Return : Genearted random number |
||
65 | /*--------------------------------------------------------------*/ |
||
66 | |||
67 | int generateRandomNumber(int minR, int maxR ) |
||
68 | { |
||
69 | int temp = rand(); |
||
70 | temp = temp % (maxR+1); |
||
71 | while(temp < minR) |
||
72 | { |
||
73 | temp = rand(); |
||
74 | temp = temp % (maxR+1); |
||
75 | } |
||
76 | return temp; |
||
77 | } |
||
78 | |||
79 | /*--------------------------------------------------------------*/ |
||
80 | /* Function to implement periodic task JET */ |
||
81 | /* Description : It fetches the execution time for the tasks in the system. |
||
82 | Then computes the Mean Execution Time of the Predator Tasks and |
||
83 | displays it along with their corresponding periods. |
||
84 | /*----------------------------------------------------------------------------------------*/ |
||
85 | |||
86 | TASK jet_task(void *arg){ |
||
87 | |||
88 | TIME sum, max, curr; |
||
89 | TIME total[24]; |
||
90 | PID id; |
||
91 | |||
92 | char *buf; |
||
93 | char tmp[48]; |
||
94 | |||
95 | int i=0; |
||
96 | int n; |
||
97 | int JNTASK=0; |
||
98 | int JXT = 480; |
||
99 | int JX = 535; |
||
100 | int JY = 310; |
||
101 | int JWIDTH = 50; |
||
102 | |||
103 | int width; |
||
104 | int widthperiod = 0; |
||
105 | int maxperiod = 80000; |
||
106 | float period=0; |
||
107 | float met; |
||
108 | |||
109 | memset(buf, '\0', sizeof(buf)); |
||
110 | grx_text("MET PERIOD", JXT+10, JY-8, LIGHTCYAN, BLACK); |
||
111 | grx_rect(JXT-4, JY-12, JXT+150, JY+160,WHITE1); |
||
112 | while (1){ |
||
113 | for (id=2, JNTASK=0; id < MAX_PROC; id++){ |
||
114 | if (jet_getstat(id, &sum, &max, &n, &curr) != -1) |
||
115 | { |
||
116 | met = (float) (sum+curr)/n; |
||
117 | buf = proc_table[id].name; |
||
118 | i=JNTASK++; |
||
119 | |||
120 | if (strcmp(buf,SNAKE_R) == 0) { |
||
121 | period = sam_red_period; |
||
122 | grx_text(buf, JXT, JY+i*8, MAGENTA, BLACK); |
||
123 | |||
124 | widthperiod = (int) ( (period/maxperiod) *JWIDTH); |
||
125 | width = (int) ((float) met/widthperiod); |
||
126 | |||
127 | grx_box(JX, JY+i*8, JX+widthperiod, JY+8+i*8, LIGHTRED); |
||
128 | grx_box(JX, JY+i*8, JX+width, JY+8+i*8, RED); |
||
129 | } |
||
130 | else if (strcmp(buf,SNAKE_B) == 0) { |
||
131 | period = sam_blue_period; |
||
132 | grx_text(buf, JXT, JY+ i*8, MAGENTA, BLACK); |
||
133 | |||
134 | widthperiod = (int) ( (period/maxperiod) *JWIDTH); |
||
135 | width = (int) ((float) met/widthperiod); |
||
136 | |||
137 | grx_box(JX, JY+i*8, JX+widthperiod, JY+8+i*8, LIGHTBLUE); |
||
138 | grx_box(JX, JY+i*8, JX+width, JY+8+i*8, BLUE); |
||
139 | } |
||
140 | else if (strcmp(buf,SNAKE_Y) == 0) { |
||
141 | period = sam_yellow_period; |
||
142 | grx_text(buf, JXT, JY+i*8, MAGENTA, BLACK); |
||
143 | |||
144 | widthperiod = (int) ( (period/maxperiod) *JWIDTH); |
||
145 | width = (int) ((float) met/widthperiod); |
||
146 | |||
147 | grx_box(JX, JY+i*8, JX+widthperiod, JY+8+i*8, YELLOW); |
||
148 | grx_box(JX, JY+i*8, JX+width, JY+8+i*8, GREEN); |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | task_endcycle(); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | |||
157 | /*-----------------------------------------------------------------------------*/ |
||
158 | /* Function to implement periodic task BarGraph */ |
||
159 | /* Description : Calculates number of preys killed by each(Red/Blue/Yellow) |
||
160 | type of predator and then makes a bar graph presenting score |
||
161 | percentages. |
||
162 | /*------------------------------------------------------------------------------*/ |
||
163 | |||
164 | TASK make_bargraph(void *arg) |
||
165 | { |
||
166 | int i; |
||
167 | int x1,y1,x2,y2; |
||
168 | |||
169 | while(1) |
||
170 | { |
||
171 | for(i=INITIAl_TASKS;i<=MAXTASKS;i++) |
||
172 | if(saamps[i].number_of_times_killed>0) |
||
173 | { |
||
174 | if(saamps[i].color==LIGHTRED1) |
||
175 | red_killed += saamps[i].number_of_times_killed; |
||
176 | else |
||
177 | if(saamps[i].color==BLUE1) |
||
178 | blue_killed += saamps[i].number_of_times_killed; |
||
179 | else |
||
180 | if(saamps[i].color==YELLOW1) |
||
181 | yellow_killed += saamps[i].number_of_times_killed; |
||
182 | |||
183 | } |
||
184 | int total_killed = 0 ; |
||
185 | total_killed = red_killed + blue_killed + yellow_killed; |
||
186 | if(total_killed>0) |
||
187 | { |
||
188 | x1 = XMAX+BARSIZE/2; |
||
189 | x2 = x1 + 10; |
||
190 | y1 = (YMAX+50)/2; |
||
191 | |||
192 | y2 = (red_killed*200)/total_killed; |
||
193 | |||
194 | grx_box(x1,YMENU+45,x2,y1,BLACK1); |
||
195 | grx_box(x1,y1-y2,x2,y1,LIGHTRED1); |
||
196 | |||
197 | x1 = XMAX+3*BARSIZE/2; |
||
198 | x2 = x1 + 10; |
||
199 | y2 = (blue_killed*200)/total_killed; |
||
200 | |||
201 | |||
202 | grx_box(x1,YMENU+45,x2,y1,BLACK1); |
||
203 | grx_box(x1,y1-y2,x2,y1,BLUE1); |
||
204 | |||
205 | |||
206 | x1 = XMAX+5*BARSIZE/2; |
||
207 | x2 = x1 + 10; |
||
208 | |||
209 | y2 = (yellow_killed*200)/total_killed; |
||
210 | grx_box(x1,YMENU+45,x2,y1,BLACK1); |
||
211 | grx_box(x1,y1-y2,x2,y1,YELLOW1); |
||
212 | |||
213 | } |
||
214 | red_killed = blue_killed = yellow_killed = 0; |
||
215 | task_endcycle(); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | /*----------------------------------------------------------------------------------------*/ |
||
220 | /* Function to implement periodic task Prey */ |
||
221 | /* Description : Checks for the presence of prey in the system. If |
||
222 | there is no prey it generates prey at random position |
||
223 | else moves the prey randomly till it is caught(killed) by the predator. |
||
224 | It uses function draw_prey to draw prey at new position. |
||
225 | /*----------------------------------------------------------------------------------------*/ |
||
226 | |||
227 | TASK prey(void *arg) |
||
228 | { |
||
229 | TIME trand; |
||
230 | trand = sys_gettime(NULL); |
||
231 | srand(trand); |
||
232 | |||
233 | while (1) |
||
234 | { |
||
235 | if(chuha.isAlive == 0) |
||
236 | { |
||
237 | int oldx,oldy; |
||
238 | |||
239 | oldx = chuha.x; |
||
240 | oldy = chuha.y; |
||
241 | chuha.x = generateRandomNumber(XMIN,XMAX); |
||
242 | chuha.y = generateRandomNumber(YMIN,YMAX); |
||
243 | |||
244 | draw_prey(oldx,oldy,chuha.x,chuha.y); |
||
245 | chuha.isAlive = 1; |
||
246 | |||
247 | } |
||
248 | else |
||
249 | { |
||
250 | int tx,ty; |
||
251 | tx = chuha.x; |
||
252 | ty = chuha.y; |
||
253 | |||
254 | if((chuha.x-PREY_RAD*5>XMIN) && (chuha.x+PREY_RAD*5<XMAX)) |
||
255 | chuha.x = generateRandomNumber(chuha.x-PREY_RAD*5,chuha.x+PREY_RAD*5); |
||
256 | else |
||
257 | if(chuha.x-PREY_RAD*5>XMIN) |
||
258 | chuha.x = generateRandomNumber(chuha.x-PREY_RAD*5,chuha.x); |
||
259 | else |
||
260 | if(chuha.x+PREY_RAD*5<XMAX) |
||
261 | chuha.x = generateRandomNumber(chuha.x,chuha.x+PREY_RAD*5); |
||
262 | |||
263 | if((chuha.y-PREY_RAD*5>YMIN) && (chuha.y+PREY_RAD*5<YMAX)) |
||
264 | chuha.y = generateRandomNumber(chuha.y-PREY_RAD*5,chuha.y+PREY_RAD*5); |
||
265 | else |
||
266 | if(chuha.y-PREY_RAD*5>YMIN) |
||
267 | chuha.y = generateRandomNumber(chuha.y-PREY_RAD*5,chuha.y); |
||
268 | else |
||
269 | if(chuha.y+PREY_RAD*5<YMAX) |
||
270 | chuha.y = generateRandomNumber(chuha.y,chuha.y+PREY_RAD*5); |
||
271 | |||
272 | draw_prey(tx,ty,chuha.x,chuha.y); |
||
273 | |||
274 | } |
||
275 | task_endcycle(); |
||
276 | } |
||
277 | } |
||
278 | |||
279 | |||
280 | /*----------------------------------------------------------------------------------------*/ |
||
281 | /* Function to implement task Predator */ |
||
282 | /* Parameters : Type of predator */ |
||
283 | /* Description : Creates new type(passed as argument)predator in the system. Then continuously |
||
284 | move towards prey. |
||
285 | Predator movement is governed by the fact that it has to avoid collision with |
||
286 | other peers in the prowl. |
||
287 | It uses function draw_saamp to draw predator at new position. |
||
288 | |||
289 | /*----------------------------------------------------------------------------------------*/ |
||
290 | |||
291 | |||
292 | TASK saamp(void *arg) |
||
293 | { |
||
294 | |||
295 | int i =(int)arg; |
||
296 | struct Saamp sam; |
||
297 | int xs; |
||
298 | int ys; |
||
299 | int tempxs,tempys; |
||
300 | int random; |
||
301 | |||
302 | TIME trand; |
||
303 | |||
304 | trand = sys_gettime(NULL); |
||
305 | srand(trand); |
||
306 | int ox,oy; |
||
307 | int flag,gk; |
||
308 | ox = sam.x = generateRandomNumber(XMIN,XMAX); |
||
309 | oy = sam.y = generateRandomNumber(YMIN,YMAX); |
||
310 | sem_wait(&grid_mutex); |
||
311 | grid[(int)(sam.y/RATIO)-MAPPING][(int)(sam.x/RATIO)-MAPPING]; |
||
312 | sem_post(&grid_mutex); |
||
313 | draw_saamp(ox,oy,sam.x,sam.y,GREEN1,saamps[i].color); |
||
314 | |||
315 | saamps[i].x = sam.x; |
||
316 | saamps[i].y = sam.y; |
||
317 | |||
318 | while (1) |
||
319 | { |
||
320 | |||
321 | tempxs = abs(sam.x - chuha.x); |
||
322 | tempys = abs(sam.y - chuha.y); |
||
323 | if(tempxs<=(PREY_RAD+RAD) && tempys<=(PREY_RAD+RAD)) |
||
324 | { |
||
325 | chuha.isAlive = 0; |
||
326 | saamps[i].number_of_times_killed++; |
||
327 | |||
328 | } |
||
329 | |||
330 | if(chuha.isAlive == 1) |
||
331 | { |
||
332 | if(tempxs!=0 || tempys !=0) |
||
333 | { |
||
334 | if(sam.x!=chuha.x) |
||
335 | { |
||
336 | if(sam.x<chuha.x) |
||
337 | sam.x++; |
||
338 | else |
||
339 | sam.x--; |
||
340 | } |
||
341 | if(sam.y!=chuha.y) |
||
342 | { |
||
343 | if(sam.y<chuha.y) |
||
344 | sam.y++; |
||
345 | else |
||
346 | sam.y--; |
||
347 | } |
||
348 | } |
||
349 | } |
||
350 | |||
351 | sem_wait(&grid_mutex); |
||
352 | gk=grid[(int)(sam.y/RATIO)-MAPPING][(int)(sam.x/RATIO)-MAPPING]; |
||
353 | sem_post(&grid_mutex); |
||
354 | if(((int)(sam.y/RATIO)-MAPPING != (int)(oy/RATIO)-MAPPING) || ((int)(sam.x/RATIO)-MAPPING != (int)(ox/RATIO)-MAPPING)) |
||
355 | { |
||
356 | if(gk==1) |
||
357 | { |
||
358 | int cnt =1; |
||
359 | |||
360 | while(gk==1) |
||
361 | { |
||
362 | |||
363 | if((sam.x-RATIO*cnt>XMIN) && (sam.x+RATIO*cnt<XMAX)) |
||
364 | sam.x = generateRandomNumber(sam.x-RATIO*cnt,sam.x+RATIO*cnt); |
||
365 | else |
||
366 | if(sam.x-RATIO*cnt>XMIN) |
||
367 | sam.x = generateRandomNumber(sam.x-RATIO*cnt,sam.x); |
||
368 | else |
||
369 | if(sam.x+RATIO*cnt<XMAX) |
||
370 | sam.x = generateRandomNumber(sam.x,sam.x+RATIO*cnt); |
||
371 | |||
372 | if(sam.y-RATIO*cnt>YMIN && sam.y+RATIO*cnt<YMAX) |
||
373 | sam.y = generateRandomNumber(sam.y-RATIO*cnt,sam.y+RATIO*cnt); |
||
374 | else |
||
375 | if(sam.y-RATIO*cnt>YMIN) |
||
376 | sam.y = generateRandomNumber(sam.y-RATIO*cnt,sam.y); |
||
377 | else |
||
378 | if(sam.y+RATIO*cnt<YMAX) |
||
379 | sam.y = generateRandomNumber(sam.y,sam.y+RATIO*cnt); |
||
380 | cnt++; |
||
381 | sem_wait(&grid_mutex); |
||
382 | gk=grid[(int)(sam.y/RATIO)-MAPPING][(int)(sam.x/RATIO)-MAPPING]; |
||
383 | if(gk==0) |
||
384 | { |
||
385 | grid[(int)(sam.y/RATIO)-MAPPING][(int)(sam.x/RATIO)-MAPPING]=1; |
||
386 | grid[(int)(oy/RATIO)-MAPPING][(int)(ox/RATIO)-MAPPING]=0; |
||
387 | draw_saamp(ox,oy,sam.x,sam.y,GREEN1,saamps[i].color); |
||
388 | } |
||
389 | sem_post(&grid_mutex); |
||
390 | |||
391 | } |
||
392 | |||
393 | } |
||
394 | else |
||
395 | { |
||
396 | sem_wait(&grid_mutex); |
||
397 | grid[(int)(sam.y/RATIO)-MAPPING][(int)(sam.x/RATIO)-MAPPING]=1; |
||
398 | grid[(int)(oy/RATIO)-MAPPING][(int)(ox/RATIO)-MAPPING]=0; |
||
399 | draw_saamp(ox,oy,sam.x,sam.y,GREEN1,saamps[i].color); |
||
400 | sem_post(&grid_mutex); |
||
401 | } |
||
402 | |||
403 | } |
||
404 | else |
||
405 | { |
||
406 | |||
407 | draw_saamp(ox,oy,sam.x,sam.y,GREEN1,saamps[i].color); |
||
408 | } |
||
409 | |||
410 | |||
411 | saamps[i].x = sam.x; |
||
412 | saamps[i].y = sam.y; |
||
413 | ox = sam.x; |
||
414 | oy = sam.y; |
||
415 | task_endcycle(); |
||
416 | } |
||
417 | } |
||
418 | |||
419 | |||
420 | /*----------------------------------------------------------------------------------------*/ |
||
421 | /* Function called before system exits. */ |
||
422 | /* Description : Closes the graphical interface and exits using sys_end.*/ |
||
423 | |||
424 | /*----------------------------------------------------------------------------------------*/ |
||
425 | |||
426 | void ciao(void) |
||
427 | { |
||
428 | grx_close(); |
||
429 | cputs("End of REPPOR Simulation"); |
||
430 | return; |
||
431 | } |
||
432 | /*----------------------------------------------------------------------------------------*/ |
||
433 | /* Function called if Alt-x is pressed. */ |
||
434 | /* Description : Closes the graphical interface and exits using sys_end.*/ |
||
435 | |||
436 | /*----------------------------------------------------------------------------------------*/ |
||
437 | |||
438 | void end(KEY_EVT *evt) |
||
439 | { |
||
440 | grx_close(); |
||
441 | cputs("End of REPPOR Simulation"); |
||
442 | sys_end(); |
||
443 | } |
||
444 | |||
445 | /*----------------------------------------------------------------------------------------*/ |
||
446 | /* Function to draw initial grid and scorecard */ |
||
447 | |||
448 | /*----------------------------------------------------------------------------------------*/ |
||
449 | |||
450 | void make_rect() |
||
451 | { |
||
452 | |||
453 | grx_box(XMIN-RAD-1, YMIN-RAD-1, XMAX+RAD+1, YMAX+RAD+1, GREEN); |
||
454 | |||
455 | grx_text("Simulation of REPPOR", XMAX+5, YMENU+8, 13, 0); |
||
456 | grx_text("R/B/Y create predator" , XMAX+5, YMENU+23, 12, 0); |
||
457 | grx_text("Esc exit to DOS" , XMAX+5, YMENU+33, 12, 0); |
||
458 | grx_rect(XMAX+YMENU,YMENU+43,620,(YMAX+50)/2,WHITE1); |
||
459 | grx_text("Scores(% eaten)",XMAX+25,(YMAX+50)/2+15,11,BLACK1); |
||
460 | grx_text("RED",XMAX+BARSIZE/2,(YMAX+50)/2+5,LIGHTRED1,0); |
||
461 | grx_text("BLUE",XMAX+3*BARSIZE/2,(YMAX+50)/2+5,BLUE1,0); |
||
462 | grx_text("YELLOW",XMAX+5*BARSIZE/2,(YMAX+50)/2+5,YELLOW1,0); |
||
463 | } |
||
464 | /*----------------------------------------------------------------------------------------*/ |
||
465 | /* Function to draw one kind of predator */ |
||
466 | |||
467 | /*----------------------------------------------------------------------------------------*/ |
||
468 | |||
469 | void create_snake_red(HARD_TASK_MODEL m) |
||
470 | { |
||
471 | saamps[number_of_tasks].color = LIGHTRED1; |
||
472 | saamps[number_of_tasks].number_of_times_killed = 0; |
||
473 | |||
474 | hard_task_default_model(m); |
||
475 | hard_task_def_ctrl_jet (m); |
||
476 | hard_task_def_arg (m, (void *)number_of_tasks); |
||
477 | hard_task_def_wcet (m, sam_red_wcet); |
||
478 | hard_task_def_mit (m, sam_red_period); |
||
479 | hard_task_def_group (m, SNAKEGROUP); |
||
480 | hard_task_def_usemath (m); |
||
481 | |||
482 | pid = task_create(SNAKE_R, saamp, &m, NULL); |
||
483 | if (pid == NIL) { |
||
484 | grx_close(); |
||
485 | perror("Could not create task <saamp>"); |
||
486 | sys_abort(1); |
||
487 | } |
||
488 | task_activate(pid); |
||
489 | number_of_tasks++; |
||
490 | |||
491 | |||
492 | } |
||
493 | /*----------------------------------------------------------------------------------------*/ |
||
494 | /* Function to draw one kind of predator */ |
||
495 | |||
496 | /*----------------------------------------------------------------------------------------*/ |
||
497 | |||
498 | void create_snake_blue(HARD_TASK_MODEL m) |
||
499 | { |
||
500 | saamps[number_of_tasks].color = BLUE1; |
||
501 | saamps[number_of_tasks].number_of_times_killed = 0; |
||
502 | |||
503 | hard_task_default_model(m); |
||
504 | hard_task_def_ctrl_jet (m); |
||
505 | hard_task_def_arg (m, (void *)number_of_tasks); |
||
506 | hard_task_def_wcet (m, sam_blue_wcet); |
||
507 | hard_task_def_mit (m, sam_blue_period); |
||
508 | hard_task_def_group (m, SNAKEGROUP); |
||
509 | hard_task_def_usemath (m); |
||
510 | pid = task_create(SNAKE_B, saamp, &m, NULL); |
||
511 | |||
512 | if (pid == NIL) { |
||
513 | grx_close(); |
||
514 | perror("Could not create task <saamp>"); |
||
515 | sys_abort(1); |
||
516 | } |
||
517 | task_activate(pid); |
||
518 | number_of_tasks++; |
||
519 | |||
520 | } |
||
521 | /*----------------------------------------------------------------------------------------*/ |
||
522 | /* Function to draw one kind of predator */ |
||
523 | |||
524 | /*----------------------------------------------------------------------------------------*/ |
||
525 | |||
526 | void create_snake_yellow(HARD_TASK_MODEL m){ |
||
527 | |||
528 | saamps[number_of_tasks].color = YELLOW1; |
||
529 | saamps[number_of_tasks].number_of_times_killed = 0; |
||
530 | |||
531 | hard_task_default_model(m); |
||
532 | hard_task_def_ctrl_jet (m); |
||
533 | hard_task_def_arg (m, (void *)number_of_tasks); |
||
534 | hard_task_def_wcet (m, sam_yellow_wcet); |
||
535 | hard_task_def_mit (m, sam_yellow_period); |
||
536 | hard_task_def_group (m, SNAKEGROUP); |
||
537 | hard_task_def_usemath (m); |
||
538 | pid = task_create(SNAKE_Y, saamp, &m, NULL); |
||
539 | if (pid == NIL) |
||
540 | { |
||
541 | grx_close(); |
||
542 | perror("Could not create task <saamp>"); |
||
543 | sys_abort(1); |
||
544 | } |
||
545 | task_activate(pid); |
||
546 | number_of_tasks++; |
||
547 | |||
548 | } |
||
549 | |||
550 | /*--------------------------------------------------------------------------------------------------------*/ |
||
551 | /* Function main() */ |
||
552 | /* Description : Creates the environment for REPPOR simulation.It creates the playfield |
||
553 | and prey task. It also creates different types of predators based on user input. |
||
554 | It uses make_bargraph() and jet_task() functions to dipaly scorecard and system usage |
||
555 | parameters respectively.*/ |
||
556 | |||
557 | /*--------------------------------------------------------------------------------------------------------*/ |
||
558 | |||
559 | int main(int argc, char *argv[]) |
||
560 | { |
||
561 | |||
562 | HARD_TASK_MODEL m; |
||
563 | HARD_TASK_MODEL m1; |
||
564 | SOFT_TASK_MODEL bar; |
||
565 | SOFT_TASK_MODEL jet; |
||
566 | KEY_EVT key; |
||
567 | int modenum; |
||
568 | char c; |
||
569 | int maxGridX=(XMAX-XMIN)/RATIO,maxGridY=(YMAX-YMIN)/RATIO,i,j; |
||
570 | |||
571 | sys_atrunlevel(ciao, NULL, RUNLEVEL_BEFORE_EXIT); |
||
572 | sem_init(&grx_mutex,0,1); |
||
573 | sem_init(&grid_mutex,0,1); |
||
574 | |||
575 | for(i=0;i<maxGridX;i++) |
||
576 | for(j=0;j<maxGridY;j++) |
||
577 | grid[i][j]=0; |
||
578 | |||
579 | /* graphic card Initialization */ |
||
580 | |||
581 | if (grx_init() < 1) { |
||
582 | sys_abort(1); |
||
583 | } |
||
584 | |||
585 | if (grx_open(640, 480, 8) < 0) { |
||
586 | cprintf("GRX Err\n"); |
||
587 | sys_abort(1); |
||
588 | } |
||
589 | |||
590 | key.ascii='x'; |
||
591 | key.scan=KEY_X; |
||
592 | key.flag=ALTL_BIT; |
||
593 | keyb_hook(key, end); |
||
594 | //Creation of playfield |
||
595 | make_rect(); |
||
596 | hard_task_default_model(m1); |
||
597 | hard_task_def_ctrl_jet(m1); |
||
598 | hard_task_def_arg(m1, (void *)number_of_tasks); |
||
599 | hard_task_def_wcet(m1, prey_wcet); |
||
600 | hard_task_def_mit(m1, prey_period); |
||
601 | hard_task_def_usemath(m1); |
||
602 | pid = task_create("Prey", prey, &m1, NULL); |
||
603 | if (pid == NIL) |
||
604 | { |
||
605 | grx_close(); |
||
606 | perror("Could not create task <Prey>"); |
||
607 | sys_abort(1); |
||
608 | } |
||
609 | number_of_tasks++; |
||
610 | task_activate(pid); |
||
611 | //Creation of Bar Graph |
||
612 | soft_task_default_model(bar); |
||
613 | soft_task_def_level(bar,1); |
||
614 | soft_task_def_ctrl_jet(bar); |
||
615 | soft_task_def_arg(bar, (void *)0); |
||
616 | soft_task_def_met(bar, WCET_BARGRAPH); |
||
617 | soft_task_def_period(bar,PERIOD_BARGRAPH); |
||
618 | soft_task_def_usemath(bar); |
||
619 | |||
620 | pid = task_create("BarGraph", make_bargraph, &bar, NULL); |
||
621 | |||
622 | if (pid != NIL) |
||
623 | { |
||
624 | task_activate(pid); |
||
625 | number_of_tasks++; |
||
626 | } |
||
627 | |||
628 | //Creation of jet task |
||
629 | soft_task_default_model(jet); |
||
630 | soft_task_def_level(jet,1); |
||
631 | soft_task_def_arg(jet, (void *) 0); |
||
632 | soft_task_def_met(jet, WCET_JET); |
||
633 | soft_task_def_period(jet, PERIOD_JET); |
||
634 | soft_task_def_usemath(jet); |
||
635 | |||
636 | pid = task_create("JET", jet_task, &jet, NULL); |
||
637 | if (pid != NIL){ |
||
638 | task_activate(pid); |
||
639 | number_of_tasks++; |
||
640 | } |
||
641 | |||
642 | c = keyb_getch(BLOCK); |
||
643 | //Creation of predator tasks |
||
644 | do { |
||
645 | |||
646 | if ((number_of_tasks <= MAXTASKS)) |
||
647 | switch(c) |
||
648 | { |
||
649 | case 'r': |
||
650 | case 'R': |
||
651 | create_snake_red(m); |
||
652 | break; |
||
653 | case 'b': |
||
654 | case 'B': |
||
655 | create_snake_blue(m); |
||
656 | break; |
||
657 | case 'y': |
||
658 | case 'Y': |
||
659 | create_snake_yellow(m); |
||
660 | break; |
||
661 | default: |
||
662 | c = keyb_getch(BLOCK); |
||
663 | continue; |
||
664 | |||
665 | } |
||
666 | c = keyb_getch(BLOCK); |
||
667 | } while (c != ESC); |
||
668 | grx_close(); |
||
669 | cputs("End of REPPOR Simulation"); |
||
670 | sys_end(); |
||
671 | return 0; |
||
672 | } |
||
673 | |||
674 |