Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1123 → Rev 1124

/demos/tags/rel_0_3/base/aster1.c
0,0 → 1,174
/*
* 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.2 2003-01-07 17:10:15 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_end();
return 0;
}
 
/demos/tags/rel_0_3/base/aster3.c
0,0 → 1,300
/*
* 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.3 2003-01-07 17:10:15 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",
iq_query_first(&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();
 
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/tags/rel_0_3/base/aster5.c
0,0 → 1,490
/*
* 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, Gerardo Lamastra and Giuseppe Lipari
*
* 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: aster5.c,v 1.2 2003-01-07 17:10:15 pj Exp $
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 13 (d), and use the CBS to serve the periodic tasks.
 
There are not periodic tasks, only CBS tasks.
 
The tasks use a PI, NPP or NOP mutex to access the video memory.
 
A flag (LONGSC) is provided to try long and short critical sections.
 
This demo is really interesting because you can note the behavior of
the system, and the differences between the various protocols...
 
*/
 
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "drivers/keyb.h"
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
#define PER_MAX 5
#define APER_MAX 8
 
#define PER_WCET 6200
#define APER_WCET 18400
#define JET_WCET 10000
#define JET_PERIOD 100000
 
#define APER_REP 22000
 
//PID aper_table[APER_MAX];
 
mutex_t m1;
 
 
#define PIMUTEX
//#define NPPMUTEX
//#define NOPMUTEX
 
#define LONGSC
 
#ifdef LONGSC
#define SOFT_MET 3000 /* 3000 12000 */
#define CLOCK_WCET 400 /* 200 300*/
#define ASTER_WCET 400 /* 200 300*/
#else
#define SOFT_MET 80000 /* 4500 */
#define CLOCK_WCET 2000 /* 200*/
#define ASTER_WCET 2000 /* 200*/
#endif
 
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
#ifdef LONGSC
mutex_unlock(&m1);
#endif
 
// task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
i++;
}
}
//num_aster--;
}
 
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = c;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
i++;
}
}
}
 
TASK soft_aster(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 + rand()%9000;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = 1;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
// task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
i++;
}
}
num_aster--;
return 0;
}
 
TASK aster()
{
PID p;
// HARD_TASK_MODEL m;
SOFT_TASK_MODEL m_soft;
int r;
int x; // adaptive bandwidth...
 
srand(7);
 
/* periodic_task_default_model(m,0,PER_WCET);
periodic_task_def_ctrl_jet(m);
for (x=0; x<PER_MAX; x++) {
r = (rand() % 200);
periodic_task_def_period(m, (64+r)*1000);
p = task_create("per",asteroide,&m,NULL);
if (p!=-1) task_activate(p);
}
*/
soft_task_default_model(m_soft);
soft_task_def_met(m_soft,SOFT_MET);
soft_task_def_ctrl_jet(m_soft);
 
x = 128; //64;
 
while (1) {
/* {
PID p;
int x;
p = level_table[0]->level_scheduler(0);
printf_xy(1,8,WHITE," ");
 
x = 0;
do {
printf_xy(3*x+1,8,WHITE,"%3d",p);
p = proc_table[p].next;
x++;
} while (p != NIL);
}
*/
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
soft_task_def_period(m_soft, (x+r)*1000);
p = task_create("aaa",soft_aster,&m_soft,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc),errno);
mutex_unlock(&m1);
}
else {
num_aster++;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
mutex_unlock(&m1);
 
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2));
 
mutex_unlock(&m1);
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2));
mutex_unlock(&m1);
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;
 
 
mutex_lock(&m1);
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
mutex_unlock(&m1);
 
for (;;) {
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 /*||
(proc_table[p].pclass & 0xFF00) == APERIODIC_PCLASS ||
(proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
mutex_lock(&m1);
if (proc_table[p].task_level == 2)
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³p%-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)CBS_get_nact(2,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
// p, sum/(nact==0 ? 1 : nact), max, proc_table[p].avail_time, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , CBS_get_nact(2,p), last[4]);
else
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]);
// p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)proc_table[p].status, (int)proc_table[p].shadow, (int)proc_table[p].timespec_priority.tv_sec,(int)proc_table[p].timespec_priority.tv_nsec/1000 , (int)last[3], (int)last[4]);
mutex_unlock(&m1);
i++;
}
}
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
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;
SOFT_TASK_MODEL m_soft;
// int i;
struct timespec fineprg;
 
#ifdef PIMUTEX
PI_mutexattr_t a;
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_t a;
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_t a;
#endif
 
KEY_EVT emerg;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
clear();
 
hard_task_default_model(m);
hard_task_def_wcet(m,ASTER_WCET);
hard_task_def_mit(m,100000);
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);
 
 
soft_task_default_model(m_aper);
soft_task_def_group(m_aper,1);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,JET_PERIOD);
soft_task_def_met(m_soft,JET_WCET);
soft_task_def_group(m_soft,1);
soft_task_def_ctrl_jet(m_soft);
soft_task_def_aperiodic(m_soft);
 
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
perror("test7.c(main): Could not create task <aster> ...");
sys_end();
l1_exit(-1);
}
 
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();
l1_exit(-1);
}
 
// p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
if (p2 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
/*
aperiodic_task_default_model(m_aper,APER_WCET);
aperiodic_task_def_ctrl_jet(m_aper);
aperiodic_task_def_system(m_aper);
 
for (i=0; i<APER_MAX; i++) {
aperiodic_task_def_level(m_aper, i/4 + 2);
aperiodic_task_def_arg(m_aper, (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();
l1_exit(-1);
}
}
*/
task_nopreempt();
 
#ifdef PIMUTEX
PI_mutexattr_default(a);
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_default(a);
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_default(a);
#endif
 
mutex_init(&m1, &a);
 
fineprg.tv_sec = 1800;
fineprg.tv_nsec = 0;
//kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
group_activate(1);
return 0;
}
 
/demos/tags/rel_0_3/base/aster6.c
0,0 → 1,484
/*
* 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, Gerardo Lamastra and Giuseppe Lipari
*
* 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: aster6.c,v 1.2 2003-01-07 17:10:15 pj Exp $
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 17 (h), and the JobControl Task uses an
SOFT_TASK_MODEL served by a polling server
 
*/
 
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "drivers/keyb.h"
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
#define PER_MAX 5
#define APER_MAX 8
 
#define PER_WCET 6200
#define APER_WCET 18400
#define JET_WCET 10000
 
#define APER_REP 22000
 
PID aper_table[APER_MAX];
 
mutex_t m1;
 
 
#define PIMUTEX
//#define NPPMUTEX
//#define NOPMUTEX
 
#define LONGSC
 
#ifdef LONGSC
#define SOFT_MET 3000 /* 12000 */
#define CLOCK_WCET 200 /* 300*/
#define ASTER_WCET 200 /* 300*/
#else
#define SOFT_MET 80000 /* 4500 */
#define CLOCK_WCET 2000 /* 200*/
#define ASTER_WCET 2000 /* 200*/
#endif
 
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
#ifdef LONGSC
mutex_unlock(&m1);
#endif
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
i++;
}
}
//num_aster--;
}
 
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = c;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
i++;
}
}
}
 
TASK soft_aster(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 + rand()%9000;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = 1;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
i++;
}
}
num_aster--;
return 0;
}
 
TASK aster()
{
PID p;
 
// HARD_TASK_MODEL m;
SOFT_TASK_MODEL m_soft;
int r;
int x; // adaptive bandwidth...
 
srand(7);
 
/* periodic_task_default_model(m,0,PER_WCET);
periodic_task_def_ctrl_jet(m);
for (x=0; x<PER_MAX; x++) {
r = (rand() % 200);
periodic_task_def_period(m, (64+r)*1000);
p = task_create("per",asteroide,&m,NULL);
if (p!=-1) task_activate(p);
}
*/
soft_task_default_model(m_soft);
soft_task_def_met(m_soft,SOFT_MET);
soft_task_def_ctrl_jet(m_soft);
 
x = 128; //64;
 
while (1) {
/* {
PID p;
int x;
p = level_table[0]->level_scheduler(0);
printf_xy(1,8,WHITE," ");
 
x = 0;
do {
printf_xy(3*x+1,8,WHITE,"%3d",p);
p = proc_table[p].next;
x++;
} while (p != NIL);
}
*/
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
soft_task_def_period(m_soft, (x+r)*1000);
p = task_create("aaa",soft_aster,&m_soft,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc),errno);
mutex_unlock(&m1);
}
else {
num_aster++;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
mutex_unlock(&m1);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2));
 
mutex_unlock(&m1);
 
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(0));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(2));
mutex_unlock(&m1);
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;
 
 
mutex_lock(&m1);
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
mutex_unlock(&m1);
 
for (;;) {
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 /*||
(proc_table[p].pclass & 0xFF00) == APERIODIC_PCLASS ||
(proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
mutex_lock(&m1);
if (proc_table[p].task_level == 2)
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)CBS_get_nact(2,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
// p, sum/(nact==0 ? 1 : nact), max, proc_table[p].avail_time, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , CBS_get_nact(2,p), last[4]);
else
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]);
// p, sum/(nact==0 ? 1 : nact), max, nact, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , last[3], last[4]);
mutex_unlock(&m1);
i++;
}
}
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
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;
SOFT_TASK_MODEL m_soft;
// int i;
struct timespec fineprg;
 
#ifdef PIMUTEX
PI_mutexattr_t a;
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_t a;
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_t a;
#endif
 
 
KEY_EVT emerg;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
clear();
 
hard_task_default_model(m);
hard_task_def_mit(m,100000);
hard_task_def_wcet(m,ASTER_WCET);
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);
 
 
soft_task_default_model(m_aper);
soft_task_def_group(m_aper,1);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,100000);
soft_task_def_met(m_soft,JET_WCET);
soft_task_def_group(m_soft,1);
soft_task_def_ctrl_jet(m_soft);
soft_task_def_aperiodic(m_soft);
 
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
perror("test7.c(main): Could not create task <aster> ...");
sys_end();
l1_exit(-1);
}
 
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();
l1_exit(-1);
}
 
// p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
p3 = task_create("JetControl",jetcontrol,&m_aper,NULL);
if (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
/*
aperiodic_task_default_model(m_aper,APER_WCET);
aperiodic_task_def_ctrl_jet(m_aper);
aperiodic_task_def_system(m_aper);
 
for (i=0; i<APER_MAX; i++) {
aperiodic_task_def_level(m_aper, i/4 + 2);
aperiodic_task_def_arg(m_aper, (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();
l1_exit(-1);
}
}
*/
task_nopreempt();
 
#ifdef PIMUTEX
PI_mutexattr_default(a);
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_default(a);
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_default(a);
#endif
 
mutex_init(&m1, &a);
 
fineprg.tv_sec = 1800;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
group_activate(1);
 
return 0;
}
 
/demos/tags/rel_0_3/base/aster7.c
0,0 → 1,307
/*
* 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 Giorgio Buttazzo, Paolo Gai, Massimiliano Giorgi
*
* 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: aster7.c,v 1.2 2003-01-07 17:10:15 pj Exp $
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 10(A), and test the PS with RM.
 
The JetControl is served by a dedicated Polling Server, too.
 
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"
#include "drivers/keyb.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
 
/* Pentium 133 / Celeron 366 */
#define PER_WCET 25000 /* 7800 */
#define APER_WCET 5500 /* 1400 */
#define CLOCK_WCET 500 /* 200 */
#define ASTER_WCET 500 /* 200 */
 
#define APER_REP 2200
 
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 = 200;
 
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",
iq_query_first(&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++;
}
}
}
 
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
 
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;
 
KEY_EVT emerg;
 
clear();
 
cprintf("Press Alt-x to end the demo...");
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
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_ctrl_jet(m_aper);
soft_task_def_level(m_aper, 1);
soft_task_def_group(m_aper,1);
soft_task_def_aperiodic(m_aper);
p3 = task_create("JetControl",jetcontrol,&m_aper,NULL);
if (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
}
 
soft_task_def_wcet(m_aper,APER_WCET);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
for (i=0; i<APER_MAX; i++) {
soft_task_def_level(m_aper, i/4 + 3);
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);
return 0;
}
 
/demos/tags/rel_0_3/base/aster8.c
0,0 → 1,542
/*
* 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 Giorgio Buttazzo, Paolo Gai, Massimiliano Giorgi
*
* 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: aster8.c,v 1.2 2003-01-07 17:10:15 pj Exp $
 
Test for Sporadic Server (ss):
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 17 (h), and the JobControl Task uses an
SOFT_TASK_MODEL served by a sporadic server
There are two "dummy" tasks that increment a counter and print
the value. One uses a SOFT_TASK_MODEL served by sporadic server,
the other uses a NRT_TASK_MODEL handled by RR module.
 
*/
 
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "modules/ss.h"
#include "drivers/keyb.h"
 
int num_aster = 0;
#define EDF_LEV 0
#define CBS_LEV 1
#define SS_LEV 2
 
#define ASTER_LIM 60
#define DISPLAY_MAX 8
#define ASTER_MAX 70
#define STAT_Y 9
 
#define PER_MAX 5
#define APER_MAX 8
 
#define PER_WCET 16000
#define APER_WCET 22000
#define JET_WCET 20000
 
#define APER_REP 22000
 
PID aper_table[APER_MAX];
 
mutex_t m1;
 
 
#define PIMUTEX
//#define PCMUTEX
//#define NPPMUTEX
//#define NOPMUTEX
 
#define LONGSC
 
#ifdef LONGSC
#define SOFT_MET 12000 /* 12000 */
#define CLOCK_WCET 300 /* 300*/
#define ASTER_WCET 300 /* 300*/
#else
#define SOFT_MET 5000 /* 4500 */
#define CLOCK_WCET 2000 /* 200*/
#define ASTER_WCET 2000 /* 200*/
#endif
 
PID p1,p2,p3,p4,p5;
 
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
#ifdef LONGSC
mutex_unlock(&m1);
#endif
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
i++;
}
}
//num_aster--;
}
 
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;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = c;
#ifndef LONGSC
mutex_unlock(&m1);
#endif
mutex_lock(&m1);
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
i++;
}
}
}
 
