Subversion Repositories shark

Rev

Rev 1563 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1562 trimarchi 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
18
/*
19
 * Copyright (C) 2000 Paolo Gai
20
 *
21
 * This program is free software; you can redistribute it and/or modify
22
 * it under the terms of the GNU General Public License as published by
23
 * the Free Software Foundation; either version 2 of the License, or
24
 * (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34
 */
35
 
36
#include "kernel/kern.h"
37
 
38
#include "fsf.h"
39
#include "fsf_server.h"
40
 
41
#include "stdlib.h"
42
#include "unistd.h"
43
#include "string.h"
44
#include "pistar.h"
45
 
46
#include "pthread.h"
47
 
48
#include "drivers/glib.h"
49
#include "global.h"
50
 
51
#include <drivers/shark_keyb26.h>
52
 
53
 
54
char *readFilePortName = "readFilePort";
55
char *displayPortName = "displayPortName";
56
 
57
#define TEST_PERIOD 50000
58
 
59
mutex_t mux;
60
int main_chunk;
61
 
62
 
63
 
64
 
65
 
66
void program_end()
67
{
68
 
69
  grx_close();
70
  exit(0);
71
}
72
 
73
void *mpeg2decoder(void *arg);
74
void *readTask(void *arg);
75
void *displayTask(void *arg);
76
void *overLoadTask(void *arg);
77
 
78
/***************************************************************
79
 *
80
 * Create the display task and bind it to a server
81
 *
82
 * Author: Robert Bäckgren
83
 ******************************************************************/
84
void addDisplayTaskToServer(fsf_server_id_t server)
85
{
86
  int err;
87
  pthread_t j = -1;
88
  HARD_TASK_MODEL ht;
89
  static fsf_sched_params_t pr;
90
 
91
 
92
  pr.policy=FSF_EDF;
93
  pr.params=&ht;
94
 
95
 
96
  hard_task_default_model(ht);
97
  hard_task_def_mit(ht,40000);
98
  hard_task_def_wcet(ht,18000);
99
  nrt_task_def_group(ht,3);
100
 
1563 trimarchi 101
  /*  
1562 trimarchi 102
  err = pthread_create(&j, NULL, displayTask, NULL);
103
  if (err) {  
1563 trimarchi 104
  grx_close();
105
  grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0);
106
  exit(err);
107
  }
108
 
109
  err=fsf_bind_local_thread_to_server(server, j,(fsf_sched_params_t *)(&pr));
110
  if (err) {
111
  grx_close();
112
  exit(err);
113
 
114
  }
115
  */   
116
  err = fsf_create_local_thread(server,(fsf_sched_params_t *)(&pr), &j,NULL,
117
              displayTask,NULL);
118
  if (err) {  
1562 trimarchi 119
    grx_close();
1563 trimarchi 120
    grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0);
1562 trimarchi 121
    exit(err);
122
  }
1563 trimarchi 123
 task_activate(j);
1562 trimarchi 124
 
125
}
126
 
127
/*********************************************************************'
128
 *
129
 * Create the input task and bind it to a server
130
 *
131
 * Author: Robert Bäckgren
132
 *********************************************************************/
133
void addReadTaskToServer(fsf_server_id_t server)
134
{
135
  int err;
136
  pthread_t j = -1;
137
  NRT_TASK_MODEL ht;
138
  static fsf_sched_params_t pr;
139
 
140
 
141
  pr.policy=FSF_RR;
142
  pr.params=&ht;
143
 
144
 
145
  nrt_task_default_model(ht);
146
  nrt_task_def_group(ht,1);
147
 
1563 trimarchi 148
  /*
1562 trimarchi 149
  err = pthread_create(&j, NULL, readTask, NULL);
150
  if (err) {  
1563 trimarchi 151
  grx_close();
152
  perror("Could not create task...");
153
  exit(err);
1562 trimarchi 154
  }
1563 trimarchi 155
 
156
  err=fsf_bind_local_thread_to_server(server, j,(fsf_sched_params_t *)(&pr));
157
  if (err) {
1562 trimarchi 158
   grx_close();
159
   //perror("Could not bind task..");
160
   exit(err);
1563 trimarchi 161
   }  
162
  */
163
 
164
 err = fsf_create_local_thread(server,(fsf_sched_params_t *)(&pr), &j,NULL,
165
                                readTask,NULL);
166
 if (err) {  
167
   grx_close();
168
   grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0);
169
   exit(err);
1562 trimarchi 170
 }
