Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/*
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
 *
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
 *               Gerardo Lamastra <gerardo@sssup.it>
 *
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
 * (see authors.txt for full list of hartik's authors)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://hartik.sssup.it
 */


/**
 ------------
 CVS :        $Id: testc.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $

 File:        $File$
 Revision:    $Revision: 1.1.1.1 $
 Last update: $Date: 2002-09-02 09:37:48 $
 ------------

 Test Number 12 (C):

 CBS test, similar to Test 11

 then at start time two task are started, one of them
   calling task_nopreempt. when the task releases, the other exec all
   the pending activations.
 at sec. 4 the test stops.

**/


/*
 * Copyright (C) 2000 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"

TASK pippo()
{
//  int i;
  struct timespec t;
//  int last = 0;

  do {
    kern_cli();
    ll_gettime(TIME_EXACT, &t);
    kern_sti();
  } while (t.tv_nsec <= 30000000L);
  return 0;
}

TASK pippo2()
{
//  int i;
  struct timespec t;
//  int last = 0;

  do {
    kern_cli();
    ll_gettime(TIME_EXACT, &t);
    kern_sti();

  } while (t.tv_nsec <= 30000000L);
  return 0;
}

TASK asteroide(void)
{
    int i;
    int y = rand() % 7 + 15;

    int load1,j;

    char s[2];

    s[0] = '*'; s[1] = 0;

    /*for (;;)*/ {
      i = 1;
      while (i < 60) {
        load1 = 10000; //8000 + rand()%2000;
        for (j=0; j<load1; j++) {
          s[0] = '*' + rand() % 100;
          puts_xy(i,y,rand()%15+1,s);
        }

        task_endcycle();

//        if (i==7)  testactive = 0;

        puts_xy(i,y,WHITE," ");
        i++;
      }
    }
    //num_aster--;
    return 0;
}

TASK aper(void *a)
{
    int i;
    int y;

    int load1,j;

    char s[2];

    y = (int) a;

    s[0] = '*'; s[1] = 0;

    /*for (;;)*/ {
      i = 1;
      while (i < 60) {
        load1 = 600000; //8000 + rand()%2000;
        for (j=0; j<load1; j++) {
          s[0] = '*' + rand() % 100;
          puts_xy(i,y,rand()%15+1,s);
        }

        task_endcycle();

        puts_xy(i,y,WHITE," ");
        i++;
      }
    }
    //num_aster--;
    return 0;
}


TASK per(void)
{
    int i;
    int y = rand() % 7 + 15;

    int load1,j;

    char s[2];

    s[0] = '*'; s[1] = 0;

    /*for (;;)*/ {
      i = 1;
      while (i < 60) {
        load1 = 1000; //8000 + rand()%2000;
        for (j=0; j<load1; j++) {
          s[0] = '*' + rand() % 100;
          puts_xy(i,y,rand()%15+1,s);
        }

        task_endcycle();

//        if (i==7)  testactive = 0;

        //puts_xy(i,y,WHITE," ");
        i++;
      }
    }
    //num_aster--;
    return 0;
}

TASK stoppa()
{
  struct timespec t;

  task_nopreempt();
  kern_printf("\nTask nopreempt");
  do {
    kern_cli();
    ll_gettime(TIME_EXACT, &t);
    kern_sti();
  } while (t.tv_sec < 3);
  kern_printf("\nTask preempt");
  task_preempt();
  kern_printf("\nFine STOPPA");
    return 0;
}



int main(int argc, char **argv)
{
  struct timespec t;
  int i;
  NRT_TASK_MODEL m;
//  HARD_TASK_MODEL m_per;
  SOFT_TASK_MODEL m_aper;
  PID p8, p9; //p1, p2, p3, p4, p5, p6, p7,

//  int k=1;

  srand(7);

  nrt_task_default_model(m);
  nrt_task_def_group(m,1);

  soft_task_default_model(m_aper);
  soft_task_def_met(m_aper,10000);
  soft_task_def_period(m_aper,100000);
  soft_task_def_group(m_aper,1);
  soft_task_def_system(m_aper);
  soft_task_def_arg(m_aper, (void *)14);
  soft_task_def_aperiodic(m_aper);
//  soft_task_def_skip_arrivals(m_aper);

  soft_task_def_periodic(m_aper);
  p8 = task_create("per", per, &m_aper, NULL);
  if (p8 == NIL)
  { kern_printf("Can't create per task...\n"); }

  p9 = task_create("stoppa", stoppa, &m, NULL);
  if (p9 == NIL)
  { kern_printf("Can't create stoppa task...\n"); }

  task_activate(p8);

  i = 0;

  NULL_TIMESPEC(&t);
  do {
    kern_cli();
    ll_gettime(TIME_EXACT, &t);
    kern_sti();

    if (i == 0 && t.tv_sec == 1 && t.tv_nsec >= 0) {
      task_activate(p9);
      i = 1;
    }
  } while (t.tv_sec < 10);
/*
  testactive = 0;
  kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
  for (i=0; i<useds; i++)
     kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i,
               s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
*/

  return 0;
}