TASK soft_aster(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 + rand()%9000;
#ifdef LONGSC
mutex_lock(&m1);
#endif
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
#ifndef LONGSC
mutex_lock(&m1);
#endif
puts_xy(i,y,rand()%15+1,s);
#ifndef LONGSC
mutex_unlock(&m1);
#endif
}
s[0] = 1;
#ifndef LONGSC
mutex_lock(&m1);
#endif
//mutex_lock(&m1);
puts_xy(i,y,rand()%15+1,s);
mutex_unlock(&m1);
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
mutex_lock(&m1);
puts_xy(i,y,WHITE," ");
mutex_unlock(&m1);
i++;
}
}
num_aster--;
return 0;
}
 
TASK aster()
{
PID p;
 
// HARD_TASK_MODEL m;
SOFT_TASK_MODEL m_soft;
int r;
int x; // adaptive bandwidth...
 
srand(7);
 
/* periodic_task_default_model(m,0,PER_WCET);
periodic_task_def_ctrl_jet(m);
for (x=0; x<PER_MAX; x++) {
r = (rand() % 200);
periodic_task_def_period(m, (64+r)*1000);
p = task_create("per",asteroide,&m,NULL);
if (p!=-1) task_activate(p);
}
*/
soft_task_default_model(m_soft);
soft_task_def_met(m_soft,SOFT_MET);
soft_task_def_ctrl_jet(m_soft);
// soft_task_def_aperiodic(m_soft);
 
x = 128; //64;
 
while (1) {
/* {
PID p;
int x;
p = level_table[0]->level_scheduler(0);
printf_xy(1,8,WHITE," ");
 
x = 0;
do {
printf_xy(3*x+1,8,WHITE,"%3d",p);
p = proc_table[p].next;
x++;
} while (p != NIL);
}
*/
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
soft_task_def_period(m_soft, (x+r)*1000);
p = task_create("aaa",soft_aster,&m_soft,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc), errno);
mutex_unlock(&m1);
}
else {
num_aster++;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u ",x);
mutex_unlock(&m1);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(EDF_LEV));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(CBS_LEV));
printf_xy(62,5,WHITE,"CSss=%6d",SS_availCs(SS_LEV));
mutex_unlock(&m1);
 
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(EDF_LEV));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(CBS_LEV));
printf_xy(62,5,WHITE,"CSss=%6d",SS_availCs(SS_LEV));
mutex_unlock(&m1);
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;
 
 
mutex_lock(&m1);
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
mutex_unlock(&m1);
 
for (;;) {
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 /*||
(proc_table[p].pclass & 0xFF00) == APERIODIC_PCLASS ||
(proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
mutex_lock(&m1);
if (proc_table[p].task_level == 1)
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)CBS_get_nact(2,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
// p, sum/(nact==0 ? 1 : nact), max, proc_table[p].avail_time, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , CBS_get_nact(2,p), last[4]);
else
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]);
// p, sum/(nact==0 ? 1 : nact), max, nact, proc_table[p].status, proc_table[p].shadow, proc_table[p].timespec_priority.tv_sec,proc_table[p].timespec_priority.tv_nsec/1000 , last[3], last[4]);
mutex_unlock(&m1);
i++;
task_activate(p3);
task_endcycle();
}
}
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
void mydummyaper(void) {
int i=0;
while(1) {
mutex_lock(&m1);
printf_xy(1,24,RED,"dummyAPER pid=%d: %d",p4,i++);
mutex_unlock(&m1);
task_activate(p4);
task_endcycle();
}
}
 
void mydummynrt(void) {
int i=0;
while(1) {
mutex_lock(&m1);
printf_xy(40,24,RED,"dummyNRT pid=%d: %d",p5,i++);
mutex_unlock(&m1);
}
}
 
int main(int argc, char **argv)
{
// PID p1,p2,p5;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
SOFT_TASK_MODEL m_aper;
SOFT_TASK_MODEL m_soft;
 
#ifdef PIMUTEX
PI_mutexattr_t a;
#endif
 
#ifdef PCMUTEX
PC_mutexattr_t a;
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_t a;
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_t a;
#endif
 
 
KEY_EVT emerg;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
clear();
 
cprintf("Press Alt-x to end the demo...");
 
hard_task_default_model(m);
hard_task_def_mit(m,100000);
hard_task_def_wcet(m,ASTER_WCET);
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);
 
 
soft_task_default_model(m_aper);
soft_task_def_group(m_aper,1);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,10000);
soft_task_def_met(m_soft,JET_WCET);
soft_task_def_group(m_soft,1);
soft_task_def_ctrl_jet(m_soft);
soft_task_def_aperiodic(m_soft);
 
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
perror("test7.c(main): Could not create task <aster> ...");
sys_end();
l1_exit(-1);
}
 
hard_task_def_mit(m,50000);
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();
l1_exit(-1);
}
 
// p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
p3 = task_create("JetControl",jetcontrol,&m_aper,NULL);
if (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
 
p4 = task_create("MyDummyAper",(void *(*)(void*))mydummyaper,&m_aper,NULL);
if (p4 == -1) {
perror("Could not create task <MyDummyAper> ...");
sys_end();
l1_exit(-1);
}
 
p5 = task_create("MyDummyNRT",(void *(*)(void*))mydummynrt,&m_nrt,NULL);
if (p5 == -1) {
perror("Could not create task <MyDummyNRT> ...");
sys_end();
l1_exit(-1);
}
/*
aperiodic_task_default_model(m_aper,APER_WCET);
aperiodic_task_def_ctrl_jet(m_aper);
aperiodic_task_def_system(m_aper);
 
for (i=0; i<APER_MAX; i++) {
aperiodic_task_def_level(m_aper, i/4 + 2);
aperiodic_task_def_arg(m_aper, (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();
l1_exit(-1);
}
}
*/
// task_nopreempt();
 
 
#ifdef PIMUTEX
PI_mutexattr_default(a);
#endif
 
#ifdef PCMUTEX
PC_mutexattr_default(a);
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_default(a);
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_default(a);
#endif
 
mutex_init(&m1, &a);
 
group_activate(1);
return 0;
}
 
/demos/tags/rel_0_3/base/cabs.c
1,3 → 1,42
/*
* 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 Giorgio Buttazzo, 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: cabs.c,v 1.3 2003-01-07 17:10:15 pj Exp $
*/
 
/*--------------------------------------------------------------*/
/* TEST ON CABS */
/*--------------------------------------------------------------*/
49,32 → 88,6
 
/****************************************************************/
 
/* This is the exception handler. It is called when an exception
is raised.
It exits from the graphical mode, then it prints a message and
shutdown the kernel using sys_abort()
*/
 
void demo_exc_handler(int signo, siginfo_t *info, void *extra)
{
struct timespec t;
 
grx_close();
 
/* Default action for an kern exception is */
kern_cli();
ll_gettime(TIME_EXACT, &t),
kern_printf("\nS.Ha.R.K. Exception raised!!!"
"\nTime (s:ns) :%ld:%ld"
"\nException number:%d (numbers in include/bits/errno.h)"
"\nPID :%d\n",
t.tv_sec, t.tv_nsec, info->si_value.sival_int,
info->si_task);
sys_abort(1);
}
 
/******************************************************************/
 
/* This function is called when Alt-X is pressed.
It simply shutdown the system using sys_end.
Note that the byebye() function is called only if we exit from
109,7 → 122,7
void byebye(void *arg)
{
grx_close();
kern_printf("Bye Bye!\n");
cprintf("Bye Bye!\n");
}
 
/*--------------------------------------------------------------*/
121,23 → 134,10
 
int main(int argc, char **argv)
{
struct sigaction action;
 
char c = 0; /* character from keyboard */
 
/* Init the standard S.Ha.R.K. exception handler */
action.sa_flags = SA_SIGINFO; /* Set the signal action */
action.sa_sigaction = demo_exc_handler;
action.sa_handler = 0;
sigfillset(&action.sa_mask); /* we block all the other signals... */
 
if (sigaction(SIGHEXC, &action, NULL) == -1) { /* set the signal */
perror("Error initializing signals...");
sys_end();
}
 
/* Set the closing function */
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT|NO_AT_ABORT);
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT);
 
/* graphic card Initialization */
if (grx_init() < 1) {
145,10 → 145,9
}
if (grx_open(640, 480, 8) < 0) {
kern_printf("GRX Err\n");
cprintf("GRX Err\n");
sys_abort(1);
}
kern_printf("Video card ok!\n");
 
grx_clear(BLACK);
 
/demos/tags/rel_0_3/base/sched.c
0,0 → 1,475
/*
* 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 Giorgio Buttazzo, Paolo Gai, Massimiliano Giorgi
*
* 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: sched.c,v 1.2 2003-01-07 17:10:15 pj Exp $
 
This demo is derived from the cbsmouse.c Hartik's example.
 
It only prints the task scheduling in graphic mode...
 
There is a parameter to choose the type of scheduling module
to initialize.
 
to init correctly the module and task bandwidth parameters, set the defines
NUM and DEN in initg.c and testg.c and remember the "s" (soft) parameter!!!
 
to plot the deadlines assigned by CBS or TBS, compile cbs.c or tbs.c with
the TESTG define
(gray dots over the mouse line are the deadlines, green dots are CBS
shifts)
 
Note that a lot of times the demo exits with an exception; to avoid
these exception you have to properly tune the task parameters.
 
On a well configured machine, you will notice the little differences
between different servers when moving the mouse ;-)
 
*/
 
#include <kernel/kern.h>
#include <drivers/glib.h>
#include <drivers/keyb.h>
#include <drivers/mouse.h>
#include <semaphore.h>
 
/*--------------------------------------------------------------*/
/* TEST ON EDF SCHEDULING */
/*--------------------------------------------------------------*/
 
#define LMOUSE 20
#define LM 40 /* line of main */
#define OFFSET 20 /* initial phase */
#define CHAR_DIM 8 /* Height of chars in pixels */
 
#define DX (640/5-1)
 
int col[3] = {2, 4, 14}; /* colors of timelines */
int lev[3] = {80, 120, 160}; /* level of timelines */
int ptime[3] = {10, 20, 25}; /* number of cycles */
int period[3] = {40, 50,100}; /* tasks' periods */
int tick = 1; /* system tick */
int tscale = 1; /* time scale */
TIME starttime = 0; /* Simulation start time (scaled) */
 
char *title; /* used in initg.c */
 
/* period[] is scaled with a factor of PERIODSCALE usec */
#define PERIODSCALE 5000
 
// update also isched.c!!!
#define NUM 2000
#define DEN 64000
 
sem_t mutex; /* Semaphore for graphix*/
 
//#define IY(y) (480 - y)
#define IY(y) y
 
/*
* mouse cursor
*
*/
 
#define W WHITE
#define R RED
#define G GREEN
#define M MAGENTA
 
/* shape */
 