1563 trimarchi 171
 task_activate(j);
1562 trimarchi 172
}
173
 
174
/**********************************************************************
175
 *
176
 * Create the decoder task and bind it to a server
177
 *
178
 * Author: Robert Bäckgren
179
 **********************************************************************/
180
void addDecoderThreadToServer(fsf_server_id_t server)
181
{
182
 
183
  int err;
184
  pthread_t j = -1;
185
  NRT_TASK_MODEL ht;
186
  static fsf_sched_params_t pr;
187
 
188
 
189
 
190
  pr.policy=FSF_RR;
191
  pr.params=&ht;
192
 
193
 
194
  nrt_task_default_model(ht);
195
  nrt_task_def_group(ht,1);
196
 
1563 trimarchi 197
  /*
198
    err = pthread_create(&j, NULL, mpeg2decoder, NULL);
199
    if (err) {  
1562 trimarchi 200
    grx_close();
201
    perror("Could not create task...");
202
    exit(err);
1563 trimarchi 203
    }
204
 
205
    err=fsf_bind_local_thread_to_server(server, j,(fsf_sched_params_t *)(&pr));
1562 trimarchi 206
 if (err) {
1563 trimarchi 207
 grx_close();
208
 //perror("Could not bind task..");
209
 exit(err);
210
 }
211
  */
212
 err = fsf_create_local_thread(server,(fsf_sched_params_t *)(&pr), &j,NULL,
213
                                mpeg2decoder,NULL);
214
 if (err) {  
1562 trimarchi 215
   grx_close();
1563 trimarchi 216
   grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0);
217
   exit(err);
218
 }
219
 task_activate(j);
1562 trimarchi 220
}
221
 
222
 
223
/***************************************************************************
224
 *
225
 * Create a dummy task and bind it to a server
226
 *
227
 * Author: Robert Bäckgren
228
 *****************************************************************************/
229
int  addOverLoadTaskToServer(fsf_server_id_t server)
230
{
231
  int err;
232
  pthread_t j = -1;
233
  HARD_TASK_MODEL ht;
234
  static fsf_sched_params_t pr;
235
 
236
 
237
 
238
  pr.policy=FSF_EDF;
239
  pr.params=&ht;
240
 
241
 
242
  hard_task_default_model(ht);
1565 trimarchi 243
  hard_task_def_mit(ht,2000000);
1562 trimarchi 244
  hard_task_def_wcet(ht,20000);
245
  nrt_task_def_group(ht,4);
246
 
1565 trimarchi 247
  /*
248
    err = pthread_create(&j, NULL, overLoadTask, NULL);
249
    if (err) {
250
    grx_text("Failed to create the decoder task",270,270,rgb16(255,255,255),0);  
1562 trimarchi 251
    return 0;
1565 trimarchi 252
    }
253
 
254
    err=fsf_bind_local_thread_to_server(server, j,(fsf_sched_params_t *)(&pr));
255
    if (err) {
256
    grx_close();
257
    //perror("Could not bind task..");
258
    exit(err);
259
    }
260
  */
261
  err = fsf_create_local_thread(server,(fsf_sched_params_t *)(&pr), &j,NULL,
262
                                overLoadTask,NULL);
263
  if (err) {  
264
    grx_close();
265
    grx_text("failed to create displayTask",0,0,rgb16(255,255,255),0);
266
    exit(err);
1562 trimarchi 267
  }
1565 trimarchi 268
  task_activate(j);
1562 trimarchi 269
 return 1;
270
}
1565 trimarchi 271
 
1562 trimarchi 272
void ending_system(KEY_EVT *e) {
273
 
274
  grx_close();
275
 
276
  exit(0);
277
}
278
 
279
 
