Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed



// JetControl

#include <kernel/kern.h>
#include <drivers/glib.h>
#include <drivers/keyb.h>
#include <semaphore.h>
//#include <stdlib.h>
#include <math.h>
#include <modules/cabs.h>
#include <modules/hartport.h>
#include "kernel/func.h"

#define CPU 1700

#if CPU==1700
#define WCET_JETCTRL      4500
#define WCET_JETDUMMY      100
#define WCET_JETSLIDE     1300
#endif

#define JET_NTASK   35
#define JET_Y_NAME 170

#define DUMMY_PID    1

#define JET_DUMMY_WIDTH    120
#define JET_DUMMY_HEIGHT    80

/* the point (x, y) is the top left corner */
#define JET_DUMMY_X        750
#define JET_DUMMY_Y        70

#define JET_SLIDE_WIDTH     30
#define JET_SLIDE_X        970

#define JET_ON 1
#define JETCTRLGRP 5


#define PERIOD_JETCTRL  100000
#define PERIOD_JETDUMMY 100000
#define PERIOD_JETSLIDE 100000
#define PERIOD_BALL      10000



extern sem_t mx_grf;

/* useful colors... */
int white;
int black;
int red;
int gray;


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(&mx_grf);
    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);
    grx_text("Dummy Task", 100,100, white, black);

    sem_post(&mx_grf);


    x = (x+1)%JET_DUMMY_WIDTH;

    task_endcycle();
  }
}


TASK jetctrl_task(void *arg)
{
  char st[50];
  TIME sum, max;
  int n;

  PID i;
  int printed = 0;

  for (;;) {
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
      if (jet_getstat(i, &sum, &max, &n, NULL) != -1) {
        if (!n) n=1;
        sprintf(st, "%6d %6d %10s", (int)sum/n, (int)max, proc_table[i].name);
        sem_wait(&mx_grf);
        grx_text(st, JET_DUMMY_X, JET_Y_NAME+16+printed*8, white, black);
        sem_post(&mx_grf);
        printed++;
      }
    }
    while (printed<JET_NTASK) {
      sem_wait(&mx_grf);
      grx_text("                        ",
               JET_DUMMY_X, JET_Y_NAME+16+printed*8, white, black);
      sem_post(&mx_grf);
      printed++;
    }
    task_endcycle();
  }
}

TASK jetslide_task(void *arg)
{
  TIME sum, curr, max;

  TIME total[JET_NTASK];
  int slides[JET_NTASK];

  PID i;
  int printed = 0;

  for (;;) {
    // Fill the total array in a nonpreemptive section
    task_nopreempt();
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
      if (jet_getstat(i, &sum, NULL, NULL, &curr) != -1) {
        total[printed] = sum+curr;
        printed++;
      }
    }
    task_preempt();

    while (printed < JET_NTASK)
      total[printed++] = 0;

    // Compute the Max elapsed time
    max = 0;
    for (i=0; i<JET_NTASK; i++)
      if (total[i] > max) max = total[i];
    if (!max) max = 1;

    // Compute the slides width
    for (i=0; i<JET_NTASK; i++)
      slides[i] = (int)( (((float)total[i])/max) * JET_SLIDE_WIDTH);

    // print the data
    sem_wait(&mx_grf);
    for (i=0; i<JET_NTASK; i++) {
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*8,
              JET_SLIDE_X+slides[i],       JET_Y_NAME+23+i*8, white);
      grx_box(JET_SLIDE_X+slides[i],       JET_Y_NAME+16+i*8,
              JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+23+i*8, red);//CHANGE MADE HERE
    }

    while (i<JET_NTASK) {
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*8,
              JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+20+i*8, red);//CHANGE MADE HERE
      i++;
    }
    sem_post(&mx_grf);
    task_endcycle();
  }
}


void scenario_jetcontrol(void)
{
  grx_text("System load"         , JET_DUMMY_X, 45, rgb16(0,0,255), black);
  grx_text("-----------", JET_DUMMY_X, JET_Y_NAME+10, white, black);
  //grx_line(JET_DUMMY_X,55,639,55,red);

  grx_text("  Mean    Max Name  Slide", JET_DUMMY_X, JET_Y_NAME, white, black);
  grx_text("-------------------------", JET_DUMMY_X, JET_Y_NAME+10, white, black);
  //grx_line(JET_DUMMY_X,JET_Y_NAME+10,JET_DUMMY_X+,JET_Y_NAME+10,white);

  grx_rect(JET_DUMMY_X-1,               JET_DUMMY_Y-1,
           JET_DUMMY_X+JET_DUMMY_WIDTH, JET_DUMMY_Y+JET_DUMMY_HEIGHT+1, white);

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

  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y, JET_DUMMY_X-5, JET_DUMMY_Y, white);
  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y+JET_DUMMY_HEIGHT, JET_DUMMY_X-5, JET_DUMMY_Y+JET_DUMMY_HEIGHT, white);

      /* useful colors ... */
    white = rgb16(255,255,255);
    black = rgb16(0,0,0);
    red   = rgb16(255,0,0);
    gray  = rgb16(128,128,128);

}

void init_jetcontrol(void)
{
    SOFT_TASK_MODEL m3, m4, m5;

    PID p3, p4, p5;

    soft_task_default_model(m3);
    soft_task_def_level(m3,1);
    soft_task_def_period(m3, PERIOD_JETCTRL);
    soft_task_def_met(m3, WCET_JETCTRL);
    soft_task_def_ctrl_jet(m3);
    soft_task_def_group(m3, JETCTRLGRP);
    p3 = task_create("jctrl", jetctrl_task, &m3, NULL);
    if (p3 == -1) {
        sys_shutdown_message("Could not create task <jetctrl> errno=%d",
                             errno);
        sys_end();
    }

    soft_task_default_model(m4);
    soft_task_def_level(m4,1);
    soft_task_def_period(m4, PERIOD_JETDUMMY);
    soft_task_def_met(m4, WCET_JETDUMMY);
    soft_task_def_group(m4, JETCTRLGRP);
    soft_task_def_usemath(m4);
    soft_task_def_ctrl_jet(m4);
    p4 = task_create("jdmy", jetdummy_task, &m4, NULL);
    if (p4 == -1) {
        sys_shutdown_message("Could not create task <jetdummy> errno=%d",
                             errno);
        sys_end();
    }

    soft_task_default_model(m5);
    soft_task_def_level(m5,1);
    soft_task_def_period(m5, PERIOD_JETSLIDE);
    soft_task_def_met(m5, WCET_JETSLIDE);
    soft_task_def_group(m5, JETCTRLGRP);
    soft_task_def_usemath(m5);
    soft_task_def_ctrl_jet(m5);
    p5 = task_create("jsli", jetslide_task, &m5, NULL);
    if (p5 == -1) {
        sys_shutdown_message("Could not create task <jetslide> errno=%d",
                             errno);
        sys_end();
    }
}