BYTE mycursor[16*16]= {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,W,W,W,W,0,0,0,0,0,0,W,W,W,W,0,
0,W,M,0,0,0,0,0,0,0,0,0,0,M,W,0,
0,W,0,M,0,0,0,0,0,0,0,0,M,0,W,0,
0,W,0,0,M,0,0,0,0,0,0,M,0,0,W,0,
0,0,0,0,0,M,0,0,0,0,M,0,0,0,0,0,
0,0,0,0,0,0,G,G,G,G,0,0,0,0,0,0,
0,0,0,0,0,0,G,0,0,G,0,0,0,0,0,0,
0,0,0,0,0,0,G,0,0,G,0,0,0,0,0,0,
0,0,0,0,0,0,G,0,0,G,0,0,0,0,0,0,
0,0,0,0,0,0,G,G,G,G,0,0,0,0,0,0,
0,0,0,0,0,0,M,M,M,M,0,0,0,0,0,0,
0,0,0,0,0,0,M,M,M,M,0,0,0,0,0,0,
0,0,0,0,0,M,M,M,M,M,M,0,0,0,0,0,
0,0,0,0,M,M,M,M,M,M,M,M,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
 
#define F 0xff
#define B 0x00
 
/* mask */
BYTE mybkg[16*16]= {
B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
B,0,0,0,0,B,F,F,F,F,B,0,0,0,0,B,
B,0,0,B,B,F,F,F,F,F,B,B,B,0,0,B,
B,0,B,0,B,F,F,F,F,F,F,B,0,B,0,B,
B,0,B,B,0,B,F,F,F,F,B,0,B,B,0,B,
B,B,B,F,B,0,B,B,B,B,0,B,F,B,B,B,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,B,0,0,0,0,0,0,B,F,F,F,F,
F,F,F,B,0,0,0,0,0,0,0,0,B,F,F,F,
F,F,F,B,B,B,B,B,B,B,B,B,B,F,F,F,
};
 
#undef B
#define B 0xff
 
/* bad mask */
BYTE mybadbkg[16*16]= {
B,B,B,B,B,B,F,F,F,F,B,B,B,B,B,B,
B,0,0,0,0,B,F,F,F,F,B,0,0,0,0,B,
B,0,0,B,B,F,F,F,F,F,B,B,B,0,0,B,
B,0,B,0,B,F,F,F,F,F,F,B,0,B,0,B,
B,0,B,B,0,B,F,F,F,F,B,0,B,B,0,B,
B,B,B,F,B,0,B,B,B,B,0,B,F,B,B,B,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,B,B,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,F,B,0,0,0,0,B,F,F,F,F,F,
F,F,F,F,B,0,0,0,0,0,0,B,F,F,F,F,
F,F,F,B,0,0,0,0,0,0,0,0,B,F,F,F,
F,F,F,B,B,B,B,B,B,B,B,B,B,F,F,F,
};
 
/* very bad mask */
BYTE myverybadbkg[16*16]= {
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,
};
 
/*--------------------------------------------------------------*/
/* Prints a grid to show task periods during execution */
/*--------------------------------------------------------------*/
 
void print_grid()
{
int i;
int a1, a2, a3;
int temp;
 
a1 = 0;
a2 = 0;
a3 = 0;
temp = 0;
 
grx_text(title, 0, 240-10 ,10, 0);
 
grx_line(OFFSET, lev[0], 639, lev[0], 5);
grx_line(OFFSET, lev[1], 639, lev[1], 5);
grx_line(OFFSET, lev[2], 639, lev[2], 5);
grx_text("T1", 0, lev[0]-8, 9, 0);
grx_text("T2", 0, lev[1]-8, 9, 0);
grx_text("T3", 0, lev[2]-8, 9, 0);
grx_text("MA", 0, LM, 8, 0);
grx_text("MO", 0, LMOUSE, 8, 0);
 
for (i = OFFSET; i < 640; i++) {
if (temp >= a1) {
grx_line(i, lev[0] - 1, i, lev[0] - 20, 3);
a1 += period[0];
}
if (temp >= a2) {
grx_line(i, lev[1] - 1, i, lev[1] - 20, 3);
a2 += period[1];
}
if (temp >= a3) {
grx_line(i, lev[2] - 1, i, lev[2] - 20, 3);
a3 += period[2];
}
temp += tick/tscale;
}
}
 
/*--------------------------------------------------------------*/
/* This function is called at system termination */
/*--------------------------------------------------------------*/
 
void my_end()
{
grx_close();
}
 
/*--------------------------------------------------------------*/
/* GENERIC PERIODIC PROCESS */
/*--------------------------------------------------------------*/
 
TASK color(int k)
{
int i;
DWORD x = OFFSET;
TIME t;
while ( x < 640L) {
for (i = 0; i < ptime[k]; i++) {
 
t = sys_gettime(NULL) / PERIODSCALE;
x = (t - starttime) + OFFSET;
if (x>=640) break;
sem_wait(&mutex);
grx_plot(x, lev[k] - 4, col[k]);
grx_plot(x, lev[k] - 5, col[k]);
grx_plot(x, lev[k] - 6, col[k]);
grx_plot(x, lev[k] - 7, col[k]);
sem_post(&mutex);
while (sys_gettime(NULL)/PERIODSCALE == t);
}
task_endcycle();
}
return 0;
}
 
void my_mouse_handler(MOUSE_EVT *ev)
{
int x;
 
x = (sys_gettime(NULL)/PERIODSCALE - starttime) + OFFSET;
if (x>=640) return;
sem_wait(&mutex);
grx_plot(x, LMOUSE, 8);
sem_post(&mutex);
}
 
/*--------------------------------------------------------------*/
/* MAIN PROCESS */
/*--------------------------------------------------------------*/
 
int main(int argc, char *argv[])
{
int x = OFFSET;
 
MOUSE_PARMS mouse = BASE_MOUSE;
HARD_TASK_MODEL mouse_hard;
SOFT_TASK_MODEL mouse_soft;
NRT_TASK_MODEL mouse_nrt;
 
char c;
KEY_EVT emerg;
 
HARD_TASK_MODEL m_per;
int modenum;
 
if (argc>=3)
switch(*argv[2]) {
case 'h':
/* this is not correct, because it don't remember activations */
hard_task_default_model(mouse_hard);
hard_task_def_mit(mouse_hard,DEN);
hard_task_def_wcet(mouse_hard,NUM);
hard_task_def_system(mouse_hard);
hard_task_def_nokill(mouse_hard);
hard_task_def_aperiodic(mouse_hard);
mouse_def_task(mouse,(TASK_MODEL *)&mouse_hard);
break;
case 's':
soft_task_default_model(mouse_soft);
soft_task_def_wcet(mouse_soft,NUM);
soft_task_def_met(mouse_soft,NUM);
soft_task_def_period(mouse_soft,DEN);
soft_task_def_system(mouse_soft);
soft_task_def_nokill(mouse_soft);
soft_task_def_aperiodic(mouse_soft);
mouse_def_task(mouse,(TASK_MODEL *)&mouse_soft);
break;
case 'n':
/* this is not correct, because it don't remember activations */
nrt_task_default_model(mouse_nrt);
nrt_task_def_system(mouse_nrt);
nrt_task_def_nokill(mouse_nrt);
mouse_def_task(mouse,(TASK_MODEL *)&mouse_nrt);
break;
default:
argc=0;
break;
}
 
/* Serial mous on COM3 */
mouse_def_ms(mouse,2);
 
if (argc>=4) {
period[0]=atoi(argv[3]);
if (period[0]<ptime[0]) period[0]=ptime[0]+5;
}
if (argc>=5) {
period[1]=atoi(argv[4]);
if (period[1]<ptime[1]) period[1]=ptime[1]+5;
}
if (argc>=6) {
period[2]=atoi(argv[5]);
if (period[2]<ptime[2]) period[2]=ptime[2]+5;
}
if (argc<2) {
cprintf("syntax: x testg <config> <mouse-task> [t1] [t2] [t3]\n");
cprintf("where <config> can be:\n");
cprintf("\t0 - EDF + CBS + RR\n");
cprintf("\t1 - RM + PS ( bkg, U=1/16) + RR, no check Ulub < 0.69\n");
cprintf("\t2 - RM + PS (nobkg, U=1/16) + RR, no check Ulub < 0.69\n");
cprintf("\t3 - EDF + PS ( bkg, U=1/16) + RR\n");
cprintf("\t4 - EDF + PS (nobkg, U=1/16) + RR\n");
cprintf("\t5 - EDF + TBS( U=1/16) + RR\n");
cprintf("\t6 - RM + DS ( bkg, U=1/16) + RR, no check Ulub < 0.69\n");
cprintf("\t7 - RM + DS (nobkg, U=1/16) + RR, no check Ulub < 0.69\n");
cprintf("\nwhere <mouse-task> can be:\n");
cprintf("\th - Hard\n");
cprintf("\ts - Soft (understimated wcet)\n");
cprintf("\tn - NRT\n");
sys_end();
return -1;
}
 
if (grx_init() == -1) {
cprintf("Error initing GraphLib!!!\n");
sys_end();
}
modenum = grx_getmode(640, 480, 8);
cprintf("Modenum :%d\n", modenum);
 
if (grx_setmode(modenum) == -1) {
cprintf("No SetMode!!!\n");
sys_end();
}
 
/* this trick can be useful when debugging ... */
//grx_close();
 
 
 
print_grid();
grx_box(DX*0,240,DX*1-1,479,GREEN);
grx_box(DX*1,240,DX*2-1,479,WHITE);
grx_box(DX*2,240,DX*3-1,479,RED);
grx_box(DX*3,240,DX*4-1,479,MAGENTA);
grx_box(DX*4,240,DX*5-1,479,BLACK);
 
sys_atrunlevel(my_end, NULL, RUNLEVEL_BEFORE_EXIT);
 
/* mutex */
sem_init(&mutex,0,1);
 
/* keyboard */
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,(void (*)(KEY_EVT *))sys_end);
keyb_getchar();
 
/* mouse */
mouse_init(&mouse);
mouse_limit(XMINLIMIT(640,480),
240,
XMAXLIMIT(640,480),
YMAXLIMIT(640,480));
mouse_position(320,280);
mouse_threshold(2);
//grx_setcolor(255,255,255,255);
mouse_grxshape(mycursor,mybkg);
mouse_grxcursor(ENABLE);
mouse_on();
mouse_hook(my_mouse_handler);
 
/* hard task creation */
 
hard_task_default_model(m_per);
hard_task_def_mit(m_per,period[0]*PERIODSCALE);
hard_task_def_wcet(m_per,ptime[0]*PERIODSCALE);
hard_task_def_group(m_per, 1);
//task_def_wcet(m, ptime[0] * sys_tick);
if (task_create("verde", color, &m_per, NULL) == -1) {
grx_close();
perror("Edf.C(main) Could not create <green>:");
sys_end();
}
hard_task_def_arg(m_per, (void *)1);
hard_task_def_wcet(m_per, ptime[1]*PERIODSCALE);
hard_task_def_mit(m_per,period[1]*PERIODSCALE);
if (task_create("red", color, &m_per, NULL) == -1) {
grx_close();
perror("Edf.C(main) Could not create <red>:");
sys_end();
}
hard_task_def_arg(m_per, (void *)2);
hard_task_def_wcet(m_per, ptime[2]*PERIODSCALE);
hard_task_def_mit(m_per,period[2]*PERIODSCALE);
if (task_create("yellow", color, &m_per, NULL) == -1) {
grx_close();
perror("Edf.C(main) Could not create <yellow>:");
sys_end();
}
starttime = sys_gettime(NULL) / PERIODSCALE;
group_activate(1);
 
/* main loop */
while (x < 640L) {
x = (sys_gettime(NULL)/PERIODSCALE - starttime) + OFFSET;
if (x>=640) break;
sem_wait(&mutex);
grx_plot(x, LM, 7);
sem_post(&mutex);
}
 
c = keyb_getchar();
 
sys_end();
return 0;
}
 
/*--------------------------------------------------------------*/
/demos/tags/rel_0_3/base/fly.c
18,11 → 18,11
 
/**
------------
CVS : $Id: fly.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
CVS : $Id: fly.c,v 1.3 2003-01-07 17:10:15 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:41 $
Revision: $Revision: 1.3 $
Last update: $Date: 2003-01-07 17:10:15 $
------------
**/
 
147,7 → 147,7
void byebye(void *arg)
{
grx_close();
kern_printf("Bye Bye!\n");
cprintf("Bye Bye!\n");
}
 
/****************************** MAIN ******************************/
160,9 → 160,6
int i = 0; /* number of tasks created */
TIME seme; /* used to init the random seed */
 
/* Set the exception handler */
set_exchandler_grx();
 
/* Set the closing function */
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT);
 
172,10 → 169,9
}
if (grx_open(640, 480, 8) < 0) {
kern_printf("GRX Err\n");
cprintf("GRX Err\n");
sys_abort(1);
}
kern_printf("Video card ok!\n");
 
/* The scenario */
grx_rect(XMIN-D-1, YMIN-D-1, XMAX+D+1, YMAX+D+1, 14);
/demos/tags/rel_0_3/base/pcdemo.c
0,0 → 1,214
/*
* 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: pcdemo.c,v 1.2 2003-01-07 17:10:15 pj Exp $
 
This test verify the correctness of the PC module.
 
The test uses 3 mutexes
m0 with ceiling 0
m1 with ceiling 0
m2 with ceiling 1
 
the main task (NRT) creates three tasks.
 
J0 with PC priority 0
starts at t=1.5 sec and lock m0, unlock m0, then lock and unlock m1
 
J1 with PC priority 1
starts at t=0.5 sec and try to lock m2
 
J2 with PC priority 2
it starts and locks m2
at t=1 sec it locks m1
at t=1.5 sec it unlocks m1
 
 
The example is similar to the scheduling diagram shown at p. 197 of the
book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
 
*/
 
#include "kernel/kern.h"
#include "drivers/keyb.h"
 
mutex_t m0,m1,m2;
 
 
void startJ(void *a)
{
task_activate((PID)a);
}
 
