Subversion Repositories shark

Rev

Rev 1178 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Project: S.Ha.R.K.
 *
 * Coordinators:
 *   Giorgio Buttazzo    <giorgio@sssup.it>
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *
 * Authors     :
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *   (see the web pages for full authors list)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


/*
 ------------
 CVS :        $Id: test7.c,v 1.2 2003-08-01 13:20:38 trimarchi Exp $

 File:        $File$
 Revision:    $Revision: 1.2 $
 Last update: $Date: 2003-08-01 13:20:38 $
 ------------

 this test shows a set of 5 tasks (+main+dummy+keyboard driver).
 
 The first 4 tasks are scheduled by a EDFSTAR Module, whereas the
 fifth one is a standard traditional EDF task. The 4 tasks uses a
 budget of 10000/100000.
 
 if edfstar.c is compiled with edfstar_printf3 active, a couple
 (dline, curtime) is showed (in ms).
 
 if cbsstar.c is compiled with cbsstar_printf3 active, the budget
 replenishments are showed.
*/


/*
 * Copyright (C) 2002 Paolo Gai
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "cbsstar.h"
#include "posixstar.h"
#include "modules/rr.h"
#include "modules/dummy.h"

#include "modules/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"

#include "modules/pi.h"
#include "modules/nop.h"

// --------------------------------------------------
// --------------------------------------------------
// Init Part
// --------------------------------------------------
// --------------------------------------------------


/*+ sysyem tick in us +*/
#define TICK 0

/*+ RR tick in us +*/
#define RRTICK 10000

TIME __kernel_register_levels__(void *arg)
{
  struct multiboot_info *mb = (struct multiboot_info *)arg;
  int cbsstar_level, posixstar_level, mybudget, mybudget1, posixstar_level1;

  EDF_register_level(EDF_ENABLE_ALL);

  cbsstar_level = CBSSTAR_register_level(3, 0);
  mybudget = CBSSTAR_setbudget(cbsstar_level, 15000, 30000);
  mybudget1 = CBSSTAR_setbudget(cbsstar_level, 14000, 56000);
  posixstar_level = POSIXSTAR_register_level(mybudget, cbsstar_level, 3000,1);
  posixstar_level1 = POSIXSTAR_register_level(mybudget1, cbsstar_level, 5000,1);
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
  dummy_register_level();

  // for the keyboard...
  //CBS_register_level(CBS_ENABLE_ALL, 0);

  //SEM_register_module();
  PI_register_module();
  NOP_register_module();
  return TICK;
}


TASK __init__(void *arg)
{
  struct multiboot_info *mb = (struct multiboot_info *)arg;
  //CABS_register_module();
  //keyb_def_map(kparms,itaMap);
  //KEYB_init(&kparms);
  __call_main__(mb);

  return (void *)0;
}

// --------------------------------------------------
// --------------------------------------------------
// The Test
// --------------------------------------------------
// --------------------------------------------------


#include <kernel/kern.h>
#include <drivers/keyb.h>
#include <semaphore.h>

mutex_t s;

void *star(void *arg)
{
  int j;
  for (;;) {
    for (j=0; j<5000; j++);
    //sem_wait(&s);
    mutex_lock(&s);
    cputc('°');
    cputs((char *)arg);
    mutex_unlock(&s);
    //kern_printf("ril");
    //sem_post(&s);
    //task_endcycle();
  }

  return NULL;
}

void *edftask(void *arg)
{
  int i,j;
  while(1) {
  for (i=0;i<5; i++) {
    for (j=0; j<10; j++);
    //sem_wait(&s);
    //mutex_lock(&s);
    cputc('°');
    cputs((char *)arg);
    //mutex_unlock(&s);
    //sem_post(&s);
  }

  task_endcycle();
  }

  return NULL;
}


