Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1664 pj 1
 
2
 
3
// JetControl
4
 
5
#include <kernel/kern.h>
6
#include <drivers/glib.h>
7
#include <drivers/keyb.h>
8
#include <semaphore.h>
9
//#include <stdlib.h>
10
#include <math.h>
11
#include <modules/cabs.h>
12
#include <modules/hartport.h>
13
#include "kernel/func.h"
14
 
15
#define CPU 1700
16
 
17
#if CPU==1700
18
#define WCET_JETCTRL      4500
19
#define WCET_JETDUMMY      100
20
#define WCET_JETSLIDE     1300
21
#endif
22
 
23
#define JET_NTASK   35
24
#define JET_Y_NAME 170
25
 
26
#define DUMMY_PID    1
27
 
28
#define JET_DUMMY_WIDTH    120
29
#define JET_DUMMY_HEIGHT    80
30
 
31
/* the point (x, y) is the top left corner */
32
#define JET_DUMMY_X        750
33
#define JET_DUMMY_Y        70
34
 
35
#define JET_SLIDE_WIDTH     30
36
#define JET_SLIDE_X        970
37
 
38
#define JET_ON 1
39
#define JETCTRLGRP 5
40
 
41
 
42
#define PERIOD_JETCTRL  100000
43
#define PERIOD_JETDUMMY 100000
44
#define PERIOD_JETSLIDE 100000
45
#define PERIOD_BALL      10000
46
 
47
 
48
 
49
extern sem_t mx_grf;
50
 
51
/* useful colors... */
52
int white;
53
int black;
54
int red;
55
int gray;
56
 
57
 
58
TASK jetdummy_task(void *arg)
59
{
60
  TIME   now_dummy, last_dummy, diff_dummy, slice;
61
  struct timespec now, last, diff;
62
  int x = 0;
63
  int height;
64
 
65
  NULL_TIMESPEC(&last);
66
  last_dummy = 0;
67
  for (;;) {
68
    task_nopreempt();
69
    jet_getstat(DUMMY_PID, NULL, NULL, NULL, &now_dummy);
70
    sys_gettime(&now);
71
    task_preempt();
72
 
73
    SUBTIMESPEC(&now, &last, &diff);
74
    slice = diff.tv_sec * 1000000 + diff.tv_nsec/1000;
75
    diff_dummy = now_dummy - last_dummy;
76
 
77
    height = (int)(JET_DUMMY_HEIGHT*((float)diff_dummy)/((float)slice));
78
 
79
    TIMESPEC_ASSIGN(&last, &now);
80
    last_dummy = now_dummy;
81
 
82
    sem_wait(&mx_grf);
83
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y,
84
             JET_DUMMY_X+x,JET_DUMMY_Y+height          ,black);
85
    grx_line(JET_DUMMY_X+x,JET_DUMMY_Y+height,
86
             JET_DUMMY_X+x,JET_DUMMY_Y+JET_DUMMY_HEIGHT,white);
87
    grx_line(JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y,
88
             JET_DUMMY_X+(x+1)%JET_DUMMY_WIDTH,JET_DUMMY_Y+JET_DUMMY_HEIGHT,255);
89
    grx_text("Dummy Task", 100,100, white, black);
90
 
91
    sem_post(&mx_grf);
92
 
93
 
94
    x = (x+1)%JET_DUMMY_WIDTH;
95
 
96
    task_endcycle();
97
  }
98
}
99
 
100
 
101
TASK jetctrl_task(void *arg)
102
{
103
  char st[50];
104
  TIME sum, max;
105
  int n;
106
 
107
  PID i;
108
  int printed = 0;
109
 
110
  for (;;) {
111
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
112
      if (jet_getstat(i, &sum, &max, &n, NULL) != -1) {
113
        if (!n) n=1;
114
        sprintf(st, "%6d %6d %10s", (int)sum/n, (int)max, proc_table[i].name);
115
        sem_wait(&mx_grf);
116
        grx_text(st, JET_DUMMY_X, JET_Y_NAME+16+printed*8, white, black);
117
        sem_post(&mx_grf);
118
        printed++;
119
      }
120
    }
121
    while (printed<JET_NTASK) {
122
      sem_wait(&mx_grf);
123
      grx_text("                        ",
124
               JET_DUMMY_X, JET_Y_NAME+16+printed*8, white, black);
125
      sem_post(&mx_grf);
126
      printed++;
127
    }
128
    task_endcycle();
129
  }
130
}
131
 