TASK j0()
{
cprintf("J0: before locking m0\n");
mutex_lock(&m0);
cprintf("J0: locked m0\n");
mutex_unlock(&m0);
cprintf("J0: unlocked m0, locking m1\n");
 
mutex_lock(&m1);
cprintf("J0: locked m1\n");
mutex_unlock(&m1);
cprintf("J0: unlocked m1, end task\n");
return 0;
}
 
 
TASK j1()
{
cprintf("J1: before locking m2\n");
mutex_lock(&m2);
cprintf("J1: locked m2\n");
mutex_unlock(&m2);
cprintf("J1: unlocked m2, end task\n");
return 0;
}
 
 
TASK j2()
{
cprintf("J2: before locking m2\n");
mutex_lock(&m2);
cprintf("J2: locked m2, waiting to t=1 sec\n");
 
while (sys_gettime(NULL) < 1000000);
 
cprintf("J2: t = 1 sec reached\n");
mutex_lock(&m1);
cprintf("J2: locked m1, waiting to t=2 sec\n");
 
while (sys_gettime(NULL) < 2000000);
 
cprintf("J2: t = 2 sec reached\n");
mutex_unlock(&m1);
cprintf("J2: unlocked m1\n");
 
mutex_unlock(&m2);
cprintf("J2: unlocked m2, end task\n");
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
 
HARD_TASK_MODEL m;
PID p0,p1,p2;
 
PC_mutexattr_t a;
PI_mutexattr_t a2;
PC_RES_MODEL r;
 
KEY_EVT emerg;
 
clear();
 
cprintf("Priority Ceiling demo. Press Alt-X to exit the demo\n");
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
hard_task_default_model(m);
hard_task_def_mit(m, 1000000);
hard_task_def_wcet(m, 20000);
PC_res_default_model(r,0);
p0 = task_create("J0", j0, &m, &r);
if (p0 == NIL)
{ cprintf("Can't create J0 task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 2100000);
hard_task_def_wcet(m, 20000);
PC_res_default_model(r,1);
p1 = task_create("J1", j1, &m, &r);
if (p1 == NIL)
{ cprintf("Can't create J1 task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 10000000);
hard_task_def_wcet(m, 3000000);
PC_res_default_model(r,2);
p2 = task_create("J2", j2, &m, &r);
if (p2 == NIL)
{ cprintf("Can't create J2 task...\n"); return 1; }
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a2);
PC_mutexattr_default(a,0);
mutex_init(&m0,(mutexattr_t *)&a);
mutex_init(&m1,(mutexattr_t *)&a);
 
PC_mutexattr_default(a,1);
mutex_init(&m2,(mutexattr_t *)&a);
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
 
kern_cli();
kern_event_post(&t,startJ,(void *)p1);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p0);
kern_sti();
 
task_activate(p2);
 
cprintf("END main\n");
 
return 0;
}
/demos/tags/rel_0_3/base/srpdemo.c
0,0 → 1,246
/*
* 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: srpdemo.c,v 1.2 2003-01-07 17:10:16 pj Exp $
 
This test verify the correctness of the SRP module.
 
There are 3 taks, Jh, Jm, Jl that uses 3 mutexes m1, m2, m3
 
the main task (NRT) creates the three tasks.
 
Jh with preemption level 3
starts at t=1.5 sec and lock m3, lock m1, unlock m1, unlock m3
 
Jm with preemption level 2
starts at t=0.5 sec and lock m3, lock m2, unlock m2, unlock m3
then lock and unlock m1
 
Jl with preemption level 1
it starts and locks m2
at t=1 sec it locks m1
at t=1.5 sec it unlocks m1
then it unlocks m2, and finally it locks and unlocks m3
 
 
The example is similar to the scheduling diagram shown at p. 210 of the
book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
 
*/
 
#include "kernel/kern.h"
#include "drivers/keyb.h"
 
#include "modules/srp.h"
 
mutex_t m1,m2,m3;
 
void startJ(void *a)
{
task_activate((PID)a);
}
 
TASK Jlobby()
{
cprintf("(*) JLobby!!!\n");
return 0;
}
 
TASK Jh()
{
PID l;
HARD_TASK_MODEL m;
SRP_RES_MODEL r;
 
cprintf("JH: creating Jy before locking m3\n");
 
hard_task_default_model(m);
hard_task_def_mit(m,30000);
hard_task_def_wcet(m,1000);
SRP_res_default_model(r,4);
l = task_create("Jlobby",Jlobby,&m,&r);
task_activate(l);
 
mutex_lock(&m3);
cprintf("JH: locked m3, locking m1\n");
mutex_lock(&m1);
cprintf("JH: locked m1, unlocking m1\n");
mutex_unlock(&m1);
cprintf("JH: unlocked m1, unlocking m3\n");
mutex_unlock(&m3);
cprintf("JH: unlocked m3, end task\n");
return 0;
}
 
 
TASK Jm()
{
cprintf("JM: before locking m3\n");
mutex_lock(&m3);
cprintf("JM: locked m3, locking m2\n");
mutex_lock(&m2);
cprintf("JM: locked m2, unlocking m2\n");
mutex_unlock(&m2);
cprintf("JM: unlocked m2, unlocking m3\n");
mutex_unlock(&m3);
cprintf("JM: unlocked m3, locking m1\n");
mutex_lock(&m1);
cprintf("JM: locked m1, unlocking m1\n");
mutex_unlock(&m1);
cprintf("JM: unlocked m1, end task\n");
return 0;
}
 
 
TASK Jl()
{
cprintf("JL: before locking m2\n");
mutex_lock(&m2);
cprintf("JL: locked m2, waiting to t=1 sec\n");
 
while (sys_gettime(NULL) < 1000000);
 
cprintf("JL: t = 1 sec reached, locking m1\n");
mutex_lock(&m1);
cprintf("JL: locked m1, waiting to t=2 sec\n");
 
while (sys_gettime(NULL) < 2000000);
 
cprintf("JL: t = 2 sec reached, unlocking m1\n");
mutex_unlock(&m1);
cprintf("JL: unlocked m1, unlocking m2\n");
 
mutex_unlock(&m2);
 
cprintf("JL: unlocked m2, locking m3\n");
mutex_lock(&m3);
cprintf("JL: locked m3, unlocking m3\n");
mutex_unlock(&m3);
cprintf("JL: unlocked m3, end task\n");
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
 
HARD_TASK_MODEL m;
PID p0,p1,p2;
 
SRP_mutexattr_t a;
SRP_RES_MODEL r;
 
PI_mutexattr_t a2;
 
KEY_EVT emerg;
 
clear();
cprintf("Stack resource Policy demo. Press Alt-X to exit the demo\n");
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a2);
SRP_mutexattr_default(a);
mutex_init(&m1,&a);
mutex_init(&m2,&a);
mutex_init(&m3,&a);
 
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
hard_task_default_model(m);
hard_task_def_mit(m, 1000000);
hard_task_def_wcet(m, 80000);
SRP_res_default_model(r, 3);
p0 = task_createn("JH", Jh, (TASK_MODEL *)&m, &r, SRP_usemutex(&m3), SRP_usemutex(&m1), NULL);
if (p0 == NIL)
{ cprintf("Can't create JH task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 2100000);
hard_task_def_wcet(m, 80000);
SRP_res_default_model(r, 2);
p1 = task_createn("JM", Jm, (TASK_MODEL *)&m, &r, SRP_usemutex(&m3), SRP_usemutex(&m1),
SRP_usemutex(&m2), NULL);
if (p1 == NIL)
{ cprintf("Can't create JM task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 10000000);
hard_task_def_wcet(m, 3000000);
SRP_res_default_model(r, 1);
p2 = task_createn("JL", Jl, (TASK_MODEL *)&m, &r, SRP_usemutex(&m3), SRP_usemutex(&m1),
SRP_usemutex(&m2), NULL);
if (p2 == NIL)
{ cprintf("Can't create JL task...\n"); return 1; }
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
 
kern_cli();
kern_event_post(&t,startJ,(void *)p1);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p0);
kern_sti();
 
task_activate(p2);
 
cprintf("END main\n");
 
return 0;
}
/demos/tags/rel_0_3/base/ego.c
18,11 → 18,11
 
/**
------------
CVS : $Id: ego.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
CVS : $Id: ego.c,v 1.3 2003-01-07 17:10:15 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:41 $
Revision: $Revision: 1.3 $
Last update: $Date: 2003-01-07 17:10:15 $
------------
**/
 
111,32 → 111,6
 
/****************************************************************/
 
/* This is the exception handler. It is called when an exception
is raised.
It exits from the graphical mode, then it prints a message and
shutdown the kernel using sys_abort()
*/
 
void demo_exc_handler(int signo, siginfo_t *info, void *extra)
{
struct timespec t;
 
grx_close();
 
/* Default action for an kern exception is */
kern_cli();
ll_gettime(TIME_EXACT, &t),
kern_printf("\nS.Ha.R.K. Exception raised!!!"
"\nTime (s:ns) :%ld:%ld"
"\nException number:%d (numbers in include/bits/errno.h)"
"\nPID :%d\n",
t.tv_sec, t.tv_nsec, info->si_value.sival_int,
info->si_task);
sys_abort(1);
}
 
/******************************************************************/
 
/* This function is called when Alt-X is pressed.
It simply shutdown the system using sys_end.
Note that the byebye() function is called only if we exit from
166,7 → 140,7
void byebye(void *arg)
{
grx_close();
kern_printf("Bye Bye!\n");
cprintf("Bye Bye!\n");
}
 
/****************************** MAIN ******************************/
176,21 → 150,9
PID pid1, pid2, pid3;
KEY_EVT emerg;
HARD_TASK_MODEL m1, m2, m3;
struct sigaction action;
 
/* Init the standard S.Ha.R.K. exception handler */
action.sa_flags = SA_SIGINFO; /* Set the signal action */
action.sa_sigaction = demo_exc_handler;
action.sa_handler = 0;
sigfillset(&action.sa_mask); /* we block all the other signals... */
 
if (sigaction(SIGHEXC, &action, NULL) == -1) { /* set the signal */
perror("Error initializing signals...");
sys_end();
}
 
/* Set the closing function */
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT|NO_AT_ABORT);
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT);
 
/* Initializes the semaphore */
sem_init(&mutex,0,1);
201,10 → 163,9
}
 
if (grx_open(640, 480, 8) < 0) {
kern_printf("GRX Err\n");
cprintf("GRX Err\n");
sys_abort(1);
}
kern_printf("Video card ok!\n");
 
/* set the keyboard handler to exit correctly */
emerg.ascii = 'x';
/demos/tags/rel_0_3/base/preempt.c
0,0 → 1,149
/*
* 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: preempt.c,v 1.2 2003-01-07 17:10:15 pj Exp $
 
CBS test with preemption disabling
 
*/
 
#include "kernel/kern.h"
 
void *periodic(void *arg)
{
int i;
int y = (int)arg;
 
for (i = 19; i < 60; i++) {
puts_xy(i,y,7,"*");
 
task_endcycle();
}
 
cprintf("Periodic: Task %d end.\n", exec_shadow);
 
return 0;
}
 
void *blocker(void *arg)
{
struct timespec t;
 
task_nopreempt();
cprintf("Blocker: Task nopreempt\n");
 
do {
sys_gettime(&t);
} while (t.tv_sec < 5);
 
cprintf("Blocker: Task preempt\n");
task_preempt();
 
cprintf("Blocker: end\n");
 
return 0;
}
 
 
 
int main(int argc, char **argv)
{
struct timespec t;
NRT_TASK_MODEL m;
SOFT_TASK_MODEL m_aper;
PID p;
 
clear();
cprintf("Preemption Test.\n");
cprintf("Start time: two periodic tasks and a blocker are created and activated.\n");
cprintf("2 seconds : blocker calls task_nopreempt.\n");
cprintf("5 seconds : task_preempt is called.\n");
cprintf(" The blocked task exec its pending activations.\n");
cprintf("10 seconds: the test stops.\n");
puts_xy(1,20,7,"save task:");
puts_xy(1,21,7,"skip task:");
 
nrt_task_default_model(m);
 
soft_task_default_model(m_aper);
soft_task_def_met(m_aper,10000);
soft_task_def_period(m_aper,200000);
soft_task_def_group(m_aper,1);
soft_task_def_arg(m_aper, (void *)20);
soft_task_def_periodic(m_aper);
 
p = task_create("save", periodic, &m_aper, NULL);
if (p == NIL)
{
perror("Can't create save task...\n");
sys_end();
}
 
soft_task_def_skip_arrivals(m_aper);
soft_task_def_arg(m_aper, (void *)21);
 
p = task_create("skip", periodic, &m_aper, NULL);
if (p == NIL)
{
perror("Can't create skip task...\n");
sys_end();
}
 
p = task_create("blocker", blocker, &m, NULL);
if (p == NIL)
{
perror("Can't create blocker task...\n");
sys_end();
}
 
cprintf("main : save & skip tasks activated.\n");
group_activate(1);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 2);
 
cprintf("main : blocker activated.\n");
task_activate(p);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 10);
 
cprintf("main : End!!!\n");
 
return 0;
}
/demos/tags/rel_0_3/base/pidemo.c
0,0 → 1,114
/*
* 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: pidemo.c,v 1.2 2003-01-07 17:10:15 pj Exp $
 
This test verify the correctness of the PI module.
 
the main task (NRT) lock a PI mutex.
then 2 tasks arrives, with priority higher than the main
 
the first try to lock the mutex, but it can't, so the main inherit
his priority. The second simply prints a string.
 
If all works, the string of the second task is printed after the end of
the first task.
 
*/
 
#include "kernel/kern.h"
 
mutex_t m1;
 
 
TASK goofy1(void *a)
{
cprintf("goofy1 before mutex_lock\n");
mutex_lock(&m1);
cprintf("goofy1 after mutex_lock\n");
 
mutex_unlock(&m1);
cprintf("goofy1 after mutex_unlock\n");
 
return 0;
}
 
TASK goofy2()
{
cprintf("goofy2 inside goofy2\n");
return 0;
}
 
int main(int argc, char **argv)
{
HARD_TASK_MODEL m;
PID p2,p3;
 
PI_mutexattr_t a;
 
hard_task_default_model(m);
hard_task_def_mit(m,50000);
hard_task_def_wcet(m,20000);
hard_task_def_group(m,1);
 
hard_task_def_arg(m,(void *)1);
p2 = task_create("goofy1", goofy1, &m, NULL);
if (p2 == NIL)
{ cprintf("Can't create goofy1 task...\n"); return 1; }
 
hard_task_def_mit(m,100000);
p3 = task_create("goofy2", goofy2, &m, NULL);
if (p3 == NIL)
{ cprintf("Can't create goofy2 task...\n"); return 1; }
 
PI_mutexattr_default(a);
mutex_init(&m1,&a);
 
cprintf("main before mutex_lock\n");
mutex_lock(&m1);
cprintf("main after mutex_lock\n");
 
group_activate(1);
 
cprintf("main after group_activate\n");
mutex_unlock(&m1);
cprintf("main after mutex_unlock\n");
 
mutex_destroy(&m1);
cprintf("main after mutex_destroy\n");
 
return 0;
}
/demos/tags/rel_0_3/base/aster.c
0,0 → 1,413
/*
* 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, Gerardo Lamastra and Giuseppe Lipari
*
* 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: aster.c,v 1.2 2003-01-07 17:10:15 pj Exp $
 
Author: Gerardo Lamastra
Giuseppe Lipari
Date: 1/10/96
 
File: Aster.C
Revision: 1.6
 
*/
 
