Subversion Repositories shark

Rev

Rev 1642 | Rev 1644 | 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"
1643 anton 35
#include "time.h"
1631 anton 36
#include "modules/elastic.h"
1639 anton 37
#include <drivers/shark_keyb26.h>
1627 giacomo 38
 
1643 anton 39
 
1639 anton 40
#define MAX_TASKS 7
1631 anton 41
 
1639 anton 42
 
1643 anton 43
/* A task that scrolls a number (the task number) across the screen */
1639 anton 44
 
1627 giacomo 45
TASK elastic_test(void *arg) {
46
 
1639 anton 47
  int y = (int)arg;
1643 anton 48
  int x = 0;  
1629 anton 49
 
1639 anton 50
  char str[2];
1643 anton 51
  str[0] = '0' + y + 1;
1639 anton 52
  str[1] = '\0';
53
 
1627 giacomo 54
  while(1) {
1639 anton 55
    puts_xy(x,y,LIGHTGRAY," ");
56
    x = (x + 1) % 80;
57
    puts_xy(x,y,LIGHTGRAY,str);
58
    task_testcancel();
1627 giacomo 59
    task_endcycle();
60
  }
61
}
62
 
1643 anton 63
/* A simple keyboard string input routine */
1639 anton 64
 
1643 anton 65
void myinput(char *query, char *buf, int len) {
1639 anton 66
  BYTE c;
67
  int n = 0;
68
 
1643 anton 69
  cprintf(query);
70
 
1639 anton 71
  do {
72
    c = keyb_getch(NON_BLOCK);
1643 anton 73
    if (c == '\r') break;
74
    if (c == '\b') {
1639 anton 75
      if (n > 0) {
1643 anton 76
        cprintf("%c", '\b');
1639 anton 77
        n--;
78
      }
1642 anton 79
    } else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) {
1639 anton 80
      cprintf("%c", c);
81
      buf[n++] = c;
82
    }
83
  } while (n < len);
84
 
85
  buf[n] = '\0';
86
  cprintf("\n");
87
}
88
 
1643 anton 89
/* The main program */
1639 anton 90
 
