Subversion Repositories shark

Rev

Blame | 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: test6.c,v 1.1 2004-06-01 11:42:45 giacomo Exp $

 File:        $File$
 Revision:    $Revision: 1.1 $
 Last update: $Date: 2004-06-01 11:42:45 $
 ------------

 this test shows a set of 5 tasks (+main+dummy+keyboard driver).
 
 The first 4 tasks are scheduled by a RMSTAR 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 "rmstar.h"
#include "modules/rr.h"
#include "modules/dummy.h"

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

#include "drivers/keyb.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, rmstar_level, mybudget;

  EDF_register_level(EDF_ENABLE_ALL);

  cbsstar_level = CBSSTAR_register_level(3, 0);
  mybudget = CBSSTAR_setbudget(cbsstar_level, 10000, 100000);
  rmstar_level = RMSTAR_register_level(mybudget, cbsstar_level);

  RR_register_level(RRTICK, RR_MAIN_YES, mb);
  dummy_register_level();

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

  SEM_register_module();

  CABS_register_module();

  return TICK;
}

TASK __init__(void *arg)
{
  struct multiboot_info *mb = (struct multiboot_info *)arg;

  KEYB_PARMS kparms = BASE_KEYB;

  HARTPORT_init();

  //keyb_def_ctrlC(kparms, NULL);
  //keyb_def_map(kparms,itaMap);
  KEYB_init(&kparms);

  __call_main__(mb);

  return (void *)0;
}

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


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

void *star(void *arg)
{
  int i,j;

  for (i=0; i<5; i++) {
    for (j=0; j<100000; j++);
    cputc('°');
    cputs((char *)arg);
    task_endcycle();
  }

  return NULL;
}

void *edftask(void *arg)
{
  int i,j;

  for (i=0; i<5; i++) {
    for (j=0; j<100000; j++);
    cputc('°');
    cputs((char *)arg);
    task_endcycle();
  }

  return NULL;
}

void create1()
{
  HARD_TASK_MODEL m1, m2;
  PID p1a, p1b, p1c, p1d, p2;

  hard_task_default_model(m1);
  hard_task_def_wcet(m1, 5000);
  hard_task_def_level(m1,2);
  hard_task_def_group(m1,1);
  hard_task_def_periodic(m1);

  hard_task_def_arg(m1,(void *)"a");
  hard_task_def_mit(m1,10000);
  p1a = task_create("a", star, &m1, NULL);
  if (p1a == -1) {
    perror("Could not create task a ...");
    sys_end();
  }

  hard_task_def_arg(m1,(void *)"b");
  hard_task_def_mit(m1,15000);
  p1b = task_create("b", star, &m1, NULL);
  if (p1b == -1) {
    perror("Could not create task b ...");
    sys_end();
  }

  hard_task_def_arg(m1,(void *)"c");
  hard_task_def_mit(m1,20000);
  p1c = task_create("c", star, &m1, NULL);
  if (p1c == -1) {
    perror("Could not create task c ...");
    sys_end();
  }

  hard_task_def_arg(m1,(void *)"d");
  hard_task_def_mit(m1,30000);
  p1d = task_create("d", star, &m1, NULL);
  if (p1d == -1) {
    perror("Could not create task d ...");
    sys_end();
  }

  hard_task_default_model(m2);
  hard_task_def_mit(m2,50000); // the budget has dline 100,000!
  hard_task_def_wcet(m2, 5000);
  hard_task_def_arg(m2,(void *)"Û");
  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();
  }

  cprintf("stars=%d %d %d %d, star2=%d\n", p1a, p1b, p1c, p1d, p2);

  group_activate(1);
}

int main(int argc, char **argv)
{
  char c;

  clear();

  cprintf("Hello, world!");

  create1();

  do {
    c =keyb_getch(BLOCK);
  } while (c != ESC);

  cprintf("ESC pressed!");

  sys_end();

  return 0;
}