/*
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!
An other couple of tasks, TITLE & PUT give an example of port
communication facility; the server task creates the port, the client
task connect to it and uses the server to accomplish some stuff.
Port can be declared READ/WRITE and can model ONE-TO-ONE communication
or MANY-TO-ONE communication.
Finally a second couple of tasks realizes a communiation through CABs;
each time a key is pressed, the ascii code is posted into the CAB by the
CCC task while the second task, WRITE, displays it on the screen and
perform other silly actions.
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 <string.h>
//#include <stdlib.h>
 
#include <kernel/kern.h>
#include <modules/sem.h>
#include <modules/hartport.h>
#include <modules/cabs.h>
#include <drivers/keyb.h>
#include <string.h>
 
 
#define __VPAGING__
 
#include <drivers/keyb.h>
#include <drivers/crtwin.h>
 
int num_aster = 0;
#define ASTER_LIM 67
 
CAB cc;
BYTE esc = FALSE;
 
TASK asteroide(void)
{
int i = 1;
int y = rand() % 7 + 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;
SOFT_TASK_MODEL m_soft;
int r;
WIN w;
 
win_init(&w,0,0,ASTER_LIM,8);
win_frame(&w,BLACK,WHITE,"Asteroids",2);
 
soft_task_default_model(m_soft);
soft_task_def_met(m_soft,2000);
soft_task_def_ctrl_jet(m_soft);
 
srand(7);
while (1) {
if (num_aster < 5) {
r = (rand() % 50) - 25;
soft_task_def_arg(m_soft,(void *)((rand() % 7)+1));
soft_task_def_period(m_soft,(50 + r)*1000);
p = task_create("aaa",asteroide,(TASK_MODEL *)&m_soft,NULL);
taskCreated++;
task_activate(p);
num_aster++;
}
 
task_endcycle();
}
}
 
TASK clock()
{
WIN w;
int s = 0, m = 0;
 
win_init(&w,68,0,11,2);
win_frame(&w,BLACK,WHITE,"Clk",1);
 
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();
}
}
 
TASK title()
{
PORT t;
WIN w;
int i,pos = 77;
char msg[85],tmp[85],ss[2];
BYTE c;
win_init(&w,0,9,79,2);
win_frame(&w,BLACK,WHITE,"Title",2);
 
for (i=0; i < 77; i++) msg[i] = ' ';
msg[77] = 0;
 
t = port_connect("title",1,STREAM,READ);
 
while (1) {
port_receive(t,&c,BLOCK);
ss[0] = c;
ss[1] = 0;
strcat(msg,ss);
puts_xy(1,10,WHITE,msg);
pos++;
if (pos > 77) {
strcpy(tmp,&(msg[1]));
tmp[pos-1] = 0;
pos -= 1;
strcpy(msg,tmp);
}
task_endcycle();
}
}
 
#define STR "..................... Hartik+ ....................."\
" Guarantees hard tasks "\
" Includes soft periodic tasks "\
"TB server for decrementing the aperiodic response time "\
"SRP for both hard & soft aperiodic tasks "\
"Portability toward other compilers/system "\
"Support for different C compiler: Watcom C 16 bit & 32 bit"\
" -- GNU C (32 bit) -- Borland C (16 bit) -- MS C (16 bit)"\
" "\
"Programmers : Gerardo Lamastra (lamastra@sssup2.sssup.it) "\
" Giuseppe Lipari (lipari@sssup2.sssup.it) "\
"Alpha AXP PCI-33 porting by Antonino Casile "\
"(casile@sssup1.sssup.it) "\
"Research coordinator: Giorgio Buttazzo (giorgio@sssup1.sssup.it)"\
" "\
" "\
" "
 
static char GreetMsg[1600];
 
TASK put(void)
{
PORT p;
 
strcpy(GreetMsg,STR);
p = port_create("title",strlen(GreetMsg),1,STREAM,WRITE);
while(1) {
port_send(p,GreetMsg,BLOCK);
task_endcycle();
}
}
 
TASK ccc(void)
{
WIN w;
char *m;
 
win_init(&w,68,3,10,3);
win_frame(&w,BLACK,WHITE,"CCC",2);
puts_xy(70,4,WHITE,"Cab");
 
while(1) {
m = cab_getmes(cc);
puts_xy(72,5,WHITE,m);
cab_unget(cc,m);
task_endcycle();
}
}
TASK write_keyb()
{
BYTE c;
char *msg;
 
while (1) {
c = keyb_getchar();
if (c == ESC) {
esc = TRUE;
task_endcycle();
}
else {
#ifdef __VPAGING__
if (c == 's') {
if (get_visual_page() == 0) set_visual_page(1);
else if (get_visual_page() == 1) set_visual_page(0);
}
#endif
msg = cab_reserve(cc);
msg[0] = c;
msg[1] = 0;
cab_putmes(cc,msg);
}
}
}
 
#define DELTA 200000.0
double carico(double rif,BYTE init)
{
double i;
DWORD t1 = 0,t2 = 1000;
double u;
 
i = 0.0;
do {
i += 1;
} while (i <= DELTA);
 
u = i / ((double) (t2 - t1));
 
if (init) return u;
else return (1.0 - u/rif);
}
 
void my_end(KEY_EVT *e)
{
set_active_page(0);
set_visual_page(0);
cprintf("Ctrl-Brk pressed!\n");
sys_end();
}
 
int main(int argc, char **argv)
{
PID p1,p2,p3,p4,p5,p6;
 
HARD_TASK_MODEL m_per;
SOFT_TASK_MODEL m_soft;
NRT_TASK_MODEL m_nrt;
 
KEY_EVT emerg;
// double rif;
struct timespec t;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,my_end);
 
#ifdef __VPAGING__
set_active_page(1);
set_visual_page(1);
#endif
CRSR_OFF();
clear();
puts_xy(0,20,WHITE,"Press ESC to exit demo.");
cc = cab_create("Cab",2,2);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,500000);
soft_task_def_met(m_soft,1000);
soft_task_def_group(m_soft, 1);
p1 = task_create("Aster",aster,&m_soft,NULL);
if (p1 == -1) {
perror("Aster.C(main): Could not create task <aster>");
sys_abort(-1);
}
 
hard_task_default_model(m_per);
hard_task_def_mit(m_per,500000);
hard_task_def_wcet(m_per,1000);
hard_task_def_group(m_per, 1);
p2 = task_create("Clock",clock,&m_per,NULL);
if (p2 == -1) {
perror("Aster.C(main): Could not create task <Clock>");
sys_abort(-1);
}
 
soft_task_def_period(m_soft, 50000);
p3 = task_create("Title",title,&m_soft, NULL);
if (p3 == -1) {
perror("Aster.C(main): Could not create task <Title>");
sys_abort(-1);
}
 
soft_task_def_period(m_soft, 1000000);
p4 = task_create("Put",put,&m_soft, NULL);
if (p4 == -1) {
perror("Aster.C(main): Could not create task <Put>");
sys_abort(-1);
}
 
nrt_task_default_model(m_nrt);
nrt_task_def_group(m_nrt, 1);
p5 = task_create("Write",write_keyb,&m_nrt,NULL);
if (p5 == -1) {
perror("Aster.C(main): Could not create task <Write>");
sys_abort(-1);
}
 
hard_task_def_mit(m_per, 50000);
p6 = task_create("CabTask",ccc,&m_per,NULL);
if (p6 == -1) {
perror("Aster.C(main): Could not create task <CabTask>\n");
sys_abort(-1);
}
 
/*
task_activate(p1);
task_activate(p2);
task_activate(p3);
task_activate(p4);
task_activate(p5);
task_activate(p6);
*/
group_activate(1);
 
while (!esc) {
sys_gettime(&t);
printf_xy(0,21,WHITE,"Clock : %-9ds %-9dns",(int)t.tv_sec, (int)t.tv_nsec);
}
 
group_kill(1);
clear();
CRSR_STD();
#ifdef __VPAGING__
set_active_page(0);
set_visual_page(0);
#endif
cprintf("System closed\n");
sys_end();
/*
sys_status(NORM_STATUS|BLOCKED_STATUS|SLEEP_STATUS|IDLE_STATUS);
sys_status(NORM_STATUS|SLEEP_STATUS);
*/
return 0;
}
 
/demos/tags/rel_0_3/base/sig.c
0,0 → 1,168
/*
* 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.3 2003-01-07 17:10:15 pj Exp $
 
File: $File$
Revision: $Revision: 1.3 $
Last update: $Date: 2003-01-07 17:10:15 $
------------
**/
 
/*
* 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_RT(int signo, siginfo_t *info, void *extra)
{
cprintf("RT signal: 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);
}
 
void catchit(int signo)
{
cprintf("RT signal: Current Running Task = %d signo=%d\n",
exec_shadow, signo);
}
 
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_RT;
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 = (void (*)(int))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/tags/rel_0_3/base/jointest.c
0,0 → 1,220
/*
* 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 Giorgio Buttazzo, 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: jointest.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
This test verify the correctness of the task_join primitive. (that
function is the same as pthread_join... someday I will change the
names...)
 
There are 4 taks, J1, J2, J3, are created as joinable, J4 as detached
 
The main task:
Creates J1 and J2, locks m1 (a PI mitex), creates C3.
at t=0.8 sec it calls a task_join on J3 (that returns EDEADLK),
it unlocks m1, then it makes task_join on J3 another time.
Next it creates J4 as detached and finally it does a task_join on J4
(that returns EINVAL).
 
J1:
at t=0.2 sec it calls task_join on J2, the it ends.
 
J2:
it simply waits t=0.4 sec and it ends.
 
J3:
First, it calls task_join on J1.
Then, at t=0.6 sec it locks m1, then unlocks it
 
J4:
it simply waits t=1 sec and it ends.
 
*/
 
#include "kernel/kern.h"
#include "drivers/keyb.h"
 
 
PID j0, j1, j2, j3, j4;
mutex_t m1;
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
TASK J1()
{
int err;
void *ret;
 
cprintf("J1: started, waiting 0.2 sec\n");
 
while (sys_gettime(NULL) < 200000);
 
cprintf("J1: 0.2 sec reached, joining J2\n");
 
err = task_join(j2, &ret);
 
cprintf("J1: join J2 returns %d error %d, exiting\n",
(int)ret,err);
return (void *)11;
}
 
TASK J2()
{
cprintf("J2: started, waiting 0.4 sec\n");
 
while (sys_gettime(NULL) < 400000);
 
cprintf("J2: 0.4 sec reached, exiting\n");
 
return (void *)22;
}
 
TASK J3()
{
int err;
void *ret;
 
cprintf("J3: started, joining J1\n");
 
err = task_join(j1, &ret);
 
cprintf("J3: join J1 returns %d error %d, waiting 0.6sec\n", (int)ret, err);
 
while (sys_gettime(NULL) < 600000);
 
cprintf("J1: 0.6 sec reached, locking m1\n");
 
mutex_lock(&m1);
 
cprintf("J3: locked m1, unlocking m1\n");
 
mutex_unlock(&m1);
 
cprintf("J3: unlocked m1, exiting\n");
 
return (void *)33;
}
 
TASK J4()
{
cprintf("J4: started, waiting 1 sec\n");
 
while (sys_gettime(NULL) < 1000000);
 
cprintf("J4: 1 sec reached, exiting\n");
 
return (void *)44;
}
 
int main(int argc, char **argv)
{
NRT_TASK_MODEL m;
 
PI_mutexattr_t a;
 
KEY_EVT emerg;
 
int err;
void *ret;
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
j0 = exec_shadow;
nrt_task_default_model(m);
nrt_task_def_joinable(m);
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a);
mutex_init(&m1,&a);
 
 
/* ---------------------------------------------------------------------
Let's go !!!!
--------------------------------------------------------------------- */
 
cprintf("main: creating J1,J2,J3, locking m1\n");
 
j1 = task_create("J1", J1, &m, NULL);
if (j1 == NIL) { cprintf("Can't create J1 task...\n"); return 1; }
task_activate(j1);
 
j2 = task_create("J2", J2, &m, NULL);
if (j2 == NIL) { cprintf("Can't create J2 task...\n"); return 1; }
task_activate(j2);
 
mutex_lock(&m1);
 
j3 = task_create("J3", J3, &m, NULL);
if (j3 == NIL) { cprintf("Can't create J3 task...\n"); return 1; }
task_activate(j3);
 
cprintf("main: waiting t=0.8 sec\n");
 
while (sys_gettime(NULL) < 800000);
 
err = task_join(j3, NULL);
 
cprintf("main: join J3 error %d, unlocking m1\n",err);
 
mutex_unlock(&m1);
 
err = task_join(j3, &ret);
 
cprintf("main: join J3 returns %d error %d, unlocked m1, creating J4\n",
(int)ret,err);
 
nrt_task_def_unjoinable(m);
j4 = task_create("J4", J4, &m, NULL);
if (j4 == NIL) { cprintf("Can't create J4 task...\n"); return 1; }
 
task_activate(j4);
 
err = task_join(j4,&ret);
 
cprintf("main: join J4 returns %d error %d, exiting\n", (int)ret, err);
 
return 0;
}
/demos/tags/rel_0_3/base/mdemo.c
0,0 → 1,200
/*
* 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: mdemo.c,v 1.1 2002-11-11 08:22:46 pj Exp $
 
This test verify the correctness of the NOP module. It works with the
PI, PC, SRP module, too.
 
The test uses one mutex
 
the main task (NRT) creates three tasks.
 
J1 with PC priority 0
starts at t=0.5 sec and lock m0
 
J2 with PC priority 1
starts at t=1 sec and doesn't lock any mutex
 
J3 with PC priority 2
it starts and locks m0
at t=2 sec it unlocks m1
 
 
The example is similar to the scheduling diagram shown at p. 188 of the
book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
 
*/
 
#include "kernel/kern.h"
#include "drivers/keyb.h"
#include "modules/srp.h"
 
mutex_t m0;
 
 
void startJ(void *a)
{
task_activate((PID)a);
}
 
TASK j1()
{
cprintf("J1: before locking m0\n");
mutex_lock(&m0);
cprintf("J1: locked m0\n");
mutex_unlock(&m0);
cprintf("J1: unlocked m0, end task\n");
return 0;
}
 
 
TASK j2()
{
cprintf("J2: waiting t=1.5 sec\n");
 
while (sys_gettime(NULL) < 1500000);
 
cprintf("J2: end task\n");
return 0;
}
 
 
TASK j3()
{
cprintf("J3: before locking m0\n");
mutex_lock(&m0);
cprintf("J3: locked m0, waiting to t=2 sec\n");
 
while (sys_gettime(NULL) < 2000000);
 
cprintf("J3: t = 1 sec reached, unlocking m0\n");
mutex_unlock(&m0);
cprintf("J3: unlocked m0, end task\n");
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
 
HARD_TASK_MODEL m;
PID p0,p1,p2;
 
PC_mutexattr_t a;
PI_mutexattr_t a2;
NOP_mutexattr_t a3;
SRP_mutexattr_t a4;
NPP_mutexattr_t a5;
 
PC_RES_MODEL r;
SRP_RES_MODEL srp;
 
KEY_EVT emerg;
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PC_mutexattr_default(a,0);
PI_mutexattr_default(a2);
NOP_mutexattr_default(a3);
SRP_mutexattr_default(a4);
NPP_mutexattr_default(a5);
mutex_init(&m0,&a4);
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
hard_task_default_model(m);
hard_task_def_wcet(m,20000);
hard_task_def_mit(m,10000000);
PC_res_default_model(r,0);
SRP_res_default_model(srp,3);
p0 = task_createn("J1", j1, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
if (p0 == NIL)
{ cprintf("Can't create J1 task...\n"); return 1; }
 
hard_task_def_wcet(m,1600000);
hard_task_def_mit(m,21000000);
PC_res_default_model(r,1);
SRP_res_default_model(srp,2);
p1 = task_createn("J2", j2, (TASK_MODEL *)&m, &r, &srp, NULL);
if (p1 == NIL)
{ cprintf("Can't create J2 task...\n"); return 1; }
 
hard_task_def_wcet(m,3000000);
hard_task_def_mit(m,100000000);
PC_res_default_model(r,2);
SRP_res_default_model(srp,1);
p2 = task_createn("J3", j3, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
if (p2 == NIL)
{ cprintf("Can't create J3 task...\n"); return 1; }
 
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
 
kern_cli();
kern_event_post(&t,startJ,(void *)p0);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p1);
kern_sti();
 
task_activate(p2);
 
cprintf("END main\n");
 
return 0;
}
/demos/tags/rel_0_3/base/aster4.c
0,0 → 1,399
/*
* 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: aster4.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
Test Number 13 (D):
 
this is a part of the classic Hartik demo Aster, and it is based on aster 3.
 
The demo creates:
- a set of TBS tasks assigned to 2 TBS servers initialized with different bandwidth.
 
- a set of periodic tasks, just to make noise (function asteroide)
 
- a set of CBS tasks that are created to fill the available free
bandwidth (function soft_aster)
 
- a few service task (the one that creates the CBS tasks (aster), a clock,
JET info visualization
 
- a set of never ending "system tasks" that simulate a device driver
task that will end only at shutdown (function aper_asteroid)
 
- a keyboard task that will execute an hook to terminate the system
 
*/
 
/*
* 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/cbs.h"
#include "drivers/keyb.h"
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
#define PER_MAX 5
#define APER_MAX 8
 
// These numbers works on a Pentium 133 */
#define PER_WCET 25000
#define APER_WCET 53000
#define CLOCK_WCET 1000
#define ASTER_WCET 1000
#define SOFT_MET 6300
 
#define APER_REP 22000
 
PID aper_table[APER_MAX];
 
int shutting_down = 0;
 
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--;
}
 
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);
 
