Subversion Repositories shark

Rev

Go to most recent revision | 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: sysend.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 $
 ------------

 System termination:

   the main task create J1, J2 and wait until 1 sec., then it calls sys_end
     and cycles around a task_testcancel

   J1 is a system task that ends at t=1.5 sec.

   J2 is another user task that dies at t= 1.8 sec (it will not die!!!)


**/


/*
 * 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 <sys/types.h>
#include <pthread.h>
#include <signal.h>

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

void *J1(void *arg)
{
  while (sys_gettime(NULL) < 1500000);
  kern_printf("J1: t = 1.5 sec, ending...");
  return 0;
}

void uscitaJ2(void *arg)
{
  kern_printf("J2: AAAARRRRGGGHHH!!! killed by someone, time = %ld\n",sys_gettime(NULL));
}

void *J2(void *arg)
{
  task_cleanup_push(uscitaJ2,NULL);

  while (sys_gettime(NULL) < 1800000);
  kern_printf("J1: t = 1.8 sec, ending...");

  task_cleanup_pop(0);
  return 0;
}

void fine(KEY_EVT *e)
{
  sys_end();
}

void uscitamain(void *arg)
{
  kern_printf("main: AAAARRRRGGGHHH!!! killed by someone, time = %ld\n",sys_gettime(NULL));
}


int main(int argc, char **argv)
{
  PID err;

  NRT_TASK_MODEL m1, m2;

    KEY_EVT emerg;
    //keyb_set_map(itaMap);
    emerg.ascii = 'x';
    emerg.scan = KEY_X;
    emerg.flag = ALTL_BIT;
    keyb_hook(emerg,fine);


  nrt_task_default_model(m1);
  nrt_task_def_system(m1);
  nrt_task_def_level(m1,1);
  nrt_task_default_model(m2);
  nrt_task_def_level(m2,1);

  kern_printf("main: creating J1\n");
  err = task_create("J1", J1, (TASK_MODEL *)&m1, NULL);
  if (err == -1) kern_printf("Error creating J1\n");
  task_activate(err);

  kern_printf("main: creating J2\n");
  err = task_create("J2", J2, (TASK_MODEL *)&m2, NULL);
  if (err == -1) kern_printf("Error creating J2\n");
  task_activate(err);

  kern_printf("main: waiting 1 sec\n");
  while (sys_gettime(NULL) < 1000000);

  kern_printf("main: sys_end()\n");

  sys_end();

  task_cleanup_push(uscitamain,NULL);

  while (1)
    task_testcancel();

  task_cleanup_pop(0);

  return 0;
}