/demos/trunk/base/time.c |
---|
0,0 → 1,69 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* 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 |
* |
* |
* CVS : $Id: time.c,v 1.1 2002-10-28 08:13:37 pj Exp $ |
* |
* Timer correctness test |
*/ |
#include "kernel/kern.h" |
#define NT 10 |
int main(int argc, char **argv) |
{ |
struct timespec t[NT]; |
int i; |
cprintf("Timer correctness test (1 second).\n"); |
for (i=0; i<NT; i++) NULL_TIMESPEC(&t[i]); |
do { |
for (i=0; i<NT-1; i++) t[i+1] = t[i]; |
sys_gettime(&t[0]); |
if (TIMESPEC_A_LT_B(&t[0],&t[1])) { |
for (i=0; i<NT; i++) |
cprintf("%d %ld\n",i, t[i].tv_nsec); |
sys_end(); |
} |
} while (t[0].tv_sec < 1); |
return 0; |
} |
/demos/trunk/base/aster1.c |
---|
0,0 → 1,175 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* 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 |
* |
* |
* CVS : $Id: aster1.c,v 1.1 2002-10-28 08:13:37 pj Exp $ |
this is a reduced verion of the classic Hartik demo Aster. |
It uses: |
- EDF module |
. periodic tasks |
- an high number of task executing concurrently |
The demo ends after 6 seconds. |
*/ |
/* |
Well, this is only a stupid demo which intend to show many |
HARTIK+ capabilities; the application is structured in the followig |
way: there is an ASTER task wich randomly creates some ASTEROID tasks |
which are displayed into the first window; each task is HARD/PERIODIC |
and auto-kills itself when it reaches the window end! |
Finally a CLOCK task is implemented to test system clock. |
Please note that usually the HARTIK+ application is made up of a task |
group which interacts among them, while the main() function, which |
became a task itself when the kernel is activated, is suspended until |
the system is ready to terminate; the MAIN task can also be used to make |
other background activities, but it should not be killed; when the |
application terminates, the control is passed to MAIN which kills |
everybody, shut down the system and can handle other operations using |
the services available with the previou operating system (I.E. the DOS). |
If you need to manage sudden abort/exception you should install your own |
exception handler and raise it through the exc_raise() primitive to |
make the system abort safely! |
Remember that the exit functions posted through sys_atexit() will be |
executed in both cases, to allow clean system shutdown. |
*/ |
#include "kernel/kern.h" |
int num_aster = 0; |
#define ASTER_LIM 67 |
#define ASTER_MAX 90 |
TASK asteroide(void) |
{ |
int i = 1; |
int y = rand() % 20 + 1; |
while (i < ASTER_LIM) { |
puts_xy(i,y,WHITE,"*"); |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
num_aster--; |
return 0; |
} |
DWORD taskCreated = 0; |
TASK aster(void) |
{ |
PID p; |
HARD_TASK_MODEL m; |
int r; |
hard_task_default_model(m); |
hard_task_def_wcet(m,500); |
srand(7); |
while (1) { |
if (num_aster < ASTER_MAX) { |
r = (rand() % 50) - 25; |
hard_task_def_arg(m,(void *)((rand() % 7)+1)); |
hard_task_def_mit(m, (50+r)*1000); |
p = task_create("aaa",asteroide,&m,NULL); |
taskCreated++; |
task_activate(p); |
num_aster++; |
} |
task_endcycle(); |
} |
} |
TASK clock() |
{ |
int s = 0, m = 0; |
while(1) { |
printf_xy(70,1,WHITE,"%2d : %2d",m,s); |
task_endcycle(); |
if (++s > 59) { |
s = 0; |
m++; |
} |
printf_xy(70,1,WHITE,"%2d : %2d",m,s); |
task_endcycle(); |
} |
} |
int main(int argc, char **argv) |
{ |
PID p1,p2; |
HARD_TASK_MODEL m; |
struct timespec t; |
clear(); |
hard_task_default_model(m); |
hard_task_def_mit(m,10000); |
hard_task_def_wcet(m,2000); |
hard_task_def_group(m,1); |
p1 = task_create("Aster",aster,&m,NULL); |
if (p1 == -1) { |
perror("Aster.C(main): Could not create task <aster> ..."); |
sys_end(); |
} |
hard_task_def_mit(m,500000); |
p2 = task_create("Clock",clock,&m,NULL); |
if (p2 == -1) { |
perror("Aster.C(main): Could not create task <Clock> ..."); |
sys_end(); |
} |
group_activate(1); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 6); |
sys_status(SCHED_STATUS); |
sys_end(); |
return 0; |
} |
/demos/trunk/base/aster2.c |
---|
0,0 → 1,240 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* 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 |
* |
* |
* CVS : $Id: aster2.c,v 1.1 2002-10-28 08:13:37 pj Exp $ |
this is a part of the classic Hartik demo Aster. |
It checks: |
- jet functions |
- The EDF level with many task, with almost full bandwidth used |
*/ |
#include "kernel/kern.h" |
#include "modules//edf.h" |
int num_aster = 0; |
#define ASTER_LIM 60 |
#define DISPLAY_MAX 15 |
#define ASTER_MAX 70 |
#define STAT_Y 9 |
// first numbers for wcet and periods are for a 486/25, the others for a |
// celeron 366 |
#define PER_WCET 13000 /*6200*/ |
#define CLOCK_WCET 1200 /* 100*/ |
#define ASTER_WCET 1200 /* 100*/ |
#define ASTER_MEAN_PERIOD 64 /*64*/ |
#define END_TEST_TIME 60 |
TASK asteroide(void) |
{ |
int i; |
int y = rand() % 7 + 1; |
int load1,j; |
char s[2]; |
s[0] = '*'; s[1] = 0; |
/*for (;;)*/ { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 1000; //10000; // 5000 + rand()%5000; |
for (j=0; j<load1; j++) { |
s[0] = '*' + rand() % 100; |
puts_xy(i,y,rand()%15+1,s); |
} |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
num_aster--; |
return 0; |
} |
TASK aster() |
{ |
PID p; |
HARD_TASK_MODEL m; |
int r; |
int x; // adaptive bandwidth... |
hard_task_default_model(m); |
hard_task_def_wcet(m,PER_WCET); |
hard_task_def_ctrl_jet(m); |
x = ASTER_MEAN_PERIOD; |
srand(7); |
while (1) { |
if (num_aster < ASTER_MAX) { |
r = (rand() % 200); |
hard_task_def_arg(m,(void *)((rand() % 7)+1)); |
hard_task_def_mit(m, (x+r)*1000); |
p = task_create("aaa",asteroide,&m,NULL); |
if (p == -1) |
{ |
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno); |
} |
else { |
num_aster++; |
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno); |
task_activate(p); |
x /= 2; |
if (x<50) x = 50; |
} |
} |
task_endcycle(); |
} |
} |
TASK clock() |
{ |
int s = 0, m = 0; |
while(1) { |
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0)); |
task_endcycle(); |
if (++s > 59) { |
s = 0; |
m++; |
} |
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0)); |
task_endcycle(); |
} |
} |
/* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
and plot on the screen the elapsed times... */ |
TASK jetcontrol() |
{ |
int i; /* a counter */ |
TIME sum, max, curr, last[5]; |
int nact; |
int j; /* the elements set by jet_gettable */ |
PID p; |
kern_cli(); |
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
kern_sti(); |
for (;;) { |
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue; |
for (j=0; j<5; j++) last[j] = 0; |
jet_gettable(p, &last[0], 5); |
kern_cli(); |
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]); |
kern_sti(); |
i++; |
} |
} |
} |
int main(int argc, char **argv) |
{ |
PID p1,p2,p3; //,p4,p5,p6; |
HARD_TASK_MODEL m; |
NRT_TASK_MODEL m_nrt; |
struct timespec t; |
clear(); |
hard_task_default_model(m); |
hard_task_def_wcet(m,ASTER_WCET); |
hard_task_def_mit(m,10000); |
hard_task_def_group(m,1); |
hard_task_def_ctrl_jet(m); |
nrt_task_default_model(m_nrt); |
nrt_task_def_group(m_nrt,1); |
nrt_task_def_ctrl_jet(m_nrt); |
p1 = task_create("Aster",aster,&m,NULL); |
if (p1 == -1) { |
perror("test7.c(main): Could not create task <aster> ..."); |
sys_end(); |
} |
hard_task_def_mit(m,500000); |
hard_task_def_wcet(m,CLOCK_WCET); |
p2 = task_create("Clock",clock,&m,NULL); |
if (p2 == -1) { |
perror("test7.c(main): Could not create task <Clock> ..."); |
sys_end(); |
} |
p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL); |
if (p2 == -1) { |
perror("test7.c(main): Could not create task <JetControl> ..."); |
sys_end(); |
} |
group_activate(1); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < END_TEST_TIME); |
sys_end(); |
return 0; |
} |
/demos/trunk/base/aster3.c |
---|
0,0 → 1,301 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* 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 |
* |
* |
* CVS : $Id: aster3.c,v 1.1 2002-10-28 08:13:37 pj Exp $ |
Test Number 10 (A): |
this is a part of the classic Hartik demo Aster. |
it is based on aster2.c, with the use of TBS to serve a set of aperiodic |
tasks. |
There are APER_MAX tasks sleeping, and when an asteroide task finish |
the current activation, it activate also an aperiodic task chosen |
randomly (if the task chosen is already active, the task_activate do |
nothing!) |
*/ |
#include "kernel/kern.h" |
#include "modules//edf.h" |
int num_aster = 0; |
#define ASTER_LIM 60 |
#define DISPLAY_MAX 15 |
#define ASTER_MAX 70 |
#define STAT_Y 9 |
#define APER_MAX 8 |
/* first numbers runs on a pentium 133, second numbers on a celeron 366 */ |
#define PER_WCET 30000 /* 6200 */ |
#define APER_WCET 50000 /* 18400 */ |
#define CLOCK_WCET 1000 /* 200 */ |
#define ASTER_WCET 1000 /* 200 */ |
#define MIN_PERIOD 200 /* 64, in ms */ |
#define APER_REP 22000 |
PID aper_table[APER_MAX]; |
TASK asteroide(void) |
{ |
int i; |
int y = rand() % 7 + 1; |
int load1,j; |
char s[2]; |
s[0] = '*'; s[1] = 0; |
/*for (;;)*/ { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 10000; //8000 + rand()%2000; |
for (j=0; j<load1; j++) { |
s[0] = '*' + rand() % 100; |
puts_xy(i,y,rand()%15+1,s); |
} |
task_activate(aper_table[rand()%APER_MAX]); |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
num_aster--; |
return 0; |
} |
TASK aper_asteroid(void *a) |
{ |
int i; |
int y = rand() % 7 + 1; |
int load1,j; |
int c; |
char s[2]; |
c = (int)a; |
s[0] = '*'; s[1] = 0; |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = APER_REP; //8000 + rand()%2000; |
for (j=0; j<load1; j++) { |
s[0] = '*' + rand() % 100; |
puts_xy(i,y,rand()%15+1,s); |
} |
s[0] = c; |
puts_xy(i,y,rand()%15+1,s); |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK aster() |
{ |
PID p; |
HARD_TASK_MODEL m; |
int r; |
int x; // adaptive bandwidth... |
hard_task_default_model(m); |
hard_task_def_wcet(m,PER_WCET); |
hard_task_def_ctrl_jet(m); |
x = MIN_PERIOD; |
srand(7); |
while (1) { |
if (num_aster < ASTER_MAX) { |
r = (rand() % 200); |
hard_task_def_arg(m,(void *)((rand() % 7)+1)); |
hard_task_def_mit(m, (x+r)*1000); |
p = task_create("aaa",asteroide,&m,NULL); |
if (p == -1) |
{ |
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno); |
} |
else { |
num_aster++; |
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno); |
task_activate(p); |
x /= 2; |
if (x<50) x = 50; |
} |
} |
task_endcycle(); |
} |
} |
TASK clock() |
{ |
int s = 0, m = 0; |
while(1) { |
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0)); |
task_endcycle(); |
if (++s > 59) { |
s = 0; |
m++; |
} |
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0)); |
task_endcycle(); |
} |
} |
/* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
and plot on the screen the elapsed times... */ |
TASK jetcontrol() |
{ |
int i; /* a counter */ |
TIME sum, max, curr, last[5]; |
int nact; |
int j; /* the elements set by jet_gettable */ |
PID p; |
kern_cli(); |
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
kern_sti(); |
for (;;) { |
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue; |
for (j=0; j<5; j++) last[j] = 0; |
jet_gettable(p, &last[0], 5); |
kern_cli(); |
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d", |
p, (int)sum/(nact==0 ? 1 : nact), (int)max, (int)nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]); |
kern_sti(); |
i++; |
} |
task_endcycle(); |
} |
} |
int main(int argc, char **argv) |
{ |
PID p1,p2;//,p3,p4,p5,p6; |
HARD_TASK_MODEL m; |
NRT_TASK_MODEL m_nrt; |
SOFT_TASK_MODEL m_aper; |
int i; |
clear(); |
set_exchandler_grx(); |
hard_task_default_model(m); |
hard_task_def_wcet(m,ASTER_WCET); |
hard_task_def_mit(m,10000); |
hard_task_def_group(m,1); |
hard_task_def_ctrl_jet(m); |
nrt_task_default_model(m_nrt); |
nrt_task_def_group(m_nrt,1); |
nrt_task_def_ctrl_jet(m_nrt); |
p1 = task_create("Aster",aster,&m,NULL); |
if (p1 == -1) { |
perror("test7.c(main): Could not create task <aster> ..."); |
sys_end(); |
} |
hard_task_def_mit(m,500000); |
hard_task_def_wcet(m,CLOCK_WCET); |
p2 = task_create("Clock",clock,&m,NULL); |
if (p2 == -1) { |
perror("test7.c(main): Could not create task <Clock> ..."); |
sys_end(); |
} |
soft_task_default_model(m_aper); |
soft_task_def_wcet(m_aper,APER_WCET); |
soft_task_def_ctrl_jet(m_aper); |
soft_task_def_aperiodic(m_aper); |
soft_task_def_level(m_aper, 2); |
aper_table[0] = task_create("JetControl",jetcontrol,&m_aper,NULL); |
if (aper_table[0] == -1) { |
perror("test7.c(main): Could not create task <JetControl> ..."); |
sys_end(); |
} |
for (i=1; i<APER_MAX; i++) { |
soft_task_def_level(m_aper, i/4 + 2); |
soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±')); |
aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL); |
if (aper_table[i] == -1) { |
perror("test7.c(main): Could not create task <aper> ..."); |
sys_end(); |
} |
} |
group_activate(1); |
{ |
struct timespec t; |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 60); |
} |
sys_end(); |
return 0; |
} |
/demos/trunk/base/hello.c |
---|
0,0 → 1,53 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* 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 |
*/ |
/* |
CVS : $Id: hello.c,v 1.1 2002-10-28 08:13:37 pj Exp $ |
hello.c: |
This test is a simple hello world function. |
*/ |
#include "kernel/kern.h" |
int main(int argc, char **argv) |
{ |
cprintf("Hello, world!\n"); |
return 0; |
} |
/demos/trunk/base/iaster1.c |
---|
0,0 → 1,99 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: iaster1.c,v 1.1 2002-10-28 08:13:37 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2002-10-28 08:13:37 $ |
------------ |
System initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register the following levels: |
an EDF (Earliest Deadline First) level |
a RR (Round Robin) level |
a Dummy level |
It can accept these task models (into () the mandatory fields): |
HARD_TASK_MODEL (wcet+mit) at level 0 |
NRT_TASK_MODEL at level 1 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* 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/edf.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
/*+ sysyem tick in us +*/ |
#define TICK 10000 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
EDF_register_level(EDF_ENABLE_ALL); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
__call_main__(mb); |
return (void *)0; |
} |
/demos/trunk/base/iaster3.c |
---|
0,0 → 1,111 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: iaster3.c,v 1.1 2002-10-28 08:13:37 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2002-10-28 08:13:37 $ |
------------ |
System initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register the following levels: |
an EDF (Earliest Deadline First) level |
a RR (Round Robin) level |
a TBS (Total Bandwidth Server) level 0.1 Us |
a TBS (Total Bandwidth Server) level 0.3 Us |
a Dummy level |
The TBS bandwidth is TBS_NUM/TBS_DEN |
It can accept these task models (into () the mandatory fields): |
HARD_TASK_MODEL (wcet+mit) at level 0 |
NRT_TASK_MODEL at level 1 |
SOFT_TASK_MODEL (wcet, periodicity=APERIODIC) at level 2,3 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* 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/edf.h" |
#include "modules/rr.h" |
#include "modules/tbs.h" |
#include "modules/dummy.h" |
#include "drivers/keyb.h" |
/*+ sysyem tick in us +*/ |
#define TICK 1200 |
#define RRTICK 5000 |
#define TBS_NUM 1 |
#define TBS_DEN 10 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
EDF_register_level(EDF_ENABLE_ALL); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
TBS_register_level(TBS_ENABLE_ALL, 0, TBS_NUM, TBS_DEN); |
TBS_register_level(TBS_ENABLE_ALL, 0, TBS_NUM*3, TBS_DEN); |
dummy_register_level(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
__call_main__(mb); |
return (void *)0; |
} |
/demos/trunk/base/readme |
---|
0,0 → 1,25 |
This directory contains a set of simple examples, useful to understand |
How to make a Shark application. |
Text mode demos: |
- hello.c --> a hello world application |
- timer.c --> tests if the time reads are always increasing |
(useful for debugging purposes) |
- sig.c --> simple example that sends signals |
- aster1.c --> a -lot- of periodic tasks that are created and then die |
(6 seconds demo) |
- aster2.c --> a simple stress test: a lot of tasks are created until Utot=1; |
uses jet functions to dump statistics. (60 seconds demo) |
- aster3.c --> aster2 + 8 tasks handled by 2 different TBS servers |
Graphical demos: |
- fly.c --> Random flies going around the screen |
- ego.c --> Periodic tasks that writes a phrease on the screen |
- cabs.c --> Example that uses cabs |
Note on the init files: |
- ihello.c (RR+dummy) |
- iaster1.c (EDF+RR+dummy) |
- iaster3.c (EDF+RR+TBS(0.1)+TBS(0.3)+dummy) |
- initfile.c (EDF+CBS+RR+dummy, SEMaphores, CABS, HARTPORTs and Keyboard) |
/demos/trunk/base/ihello.c |
---|
0,0 → 1,95 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: ihello.c,v 1.1 2002-10-28 08:13:37 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2002-10-28 08:13:37 $ |
------------ |
The simplest initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register the following levels: |
a RR (Round Robin) level |
a Dummy level |
It can accept these task models: |
NRT_TASK_MODEL at level 0 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* 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/rr.h" |
#include "modules/dummy.h" |
/*+ sysyem tick in us +*/ |
#define TICK 300 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
__call_main__(mb); |
return (void *)0; |
} |
/demos/trunk/base/sig.c |
---|
0,0 → 1,163 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: sig.c,v 1.1 2002-10-28 08:13:37 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2002-10-28 08:13:37 $ |
------------ |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo |
* |
* 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 |
* |
*/ |
/* |
Test Number 5: |
this test is a simple main() function with one other task |
This test can be useful to test functions like: |
sys_gettime |
sigemptyset |
sigaddset |
hartik_deliver_pending_signals |
sys_end |
task_sigmask |
sigaction |
sigqueue |
task_signal |
*/ |
#include "kernel/kern.h" |
TASK goofy(void *arg) |
{ |
struct timespec t; |
cprintf("Goofy: waiting 2 secs...\n"); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 2); // wait until 2 sec |
cprintf("Goofy: ok, I'm ready :-)\n"); |
return 0; |
} |
void catchit(int signo, siginfo_t *info, void *extra) |
{ |
cprintf("Current Running Task = %d signo=%d code=%d value=%d from pid=%d\n", |
exec_shadow, |
info->si_signo, info->si_code, |
info->si_value.sival_int, info->si_task); |
} |
int main(int argc, char **argv) |
{ |
struct timespec t; |
NRT_TASK_MODEL m; |
PID p2; |
sigset_t newmask; |
sigset_t oldmask; |
struct sigaction action; |
union sigval sval; |
clear(); |
/* Set the signal action */ |
action.sa_flags = SA_SIGINFO; |
action.sa_sigaction = catchit; |
action.sa_handler = 0; |
action.sa_mask = 0; |
if (sigaction(SIGUSR1, &action, NULL) == -1) { |
perror("Error using sigaction."); |
return -1; |
} |
action.sa_flags = 0; |
action.sa_handler = catchit; |
if (sigaction(SIGILL, &action, NULL) == -1) { |
perror("Error using sigaction."); |
return -1; |
} |
/* create another task */ |
nrt_task_default_model(m); |
nrt_task_def_group(m,1); |
p2 = task_create("goofy", goofy, &m, NULL); |
if (p2 == NIL) |
{ |
cprintf("Can't create goofy task...\n"); |
return 1; |
} |
group_activate(1); |
/* block the signal for the main task */ |
sigemptyset(&newmask); |
sigaddset(&newmask,SIGUSR1); |
task_sigmask(SIG_BLOCK, &newmask, &oldmask); // pthread_sigmask |
cprintf("main: Sending 2 signals ...\n"); |
sval.sival_int = 123; |
sigqueue(0,SIGUSR1,sval); |
sval.sival_int = 999; |
sigqueue(0,SIGUSR1,sval); |
cprintf("main: Now sending a signal to myself," |
" then wait until 4 secs...\n"); |
task_signal(0 /* main */, SIGILL); // pthread_kill |
NULL_TIMESPEC(&t); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 4); // wait until 4 s |
cprintf("main: ending...\n"); |
return 0; |
} |
/demos/trunk/base/makefile |
---|
7,10 → 7,32 |
endif |
include $(BASE)/config/config.mk |
PROGS= ego fly cabs |
PROGS= ego fly cabs hello sig aster1 aster2 aster3 time |
include $(BASE)/config/example.mk |
# Text applications |
hello: |
make -f $(SUBMAKE) APP=hello INIT= OTHEROBJS="ihello.o" OTHERINCL= |
time: |
make -f $(SUBMAKE) APP=time INIT= OTHEROBJS="ihello.o" OTHERINCL= |
sig: |
make -f $(SUBMAKE) APP=sig INIT= OTHEROBJS="ihello.o" OTHERINCL= |
aster1: |
make -f $(SUBMAKE) APP=aster1 INIT= OTHEROBJS="iaster1.o" OTHERINCL= |
aster2: |
make -f $(SUBMAKE) APP=aster2 INIT= OTHEROBJS="iaster1.o" OTHERINCL= |
aster3: |
make -f $(SUBMAKE) APP=aster3 INIT= OTHEROBJS="iaster3.o" OTHERINCL= |
# Graphical applications |
ego: |
make -f $(SUBMAKE) APP=ego INIT= OTHEROBJS="initfile.o" OTHERINCL= |