Subversion Repositories shark

Rev

Rev 1639 | Rev 1643 | 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
 
1627 giacomo 43
TASK elastic_test(void *arg) {
44
 
1639 anton 45
  int y = (int)arg;
46
  int x = 0;
1629 anton 47
 
1639 anton 48
  char str[2];
49
  str[0] = '0' + y;
50
  str[1] = '\0';
51
 
1627 giacomo 52
  while(1) {
1639 anton 53
    puts_xy(x,y,LIGHTGRAY," ");
54
    x = (x + 1) % 80;
55
    puts_xy(x,y,LIGHTGRAY,str);
56
    task_testcancel();
1627 giacomo 57
    task_endcycle();
58
  }
59
}
60
 
1639 anton 61
 
62
void myinput(char *str, char *buf, int len) {
63
  BYTE c;
64
  int n = 0;
65
 
66
  cprintf(str);
67
  do {
68
    c = keyb_getch(NON_BLOCK);
69
    if (c == ENTER) break;
70
    if (c == 8) { // backspace
71
      if (n > 0) {
72
        cprintf("%c", c);
73
        n--;
74
      }
1642 anton 75
    } else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) {
1639 anton 76
      cprintf("%c", c);
77
      buf[n++] = c;
78
    }
79
  } while (n < len);
80
 
81
  buf[n] = '\0';
82
  cprintf("\n");
83
}
84
 
85
 
1627 giacomo 86
int main(int argc, char **argv)
87
{
1639 anton 88
  ELASTIC_TASK_MODEL e;
89
  PID el_pid;
1642 anton 90
  PID pidvec[MAX_TASKS];
1639 anton 91
  int quit = 0;
92
  char buf[80];
93
  int y;
94
  int Tmin, Tmax, C, E, T, nbr, i;
95
  double U;
1627 giacomo 96
 
1639 anton 97
  clear();
98
 
99
  for (i=0; i<MAX_TASKS; i++) pidvec[i] = NIL;
1627 giacomo 100
 
1639 anton 101
  do {
1631 anton 102
 
1639 anton 103
    for (y = 7; y <=15; y++) {
104
      puts_xy(0,y,LIGHTGRAY,"                                                                                ");
105
    }
106
    place(0,7);
1627 giacomo 107
 
1639 anton 108
    U = 0.0;
109
    cprintf("Nbr  Tmin  Tmax    C     E     T  \n");
110
    for (i=0; i<MAX_TASKS; i++) {
111
      if (pidvec[i] != NIL) {
112
        Tmin = ELASTIC_get_Tmin(pidvec[i])/1000;
113
        Tmax = ELASTIC_get_Tmax(pidvec[i])/1000;
114
        C = ELASTIC_get_C(pidvec[i])/1000;
115
        E = ELASTIC_get_E(pidvec[i]);
116
        T = ELASTIC_get_period(pidvec[i])/1000;
117
        U += (double)C/(double)T;
118
        cprintf(" %1d   %4d  %4d  %4d  %4d  %4d\n", i, Tmin, Tmax, C, E, T);
119
      }
120
    }
121
    cprintf("Total utilization: %5.3f\n", U);
1631 anton 122
 
1639 anton 123
    puts_xy(0,16,LIGHTGRAY,"                                                                                ");
124
    place(0,16);
1627 giacomo 125
 
1642 anton 126
    myinput("(q)uit, (c)reate, (k)ill, force (p)eriod, set (e)lasticity? ", buf, 10);
1639 anton 127
    for (y = 17; y <=24; y++) {
128
      puts_xy(0,y,LIGHTGRAY,"                                                                                ");
129
    }
1631 anton 130
 
1639 anton 131
    switch (buf[0]) {
132
    case 'q':
133
      quit = 1;
134
      break;
135
    case 'c':
136
      cprintf("Create task\n");
137
      for (i=0; i<MAX_TASKS; i++) {
138
        if (pidvec[i] == NIL) break;
139
      }
140
      if (i == MAX_TASKS) {
141
        cprintf("No more task slots available!\n");
142
        break;
143
      }
144
      myinput("Tmin (ms): ", buf, 10);
145
      Tmin = 1000*atoi(buf);
146
      myinput("Tmax (ms): ", buf, 10);
147
      Tmax = 1000*atoi(buf);
148
      myinput("C (ms): ", buf, 10);
149
      C = 1000*atoi(buf);
150
      myinput("E: ", buf, 10);
151
      E = atoi(buf);
152
      elastic_task_default_model(e);
153
      elastic_task_def_period(e, Tmin, Tmax);
154
      elastic_task_def_wcet(e, C);
155
      elastic_task_def_param(e, E, PERIOD_SCALING);
156
      elastic_task_def_arg(e, (void *)i);
157
      el_pid = task_create("Elastic",elastic_test,&e,NULL);
158
      if (el_pid == NIL) {
1642 anton 159
        cprintf("task_create failed!\n");
1639 anton 160
      } else {
161
        pidvec[i] = el_pid;
162
        task_activate(el_pid);
163
      }
164
      break;
1642 anton 165
    case 'p':
1639 anton 166
      myinput("Force period\nTask nbr: ", buf, 10);
167
      nbr = atoi(buf);
168
      if (nbr < 0 || nbr >= MAX_TASKS) {
169
        cprintf("Invalid task number!\n");
170
        break;
171
      }
172
      el_pid = pidvec[nbr];
173
      if (el_pid == NIL) {
174
        cprintf("Task doesn't exist!\n");
175
        break;
176
      }
177
      myinput("T (ms): ", buf, 10);
178
      T = 1000*atoi(buf);
1642 anton 179
      if (ELASTIC_set_period(el_pid, T) == -1) {
180
        cprintf("ELASTIC_set_period failed!\n");
181
      }
1639 anton 182
      break;
1642 anton 183
    case 'k':
184
      myinput("Kill task\nTask nbr: ", buf, 10);
1639 anton 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;
1642 anton 198
    case 'e':
199
      myinput("Set elasticity\nTask nbr: ", buf, 10);
200
      nbr = atoi(buf);
201
      if (nbr < 0 || nbr >= MAX_TASKS) {
202
        cprintf("Invalid task number!\n");
203
        break;
204
      }
205
      el_pid = pidvec[nbr];
206
      if (el_pid == NIL) {
207
        cprintf("Task doesn't exist!\n");
208
        break;
209
      }
210
      myinput("E: ", buf, 10);
211
      E = atoi(buf);
212
      if (ELASTIC_set_E(el_pid, E) == -1) {
213
        cprintf("ELASTIC_set_E failed!\n");
214
      }
215
      break;
1639 anton 216
    default:
217
      cprintf("Unknown command\n");
218
      break;
219
    }
1631 anton 220
 
1639 anton 221
  } while (!quit);
1631 anton 222
 
1639 anton 223
  sys_end();
1628 giacomo 224
 
1627 giacomo 225
  return 0;
226
 
227
}