1627 giacomo 91
int main(int argc, char **argv)
92
{
1639 anton 93
  ELASTIC_TASK_MODEL e;
94
  PID el_pid;
1642 anton 95
  PID pidvec[MAX_TASKS];
1639 anton 96
  int quit = 0;
97
  char buf[80];
98
  int y;
99
  int Tmin, Tmax, C, E, T, nbr, i;
100
  double U;
1627 giacomo 101
 
1643 anton 102
  for (i=0; i<MAX_TASKS; i++) pidvec[i] = NIL;
1639 anton 103
  clear();
1627 giacomo 104
 
1643 anton 105
  /* Create predefined task 1 */
106
  elastic_task_default_model(e);
107
  elastic_task_def_period(e, 50000, 200000);
108
  elastic_task_def_wcet(e, 25000);
109
  elastic_task_def_param(e, 5, PERIOD_SCALING);
110
  elastic_task_def_arg(e, (void *)0);
111
  el_pid = task_create("Elastic",elastic_test,&e,NULL);
112
  if (el_pid == NIL) {
113
    cprintf("ELASTIC_public_create failed!\n");
114
  } else {
115
    pidvec[0] = el_pid;
116
    task_activate(el_pid);
117
  }
118
 
119
  /* Create predefined task 2 */
120
  elastic_task_default_model(e);
121
  elastic_task_def_period(e, 100000, 150000);
122
  elastic_task_def_wcet(e, 40000);
123
  elastic_task_def_param(e, 10, PERIOD_SCALING);
124
  elastic_task_def_arg(e, (void *)1);
125
  el_pid = task_create("Elastic",elastic_test,&e,NULL);
126
  if (el_pid == NIL) {
127
    cprintf("ELASTIC_public_create failed!\n");
128
  } else {
129
    pidvec[1] = el_pid;
130
    task_activate(el_pid);
131
  }
132
 
1639 anton 133
  do {
1631 anton 134
 
1639 anton 135
    for (y = 7; y <=15; y++) {
136
      puts_xy(0,y,LIGHTGRAY,"                                                                                ");
137
    }
138
    place(0,7);
1627 giacomo 139
 
1639 anton 140
    U = 0.0;
141
    cprintf("Nbr  Tmin  Tmax    C     E     T  \n");
142
    for (i=0; i<MAX_TASKS; i++) {
143
      if (pidvec[i] != NIL) {
144
        Tmin = ELASTIC_get_Tmin(pidvec[i])/1000;
145
        Tmax = ELASTIC_get_Tmax(pidvec[i])/1000;
146
        C = ELASTIC_get_C(pidvec[i])/1000;
147
        E = ELASTIC_get_E(pidvec[i]);
148
        T = ELASTIC_get_period(pidvec[i])/1000;
149
        U += (double)C/(double)T;
1643 anton 150
        cprintf(" %1d   %4d  %4d  %4d  %4d  %4d\n", i+1, Tmin, Tmax, C, E, T);
1639 anton 151
      }
152
    }
153
    cprintf("Total utilization: %5.3f\n", U);
1631 anton 154
 
1639 anton 155
    puts_xy(0,16,LIGHTGRAY,"                                                                                ");
156
    place(0,16);
1627 giacomo 157
 
1643 anton 158
    myinput("(q)uit, (c)reate, (k)ill, force (p)eriod, change (e)lasticity? ", buf, 10);
1639 anton 159
    for (y = 17; y <=24; y++) {
160
      puts_xy(0,y,LIGHTGRAY,"                                                                                ");
161
    }
1631 anton 162
 
1639 anton 163
    switch (buf[0]) {
1643 anton 164
 
165
      /* Quit */
1639 anton 166
    case 'q':
167
      quit = 1;
168
      break;
1643 anton 169
 
170
      /* Create task */
1639 anton 171
    case 'c':
1643 anton 172
      cprintf("Create task");
1639 anton 173
      for (i=0; i<MAX_TASKS; i++) {
174
        if (pidvec[i] == NIL) break;
175
      }
176
      if (i == MAX_TASKS) {
1643 anton 177
        cprintf("\nNo more task slots available!\n");
1639 anton 178
        break;
1643 anton 179
      } else {
180
        cprintf(" %d\n", i+1);
1639 anton 181
      }
182
      myinput("Tmin (ms): ", buf, 10);
183
      Tmin = 1000*atoi(buf);
184
      myinput("Tmax (ms): ", buf, 10);
185
      Tmax = 1000*atoi(buf);
186
      myinput("C (ms): ", buf, 10);
187
      C = 1000*atoi(buf);
188
      myinput("E: ", buf, 10);
189
      E = atoi(buf);
190
      elastic_task_default_model(e);
191
      elastic_task_def_period(e, Tmin, Tmax);
192
      elastic_task_def_wcet(e, C);
193
      elastic_task_def_param(e, E, PERIOD_SCALING);
194
      elastic_task_def_arg(e, (void *)i);
195
      el_pid = task_create("Elastic",elastic_test,&e,NULL);
196
      if (el_pid == NIL) {
1643 anton 197
        cprintf("ELASTIC_public_create failed!\n");
1639 anton 198
      } else {
199
        pidvec[i] = el_pid;
200
        task_activate(el_pid);
201
      }
202
      break;
1643 anton 203
 
204
      /* Force period */
1642 anton 205
    case 'p':
1639 anton 206
      myinput("Force period\nTask nbr: ", buf, 10);
207
      nbr = atoi(buf);
1643 anton 208
      if (nbr < 1 || nbr > MAX_TASKS) {
1639 anton 209
        cprintf("Invalid task number!\n");
210
        break;
211
      }
1643 anton 212
      el_pid = pidvec[nbr-1];
1639 anton 213
      if (el_pid == NIL) {
1643 anton 214
        cprintf("Task does not exist!\n");
1639 anton 215
        break;
216
      }
217
      myinput("T (ms): ", buf, 10);
218
      T = 1000*atoi(buf);
1642 anton 219
      if (ELASTIC_set_period(el_pid, T) == -1) {
220
        cprintf("ELASTIC_set_period failed!\n");
221
      }
1639 anton 222
      break;
1643 anton 223
 
224
      /* Kill task */
1642 anton 225
    case 'k':
226
      myinput("Kill task\nTask nbr: ", buf, 10);
1639 anton 227
      nbr = atoi(buf);
1643 anton 228
      if (nbr < 1 || nbr > MAX_TASKS) {
1639 anton 229
        cprintf("Invalid task number!\n");
230
        break;
231
      }
1643 anton 232
      el_pid = pidvec[nbr-1];
1639 anton 233
      if (el_pid == NIL) {
1643 anton 234
        cprintf("Task does not exist!\n");
1639 anton 235
        break;
236
      }
237
      task_kill(el_pid);
1643 anton 238
      pidvec[nbr-1] = NIL;
239
      usleep(500000);  // wait half a second before redrawing the task table!!!
240
      /* also erase task number */
241
      puts_xy(0,nbr-1,LIGHTGRAY,"                                                                                ");
1639 anton 242
      break;
1643 anton 243
 
244
      /* Set elasticity */
1642 anton 245
    case 'e':
246
      myinput("Set elasticity\nTask nbr: ", buf, 10);
247
      nbr = atoi(buf);
1643 anton 248
      if (nbr < 1 || nbr > MAX_TASKS) {
1642 anton 249
        cprintf("Invalid task number!\n");
250
        break;
251
      }
1643 anton 252
      el_pid = pidvec[nbr-1];
1642 anton 253
      if (el_pid == NIL) {
1643 anton 254
        cprintf("Task does not exist!\n");
1642 anton 255
        break;
256
      }
257
      myinput("E: ", buf, 10);
258
      E = atoi(buf);
259
      if (ELASTIC_set_E(el_pid, E) == -1) {
260
        cprintf("ELASTIC_set_E failed!\n");
261
      }
262
      break;
1643 anton 263
 
1639 anton 264
    default:
265
      cprintf("Unknown command\n");
266
      break;
267
    }
1631 anton 268
 
1639 anton 269
  } while (!quit);
1631 anton 270
 
1639 anton 271
  sys_end();
1628 giacomo 272
 
1627 giacomo 273
  return 0;
274
 
275
}