Rev 1639 | Rev 1643 | 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 :
* Giacomo Guidi <giacomo@gandalf.sssup.ti>
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
/*
* 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
*/
#include "kernel/kern.h"
#include "modules/elastic.h"
#include <drivers/shark_keyb26.h>
#define MAX_TASKS 7
extern unsigned int usleep(unsigned int usec); // include file for this??
TASK elastic_test(void *arg) {
int y = (int)arg;
int x = 0;
char str[2];
str[0] = '0' + y;
str[1] = '\0';
while(1) {
puts_xy(x,y,LIGHTGRAY," ");
x = (x + 1) % 80;
puts_xy(x,y,LIGHTGRAY,str);
task_testcancel();
task_endcycle();
}
}
void myinput(char *str, char *buf, int len) {
BYTE c;
int n = 0;
cprintf(str);
do {
c = keyb_getch(NON_BLOCK);
if (c == ENTER) break;
if (c == 8) { // backspace
if (n > 0) {
cprintf("%c", c);
n--;
}
} else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) {
cprintf("%c", c);
buf[n++] = c;
}
} while (n < len);
buf[n] = '\0';
cprintf("\n");
}
int main(int argc, char **argv)
{
ELASTIC_TASK_MODEL e;
PID el_pid;
PID pidvec[MAX_TASKS];
int quit = 0;
char buf[80];
int y;
int Tmin, Tmax, C, E, T, nbr, i;
double U;
clear();
for (i=0; i<MAX_TASKS; i++) pidvec[i] = NIL;
do {
for (y = 7; y <=15; y++) {
puts_xy(0,y,LIGHTGRAY," ");
}
place(0,7);
U = 0.0;
cprintf("Nbr Tmin Tmax C E T \n");
for (i=0; i<MAX_TASKS; i++) {
if (pidvec[i] != NIL) {
Tmin = ELASTIC_get_Tmin(pidvec[i])/1000;
Tmax = ELASTIC_get_Tmax(pidvec[i])/1000;
C = ELASTIC_get_C(pidvec[i])/1000;
E = ELASTIC_get_E(pidvec[i]);
T = ELASTIC_get_period(pidvec[i])/1000;
U += (double)C/(double)T;
cprintf(" %1d %4d %4d %4d %4d %4d\n", i, Tmin, Tmax, C, E, T);
}
}
cprintf("Total utilization: %5.3f\n", U);
puts_xy(0,16,LIGHTGRAY," ");
place(0,16);
myinput("(q)uit, (c)reate, (k)ill, force (p)eriod, set (e)lasticity? ", buf, 10);
for (y = 17; y <=24; y++) {
puts_xy(0,y,LIGHTGRAY," ");
}
switch (buf[0]) {
case 'q':
quit = 1;
break;
case 'c':
cprintf("Create task\n");
for (i=0; i<MAX_TASKS; i++) {
if (pidvec[i] == NIL) break;
}
if (i == MAX_TASKS) {
cprintf("No more task slots available!\n");
break;
}
myinput("Tmin (ms): ", buf, 10);
Tmin = 1000*atoi(buf);
myinput("Tmax (ms): ", buf, 10);
Tmax = 1000*atoi(buf);
myinput("C (ms): ", buf, 10);
C = 1000*atoi(buf);
myinput("E: ", buf, 10);
E = atoi(buf);
elastic_task_default_model(e);
elastic_task_def_period(e, Tmin, Tmax);
elastic_task_def_wcet(e, C);
elastic_task_def_param(e, E, PERIOD_SCALING);
elastic_task_def_arg(e, (void *)i);
el_pid = task_create("Elastic",elastic_test,&e,NULL);
if (el_pid == NIL) {
cprintf("task_create failed!\n");
} else {
pidvec[i] = el_pid;
task_activate(el_pid);
}
break;
case 'p':
myinput("Force period\nTask nbr: ", buf, 10);
nbr = atoi(buf);
if (nbr < 0 || nbr >= MAX_TASKS) {
cprintf("Invalid task number!\n");
break;
}
el_pid = pidvec[nbr];
if (el_pid == NIL) {
cprintf("Task doesn't exist!\n");
break;
}
myinput("T (ms): ", buf, 10);
T = 1000*atoi(buf);
if (ELASTIC_set_period(el_pid, T) == -1) {
cprintf("ELASTIC_set_period failed!\n");
}
break;
case 'k':
myinput("Kill task\nTask nbr: ", buf, 10);
nbr = atoi(buf);
if (nbr < 0 || nbr >= MAX_TASKS) {
cprintf("Invalid task number!\n");
break;
}
el_pid = pidvec[nbr];
if (el_pid == NIL) {
cprintf("Task doesn't exist!\n");
break;
}
task_kill(el_pid);
pidvec[nbr] = NIL;
break;
case 'e':
myinput("Set elasticity\nTask nbr: ", buf, 10);
nbr = atoi(buf);
if (nbr < 0 || nbr >= MAX_TASKS) {
cprintf("Invalid task number!\n");
break;
}
el_pid = pidvec[nbr];
if (el_pid == NIL) {
cprintf("Task doesn't exist!\n");
break;
}
myinput("E: ", buf, 10);
E = atoi(buf);
if (ELASTIC_set_E(el_pid, E) == -1) {
cprintf("ELASTIC_set_E failed!\n");
}
break;
default:
cprintf("Unknown command\n");
break;
}
} while (!quit);
sys_end();
return 0;
}