Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1104 → Rev 1103

/demos/trunk/oldexamples/makefile
File deleted
/demos/trunk/oldexamples/kernel/makefile
0,0 → 1,73
#
#
#
 
ifndef BASE
BASE=../../..
endif
include $(BASE)/config/config.mk
 
PROGS= testc testd teste testf testg
PROGS+= testh testi testj testk testl testm testn testo testp
PROGS+= testq testr tests testu testw testz testss
PROGS+= ptest1 ptest2 ptest3 ptest4 ptest5 ptest6 sysend
PROGS+= perf1 perf2 perf3 perf4
 
include $(BASE)/config/example.mk
 
testc:
make -f $(SUBMAKE) BASE=$(BASE) APP=testc INIT=init4.o OTHEROBJS=
testd:
make -f $(SUBMAKE) BASE=$(BASE) APP=testd INIT=init5.o OTHEROBJS=
teste:
make -f $(SUBMAKE) BASE=$(BASE) APP=teste INIT=init6.o OTHEROBJS=
testf:
make -f $(SUBMAKE) BASE=$(BASE) APP=testf INIT=h3pi.o OTHEROBJS=
testg:
make -f $(SUBMAKE) BASE=$(BASE) APP=testg INIT=initg.o OTHEROBJS=
testh:
make -f $(SUBMAKE) BASE=$(BASE) APP=testh INIT=h3pi.o OTHEROBJS=
testi:
make -f $(SUBMAKE) BASE=$(BASE) APP=testi INIT=h3pi.o OTHEROBJS=
testj:
make -f $(SUBMAKE) BASE=$(BASE) APP=testj INIT=h3pi.o OTHEROBJS=
testk:
make -f $(SUBMAKE) BASE=$(BASE) APP=testk INIT=h3pi.o OTHEROBJS=
testl:
make -f $(SUBMAKE) BASE=$(BASE) APP=testl INIT=h3pips.o OTHEROBJS=
testm:
make -f $(SUBMAKE) BASE=$(BASE) APP=testm INIT=rm1.o OTHEROBJS=
testn:
make -f $(SUBMAKE) BASE=$(BASE) APP=testn INIT=hartik3.o OTHEROBJS=
testo:
make -f $(SUBMAKE) BASE=$(BASE) APP=testo INIT=hartik3.o OTHEROBJS=
testp:
make -f $(SUBMAKE) BASE=$(BASE) APP=testp INIT=hartik3.o OTHEROBJS=
testq:
make -f $(SUBMAKE) BASE=$(BASE) APP=testq INIT=h3pips.o OTHEROBJS=
testr:
make -f $(SUBMAKE) BASE=$(BASE) APP=testr INIT=h3pips.o OTHEROBJS=
tests:
make -f $(SUBMAKE) BASE=$(BASE) APP=tests INIT=hartik3.o OTHEROBJS=
testu:
make -f $(SUBMAKE) BASE=$(BASE) APP=testu INIT=h3pips.o OTHEROBJS=
testw:
make -f $(SUBMAKE) BASE=$(BASE) APP=testw INIT=pinit.o OTHEROBJS=
testz:
make -f $(SUBMAKE) BASE=$(BASE) APP=testz INIT=hartik3.o OTHEROBJS=
testss:
make -f $(SUBMAKE) BASE=$(BASE) APP=testss INIT=h3piss.o OTHEROBJS=
 
 
sysend:
make -f $(SUBMAKE) BASE=$(BASE) APP=sysend INIT=init1.o OTHEROBJS=
 
perf1:
make -f $(SUBMAKE) BASE=$(BASE) APP=perf1 INIT= OTHEROBJS=
perf2:
make -f $(SUBMAKE) BASE=$(BASE) APP=perf2 INIT=init5.o OTHEROBJS=
perf3:
make -f $(SUBMAKE) BASE=$(BASE) APP=perf3 INIT=init5.o OTHEROBJS=
perf4:
make -f $(SUBMAKE) BASE=$(BASE) APP=perf4 INIT= OTHEROBJS=
 
/demos/trunk/oldexamples/kernel/perf1.c
0,0 → 1,186
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: perf1.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Performance test 1:
 
there is one RR task that is preempted N_EDF times by an EDF task.
 
the test prints the differences of the execution time.
 
the test have to be compiled with the one shot timer, and it does not
use any init file.
 
**/
 
/*
* 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"
 
#define TIMESPEC_N 100
#define RR_N 1000000000
#define EDF_N 2500
 
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(1000*1000*1000, RR_MAIN_NO, mb);
RR_register_level(10000, RR_MAIN_YES, mb);
dummy_register_level();
 
return 300;
}
 
void *crash_RR(void *arg);
void *crash_EDF(void *arg);
 
void *__init__(void *arg)
{
int i;
 
PID p1,p2;
 
HARD_TASK_MODEL m_hard;
NRT_TASK_MODEL m_nrt;
 
TIME t[TIMESPEC_N];
 
// JET data
TIME sum, max, curr;
int nact;
 
 
 
hard_task_default_model(m_hard);
hard_task_def_mit (m_hard,2000);
hard_task_def_wcet (m_hard,1000);
hard_task_def_group (m_hard,1);
hard_task_def_ctrl_jet (m_hard);
 
nrt_task_default_model (m_nrt);
nrt_task_def_group (m_nrt,1);
nrt_task_def_ctrl_jet (m_nrt);
 
p1 = task_create("crash_EDF",crash_EDF,&m_hard,NULL);
if (p1 == -1) {
perror("Could not create task <crask_EDF> ...");
sys_end();
}
 
p2 = task_create("crash_RR",crash_RR,&m_nrt,NULL);
if (p2 == -1) {
perror("Could not create task <crask_RR> ...");
sys_end();
}
 
kern_cli();
/* timespec read time */
for (i=0; i<TIMESPEC_N; i++) {
t[i] = ll_gettime(TIME_EXACT, NULL);
}
kern_sti();
 
kern_printf("\n");
for (i=0; i<TIMESPEC_N; i++) {
kern_printf("%d: %ld Û", i, t[i]);
}
kern_printf("\n");
 
task_activate(p2);
 
jet_getstat(p2, &sum, &max, &nact, &curr);
kern_printf("RR test (alone): sum=%ld, max=%ld, nact=%d, curr=%ld\n",
sum, max, nact, curr);
jet_delstat(p2);
 
group_activate(1);
 
jet_getstat(p2, &sum, &max, &nact, &curr);
kern_printf("\nRR test : sum=%ld, max=%ld, nact=%d, curr=%ld\n",
sum, max, nact, curr);
jet_getstat(p1, &sum, &max, &nact, &curr);
kern_printf("EDF test : sum=%ld, max=%ld, nact=%d, curr=%ld\n",
sum, max, nact, curr);
 
sys_end();
 
return 0;
}
 
void *crash_RR(void *arg)
{
int i;
 
for (;;) {
for (i=0; i<RR_N; i++);
task_sleep();
}
return 0;
}
 
void *crash_EDF(void *arg)
{
int i;
 
for (;;) {
for (i=0; i<EDF_N; i++)
task_endcycle();
task_sleep();
}
return 0;
}
 
// not used!!!
int main(int argc, char **argv)
{
return 0;
}
 
 
 
 
/demos/trunk/oldexamples/kernel/perf2.c
0,0 → 1,401
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: perf2.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Performance Test 2:
 
This test tries to measure the time spent into the event handlers.
It is based on test D.
 
WARNING: the symbol __PERF_TEST2__ must be defined into the file
kernel/config.h
 
 
**/
 
/*
* 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"
 
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 8200
#define APER_WCET 20400
#define CLOCK_WCET 1600
#define ASTER_WCET 1600
#define SOFT_MET 3300
 
#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) {
kern_printf("±%d±",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;
 
/*for (;;)*/ {
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);
 
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",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 fine()
{
sys_end();
}
 
void exiting(void *arg)
{
kern_printf("EXITING");
shutting_down = 1;
}
 
TIME perftime_prol[10001];
TIME perftime_epil[10001];
int perftime_count = 0;
 
void perftest_stat(void *arg)
{
int i;
TIME d, sum=0, max=0;
 
for (i=0; i<9000; i++) {
d = perftime_epil[i]-perftime_prol[i];
sum += d;
if (max < d) max = d;
kern_printf("Û%ld %ldÛ",perftime_epil[i],perftime_prol[i]);
}
kern_printf("\n°°° perftime_count=%u sum=%lu max=%lu °°°\n",perftime_count, sum, max);
}
 
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;
 
kern_cli();
 
kern_sti();
 
sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN);
sys_atrunlevel(perftest_stat, NULL, RUNLEVEL_BEFORE_EXIT);
 
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);
 
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("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 (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
 
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("test7.c(main): Could not create task <aper> ...");
sys_end();
l1_exit(-1);
}
}
 