if (shutting_down) {
cprintf("Ending System Task %d\n",exec_shadow);
return 0;
}
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
}
 
TASK soft_aster(void)
{
int i;
int y = rand() % 7 + 1;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
i = 1;
while (i < ASTER_LIM) {
load1 = 1000 + rand()%9000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
s[0] = 1;
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 aster()
{
PID p;
 
HARD_TASK_MODEL m;
SOFT_TASK_MODEL m_soft;
int r;
int x; // adaptive bandwidth...
 
srand(7);
 
/* create a set of periodic tasks, just to make noise */
hard_task_default_model(m);
hard_task_def_wcet(m,PER_WCET);
hard_task_def_ctrl_jet(m);
for (x=0; x<PER_MAX; x++) {
r = (rand() % 200);
hard_task_def_mit(m, (64+r)*1000);
p = task_create("per",asteroide,&m,NULL);
if (p!=-1) task_activate(p);
}
 
soft_task_default_model(m_soft);
soft_task_def_met(m_soft,SOFT_MET);
soft_task_def_ctrl_jet(m_soft);
 
x = 64;
 
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
soft_task_def_period(m_soft, (x+r)*1000);
p = task_create("aaa",soft_aster,&m_soft,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&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,"Uedf=%12u",EDF_usedbandwidth(0));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
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,"Uedf=%12u",EDF_usedbandwidth(0));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(4));
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 ||
(proc_table[p].pclass & 0xFF00) == HARD_PCLASS) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
kern_cli();
if (proc_table[p].task_level == 4)
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)CBS_get_nact(4,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
else
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++;
}
}
}
 
void endfun(KEY_EVT *k)
{
sys_end();
}
 
void exiting(void *arg)
{
cprintf("System shut down...\n");
shutting_down = 1;
}
 
int main(int argc, char **argv)
{
KEY_EVT k;
 
PID p1,p2,p3;
HARD_TASK_MODEL m;
SOFT_TASK_MODEL m_aper;
SOFT_TASK_MODEL m_soft;
int i;
 
k.flag = 0;
k.scan = KEY_ENT;
k.ascii = 13;
keyb_hook(k, endfun);
 
clear();
cprintf("Press ENTER to end the demo...");
sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN);
 
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);
 
soft_task_default_model(m_soft);
soft_task_def_met(m_soft,1000);
soft_task_def_period(m_soft,100000);
soft_task_def_group(m_soft,1);
soft_task_def_ctrl_jet(m_soft);
soft_task_def_aperiodic(m_soft);
 
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
perror("aster4.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("aster4.c(main): Could not create task <Clock> ...");
sys_end();
}
 
p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
if (p3 == -1) {
perror("aster4.c(main): Could not create task <JetControl> ...");
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_system(m_aper);
soft_task_def_aperiodic(m_aper);
 
for (i=0; 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("aster4.c(main): Could not create task <aper> ...");
sys_end();
}
}
 
group_activate(1);
return 0;
}
 
/demos/tags/rel_0_3/base/isemdemo.c
0,0 → 1,98
/*
* 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: isemdemo.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2002-11-11 08:22:45 $
------------
 
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"
#include "modules/sem.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();
 
SEM_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_0_3/base/imdemo.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
*/
 
/*
* 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: imdemo.c,v 1.1 2002-11-11 08:22:45 pj Exp $
**/
 
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "modules/rr.h"
#include "modules/dummy.h"
 
#include "modules/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
#include "modules/pi.h"
#include "modules/pc.h"
#include "modules/srp.h"
#include "modules/npp.h"
#include "modules/nop.h"
 
#include "drivers/keyb.h"
 
 
/*+ sysyem tick in us +*/
//#define TICK 1000
#define TICK 0
 
/*+ 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);
CBS_register_level(CBS_ENABLE_ALL, 0);
dummy_register_level();
 
SEM_register_module();
 
CABS_register_module();
 
PI_register_module();
PC_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
KEYB_init(NULL);
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_0_3/base/memtest.c
0,0 → 1,101
/*
* 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 Giorgio Buttazzo, 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: memtest.c,v 1.1 2002-11-11 08:22:46 pj Exp $
*/
 
/*
* 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 <stdlib.h>
 
int main(int argc, char **argv)
{
void *a;
 
clear();
 
a = malloc(4500);
cprintf("malloc : %ld\n", (DWORD)a);
free(a);
 
kern_cli(); a = DOS_alloc(4500); kern_sti();
cprintf("below 1 M: %ld\n", (DWORD)a);
kern_cli(); DOS_free(a,4500); kern_sti();
 
kern_cli(); a = kern_alloc_aligned(10000,MEMORY_UNDER_16M,10,0); kern_sti();
cprintf("below 16M: %ld\n", (DWORD)a);
kern_cli(); kern_free(a,10000); kern_sti();
 
kern_cli(); a = kern_alloc_aligned(10000,MEMORY_FROM_1M_TO_16M,2,0); kern_sti();
cprintf(">1M <16M : %ld\n", (DWORD)a);
kern_cli(); kern_free(a,10000); kern_sti();
 
kern_cli(); a = kern_alloc(10000); kern_sti();
cprintf("normal : %ld\n", (DWORD)a);
kern_cli(); kern_free(a,10000); kern_sti();
 
kern_cli(); a = kern_alloc_page(MEMORY_UNDER_1M); kern_sti();
cprintf("page <1M : %ld\n", (DWORD)a);
kern_cli(); kern_free_page(a); kern_sti();
 
kern_cli(); a = kern_alloc_page(MEMORY_FROM_1M_TO_16M); kern_sti();
cprintf("p>1<16M : %ld\n", (DWORD)a);
kern_cli(); kern_free_page(a); kern_sti();
 
kern_cli(); a = kern_alloc_page(0); kern_sti();
cprintf("page : %ld\n", (DWORD)a);
kern_cli(); kern_free_page(a); kern_sti();
 
return 0;
}
/demos/tags/rel_0_3/base/intsem.c
0,0 → 1,101
/*
* 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 Giorgio Buttazzo, 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: intsem.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
this test is a simple main() function with one other task.
 
This test verify the correctness of the internal_sem functions.
 
*/
 
#include "kernel/kern.h"
 
#include <kernel/int_sem.h>
 
internal_sem_t s;
 
TASK pippo(void *a)
{
int i=0;
struct timespec t;
 
do {
sys_gettime(&t);
 
if (i==0 && t.tv_sec == (int)a) {
i = 1;
cprintf("before internal_sem_wait %d\n",(int)a);
internal_sem_wait(&s);
cprintf("after internal_sem_wait %d\n",(int)a);
}
 
if (i==1 && t.tv_sec == 2+(int)a) {
i = 2;
cprintf("before internal_sem_post %d\n",(int)a);
internal_sem_post(&s);
cprintf("after internal_sem_post %d\n",(int)a);
return 0;
}
 
 
} while (1);
}
 
int main(int argc, char **argv)
{
NRT_TASK_MODEL m;
PID p2,p3;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
nrt_task_def_arg(m,(void *)1);
p2 = task_create("pippo1", pippo, &m, NULL);
if (p2 == NIL)
{ cprintf("Can't create pippo1 task...\n"); return 1; }
 
nrt_task_def_arg(m,(void *)2);
p3 = task_create("pippo2", pippo, &m, NULL);
if (p3 == NIL)
{ cprintf("Can't create pippo2 task...\n"); return 1; }
 
internal_sem_init(&s,1);
 
group_activate(1);
 
return 0;
}
/demos/tags/rel_0_3/base/isched.c
0,0 → 1,207
/*
* 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: isched.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2002-11-11 08:22:45 $
------------
 
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 CBS (Costant Bandwidth Server) level
a Dummy level
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
NRT_TASK_MODEL at level 1
SOFT_TASK_MODEL (met, period) at level 2
 
This file is similar to the configuration of Hartik 3.3.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/rm.h"
 
#include "modules/cbs.h"
#include "modules/tbs.h"
#include "modules/ps.h"
#include "modules/ds.h"
 
#include "modules/rr.h"
#include "modules/rr2.h"
 
#include "modules/dummy.h"
 
#include "modules/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
 
#include "drivers/keyb.h"
 
 
/*+ sysyem tick in us +*/
#define TICK 300
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
 
/* the mouse task use 160 us approx on my Celeron 366 */
#define NUM 2000
#define DEN 64000
//#define DEN 8000
 
//#undef XXX
//#define XXX
 
int argc;
char *argv[100];
 
extern char *title;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
int conf;
 
__compute_args__(mb,&argc, argv);
 
if (argc < 2)
conf = '0'; // default
else
conf = *argv[1];
 
switch (conf) {
case '1':
RM_register_level(0); // NO GUARANTEE!!!
PS_register_level(PS_ENABLE_BACKGROUND, 0, NUM, DEN);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
title = "1 - RM + PS ( bkg, U=1/16) + RR, no check Ulub < 0.69";
break;
 
case '2':
RM_register_level(0); // NO GUARANTEE!!!
PS_register_level(0, 0, NUM, DEN);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
title = "2 - RM + PS (nobkg, U=1/16) + RR, no check Ulub < 0.69\n";
break;
 
case '3':
EDF_register_level(2);
PS_register_level(PS_ENABLE_ALL_EDF, 0, NUM, DEN);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
title = "3 - EDF + PS ( bkg, U=1/16) + RR";
break;
 
case '4':
EDF_register_level(2);
PS_register_level(PS_ENABLE_GUARANTEE_EDF, 0, NUM, DEN);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
title = "4 - EDF + PS (nobkg, U=1/16) + RR";
break;
 
case '5':
EDF_register_level(2);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
TBS_register_level(TBS_ENABLE_ALL, 0, NUM, DEN);
title = "5 - EDF + TBS( U=1/16) + RR";
break;
 
case '6':
RM_register_level(0); // NO GUARANTEE!!!
DS_register_level(DS_ENABLE_BACKGROUND, 0, NUM, DEN);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
title = "6 - RM + DS ( bkg, U=1/16) + RR, no check Ulub < 0.69";
break;
 
case '7':
RM_register_level(0); // NO GUARANTEE!!!
DS_register_level(0, 0, NUM, DEN);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
title = "7 - RM + DS (nobkg, U=1/16) + RR, no check Ulub < 0.69\n";
break;
 
default: // '0'
EDF_register_level(2);
RR2_register_level(RRTICK, RR2_MAIN_YES, mb);
CBS_register_level(CBS_ENABLE_ALL, 0);
title = "0 - EDF + CBS + RR";
}
 
dummy_register_level();
 
SEM_register_module();
 
CABS_register_module();
 
return TICK;
}
 
int main(int argc, char **argv);
 
TASK __init__(void *arg)
{
// struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
KEYB_init(NULL);
 
main(argc,argv);
 
return (void *)0;
}
 
/demos/tags/rel_0_3/base/iaster4.c
0,0 → 1,133
/*
* 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: iaster4.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2002-11-11 08:22:45 $
------------
 
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 CBS (Constant Bandwidth Server) level
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
SOFT_TASK_MODEL (met,period) at level 4
 
**/
 
/*
* 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/cbs.h"
#include "modules/rrsoft.h"
#include "modules/dummy.h"
#include "drivers/keyb.h"
#include "modules/sem.h"
#include "modules/hartport.h"
 
/*+ sysyem tick in us +*/
//#define TICK 300
#define TICK 0
 
#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);
CBS_register_level(CBS_ENABLE_ALL, 0);
 
/* RRSOFT_register_level(RRTICK, RR_MAIN_NO, mb, RRSOFT_ONLY_HARD);
RR_register_level(RRTICK, RR_MAIN_NO, mb);
RRSOFT_register_level(RRTICK, RR_MAIN_NO, mb, RRSOFT_ONLY_SOFT); //cbs
RRSOFT_register_level(RRTICK, RR_MAIN_NO, mb, RRSOFT_ONLY_SOFT); //tbs
RRSOFT_register_level(RRTICK, RR_MAIN_NO, mb, RRSOFT_ONLY_SOFT); //tbs
RR_register_level(RRTICK, RR_MAIN_YES, mb);
*/
 
dummy_register_level();
 
