Subversion Repositories shark

Rev

Rev 1562 | 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);
243
  hard_task_def_mit(ht,200000);
244
  hard_task_def_wcet(ht,20000);
245
  nrt_task_def_group(ht,4);
246
 
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);  
251
    return 0;
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
 }
1563 trimarchi 260
 
1562 trimarchi 261
 return 1;
262
}
263
void ending_system(KEY_EVT *e) {
264
 
265
  grx_close();
266
 
267
  exit(0);
268
}
269
 
270
 
271
int main(int argc, char **argv)
272
{
273
 
274
  char ch;
275
  int err;
276
  int i = 1;
277
  char tmp[100];
1563 trimarchi 278
  struct timespec simtime;
1562 trimarchi 279
  //KEY_EVT k;
1563 trimarchi 280
  union sigval no_sigval = {0};
281
 
1562 trimarchi 282
  PI_mutexattr_t a;
283
  KEY_EVT ev;
284
 
1563 trimarchi 285
  /* 10% */
1562 trimarchi 286
  struct timespec decoderPeriod = {0,30000000};
287
  struct timespec decoderBudget = {0,3000000};
1563 trimarchi 288
 
289
  /* 10% */
1562 trimarchi 290
  struct timespec readTaskPeriod = {0,30000000};
291
  struct timespec readTaskBudget = {0,3000000};
292
 
1563 trimarchi 293
  /* 45% */
1562 trimarchi 294
  struct timespec displayPeriod = {0,40000000};
295
  struct timespec displayBudget = {0,18000000};
296
 
1563 trimarchi 297
  // 5 %
1562 trimarchi 298
  struct timespec overloadPeriod = {0,10000000};
1563 trimarchi 299
  struct timespec overloadBudget = {0,500000};
1562 trimarchi 300
 
301
  fsf_server_id_t decoderServer;
302
  fsf_server_id_t readTaskServer;
303
  fsf_server_id_t displayServer;
304
  fsf_server_id_t overloadServer;
305
 
306
  fsf_contract_parameters_t overloadContract;
307
  fsf_contract_parameters_t decoderContract;
308
  fsf_contract_parameters_t readTaskContract;
309
  fsf_contract_parameters_t displayContract;
310
 
311
  union sigval sval;
312
 
313
 
1563 trimarchi 314
  //ev.ascii = 'c';
315
  //ev.scan  = KEY_C;
316
  //ev.status = KEY_PRESSED;
317
  //ev.flag = CNTR_BIT;
318
  //keyb_hook(ev, ending_system, FALSE);
1562 trimarchi 319
 
320
  PI_mutexattr_default(a);
1563 trimarchi 321
  fsf_init();
1562 trimarchi 322
 
323
  mutex_init(&mux,&a);
324
 
325
  // Set up the different servers
326
  fsf_initialize_contract(&readTaskContract);
1563 trimarchi 327
  err=fsf_set_contract_basic_parameters(&readTaskContract,&readTaskBudget,&readTaskPeriod,FSF_DEFAULT_WORKLOAD);
328
  if (err) {
329
    exit(err);
330
  }
331
  err=fsf_set_contract_reclamation_parameters(&readTaskContract,&readTaskBudget,&readTaskPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1);
332
  if (err) exit(err);
333
  err=fsf_set_contract_timing_requirements(&readTaskContract,true,NULL,0,no_sigval,0,no_sigval);
334
  if (err) exit(err);
335
 
1562 trimarchi 336
  fsf_set_contract_scheduling_policy(&readTaskContract, FSF_RR);
337
 
338
  fsf_initialize_contract(&decoderContract);
1563 trimarchi 339
  err=fsf_set_contract_basic_parameters(&decoderContract,&decoderBudget,&decoderPeriod,FSF_DEFAULT_WORKLOAD);
340
  if (err) {
341
    grx_close();
342
    exit(err);
343
  }
344
 
345
  err=fsf_set_contract_reclamation_parameters(&decoderContract,&decoderBudget,&decoderPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1);
346
  if (err) exit(err);
347
  err=fsf_set_contract_timing_requirements(&decoderContract,true,NULL,0,no_sigval,0,no_sigval);
348
  if (err) exit(err);
349
 
1562 trimarchi 350
  fsf_set_contract_scheduling_policy(&decoderContract, FSF_RR);
351
 
352
  fsf_initialize_contract(&displayContract);
1563 trimarchi 353
  err=fsf_set_contract_basic_parameters(&displayContract,&displayBudget,&displayPeriod,FSF_DEFAULT_WORKLOAD);
354
  if (err) {
355
    exit(err);
356
  }
357
 
358
  err=fsf_set_contract_reclamation_parameters(&displayContract,&displayBudget,&displayPeriod,FSF_DEFAULT_GRANULARITY, NULL, 1,1);
359
  if (err) exit(err);
360
  err=fsf_set_contract_timing_requirements(&displayContract,true,NULL,0,no_sigval,0,no_sigval);
361
  if (err) exit(err);
362
 
1562 trimarchi 363
  fsf_set_contract_scheduling_policy(&displayContract, FSF_EDF);
364
 
365
  fsf_initialize_contract(&overloadContract);
1563 trimarchi 366
  err=fsf_set_contract_basic_parameters(&overloadContract,&overloadBudget,&overloadPeriod,FSF_DEFAULT_WORKLOAD);
367
  if (err) {
368
    exit(err);
369
  }
370
 
1562 trimarchi 371
  fsf_set_contract_scheduling_policy(&overloadContract, FSF_EDF);
372
 
373
  err = fsf_negotiate_contract(&readTaskContract,&readTaskServer);
1563 trimarchi 374
  if (err) {
375
    exit(err);
376
  }
377
 
1562 trimarchi 378
  err = fsf_negotiate_contract(&decoderContract,&decoderServer);
1563 trimarchi 379
  if (err) {
380
    exit(err);
381
  }
1562 trimarchi 382
  err = fsf_negotiate_contract(&displayContract,&displayServer);
1563 trimarchi 383
  if (err) {
384
    exit(err);
385
  }
386
 
1562 trimarchi 387
  err = fsf_negotiate_contract(&overloadContract,&overloadServer);
1563 trimarchi 388
  if (err) {
389
    exit(err);
390
  }
1562 trimarchi 391
 
392
 
393
  // Create and bind different ports to communication links (This ports a declared in global.h)
394
  if((readTaskPort = port_create(readFilePortName, sizeof(struct readDecodeMessage), NUMBER_OF_MESSAGE, STREAM, WRITE)) == -1)
395
    {
396
      grx_text("failed to create readTask Port",0,0,rgb16(255,255,255),0);
397
      exit(-1);
398
    }
399
  if((decoderTaskPort->displayTaskPort = port_create(displayPortName, sizeof(struct decodeDisplayMessage), NUMBER_OF_MESSAGE, STREAM, WRITE)) == -1)
400
    {
1563 trimarchi 401
      grx_text("failed to create displayTask Port",0,0,rgb16(255,255,255),0);      
1562 trimarchi 402
      exit(-1);
403
    }
404
  if((decoderTaskPort->readTaskPort = port_connect(readFilePortName, sizeof(struct readDecodeMessage), STREAM, READ)) == -1)
405
    {
406
      grx_text("failed to connect to readTask Port",0,0,rgb16(255,255,255),0);
407
      exit(-1);
408
    }
409
  if((displayTaskPort = port_connect(displayPortName, sizeof(struct decodeDisplayMessage), STREAM, READ)) == -1)
410
    {
411
      grx_text("failed to connect to displayTask Port",0,0,rgb16(255,255,255),0);
1563 trimarchi 412
      exit(-1);
1562 trimarchi 413
    }
414
 
415
  //graphic card Initialization
1563 trimarchi 416
  if (grx_init() < 1) {    
1562 trimarchi 417
    exit(-1);
418
  }
419
 
420
  if (grx_open(800, 600, 16) < 0) {
421
    cprintf("GRX Err\n");
422
    exit(-1);
1563 trimarchi 423
  }
424
 
425
  kern_gettime(&simtime);
426
  simtime.tv_sec+=20;
427
  kern_event_post(&simtime,(void *)((void *)(ending_system)), NULL);
428
  /*ch = keyb_getch(BLOCK);
1562 trimarchi 429
 
430
  while(ch != ESC) {
431
 
432
      switch (ch)
433
        {
434
 
1563 trimarchi 435
            case '1': */
1562 trimarchi 436
              addReadTaskToServer(readTaskServer);
437
              addDecoderThreadToServer(decoderServer);
438
              addDisplayTaskToServer(displayServer);
1563 trimarchi 439
/*
1562 trimarchi 440
            break;
441
            case '2':
442
              sprintf(tmp,"Number of dummy task: %d", i);
443
              grx_text(tmp,0,0,rgb16(255,255,255),0);
444
              i++;
445
              addOverLoadTaskToServer(overloadServer);
446
            break;
447
            case '4':
448
              ending_system(NULL);
449
              break;
450
        }
451
 
452
    ch = keyb_getch(BLOCK);
453
 
454
  }
1563 trimarchi 455
*/
456
              //ending_system(NULL);
457
              while(1);
1562 trimarchi 458
 
459
 return 0;
460
 
461
}
462