task_nopreempt();
fineprg.tv_sec = 60;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,fine,NULL);
group_activate(1);
return 0;
}
 
/demos/trunk/oldexamples/kernel/perf3.c
0,0 → 1,434
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: perf3.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Performance Test 3:
 
this test is based on test D.
 
the test creates some random events. each event measure the difference
beetween his activation time and thecurrent time.
 
**/
 
/*
* 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"
 
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 8200
#define APER_WCET 20400
#define CLOCK_WCET 1600
#define ASTER_WCET 1600
#define SOFT_MET 3300
 
#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) {
kern_printf("±%d±",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;
 
/*for (;;)*/ {
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);
 
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",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 fine()
{
sys_end();
}
 
void exiting(void *arg)
{
kern_printf("EXITING");
shutting_down = 1;
}
 
 
 
 
 
struct timespec last_random_time;
TIME max=0;
TIME sum=0;
int n=0;
 
void random_event(void *arg)
{
struct timespec t, sub;
TIME delta;
 
// get the current time
ll_gettime(TIME_EXACT, &t);
 
// compute the delta
SUBTIMESPEC(&t, &last_random_time, &sub);
delta = TIMESPEC2USEC(&sub);
 
// update the statistics
if (max < delta) max = delta;
sum += delta;
n++;
 
/* kern_printf("sub=%d.%d t=%d.%d last=%d.%d °\n",sub.tv_sec, sub.tv_nsec/1000,
t.tv_sec, t.tv_nsec/1000,
last_random_time.tv_sec, last_random_time.tv_nsec/1000);
*/ //return;
// create a new event
if (shutting_down)
return;
 
delta = (rand()%30000)+100;
ADDUSEC2TIMESPEC(delta, &t);
TIMESPEC_ASSIGN(&last_random_time, &t);
kern_event_post(&last_random_time, random_event, NULL);
}
 
void perftest_printdata(void *arg)
{
kern_printf("\n°°° max=%ld sum=%ld n=%d °°°",max,sum,n);
}
 
int main(int argc, char **argv)
{
PID p2; //p1,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;
 
sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN);
sys_atrunlevel(perftest_printdata, NULL, RUNLEVEL_BEFORE_EXIT);
 
kern_printf("\n\n");
 
srand(1234);
NULL_TIMESPEC(&last_random_time);
i = rand()%30000+2000;
ADDUSEC2TIMESPEC(i, &last_random_time);
// last_random_time.tv_sec = 2;
// last_random_time.tv_nsec = 0;
kern_cli();
kern_event_post(&last_random_time, random_event, NULL);
kern_sti();
 
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);
 
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("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 (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
 
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("test7.c(main): Could not create task <aper> ...");
sys_end();
l1_exit(-1);
}
}
*/
task_nopreempt();
fineprg.tv_sec = 6;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,fine,NULL);
group_activate(1);
return 0;
}
 
/demos/trunk/oldexamples/kernel/perf4.c
0,0 → 1,112
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: perf4.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Performance test 1:
 
there is one RR task that is preempted N_EDF times by an EDF task.
 
the test prints the differences of the execution time.
 
the test have to be compiled with the one shot timer, and it does not
use any init file.
 
**/
 
/*
* 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"
#include "modules/pi.h"
 
#define TIMESPEC_N 100
#define RR_N 1000000000
#define EDF_N 2500
 
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(1000*1000*1000, RR_MAIN_NO, mb);
RR_register_level(10000, RR_MAIN_YES, mb);
dummy_register_level();
 
PI_register_module();
 
return 1200;
}
 
void *crash_RR(void *arg);
void *crash_EDF(void *arg);
 
void *__init__(void *arg)
{
TIME t1, t2;
PI_mutexattr_t a;
mutex_t m1;
int i;
 
PI_mutexattr_default(a);
 
mutex_init(&m1, &a);
 
t1 = sys_gettime(NULL);
for (i=0; i<1000; i++) {
mutex_lock(&m1);
mutex_unlock(&m1);
}
t2 = sys_gettime(NULL);
 
kern_printf("t1=%ld, t2=%ld\n",t1,t2);
 
return 0;
}
 
// not used !!!
int main(int argc, char **argv)
{
return 0;
}
/demos/trunk/oldexamples/kernel/testb.c
0,0 → 1,244
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testb.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 11 (B):
 
CBS test, similar to Test 10
 
There are 4 CBS aperiodic tasks and 1 periodic task.
after 5 secs, there is another activation of two of the four tasks.
at sec. 10 the test stops.
 
**/
 
/*
* 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"
 
#if !defined(__TEST1__)
THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
#endif
 
struct timespec s_stime[10000];
struct timespec s_send[10000];
TIME s_curr[10000];
PID s_PID[10000];
int useds=0;
int testactive=1;
 
 
TASK pippo()
{
int i;
struct timespec t;
int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_nsec <= 30000000L);
}
 
TASK pippo2()
{
int i;
struct timespec t;
int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
} while (t.tv_nsec <= 30000000L);
}
 
TASK asteroide(void)
{
int i;
int y = rand() % 7 + 15;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 10000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
task_endcycle();
 
if (i==7) testactive = 0;
 
puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
}
 
TASK aper(void *a)
{
int i;
int y;
 
int load1,j;
 
char s[2];
 
y = (int) a;
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 600000; //8000 + rand()%2000;
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--;
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
int i;
NRT_TASK_MODEL m;
HARD_TASK_MODEL m_per;
SOFT_TASK_MODEL m_aper;
PID p1, p2, p3, p4, p5;
int k=1;
 
srand(7);
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p1 = task_create("pippo", pippo, &m, NULL);
if (p1 == NIL)
{ kern_printf("Can't create pippo task...\n"); }
 
p2 = task_create("pippo2", pippo2, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); }
 
hard_task_default_model(m_per);
hard_task_def_mit(m_per,15000);
hard_task_def_wcet(m_per,6200);
hard_task_def_group(m_per,1);
p3 = task_create("asteroide", asteroide, &m_per, NULL);
if (p3 == NIL)
{ kern_printf("Can't create asteroide task...\n"); }
 
soft_task_default_model(m_aper);
soft_task_def_met(m_aper,10000);
soft_task_def_period(m_aper,100000);
soft_task_def_group(m_aper,1);
soft_task_def_system(m_aper);
soft_task_def_arg(m_aper, 14);
soft_task_def_aperiodic(m_aper);
p4 = task_create("aper", aper, &m_aper, NULL);
if (p4 == NIL)
{ kern_printf("Can't create aper task...\n"); }
 
soft_task_def_arg(m_aper, 13);
p5 = task_create("aper", aper, &m_aper, NULL);
if (p5 == NIL)
{ kern_printf("Can't create aper(2) task...\n"); }
 
soft_task_def_arg(m_aper, 12);
p5 = task_create("aper", aper, &m_aper, NULL);
if (p5 == NIL)
{ kern_printf("Can't create aper(2) task...\n"); }
 
soft_task_def_arg(m_aper, 11);
p5 = task_create("aper", aper, &m_aper, NULL);
if (p5 == NIL)
{ kern_printf("Can't create aper(2) task...\n"); }
 
// kern_printf("p1=%d p2=%d p3=%d p4=%d\n",p1,p2,p3,p4);
group_activate(1);
 
 
// task_kill(p2);
i = 1;
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (i && t.tv_sec == 5) {
task_activate(p4);
task_activate(p5);
i = 0;
}
 
// task_kill(p3);
} while (t.tv_sec < 10);
testactive = 0;
 
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<useds; i++)
kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
 
return 0;
}
/demos/trunk/oldexamples/kernel/testc.c
0,0 → 1,260
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testc.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 12 (C):
 
CBS test, similar to Test 11
 
then at start time two task are started, one of them
calling task_nopreempt. when the task releases, the other exec all
the pending activations.
at sec. 4 the test stops.
 
**/
 