SEM_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
KEYB_init(NULL);
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_0_3/base/iaster6.c
0,0 → 1,130
/*
* 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: iaster6.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2002-11-11 08:22:45 $
------------
 
System initialization file
 
h3pips.c
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a RR (Round Robin) level
a CBS (Costant Bandwidth Server) level
a PS (Polling Server) level
a Dummy level
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
NRT_TASK_MODEL at level 1
SOFT_TASK_MODEL (met, period) at level 2
SOFT_TASK_MODEL (periodicity=APERIODIC) at level 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/cbs.h"
#include "modules/rr.h"
#include "modules/dummy.h"
#include "modules/ps.h"
 
#include "modules/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
#include "modules/pi.h"
#include "modules/pc.h"
#include "modules/srp.h"
#include "modules/npp.h"
#include "modules/nop.h"
 
#include "drivers/keyb.h"
 
 
/*+ sysyem tick in us +*/
#define TICK 1000
 
/*+ 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);
CBS_register_level(CBS_ENABLE_ALL, 0);
PS_register_level(2 /*PS_ENABLE_ALL_EDF*/,0,500,100000);
dummy_register_level();
 
SEM_register_module();
 
CABS_register_module();
 
PI_register_module();
PC_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
KEYB_init(NULL);
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_0_3/base/iaster7.c
0,0 → 1,144
/*
* 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: iaster7.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2002-11-11 08:22:45 $
------------
 
System initialization file
 
The tick is set to TICK ms.
 
This file contains the 2 functions needed to initialize the system.
 
These functions register a set of scheduling modules, in a fixed or
dynamic priority way...
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
SOFT_TASK_MODEL (periodicity=APERIODIC) at level 1
NRT_TASK_MODEL at level 2
SOFT_TASK_MODEL (periodicity=APERIODIC, wcet (only if TBS) ) at level 3,4
 
**/
 
/*
* 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/tbs.h"
 
#include "modules/rm.h"
#include "modules/rr.h"
#include "modules/ps.h"
 
#include "modules/dummy.h"
 
#include "modules/sem.h"
#include "modules/hartport.h"
 
#include "drivers/keyb.h"
 
#include <ll/stdio.h>
 
 
/*+ sysyem tick in us +*/
#define TICK 300
 
#define RRTICK 5000
 
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
// EDF_register_level(EDF_ENABLE_ALL);
// PS_register_level(2 /*PS_ENABLE_ALL_EDF*/,0,1000,100000);
// RR_register_level(RRTICK, RR_MAIN_YES, mb);
// TBS_register_level(TBS_ENABLE_ALL, 0, 1, 10);
// PS_register_level(2,0,3000,10000);
// TBS_register_level(TBS_ENABLE_ALL, 0, 3, 10);
 
 
RM_register_level(RM_ENABLE_ALL);
PS_register_level(PS_ENABLE_ALL_RM,0,1000,100000);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
PS_register_level(4,0,10000,100000);
PS_register_level(4,0,30000,100000);
 
 
 
dummy_register_level();
 
SEM_register_module();
 
return TICK;
}
 
SOFT_TASK_MODEL m;
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
KEYB_PARMS k = BASE_KEYB;
 
soft_task_default_model(m);
soft_task_def_wcet(m,2000);
soft_task_def_met(m,800);
soft_task_def_period(m,25000);
soft_task_def_system(m);
soft_task_def_nokill(m);
soft_task_def_aperiodic(m);
soft_task_def_level(m,4);
keyb_def_task(k,&m);
 
HARTPORT_init();
 
if (KEYB_init(&k) < 0)
cprintf("Error during the init of the Keyboard!!!");
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_0_3/base/iaster8.c
0,0 → 1,128
/*
* 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: iaster8.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2002-11-11 08:22:45 $
------------
 
System initialization file
 
h3piss.c
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a CBS (Costant Bandwidth Server) level
a SS (Sporadic Server) level
a RR (Round Robin) level
a Dummy level
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
SOFT_TASK_MODEL (met, period) at level 1
SOFT_TASK_MODEL (periodicity=APERIODIC) at level 2
NRT_TASK_MODEL at level 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/rm.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "modules/rr.h"
#include "modules/dummy.h"
#include "modules/ss.h"
 
#include "modules/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
#include "modules/pi.h"
#include "modules/pc.h"
#include "modules/srp.h"
#include "modules/npp.h"
#include "modules/nop.h"
 
#include "drivers/keyb.h"
 
 
/*+ system tick in us +*/
#define TICK 1000
 
/*+ 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);
CBS_register_level(CBS_ENABLE_ALL, 0);
SS_register_level(SS_ENABLE_GUARANTEE_EDF,0,5000,20000);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
 
CABS_register_module();
 
PC_register_module();
PI_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
KEYB_init(NULL);
__call_main__(mb);
return (void *)0;
}
 
/demos/tags/rel_0_3/base/pcidemo.c
0,0 → 1,86
/*
* 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, Luca Abeni
*
* 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: pcidemo.c,v 1.1 2002-11-11 08:22:46 pj Exp $
 
This is the pcitest Hartik's example.
 
*/
 
#include "kernel/kern.h"
#include "drivers/keyb.h"
 
#include "drivers/llpci.h"
#include "drivers/pci.h"
 
void scan()
{
BYTE bus, dev;
 
/* Scan the devices connected to the PCI bus */
if (pci_init() == 1) {
clear();
pci_show();
bus = 0; dev = 0;
if (pcibios_find_device(0x8086, 0x7000, 0, &bus, &dev) == NULL)
cprintf("Not found... %d %d\n", bus, dev);
else cprintf("Found: %d \t %d\n", bus, dev);
 
if (pcibios_find_class(0x300, 0, &bus, &dev) == NULL)
cprintf("Not found... %d %d\n", bus, dev);
else cprintf("Found: %d \t %d\n", bus, dev);
} else cprintf("PCI not found!!!\n");
}
 
void endfun(KEY_EVT *k)
{
sys_end();
}
 
int main (int argc, char *argv[])
{
KEY_EVT k;
k.flag = CNTR_BIT;
k.scan = KEY_C;
k.ascii = 'c';
keyb_hook(k,endfun);
 
scan();
sys_end();
return 0;
}
/demos/tags/rel_0_3/base/condtest.c
0,0 → 1,222
/*
* 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 Giorgio Buttazzo, 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: condtest.c,v 1.1 2002-11-11 08:22:45 pj Exp $
 
This test verify the correctness of the condition variables.
(... it doesn't test all...)
 
The test uses 1 mutex
 
the main task (NRT) creates three tasks.
 
J0, J1, J3
starts, lock the mutex, and wait on a condition variable
 
J2
at t = 0.5 lock the mutex and call cond_signal
at t = 1 lock the mutex and call cond_signal
 
*/
 
#include "kernel/kern.h"
#include "drivers/keyb.h"
 
 
mutex_t m0;
cond_t c0;
 
int number = 0;
 
PID p0,p1,p2,p3;
 
TASK j0()
{
cprintf("J0: before locking m0\n");
mutex_lock(&m0);
cprintf("J0: locked m0, waiting on c0, number =%d\n", number);
while (!number) {
cond_wait(&c0,&m0);
cprintf("J0: number = %d, if >0 unlocking m0\n",number);
}
number--;
mutex_unlock(&m0);
cprintf("J0: unlocked m0, end task\n");
return 0;
}
 
 
TASK j1()
{
cprintf("J1: before locking m0\n");
mutex_lock(&m0);
cprintf("J1: locked m0, waiting on c0, number =%d\n", number);
while (!number) {
cond_wait(&c0,&m0);
cprintf("J1: number = %d, if >0 unlocking m0\n",number);
}
number--;
mutex_unlock(&m0);
cprintf("J1: unlocked m0, end task\n");
return 0;
}
 
 
TASK j2()
{
// struct timespec t;
 
cprintf("J2: started, waiting t=0.5 sec\n");
while (sys_gettime(NULL) < 500000);
 
cprintf("J2: before locking m0\n");
mutex_lock(&m0);
cprintf("J2: locked m0, number++ (was %d), cond_signal\n", number);
 
number++;
cond_signal(&c0);
// cond_broadcast(&c0);
 
cprintf("J2: unlocking m0\n");
mutex_unlock(&m0);
 
cprintf("J2: waiting t=1 sec\n");
while (sys_gettime(NULL) < 1000000);
 
cprintf("J2: Killing J3\n");
task_kill(p3);
cprintf("J2: before locking m0\n");
mutex_lock(&m0);
cprintf("J2: locked m0, number++ (was %d), cond_signal\n", number);
 
number++;
cond_signal(&c0);
// cond_broadcast(&c0);
 
cprintf("J2: unlocking m0\n");
mutex_unlock(&m0);
cprintf("J2: unlocked m0, end task\n");
return 0;
}
 
void cleanup_lock(void *arg)
{
cprintf("J3: KILL!!!\n");
mutex_unlock(&m0);
cprintf("J3: unlocked m0 by the cleanup function\n");
}
 
TASK j3()
{
cprintf("J3: before locking m0\n");
mutex_lock(&m0);
cprintf("J3: locked m0, waiting on c0, number =%d\n", number);
task_cleanup_push(cleanup_lock, (void *)&m0);
while (!number) {
cond_wait(&c0,&m0);
cprintf("J3: number = %d, if >0 unlocking m0\n",number);
}
task_cleanup_pop(0);
// I hope this task never reach this point... it is killed by J2!!!
number--;
mutex_unlock(&m0);
cprintf("J3: unlocked m0, end task\n");
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
 
int main(int argc, char **argv)
{
// struct timespec t;
 
NRT_TASK_MODEL m;
 
PI_mutexattr_t a;
 
KEY_EVT emerg;
 
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
p0 = task_create("J0", j0, &m, NULL);
if (p0 == NIL)
{ cprintf("Can't create J0 task...\n"); return 1; }
 
p1 = task_create("J1", j1, &m, NULL);
if (p1 == NIL)
{ cprintf("Can't create J1 task...\n"); return 1; }
 
p2 = task_create("J2", j2, &m, NULL);
if (p2 == NIL)
{ cprintf("Can't create J2 task...\n"); return 1; }
 
p3 = task_create("J3", j3, &m, NULL);
if (p3 == NIL)
{ cprintf("Can't create J3 task...\n"); return 1; }
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a);
mutex_init(&m0,&a);
 
cond_init(&c0);
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
group_activate(1);
 
cprintf("END main\n");
 
return 0;
}
/demos/tags/rel_0_3/base/keycode.c
0,0 → 1,80
/*
* 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 Giorgio Buttazzo, 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: keycode.c,v 1.1 2002-11-11 08:22:46 pj Exp $
*/
 
#include <kernel/kern.h>
#include <drivers/keyb.h>
 
int main(int argc, char **argv)
{
KEY_EVT k;
 
clear();
k.ascii = 0;
 
cprintf("Press ESC to end the demo, 2 for itamap, 3 for engmap\n");
while (k.ascii != ESC) {
keyb_getcode(&k,BLOCK);
if (k.ascii == '2') {
keyb_set_map(itaMap);
cprintf("\nItalian Keymap set\n");
}
if (k.ascii == '3') {
keyb_set_map(engMap);
cprintf("\nEnglish Keymap set\n");
}
if (isLeftCtrl(k)) putc_xy(72+0,0,RED,'L');
else putc_xy(72+0,0,RED,' ');
if (isRightCtrl(k)) putc_xy(72+1,0,RED,'R');
else putc_xy(72+1,0,RED,' ');
if (isLeftAlt(k)) putc_xy(72+2,0,GREEN,'L');
else putc_xy(72+2,0,RED,' ');
if (isRightAlt(k)) putc_xy(72+3,0,GREEN,'R');
else putc_xy(72+3,0,RED,' ');
if (isLeftShift(k)) putc_xy(72+4,0,YELLOW,'L');
else putc_xy(72+4,0,RED,' ');
if (isRightShift(k)) putc_xy(72+5,0,YELLOW,'R');
else putc_xy(72+5,0,RED,' ');
cprintf("%d [%c]\t",k.scan,k.ascii);
 
}
 
sys_end();
return 0;
}
/demos/tags/rel_0_3/base/mousfind.c
0,0 → 1,216
/*
* 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 Giorgio Buttazzo, 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: mousfind.c,v 1.1 2002-11-11 08:22:46 pj Exp $
*/
 
/*
* Copyright (C) 2000 Paolo Gai, Massimiliano Giorgi
*
* 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 <drivers/mouse.h>
#include <drivers/keyb.h>
 
/* don't include this into real applications!!! */
#include <../drivers/char/_mouse.h>
 
int done;
 
void my_mouse_hook(MOUSE_EVT *m)
{
static int buttons=-1;
if (buttons!=m->buttons) {
buttons=m->buttons;
//mouse_off();
if (isLeftButton(*m)) puts_xy(9,22,RED,"active");
else puts_xy(9,22,RED," ");
if (isCentralButton(*m)) puts_xy(9,23,RED,"active");
else puts_xy(9,23,RED," ");
if (isRightButton(*m)) puts_xy(9,24,RED,"active");
else puts_xy(9,24,RED," ");
//mouse_on();
}
 
 
/*
if (tindex>20&&first) {
int i;
cprintf("\nSTART\n");
for (i=0;i<tindex;i++) {
cprintf("%i\n",(int)tdata[i]);
}
for (i=1;i<tindex;i++) {
cprintf("%i ",(int)(tdata[i]-tdata[i-1]));
}
first=0;
}
*/
}
 
