Subversion Repositories shark

Rev

Go to most recent revision | 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: jetctrl.c,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $

 File:        $File$
 Revision:    $Revision: 1.1.1.1 $
 Last update: $Date: 2004-05-24 18:03:39 $
 ------------
**/


/*
 * 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
 *
 */


/*
 * this file is directly derived from the demos/jumpball/jetctrl.c .
 * I just added this controls to check when the system will become overloaded
 */


#define WCET_JETDUMMY      200
#define PERIOD_JETDUMMY 100000
#define DUMMY_PID    1

#define JET_DUMMY_WIDTH    (CMD_WIDTH-370)
#define JET_DUMMY_HEIGHT   (CMD_HEIGHT-40)

/* the point (x, y) is the top left corner */
#define JET_DUMMY_X        (TRACK_X1+360)
#define JET_DUMMY_Y        (TRACK_Y2+32)

// JetControl

#include "semaphore.h"
#include "include/const.h"
#include "kernel/func.h"
#include "drivers/glib.h"

extern sem_t grx_mutex;

/* useful colors... */
int white;
int black;
extern int red;
extern int lightgray;

TASK jetdummy_task(void *arg)
{
  TIME   now_dummy, last_dummy, diff_dummy, slice;
  struct timespec now, last, diff;
  int x = 0;
  int height;

  NULL_TIMESPEC(&last);
  last_dummy = 0;
  for (;;) {
    task_nopreempt();
    jet_getstat(DUMMY_PID, NULL, NULL, NULL, &now_dummy);
    sys_gettime(&now);
    task_preempt();

    SUBTIMESPEC(&now, &last, &diff);
    slice = diff.tv_sec * 1000000 + diff.tv_nsec/1000;
    diff_dummy = now_dummy - last_dummy;

    height = (int)(JET_DUMMY_HEIGHT*((float)diff_dummy)/((float)slice));

    TIMESPEC_ASSIGN(&last, &now);
    last_dummy = now_dummy;

    sem_wait(&grx_mutex);
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y,
             JET_DUMMY_X+x,JET_DUMMY_Y+height          ,black);
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y+height,
             JET_DUMMY_X+x,JET_DUMMY_Y+JET_DUMMY_HEIGHT,white);
    grx_line(JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y,
             JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y+JET_DUMMY_HEIGHT,255);
    sem_post(&grx_mutex);

    x = (x+1)%JET_DUMMY_WIDTH;

    task_endcycle();
  }
}

void init_jetcontrol(void)
{
    SOFT_TASK_MODEL m4;

    PID p4;

    /* useful colors ... */
    white = WHITE;
    black = BLACK;

    /* scenario */
    sem_wait(&grx_mutex);
    grx_text("System load",
             JET_DUMMY_X+8, JET_DUMMY_Y-10, lightgray, black);
    grx_rect(JET_DUMMY_X-1,               JET_DUMMY_Y-1,
             JET_DUMMY_X+JET_DUMMY_WIDTH, JET_DUMMY_Y+JET_DUMMY_HEIGHT+1, lightgray);

    grx_text("100%", JET_DUMMY_X-40, JET_DUMMY_Y, lightgray, black);
    grx_text("  0%", JET_DUMMY_X-40, JET_DUMMY_Y+JET_DUMMY_HEIGHT-8, lightgray, black);

    grx_line(JET_DUMMY_X-1, JET_DUMMY_Y, JET_DUMMY_X-5, JET_DUMMY_Y, lightgray);
    grx_line(JET_DUMMY_X-1, JET_DUMMY_Y+JET_DUMMY_HEIGHT, JET_DUMMY_X-5, JET_DUMMY_Y+JET_DUMMY_HEIGHT, lightgray);
    sem_post(&grx_mutex);

    /* jetdummy task */
    soft_task_default_model(m4);
    soft_task_def_period(m4, PERIOD_JETDUMMY);
    soft_task_def_met(m4, WCET_JETDUMMY);
    soft_task_def_usemath(m4);
    p4 = task_create("jdmy", jetdummy_task, &m4, NULL);
    if (p4 == -1) {
        grx_close();
        perror("Could not create task <jetdummy>");
        sys_end();
    }
    task_activate(p4);
}