/*
* 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"
 
TASK pippo()
{
// int i;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_nsec <= 30000000L);
return 0;
}
 
TASK pippo2()
{
// int i;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
} while (t.tv_nsec <= 30000000L);
return 0;
}
 
TASK asteroide(void)
{
int i;
int y = rand() % 7 + 15;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 10000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
// if (i==7) testactive = 0;
 
puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
return 0;
}
 
TASK aper(void *a)
{
int i;
int y;
 
int load1,j;
 
char s[2];
 
y = (int) a;
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 600000; //8000 + rand()%2000;
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 per(void)
{
int i;
int y = rand() % 7 + 15;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < 60) {
load1 = 1000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
// if (i==7) testactive = 0;
 
//puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
return 0;
}
 
TASK stoppa()
{
struct timespec t;
 
task_nopreempt();
kern_printf("\nTask nopreempt");
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
} while (t.tv_sec < 3);
kern_printf("\nTask preempt");
task_preempt();
kern_printf("\nFine STOPPA");
return 0;
}
 
 
 
int main(int argc, char **argv)
{
struct timespec t;
int i;
NRT_TASK_MODEL m;
// HARD_TASK_MODEL m_per;
SOFT_TASK_MODEL m_aper;
PID p8, p9; //p1, p2, p3, p4, p5, p6, p7,
 
// int k=1;
 
srand(7);
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
soft_task_default_model(m_aper);
soft_task_def_met(m_aper,10000);
soft_task_def_period(m_aper,100000);
soft_task_def_group(m_aper,1);
soft_task_def_system(m_aper);
soft_task_def_arg(m_aper, (void *)14);
soft_task_def_aperiodic(m_aper);
// soft_task_def_skip_arrivals(m_aper);
 
soft_task_def_periodic(m_aper);
p8 = task_create("per", per, &m_aper, NULL);
if (p8 == NIL)
{ kern_printf("Can't create per task...\n"); }
 
p9 = task_create("stoppa", stoppa, &m, NULL);
if (p9 == NIL)
{ kern_printf("Can't create stoppa task...\n"); }
 
task_activate(p8);
 
i = 0;
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (i == 0 && t.tv_sec == 1 && t.tv_nsec >= 0) {
task_activate(p9);
i = 1;
}
} while (t.tv_sec < 10);
/*
testactive = 0;
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<useds; i++)
kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
*/
return 0;
}
/demos/trunk/oldexamples/kernel/testd.c
0,0 → 1,381
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testd.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 13 (D):
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 10 (A), and use the CBS to serve the periodic tasks.
 
There still remain some periodic tasks, that are guaranteed basing on their
wcet.
 
It also tests the shutdown...
 
 
**/
 
/*
* 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"
 
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 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) {
kern_printf("±%d±",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;
 
/*for (;;)*/ {
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);
 
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",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 fine()
{
sys_end();
}
 
void exiting(void *arg)
{
kern_printf("EXITING");
shutting_down = 1;
}
 
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;
 
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);
 
// 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_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("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 (p3 == -1) {
perror("test7.c(main): Could not create task <JetControl> ...");
sys_end();
l1_exit(-1);
}
 
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("test7.c(main): Could not create task <aper> ...");
sys_end();
l1_exit(-1);
}
}
 
task_nopreempt();
fineprg.tv_sec = 6;
fineprg.tv_nsec = 0;
// kern_event_post(&fineprg,fine,NULL);
group_activate(1);
return 0;
}
 
/demos/trunk/oldexamples/kernel/teste.c
0,0 → 1,115
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: teste.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 14 (E):
 
this test is a simple main() function with one other task.
 
This test verify the correctness of the sem module.
 
 
**/
 
/*
* 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/sem.h>
 
sem_t s;
 
TASK pippo(void *a)
{
int i=0;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (i==0 && t.tv_sec == (int)a) {
i = 1;
kern_printf("before sem_wait %d\n",(int)a);
sem_wait(&s);
kern_printf("after sem_wait %d\n",(int)a);
}
 
if (i==1 && t.tv_sec == 2+(int)a) {
i = 2;
kern_printf("before sem_post %d\n",(int)a);
sem_post(&s);
kern_printf("after sem_post %d\n",(int)a);
return 0;
}
 
 
} while (1);
}
 
int main(int argc, char **argv)
{
// struct timespec t;
// int i;
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)
{ kern_printf("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)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
sem_init(&s,0,1);
 
group_activate(1);
 
return 0;
}
/demos/trunk/oldexamples/kernel/testf.c
0,0 → 1,128
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testf.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 15 (F):
 
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.
 
**/
 
/*
* 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"
 
mutex_t m1;
 
 
TASK pippo1(void *a)
{
// int i=0;
// struct timespec t;
// int last = 0;
 
kern_printf("pippo1 prima di mutex_lock\n");
mutex_lock(&m1);
kern_printf("pippo1 dopo mutex_lock\n");
 
mutex_unlock(&m1);
kern_printf("pippo1 dopo mutex_unlock\n");
return 0;
}
 
TASK pippo2()
{
kern_printf("pippo2 Dentro pippo2\n");
return 0;
}
 
int main(int argc, char **argv)
{
// struct timespec t;
// int i;
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,10000);
hard_task_def_group(m,1);
 
hard_task_def_arg(m,(void *)1);
p2 = task_create("pippo1", pippo1, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo1 task...\n"); return 1; }
 
hard_task_def_mit(m,100000);
p3 = task_create("pippo2", pippo2, &m, NULL);
if (p3 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
PI_mutexattr_default(a);
mutex_init(&m1,&a);
 
kern_printf("main prima di mutex_lock\n");
mutex_lock(&m1);
kern_printf("main dopo mutex_lock, exec=%d, exec_shadow=%d\n", exec, exec_shadow);
 
group_activate(1);
 
kern_printf("main dopo group_activate, exec=%d, exec_shadow=%d\n", exec, exec_shadow);
mutex_unlock(&m1);
kern_printf("main dopo mutex_unlock\n");
 
mutex_destroy(&m1);
kern_printf("main dopo mutex_destroy\n");
 
return 0;
}
/demos/trunk/oldexamples/kernel/testg.c
0,0 → 1,485
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testg.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test 16 (G):
 
This is a part of 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)
 
**/
 
/*
* 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 "drivers/glib.h"
#include "drivers/keyb.h"
#include "drivers/mouse.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 */
 
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 initg.c!!!
#define NUM 200
#define DEN 64000
 
//SEM 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;
// char str[50];
 
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();
// sys_status(0xFFFF);
// sys_end();
}
 
/*--------------------------------------------------------------*/
/* 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, BLOCK);
kern_cli();
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_signal(mutex);
kern_sti();
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, BLOCK);
grx_plot(x, LMOUSE, 8);
//while (sys_ticks()==s);
//sem_signal(mutex);
}
 
/*--------------------------------------------------------------*/
/* MAIN PROCESS */
/*--------------------------------------------------------------*/
 
int main(int argc, char *argv[])
{
int i;
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;
 
//sys_def_nocheck(si);
//sys_def_tick(si, tick, mSec);
//sys_init(&si);
 
//cprintf("Sys GetTick... %lu 100000 / sys_tick: %lu \n", sys_gettick(), 100000 / sys_gettick());
 
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_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_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);
mouse_def_task(mouse,(TASK_MODEL *)&mouse_nrt);
break;
default:
argc=0;
break;
}
mouse_def_ms(mouse,0);
 
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();
}
/* */
// grx_close();
print_grid();
#define DX (640/5-1)
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);
 
for (i=0;i<3;i++) {
period[i]=period[i]*PERIODSCALE;
//ptime[i]=ptime[i] *PERIODSCALE; ptime is not scaled
}
sys_atrunlevel(my_end, NULL, RUNLEVEL_BEFORE_EXIT);
 
/* mutex */
// mutex = sem_create(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]);
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();
l1_exit(-1);
}
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]);
if (task_create("red", color, &m_per, NULL) == -1) {
grx_close();
perror("Edf.C(main) Could not create <red>:");
sys_end();
l1_exit(-1);
}
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]);
if (task_create("yellow", color, &m_per, NULL) == -1) {
grx_close();
perror("Edf.C(main) Could not create <yellow>:");
sys_end();
l1_exit(-1);
}
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, BLOCK);
kern_cli();
grx_plot(x, LM, 7);
kern_sti(); // sem_signal(mutex);
}
 
c = keyb_getchar();
return 0;
}
 
/*--------------------------------------------------------------*/
/demos/trunk/oldexamples/kernel/testh.c
0,0 → 1,493
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testh.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 17 (h):
 
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.
 
**/
 
/*
* 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
 
#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",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);
 
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/trunk/oldexamples/kernel/testi.c
0,0 → 1,234
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testi.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 18 (I):
 
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
 
**/
 