132
TASK jetslide_task(void *arg)
133
{
134
  TIME sum, curr, max;
135
 
136
  TIME total[JET_NTASK];
137
  int slides[JET_NTASK];
138
 
139
  PID i;
140
  int printed = 0;
141
 
142
  for (;;) {
143
    // Fill the total array in a nonpreemptive section
144
    task_nopreempt();
145
    for (i=2, printed=0; i<MAX_PROC && printed<JET_NTASK; i++) {
146
      if (jet_getstat(i, &sum, NULL, NULL, &curr) != -1) {
147
        total[printed] = sum+curr;
148
        printed++;
149
      }
150
    }
151
    task_preempt();
152
 
153
    while (printed < JET_NTASK)
154
      total[printed++] = 0;
155
 
156
    // Compute the Max elapsed time
157
    max = 0;
158
    for (i=0; i<JET_NTASK; i++)
159
      if (total[i] > max) max = total[i];
160
    if (!max) max = 1;
161
 
162
    // Compute the slides width
163
    for (i=0; i<JET_NTASK; i++)
164
      slides[i] = (int)( (((float)total[i])/max) * JET_SLIDE_WIDTH);
165
 
166
    // print the data
167
    sem_wait(&mx_grf);
168
    for (i=0; i<JET_NTASK; i++) {
169
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*8,
170
              JET_SLIDE_X+slides[i],       JET_Y_NAME+23+i*8, white);
171
      grx_box(JET_SLIDE_X+slides[i],       JET_Y_NAME+16+i*8,
172
              JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+23+i*8, red);//CHANGE MADE HERE
173
    }
174
 
175
    while (i<JET_NTASK) {
176
      grx_box(JET_SLIDE_X,                 JET_Y_NAME+16+i*8,
177
              JET_SLIDE_X+JET_SLIDE_WIDTH, JET_Y_NAME+20+i*8, red);//CHANGE MADE HERE
178
      i++;
179
    }
180
    sem_post(&mx_grf);
181
    task_endcycle();
182
  }
183
}
184
 
185
 
186
void scenario_jetcontrol(void)
187
{
188
  grx_text("System load"         , JET_DUMMY_X, 45, rgb16(0,0,255), black);
189
  grx_text("-----------", JET_DUMMY_X, JET_Y_NAME+10, white, black);
190
  //grx_line(JET_DUMMY_X,55,639,55,red);
191
 
192
  grx_text("  Mean    Max Name  Slide", JET_DUMMY_X, JET_Y_NAME, white, black);
193
  grx_text("-------------------------", JET_DUMMY_X, JET_Y_NAME+10, white, black);
194
  //grx_line(JET_DUMMY_X,JET_Y_NAME+10,JET_DUMMY_X+,JET_Y_NAME+10,white);
195
 
196
  grx_rect(JET_DUMMY_X-1,               JET_DUMMY_Y-1,
197
           JET_DUMMY_X+JET_DUMMY_WIDTH, JET_DUMMY_Y+JET_DUMMY_HEIGHT+1, white);
198
 
199
  grx_text("100%", JET_DUMMY_X-40, JET_DUMMY_Y, white, black);
200
  grx_text("  0%", JET_DUMMY_X-40, JET_DUMMY_Y+JET_DUMMY_HEIGHT-8, white, black);
201
 
202
  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y, JET_DUMMY_X-5, JET_DUMMY_Y, white);
203
  grx_line(JET_DUMMY_X-1, JET_DUMMY_Y+JET_DUMMY_HEIGHT, JET_DUMMY_X-5, JET_DUMMY_Y+JET_DUMMY_HEIGHT, white);
204
 
205
      /* useful colors ... */
206
    white = rgb16(255,255,255);
207
    black = rgb16(0,0,0);
208
    red   = rgb16(255,0,0);
209
    gray  = rgb16(128,128,128);
210
 
211
}
212
 
213
void init_jetcontrol(void)
214
{
215
    SOFT_TASK_MODEL m3, m4, m5;
216
 
217
    PID p3, p4, p5;
218
 
219
    soft_task_default_model(m3);
220
    soft_task_def_level(m3,1);
221
    soft_task_def_period(m3, PERIOD_JETCTRL);
222
    soft_task_def_met(m3, WCET_JETCTRL);
223
    soft_task_def_ctrl_jet(m3);
224
    soft_task_def_group(m3, JETCTRLGRP);
225
    p3 = task_create("jctrl", jetctrl_task, &m3, NULL);
226
    if (p3 == -1) {
227
        sys_shutdown_message("Could not create task <jetctrl> errno=%d",
228
                             errno);
229
        sys_end();
230
    }
231
 
232
    soft_task_default_model(m4);
233
    soft_task_def_level(m4,1);
234
    soft_task_def_period(m4, PERIOD_JETDUMMY);
235
    soft_task_def_met(m4, WCET_JETDUMMY);
236
    soft_task_def_group(m4, JETCTRLGRP);
237
    soft_task_def_usemath(m4);
238
    soft_task_def_ctrl_jet(m4);
239
    p4 = task_create("jdmy", jetdummy_task, &m4, NULL);
240
    if (p4 == -1) {
241
        sys_shutdown_message("Could not create task <jetdummy> errno=%d",
242
                             errno);
243
        sys_end();
244
    }
245
 
246
    soft_task_default_model(m5);
247
    soft_task_def_level(m5,1);
248
    soft_task_def_period(m5, PERIOD_JETSLIDE);
249
    soft_task_def_met(m5, WCET_JETSLIDE);
250
    soft_task_def_group(m5, JETCTRLGRP);
251
    soft_task_def_usemath(m5);
252
    soft_task_def_ctrl_jet(m5);
253
    p5 = task_create("jsli", jetslide_task, &m5, NULL);
254
    if (p5 == -1) {
255
        sys_shutdown_message("Could not create task <jetslide> errno=%d",
256
                             errno);
257
        sys_end();
258
    }
259
}
260
 
261