Blame |
Last modification |
View Log
| RSS feed
#include "constants.h"
#include "atcsim.h"
#include <kernel/func.h>
#include <kernel/kern.h> //include the SHARK kernel header
#include <drivers/glib.h> //include the graphics library
#include <drivers/keyb.h> //include the keyboard library
#include <semaphore.h> //include the semaphore library
#include <stdlib.h> //include the standard library
#include <math.h> //include the math library for random
#include <string.h>
extern sem_t graphics_mutex
;
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
(&graphics_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);
// grx_text("Dummy task", 100,100, gray, black);
sem_post
(&graphics_mutex
);
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
, "%4d %4d %8s", (int)sum
/n
, (int)max
, proc_table
[i
].
name);
sem_wait
(&graphics_mutex
);
grx_text
(st
, XMAX
+10, JET_Y_NAME
+16+printed
*8, gray
, black
);
sem_post
(&graphics_mutex
);
printed
++;
}
}
while (printed
<JET_NTASK
) {
sem_wait
(&graphics_mutex
);
grx_text
(" ",
XMAX
+10, JET_Y_NAME
+16+printed
*8, gray
, black
);
sem_post
(&graphics_mutex
);
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
(&graphics_mutex
);
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, gray
);
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, black
);
}
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, black
);
i
++;
}
sem_post
(&graphics_mutex
);
task_endcycle
();
}
}
void scenario_jetcontrol
(void)
{
grx_text
("System load", XMAX
+10, YMIN
+100, rgb16
(0,0,255), black
);
grx_line
(XMAX
+10,YMIN
+100,XMAX
+JET_DUMMY_WIDTH
,YMIN
+100,red
);
grx_text
("Mean Max Name Slide", XMAX
+10, JET_Y_NAME
, gray
, black
);
grx_line
(XMAX
+10,JET_Y_NAME
+10,XMAX
+JET_DUMMY_WIDTH
,JET_Y_NAME
+10,gray
);
grx_rect
(JET_DUMMY_X
-1, JET_DUMMY_Y
-1, JET_DUMMY_X
+JET_DUMMY_WIDTH
, JET_DUMMY_Y
+JET_DUMMY_HEIGHT
+1, gray
);
grx_text
("100%", JET_DUMMY_X
-40, JET_DUMMY_Y
, gray
, black
);
grx_text
(" 0%", JET_DUMMY_X
-40, JET_DUMMY_Y
+JET_DUMMY_HEIGHT
-8, gray
, black
);
grx_line
(JET_DUMMY_X
-1, JET_DUMMY_Y
, JET_DUMMY_X
-5, JET_DUMMY_Y
, gray
);
grx_line
(JET_DUMMY_X
-1, JET_DUMMY_Y
+JET_DUMMY_HEIGHT
, JET_DUMMY_X
-5, JET_DUMMY_Y
+JET_DUMMY_HEIGHT
, gray
);
}
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
, JETCONTROL
);
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
, JETCONTROL
);
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
, JETCONTROL
);
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
();
}
}