/*
* 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 "drivers/keyb.h"
 
mutex_t m0,m1,m2;
 
 
TIME gt(void)
{
TIME t;
kern_cli();
t = ll_gettime(TIME_EXACT,NULL);
kern_sti();
return t;
}
 
void startJ(void *a)
{
// task_activate((PID)a);
PID p = (PID) a;
LEVEL l;
 
kern_printf("startJ: %d\n",p);
 
l = proc_table[p].task_level;
level_table[l]->task_activate(l,p);
event_need_reschedule();
}
 
TASK j0()
{
kern_printf("J0: before locking m0\n");
mutex_lock(&m0);
kern_printf("J0: locked m0\n");
mutex_unlock(&m0);
kern_printf("J0: unlocked m0, locking m1\n");
 
mutex_lock(&m1);
kern_printf("J0: locked m1\n");
mutex_unlock(&m1);
kern_printf("J0: unlocked m1, end task\n");
return 0;
}
 
 
TASK j1()
{
kern_printf("J1: before locking m2\n");
mutex_lock(&m2);
kern_printf("J1: locked m2\n");
mutex_unlock(&m2);
kern_printf("J1: unlocked m2, end task\n");
return 0;
}
 
 
TASK j2()
{
// struct timespec t;
kern_printf("J2: before locking m2\n");
mutex_lock(&m2);
kern_printf("J2: locked m2, waiting to t=1 sec\n");
 
while (gt() < 1000000);
 
kern_printf("J2: t = 1 sec reached\n");
mutex_lock(&m1);
kern_printf("J2: locked m1, waiting to t=2 sec\n");
 
while (gt() < 2000000);
 
kern_printf("J2: t = 2 sec reached\n");
mutex_unlock(&m1);
kern_printf("J2: unlocked m1\n");
 
mutex_unlock(&m2);
kern_printf("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;
 
//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)
{ kern_printf("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)
{ kern_printf("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)
{ kern_printf("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;
// t.tv_nsec = 30000000;
kern_event_post(&t,startJ,(void *)p1);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p0);
 
task_activate(p2);
 
kern_printf("END main\n");
 
return 0;
}
/demos/trunk/oldexamples/kernel/testj.c
0,0 → 1,268
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testj.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 19 (J):
 
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
 
**/
 
/*
* 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 "drivers/keyb.h"
 
#include <modules//srp.h>
 
mutex_t m1,m2,m3;
 
 
TIME gt(void)
{
TIME t;
kern_cli();
t = ll_gettime(TIME_EXACT,NULL);
kern_sti();
return t;
}
 
void startJ(void *a)
{
// task_activate((PID)a);
PID p = (PID) a;
LEVEL l;
 
kern_printf("startJ: %d\n",a);
 
l = proc_table[p].task_level;
level_table[l]->task_activate(l,p);
event_need_reschedule();
}
 
TASK Jlobby()
{
kern_printf("(*)");
return 0;
}
 
TASK Jh()
{
PID l;
HARD_TASK_MODEL m;
SRP_RES_MODEL r;
 
kern_printf("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);
kern_printf("JH: locked m3, locking m1\n");
mutex_lock(&m1);
kern_printf("JH: locked m1, unlocking m1\n");
mutex_unlock(&m1);
kern_printf("JH: unlocked m1, unlocking m3\n");
mutex_unlock(&m3);
kern_printf("JH: unlocked m3, end task\n");
return 0;
}
 
 
TASK Jm()
{
kern_printf("JM: before locking m3\n");
mutex_lock(&m3);
kern_printf("JM: locked m3, locking m2\n");
mutex_lock(&m2);
kern_printf("JM: locked m2, unlocking m2\n");
mutex_unlock(&m2);
kern_printf("JM: unlocked m2, unlocking m3\n");
mutex_unlock(&m3);
kern_printf("JM: unlocked m3, locking m1\n");
mutex_lock(&m1);
kern_printf("JM: locked m1, unlocking m1\n");
mutex_unlock(&m1);
kern_printf("JM: unlocked m1, end task\n");
return 0;
}
 
 
TASK Jl()
{
// struct timespec t;
kern_printf("JL: before locking m2\n");
mutex_lock(&m2);
kern_printf("JL: locked m2, waiting to t=1 sec\n");
 
while (gt() < 1000000);
 
kern_printf("JL: t = 1 sec reached, locking m1\n");
mutex_lock(&m1);
kern_printf("JL: locked m1, waiting to t=2 sec\n");
 
while (gt() < 2000000);
 
kern_printf("JL: t = 2 sec reached, unlocking m1\n");
mutex_unlock(&m1);
kern_printf("JL: unlocked m1, unlocking m2\n");
 
mutex_unlock(&m2);
 
kern_printf("JL: unlocked m2, locking m3\n");
mutex_lock(&m3);
kern_printf("JL: locked m3, unlocking m3\n");
mutex_unlock(&m3);
kern_printf("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;
 
//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)
{ kern_printf("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)
{ kern_printf("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)
{ kern_printf("Can't create JL task...\n"); return 1; }
 
// sys_abort(1);
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
// t.tv_nsec = 30000000;
kern_event_post(&t,startJ,(void *)p1);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p0);
 
task_activate(p2);
 
kern_printf("END main\n");
 
return 0;
}
/demos/trunk/oldexamples/kernel/testk.c
0,0 → 1,226
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testk.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 20 (K):
 
This test verify the correctness of the NOP module. It works with the PI
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
 
**/
 
/*
* 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 "drivers/keyb.h"
 
#include <modules//srp.h>
 
mutex_t m0;
 
 
TIME gt(void)
{
TIME t;
kern_cli();
t = ll_gettime(TIME_EXACT,NULL);
kern_sti();
return t;
}
 
void startJ(void *a)
{
// task_activate((PID)a);
PID p = (PID) a;
LEVEL l;
 
kern_printf("startJ: %d\n",p);
 
l = proc_table[p].task_level;
level_table[l]->task_activate(l,p);
event_need_reschedule();
}
 
TASK j1()
{
kern_printf("J1: before locking m0\n");
mutex_lock(&m0);
kern_printf("J1: locked m0\n");
mutex_unlock(&m0);
kern_printf("J1: unlocked m0, end task\n");
return 0;
}
 
 
TASK j2()
{
kern_printf("J2: waiting t=1.5 sec\n");
 
while (gt() < 1500000);
 
kern_printf("J2: end task\n");
return 0;
}
 
 
TASK j3()
{
kern_printf("J3: before locking m0\n");
mutex_lock(&m0);
kern_printf("J3: locked m0, waiting to t=2 sec\n");
 
while (gt() < 2000000);
 
kern_printf("J3: t = 1 sec reached, unlocking m0\n");
mutex_unlock(&m0);
kern_printf("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, &m, &r, &srp, NULL);
p0 = task_createn("J1", j1, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
if (p0 == NIL)
{ kern_printf("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)
{ kern_printf("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, &m, &r, &srp, NULL);
p2 = task_createn("J3", j3, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
if (p2 == NIL)
{ kern_printf("Can't create J3 task...\n"); return 1; }
 
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
// t.tv_nsec = 30000000;
kern_event_post(&t,startJ,(void *)p0);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p1);
 
task_activate(p2);
 
kern_printf("END main\n");
 
return 0;
}
/demos/trunk/oldexamples/kernel/testl.c
0,0 → 1,487
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testl.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 21 (l):
 
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
 
**/
 
/*
* 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
 
#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",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);
 
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/trunk/oldexamples/kernel/testm.c
0,0 → 1,318
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testm.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 22 (M):
 
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!)
 
 
**/
 
/*
* 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 "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
 
#define PER_WCET 7800
#define APER_WCET 14000
#define CLOCK_WCET 200
#define ASTER_WCET 200
 
#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 = 64;
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (x+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",freedesc,errno);
}
else {
num_aster++;
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(0));
task_endcycle();
}
}
 
 
 
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
and plot on the screen the elapsed times... */
TASK jetcontrol()
{
int i; /* a counter */
TIME sum, max, curr, last[5];
int nact;
int j; /* the elements set by jet_gettable */
PID p;
 
 
kern_cli();
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
kern_sti();
 
for (;;) {
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
kern_cli();
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
kern_sti();
i++;
}
}
}
 
 
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;
struct timespec fineprg;
 
KEY_EVT emerg;
//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();
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);
}
 
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();
l1_exit(-1);
}
 
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();
l1_exit(-1);
}
}
 
fineprg.tv_sec = 1000;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
 
group_activate(1);
return 0;
}
 
/demos/trunk/oldexamples/kernel/testn.c
0,0 → 1,211
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testn.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 23 (N):
 
This is the mousfind.c Hartik's example.
 
It find the mouse...
 
**/
 
/*
* 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 <drivers/mouse.h>
#include <drivers/keyb.h>
 
/* don't include this into real applications*/
#include <../drivers/char/_mouse.h>
 
#define cons_columns 80
#define cons_rows 25
 
int done;
 
void my_ctrlC_function(KEY_EVT *k)
{
CRSR_STD();
done=1;
//sys_status(0xffff);
sys_end();
l1_exit(0);
}
 
