Subversion Repositories shark

Rev

Rev 1085 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
21
 CVS :        $Id: jetctrl.c,v 1.1.1.1 2002-09-02 09:37:42 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2002-09-02 09:37:42 $
26
 ------------
27
**/
28
 
29
/*
30
 * Copyright (C) 2000 Paolo Gai
31
 *
32
 * This program is free software; you can redistribute it and/or modify
33
 * it under the terms of the GNU General Public License as published by
34
 * the Free Software Foundation; either version 2 of the License, or
35
 * (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45
 *
46
 */
47
 
48
/*
49
 * this file is directly derived from the demos/jumpball/jetctrl.c .
50
 * I just added this controls to check when the system will become overloaded
51
 */
52
 
53
#define WCET_JETDUMMY      200
54
#define PERIOD_JETDUMMY 100000
55
#define DUMMY_PID    1
56
 
57
#define JET_DUMMY_WIDTH    (CMD_WIDTH-370)
58
#define JET_DUMMY_HEIGHT   (CMD_HEIGHT-40)
59
 
60
/* the point (x, y) is the top left corner */
61
#define JET_DUMMY_X        (TRACK_X1+360)
62
#define JET_DUMMY_Y        (TRACK_Y2+32)
63
 
64
// JetControl
65
 
66
#include "semaphore.h"
67
#include "include/const.h"
68
#include "kernel/func.h"
69
#include "drivers/glib.h"
70
 
71
extern sem_t grx_mutex;
72
 
73
/* useful colors... */
74
int white;
75
int black;
76
extern int red;
77
extern int lightgray;
78
 
79
TASK jetdummy_task(void *arg)
80
{
81
  TIME   now_dummy, last_dummy, diff_dummy, slice;
82
  struct timespec now, last, diff;
83
  int x = 0;
84
  int height;
85
 
86
  NULL_TIMESPEC(&last);
87
  last_dummy = 0;
88
  for (;;) {
89
    task_nopreempt();
90
    jet_getstat(DUMMY_PID, NULL, NULL, NULL, &now_dummy);
91
    sys_gettime(&now);
92
    task_preempt();
93
 
94
    SUBTIMESPEC(&now, &last, &diff);
95
    slice = diff.tv_sec * 1000000 + diff.tv_nsec/1000;
96
    diff_dummy = now_dummy - last_dummy;
97
 
98
    height = (int)(JET_DUMMY_HEIGHT*((float)diff_dummy)/((float)slice));
99
 
100
    TIMESPEC_ASSIGN(&last, &now);
101
    last_dummy = now_dummy;
102
 
103
    sem_wait(&grx_mutex);
104
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y,
105
             JET_DUMMY_X+x,JET_DUMMY_Y+height          ,black);
106
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y+height,
107
             JET_DUMMY_X+x,JET_DUMMY_Y+JET_DUMMY_HEIGHT,white);
108
    grx_line(JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y,
109
             JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y+JET_DUMMY_HEIGHT,255);
110
    sem_post(&grx_mutex);
111
 
112
    x = (x+1)%JET_DUMMY_WIDTH;
113
 
114
    task_endcycle();
115
  }
116
}
117
 
118
void init_jetcontrol(void)
119
{
120
    SOFT_TASK_MODEL m4;
121
 
122
    PID p4;
123
 
124
    /* useful colors ... */
125
    white = WHITE;
126
    black = BLACK;
127
 
128
    /* scenario */
129
    sem_wait(&grx_mutex);
130
    grx_text("System load",
131
             JET_DUMMY_X+8, JET_DUMMY_Y-10, lightgray, black);
132
    grx_rect(JET_DUMMY_X-1,               JET_DUMMY_Y-1,
133
             JET_DUMMY_X+JET_DUMMY_WIDTH, JET_DUMMY_Y+JET_DUMMY_HEIGHT+1, lightgray);
134
 
135
    grx_text("100%", JET_DUMMY_X-40, JET_DUMMY_Y, lightgray, black);
136
    grx_text("  0%", JET_DUMMY_X-40, JET_DUMMY_Y+JET_DUMMY_HEIGHT-8, lightgray, black);
137
 
138
    grx_line(JET_DUMMY_X-1, JET_DUMMY_Y, JET_DUMMY_X-5, JET_DUMMY_Y, lightgray);
139
    grx_line(JET_DUMMY_X-1, JET_DUMMY_Y+JET_DUMMY_HEIGHT, JET_DUMMY_X-5, JET_DUMMY_Y+JET_DUMMY_HEIGHT, lightgray);
140
    sem_post(&grx_mutex);
141
 
142
    /* jetdummy task */
143
    soft_task_default_model(m4);
144
    soft_task_def_period(m4, PERIOD_JETDUMMY);
145
    soft_task_def_met(m4, WCET_JETDUMMY);
146
    soft_task_def_usemath(m4);
147
    p4 = task_create("jdmy", jetdummy_task, &m4, NULL);
148
    if (p4 == -1) {
149
        grx_close();
150
        perror("Could not create task <jetdummy>");
151
        sys_end();
152
    }
153
    task_activate(p4);
154
}
155