280
int main(int argc, char **argv)
281
{
282
 
283
  char ch;
284
  int err;
285
  int i = 1;
286
  char tmp[100];
1563 trimarchi 287
  struct timespec simtime;
1562 trimarchi 288
  //KEY_EVT k;
1563 trimarchi 289
  union sigval no_sigval = {0};
290
 
1562 trimarchi 291
  PI_mutexattr_t a;
292
  KEY_EVT ev;
293
 
1563 trimarchi 294
  /* 10% */
1562 trimarchi 295
  struct timespec decoderPeriod = {0,30000000};
296
  struct timespec decoderBudget = {0,3000000};
1563 trimarchi 297
 
298
  /* 10% */
1562 trimarchi 299
  struct timespec readTaskPeriod = {0,30000000};
300
  struct timespec readTaskBudget = {0,3000000};
301
 
1563 trimarchi 302
  /* 45% */
1562 trimarchi 303
  struct timespec displayPeriod = {0,40000000};
304
  struct timespec displayBudget = {0,18000000};
305
 
1563 trimarchi 306
  // 5 %
1562 trimarchi 307
  struct timespec overloadPeriod = {0,10000000};
1563 trimarchi 308
  struct timespec overloadBudget = {0,500000};
1562 trimarchi 309
 
310
  fsf_server_id_t decoderServer;
311
  fsf_server_id_t readTaskServer;
312
  fsf_server_id_t displayServer;
313
  fsf_server_id_t overloadServer;
314
 
315
  fsf_contract_parameters_t overloadContract;
316
  fsf_contract_parameters_t decoderContract;
317
  fsf_contract_parameters_t readTaskContract;
318
  fsf_contract_parameters_t displayContract;
319
 
320
  union sigval sval;
321
 
322
 
1563 trimarchi 323
  //ev.ascii = 'c';
324
  //ev.scan  = KEY_C;
325
  //ev.status = KEY_PRESSED;
326
  //ev.flag = CNTR_BIT;
327
  //keyb_hook(ev, ending_system, FALSE);
1562 trimarchi 328
 
329
  PI_mutexattr_default(a);
1563 trimarchi 330
  fsf_init();
1562 trimarchi 331
 
332
  mutex_init(&mux,&a);
333
 
334
  // Set up the different servers
335
  fsf_initialize_contract(&readTaskContract);
1563 trimarchi 336
  err=fsf_set_contract_basic_parameters(&readTaskContract,&readTaskBudget,&readTaskPeriod,FSF_DEFAULT_WORKLOAD);
337
  if (err) {
338
    exit(err);
339
  }
340
  err=fsf_set_contract_reclamation_parameters(&readTaskContract,&readTaskBudget,&readTaskPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1);
341
  if (err) exit(err);
342
  err=fsf_set_contract_timing_requirements(&readTaskContract,true,NULL,0,no_sigval,0,no_sigval);
343
  if (err) exit(err);
344
 
1562 trimarchi 345
  fsf_set_contract_scheduling_policy(&readTaskContract, FSF_RR);
346
 
347
  fsf_initialize_contract(&decoderContract);
1563 trimarchi 348
  err=fsf_set_contract_basic_parameters(&decoderContract,&decoderBudget,&decoderPeriod,FSF_DEFAULT_WORKLOAD);
349
  if (err) {
350
    grx_close();
351
    exit(err);
352
  }
353
 
354
  err=fsf_set_contract_reclamation_parameters(&decoderContract,&decoderBudget,&decoderPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1);
355
  if (err) exit(err);
356
  err=fsf_set_contract_timing_requirements(&decoderContract,true,NULL,0,no_sigval,0,no_sigval);
357
  if (err) exit(err);
358
 
1562 trimarchi 359
  fsf_set_contract_scheduling_policy(&decoderContract, FSF_RR);
360
 
361
  fsf_initialize_contract(&displayContract);
1563 trimarchi 362
  err=fsf_set_contract_basic_parameters(&displayContract,&displayBudget,&displayPeriod,FSF_DEFAULT_WORKLOAD);
363
  if (err) {
364
    exit(err);
365
  }
366
 
367
  err=fsf_set_contract_reclamation_parameters(&displayContract,&displayBudget,&displayPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1);
368
  if (err) exit(err);
369
  err=fsf_set_contract_timing_requirements(&displayContract,true,NULL,0,no_sigval,0,no_sigval);
370
  if (err) exit(err);
371
 
1562 trimarchi 372
  fsf_set_contract_scheduling_policy(&displayContract, FSF_EDF);
373
 
374
  fsf_initialize_contract(&overloadContract);
1563 trimarchi 375
  err=fsf_set_contract_basic_parameters(&overloadContract,&overloadBudget,&overloadPeriod,FSF_DEFAULT_WORKLOAD);
376
  if (err) {
377
    exit(err);
378
  }
379
 
1565 trimarchi 380
  err=fsf_set_contract_reclamation_parameters(&overloadContract,&overloadBudget,&overloadPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1);
381
  if (err) exit(err);
382
  err=fsf_set_contract_timing_requirements(&overloadContract,true,NULL,0,no_sigval,0,no_sigval);
383
  if (err) exit(err);
384
 
1562 trimarchi 385
  fsf_set_contract_scheduling_policy(&overloadContract, FSF_EDF);
386
 
387
  err = fsf_negotiate_contract(&readTaskContract,&readTaskServer);
1563 trimarchi 388
  if (err) {
389
    exit(err);
390
  }
391
 
1562 trimarchi 392
  err = fsf_negotiate_contract(&decoderContract,&decoderServer);
1563 trimarchi 393
  if (err) {
394
    exit(err);
395
  }
1562 trimarchi 396
  err = fsf_negotiate_contract(&displayContract,&displayServer);
1563 trimarchi 397
  if (err) {
398
    exit(err);
399
  }
400
 
1562 trimarchi 401
  err = fsf_negotiate_contract(&overloadContract,&overloadServer);
1563 trimarchi 402
  if (err) {
403
    exit(err);
404
  }
1562 trimarchi 405
 
406
 
407
  // Create and bind different ports to communication links (This ports a declared in global.h)
408
  if((readTaskPort = port_create(readFilePortName, sizeof(struct readDecodeMessage), NUMBER_OF_MESSAGE, STREAM, WRITE)) == -1)
409
    {
410
      grx_text("failed to create readTask Port",0,0,rgb16(255,255,255),0);
411
      exit(-1);
412
    }
413
  if((decoderTaskPort->displayTaskPort = port_create(displayPortName, sizeof(struct decodeDisplayMessage), NUMBER_OF_MESSAGE, STREAM, WRITE)) == -1)
414
    {
1563 trimarchi 415
      grx_text("failed to create displayTask Port",0,0,rgb16(255,255,255),0);      
1562 trimarchi 416
      exit(-1);
417
    }
418
  if((decoderTaskPort->readTaskPort = port_connect(readFilePortName, sizeof(struct readDecodeMessage), STREAM, READ)) == -1)
419
    {
420
      grx_text("failed to connect to readTask Port",0,0,rgb16(255,255,255),0);
421
      exit(-1);
422
    }
423
  if((displayTaskPort = port_connect(displayPortName, sizeof(struct decodeDisplayMessage), STREAM, READ)) == -1)
424
    {
425
      grx_text("failed to connect to displayTask Port",0,0,rgb16(255,255,255),0);
1563 trimarchi 426
      exit(-1);
1562 trimarchi 427
    }
428
 
429
  //graphic card Initialization
1563 trimarchi 430
  if (grx_init() < 1) {    
1562 trimarchi 431
    exit(-1);
432
  }
433
 
434
  if (grx_open(800, 600, 16) < 0) {
435
    cprintf("GRX Err\n");
436
    exit(-1);
1563 trimarchi 437
  }
438
 
439
  kern_gettime(&simtime);
1565 trimarchi 440
  for (i=1; i<10;i++)  {
441
    simtime.tv_sec+=1;
442
    kern_event_post(&simtime,(void *)((void *)(addOverLoadTaskToServer)), (void *)overloadServer);
443
  }
444
 
445
  simtime.tv_sec+=10;
1563 trimarchi 446
  kern_event_post(&simtime,(void *)((void *)(ending_system)), NULL);
447
  /*ch = keyb_getch(BLOCK);
1562 trimarchi 448
 
449
  while(ch != ESC) {
450
 
451
      switch (ch)
452
        {
453
 
1563 trimarchi 454
            case '1': */
1562 trimarchi 455
              addReadTaskToServer(readTaskServer);
456
              addDecoderThreadToServer(decoderServer);
457
              addDisplayTaskToServer(displayServer);
1563 trimarchi 458
/*
1562 trimarchi 459
            break;
460
            case '2':
461
              sprintf(tmp,"Number of dummy task: %d", i);
462
              grx_text(tmp,0,0,rgb16(255,255,255),0);
463
              i++;
464
              addOverLoadTaskToServer(overloadServer);
465
            break;
466
            case '4':
467
              ending_system(NULL);
468
              break;
469
        }
470
 
471
    ch = keyb_getch(BLOCK);
472
 
473
  }
1563 trimarchi 474
*/
475
              //ending_system(NULL);
476
              while(1);
1562 trimarchi 477
 
478
 return 0;
479
 
480
}
481