//extern int tindex;
//extern DWORD tdata[];
//int first=1;
 
 
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[])
{
// KEYB_PARMS keyb =BASE_KEYB;
MOUSE_PARMS mouse=BASE_MOUSE;
int ch,running,nm;
int sens=5;
 
/* keyboard initialization */
// keyb_def_ctrlC(keyb,my_ctrlC_function);
// keyb_init(&keyb);
 
/* 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("[ctrl-c]\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;
while (!done) {
ch=keyb_getch(TRUE);
switch(ch) {
 
/* 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) {
/* 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[ch-'a'].name);
/* threshold */
place(11,21);
cprintf("%i ",sens);
/* don't use this method to change a mouse protocol */
/* use mouse_def_???? macros instead */
mouse.type=ch-'a';
/* 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();
sys_end();
return 0;
}
/demos/trunk/oldexamples/kernel/testo.c
0,0 → 1,99
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testo.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test 24 (O):
 
This is the pcitest Hartik's example.
 
**/
 
/*
* 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 <drivers/keyb.h>
 
#include <drivers/llpci.h>
#include <drivers/pci.h>
 
void scan()
{
// int i, ndev;
// WORD Class;
// struct pci_regs *r;
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_abort(60000);
}
 
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();
while(1);
sys_end();
return -1;
}
/demos/trunk/oldexamples/kernel/testp.c
0,0 → 1,227
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testp.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test 25 (P):
 
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.
 
**/
 
/*
* 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 <mem.h>
//#include <stdlib.h>
#include <string.h>
//#include <cons.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_status(0xFFFF);
sys_abort(500);
//exit(1);
}
 
int main(void)
{
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");
// strcpy(talk_myipaddr, "193.205.82.46");
// strcpy(talk_toipaddr, "193.205.82.44");
 
strcpy(talk_myipaddr, "193.205.82.44");
strcpy(talk_toipaddr, "193.205.82.46");
 
/* 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...*/
//task_nopreempt();
nrt_task_default_model(m_nrt);
task_activate(task_create("aaa",scrittore,&m_nrt,NULL));
task_activate(task_create("bbb",write,&m_nrt,NULL));
//clear();
//task_preempt();
/*...and wait!!! */
while (!esc) {
}
sys_end();
//clear();
return 0;
}
/demos/trunk/oldexamples/kernel/testq.c
0,0 → 1,229
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testq.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 26 (Q):
 
This test verify the correctness of the task_join primitive.
 
There are 4 taks, J1, J2, J3, are created as joinable, J4 as detached
(the standard with hartik...)
 
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.
 
**/
 
/*
* 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 "drivers/keyb.h"
 
#include <modules//srp.h>
 
 
PID j0, j1, j2, j3, j4;
mutex_t m1;
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
TASK J1()
{
int err;
void *ret;
 
kern_printf("J1: started, waiting 0.2 sec\n");
 
while (sys_gettime(NULL) < 200000);
 
kern_printf("J1: 0.2 sec reached, joining J2\n");
 
err = task_join(j2, &ret);
 
kern_printf("J1: join J2 returns %d error %d, exiting\n",
(int)ret,err);
return (void *)11;
}
 
TASK J2()
{
kern_printf("J2: started, waiting 0.4 sec\n");
 
while (sys_gettime(NULL) < 400000);
 
kern_printf("J2: 0.4 sec reached, exiting\n");
 
return (void *)22;
}
 
TASK J3()
{
int err;
void *ret;
 
kern_printf("J3: started, joining J1\n");
 
err = task_join(j1, &ret);
 
kern_printf("J3: join J1 returns %d error %d, waiting 0.6sec\n", (int)ret, err);
 
while (sys_gettime(NULL) < 600000);
 
kern_printf("J1: 0.6 sec reached, locking m1\n");
 
mutex_lock(&m1);
 
kern_printf("J3: locked m1, unlocking m1\n");
 
mutex_unlock(&m1);
 
kern_printf("J3: unlocked m1, exiting\n");
 
return (void *)33;
}
 
TASK J4()
{
kern_printf("J4: started, waiting 1 sec\n");
 
while (sys_gettime(NULL) < 1000000);
 
kern_printf("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 !!!!
--------------------------------------------------------------------- */
 
kern_printf("main: creating J1,J2,J3, locking m1\n");
 
j1 = task_create("J1", J1, &m, NULL);
if (j1 == NIL) { kern_printf("Can't create J1 task...\n"); return 1; }
task_activate(j1);
 
j2 = task_create("J2", J2, &m, NULL);
if (j2 == NIL) { kern_printf("Can't create J2 task...\n"); return 1; }
task_activate(j2);
 
mutex_lock(&m1);
 
j3 = task_create("J3", J3, &m, NULL);
if (j3 == NIL) { kern_printf("Can't create J3 task...\n"); return 1; }
task_activate(j3);
 
kern_printf("main: waiting t=0.8 sec\n");
 
while (sys_gettime(NULL) < 800000);
 
err = task_join(j3, NULL);
 
kern_printf("main: join J3 error %d, unlocking m1\n",err);
 
mutex_unlock(&m1);
 
err = task_join(j3, &ret);
 
kern_printf("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) { kern_printf("Can't create J4 task...\n"); return 1; }
 
task_activate(j4);
 
err = task_join(j4,&ret);
 
kern_printf("main: join J4 returns %d error %d, exiting\n", (int)ret, err);
 
return 0;
}
/demos/trunk/oldexamples/kernel/test1.c
0,0 → 1,167
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: test1.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 1:
 
this test is a simple main() function with other 2 task
 
This test has to be compiled with init1.c, that introduce 2 RR levels
with a timeslice of 300us (!)
 
This test can be useful to test functions like
 
task_nopreempt
task_preempt
task_create
task_activate
task_delay
group_activate
normal task termination (task_abort)
normal system termination (sys_end)
standard atexit functions (the keyboard...)
 
 
**/
 
/*
* 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"
 
// for min
#include "ll/stdlib.h"
 
#include "ll/stdio.h"
 
 
#if !defined(__TEST1__)
THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
#endif
 
struct timespec s_stime[10000];
struct timespec s_send[10000];
TIME s_curr[10000];
PID s_PID[10000];
int useds=0;
int testactive=1;
 
 
TASK pippo()
{
// int i;
struct timespec t;
int last = 0;
 
do {
//kern_printf("!");
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if ((t.tv_nsec/1000000) != last) { //ogni 7000
// kern_printf("Û%dÛ",t);
last = t.tv_nsec/1000000;
// task_delay(3000000);
}
 
} while (t.tv_nsec <= 20000000L);
}
 
TASK pippo2()
{
struct timespec t;
do {
// kern_printf("pippo2");
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
if (t.tv_nsec > 5000000 && t.tv_nsec <= 12000000) task_nopreempt();
if (t.tv_nsec > 12000000) task_preempt();
 
} while (t.tv_nsec <= 20000000L);
}
 
int main(int argc, char **argv)
{
struct timespec t;
int i;
NRT_TASK_MODEL m;
PID p2,p3;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p2 = task_createn("pippo", pippo, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo task...\n"); return 1; }
 
p3 = task_createn("pippo2", pippo2, &m, NULL);
if (p3 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
group_activate(1);
 
 
kern_printf("DENTRO MAIN %d\n",ll_context_save());
 
// testactive = 1;
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
// task_delay(14000);
 
} while (t.tv_nsec <= 40000000L);
testactive = 0;
 
// sys_status(0xFFFF);
// return 0;
 
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<min(useds,20); i++)
kern_printf("%6d: pid %6d stime %-9d reschedule %-9d avail %-9d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
// sys_end();
 
kern_printf("DENTRO MAIN %d\n",ll_context_save());
return 0;
}
/demos/trunk/oldexamples/kernel/test2.c
0,0 → 1,161
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: test2.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 2:
task_testcancel,
task_delay
task_setcancelstate
 
The task 2 disappear after time 10000 because we have reactivated
the cancelability and a testcancel is issued
 
**/
 