void create1()
{
  int i;
  NRT_TASK_MODEL m1;
  HARD_TASK_MODEL m2;
  PID p1a, p1b, p1c[20],p2,p3;
  struct timespec fineprg;
  nrt_task_default_model(m1);
  nrt_task_def_group(m1, 1);
  nrt_task_def_level(m1,2);
  nrt_task_def_arg(m1,(void *)"A");
  nrt_task_def_weight(m1,0);
  p1a = task_create("a",star,&m1,NULL);
  if (p1a == -1) {
    perror("Could not create task <Write>");
    sys_abort(-1);
  }
 
  nrt_task_def_arg(m1,(void *)"B");
  nrt_task_def_group(m1, 1);
  nrt_task_def_level(m1,2);
    p1b = task_create("b", star, &m1, NULL);
  if (p1b == -1) {
    perror("Could not create task b ...");
    sys_end();
  }
 
 nrt_task_def_arg(m1,(void *)"1");
 nrt_task_def_group(m1, 1);
 nrt_task_def_level(m1,2);

  p1c[5] = task_create("1", star, &m1, NULL);
  if (p1c[5] == -1) {
     perror("Could not create task b ...");
     sys_end();
 }

 
  nrt_task_def_arg(m1,(void *)"C");
  nrt_task_def_group(m1, 1);
  nrt_task_def_level(m1,2);
 
  p1c[4] = task_create("c", star, &m1, NULL);
  if (p1c[4] == -1) {
    perror("Could not create task b ...");
    sys_end();
  }

  nrt_task_def_arg(m1,(void *)"D");
  nrt_task_def_group(m1, 1);
  nrt_task_def_level(m1,2);
 
  p1c[5] = task_create("d", star, &m1, NULL);
  if (p1c[5] == -1) {
    perror("Could not create task b ...");
    sys_end();
  }
 
  nrt_task_def_arg(m1,(void *)"E");
  nrt_task_def_group(m1, 1);
  nrt_task_def_level(m1,2);
 
  p1c[0] = task_create("e", star, &m1, NULL);
  if (p1c[0] == -1) {
    perror("Could not create task b ...");
    sys_end();
  }

  nrt_task_def_arg(m1,(void *)"F");
  p1c[1] = task_create("f", star, &m1, NULL);
  if (p1c[1] == -1) {
    perror("Could not create task b ...");
    sys_end();
  }

 
  nrt_task_def_arg(m1,(void *)"G");
  nrt_task_def_group(m1, 1);
  nrt_task_def_level(m1,2);
 
  p1c[2] = task_create("g", star, &m1, NULL);
  if (p1c[2] == -1) {
    perror("Could not create task b ...");
    sys_end();
  }

  nrt_task_def_arg(m1,(void *)"H");
  p1c[3] = task_create("h", star, &m1, NULL);
  if (p1c[3] == -1) {
    perror("Could not create task b ...");
    sys_end();
  }
 
  nrt_task_def_arg(m1,(void *)"I");
  p1c[4] = task_create("h", star, &m1, NULL);
  if (p1c[4] == -1) {
      perror("Could not create task b ...");
      sys_end();
  }
 
     

  hard_task_default_model(m2);
  hard_task_def_ctrl_jet(m2);
  hard_task_def_mit(m2,32000); // the budget has dline 100,000!
  hard_task_def_wcet(m2, 3000);
  hard_task_def_arg(m2,(void *)"X");
  hard_task_def_group(m2,1);
  hard_task_def_periodic(m2);
   
  p2 = task_create("2", edftask, &m2, NULL);
  if (p2 == -1) {
    perror("Could not create task edf ...");
    sys_end();
  }

  hard_task_def_mit(m2,32000); // the budget has dline 100,000!
  hard_task_def_wcet(m2, 3000);
  hard_task_def_arg(m2,(void *)"K");
  p3 = task_create("3", edftask, &m2, NULL);
  if (p3 == -1) {
    perror("Could not create task edf ...");
    sys_end();
  }

  cprintf("stars=%d", p2);
  fineprg.tv_sec=140;
  fineprg.tv_nsec=0;
  kern_event_post(&fineprg,(void(*)(void *))sys_end, NULL);
  group_activate(1);
}

int main(int argc, char **argv)
{
  char c='t';
  PI_mutexattr_t a;
  PI_mutexattr_default(a);

  //NOP_mutexattr_t a;
  //NOP_mutexattr_default(a);


  mutex_init(&s,&a);

  clear();
 

  cprintf("Hello, world!\nPress ESC to end the demo...\n");

  create1();

  do {
    //c =keyb_getch(BLOCK);
    //        cprintf("[]");
  } while (c != ESC);

  cprintf("ESC pressed!");

  sys_end();

  return 0;
}