Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1627 giacomo 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
 *   Giacomo Guidi       <giacomo@gandalf.sssup.ti>
10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
18
/*
19
 * This program is free software; you can redistribute it and/or modify
20
 * it under the terms of the GNU General Public License as published by
21
 * the Free Software Foundation; either version 2 of the License, or
22
 * (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU General Public License
30
 * along with this program; if not, write to the Free Software
31
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
 */
33
 
34
#include "kernel/kern.h"
1631 anton 35
#include "modules/elastic.h"
1639 anton 36
#include <drivers/shark_keyb26.h>
1627 giacomo 37
 
1639 anton 38
#define MAX_TASKS 7
1631 anton 39
 
1639 anton 40
extern unsigned int usleep(unsigned int usec); // include file for this??
41
 
42
 
43
PID pidvec[10];
44
 
45
 
1627 giacomo 46
TASK elastic_test(void *arg) {
47
 
1639 anton 48
  int y = (int)arg;
49
  int x = 0;
1629 anton 50
 
1639 anton 51
  char str[2];
52
  str[0] = '0' + y;
53
  str[1] = '\0';
54
 
1627 giacomo 55
  while(1) {
1639 anton 56
    puts_xy(x,y,LIGHTGRAY," ");
57
    x = (x + 1) % 80;
58
    puts_xy(x,y,LIGHTGRAY,str);
59
    task_testcancel();
1627 giacomo 60
    task_endcycle();
61
  }
62
}
63
 
1639 anton 64
 
65
void myinput(char *str, char *buf, int len) {
66
  BYTE c;
67
  int n = 0;
68
 
69
  cprintf(str);
70
  do {
71
    c = keyb_getch(NON_BLOCK);
72
    if (c == ENTER) break;
73
    if (c == 8) { // backspace
74
      if (n > 0) {
75
        cprintf("%c", c);
76
        n--;
77
      }
78
    } else if (c) {
79
      cprintf("%c", c);
80
      buf[n++] = c;
81
    }
82
  } while (n < len);
83
 
84
  buf[n] = '\0';
85
  cprintf("\n");
86
}
87
 
88
 
1627 giacomo 89
int main(int argc, char **argv)
90
{
1639 anton 91
  ELASTIC_TASK_MODEL e;
92
  PID el_pid;
93
  int quit = 0;
94
  char buf[80];
95
  int y;
96
  int Tmin, Tmax, C, E, T, nbr, i;
97
  double U;
1627 giacomo 98
 
1639 anton 99
  clear();
100
 
101
  for (i=0; i<MAX_TASKS; i++) pidvec[i] = NIL;
1627 giacomo 102
 
1639 anton 103
  do {
1631 anton 104
 
1639 anton 105
    for (y = 7; y <=15; y++) {
106
      puts_xy(0,y,LIGHTGRAY,"                                                                                ");
107
    }
108
    place(0,7);
1627 giacomo 109
 
1639 anton 110
    U = 0.0;
111
    cprintf("Nbr  Tmin  Tmax    C     E     T  \n");
112
    for (i=0; i<MAX_TASKS; i++) {
113
      if (pidvec[i] != NIL) {
114
        Tmin = ELASTIC_get_Tmin(pidvec[i])/1000;
115
        Tmax = ELASTIC_get_Tmax(pidvec[i])/1000;
116
        C = ELASTIC_get_C(pidvec[i])/1000;
117
        E = ELASTIC_get_E(pidvec[i]);
118
        T = ELASTIC_get_period(pidvec[i])/1000;
119
        U += (double)C/(double)T;
120
        cprintf(" %1d   %4d  %4d  %4d  %4d  %4d\n", i, Tmin, Tmax, C, E, T);
121
      }
122
    }
123
    cprintf("Total utilization: %5.3f\n", U);
1631 anton 124
 
1639 anton 125
    puts_xy(0,16,LIGHTGRAY,"                                                                                ");
126
    place(0,16);
1627 giacomo 127
 
1639 anton 128
    myinput("(q)uit, (c)reate, (f)orce period, (d)elete? ", buf, 10);
129
    for (y = 17; y <=24; y++) {
130
      puts_xy(0,y,LIGHTGRAY,"                                                                                ");
131
    }
1631 anton 132
 
1639 anton 133
    switch (buf[0]) {
134
    case 'q':
135
      quit = 1;
136
      break;
137
    case 'c':
138
      cprintf("Create task\n");
139
      for (i=0; i<MAX_TASKS; i++) {
140
        if (pidvec[i] == NIL) break;
141
      }
142
      if (i == MAX_TASKS) {
143
        cprintf("No more task slots available!\n");
144
        break;
145
      }
146
      myinput("Tmin (ms): ", buf, 10);
147
      Tmin = 1000*atoi(buf);
148
      myinput("Tmax (ms): ", buf, 10);
149
      Tmax = 1000*atoi(buf);
150
      myinput("C (ms): ", buf, 10);
151
      C = 1000*atoi(buf);
152
      myinput("E: ", buf, 10);
153
      E = atoi(buf);
154
      elastic_task_default_model(e);
155
      elastic_task_def_period(e, Tmin, Tmax);
156
      elastic_task_def_wcet(e, C);
157
      elastic_task_def_param(e, E, PERIOD_SCALING);
158
      elastic_task_def_arg(e, (void *)i);
159
      el_pid = task_create("Elastic",elastic_test,&e,NULL);
160
      if (el_pid == NIL) {
161
        cprintf("Cannot create task!\n");
162
      } else {
163
        pidvec[i] = el_pid;
164
        task_activate(el_pid);
165
      }
166
      break;
167
    case 'f':
168
      myinput("Force period\nTask nbr: ", buf, 10);
169
      nbr = atoi(buf);
170
      if (nbr < 0 || nbr >= MAX_TASKS) {
171
        cprintf("Invalid task number!\n");
172
        break;
173
      }
174
      el_pid = pidvec[nbr];
175
      if (el_pid == NIL) {
176
        cprintf("Task doesn't exist!\n");
177
        break;
178
      }
179
      myinput("T (ms): ", buf, 10);
180
      T = 1000*atoi(buf);
181
      ELASTIC_set_period(el_pid, T);
182
      break;
183
    case 'd':
184
      myinput("Delete task\nTask nbr: ", buf, 10);
185
      nbr = atoi(buf);
186
      if (nbr < 0 || nbr >= MAX_TASKS) {
187
        cprintf("Invalid task number!\n");
188
        break;
189
      }
190
      el_pid = pidvec[nbr];
191
      if (el_pid == NIL) {
192
        cprintf("Task doesn't exist!\n");
193
        break;
194
      }
195
      task_kill(el_pid);
196
      pidvec[nbr] = NIL;
197
      break;
198
    default:
199
      cprintf("Unknown command\n");
200
      break;
201
    }
1631 anton 202
 
1639 anton 203
  } while (!quit);
1631 anton 204
 
1639 anton 205
  sys_end();
1628 giacomo 206
 
1627 giacomo 207
  return 0;
208
 
209
}