/*
* 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"
 
#if !defined(__TEST1__)
THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
#endif
 
struct timespec s_stime[10000];
struct timespec s_send[10000];
TIME s_curr[10000];
PID s_PID[10000];
int useds=0;
int testactive=1;
 
 
TASK pippo()
{
int i;
struct timespec t;
// int last = 0;
 
task_setcancelstate(TASK_CANCEL_DISABLE,&i);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
// printf_xy(10,8,WHITE,"%9d s%9d n%9d",exec_shadow,t.tv_sec,t.tv_nsec);
 
if (t.tv_nsec > 10000000)
{
task_setcancelstate(TASK_CANCEL_ENABLE,&i);
}
if (t.tv_nsec > 5000000)
{
// kern_printf("\n%d %dÄ", exec_shadow, proc_table[exec_shadow].control);
task_testcancel();
}
task_delay(1000);
// kern_printf("Dopo Delay %d ",exec_shadow);
 
} while (t.tv_nsec <= 30000000L);
}
 
TASK pippo2()
{
int i;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
// printf_xy(10,9,WHITE,"%d s%9d n%9d\n",exec_shadow,t.tv_sec,t.tv_nsec);
// kern_printf("Û%dÛ",proc_table[exec_shadow].control);
 
if (t.tv_nsec > 15000000)
{
// kern_printf("XXXXXXXXXX");
task_setcanceltype(TASK_CANCEL_ASYNCHRONOUS,&i);
}
task_delay(1000);
 
} while (t.tv_nsec <= 30000000L);
}
 
int main(int argc, char **argv)
{
struct timespec t;
int i;
NRT_TASK_MODEL m;
PID p2,p3;
// int k=1;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p2 = task_create("pippo2", pippo, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
p3 = task_create("pippo3", pippo2, &m, NULL);
if (p3 == NIL)
{ kern_printf("Can't create pippo3 task...\n"); return 1; }
 
group_activate(1);
 
 
task_kill(p2);
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
task_kill(p3);
 
} while (t.tv_nsec <= 20000000L);
testactive = 0;
 
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<useds; i++)
kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
 
return 0;
}
/demos/trunk/oldexamples/kernel/testr.c
0,0 → 1,231
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testr.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 27 (R):
 
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
 
 
**/
 
/*
* 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 "drivers/keyb.h"
 
 
mutex_t m0;
cond_t c0;
 
int number = 0;
 
PID p0,p1,p2,p3;
 
TASK j0()
{
kern_printf("J0: before locking m0\n");
mutex_lock(&m0);
kern_printf("J0: locked m0, waiting on c0, number =%d\n", number);
while (!number) {
cond_wait(&c0,&m0);
kern_printf("J0: number = %d, if >0 unlocking m0\n",number);
}
number--;
mutex_unlock(&m0);
kern_printf("J0: unlocked m0, end task\n");
return 0;
}
 
 
TASK j1()
{
kern_printf("J1: before locking m0\n");
mutex_lock(&m0);
kern_printf("J1: locked m0, waiting on c0, number =%d\n", number);
while (!number) {
cond_wait(&c0,&m0);
kern_printf("J1: number = %d, if >0 unlocking m0\n",number);
}
number--;
mutex_unlock(&m0);
kern_printf("J1: unlocked m0, end task\n");
return 0;
}
 
 
TASK j2()
{
// struct timespec t;
 
kern_printf("J2: started, waiting t=0.5 sec\n");
while (sys_gettime(NULL) < 500000);
 
kern_printf("J2: before locking m0\n");
mutex_lock(&m0);
kern_printf("J2: locked m0, number++ (was %d), cond_signal\n", number);
 
number++;
cond_signal(&c0);
// cond_broadcast(&c0);
 
kern_printf("J2: unlocking m0\n");
mutex_unlock(&m0);
 
kern_printf("J2: waiting t=1 sec\n");
while (sys_gettime(NULL) < 1000000);
 
kern_printf("J2: Killing J3\n");
task_kill(p3);
kern_printf("J2: before locking m0\n");
mutex_lock(&m0);
kern_printf("J2: locked m0, number++ (was %d), cond_signal\n", number);
 
number++;
cond_signal(&c0);
// cond_broadcast(&c0);
 
kern_printf("J2: unlocking m0\n");
mutex_unlock(&m0);
kern_printf("J2: unlocked m0, end task\n");
return 0;
}
 
void cleanup_lock(void *arg)
{
kern_printf("J3: KILL!!!\n");
mutex_unlock(&m0);
kern_printf("J3: unlocked m0 by the cleanup function\n");
}
 
TASK j3()
{
kern_printf("J3: before locking m0\n");
mutex_lock(&m0);
kern_printf("J3: locked m0, waiting on c0, number =%d\n", number);
task_cleanup_push(cleanup_lock, (void *)&m0);
while (!number) {
cond_wait(&c0,&m0);
kern_printf("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);
kern_printf("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)
{ kern_printf("Can't create J0 task...\n"); return 1; }
 
p1 = task_create("J1", j1, &m, NULL);
if (p1 == NIL)
{ kern_printf("Can't create J1 task...\n"); return 1; }
 
p2 = task_create("J2", j2, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create J2 task...\n"); return 1; }
 
p3 = task_create("J3", j3, &m, NULL);
if (p3 == NIL)
{ kern_printf("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);
 
kern_printf("END main\n");
 
return 0;
}
/demos/trunk/oldexamples/kernel/tests.c
0,0 → 1,79
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: tests.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
memtest.c:
 
try to allocate different regions of memory...
 
**/
 
/*
* 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"
 
int main(int argc, char **argv)
{
void *a;
 
kern_cli(); a = DOS_alloc(4500); kern_sti();
kern_printf("below 1 M: %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_aligned(10000,MEMORY_UNDER_16M,10,0); kern_sti();
kern_printf("below 16M: %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_aligned(10000,MEMORY_FROM_1M_TO_16M,2,0); kern_sti();
kern_printf(">1M <16M : %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc(10000); kern_sti();
kern_printf("normal : %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_page(MEMORY_UNDER_1M); kern_sti();
kern_printf("page <1M : %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_page(MEMORY_FROM_1M_TO_16M); kern_sti();
kern_printf("p>1<16M : %ld\n", (DWORD)a);
 
kern_cli(); a = kern_alloc_page(0); kern_sti();
kern_printf("page : %ld\n", (DWORD)a);
 
return 0;
}
/demos/trunk/oldexamples/kernel/test3.c
0,0 → 1,137
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: test3.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number 3:
task_cleanup_push
task_cleanup_pop
 
It may print many 0 and then only one 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"
 
#if !defined(__TEST1__)
THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
#endif
 
struct timespec s_stime[10000];
struct timespec s_send[10000];
TIME s_curr[10000];
PID s_PID[10000];
int useds=0;
int testactive=1;
 
 
void fun1(void *p)
{
kern_printf("ÛÛ %d ÛÛ",(int)p);
}
 
 
TASK pippo()
{
int i;
struct timespec t;
int last = 0;
task_cleanup_push(fun1,(void *)1);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (t.tv_nsec > 5000000)
{
task_testcancel();
 
task_cleanup_push(fun1,(void *)-1);
task_cleanup_push(fun1,(void *)0);
task_cleanup_pop(1);
task_cleanup_pop(0);
}
task_delay(1000);
 
} while (t.tv_nsec <= 30000000L);
task_cleanup_pop(1);
}
 
 
 
int main(int argc, char **argv)
{
struct timespec t;
NRT_TASK_MODEL m;
PID p2,p3;
int k=1;
int i;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p2 = task_create("pippo2", pippo, &m, NULL);
if (p2 == NIL)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
group_activate(1);
 
 
NULL_TIMESPEC(&t);
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (t.tv_nsec > 10000000) task_kill(p2);
} while (t.tv_nsec <= 20000000L);
testactive = 0;
 
return 0;
 
kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
for (i=0; i<useds; i++)
kern_printf("%6d: pid %6d stime %6d reschedule %6d avail %6d\n",i,
s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
 
return 0;
}
/demos/trunk/oldexamples/kernel/testu.c
0,0 → 1,115
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testu.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Test Number ?? (U):
 
this test is a simple main() function with one other task.
 
This test verify the correctness of the internal_sem functions.
 
 
**/
 
/*
* 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 <kernel/int_sem.h>
 
internal_sem_t s;
 
TASK pippo(void *a)
{
int i=0;
struct timespec t;
// int last = 0;
 
do {
kern_cli();
ll_gettime(TIME_EXACT, &t);
kern_sti();
 
if (i==0 && t.tv_sec == (int)a) {
i = 1;
kern_printf("before internal_sem_wait %d\n",(int)a);
internal_sem_wait(&s);
kern_printf("after internal_sem_wait %d\n",(int)a);
}
 
if (i==1 && t.tv_sec == 2+(int)a) {
i = 2;
kern_printf("before internal_sem_post %d\n",(int)a);
internal_sem_post(&s);
kern_printf("after internal_sem_post %d\n",(int)a);
return 0;
}
 
 
} while (1);
}
 
int main(int argc, char **argv)
{
// struct timespec t;
// int i;
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)
{ kern_printf("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)
{ kern_printf("Can't create pippo2 task...\n"); return 1; }
 
internal_sem_init(&s,1);
 
group_activate(1);
 
return 0;
}
/demos/trunk/oldexamples/kernel/sysend.c
0,0 → 1,143
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: sysend.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
System termination:
 
the main task create J1, J2 and wait until 1 sec., then it calls sys_end
and cycles around a task_testcancel
 
J1 is a system task that ends at t=1.5 sec.
 
J2 is another user task that dies at t= 1.8 sec (it will not die!!!)
 
 
**/
 