int main(int argc,char *argv[])
{
MOUSE_PARMS mouse=BASE_MOUSE;
int ch,running,nm;
int sens=5;
 
/* screen */
clear();
 
nm=0;
while (*vmouse[nm].name!='\0') {
cprintf("%c %s:\t %s\n",(char)('a'+nm),vmouse[nm].name,vmouse[nm].desc);
nm++;
}
 
cprintf("\n[a-%c]\t select a mouse server\n",(char)(nm+'a'-1));
cprintf("[z]\t decrement mouse threshold\n");
cprintf("[x]\t incremnet mouse threshold\n");
cprintf("[1-4]\t COM port\n");
cprintf("[ENTER]\t exit\n");
place(0,20);
cputs("mouse server:\n");
cputs("threshold:\n");
cputs("left :\n");
cputs("central:\n");
cputs("right :");
CRSR_OFF();
 
/* main loop */
running=done=0;
 
mouse_def_ms(mouse,0);
 
while (!done) {
ch=keyb_getch(TRUE);
switch(ch) {
 
/* exit demo */
 
case ENTER:
done = 1;
break;
/* decrement threshold */
 
case 'z':
sens--;
if (sens<2) sens=2;
mouse_threshold(sens);
/* threshold */
place(11,21);
cprintf("%i ",sens);
break;
 
/* increment threshold */
case 'x':
sens++;
if (sens>100) sens=100;
mouse_threshold(sens);
/* threshold */
place(11,21);
cprintf("%i ",sens);
break;
 
/* change mouse protocol */
default:
if (ch>='a'&&ch<='a'+nm-1) {
/* don't use this method to change a mouse protocol */
/* use mouse_def_???? macros instead */
mouse.type=ch-'a';
} else
if (ch>='1'&&ch<='4') {
/* don't use this method to change a mouse com port */
/* use mouse_def_???? macros instead */
mouse.port = ch-'1';
}
else
break;
 
/* check if a mouse server is running... */
if (running) {
/* disable autocursor */
mouse_txtcursor(DISABLE);
/* destroy actual mouse server */
mouse_end();
}
/* mouse server name */
puts_xy(14,20,GREEN," ");
puts_xy(14,20,GREEN,vmouse[mouse.type].name);
/* threshold */
place(11,21);
cprintf("%i ",sens);
/* start a new server */
running=(mouse_init(&mouse)==0?1:0);
/* if running ...*/
if (running) {
/* set mouse limit */
mouse_limit(0,0,cons_columns-1,cons_rows-1);
/* enable autocursor */
mouse_txtcursor(ENABLE|AUTOOFF);
/* hook my function */
mouse_hook(my_mouse_hook);
/* show mouse cursor */
mouse_on();
}
break;
}
}
 
CRSR_STD();
clear();
sys_end();
return 0;
}
/demos/tags/rel_0_3/base/semdemo.c
0,0 → 1,97
/*
* 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: semdemo.c,v 1.1 2002-11-11 08:22:46 pj Exp $
 
This is a really simple semaphore demo.
 
*/
 
#include "kernel/kern.h"
 
#include "semaphore.h"
 
sem_t s;
 
void *goofy(void *a)
{
struct timespec t;
char *n = proc_table[exec_shadow].name;
 
cprintf("Task %s: Locking semaphore...\n", n);
 
sem_wait(&s);
cprintf("Task %s: Semaphore locked...\n", n);
 
do {
sys_gettime(&t);
} while (t.tv_sec < (int)a);
 
cprintf("Task %s: Unlocking semaphore...\n", n);
 
sem_post(&s);
 
cprintf("Task %s: Semaphore unlocked...\n", n);
 
return 0;
}
 
int main(int argc, char **argv)
{
NRT_TASK_MODEL m;
PID p2,p3;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
nrt_task_def_arg(m,(void *)1);
p2 = task_create("goofy1", goofy, &m, NULL);
if (p2 == NIL)
{ cprintf("Can't create goofy1 task...\n"); return 1; }
 
nrt_task_def_arg(m,(void *)2);
p3 = task_create("goofy2", goofy, &m, NULL);
if (p3 == NIL)
{ cprintf("Can't create goofy2 task...\n"); return 1; }
cprintf("Initializing semaphore...\n");
 
sem_init(&s,0,1);
 
group_activate(1);
 
return 0;
}
/demos/tags/rel_0_3/base/talk.c
0,0 → 1,209
/*
* 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 Luca Abeni, 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 the talkdx.c Hartik's example.
 
File: Talk.C
Revision: 1.00
Author: Luca Abeni
 
 
Simple Netlib demo: nothing of seriously real-time, only another Unix
Talk clone.
Read it to see how the UDP/IP layers of the networ library work.
 
*/
 
#include <kernel/kern.h>
#include <string.h>
 
#include <drivers/crtwin.h>
#include <drivers/keyb.h>
 
#include <drivers/udpip.h>
 
 
WIN dbg;
BYTE esc = FALSE;
 
char talk_myipaddr[20];
char talk_toipaddr[20];
 
/*
This non real-time task reads UDP packets from the network and writes
them in a window
*/
TASK scrittore(void)
{
char str[2000];
UDP_ADDR from, local;
WIN displ;
int s,n;
 
/* Connect on the local port #100 */
local.s_port = 100;
s = udp_bind(&local, NULL);
 
/* Open the window */
win_init(&displ,0,0,79,6);
win_frame(&displ,BLACK,WHITE,"Remote",2);
 
while (1) {
/* Clear the buffer for receiving the packet...*/
memset(str, 0, 1999);
/*...and receive the packet (block until a packet arrives */
n = udp_recvfrom(s, str, &from);
win_puts(&displ, str);
}
}
 
/*
This non real-time task reads strings from the keyoard and sends them
to the remote host
*/
TASK write(void)
{
WIN wr;
UDP_ADDR to,local;
char str[80];
int s;
IP_ADDR bindlist[5];
 
/* Create a socket for transitting */
ip_str2addr(talk_myipaddr,&(local.s_addr));
local.s_port = 101;
 
/*
If we want the address of the remote host in the ARP table before
begginning the transmission (to eliminate a possible source of
unpredictability), we can use the bindlist, otherwise we set the
second parameter of udp_bind to NULL
*/
ip_str2addr(talk_toipaddr,&(bindlist[0]));
memset(&(bindlist[1]), 0, sizeof(IP_ADDR));
s = udp_bind(&local, /*bindlist*/NULL);
 
win_init(&wr,0,7,79,6);
win_frame(&wr,BLACK,WHITE,"Local",2);
ip_str2addr(talk_toipaddr,&(to.s_addr));
to.s_port = 100;
sprintf(str,"Local IP address %d.%d.%d.%d\n", local.s_addr.ad[0],
local.s_addr.ad[1], local.s_addr.ad[2],
local.s_addr.ad[3]);
win_puts(&dbg,str);
sprintf(str,"Talk to %d.%d.%d.%d ",to.s_addr.ad[0],to.s_addr.ad[1],
to.s_addr.ad[2],to.s_addr.ad[3]);
win_puts(&dbg,str);
while (1) {
/* Get the string...*/
win_gets(&wr,str,78);
strcat(str,"\n");
/*...and send it!!! */
udp_sendto(s,str,strlen(str)+2,&to);
}
}
 
/* This function is called when the user presses CTRL-C (stops the systems) */
void esci(KEY_EVT *k)
{
esc = TRUE;
cprintf("Ctrl-Brk pressed!\n");
sys_end();
}
 
int main(int argc, char **argv)
{
KEY_EVT k;
 
struct net_model m = net_base;
 
NRT_TASK_MODEL m_nrt;
 
k.flag = CNTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
keyb_hook(k,esci);
k.flag = CNTR_BIT;
k.scan = KEY_C;
k.ascii = 'c';
keyb_hook(k,esci);
 
clear();
cprintf(" Hartik Talk! Ver. 1.00\n");
 
if (argc != 3) {
cprintf("Hartik Talk usage: talk fromIP toIP\n");
return 0;
}
 
strcpy(talk_myipaddr, argv[1]);
strcpy(talk_toipaddr, argv[2]);
 
/* We want a task for TX mutual exclusion */
net_setmode(m, TXTASK);
/* We use UDP/IP stack */
net_setudpip(m, talk_myipaddr);
/* OK: let's start the NetLib! */
if (net_init(&m) == 1) {
cprintf("Net Init OK...\n");
} else {
cprintf("Net Init Failed...\n");
sys_abort(300);
}
 
 
//dump_irq();
cprintf("\n\n\n\tPress ENTER\n");
while (!esc) {
keyb_getcode(&k,BLOCK);
if (k.ascii == 13) esc = TRUE;
}
 
esc = FALSE;
clear();
win_init(&dbg,0,20,60,3);
win_frame(&dbg,BLACK,WHITE,"Debug",2);
/* Start the sender and receiver tasks...*/
nrt_task_default_model(m_nrt);
task_activate(task_create("aaa",scrittore,&m_nrt,NULL));
task_activate(task_create("bbb",write,&m_nrt,NULL));
return 0;
}
/demos/tags/rel_0_3/base/aster2.c
0,0 → 1,241
/*
* 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.2 2002-11-11 08:20:44 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",
iq_query_first(&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/tags/rel_0_3/base/readme
0,0 → 1,50
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
- semdemo.c --> simple example that uses a semaphore for mutual exclusion
- pidemo.c --> simple example that uses PI mutexes between NRT and Hard tasks
- pcdemo.c --> simple example that uses PC mutexes between NRT and Hard tasks
- srpdemo.c --> simple example that uses SRP mutexes between NRT and Hard tasks
- mdemo.c --> simple example that uses a mutex, initialized with whatever
protocol you want ;-)
- aster.c --> Wow! the original Hartik ASTER demo!!! (EDF, CABs, ...)
- 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
- aster4.c --> aster3 + CBS tasks + Shutdown demo with system tasks
- aster5.c --> aster3 + only CBS tasks + mutexes... Really interesting!
- aster6.c --> aster5 + Polling Server to serve the JetCtrl task
- aster7.c --> another aster clone with Rate monotonic and Polling server
- aster8.c --> aster5 + Sporadic Server
- preempt.c --> simple test for CBS, task_preempt, task_nopreempt, and
save/skip arrivals
- pcidemo.c --> PCI Bus scan
- talk.c --> UDP Unix Talk clone (useful to understand the network driver)
- mousfind.c--> Simple text mouse protocol finder
- jointest.c--> Simple test that uses the task_join primitive
- condtest.c--> Simple test that uses condition variables
- intsem.c --> Simple test that uses internal semaphores
- keycode.c --> Prints Keyboard Keycodes on the screen
- memtest.c --> Do you need to use malloc, kern_alloc & co?
 
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
- sched.c --> Scheduling example (mouse, EDF, RM, DS, PS, TBS)
 
Note on the init files:
- ihello.c (RR+dummy)
- isemdemo.c (iaster1+Semaphores)
- iaster1.c (EDF+RR+dummy)
- iaster3.c (EDF+RR+TBS(0.1)+TBS(0.3)+dummy)
- iaster4.c (iaster3+CBS)
- initfile.c (EDF+CBS+RR+dummy, SEMaphores, CABS, HARTPORTs and Keyboard)
- isched.c (Configurable scheduling architecture)
/demos/tags/rel_0_3/base/makefile
7,10 → 7,96
endif
include $(BASE)/config/config.mk
 
PROGS= ego fly cabs
PROGS = hello sig time preempt
PROGS += aster aster1 aster2 aster3 aster4 aster5 aster6 aster7 aster8
PROGS += pcidemo talk mousfind keycode memtest
PROGS += jointest condtest intsem semdemo pidemo pcdemo srpdemo mdemo
PROGS += ego fly cabs sched
 
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=
 
preempt:
make -f $(SUBMAKE) APP=preempt INIT= OTHEROBJS="initfile.o" OTHERINCL=
 
semdemo:
make -f $(SUBMAKE) APP=semdemo INIT= OTHEROBJS="isemdemo.o" OTHERINCL=
 
pidemo:
make -f $(SUBMAKE) APP=pidemo INIT= OTHEROBJS="imdemo.o" OTHERINCL=
 
pcdemo:
make -f $(SUBMAKE) APP=pcdemo INIT= OTHEROBJS="imdemo.o" OTHERINCL=
 
srpdemo:
make -f $(SUBMAKE) APP=srpdemo INIT= OTHEROBJS="imdemo.o" OTHERINCL=
 
mdemo:
make -f $(SUBMAKE) APP=mdemo INIT= OTHEROBJS="imdemo.o" OTHERINCL=
 
aster:
make -f $(SUBMAKE) APP=aster INIT= OTHEROBJS="initfile.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=
 
aster4:
make -f $(SUBMAKE) APP=aster4 INIT= OTHEROBJS="iaster4.o" OTHERINCL=
 
aster5:
make -f $(SUBMAKE) APP=aster5 INIT= OTHEROBJS="imdemo.o" OTHERINCL=
 
aster6:
make -f $(SUBMAKE) APP=aster6 INIT= OTHEROBJS="iaster6.o" OTHERINCL=
 
aster7:
make -f $(SUBMAKE) APP=aster7 INIT= OTHEROBJS="iaster7.o" OTHERINCL=
 
aster8:
make -f $(SUBMAKE) APP=aster8 INIT= OTHEROBJS="iaster8.o" OTHERINCL=
 
pcidemo:
make -f $(SUBMAKE) APP=pcidemo INIT= OTHEROBJS="initfile.o" OTHERINCL=
 
talk:
make -f $(SUBMAKE) APP=talk INIT= OTHEROBJS="initfile.o" OTHERINCL=
 
mousfind:
make -f $(SUBMAKE) APP=mousfind INIT= OTHEROBJS="initfile.o" OTHERINCL=
 
jointest:
make -f $(SUBMAKE) APP=jointest INIT= OTHEROBJS="imdemo.o" OTHERINCL=
 
condtest:
make -f $(SUBMAKE) APP=condtest INIT= OTHEROBJS="imdemo.o" OTHERINCL=
 
intsem:
make -f $(SUBMAKE) APP=intsem INIT= OTHEROBJS="imdemo.o" OTHERINCL=
 
keycode:
make -f $(SUBMAKE) APP=keycode INIT= OTHEROBJS="initfile.o" OTHERINCL=
 
memtest:
make -f $(SUBMAKE) APP=memtest INIT= OTHEROBJS="initfile.o" OTHERINCL=
 
# Graphical applications
 
ego:
make -f $(SUBMAKE) APP=ego INIT= OTHEROBJS="initfile.o" OTHERINCL=
 
20,3 → 106,5
cabs:
make -f $(SUBMAKE) APP=cabs INIT= OTHEROBJS="initfile.o" OTHERINCL=
 
sched:
make -f $(SUBMAKE) APP=sched INIT= OTHEROBJS="isched.o" OTHERINCL=
/demos/tags/rel_0_3/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/tags/rel_0_3/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/tags/rel_0_3/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/tags/rel_0_3/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/tags/rel_0_3/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;
}