/*
* 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 <sys/types.h>
#include <pthread.h>
#include <signal.h>
 
#include <kernel/kern.h>
#include <drivers/keyb.h>
 
void *J1(void *arg)
{
while (sys_gettime(NULL) < 1500000);
kern_printf("J1: t = 1.5 sec, ending...");
return 0;
}
 
void uscitaJ2(void *arg)
{
kern_printf("J2: AAAARRRRGGGHHH!!! killed by someone, time = %ld\n",sys_gettime(NULL));
}
 
void *J2(void *arg)
{
task_cleanup_push(uscitaJ2,NULL);
 
while (sys_gettime(NULL) < 1800000);
kern_printf("J1: t = 1.8 sec, ending...");
 
task_cleanup_pop(0);
return 0;
}
 
void fine(KEY_EVT *e)
{
sys_end();
}
 
void uscitamain(void *arg)
{
kern_printf("main: AAAARRRRGGGHHH!!! killed by someone, time = %ld\n",sys_gettime(NULL));
}
 
 
int main(int argc, char **argv)
{
PID err;
 
NRT_TASK_MODEL m1, m2;
 
KEY_EVT emerg;
//keyb_set_map(itaMap);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,fine);
 
 
nrt_task_default_model(m1);
nrt_task_def_system(m1);
nrt_task_def_level(m1,1);
nrt_task_default_model(m2);
nrt_task_def_level(m2,1);
 
kern_printf("main: creating J1\n");
err = task_create("J1", J1, (TASK_MODEL *)&m1, NULL);
if (err == -1) kern_printf("Error creating J1\n");
task_activate(err);
 
kern_printf("main: creating J2\n");
err = task_create("J2", J2, (TASK_MODEL *)&m2, NULL);
if (err == -1) kern_printf("Error creating J2\n");
task_activate(err);
 
kern_printf("main: waiting 1 sec\n");
while (sys_gettime(NULL) < 1000000);
 
kern_printf("main: sys_end()\n");
 
sys_end();
 
task_cleanup_push(uscitamain,NULL);
 
while (1)
task_testcancel();
 
task_cleanup_pop(0);
 
return 0;
}
/demos/trunk/oldexamples/kernel/testw.c
0,0 → 1,42
//#include <string.h>
//#include <stdlib.h>
//#include <cons.h>
 
 
#include <kernel/kern.h>
#include <drivers/keyb.h>
 
int main(int argc, char **argv)
{
KEY_EVT k;
clear();
k.ascii = 0;
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/trunk/oldexamples/kernel/testz.c
0,0 → 1,456
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testz.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
Author: Gerardo Lamastra
Giuseppe Lipari
Date: 1/10/96
 
File: Aster.C
Revision: 1.6
 
**/
 
/*
* 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
*
*/
 
/*
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__
 
 
#ifdef __TRACE__
#undef __TRACE__
#endif
 
/* #define __TRACE__ */
 
#ifdef __TRACE__
#include "sys\log.h"
#endif
 
#include <drivers/keyb.h>
//#include cons.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_sleep();
}
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();
}
 
void res(void *arg)
{
sys_status(CLOCK_STATUS|SCHED_STATUS);
}
 
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;
#ifdef __TRACE__
LOG_INFO li = BASE_LOG;
log_set_limit(li,9000);
log_set_name(li,"aster.hrt");
#endif
 
sys_atrunlevel(res, NULL, RUNLEVEL_BEFORE_EXIT);
 
#ifdef __TRACE__
log_init(&li);
#endif
 
//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);
}
#ifdef __TRACE__
log_loop();
#endif
/*
task_activate(p1);
task_activate(p2);
task_activate(p3);
task_activate(p4);
task_activate(p5);
task_activate(p6);
*/
group_activate(1);
 
while (!esc) {
kern_cli();
ll_gettime(TIME_EXACT,&t);
kern_sti();
 
printf_xy(0,21,WHITE,"Clock : %-9ds %-9dns",(int)t.tv_sec, (int)t.tv_nsec);
}
 
#ifdef __TRACE__
log_fix();
#endif
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/trunk/oldexamples/kernel/testss.c
0,0 → 1,547
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/**
------------
CVS : $Id: testss.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:48 $
------------
 
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.
 
**/
 
/*
* 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/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",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;
struct timespec fineprg;
 
#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);
 
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);
 
fineprg.tv_sec = 1800;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
group_activate(1);
return 0;
}
 
/demos/trunk/oldexamples/stdio/initfs.c
File deleted
/demos/trunk/oldexamples/fs/initfs.c
File deleted
/demos/trunk/oldexamples/block/makefile
0,0 → 1,35
#
#
#
 
ifndef BASE
BASE=../../..
endif
include $(BASE)/config/config.mk
 
PROGS=idetest0 idetest1 idetest2 idetest3 idelin idernd
OBJS=common.o
 
include $(BASE)/config/example.mk
 
#
#
#
 
idetest0:
make -f $(SUBMAKE) BASE=$(BASE) APP=idetest0 INIT=initblk.o OTHEROBJS=common.o
 
idetest1:
make -f $(SUBMAKE) BASE=$(BASE) APP=idetest1 INIT=initblk.o OTHEROBJS=common.o
 
idetest2:
make -f $(SUBMAKE) BASE=$(BASE) APP=idetest2 INIT=initblk.o OTHEROBJS=common.o
 
idetest3:
make -f $(SUBMAKE) BASE=$(BASE) APP=idetest3 INIT=initblk.o OTHEROBJS=common.o
 
idelin:
make -f $(SUBMAKE) BASE=$(BASE) APP=idelin INIT=initblk.o OTHEROBJS=common.o
 
idernd:
make -f $(SUBMAKE) BASE=$(BASE) APP=idernd INIT=initblk.o OTHEROBJS=common.o
/demos/trunk/oldexamples/block/idetest0.c
0,0 → 1,15
/*
*
*
*
*/
 
#include <fs/bdev.h>
 
#include "common.h"
 
int main(int argc,char *argv[])
{
showmessage("Have ide devices been found?\n");
return 0;
}
/demos/trunk/oldexamples/block/idetest1.c
0,0 → 1,20
/*
*
*
*
*/
 
#include <fs/bdev.h>
 
#include "common.h"
 
int main(int argc,char *argv[])
{
 
showmessage("This test try to identify the partions of all hard disks\n");
bdev_dump_names();
 
waitend();
return 0;
}
/demos/trunk/oldexamples/block/idetest2.c
0,0 → 1,77
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <drivers/keyb.h>
 
#include <fs/bdevinit.h>
#include <fs/bdev.h>
 
#include <string.h>
 
#include "common.h"
 
#define DISKDEVICE "ide/hda1"
 
__uint8_t buffer[2048] __attribute__ ((aligned (4)));
__dev_t dev;
 
extern char *ide_error_msg[];
 
int main(int argc,char *argv[])
{
__blkcnt_t blk;
int res;
int c;
 
showmessage("This test try to read some blocks from first hard disk\n");
 
dev=bdev_find_byname(DISKDEVICE);
if (dev<0) {
cprintf("Can't find device to operate with\n");
return -1;
}
cprintf("Using device %s (dev=%04x)\n",DISKDEVICE,dev);
 
blk=0;
for (;;) {
cprintf("Commands: x-exit r-read n-next block p-prev block\n");
c = keyb_getchar();
switch(c) {
case 'x':
return 0;
 
case 'n':
blk++;
cprintf("Block %li\n",(long)blk);
break;
 
case 'p':
if (blk>=0) blk--;
cprintf("Block %li\n",(long)blk);
break;
case 'r':
cprintf("Reading block %li...\n",(long)blk);
memset(buffer,0xff,sizeof(buffer));
res=bdev_read(dev,blk,buffer);
cprintf("Result %i\n",res);
//cprintf("Soft reset done %i\n",ide[0].errors);
if (res!=0) {
cprintf(" %s\n",(char*)ide_error_msg[-res]);
}
debug_dump_buffer(buffer,64);
break;
 
default:
cprintf("Invalid command!\n");
break;
}
cprintf("\n");
}
return 0;
}
/demos/trunk/oldexamples/block/idelin.c
0,0 → 1,71
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <kernel/func.h>
 
#include <fs/bdevinit.h>
#include <fs/bdev.h>
 
#include <stdlib.h>
#include <string.h>
 
#include "common.h"
 
#define DISKDEVICE "ide/hda"
 
#define TEST_MB 16
 
#define NUMBLOCK (TEST_MB*1024l*1024l/512l)
 
__dev_t dev;
 
__uint8_t buffer[2048];
 
int main(int argc,char *argv[])
{
__blkcnt_t blk;
int res;
int errors;
TIME sttime,etime;
 
showmessage("\n"
"This test read data from first hard disk to test\n"
"disk throughtput.\n"
"Remeber that the reads are made block by block so\n"
"don't worry if you see a low throughtput.\n"
);
dev=bdev_find_byname(DISKDEVICE);
if (dev<0) {
cprintf("\nCan't find device to operate with\n");
return -1;
}
cprintf("\nUsing device %s (dev=%04x)\n",DISKDEVICE,dev);
 
cprintf("Please wait (reading %i MB linearly?!?)...",TEST_MB);
 
sttime=sys_gettime(NULL);
errors=0;
for (blk=0;blk<NUMBLOCK;blk++) {
res=bdev_read(dev,blk,buffer);
//res=bdev_seek(dev,blk);
if (res!=0) errors++;
}
etime=sys_gettime(NULL)-sttime;
 
cprintf("\nDone\n\n");
cprintf("elapse time : %li sec %li msec\n",
etime/1000000l,
(etime/1000l)%1000l);
cprintf("throughtput : %6.3f MB/s\n",
NUMBLOCK*512.0/1024.0/1024.0/etime*1000000.0);
//cprintf("soft reset made: %i\n",ide[0].errors);
cprintf("errors : %i\n",errors);
cprintf("\n");
return 0;
}
/demos/trunk/oldexamples/block/idetest3.c
0,0 → 1,66
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <drivers/keyb.h>
 
#include <fs/bdevinit.h>
#include <fs/bdev.h>
 
#include <string.h>
 
#include "common.h"
 
#define DISKDEVICE "ide/hda1"
#define BLOCKNUMBER 58549
 
__uint8_t buffer[2048] __attribute__ ((aligned (4)));
 
extern char *ide_error_msg[];
 
int main(int argc,char *argv[])
{
__dev_t dev;
__blkcnt_t blk;
int res;
// int c;
 
showmessage("This test tries to read a block from the first hard disk\n"
"and then it tries to write it to disk\n"
"Press [CTRL-C] to abort...");
dev=bdev_find_byname(DISKDEVICE);
if ((int)dev<0) {
cprintf("Can't find device to operate with\n");
cprintf("%s not present!\n",DISKDEVICE);
return -1;
}
cprintf("Using device %s (dev=%04x)\n",DISKDEVICE,dev);
blk=BLOCKNUMBER;
 
cprintf("Reading block %li...\n",(long)blk);
memset(buffer,0xff,sizeof(buffer));
res=bdev_read(dev,blk,buffer);
cprintf("Result %i\n",res);
//cprintf("Soft reset done %i\n",ide[0].errors);
if (res!=0) {
cprintf(" %s\n",(char*)ide_error_msg[-res]);
return -1;
}
debug_dump_buffer(buffer,64);
 
cprintf("Writing block %li...\n",(long)blk);
res=bdev_write(dev,blk,buffer);
cprintf("Result %i\n",res);
//cprintf("Soft reset done %i\n",ide[0].errors);
if (res!=0) {
cprintf(" %s\n",(char*)ide_error_msg[-res]);
}
 
waitend();
return 0;
}
/demos/trunk/oldexamples/block/idetx430.c
0,0 → 1,79
/*
*
*
*
*/
 
#include <ll/ll.h>
#include <ll/stdlib.h>
#include <kernel/func.h>
#include <drivers/keyb.h>
 
#include <fs/bdevinit.h>
#include <fs/util.h>
#include <fs/bdev.h>
 
#include "../ide.h"
#include "../debug.h"
 
#define DISKDEVICE "ide/hda1"
 
#define NUMBLOCK 1000
 
__dev_t dev;
 
int __bdev_sub_init(void)
{
BDEV_PARMS bdev=BASE_BDEV;
bdev_def_showinfo(bdev,TRUE);
bdev_init(&bdev);
dev=bdev_find_byname(DISKDEVICE);
if (dev<0) {
cprintf("Can't find device to operate with\n");
sys_end();
return -1;
}
cprintf("Using device %s (dev=%04x)\n",DISKDEVICE,dev);
return 0;
}
 
int __fs_sub_init(void)
{
return 0;
}
 
__uint8_t buffer[2048];
 
int main(int argc,char *argv[])
{
__blkcnt_t blk;
int res;
int c,i,errors;
TIME sttime,etime;
cprintf("Press a key to continue\n\n");
c=keyb_getchar();
cprintf("Please wait (reading 100 blocks for 10 times)...");
 
sttime=sys_gettime(NULL);
errors=0;
for (blk=0;blk<100;blk++) {
for (i=0;i<10;i++) {
res=bdev_read(dev,blk,buffer);
if (res!=0) errors++;
}
}
etime=sys_gettime(NULL)-sttime;
 
cprintf("\nDone\n\n");
cprintf("elapse time : %li sec %li msec\n",
etime/1000000l,
(etime/1000l)%1000l);
cprintf("soft reset made: %i\n",ide[0].errors);
cprintf("errors : %i\n",errors);
cprintf("\n");
return 0;
}
/demos/trunk/oldexamples/block/idernd.c
0,0 → 1,68
/*
*
*
*
*/
 
#include <ll/i386/cons.h>
#include <kernel/func.h>
 
#include <fs/bdevinit.h>
#include <fs/bdev.h>
 
#include <stdlib.h>
#include <string.h>
 
#include "common.h"
 
#define DISKDEVICE "ide/hda1"
 
#define NUMBLOCK 1000
 
__dev_t dev;
__uint8_t buffer[2048];
 
int main(int argc,char *argv[])
{
__blkcnt_t blk;
int res;
int errors;
TIME sttime,etime;
showmessage("\n"
"This test read RAMDOMLY data from first hard disk to test\n"
"disk throughtput.\n"
"Remeber that the reads are made RANDOMLY block by block so\n"
"don't worry if you see a VERY low throughtput.\n"
);
srand(7);
 
dev=bdev_find_byname(DISKDEVICE);
if (dev<0) {
cprintf("\nCan't find device to operate with\n");
return -1;
}
cprintf("\nUsing device %s (dev=%04x)\n",DISKDEVICE,dev);
 
cprintf("Please wait (reading %i KB ramdomly)...",NUMBLOCK/2);
 
sttime=sys_gettime(NULL);
errors=0;
for (blk=0;blk<NUMBLOCK;blk++) {
res=bdev_read(dev,rand()%5000,buffer);
if (res!=0) errors++;
}
etime=sys_gettime(NULL)-sttime;
 
cprintf("\nDone\n\n");
cprintf("elapse time : %li sec %li msec\n",
etime/1000000l,
(etime/1000l)%1000l);
cprintf("throughtput : %6.3f KB/s\n",
NUMBLOCK*512.0/1024.0/etime*1000000.0);
//cprintf("soft reset made: %i\n",ide[0].errors);
cprintf("errors : %i\n",errors);
cprintf("\n");
return 0;
}
/demos/trunk/oldexamples/block/common.c
0,0 → 1,75
 
#include <kernel/func.h>
 
#include <fs/bdevinit.h>
#include <fs/fsinit.h>
#include <fs/bdev.h>
 
#include <drivers/keyb.h>
 
#include <sys/mount.h>
 
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
 
/* -- */
 
int __register_sub_init(void)
{
return 0;
}
 
/* -- */
 
int __bdev_sub_init(void)
{
BDEV_PARMS bdev=BASE_BDEV;
bdev_def_showinfo(bdev,TRUE);
bdev_init(&bdev);
 
return 0;
}
 
/* -- */
 
void ctrlc_exit(KEY_EVT *k)
{
//sys_status(SCHED_STATUS);
cprintf("CTRL-C pressed!\n");
sys_end();
}
 
/* -- */
 
void showmessage(char *s)
{
cputs(s);
cprintf("Press [x] to begin...");
while (keyb_getchar()!='x');
cprintf("\n");
}
 
void waitend(void)
{
int c;
cprintf("Press [x] to exit...");
while ((c=keyb_getchar())!='x');
cprintf("\n");
}
 
/* -- */
 
void debug_dump_buffer(char *buf, int size)
{
int i;
for (i=0;i<size;i++) {
if (i%16==0) {
if (i!=0) cprintf("\n");
cprintf("%04x: ",i);
}
cprintf("%02x ",(unsigned char)*(buf+i));
}
cprintf("\n");
}
/demos/trunk/oldexamples/block/common.h
0,0 → 1,11
 
#ifndef __COMMON_H
#define __COMMON_H
 
void showmessage(char *s);
void waitend(void);
 
void debug_dump_buffer(char *buf, int size);
 
#endif
/demos/trunk/oldexamples/mpeg/initfs.c
File deleted