Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1616 → Rev 1617

/demos/tags/rel_1_5_4/orbit/orbit.dat
0,0 → 1,21
----------------------------------------------------
period: 10000 wcet: 100
delta: 1. scala: 150.
G: 6.6e-15
r_pianeta: 4 r_Terra: 8
X_centro: 320 Y_centro: 240
 
------------------- pianeti ------------------------
massa pos.x pos.y vel.x vel.y
0: 6.0e21 0. 0. 0. 0.
1: 1.0e21 10000. 8000. -60. 0.
2: 1.0e8 5000. 0. 0. 80.
3: 5.0e18 10000. 8000. -50. 0.
4: 1.0e9 10000. 8000. -40. 20.
5: 1.0e15 1000. 5000. -80. 0.
6: 1.0e5 1000. 5000. -80. 0.
7: 1.0e17 1000. 5000. -80. 0.
8: 1.0e5 1000. 5000. -80. 0.
9: 1.0e5 1000. 5000. -80. 0.
10: 1.0e5 1000. 5000. -80. 0.
----------------------------------------------------
/demos/tags/rel_1_5_4/orbit/initfile.c
0,0 → 1,200
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* Tullio Facchinetti <tullio.facchinetti@unipv.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* 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 "intdrive/intdrive/intdrive.h"
#include "edf/edf/edf.h"
#include "hardcbs/hardcbs/hardcbs.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
 
#include "sem/sem/sem.h"
#include "hartport/hartport/hartport.h"
#include "cabs/cabs/cabs.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_pci26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#define FRAME_BUFFER_DEVICE 0
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 2000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
LEVEL EDF_level;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_level = EDF_register_level(EDF_ENABLE_ALL);
HCBS_register_level(HCBS_ENABLE_ALL, EDF_level);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
CABS_register_module();
 
//read_file();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(1);
}
 
}
 
int device_drivers_init() {
 
int res;
KEYB_PARMS kparms = BASE_KEYB;
LINUXC26_register_module(TRUE);
 
PCI26_init();
 
INPUT26_init();
 
keyb_def_ctrlC(kparms, NULL);
 
KEYB26_init(&kparms);
 
FB26_init();
res = FB26_open(FRAME_BUFFER_DEVICE);
if (res) {
cprintf("Error: Cannot open graphical mode\n");
KEYB26_close();
INPUT26_close();
exit(1);
}
FB26_use_grx(FRAME_BUFFER_DEVICE);
FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
return 0;
 
}
 
int device_drivers_close() {
FB26_close(FRAME_BUFFER_DEVICE);
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
/demos/tags/rel_1_5_4/orbit/orbit.c
0,0 → 1,351
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
------------
CVS : $Id: orbit.c,v 1.9 2005-01-08 14:34:48 pj Exp $
 
File: $File$
Revision: $Revision: 1.9 $
Last update: $Date: 2005-01-08 14:34:48 $
------------
*/
 
/*
* Copyright (C) 2000 Giorgio Buttazzo and 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
*
*/
 
/****************************************************************/
/* SIMULAZIONE DI MASSE CHE ORBITANO */
/****************************************************************/
 
#include <kernel/kern.h>
#include <semaphore.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
#include <drivers/shark_fb26.h>
#include <drivers/shark_keyb26.h>
 
#define MAX 11 /* numero massimo pianeti */
#define XMAX 639 /* valore massimo coordinata X */
#define YMAX 479 /* valore massimo coordinata Y */
 
extern int vga16color[16];
 
struct coord {
double x;
double y;
};
 
int flen; // file length
 
double mass[MAX]; /* vettore masse pianeti */
struct coord pos[MAX]; /* vettore posizioni attuali */
struct coord vel[MAX]; /* vettore velocita' iniziali */
 
int XGS, YGS; /* Coordinate centro spazio */
int RP, RT; /* raggio pianeta, raggio Terra */
int np; /* numero attuale di pianeti */
double G; /* Gravitazione Universale */
double tick; /* tick di sistema */
double delta; /* incremento temporale */
double scala; /* fattore grafico di scala */
 
char fbuf[1000] ="\
----------------------------------------------------\n\
period: 10000 wcet: 500\n\
delta: 1. scala: 150.\n\
G: 6.6e-15\n\
r_pianeta: 4 r_Terra: 8\n\
X_centro: 320 Y_centro: 240\n\
------------------- pianeti ------------------------\n\
massa pos.x pos.y vel.x vel.y\n\
0: \t 6.0e21 \t 0. \t 0. \t 0. \t 0. \n\
1: \t 1.0e21 \t 10000. \t 8000. \t -60. \t 0. \n\
2: \t 1.0e8 \t 5000. \t 0. \t 0. \t 80. \n\
3: \t 5.0e18 \t 10000. \t 8000. \t -50. \t 0. \n\
4: \t 1.0e9 \t 10000. \t 8000. \t -40. \t 20. \n\
5: \t 1.0e15 \t 1000. \t 5000. \t -80. \t 0. \n\
6: \t 1.0e5 \t 1000. \t 5000. \t -80. \t 0. \n\
7: \t 1.0e17 \t 1000. \t 5000. \t -80. \t 0. \n\
8: \t 1.0e5 \t 1000. \t 5000. \t -80. \t 0. \n\
9: \t 1.0e5 \t 1000. \t 5000. \t -80. \t 0. \n\
10: \t 1.0e5 \t 1000. \t 5000. \t -80. \t 0. \n\
----------------------------------------------------\n";
 
// -------------------------------------------------------
// NOTA: %f o %lf significa double e %nf significa float
// -------------------------------------------------------
 
PID pid;
int period; /* task period */
int wcet; /* task wcet */
sem_t mutex; /* semaforo di mutua esclusione */
 
 
void get_par(void);
 
/*--------------------------------------------------------------*/
 
int inside(int x, int y)
{
return ((x > RP) && (x < XMAX-RP) &&
(y > RP) && (y < YMAX-RP));
}
 
/*--------------------------------------------------------------*/
 
TASK massa(void *xxx)
{
int i = (int)xxx; /* parametro del task */
int gx, gy; /* coordinate grafiche pallina */
int ox, oy; /* vecchia posizione pallina */
int j;
int r, col; /* raggio e colore pianeta */
double dt; /* incremento temporale */
double dist=0.0, dx, dy; /* distanze pianeta-pianeta */
double dist0=0.0; /* distanze pianeta-Terra */
double x, y; /* posizione del pianeta */
double vx, vy; /* velocita' del pianeta */
double ax, ay; /* accelerazione del pianeta */
double k; /* variabile ausiliaria */
double arg; /* variabile di appoggio */
 
x = pos[i].x; y = pos[i].y;
vx = vel[i].x; vy = vel[i].y;
ox = XGS + x / scala;
oy = YGS + y / scala;
dt = delta;
 
do {
x = pos[i].x;
y = pos[i].y;
ax = ay = 0.0;
for (j=0; j<np; j++) {
if (j != i) {
dx = pos[j].x - x;
dy = pos[j].y - y;
arg = dx*dx + dy*dy;
dist = sqrt(arg);
if (dist < RP*scala) dist = RP*scala;
k = G * mass[j] / (dist*dist*dist);
ax += k * dx;
ay += k * dy;
}
if (j == 0) dist0 = dist - (RP+RT)*scala;
}
x += vx*dt + 0.5*ax*dt*dt;
y += vy*dt + 0.5*ay*dt*dt;
vx += ax * dt;
vy += ay * dt;
 
gx = XGS + x / scala;
gy = YGS + y / scala;
 
r = RP;
col = i + 1;
 
sem_wait(&mutex);
grx_disc(ox,oy,r,vga16color[0]);
grx_disc(gx,gy,r,vga16color[col]);
sem_post(&mutex);
 
pos[i].x = x; pos[i].y = y;
ox = gx; oy = gy;
 
task_endcycle();
 
} while ((dist0 > 0) && inside(gx,gy));
 
sem_wait(&mutex);
grx_disc(ox,oy,r,vga16color[0]);
grx_disc(XGS,YGS,RT,vga16color[12]);
grx_circle(XGS,YGS,RT,vga16color[14]);
sem_post(&mutex);
 
return NULL;
}
 
/*--------------------------------------------------------------*/
/* MAIN */
/*--------------------------------------------------------------*/
 
int main()
{
HARD_TASK_MODEL m;
char c; /* carattere letto da tastiera */
 
sem_init(&mutex,0,1);
 
get_par();
 
grx_disc(XGS,YGS,RT,vga16color[12]);
grx_circle(XGS,YGS,RT,vga16color[14]);
 
np = 0;
 
do {
if (np < MAX-1) {
np++;
hard_task_default_model(m);
hard_task_def_arg (m, (void *)np);
hard_task_def_wcet (m, wcet);
hard_task_def_mit (m, period);
hard_task_def_usemath (m);
pid = task_create("massa", massa, &m, NULL);
if (pid == NIL) {
sys_shutdown_message("Could not create task");
exit(1);
}
task_activate(pid);
}
c = keyb_getch(BLOCK);
 
} while (c != ESC);
 
exit(1);
 
return 0;
}
 
/*------------------------------------------------------*/
/* file reading */
/*------------------------------------------------------*/
 
void read_file(void)
{
int err;
DOS_FILE *fp;
 
fp = DOS_fopen("orbit.dat","r");
 
if (!fp) {
err = DOS_error();
cprintf("Error %d opening myfile.txt...\n", err);
flen = 0;
return;
}
 
flen = DOS_fread(&fbuf, 1, 1000, fp);
cprintf("Read %d bytes from orbit.dat\n", flen);
 
DOS_fclose(fp);
}
 
/*------------------------------------------------------*/
/* get data from buffer */
/*------------------------------------------------------*/
 
void get_par(void)
{
int x = 0;
int i;
double vx, vy, px, py;
flen = strlen(fbuf);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &period);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &wcet);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%lf", &delta);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%lf", &scala);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%lf", &G);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &RP);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &RT);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &XGS);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &YGS);
 
for (i=0; i<MAX; i++) {
 
mass[i] = 0.;
px = 0.;
py = 0.;
vx = 0.;
vy = 0.;
 
while ((fbuf[x] != '\t') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%lf", &mass[i]);
 
while ((fbuf[x] != '\t') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%lf", &px);
 
while ((fbuf[x] != '\t') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%lf", &py);
 
while ((fbuf[x] != '\t') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%lf", &vx);
 
while ((fbuf[x] != '\t') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%lf", &vy);
 
pos[i].x = px; pos[i].y = py;
 
vel[i].x = vx; vel[i].y = vy;
 
}
}
 
/*--------------------------------------------------------------*/
 
/demos/tags/rel_1_5_4/orbit/makefile
0,0 → 1,16
#
#
#
 
ifndef BASE
BASE=../..
endif
include $(BASE)/config/config.mk
 
PROGS= orbit
 
include $(BASE)/config/example.mk
 
orbit:
make -f $(SUBMAKE) APP=orbit INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__"
 
/demos/tags/rel_1_5_4/mix/mix.dat
0,0 → 1,12
TASK NAME PERIOD WCET
------------------------------------------
task1 watch: 1000000 200
task2 tasto: 2000 200
task3 palla: 2000 200
task4 mosca: 20000 200
task5 infor: 20000 300
task6 ruota: 5000 400
task7 color: 2000 200
task8 pendo: 5000 400
------------------------------------------
 
/demos/tags/rel_1_5_4/mix/readme
0,0 → 1,7
MIX
---
 
This simple applications is a pout-pourri of simple graphic tasks
that does different things with different timing constraints...
 
Paolo
/demos/tags/rel_1_5_4/mix/initfile.c
0,0 → 1,200
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* Tullio Facchinetti <tullio.facchinetti@unipv.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* 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 "intdrive/intdrive/intdrive.h"
#include "edf/edf/edf.h"
#include "hardcbs/hardcbs/hardcbs.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
 
#include "sem/sem/sem.h"
#include "hartport/hartport/hartport.h"
#include "cabs/cabs/cabs.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_pci26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#define FRAME_BUFFER_DEVICE 0
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 2000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
LEVEL EDF_level;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_level = EDF_register_level(EDF_ENABLE_ALL);
HCBS_register_level(HCBS_ENABLE_ALL, EDF_level);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
CABS_register_module();
 
//read_file();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(1);
}
 
}
 
int device_drivers_init() {
 
int res;
KEYB_PARMS kparms = BASE_KEYB;
LINUXC26_register_module(TRUE);
 
PCI26_init();
 
INPUT26_init();
 
keyb_def_ctrlC(kparms, NULL);
 
KEYB26_init(&kparms);
 
FB26_init();
res = FB26_open(FRAME_BUFFER_DEVICE);
if (res) {
cprintf("Error: Cannot open graphical mode\n");
KEYB26_close();
INPUT26_close();
exit(1);
}
FB26_use_grx(FRAME_BUFFER_DEVICE);
FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
return 0;
 
}
 
int device_drivers_close() {
FB26_close(FRAME_BUFFER_DEVICE);
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
/demos/tags/rel_1_5_4/mix/mix.c
0,0 → 1,766
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
------------
CVS : $Id: mix.c,v 1.7 2005-01-08 14:33:10 pj Exp $
 
File: $File$
Revision: $Revision: 1.7 $
Last update: $Date: 2005-01-08 14:33:10 $
------------
*/
 
/*
* Copyright (C) 2000 Giorgio Buttazzo and 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
*
*/
 
/*--------------------------------------------------------------*/
/* DEMO with 9 INDEPENDENT TASKS */
/*--------------------------------------------------------------*/
 
#include <kernel/kern.h>
 
#include <drivers/shark_fb26.h>
#include <drivers/shark_keyb26.h>
 
#include <semaphore.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#define PIG 3.1415
#define DURATA 10000 /* counter duration in tick */
 
#define LW 200 /* window length */
#define HW 150 /* window height */
#define HLOAD 30 /* Y level for the max load */
#define LLOAD (HW-HLOAD-5) /* length for the max load */
 
#define XWL 10 /* left X of LEFT window */
#define XWM 220 /* left X of MIDDLE window */
#define XWR 430 /* left X RIGHT window */
 
#define YWH 5 /* top Y of HIGH window */
#define YWM 165 /* top Y of MIDDLE window */
#define YWL 325 /* top Y of LOW window */
 
int flen = 0; /* file length */
int fine = 0; /* ending flag */
 
sem_t mx_mat, mx_grf; /* mutex semaphores */
 
int wcet[10]; /* array of task wcets */
int period[10]; /* array of task periods */
double load(long); /* load evaluation function */
 
PID ptas;
char talk[5][25] = {" SHARK Demonstration ",
" RETIS Lab -- Scuola ",
" Superiore S. Anna ",
" HARD REAL-TIME DEMO ",
" June 5, 2001 "};
 
char fbuf[1000] = "\
TASK NAME PERIOD WCET\n\
------------------------------------------\n\
task1 watch: 1000000 200\n\
task2 tasto: 2000 200\n\
task3 palla: 2000 200\n\
task4 mosca: 20000 200\n\
task5 infor: 20000 300\n\
task6 ruota: 5000 400\n\
task7 color: 2000 200\n\
task8 pendo: 5000 400\n\
------------------------------------------\n";
 
extern int vga16color[16];
 
/*------------------------------------------------------*/
/* file reading */
/*------------------------------------------------------*/
 
void read_file(void)
{
int err;
DOS_FILE *fp;
 
fp = DOS_fopen("mix.dat","r");
 
if (!fp) {
err = DOS_error();
cprintf("Error %d opening myfile.txt...\n", err);
flen = 0;
return;
}
 
flen = DOS_fread(&fbuf, 1, 1000, fp);
cprintf("Read %d bytes from file\n", flen);
DOS_fclose(fp);
}
 
/*------------------------------------------------------*/
/* get data from buffer */
/*------------------------------------------------------*/
 
void get_par(void)
{
int x = 0;
int i;
 
flen = strlen(fbuf);
 
for (i=1; i<=8; i++) {
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d %d", &period[i], &wcet[i]);
}
}
 
/*--------------------------------------------------------------*/
 
void finish1()
{
exit(1);
}
 
/*--------------------------------------------------------------*/
 
void finish2()
{
fine = 1;
}
 
/****************************************************************/
/* PROCESSO OROLOGIO */
/****************************************************************/
 
#define LLAN 40 /* length of watch stick */
 
TASK watch()
{
int x0 = XWL + LW/2;
int y0 = YWH + HW/2;
int grad;
int xg, yg;
int xt, yt, d;
int sec, min;
char s[5];
double rad, x, y;
 
xg = x0;
yg = y0 - LLAN;
xt = XWL + 78;
yt = YWH + 12;
sec = min = 0;
 
while (1) {
sec = (sec + 1) % 60;
if (sec == 0) min++;
grad = 90 - sec * 6;
rad = (double)grad * PIG / 180.;
 
sem_wait(&mx_mat);
x = (double)x0 + (double)LLAN * cos(rad);
y = (double)y0 - (double)LLAN * sin(rad);
sem_post(&mx_mat);
 
sem_wait(&mx_grf);
grx_line(x0, y0, xg, yg, vga16color[0]);
sem_post(&mx_grf);
 
xg = x;
yg = y;
 
sem_wait(&mx_grf);
grx_line(x0, y0, xg, yg, vga16color[14]);
sem_post(&mx_grf);
 
sem_wait(&mx_grf);
grx_text("0 :0 ", xt, yt, vga16color[14], vga16color[0]);
sprintf(s, "%d", min);
grx_text(s, xt+8, yt, vga16color[14], vga16color[0]);
sprintf(s, "%d", sec);
if (sec > 9) d = 24; else d = 32;
grx_text(s, xt+d, yt, vga16color[14], vga16color[0]);
sem_post(&mx_grf);
 
task_endcycle();
}
}
 
/****************************************************************/
/* PROCESSO DI RIEMPIMENTO */
/****************************************************************/
 
#define CIMA (YWH+5) /* fondo del recipiente */
#define FONDO (YWH+HW-5) /* cima del recipiente */
#define LREC (XWM+75) /* lato sinistro recipiente */
#define DREC 50 /* diametro del recipiente */
 
TASK tasto()
{
int x, y;
int x0; /* coord. sinistra recipiente */
int col, cliq, bkg;
int i;
int liv; /* livello del liquido */
 
cliq = 9;
bkg = 14;
x0 = LREC;
x = x0 + DREC/2;
y = CIMA;
liv = FONDO;
 
while (1) {
 
col = cliq;
for (i=0; i<2; i++) { /* disegna goccia */
while (y < liv) {
sem_wait(&mx_grf);
grx_plot(x,y,vga16color[col]);
sem_post(&mx_grf);
y++;
}
y = CIMA;
col = bkg;
}
 
liv--;
sem_wait(&mx_grf);
grx_line(x0+1, liv, x0+DREC-1, liv, vga16color[cliq]);
sem_post(&mx_grf);
 
if (liv <= CIMA+1) { /* swap colors */
i = bkg; bkg = cliq; cliq = i;
liv = FONDO;
}
 
task_endcycle();
}
}
 
/****************************************************************/
 
void kboar()
{
task_activate(ptas);
}
 
/****************************************************************/
/* PROCESSO PALLA */
/****************************************************************/
 
#define VMIN 11. /* velocit… minima per suono */
#define LP 3 /* lato della pallina */
 
TASK palla()
{
int ox, oy; /* vecchia posizione pallina */
int x0; /* posizione iniziale pallina */
int xmin, xmax;
int base, top;
int xg, yg; /* coordinate grafiche pallina */
double x, y; /* coordinate pallina */
double G = 9.8;
double vx, vy, v0; /* velocit… della pallina */
double t, tx; /* variabile temporale */
double dt; /* incremento temporale */
double arg; /* variabile di appoggio */
 
xmin = XWR+LP+1;
xmax = XWR+LW-LP-1;
base = YWH+HW-LP-1;
top = HW-10-LP;
x = ox = x0 = xmin;
y = oy = top;
arg = 2.*G*(double)top;
vy = v0 = sqrt(arg);
vx = 15.;
tx = 0.0;
t = vy / G;
dt = .02;
 
while (1) {
x = x0 + vx*tx;
y = base - vy*t + .5*G*t*t;
if (y >= base) {
t = 0.0;
vy = v0;
y = base - vy*t + .5*G*t*t;
}
if (x >= xmax) {
tx = 0.0;
x0 = xmax;
vx = -vx;
x = x0 + vx*tx;
}
if (x <= xmin) {
tx = 0.0;
x0 = xmin;
vx = -vx;
x = x0 + vx*tx;
}
xg = x; yg = y;
sem_wait(&mx_grf);
grx_disc(ox,oy,LP,vga16color[0]);
grx_disc(xg,yg,LP,vga16color[10]);
sem_post(&mx_grf);
oy = yg; ox = xg;
t += dt;
tx += dt;
task_endcycle();
}
}
 
/****************************************************************/
/* PROCESSO MOSCA */
/****************************************************************/
 
TASK mosca()
{
int x, y, Ax, Ay, h;
int x0, y0, tet;
int xmax,ymax;
double A, B;
double r;
double rnd;
 
xmax = LW/2-1; ymax = HW/2-1;
x = 0; y = 0; tet = 0;
x0 = XWL+LW/2; y0 = YWM+HW/2;
A = 5.; B = 30.;
 
while (1) {
 
rnd = (rand()%100)/100.; /* rnd = [0,1] */
h = (2. * B * rnd) - B; /* h = [-B,B] */
tet = tet + h;
 
if (tet > 360) tet = tet - 360;
if (tet < 0) tet = tet + 360;
r = tet * PIG / 180.;
 
sem_wait(&mx_mat);
Ax = (double)(A * cos(r));
Ay = (double)(A * sin(r));
sem_post(&mx_mat);
x = x + Ax;
y = y + Ay;
 
if ((x >= xmax) || (x <= -xmax) ||
(y >= ymax) || (y <= -ymax)) {
x = x - Ax;
y = y - Ay;
tet = tet - 180;
if (tet > 360) tet = tet - 360;
if (tet < 0) tet = tet + 360;
r = tet * PIG / 180.;
sem_wait(&mx_mat);
Ax = (double)(A * cos(r));
Ay = (double)(A * sin(r));
sem_post(&mx_mat);
x = x + Ax;
y = y + Ay;
}
sem_wait(&mx_grf);
grx_plot(x+x0, y+y0, vga16color[10]);
sem_post(&mx_grf);
task_endcycle();
}
}
 
/****************************************************************/
/* PROCESSO INFORMAZIONI */
/****************************************************************/
 
TASK infor()
{
char s[2];
int x, y;
int r;
int i = 0;
int leng;
int col = 0;
 
r = 0;
x = XWM + 16;
y = YWM + 40;
s[1] = 0;
 
leng = 0;
while (talk[0][leng] != 0) leng++;
 
while (1) {
s[0] = talk[r][i];
sem_wait(&mx_grf);
grx_text(s,x+i*8,y+r*8,vga16color[col+10],vga16color[1]);
sem_post(&mx_grf);
i++;
if (i == leng) {
i = 0;
r = (r + 1) % 5;
if (r == 0) col = (col + 1) % 6;
}
task_endcycle();
}
}
 
/****************************************************************/
/* PROCESSO RUOTA */
/****************************************************************/
 
TASK ruota()
{
int x0 = XWR + LW/2;
int y0 = YWM + HW/2;
int grad = 90;
int xg, yg;
double rad, x, y;
 
xg = x0;
yg = y0 + LLAN;
 
while (1) {
 
rad = (double)grad * PIG / 180.;
 
sem_wait(&mx_mat);
x = (double)x0 + (double)LLAN * cos(rad);
y = (double)y0 + (double)LLAN * sin(rad);
sem_post(&mx_mat);
 
sem_wait(&mx_grf);
grx_disc(xg, yg, 4, vga16color[0]);
sem_post(&mx_grf);
 
xg = x; yg = y;
 
sem_wait(&mx_grf);
grx_disc(xg, yg, 4, vga16color[13]);
sem_post(&mx_grf);
 
grad = (grad + 1) % 360;
 
task_endcycle();
}
}
 
/****************************************************************/
/* PROCESSO COLORI */
/****************************************************************/
 
TASK color()
{
int xx0 = XWL+5;
int yy0 = YWL+5;
int n, col;
int x, y;
 
x = 0; y = 0;
 
while (1) {
n = 19. * ((rand()%100)/100.);
x = xx0 + n * 10;
n = 14. * ((rand()%100)/100.);
y = yy0 + n * 10;
col = 16. * ((rand()%100)/100.);
 
/* xg = xx0 + x;
yg = yy0 + y;
x = (x + 10)%(LW-10);
y = (y + 10)%(HW-10);
*/
sem_wait(&mx_grf);
grx_box(x, y, x+9, y+9, vga16color[col]);
sem_post(&mx_grf);
 
task_endcycle();
}
}
 
/****************************************************************/
/* PROCESSO PENDOLO */
/****************************************************************/
 
TASK pendo()
{
int x0 = XWM+LW/2;
int y0 = YWL+10;
int xg, yg;
int col = 11;
double x, y, teta;
double v, a, dt;
double g, l;
 
g = 9.8;
l = 80.;
dt = 0.1;
teta = 40. * PIG / 180.;
v = 0.;
sem_wait(&mx_mat);
x = l * sin((double)teta);
y = l * cos((double)teta);
a = -(g/l) * sin((double)teta);
sem_post(&mx_mat);
xg = x0 + x;
yg = y0 + y;
 
while (1) {
 
v += a * dt;
teta += v * dt;
sem_wait(&mx_mat);
x = l * sin((double)teta);
y = l * cos((double)teta);
a = -(g/l) * sin((double)teta);
sem_post(&mx_mat);
 
sem_wait(&mx_grf);
grx_line(x0, y0, xg, yg, vga16color[0]);
grx_circle(xg, yg, 5, vga16color[0]);
grx_disc(xg, yg, 4, vga16color[0]);
sem_post(&mx_grf);
 
xg = x0+x; yg = y0+y;
 
sem_wait(&mx_grf);
grx_line(x0, y0, xg, yg, vga16color[col]);
grx_circle(xg, yg, 5, vga16color[col+2]);
grx_disc(xg, yg, 4, vga16color[col+1]);
sem_post(&mx_grf);
 
task_endcycle();
}
}
 
/****************************** gener ******************************/
 
TASK gener()
{
HARD_TASK_MODEL m;
SOFT_TASK_MODEL am;
PID pid;
 
//---------------------------------------------
hard_task_default_model(m);
hard_task_def_wcet (m, wcet[1]);
hard_task_def_mit (m, period[1]);
hard_task_def_usemath (m);
pid = task_create("watch", watch, &m, NULL);
task_activate(pid);
keyb_getch(BLOCK);
//---------------------------------------------
soft_task_default_model(am);
soft_task_def_met (am, wcet[2]);
soft_task_def_period (am, period[2]);
soft_task_def_aperiodic(am);
soft_task_def_usemath (am);
ptas = task_create("tasto", tasto, &am, NULL);
task_activate(ptas);
keyb_getch(BLOCK);
//---------------------------------------------
hard_task_default_model(m);
hard_task_def_wcet (m, wcet[3]);
hard_task_def_mit (m, period[3]);
hard_task_def_usemath (m);
pid = task_create("palla", palla, &m, NULL);
task_activate(pid);
keyb_getch(BLOCK);
//---------------------------------------------
hard_task_default_model(m);
hard_task_def_wcet (m, wcet[4]);
hard_task_def_mit (m, period[4]);
hard_task_def_usemath (m);
pid = task_create("mosca", mosca, &m, NULL);
task_activate(pid);
keyb_getch(BLOCK);
//---------------------------------------------
hard_task_default_model(m);
hard_task_def_wcet (m, wcet[5]);
hard_task_def_mit (m, period[5]);
hard_task_def_usemath (m);
pid = task_create("infor", infor, &m, NULL);
task_activate(pid);
keyb_getch(BLOCK);
//---------------------------------------------
hard_task_default_model(m);
hard_task_def_wcet (m, wcet[6]);
hard_task_def_mit (m, period[6]);
hard_task_def_usemath (m);
pid = task_create("ruota", ruota, &m, NULL);
task_activate(pid);
keyb_getch(BLOCK);
//---------------------------------------------
hard_task_default_model(m);
hard_task_def_wcet (m, wcet[7]);
hard_task_def_mit (m, period[7]);
hard_task_def_usemath (m);
pid = task_create("color", color, &m, NULL);
task_activate(pid);
keyb_getch(BLOCK);
//---------------------------------------------
hard_task_default_model(m);
hard_task_def_wcet (m, wcet[8]);
hard_task_def_mit (m, period[8]);
hard_task_def_usemath (m);
pid = task_create("pendo", pendo, &m, NULL);
task_activate(pid);
//---------------------------------------------
 
return NULL;
}
 
/****************************** MAIN ******************************/
 
int main()
{
char s[20]; /* carattere letto da tastiera */
int x0, y0;
int x, y;
TIME t1, count; /* contatori valutazione carico */
double car; /* valore del carico corrente */
TIME seme;
PID pid;
NRT_TASK_MODEL m2;
KEY_EVT eva, evx, evs;
 
/* set the keyboard handler */
eva.ascii = 'a';
eva.scan = KEY_A;
eva.flag = 0;
eva.status = KEY_PRESSED;
keyb_hook(eva,kboar,FALSE);
 
evx.ascii = 'x';
evx.scan = KEY_X;
evx.flag = ALTL_BIT;
evx.status = KEY_PRESSED;
keyb_hook(evx,finish1,FALSE);
 
evs.ascii = ESC;
evs.scan = KEY_ESC;
evs.flag = 0;
evs.status = KEY_PRESSED;
keyb_hook(evs,finish2,FALSE);
 
sem_init(&mx_mat,0,1);
sem_init(&mx_grf,0,1);
 
seme = sys_gettime(NULL);
srand(seme);
 
get_par();
 
grx_rect(XWL,YWH,XWL+LW,YWH+HW,vga16color[14]);
grx_rect(XWM,YWH,XWM+LW,YWH+HW,vga16color[14]);
grx_rect(XWR,YWH,XWR+LW,YWH+HW,vga16color[14]);
 
grx_rect(XWL,YWM,XWL+LW,YWM+HW,vga16color[14]);
grx_rect(XWM,YWM,XWM+LW,YWM+HW,vga16color[14]);
grx_rect(XWR,YWM,XWR+LW,YWM+HW,vga16color[14]);
 
grx_rect(XWL,YWL,XWL+LW,YWL+HW,vga16color[14]);
grx_rect(XWM,YWL,XWM+LW,YWL+HW,vga16color[14]);
grx_rect(XWR,YWL,XWR+LW,YWL+HW,vga16color[14]);
 
x0 = XWL + LW/2;
y0 = YWH + HW/2;
grx_circle(x0, y0, LLAN+3, vga16color[12]);
grx_rect(XWL+74, YWH+7, XWL+120, YWH+22, vga16color[12]);
 
x0 = LREC;
grx_line(x0, CIMA, x0, FONDO, vga16color[15]);
grx_line(x0+DREC, CIMA, x0+DREC, FONDO, vga16color[15]);
grx_line(x0, FONDO, x0+DREC, FONDO, vga16color[15]);
grx_box(x0+1, CIMA, x0+DREC-1, FONDO-1, vga16color[14]);
grx_text("Press A", XWM+16, YWH+48, vga16color[10], vga16color[0]);
grx_text("to fill", XWM+16, YWH+64, vga16color[10], vga16color[0]);
 
grx_text("Press:", XWM+18, YWM+HW-50, vga16color[10], vga16color[0]);
grx_text("ESC to exit", XWM+18, YWM+HW-40, vga16color[10], vga16color[0]);
grx_text("SPACE to create", XWM+18, YWM+HW-30, vga16color[10], vga16color[0]);
 
x0 = XWR + LW/2;
y0 = YWM + HW/2;
grx_circle(x0, y0, LLAN/3, vga16color[14]);
grx_disc(x0, y0, LLAN/3-1, vga16color[12]);
 
x0 = XWR+5;
y0 = YWL+HW-5;
grx_line(x0, YWL+HLOAD, x0+LW-10, YWL+HLOAD, vga16color[12]);
grx_text("SYSTEM WORKLOAD:", x0+5, YWL+HLOAD-10, vga16color[10], vga16color[0]);
 
count = 0;
t1 = sys_gettime(NULL);
do count++; while (sys_gettime(NULL) < (t1 + DURATA));
 
nrt_task_default_model(m2);
pid = task_create("gener", gener, &m2, NULL);
task_activate(pid);
 
x = 0;
while (!fine) {
car = load(count);
y = (double)LLOAD*car;
sem_wait(&mx_grf);
grx_line(x0+x, y0-LLOAD+1, x0+x, y0, vga16color[0]);
grx_line(x0+x, y0-y, x0+x, y0, vga16color[15]);
grx_text(" ", x0+LW-60, YWL+HLOAD-10, vga16color[0], vga16color[0]);
sprintf(s, "%.3f", car);
grx_text(s, x0+LW-50, YWL+HLOAD-10, vga16color[15], vga16color[0]);
sem_post(&mx_grf);
x = (x + 1) % (LW-10);
}
 
exit(1);
 
return 0;
}
 
/****************************************************************/
 
double load(long n)
{
TIME i, t1;
double carico;
 
i = 0;
t1 = sys_gettime(NULL);
do i++; while (sys_gettime(NULL) < (t1 + DURATA));
carico = 1. - (double)i / (double)n;
return(carico);
}
 
/****************************************************************/
/demos/tags/rel_1_5_4/mix/makefile
0,0 → 1,16
#
#
#
 
ifndef BASE
BASE=../..
endif
include $(BASE)/config/config.mk
 
PROGS= mix
 
include $(BASE)/config/example.mk
 
mix:
make -f $(SUBMAKE) APP=mix INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__"
 
/demos/tags/rel_1_5_4/pci6025e/readme
0,0 → 1,7
These are the demos available for the National Instruments PCI6025e boards.
 
These demos and the PCI driver have been made by
Marco Ziglioli (zi_mar@libero.it). Please send any comments to:
zi_mar@libero.it or to shark-help@gandalf.sssup.it.
 
Paolo
/demos/tags/rel_1_5_4/pci6025e/test_bms.c
0,0 → 1,262
/*****************************************************************************
* Filename: test_bms.c *
* Author: Marco Ziglioli (Doctor Stein) *
* Date: 27/06/2001 *
* Description: Test program for buffered period and semiperiod measurement *
* capacity of National PCI6025E board *
*----------------------------------------------------------------------------*
* Notes: FOUT are enable and avaiable on pin 50 to provide 1 Mhz frequency *
* You should connect source 0 (PIN 41) and source 1 (pin 45) to this *
* freq source. Gate 0 (pin 42) and gate 1 (pin 44) must be connected *
* rispectivly to DIO7 (pin 32) and DIO6 (pin 30). *
* Use 'g' button to activate gate_action_task which generate a square *
* wave with a freq of 0.5 Hz and Duty cycle of 75%. *
* 's' button should show counters countent but gate_action_task *
* when active shows counters content automatically so 's' button isn't*
* useful. *
*****************************************************************************/
 
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
*
* Copyright (C) 2001 Marco Ziglioli
*
* 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/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#include <drivers/pci6025e/timer.h>
#include <drivers/pci6025e/dio_ppi.h>
 
#define SHOW_MET 30000
#define SHOW_WCET 50000
#define SHOW_PERIOD 1000000
 
#define GATE_MET 2000
#define GATE_WCET 5000
#define GATE_PERIOD 2000000
 
#define GATE_ACTION_P 500000
#define GATE_ACTION_W 10000
 
#define black rgb16(0, 0, 0)
 
void endFun(KEY_EVT *);
void gateEvent(KEY_EVT *);
void showEvent(KEY_EVT *);
 
void closeEvent(void *);
 
void drawInterface(void);
 
TASK show_val_body(int);
TASK gate_action_body(int);
 
BYTE sys = 0;
PID show_val_pid, gate_action_pid;
 
int main(int argc, char **argv)
{
KEY_EVT k;
SOFT_TASK_MODEL show_val_mod;
HARD_TASK_MODEL gate_action_model;
 
k.flag = CNTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, endFun, FALSE);
 
k.flag = CNTR_BIT;
k.status = KEY_PRESSED;
keyb_hook(k, endFun, FALSE);
 
k.flag = 0;
k.scan = KEY_G;
k.ascii = 'g';
k.status = KEY_PRESSED;
keyb_hook(k, gateEvent, FALSE);
 
k.scan = KEY_S;
k.ascii = 's';
k.status = KEY_PRESSED;
keyb_hook(k, showEvent, FALSE);
 
if(!reMap()){
sys = 11;
exit(1);
}
 
soft_task_default_model(show_val_mod);
soft_task_def_aperiodic(show_val_mod);
soft_task_def_level(show_val_mod, 2);
soft_task_def_met(show_val_mod, SHOW_MET);
soft_task_def_wcet(show_val_mod, SHOW_WCET);
soft_task_def_period(show_val_mod, SHOW_PERIOD);
if( (show_val_pid = task_create("Show task", show_val_body, &show_val_mod, NULL))
== NIL ){
sys = 20;
exit(1);
}
 
hard_task_default_model(gate_action_model);
hard_task_def_mit(gate_action_model, GATE_ACTION_P);
hard_task_def_wcet(gate_action_model, GATE_ACTION_W);
if( (gate_action_pid = task_create("Gate Action", gate_action_body, &gate_action_model, NULL))
== NIL ){
sys = 22;
exit(1);
}
 
drawInterface();
 
DIO_init();
DIO_setup(0xFF);
DIO_write(0x00);
 
//All PFI configured as input
PFIprogramming(0x0000);
 
//Fout provide 1MHz: timebase = 20MHz; divided by 2; on FOUT pin also divided by 10
setIntClock(0, 1, 10);
 
//Reset both counters
TIM_reset(2);
 
//C0 measures period on PFI3 with gate from PFI 4 driven by DIO7
TIM_bufferedTimeMeasurement(C0, 0x04, 0x45, 0, 0);
 
//C1 measures semiperiod on PFI 6 with gate from PFI 5 driven by FIO6
TIM_bufferedTimeMeasurement(C1, 0x87, 0x46, 1, 0);
 
//arm both counters
TIM_arm(2);
 
return 0;
}
 
void endFun(KEY_EVT *k)
{
closeEvent(NULL);
 
exit(1);
}
 
void showEvent(KEY_EVT *k)
{
task_activate(show_val_pid);
}
 
void gateEvent(KEY_EVT *k)
{
task_activate(gate_action_pid);
}
 
void drawInterface(void)
{
grx_rect(1, 1, 799, 129, rgb16(105, 0, 0));
grx_rect(2, 2, 798, 128, rgb16(155, 0, 0));
grx_rect(3, 3, 797, 127, rgb16(205, 0, 0));
grx_rect(4, 4, 796, 126, rgb16(255, 0, 0));
 
grx_text("Test program for Buffered Period and Semiperiod measure through PCI6025E timers",
7, 10, rgb16(50, 255, 50), black);
 
grx_text("This program counting rise edges on counters source (PFI3 & PFI6) between two rising",
7, 25, rgb16(0, 255, 255), black);
grx_text("edges on gate (PFI 42) and beetwen each gate edge (PFI44).FOUT is enabled and",
7, 33, rgb16(0, 255, 255), black);
grx_text("provides a frequency of 1 MHz", 7, 41, rgb16(0, 255, 255), black);
grx_text("Instruction:",7, 53, rgb16(255, 0, 0), black);
grx_text("Use 's' to see counters value",
7, 61, rgb16(0, 255, 255), black);
grx_text("Use 'g' to enbale automatic tasks which generate square wave with freq of 0.5Hz",
7, 68, rgb16(0, 255, 255), black);
 
grx_text("And duty cycle of 75%. Counter 0 must be loaded with about 2E6 ticks and counter 1",
7, 75, rgb16(0, 255, 255), black);
grx_text("must be loaded alternativly with about 1.5E6 and 0.5E6 ticks",
7, 83, rgb16(0, 255, 255), black);
 
grx_text("Please connect DIO7 (pin 32) to PFI4 (pin 42) and DIO6 (pin 30) to PFI5 (pin 44)",
7, 95, rgb16(0, 255, 0), black);
grx_text("CTRL-C for Exit", 7, 110, rgb16(200, 200, 0), black);
 
grx_rect(1, 147, 355, 183, rgb16(0, 105, 0));
grx_rect(2, 148, 354, 182, rgb16(0, 155, 0));
grx_rect(3, 149, 353, 181, rgb16(0, 205, 0));
grx_rect(4, 150, 352, 180, rgb16(0, 255, 0));
grx_text("Period", 7, 155, rgb16(255, 255, 0), black);
 
grx_rect(455, 147, 799, 183, rgb16(0, 105, 0));
grx_rect(456, 148, 798, 182, rgb16(0, 155, 0));
grx_rect(457, 149, 797, 181, rgb16(0, 205, 0));
grx_rect(458, 150, 796, 180, rgb16(0, 255, 0));
grx_text("Semiperiod", 461, 155, rgb16(255, 0, 255), black);
}
 
TASK show_val_body(int dummy)
{
DWORD val;
char buf[40];
 
while(1){
val = TIM_readHWSaveReg(C0);
sprintf(buf,"C0 %07ld", val);
grx_text(buf, 7, 165, rgb16(255, 0, 0), rgb16(0, 0, 0));
val = TIM_readHWSaveReg(C1);
sprintf(buf,"C1 %07ld", val);
grx_text(buf, 461, 165, rgb16(0, 255, 0), rgb16(0, 0, 0));
 
task_endcycle();
}
}
 
TASK gate_action_body(int dummy)
{
int i;
i = 0;
 
while(1){
if( (i%4)==0 ) DIO_write(0xC0);
if( (i%4)==3 ) DIO_write(0x00);
 
i++;
 
task_activate(show_val_pid);
 
task_endcycle();
}
}
 
void closeEvent(void *arg)
{
TIM_disarm(2);
switch(sys){
case 0: sys_shutdown_message("Ok\n"); break;
case 10: sys_shutdown_message("No PCI\n"); break;
case 11: sys_shutdown_message("No National Board\n"); break;
case 20: sys_shutdown_message("task <show val> down\n"); break;
case 22: sys_shutdown_message("task <gate action> down\n"); break;
case 30: sys_shutdown_message("Cannot initialize grx\n"); break;
case 31: sys_shutdown_message("Resolution 800x600x16 not supported\n"); break;
case 32: sys_shutdown_message("Cannot sets up graphic envirorment\n"); break;
default: sys_shutdown_message("????????????\n"); break;
}
}
/demos/tags/rel_1_5_4/pci6025e/wave.c
0,0 → 1,312
/*****************************************************************************
* Filename: wave.c *
* Author: Marco Ziglioli (Doctor Stein) *
* Date: 12/06/2001 *
* Description: Little test program for Analog Output section of PCI6025E *
*----------------------------------------------------------------------------*
* Notes: Connect an oscilloscope to DACs output pins (20 & 21) and *
* watch the waveforms. *
* and decrise voltage *
*****************************************************************************/
 
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
*
* Copyright (C) 2001 Marco Ziglioli
*
* 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/shark_fb26.h>
#include <drivers/shark_keyb26.h>
 
#include <sem/sem/sem.h>
 
#include <drivers/pci6025e/dac.h>
 
#define MAX_VAL 500
 
#define WAVE_PERIOD 1000
#define WAVE_WCET 200
#define GRAPH_PERIOD 1000
#define GRAPH_WCET 550
 
#define TASK_GROUP 1
 
#define DAC0_CONV 0.1
#define DAC1_CONV 0.05
 
#define INC 40
 
void createWaves(void);
void drawInterface(void);
 
void endfun(KEY_EVT *);
void close_event(void *);
 
TASK wave_body(int);
TASK video_body(int);
 
WORD wave0[MAX_VAL], wave1[MAX_VAL];
int black = rgb16(0,0,0),
white = rgb16(255, 255, 255);
 
BYTE sys = 0;
 
int main(int argc, char **argv)
{
KEY_EVT k;
HARD_TASK_MODEL wave0, wave1;
HARD_TASK_MODEL video;
PID wave0_pid, wave1_pid, video_pid;
 
k.flag = CNTR_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, endfun, FALSE);
 
k.flag = CNTL_BIT;
k.status = KEY_PRESSED;
keyb_hook(k, endfun, FALSE);
 
hard_task_default_model(wave0);
hard_task_def_wcet(wave0, WAVE_WCET);
hard_task_def_mit(wave0, WAVE_PERIOD);
hard_task_def_arg(wave0, 0);
hard_task_def_group(wave0, TASK_GROUP);
if( (wave0_pid = task_create("Wave 0", wave_body, &wave0, NULL)) == NIL ){
sys = 10;
exit(1);
}
 
hard_task_default_model(wave1);
hard_task_def_wcet(wave1, WAVE_WCET);
hard_task_def_mit(wave1, WAVE_PERIOD);
hard_task_def_arg(wave1, (void *)1);
hard_task_def_group(wave1, TASK_GROUP);
if( (wave1_pid = task_create("Wave 1", wave_body, &wave1, NULL)) == NIL ){
sys = 11;
exit(1);
}
 
hard_task_default_model(video);
hard_task_def_wcet(video, GRAPH_WCET);
hard_task_def_mit(video, GRAPH_PERIOD);
hard_task_def_group(video, TASK_GROUP);
if( (video_pid = task_create("Video task", video_body, &video, NULL))
== NIL ){
sys = 12;
exit(1);
}
 
if(!reMap()){
sys = 21;
exit(1);
}
 
createWaves();
drawInterface();
//Analog output section set up
DAC_Init();
 
/*
*AI_TIMEBASE div by 2; OUT_TIMEBASE div by 2; single DAC mode
*TMRDACWR = 3 OUT_TIMEBASE period; FIFO flags polarity active low
*TMRDACWR disabled; DMA PIO control = FIFO DATA interface mode
*UPDATE signal timebase = AO_UPDATE pulse width
*UPDATE pulsewidth = 3-3.5 OUT_TIMEBASE period
*UPDATE signal polarity = HIGH Z
*/
DAC_boardInit(0x02, 0x4000);
 
/*
*LDAC0 source = UPDATE
*DAC0 update immediately
*LDAC1 source = UPDATE
*DAC1 update immediately
*/
DAC_LDACSourceUpdate(0x00);
//End of Analog output section setup
 
 
group_activate(TASK_GROUP);
 
return 0;
}
 
void endfun(KEY_EVT *k)
{
close_event(NULL);
 
exit(1);
}
 
void close_event(void *arg)
{
switch(sys){
case 0: sys_shutdown_message("Regular End!\n"); break;
case 10: sys_shutdown_message("Cannot create <wave 0> task!\n"); break;
case 11: sys_shutdown_message("Cannot create <wave 1> task!\n"); break;
case 12: sys_shutdown_message("Cannot create <video> task!\n"); break;
case 20: sys_shutdown_message("No PCI bus found!\n"); break;
case 21: sys_shutdown_message("No NATIONAL PCI E-Series board found on PCI bus!\n");
break;
case 30: sys_shutdown_message("Cannot start graphic envirorment!\n"); break;
case 31: sys_shutdown_message("800x600x16 video mode not supported!\n");
default: sys_shutdown_message("Unknown exit event!\n"); break;
}
}
 
/*
* Wave's samples generation
*/
void createWaves(void)
{
int i;
int value0, value1;
BYTE direction;
 
/* Wave0
* * * * * * * *
** ** ** ** ** ** ** **
* ** * * ** ** ** ** ** *
* * ** * * * * * *
--------------------------...
 
Wave 1
* *
* * * *
* * * *
* * * *
-------*-------*-------*--...
* * *
* * *
* *
* */
 
value0 = 0;
value1 = 0;
direction = 0;
for(i=0; i<MAX_VAL; i++){
wave0[i] = (value0 & 0x0FFF);
wave1[i] = (value1 & 0x0FFF);
 
value0 = (value0 + INC) % 2000;
if(!direction) value1 += INC;
else value1 -= INC;
 
if(value1 >= 2000) direction = 1;
if(value1 <= -2000) direction = 0;
}
}
 
void drawInterface(void)
{
int i;
 
grx_rect(1, 1, 799, 69, rgb16(105, 0, 105));
grx_rect(2, 2, 798, 68, rgb16(155, 0, 155));
grx_rect(3, 3, 797, 67, rgb16(205, 0, 205));
grx_rect(4, 4, 796, 66, rgb16(255, 0, 255));
 
grx_text("Test program for Analog output section of PCI6025E",
7, 10, rgb16(50, 255, 50), black);
grx_text("DAC0 and DAC1 should generate saw-toothed wave and triangular wave",
7, 33, rgb16(0, 255, 255), black);
grx_text("Use an oscilloscope to test this software",
7, 40, rgb16(0, 255, 255), black);
 
grx_text("CTRL-C for Exit", 7, 55, rgb16(200, 200, 0), black);
 
grx_text("DAC 0", 100, 92, rgb16(200, 200, 0), black);
grx_rect(1, 100, 799, 325, rgb16(0, 105, 0));
grx_rect(2, 101, 798, 324, rgb16(0, 155, 0));
grx_rect(3, 102, 797, 323, rgb16(0, 205, 0));
grx_rect(4, 103, 796, 322, rgb16(0, 255, 0));
grx_line(19, 115, 19, 320, white);
grx_line(14, 315, 530, 315, white);
 
grx_text("DAC 1", 100, 362, rgb16(200, 200, 0), black);
grx_rect(1, 370, 799, 595, rgb16(105, 0, 0));
grx_rect(2, 371, 798, 594, rgb16(155, 0, 0));
grx_rect(3, 372, 797, 593, rgb16(205, 0, 0));
grx_rect(4, 373, 796, 592, rgb16(255, 0, 0));
grx_line(19, 385, 19, 585, white);
grx_line(14, 485, 530, 485, white);
 
for(i=22; i<530; i+=2){
//DAC0
grx_plot(i, 115, white);
grx_plot(i, 215, white);
//DAC1
grx_plot(i, 385, white);
grx_plot(i, 435, white);
grx_plot(i, 535, white);
grx_plot(i, 585, white);
}
 
grx_text("5 V", 540, 211, rgb16(0, 255, 0), black);
grx_text("10 V", 540, 111, rgb16(0, 255, 0), black);
grx_text("+5 V", 540, 431, rgb16(0, 255, 0), black);
grx_text("+10 V", 540, 381, rgb16(0, 255, 0), black);
grx_text("-5 V", 540, 531, rgb16(255, 0, 0), black);
grx_text("-10 V", 540, 581, rgb16(255, 0 , 0), black);
}
 
/*
* Sends out waves' samples
*/
TASK wave_body(int wv)
{
int i = 0;
while(1){
if(wv)
DAC_output(DAC1, wave1[i]);
else
DAC_output(DAC0, wave0[i]);
 
i = (i + 1) % 500;
task_endcycle();
}
}
 
/*
* Shows wave on screen
*/
TASK video_body(int dummy)
{
int i = 0;
int n_tmp = 0, o_tmp;
//char buf[10];
 
while(1){
o_tmp = n_tmp;
if( (wave1[i] & 0x0800) != 0 ) n_tmp = wave1[i]-0x0FFF;
else n_tmp = wave1[i];
 
if(i>0){
grx_line(19+i, 314-wave0[i-1]*DAC0_CONV,
20+i, 314-wave0[i]*DAC0_CONV, rgb16(255, 255, 0));
grx_line(19+i, 485-o_tmp*DAC1_CONV,
20+i, 485-n_tmp*DAC1_CONV, rgb16(0, 255, 255));
}
 
i = (i + 1) % 500;
task_endcycle();
}
}
/demos/tags/rel_1_5_4/pci6025e/test_mes.c
0,0 → 1,278
/*****************************************************************************
* Filename: test_mes.c *
* Author: Marco Ziglioli (Doctor Stein) *
* Date: 25/06/2001 *
* Description: Test file for single period and pulsewidth measurement feature*
* of PCI6025E timers/counters *
*----------------------------------------------------------------------------*
* Notes: board is configured to provide a frequency of 1 MHZ through its FOUT*
* pin (50). PFI3 (41) and PFI6 (45) are configured like source pins *
* counter 0 and counter 1. PFI4 (42) and PFI 5(44) are the gates for *
* the two counters. Please connect DIO7(32) to PFI4 and DIO6(30) to *
* PFI 5. *
* With 'g' key a task is started which generate a square wave on DIO7 *
* with a period of 2 secs. With 'h' key the same square wave is *
* generated on DIO6. *
* When measurement is performed data are stored into Hardware Save *
* Registers: use key 's' to show this values *
*****************************************************************************/
 
 
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
*
* Copyright (C) 2001 Marco Ziglioli
*
* 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/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#include <drivers/pci6025e/timer.h>
#include <drivers/pci6025e/dio_ppi.h>
 
#define TASK_MET 20000
#define TASK_WCET 50000
#define TASK_PERIOD 100000
 
#define PERIOD 1000000
 
void endFun(KEY_EVT *);
void gateEvent(KEY_EVT *);
 
void drawInterface(void);
void closeEvent(void *);
 
TASK show_body(int);
TASK gate_body(int);
 
BYTE sys = 0;
PID c0_gate_pid, c1_gate_pid, show_pid;
int black = rgb16(0, 0, 0);
 
int main(int argc, char **argv)
{
KEY_EVT k;
SOFT_TASK_MODEL show_model;
HARD_TASK_MODEL gating;
 
k.flag = CNTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, endFun, FALSE);
 
k.flag = CNTR_BIT;
k.status = KEY_PRESSED;
keyb_hook(k, endFun, FALSE);
 
k.flag = 0;
k.scan = KEY_G;
k.ascii = 'g';
k.status = KEY_PRESSED;
keyb_hook(k, gateEvent, FALSE);
 
k.scan = KEY_H;
k.ascii = 'h';
k.status = KEY_PRESSED;
keyb_hook(k, gateEvent, FALSE);
 
k.scan = KEY_S;
k.ascii = 's';
k.status = KEY_PRESSED;
keyb_hook(k, gateEvent, FALSE);
 
if(!reMap()){
sys = 11;
exit(1);
}
 
soft_task_default_model(show_model);
soft_task_def_level(show_model, 2);
soft_task_def_met(show_model, TASK_MET);
soft_task_def_wcet(show_model, TASK_WCET);
soft_task_def_aperiodic(show_model);
soft_task_def_period(show_model, TASK_PERIOD);
if( (show_pid = task_create("Show task", show_body, &show_model, NULL))
== NIL ){
sys = 20;
exit(1);
}
 
hard_task_default_model(gating);
hard_task_def_mit(gating, PERIOD);
hard_task_def_wcet(gating, 20000);
hard_task_def_arg(gating, C0);
if( (c0_gate_pid = task_create("C0 Gate task", gate_body, &gating, NULL)) == NIL ){
sys = 21;
exit(1);
}
 
hard_task_def_arg(gating, (void *)C1);
if( (c1_gate_pid = task_create("C1 Gate task", gate_body, &gating, NULL)) == NIL ){
sys = 22;
exit(1);
}
 
drawInterface();
//Enable DIO to manage gates
DIO_init();
DIO_setup(0xFF);
DIO_write(0x00);
 
//All PFI configured as input
PFIprogramming(0x0000);
//Fout provide 1MHz: timebase = 20MHz; divided by 2; on FOUT pin also divided by 10
setIntClock(0, 1, 10);
 
//Reset both counters
TIM_reset(2);
//Source PFI3(41); Gate PFI 4(42); Measure period
TIM_timeMeasurement(C0, 0x04, 0x45, 0, 0x00, 0);
//Source PFI6(45); Gate PFI 5(44); Measure pulsewidth
TIM_timeMeasurement(C1, 0x87, 0x46, 1, 0x00, 0);
 
//Arm both counter
TIM_arm(2);
 
return 0;
}
 
TASK show_body(int dummy)
{
DWORD val;
char buf[20];
 
while(1){
val = TIM_readHWSaveReg(C0);
sprintf(buf, "%ld", val);
grx_text(buf, 600, 471, rgb16(0, 255, 0), black);
val = TIM_readHWSaveReg(C1);
sprintf(buf, "%ld", val);
grx_text(buf, 200, 471, rgb16(255, 0, 0), black);
 
task_endcycle();
}
}
 
TASK gate_body(int counter)
{
BYTE out;
 
if(counter == C0) out = 0x80;
else out = 0x40;
 
while(1){
DIO_write(out);
if(counter == C0){
if(out) out = 0x00;
else out = 0x80;
} else {
if(out) out = 0x40;
else out = 0x00;
}
 
task_endcycle();
}
}
 
void drawInterface(void)
{
grx_rect(1, 1, 799, 120, rgb16(105, 0, 0));
grx_rect(2, 2, 798, 119, rgb16(155, 0, 0));
grx_rect(3, 3, 797, 118, rgb16(205, 0, 0));
grx_rect(4, 4, 796, 117, rgb16(255, 0, 0));
 
grx_text("Test program for single period and pulsewidth measurement features",
7, 10, rgb16(200, 200, 0), black);
 
grx_text("This program measures single period and pulsewidth of a square wave",
7, 20, rgb16(0, 255, 0), black);
grx_text("with frequency of 0.5 Hz", 7, 28, rgb16(0, 255, 0), black);
grx_text("Please connect PFI3 & PFI6 (41 & 45) to FOUT pin (50) or to 1Mhz frequency source",
7, 40, rgb16(255, 0, 0), black);
grx_text("Connect also DIO7 (32) to PFI4 (42) and DIO6 to PFI5 (44)",
7, 48, rgb16(255, 0, 0), black);
grx_text("Commands:", 7, 60, rgb16(0, 120, 0), black);
grx_text("Use 'g' to start wave generation on DIO7",
7, 70, rgb16(0, 255, 255), black);
grx_text("Use 'h' to start wave generation on DIO6",
7, 78, rgb16(0, 255, 255), black);
grx_text("Use 's' to show Hardware Save Registers content",
7, 86, rgb16(0, 255, 255), black);
grx_text("CTRL-C to exit", 7, 105, rgb16(255, 255, 0), black);
 
grx_rect(197, 127, 603, 423, rgb16(0, 255, 0));
grx_rect(198, 128, 602, 422, rgb16(0, 205, 0));
grx_rect(199, 129, 601, 421, rgb16(0, 155, 0));
grx_rect(200, 130, 600, 420, rgb16(0, 105, 0));
grx_line(215, 405, 215, 150, rgb16(255, 255, 255));
grx_line(210, 400, 580, 400, rgb16(255, 255, 255));
grx_line(220, 395, 220, 170, rgb16(0, 0, 255));
grx_line(220, 170, 390, 170, rgb16(0, 0, 255));
grx_line(390, 170, 390, 395, rgb16(0, 0, 255));
grx_line(390, 395, 560, 395, rgb16(0, 0, 255));
grx_line(220, 150, 560, 150, rgb16(0, 255, 0));
grx_line(220, 155, 390, 155, rgb16(255, 0, 0));
 
grx_rect(1, 450, 390, 503, rgb16(105, 0, 0));
grx_rect(2, 451, 389, 502, rgb16(155, 0, 0));
grx_rect(3, 452, 388, 501, rgb16(205, 0, 0));
grx_rect(4, 453, 387, 500, rgb16(255, 0, 0));
grx_text("Pulsewidth: [us]", 7, 471, rgb16(255, 0, 0), black);
 
grx_rect(410, 450, 799, 503, rgb16(105, 0, 0));
grx_rect(411, 451, 798, 502, rgb16(155, 0, 0));
grx_rect(412, 452, 797, 501, rgb16(205, 0, 0));
grx_rect(413, 453, 796, 500, rgb16(255, 0, 0));
grx_text("Period: [us]", 416, 471, rgb16(0, 255, 0), black);
}
 
void endFun(KEY_EVT *k)
{
closeEvent(NULL);
exit(1);
}
 
void gateEvent(KEY_EVT *k)
{
if(k->scan == KEY_G) task_activate(c0_gate_pid);
if(k->scan == KEY_H) task_activate(c1_gate_pid);
if(k->scan == KEY_S) task_activate(show_pid);
}
 
void closeEvent(void *arg)
{
TIM_disarm(2);
 
switch(sys){
case 0: sys_shutdown_message("OK\n"); break;
case 10: sys_shutdown_message("No PCI bus found\n"); break;
case 11: sys_shutdown_message("No NATIONAL board found\n"); break;
case 20: sys_shutdown_message("task <show value> down!!\n"); break;
case 21: sys_shutdown_message("task <C0 gate manage> down!!!\n"); break;
case 22: sys_shutdown_message("task <C1 gate manage> down!!!\n"); break;
case 30: sys_shutdown_message("Cannot init graphic envirorment\n"); break;
case 31: sys_shutdown_message("graphic mode 800x600x16 not supported\n"); break;
default: sys_shutdown_message("???????????????\n"); break;
}
}
/demos/tags/rel_1_5_4/pci6025e/test_dac.c
0,0 → 1,352
/*****************************************************************************
* Filename: test_dac.c *
* Author: Marco Ziglioli (Doctor Stein) *
* Date: 12/06/2001 *
* Description: Little test program for Analog Output section of PCI6025E *
*----------------------------------------------------------------------------*
* Notes: Connect a multimeter to DAC1 output (pin 21) and watch *
* tension value. Use '+' and '-' on numeric pad to increase *
* and decrise voltage *
* With this program it's possible to point out possible *
* offset errors. To correct them no software are written but *
* in National board package there's the program to calibrate *
* the board. Otherwise you can see how much is the offset *
* and you can compensate it through software value *
*****************************************************************************/
 
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
*
* Copyright (C) 2001 Marco Ziglioli
*
* 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/shark_fb26.h>
#include <drivers/shark_keyb26.h>
 
#include <drivers/pci6025e/dac.h>
 
#define TASK_VOLT_PERIOD 150E3
#define TASK_VOLT_WCET 080E3
#define TASK_DAC_PERIOD 050E3
#define TASK_DAC_WCET 020E3
 
#define CONV 10/2048
 
#define TASK_GROUP 1
 
WORD dac0_value = 0,
dac1_value = 0;
 
BYTE sys = 0;
BYTE dac = 0;
 
//some colors
int black = rgb16(0, 0, 0),
white = rgb16(255, 255, 255);
 
void drawInterface(void);
void endfun(KEY_EVT *);
void inc(KEY_EVT *);
void dec(KEY_EVT *);
void change_dac(KEY_EVT *);
void close_event(void *);
TASK Voltage_body(int);
TASK DAC_Check_body(int);
 
int main(int argc, char **argv)
{
KEY_EVT k;
HARD_TASK_MODEL m, d;
PID pid_m, pid_d;
 
k.flag = CNTR_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, endfun, FALSE);
 
k.flag = CNTL_BIT;
k.status = KEY_PRESSED;
keyb_hook(k, endfun, FALSE);
 
k.flag = 0;
k.scan = 78;
k.ascii = 43;
k.status = KEY_PRESSED;
keyb_hook(k, inc, FALSE);
 
k.flag = 0;
k.scan = 74;
k.ascii = 45;
k.status = KEY_PRESSED;
keyb_hook(k, dec, FALSE);
 
k.flag = 0;
k.scan = KEY_V;
k.ascii = 'v';
k.status = KEY_PRESSED;
keyb_hook(k, change_dac, FALSE);
 
hard_task_default_model(m);
hard_task_def_wcet(m, TASK_VOLT_WCET);
hard_task_def_mit(m, TASK_VOLT_PERIOD);
hard_task_def_group(m, TASK_GROUP);
pid_m = task_create("Voltage", Voltage_body, &m, NULL);
if(pid_m == NIL){
sys = 30;
exit(1);
}
 
hard_task_default_model(d);
hard_task_def_wcet(d, TASK_DAC_WCET);
hard_task_def_mit(d, TASK_DAC_PERIOD);
hard_task_def_group(d, TASK_GROUP);
pid_d = task_create("DAC Check", DAC_Check_body, &d, NULL);
if(pid_d == NIL){
sys = 31;
exit(1);
}
 
//Check if a NI board is on PCI bus
if(!reMap()){
sys = 11;
exit(1);
}
 
drawInterface();
 
//Analog output section set up
DAC_Init();
 
/*
*AI_TIMEBASE div by 2; OUT_TIMEBASE div by 2; single DAC mode
*TMRDACWR = 3 OUT_TIMEBASE period; FIFO flags polarity active low
*TMRDACWR disabled; DMA PIO control = FIFO DATA interface mode
*UPDATE signal timebase = AO_UPDATE pulse width
*UPDATE pulsewidth = 3-3.5 OUT_TIMEBASE period
*UPDATE signal polarity = HIGH Z
*/
DAC_boardInit(0x02, 0x4000);
/*
*LDAC0 source = UPDATE
*DAC0 update immediately
*LDAC1 source = UPDATE
*DAC1 update immediately
*/
DAC_LDACSourceUpdate(0x00);
//End of Analog output section setup
 
group_activate(TASK_GROUP);
 
return 0;
}
 
/*
* Every time operator select a new value to send to a DAc this TASK makes
* actions needed to perform the operation
*/
TASK Voltage_body(int dac_work)
{
WORD old0_value, old1_value;
char buf[6];
float volt;
 
old0_value = dac0_value;
old1_value = dac1_value;
while(1){
if(dac){
if(dac1_value != old1_value){
DAC_output(DAC1, dac1_value);
old1_value = dac1_value;
sprintf(buf, "%04d", dac1_value);
grx_text(buf, 70, 120, rgb16(180, 0, 0), rgb16(255,255,140));
sprintf(buf, "%04x", dac1_value);
grx_text(buf, 300, 120, rgb16(180, 0, 0), rgb16(255,255,140));
if( (dac1_value & 0x0800) == 0 )
volt = (float)dac1_value * (float)CONV;
else
volt = (float)(dac1_value-0x0FFF) * (float)CONV;
sprintf(buf, "%05.2f", volt);
grx_text(buf, 70, 177, rgb16(180, 40, 180), black);
}
} else {
if(dac0_value != old0_value){
DAC_output(DAC0, dac0_value);
old0_value = dac0_value;
sprintf(buf, "%04d", dac0_value);
grx_text(buf, 521, 120, rgb16(180, 0, 0), rgb16(255,255,140));
sprintf(buf, "%04x", dac0_value);
grx_text(buf, 754, 120, rgb16(180, 0, 0), rgb16(255,255,140));
if( (dac0_value & 0x0800) == 0 )
volt = (float)dac0_value * (float)CONV;
else
volt = (float)(dac0_value-0x0FFF) * (float)CONV;
sprintf(buf, "%05.2f", volt);
grx_text(buf, 521, 177, rgb16(180, 40, 180), black);
}
}
task_endcycle();
}
}
 
/*
* This TASK show which is the DAC active
*/
TASK DAC_Check_body(int dummy)
{
BYTE old = dac;
char buf[8];
 
while(1){
if(dac != old){
old = dac;
sprintf(buf, "DAC %d", dac);
grx_text(buf, 385, 90, rgb16(255*dac, 255*(1-dac), 0), black);
}
task_endcycle();
}
}
 
void drawInterface(void)
{
grx_rect(1, 1, 799, 69, rgb16(105, 0, 0));
grx_rect(2, 2, 798, 68, rgb16(155, 0, 0));
grx_rect(3, 3, 797, 67, rgb16(205, 0, 0));
grx_rect(4, 4, 796, 66, rgb16(255, 0, 0));
 
grx_text("Test program for Analog output section of PCI6025E",
7, 10, rgb16(50, 255, 50), black);
grx_text("Use '+' and '-' on numeric pad to change tension",
7, 25, rgb16(0, 255, 255), black);
grx_text("Connect a tester to DAC1 output (pin21) or to DAC0 output (pin20)",
7, 33, rgb16(0, 255, 255), black);
grx_text("Use 'v' to alternate change active DAC",
7, 40, rgb16(0, 255, 255), black);
 
grx_text("CTRL-C for Exit", 7, 55, rgb16(200, 200, 0), black);
 
grx_rect(1, 80, 355, 150, rgb16(0, 105, 0));
grx_rect(2, 81, 354, 149, rgb16(0, 155, 0));
grx_rect(3, 82, 353, 148, rgb16(0, 205, 0));
grx_rect(4, 83, 352, 147, rgb16(0, 255, 0));
 
grx_rect(1, 160, 355, 199, rgb16(0, 105, 0));
grx_rect(2, 161, 354, 198, rgb16(0, 155, 0));
grx_rect(3, 162, 353, 197, rgb16(0, 205, 0));
grx_rect(4, 163, 352, 196, rgb16(0, 255, 0));
 
grx_rect(455, 80, 799, 150, rgb16(105, 105, 0));
grx_rect(456, 81, 798, 149, rgb16(155, 155, 0));
grx_rect(457, 82, 797, 148, rgb16(205, 205, 0));
grx_rect(458, 83, 796, 147, rgb16(255, 255, 0));
 
grx_rect(455, 160, 799, 199, rgb16(105, 105, 0));
grx_rect(456, 161, 798, 198, rgb16(155, 155, 0));
grx_rect(457, 162, 797, 197, rgb16(205, 205, 0));
grx_rect(458, 163, 796, 196, rgb16(255, 255, 0));
 
grx_rect(360, 80, 450, 105, rgb16(85, 85, 255));
grx_rect(361, 81, 449, 104, rgb16(125, 125, 255));
grx_rect(362, 82, 448, 103, rgb16(175, 175, 255));
grx_rect(363, 83, 447, 102, rgb16(225, 225, 255));
 
grx_rect(153, 93, 195, 103, rgb16(255, 0, 0));
grx_text("DAC 1", 155, 95, rgb16(255, 170, 170), black);
 
grx_rect(607, 93, 649, 103, rgb16(255, 0, 0));
grx_text("DAC 0", 609, 95, rgb16(255, 255, 210), black);
 
grx_text("Decimal", 7, 120, rgb16(120, 120, 255), black);
grx_text("Hexadecimal", 200, 120, rgb16(120, 120, 255), black);
grx_text("Tension", 7, 177, rgb16(120, 120, 255), black);
 
grx_text("Decimal", 461, 120, rgb16(255, 120, 120), black);
grx_text("Hexadecimal", 654, 120, rgb16(255, 120, 120), black);
grx_text("Tension", 461, 177, rgb16(255, 120, 120), black);
}
 
void close_event(void *arg)
{
switch(sys){
case 0 : sys_shutdown_message("Regular End\n"); break;
case 1 : sys_shutdown_message("End fun invoked\n"); break;
case 10: sys_shutdown_message("Pci bus not found\n"); break;
case 11: sys_shutdown_message("No National board found\n"); break;
case 20: sys_shutdown_message("Cannot initialize graphic envirorment\n"); break;
case 21: sys_shutdown_message("Cannot start envirorment in 800x600x16\n"); break;
case 30: sys_shutdown_message("Cannot create task <voltage>\n"); break;
case 31: sys_shutdown_message("Canot create task <DAC Check>\n"); break;
case 40: sys_shutdown_message("Break on clock end event\n"); break;
default: sys_shutdown_message("Unkwon exit event\n"); break;
}
}
 
void endfun(KEY_EVT *k)
{
close_event(NULL);
 
exit(1);
}
 
/*
* Capture correct key event and increase output tension of active DAC
*/
void inc(KEY_EVT *k)
{
if(dac){
if( (dac1_value & 0x0800) == 0 && dac1_value > 0x07FF )
dac1_value = 0;
else
dac1_value++;
} else {
if( (dac0_value & 0x0800) == 0 && dac0_value > 0x07FF )
dac0_value = 0;
else
dac0_value++;
}
}
 
/*
* Same as above but decrease tension
*/
void dec(KEY_EVT *k)
{
if(dac){
if(dac1_value < 1)
dac1_value = 0x0FFF;
else
dac1_value -= 1;
} else {
if(dac0_value < 1)
dac0_value = 0x0FFF;
else
dac0_value -= 1;
}
}
 
/*
* Capture correct key event and change active DAC
*/
void change_dac(KEY_EVT *k)
{
if(dac) dac = 0;
else dac = 1;
}
 
/demos/tags/rel_1_5_4/pci6025e/test_ec.c
0,0 → 1,392
/*****************************************************************************
* Filename: test_ec.c *
* Author: Marco Ziglioli (Doctor Stein) *
* Date: 20/06/2001 *
* Description: Test program for gated event counting using PCI6025E board *
*----------------------------------------------------------------------------*
* Notes: FOUT are enabled to provide a frequency of 6250 Hz. You could *
* connect PFI3 (pin 41) and PFI6 (pin 45) to this source for counting *
* edges. Gated counting are enabled and PFI4 (pin 42) is gate pin for *
* counter 0 and PFI5 (pin 44) is gate pin for counter 0. DIO 7 and 6 *
* are als configured to switch between 0 and 5 V. Connect DIO 7 to *
* gate 0 and DIO 6 to gate 1. Use 'g' (counter 0) and 'h' (counter 1) *
* to change DIO lines value. On left area of the screen you should *
* see counter while counting and on the right area you should lock *
* counter values by pressing 's' key. *
* Notice that line parameters are enabled and accept inital value *
* for the two counters. If they aren't specified or they are wrong *
* counters start from 0x00FFFFFF (counter 0 which counts down) and *
* 0x00000000 (counter 1 which counts up). *
* Last time addiction: TC Interrupts and Gate interrupts are enabled *
* Bottom squares indicates when an interrupt is *
* raised *
*****************************************************************************/
 
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
*
* Copyright (C) 2001 Marco Ziglioli
*
* 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/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#include <drivers/pci6025e/timer.h>
#include <drivers/pci6025e/dio_ppi.h>
 
#ifndef INT_NO
#define INT_NO NIDevice_info[0].InterruptLevel
#endif
 
BYTE sys = 0;
 
PID show_aper_pid;
BYTE out = 0x00;
 
int black = rgb16(0, 0, 0),
white = rgb16(255, 255, 255);
 
void endfun(KEY_EVT *);
void close_event(void *);
void show_evt(KEY_EVT *k);
void gate_change(KEY_EVT *k);
 
void drawInterface(void);
 
void int_evt(int intno);
 
TASK show_per(int);
TASK show_aper(int);
 
int main(int argc, char **argv)
{
KEY_EVT k;
SOFT_TASK_MODEL show_per_mod, show_aper_mod;
PID show_per_pid;
int result;
DWORD init_val_c0, init_val_c1;
 
if(argc >= 3){
if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1)
init_val_c0 = 0x00FFFFFF;
if( (result = sscanf(argv[2], "%ld", &init_val_c1)) != 1)
init_val_c1 = 0x00000000;
}
if(argc == 2){
if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1)
init_val_c0 = 0x00FFFFFF;
init_val_c1 = 0x00000000;
}
if(argc == 1){
init_val_c0 = 0x00FFFFFF;
init_val_c1 = 0x00000000;
}
 
k.flag = CNTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, endfun, FALSE);
 
k.flag = CNTR_BIT;
k.status = KEY_PRESSED;
keyb_hook(k, endfun, FALSE);
 
soft_task_default_model(show_aper_mod);
soft_task_def_aperiodic(show_aper_mod);
soft_task_def_level(show_aper_mod, 2);
soft_task_def_period(show_aper_mod, 250000);
soft_task_def_met(show_aper_mod, 30000);
soft_task_def_wcet(show_aper_mod, 60000);
if( (show_aper_pid = task_create("Show aperiodic task", show_aper, &show_aper_mod, NULL)) == NIL ){
sys = 10;
exit(1);
}
 
k.flag = 0;
k.scan = KEY_S;
k.ascii = 's';
k.status = KEY_PRESSED;
keyb_hook(k, show_evt, FALSE);
 
k.flag = 0;
k.scan = KEY_G;
k.ascii = 'g';
k.status = KEY_PRESSED;
keyb_hook(k, gate_change, FALSE);
 
k.scan = KEY_H;
k.ascii = 'h';
k.status = KEY_PRESSED;
keyb_hook(k, gate_change, FALSE);
 
soft_task_default_model(show_per_mod);
soft_task_def_level(show_per_mod, 2);
soft_task_def_met(show_per_mod, 1000);
soft_task_def_period(show_per_mod, 10000);
if( (show_per_pid = task_create("Show periodic task", show_per, &show_per_mod, NULL)) == NIL){
sys = 11;
exit(1);
}
 
if(!reMap()){
sys = 21;
exit(1);
}
 
drawInterface();
//Init DIO lines used to manage counters gates
DIO_init();
DIO_setup(0xFF);
DIO_write(out);
 
//All PFI are configured as input
PFIprogramming(0x0000);
//FOUT enable; Slow TIMEBASE, divided by two; divided by 16 on FOUT pin
setIntClock(1, 1, 0);
 
TIM_reset(2); //Reset both two counters
 
//Source PFI3(41); Gate PFI 4(42); Down counting; counts rising edge;
TIM_eventCounting(C0, 0x04, 0x45, 0x03, init_val_c0);
 
//Source PFI6(45); Gate PFI 5(44); Up counting; counts rising edge;
TIM_eventCounting(C1, 0x87, 0x46, 0x03, init_val_c1);
 
//Set up interrupt group A and B enabling and programming to assert a request
//both on line 2 and 3 respectively
INT_setup(0x0A, 0x0B);
INT_personalize(0x03); //Interrupt request polarity low; IRQ driven on line 0 and 1
 
handler_set(INT_NO, int_evt, FALSE, show_aper_pid, NULL);
 
TIM_arm(2); //Arm both two counters
 
task_activate(show_per_pid);
 
return 0;
}
 
void drawInterface(void)
{
grx_rect(1, 1, 799, 99, rgb16(105, 0, 0));
grx_rect(2, 2, 798, 98, rgb16(155, 0, 0));
grx_rect(3, 3, 797, 97, rgb16(205, 0, 0));
grx_rect(4, 4, 796, 96, rgb16(255, 0, 0));
 
grx_text("Test program for Gated Event Counting capacity of PCI6025E timers",
7, 10, rgb16(50, 255, 50), black);
 
grx_text("This program counting rise edges on counters source (PFI3 & PFI6) when releted gates",
7, 25, rgb16(0, 255, 255), black);
grx_text("(PFI 42 & 44) are enabled. Frequency Out (FOUT) is enabled and provides a frequency of 6250 Hz",
7, 33, rgb16(0, 255, 255), black);
 
grx_text("Instruction:",7, 43, rgb16(255, 0, 0), black);
grx_text("Use 's' to lock counters value in right squares",
7, 51, rgb16(0, 255, 255), black);
grx_text("Use 'g' to block or to release alternativly counter 0 (see top-left square)",
7, 58, rgb16(0, 255, 255), black);
 
grx_text("Use 'h' to block or to release alternativly counter 1 (see bottom-left square)",
7, 65, rgb16(0, 255, 255), black);
 
grx_text("Please connect DIO7 (pin 32) to PFI4 (pin 42) and DIO6 (pin 30) to PFI5 (pin 44)",
7, 78, rgb16(0, 255, 0), black);
grx_text("CTRL-C for Exit", 7, 88, rgb16(200, 200, 0), black);
 
grx_rect(1, 110, 355, 170, rgb16(0, 105, 0));
grx_rect(2, 111, 354, 169, rgb16(0, 155, 0));
grx_rect(3, 112, 353, 168, rgb16(0, 205, 0));
grx_rect(4, 113, 352, 167, rgb16(0, 255, 0));
grx_text("Counter 0 evolution", 7, 120, rgb16(255, 255, 0), black);
 
grx_rect(455, 110, 799, 170, rgb16(0, 105, 0));
grx_rect(456, 111, 798, 169, rgb16(0, 155, 0));
grx_rect(457, 112, 797, 168, rgb16(0, 205, 0));
grx_rect(458, 113, 796, 167, rgb16(0, 255, 0));
grx_text("Counter 0 locked value", 461, 120, rgb16(255, 0, 255), black);
 
grx_rect(360, 110, 450, 170, rgb16(0, 105, 0));
grx_rect(361, 111, 449, 169, rgb16(0, 155, 0));
grx_rect(362, 112, 448, 168, rgb16(0, 205, 0));
grx_rect(363, 113, 447, 167, rgb16(0, 255, 0));
grx_text("Gate0", 367, 120, rgb16(200, 255, 200), black);
grx_text("0 V", 367, 145, rgb16(255, 0, 0), black);
 
grx_rect(1, 190, 355, 260, rgb16(85, 85, 255));
grx_rect(2, 191, 354, 259, rgb16(135, 135, 255));
grx_rect(3, 192, 353, 258, rgb16(190, 190, 255));
grx_rect(4, 193, 352, 257, rgb16(230, 239, 255));
grx_text("Counter 1 evolution", 7, 200, white, black);
 
grx_rect(455, 190, 799, 260, rgb16(85, 85, 255));
grx_rect(456, 191, 798, 259, rgb16(135, 135, 255));
grx_rect(457, 192, 797, 258, rgb16(190, 190, 255));
grx_rect(458, 193, 796, 257, rgb16(230, 230, 255));
grx_text("Counter 1 locked value", 461, 200, white, black);
 
grx_rect(360, 190, 450, 260, rgb16(85, 85, 255));
grx_rect(361, 191, 449, 259, rgb16(135, 135, 255));
grx_rect(362, 192, 448, 258, rgb16(190, 190, 255));
grx_rect(363, 193, 447, 257, rgb16(230, 230, 255));
grx_text("Gate1", 367, 200, rgb16(255, 200, 255), black);
grx_text("0 V", 367, 225, rgb16(255, 0, 0), black);
 
grx_text("Counter 0 Interrupt events", 7, 340, rgb16(255, 200, 100), black);
grx_text("Counter 1 Interrupt events", 461, 340, rgb16(255, 200, 100), black);
grx_rect(1, 350, 355, 400, rgb16(105, 0, 0));
grx_rect(2, 351, 354, 399, rgb16(155, 0, 0));
grx_rect(3, 352, 353, 398, rgb16(205, 0, 0));
grx_rect(4, 353, 352, 397, rgb16(255, 0, 0));
grx_rect(455, 350, 799, 400, rgb16(105, 0, 0));
grx_rect(456, 351, 798, 399, rgb16(155, 0, 0));
grx_rect(457, 352, 797, 398, rgb16(205, 0, 0));
grx_rect(458, 353, 796, 397, rgb16(255, 0, 0));
}
 
 
TASK show_per(int none)
{
DWORD val;
char buf[30];
 
while(1){
val = TIM_readCounter(C0); //Read counter 0 value
sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val);
grx_text(buf, 7, 145, rgb16(255, 0, 0), black);
 
val = TIM_readCounter(C1); //Read counter 1 value
sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val);
grx_text(buf, 7, 225, rgb16(255, 0, 0), black);
 
task_endcycle();
}
}
 
TASK show_aper(int dummy)
{
DWORD val;
char buf[30];
 
while(1){
val = TIM_readCounter(C0);
sprintf(buf, "HEX: %08lx DEC: %08ld", val, val);
grx_text(buf, 461, 145, rgb16(80, 80, 255), black);
 
val = TIM_readCounter(C1);
sprintf(buf, "HEX: %08lx DEC: %08ld", val, val);
grx_text(buf, 461, 225, rgb16(80, 80, 255), black);
 
task_endcycle();
}
}
 
void endfun(KEY_EVT *k)
{
close_event(NULL);
 
exit(1);
}
 
void show_evt(KEY_EVT *k)
{
task_activate(show_aper_pid);
}
 
void gate_change(KEY_EVT *k)
{
if(k->ascii == 'g'){
if( (out & 0x80) != 0){
out &= 0x7F;
grx_text("0 V", 367, 145, rgb16(255, 0, 0), black);
} else {
out |= 0x80;
grx_text("5 V", 367, 145, rgb16(0, 255, 0), black);
}
} else {
if( (out & 0x40) != 0){
out &= 0xBF;
grx_text("0 V", 367, 225, rgb16(255, 0, 0), black);
} else {
out |= 0x40;
grx_text("5 V", 367, 225, rgb16(0, 255, 0), black);
}
}
 
DIO_write(out);
}
 
void close_event(void *arg)
{
TIM_disarm(2); //Disable both two counters
handler_remove(INT_NO);
 
switch(sys){
case 0: sys_shutdown_message("OK\n"); break;
case 10: sys_shutdown_message("Task <show aperiodic> down\n"); break;
case 11: sys_shutdown_message("Task <show periodic> down\n"); break;
case 20: sys_shutdown_message("No PCI bus\n"); break;
case 21: sys_shutdown_message("No National board on PCI bus\n"); break;
case 30: sys_shutdown_message("No graphic can be initialized\n"); break;
case 31: sys_shutdown_message("This graphic mode cannot be supported\n"); break;
default: sys_shutdown_message("???????????\n"); break;
}
}
 
void int_evt(int intno)
{
WORD status;
 
status = DAQ_STC_Windowed_Mode_Read(AI_STATUS_1);
if( (status & 0x8000) != 0){
if( (status & 0x0008) != 0){
grx_text("INT Group A raised! G0 Rolls over", 7, 360, rgb16(0, 255, 0), black);
set(interrupt_a_ack, 14);
DAQ_STC_Windowed_Mode_Write(INTERRUPT_A_ACK, interrupt_a_ack);
clr(interrupt_a_ack, 14);
}
if( (status & 0x0004) != 0){
grx_text("INT Group A raised! G0 gate pressed", 7, 380, rgb16(0, 255, 0), black);
set(interrupt_a_ack, 15);
DAQ_STC_Windowed_Mode_Write(INTERRUPT_A_ACK, interrupt_a_ack);
clr(interrupt_a_ack, 15);
}
return;
}
 
status = DAQ_STC_Windowed_Mode_Read(AO_STATUS_1);
if( (status & 0x8000) != 0){
if( (status & 0x0008) != 0){
grx_text("INT Group B raised! G1 Rolls over", 461, 360, rgb16(0, 255, 0), black);
set(interrupt_b_ack, 14);
DAQ_STC_Windowed_Mode_Write(INTERRUPT_B_ACK, interrupt_b_ack);
clr(interrupt_b_ack, 14);
}
if( (status & 0x0004) != 0){
grx_text("INT Group B raised! G1 gate pressed", 461, 380, rgb16(0, 255, 0), black);
set(interrupt_b_ack, 15);
DAQ_STC_Windowed_Mode_Write(INTERRUPT_B_ACK, interrupt_b_ack);
clr(interrupt_b_ack, 15);
}
return;
}
}
/* End of file: Test_ec.c */
/demos/tags/rel_1_5_4/pci6025e/test_bec.c
0,0 → 1,324
/*****************************************************************************
* Filename: test_bec.c *
* Author: Marco Ziglioli (Doctor Stein) *
* Date: 20/06/2001 *
* Description: Test program for buffered gated event counting using PCI6025E *
* board *
*----------------------------------------------------------------------------*
* Notes: FOUT are enabled to provide a frequency of 6250 Hz. You could *
* connect PFI3 (pin 41) and PFI6 (pin 45) to this source for counting *
* edges. Gated counting are enabled and PFI4 (pin 42) is gate pin for *
* counter 0 and PFI5 (pin 44) is gate pin for counter 0. DIO 7 and 6 *
* are als configured to switch between 0 and 5 V. Connect DIO 7 to *
* gate 0 and DIO 6 to gate 1. Use 'g' (counter 0) and 'h' (counter 1) *
* to change DIO lines value. On left area of the screen you should *
* see counter while counting and on the right area you should lock *
* counter values by pressing 's' key. *
* Notice that line parameters are enabled and accept inital value *
* for the two counters. If they aren't specified or they are wrong *
* counters start from 0x00FFFFFF (counter 0 which counts down) and *
* 0x00000000 (counter 1 which counts up). *
*****************************************************************************/
 
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
*
* Copyright (C) 2001 Marco Ziglioli
*
* 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/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#include <drivers/pci6025e/timer.h>
#include <drivers/pci6025e/dio_ppi.h>
 
BYTE sys = 0;
 
PID show_aper_pid;
BYTE out = 0x00;
 
int black = rgb16(0, 0, 0),
white = rgb16(255, 255, 255);
 
void endfun(KEY_EVT *);
void close_event(void *);
void show_evt(KEY_EVT *k);
void gate_change(KEY_EVT *k);
 
void drawInterface(void);
 
TASK show_per(int);
TASK show_aper(int);
 
int main(int argc, char **argv)
{
KEY_EVT k;
SOFT_TASK_MODEL show_per_mod, show_aper_mod;
PID show_per_pid;
int result;
DWORD init_val_c0, init_val_c1;
 
if(argc >= 3){
if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1)
init_val_c0 = 0x00FFFFFF;
if( (result = sscanf(argv[2], "%ld", &init_val_c1)) != 1)
init_val_c1 = 0x00000000;
}
if(argc == 2){
if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1)
init_val_c0 = 0x00FFFFFF;
init_val_c1 = 0x00000000;
}
if(argc == 1){
init_val_c0 = 0x00FFFFFF;
init_val_c1 = 0x00000000;
}
 
k.flag = CNTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, endfun, FALSE);
 
k.flag = CNTR_BIT;
k.status = KEY_PRESSED;
keyb_hook(k, endfun, FALSE);
 
soft_task_default_model(show_aper_mod);
soft_task_def_aperiodic(show_aper_mod);
soft_task_def_level(show_aper_mod, 2);
soft_task_def_period(show_aper_mod, 250000);
soft_task_def_met(show_aper_mod, 30000);
soft_task_def_wcet(show_aper_mod, 60000);
if( (show_aper_pid = task_create("Show aperiodic task", show_aper, &show_aper_mod, NULL)) == NIL ){
sys = 10;
exit(1);
}
 
k.flag = 0;
k.scan = KEY_S;
k.ascii = 's';
k.status = KEY_PRESSED;
keyb_hook(k, show_evt, FALSE);
 
k.flag = 0;
k.scan = KEY_G;
k.ascii = 'g';
k.status = KEY_PRESSED;
keyb_hook(k, gate_change, FALSE);
 
k.scan = KEY_H;
k.ascii = 'h';
k.status = KEY_PRESSED;
keyb_hook(k, gate_change, FALSE);
 
soft_task_default_model(show_per_mod);
soft_task_def_level(show_per_mod, 2);
soft_task_def_met(show_per_mod, 1000);
soft_task_def_period(show_per_mod, 10000);
if( (show_per_pid = task_create("Show periodic task", show_per, &show_per_mod, NULL)) == NIL){
sys = 11;
exit(1);
}
 
if(!reMap()){
sys = 21;
exit(1);
}
 
drawInterface();
 
DIO_init();
DIO_setup(0xFF);
DIO_write(out);
 
PFIprogramming(0x0000);
setIntClock(1, 1, 0);
TIM_reset(2); //Reset both two counters
 
 
//Source PFI3(41); Gate PFI 4(42); Down counting; counts rising edge;
TIM_bufferedEventCounting(C0, 0x04, 0x45, 0x01, init_val_c0);
 
//Source PFI6(45); Gate PFI 5(44); Up counting; counts rising edge;
TIM_bufferedEventCounting(C1, 0x87, 0x46, 0x00, init_val_c1);
 
TIM_arm(2); //Arm both two counters
 
task_activate(show_per_pid);
 
return 0;
}
 
void drawInterface(void)
{
grx_rect(1, 1, 799, 99, rgb16(105, 0, 0));
grx_rect(2, 2, 798, 98, rgb16(155, 0, 0));
grx_rect(3, 3, 797, 97, rgb16(205, 0, 0));
grx_rect(4, 4, 796, 96, rgb16(255, 0, 0));
 
grx_text("Test program for Buffered Event Counting capacity of PCI6025E timers",
7, 10, rgb16(50, 255, 50), black);
 
grx_text("This program counting rise edges on counters source (PFI3 & PFI6)",
7, 18, rgb16(0, 255, 255), black);
grx_text("Counter 1 will be resetted every gate falling edge",
7, 26, rgb16(0, 255, 255), black);
grx_text("(PFI 42 & 44) are enabled. Frequency Out (FOUT) is enabled and provides a frequency of 6250 Hz",
7, 34, rgb16(0, 255, 255), black);
 
grx_text("Instruction:",7, 43, rgb16(255, 0, 0), black);
grx_text("Use 's' to watch contents of Hardware save registers updated every time gate goes down",
7, 51, rgb16(0, 255, 255), black);
grx_text("Use 'g' to generate an event on counter 0 gate (see top-left square)",
7, 58, rgb16(0, 255, 255), black);
 
grx_text("Use 'h' to generate an event on counter 1 gate (see bottom-left square)",
7, 65, rgb16(0, 255, 255), black);
 
grx_text("Please connect DIO7 (pin 32) to PFI4 (pin 42) and DIO6 (pin 30) to PFI5 (pin 44)",
7, 78, rgb16(0, 255, 0), black);
grx_text("CTRL-C for Exit", 7, 88, rgb16(200, 200, 0), black);
 
grx_rect(1, 110, 355, 170, rgb16(0, 105, 0));
grx_rect(2, 111, 354, 169, rgb16(0, 155, 0));
grx_rect(3, 112, 353, 168, rgb16(0, 205, 0));
grx_rect(4, 113, 352, 167, rgb16(0, 255, 0));
grx_text("Counter 0 evolution", 7, 120, rgb16(255, 255, 0), black);
 
grx_rect(455, 110, 799, 170, rgb16(0, 105, 0));
grx_rect(456, 111, 798, 169, rgb16(0, 155, 0));
grx_rect(457, 112, 797, 168, rgb16(0, 205, 0));
grx_rect(458, 113, 796, 167, rgb16(0, 255, 0));
grx_text("Counter 0 locked value", 461, 120, rgb16(255, 0, 255), black);
 
grx_rect(360, 110, 450, 170, rgb16(0, 105, 0));
grx_rect(361, 111, 449, 169, rgb16(0, 155, 0));
grx_rect(362, 112, 448, 168, rgb16(0, 205, 0));
grx_rect(363, 113, 447, 167, rgb16(0, 255, 0));
grx_text("Gate0", 367, 120, rgb16(200, 255, 200), black);
grx_text("0 V", 367, 145, rgb16(255, 0, 0), black);
 
grx_rect(1, 190, 355, 260, rgb16(85, 85, 255));
grx_rect(2, 191, 354, 259, rgb16(135, 135, 255));
grx_rect(3, 192, 353, 258, rgb16(190, 190, 255));
grx_rect(4, 193, 352, 257, rgb16(230, 239, 255));
grx_text("Counter 1 evolution", 7, 200, white, black);
 
grx_rect(455, 190, 799, 260, rgb16(85, 85, 255));
grx_rect(456, 191, 798, 259, rgb16(135, 135, 255));
grx_rect(457, 192, 797, 258, rgb16(190, 190, 255));
grx_rect(458, 193, 796, 257, rgb16(230, 230, 255));
grx_text("Counter 1 locked value", 461, 200, white, black);
 
grx_rect(360, 190, 450, 260, rgb16(85, 85, 255));
grx_rect(361, 191, 449, 259, rgb16(135, 135, 255));
grx_rect(362, 192, 448, 258, rgb16(190, 190, 255));
grx_rect(363, 193, 447, 257, rgb16(230, 230, 255));
grx_text("Gate1", 367, 200, rgb16(255, 200, 255), black);
grx_text("0 V", 367, 225, rgb16(255, 0, 0), black);
}
 
TASK show_per(int none)
{
DWORD val;
char buf[30];
 
while(1){
val = TIM_readCounter(C0); //Read from Hardware Save Register
sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val);
grx_text(buf, 7, 145, rgb16(255, 0, 0), black);
 
val = TIM_readCounter(C1); //Read from Hardware Save Register
sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val);
grx_text(buf, 7, 225, rgb16(255, 0, 0), black);
 
task_endcycle();
}
}
 
TASK show_aper(int dummy)
{
DWORD val;
char buf[30];
 
while(1){
val = TIM_readHWSaveReg(C0); //Read from Hardware Save Register
sprintf(buf, "HEX: %08lx DEC: %08ld", val, val);
grx_text(buf, 461, 145, rgb16(80, 80, 255), black);
 
val = TIM_readHWSaveReg(C1); //Read from Hardware Save Register
sprintf(buf, "HEX: %08lx DEC: %08ld", val, val);
grx_text(buf, 461, 225, rgb16(80, 80, 255), black);
 
task_endcycle();
}
}
 
void endfun(KEY_EVT *k)
{
close_event(NULL);
 
exit(1);
}
 
void show_evt(KEY_EVT *k)
{
task_activate(show_aper_pid);
}
 
void gate_change(KEY_EVT *k)
{
if(k->ascii == 'g'){
if( (out & 0x80) != 0){
out &= 0x7F;
grx_text("0 V", 367, 145, rgb16(255, 0, 0), black);
} else {
out |= 0x80;
grx_text("5 V", 367, 145, rgb16(0, 255, 0), black);
}
} else {
if( (out & 0x40) != 0){
out &= 0xBF;
grx_text("0 V", 367, 225, rgb16(255, 0, 0), black);
} else {
out |= 0x40;
grx_text("5 V", 367, 225, rgb16(0, 255, 0), black);
}
}
 
DIO_write(out);
}
 
void close_event(void *arg)
{
TIM_disarm(2); //Disable both two counters
 
switch(sys){
case 0: sys_shutdown_message("OK\n"); break;
case 10: sys_shutdown_message("Task <show aperiodic> down\n"); break;
case 11: sys_shutdown_message("Task <show periodic> down\n"); break;
case 20: sys_shutdown_message("No PCI bus\n"); break;
case 21: sys_shutdown_message("No National board on PCI bus\n"); break;
case 30: sys_shutdown_message("No graphic can be initialized\n"); break;
case 31: sys_shutdown_message("This graphic mode cannot be supported\n"); break;
default: sys_shutdown_message("???????????\n"); break;
}
}
/* End of file: Test_bec.c */
/demos/tags/rel_1_5_4/pci6025e/initfile.c
0,0 → 1,198
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* Tullio Facchinetti <tullio.facchinetti@unipv.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* 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 "intdrive/intdrive/intdrive.h"
#include "edf/edf/edf.h"
#include "hardcbs/hardcbs/hardcbs.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
 
#include "sem/sem/sem.h"
#include "hartport/hartport/hartport.h"
#include "cabs/cabs/cabs.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_pci26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#define FRAME_BUFFER_DEVICE 0
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 2000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
LEVEL EDF_level;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_level = EDF_register_level(EDF_ENABLE_ALL);
HCBS_register_level(HCBS_ENABLE_ALL, EDF_level);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
CABS_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(1);
}
 
}
 
int device_drivers_init() {
 
int res;
KEYB_PARMS kparms = BASE_KEYB;
LINUXC26_register_module(TRUE);
 
PCI26_init();
 
INPUT26_init();
 
keyb_def_ctrlC(kparms, NULL);
 
KEYB26_init(&kparms);
 
FB26_init();
res = FB26_open(FRAME_BUFFER_DEVICE);
if (res) {
cprintf("Error: Cannot open graphical mode\n");
KEYB26_close();
INPUT26_close();
exit(1);
}
FB26_use_grx(FRAME_BUFFER_DEVICE);
FB26_setmode(FRAME_BUFFER_DEVICE,"800x600-16");
return 0;
 
}
 
int device_drivers_close() {
FB26_close(FRAME_BUFFER_DEVICE);
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
/demos/tags/rel_1_5_4/pci6025e/test_ppi.c
0,0 → 1,177
/*****************************************************************************
* Filename: Test_ppi.c *
* Author: Marco Ziglioli (Doctor Stein) *
* Date: 22/05/2001 *
* Description: Test PPI82C55MSM on NI DAQ PCI6025E *
*----------------------------------------------------------------------------*
* Notes: Configures port A and port C in input and port B in output *
* Test 1: *
* Now connect port B to port A and watch on video value changes *
* in counting order. After connect port B to port C and watch *
* the same events on port C *
* Test 2: *
* Connect 8 LEDs on port B and port A and port C lines to Vcc or*
* GND. Now run this test and watch 8 diode changing in counting *
* mode and on screen port A and port C values displayed *
*****************************************************************************/
 
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
*
* Copyright (C) 2001 Marco Ziglioli
*
* 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 <drivers/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#include <drivers/pci6025e/dio_ppi.h>
 
void exit_fun(KEY_EVT *);
TASK test_ppi(int);
void close_event(void *);
void draw_screen(void);
 
BYTE system = 0;
 
int main(int argc, char **argv)
{
HARD_TASK_MODEL m;
KEY_EVT k;
PID pid_m;
 
k.flag = CNTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, exit_fun, FALSE);
k.flag = CNTR_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, exit_fun, FALSE);
 
hard_task_default_model(m);
hard_task_def_wcet(m, 90000);
hard_task_def_mit(m, 250000);
pid_m = task_create("TEST PPI", test_ppi, &m, NULL);
if(pid_m == NIL){
system = 10;
exit(1);
}
 
//Look for a National board on PCI bus
if(!reMap()){
system = 21;
exit(1);
}
 
//Start configuring DIO module
PPI_init();
 
draw_screen();
 
task_activate(pid_m);
 
return 0;
}
 
void draw_screen(void)
{
grx_rect(5, 5, 610, 130, rgb16(255, 0, 0));
grx_rect(4, 4, 611, 131, rgb16(0,255,255));
grx_rect(3, 3, 612, 132, rgb16(255, 0, 0));
grx_rect(15, 45, 195, 100, rgb16(255, 0, 0));
grx_rect(215, 45, 395, 100, rgb16(0, 255, 0));
grx_rect(415, 45, 595, 100, rgb16(200, 200, 255));
grx_text("Test of PPI82C55MSM function (Hosted on PCI6025E)",
9, 7, rgb16(0, 255, 0), rgb16(0, 0, 0));
grx_text("PORT A and PORT C are configured in input mode",
9, 20, rgb16(255, 70, 70), rgb16(0, 0, 0));
grx_text("PORT B is configured in output mode",
9, 28, rgb16(255, 70, 70), rgb16(0, 0, 0));
grx_text("PORT B (Output)", 35, 50, rgb16(200, 0, 0), rgb16(0, 0, 0));
grx_text("PORT A (Input)", 235, 50, rgb16(30,255,30), rgb16(0, 0, 0));
grx_text("PORT C (Input)", 435, 50, rgb16(200,200,255), rgb16(0, 0, 0));
grx_text("CTRL + C to exit", 9, 115, rgb16(255,255,0), rgb16(0,0,0));
}
 
/*
* At each activation this task sends out value on port B and reads values from
* port A and C
*/
TASK test_ppi(int dummy)
{
BYTE val, pA, pC;
int i;
char buf[10];
 
PPI_config(0x99); //Mode 0 for all; Port A, Port C input; Port B output
val = 0;
while(1){
PPI_write(PPI_PORT_B, val); //sends out value
pA = PPI_read(PPI_PORT_A); //reads from port A
pC = PPI_read(PPI_PORT_C); //reads from port C
 
for(i=7; i>=0; i--){
if( (val>>i)%2 )
grx_text("1", 25+10*(7-i), 75, rgb16(255,0,0), rgb16(0,0,0));
else
grx_text("0", 25+10*(7-i), 75, rgb16(255,0,0), rgb16(0,0,0));
if( (pA>>i)%2 )
grx_text("1", 225+10*(7-i), 75, rgb16(0,255,0), rgb16(0,0,0));
else
grx_text("0", 225+10*(7-i), 75, rgb16(0,255,0), rgb16(0,0,0));
if( (pC>>i)%2 )
grx_text("1", 425+10*(7-i), 75, rgb16(200,200,255), rgb16(0,0,0));
else
grx_text("0", 425+10*(7-i), 75, rgb16(200,200,255), rgb16(0,0,0));
}
sprintf(buf, "%03d", val);
grx_text(buf, 140, 75, rgb16(255,0,0), rgb16(0,0,0));
sprintf(buf, "%03d", pA);
grx_text(buf, 340, 75, rgb16(0,255,0), rgb16(0,0,0));
sprintf(buf, "%03d", pC);
grx_text(buf, 540, 75, rgb16(200,200,255), rgb16(0,0,0));
val++;
task_endcycle();
}
}
 
void close_event(void *arg)
{
switch(system){
case 0: sys_shutdown_message("Regular end\n"); break;
case 10:sys_shutdown_message("Cannot create task 'TEST PPI'\n"); break;
case 20:sys_shutdown_message("Pci bus don't find\n"); break;
case 21:sys_shutdown_message("No National board on PC\n"); break;
case 30:sys_shutdown_message("Cannot start graphic envirorment\n"); break;
default: sys_shutdown_message("Unknown exit\n"); break;
}
}
 
void exit_fun(KEY_EVT *k)
{
system = 0;
close_event(NULL);
 
exit(1);
}
 
/*end of file: test_ppi.c*/
/demos/tags/rel_1_5_4/pci6025e/test_dio.c
0,0 → 1,171
/*****************************************************************************
* Filename: Test_dio.c *
* Author: Marco Ziglioli (Doctor Stein) *
* Date: 22/03/2001 *
* Last update: 22/03/2001 *
* Description: Test STC digital lines (8 lines) *
*----------------------------------------------------------------------------*
* Notes: Configure DIO 4 5 6 7 in input and DIO 0 1 2 3 in output *
* Two way to test this 8 lines: *
* 1) Connect 4 LEDs to output lines and check LEDs lights *
* themselves in counting order. Connect input lines to Vcc *
* or GND and check on video that STC has readed the right *
* nibble *
* 2) Connect 4 output lines with 4 input lines and check on *
* video that the nibble readed by STC change in counting *
* order *
*****************************************************************************/
 
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
*
* Copyright (C) 2001 Marco Ziglioli
*
* 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/shark_fb26.h>
#include <drivers/shark_keyb26.h>
 
#include <drivers/pci6025e/dio_ppi.h>
 
BYTE system = 0;
 
void close_event(void *);
TASK test_DIO(int dummy);
void exit_fun(KEY_EVT *);
void draw_screen(void);
 
int main(int argc, char **argv)
{
HARD_TASK_MODEL m;
KEY_EVT k;
PID pid_m;
 
k.flag = CNTL_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, exit_fun, FALSE);
k.flag = CNTR_BIT;
k.scan = KEY_C;
k.ascii = 'c';
k.status = KEY_PRESSED;
keyb_hook(k, exit_fun, FALSE);
 
hard_task_default_model(m);
hard_task_def_wcet(m, 90000);
hard_task_def_mit(m, 250000);
pid_m = task_create("TEST DIO", test_DIO, &m, NULL);
if(pid_m == NIL){
system = 10;
exit(1);
}
 
//Look for a National board on PCI bus
if(!reMap()){
system = 21;
exit(1);
}
 
//Start configuring DIO module
DIO_init();
 
draw_screen();
 
task_activate(pid_m);
 
return 0;
}
 
void draw_screen(void)
{
grx_rect(5, 5, 405, 130, rgb16(255, 0, 0));
grx_rect(4, 4, 406, 131, rgb16(0,255,255));
grx_rect(3, 3, 407, 132, rgb16(255, 0, 0));
grx_rect(15, 45, 195, 100, rgb16(255, 0, 0));
grx_rect(215, 45, 395, 100, rgb16(0, 255, 0));
grx_text("Test of PCI6025E DIO function",
9, 7, rgb16(0, 255, 0), rgb16(0, 0, 0));
grx_text("DIO 4-5-6-7 are configured in input mode",
9, 20, rgb16(255, 70, 70), rgb16(0, 0, 0));
grx_text("DIO 0-1-2-3 are configured in output mode",
9, 28, rgb16(255, 70, 70), rgb16(0, 0, 0));
grx_text("Output bits", 35, 50, rgb16(200, 0, 0), rgb16(0, 0, 0));
grx_text("input bits", 235, 50, rgb16(30,255,30), rgb16(0, 0, 0));
grx_text("CTRL + C to exit", 9, 115, rgb16(255,255,0), rgb16(0,0,0));
}
 
/*
* At each activation this task change output value of lowest digitals line
* and read value on highest digital lines, showing them at video
*/
TASK test_DIO(int dummy)
{
BYTE out_val = 0x00,
in_val = 0;
int i;
char buf[10];
 
//DIO 0..3 configured as output
//DIO 4..7 configured as input
DIO_setup(0x0F);
 
while(1){
DIO_write(out_val); //sends out value
in_val = DIO_read() >> 4; //reads value
 
for(i=3; i>=0; i--){
if( (out_val>>i)%2 )
grx_text("1", 25+10*(3-i), 75, rgb16(255,0,0), rgb16(0,0,0));
else
grx_text("0", 25+10*(3-i), 75, rgb16(255,0,0), rgb16(0,0,0));
if( (in_val>>i)%2 )
grx_text("1", 225+10*(3-i), 75, rgb16(0,255,0), rgb16(0,0,0));
else
grx_text("0", 225+10*(3-i), 75, rgb16(0,255,0), rgb16(0,0,0));
}
sprintf(buf, "%03d", out_val);
grx_text(buf, 80, 75, rgb16(255,0,0), rgb16(0,0,0));
sprintf(buf, "%03d", in_val);
grx_text(buf, 280, 75, rgb16(0,255,0), rgb16(0,0,0));
 
out_val = (out_val+1)%16;
task_endcycle();
}
}
 
void close_event(void *arg)
{
switch(system){
case 0: sys_shutdown_message("Regular end\n"); break;
case 10:sys_shutdown_message("Cannot create task TEST DIO\n"); break;
case 21:sys_shutdown_message("No National board on PC\n"); break;
case 30:sys_shutdown_message("Cannot start graphic envirorment\n"); break;
default: sys_shutdown_message("Unknown exit\n"); break;
}
}
 
void exit_fun(KEY_EVT *k)
{
system = 0;
close_event(NULL);
 
exit(1);
}
 
/demos/tags/rel_1_5_4/pci6025e/makefile
0,0 → 1,32
#
#
# PCI6025E Examples and Test programs
#
#
 
ifndef BASE
BASE=../..
endif
include $(BASE)/config/config.mk
 
PROGS= test_dac wave test_dio test_ppi test_ec test_bec test_mes test_bms
 
include $(BASE)/config/example.mk
 
test_dac:
make -f $(SUBMAKE) APP=test_dac OTHEROBJS=initfile.o SHARKOPT="__LINUXC26__ __PCI__ __6025E__ __INPUT__ __FB__"
wave:
make -f $(SUBMAKE) APP=wave OTHEROBJS=initfile.o SHARKOPT="__LINUXC26__ __PCI__ __6025E__ __INPUT__ __FB__"
test_dio:
make -f $(SUBMAKE) APP=test_dio OTHEROBJS=initfile.o SHARKOPT="__LINUXC26__ __PCI__ __6025E__ __INPUT__ __FB__"
test_ppi:
make -f $(SUBMAKE) APP=test_ppi OTHEROBJS=initfile.o SHARKOPT="__LINUXC26__ __PCI__ __6025E__ __INPUT__ __FB__"
test_ec:
make -f $(SUBMAKE) APP=test_ec OTHEROBJS=initfile.o SHARKOPT="__LINUXC26__ __PCI__ __6025E__ __INPUT__ __FB__"
test_bec:
make -f $(SUBMAKE) APP=test_bec OTHEROBJS=initfile.o SHARKOPT="__LINUXC26__ __PCI__ __6025E__ __INPUT__ __FB__"
test_mes:
make -f $(SUBMAKE) APP=test_mes OTHEROBJS=initfile.o SHARKOPT="__LINUXC26__ __PCI__ __6025E__ __INPUT__ __FB__"
test_bms:
make -f $(SUBMAKE) APP=test_bms OTHEROBJS=initfile.o SHARKOPT="__LINUXC26__ __PCI__ __6025E__ __INPUT__ __FB__"
 
/demos/tags/rel_1_5_4/base/cabs.dat
0,0 → 1,11
----------------------------------------------------
system tick (ms): 1
----------------------------------------------------
 
task periods (ticks)
----------------------------------------------------
producer 1: 200 consumer 1: 400
producer 2: 100 consumer 2: 400
producer 3: 300 consumer 3: 150
producer 4: 800 consumer 4: 200
----------------------------------------------------
/demos/tags/rel_1_5_4/base/initfile.c
0,0 → 1,184
/*
* Project: S.Ha.R.K
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* Authors:
* ...
* Tullio Facchinetti <tullio.facchinetti@unipv.it>
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/*
* 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 "edf/edf/edf.h"
#include "cbs/cbs/cbs.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
#include "intdrive/intdrive/intdrive.h"
 
#include "sem/sem/sem.h"
#include "hartport/hartport/hartport.h"
 
#include "pi/pi/pi.h"
#include "pc/pc/pc.h"
#include "srp/srp/srp.h"
#include "npp/npp/npp.h"
#include "nop/nop/nop.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
 
#define FRAME_BUFFER_DEVICE 0
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
LEVEL EDF_level;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_level = EDF_register_level(EDF_ENABLE_ALL);
CBS_register_level(CBS_ENABLE_ALL, EDF_level);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
 
PI_register_module();
PC_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(1);
}
 
}
 
int device_drivers_init() {
 
KEYB_PARMS kparms = BASE_KEYB;
LINUXC26_register_module(TRUE);
 
INPUT26_init();
 
keyb_def_ctrlC(kparms, NULL);
 
KEYB26_init(&kparms);
 
return 0;
 
}
 
int device_drivers_close() {
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
/demos/tags/rel_1_5_4/base/ipcidemo.c
0,0 → 1,149
/*
* Project: S.Ha.R.K
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/*
* 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 "edf/edf/edf.h"
#include "hardcbs/hardcbs/hardcbs.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
#include "intdrive/intdrive/intdrive.h"
 
#include "sem/sem/sem.h"
#include "hartport/hartport/hartport.h"
 
#include "drivers/shark_linuxc26.h"
#include "drivers/shark_pci26.h"
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 1000
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_register_level(EDF_ENABLE_ALL);
HCBS_register_level(HCBS_ENABLE_ALL, 1);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
set_shutdown_task();
 
device_drivers_init();
 
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(1);
}
 
}
 
int device_drivers_init() {
LINUXC26_register_module(TRUE);
PCI26_init();
 
return 0;
}
 
int device_drivers_close() {
 
return 0;
 
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg) {
 
struct timespec t;
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
 
}
/demos/tags/rel_1_5_4/base/aster3.c
0,0 → 1,303
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: aster3.c,v 1.11 2006-07-05 08:26:37 tullio Exp $
 
Test Number 10 (A):
 
this is a part of the classic Hartik demo Aster.
 
it is based on aster2.c, with the use of TBS to serve a set of aperiodic
tasks.
 
There are APER_MAX tasks sleeping, and when an asteroide task finish
the current activation, it activate also an aperiodic task chosen
randomly (if the task chosen is already active, the task_activate do
nothing!)
 
 
*/
 
#include "kernel/kern.h"
#include "edf/edf/edf.h"
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
#define APER_MAX 8
 
/* first numbers runs on a pentium 133, second numbers on a celeron 366 */
#define PER_WCET 30000 /* 6200 */
#define APER_WCET 50000 /* 18400 */
#define CLOCK_WCET 1000 /* 200 */
#define ASTER_WCET 1000 /* 200 */
#define MIN_PERIOD 200 /* 64, in ms */
 
#define APER_REP 22000
 
PID aper_table[APER_MAX];
 
TASK asteroide(void)
{
int i;
int y = rand() % 7 + 1;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < ASTER_LIM) {
load1 = 10000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
num_aster--;
return 0;
}
 
TASK aper_asteroid(void *a)
{
int i;
int y = rand() % 7 + 1;
 
int load1,j;
int c;
 
char s[2];
 
c = (int)a;
s[0] = '*'; s[1] = 0;
 
for (;;) {
i = 1;
while (i < ASTER_LIM) {
load1 = APER_REP; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
s[0] = c;
puts_xy(i,y,rand()%15+1,s);
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
}
 
TASK aster()
{
PID p;
 
HARD_TASK_MODEL m;
int r;
int x; // adaptive bandwidth...
 
hard_task_default_model(m);
hard_task_def_wcet(m,PER_WCET);
hard_task_def_ctrl_jet(m);
 
x = MIN_PERIOD;
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (x+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc),errno);
}
else {
num_aster++;
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(1));
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(1));
task_endcycle();
}
}
 
 
 
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
and plot on the screen the elapsed times... */
TASK jetcontrol()
{
int i; /* a counter */
TIME sum, max, curr, last[5];
int nact;
int j; /* the elements set by jet_gettable */
PID p;
 
 
kern_cli();
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
kern_sti();
 
for (;;) {
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
kern_cli();
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
p, (int)sum/(nact==0 ? 1 : nact), (int)max, (int)nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
kern_sti();
i++;
}
task_endcycle();
}
}
 
int main(int argc, char **argv)
{
PID p1,p2;//,p3,p4,p5,p6;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
SOFT_TASK_MODEL m_aper;
int i;
 
clear();
 
hard_task_default_model(m);
hard_task_def_wcet(m,ASTER_WCET);
hard_task_def_mit(m,10000);
hard_task_def_group(m,1);
hard_task_def_ctrl_jet(m);
 
nrt_task_default_model(m_nrt);
nrt_task_def_group(m_nrt,1);
nrt_task_def_ctrl_jet(m_nrt);
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
sys_shutdown_message("aster3.c(main): Could not create task <aster> ...");
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) {
sys_shutdown_message("aster3.c(main): Could not create task <Clock> ...");
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_aperiodic(m_aper);
 
soft_task_def_level(m_aper, 3);
aper_table[0] = task_create("JetControl",jetcontrol,&m_aper,NULL);
if (aper_table[0] == -1) {
sys_shutdown_message("aster3.c(main): Could not create task <JetControl> ...");
exit(1);
}
char st[80];
 
for (i=1; i<APER_MAX; i++) {
soft_task_def_level(m_aper, i/4 + 2);
soft_task_def_arg(m_aper, (void *)(i/4 ? 'Û' : '±'));
aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL);
if (aper_table[i] == -1) {
sprintf(st, "aster3.c(main): Could not create task <aper> #%d...", i);
sys_shutdown_message(st);
exit(1);
}
}
 
 
group_activate(1);
 
{
struct timespec t;
do {
sys_gettime(&t);
} while (t.tv_sec < 60);
}
 
exit(0);
return 0;
}
 
/demos/tags/rel_1_5_4/base/iaster4.c
0,0 → 1,177
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
#include "kernel/kern.h"
#include "intdrive/intdrive/intdrive.h"
#include "edf/edf/edf.h"
#include "rr/rr/rr.h"
#include "tbs/tbs/tbs.h"
#include "cbs/cbs/cbs.h"
#include "rrsoft/rrsoft/rrsoft.h"
#include "dummy/dummy/dummy.h"
#include "sem/sem/sem.h"
 
/*+ sysyem tick in us +*/
#define TICK 0
 
#define RRTICK 5000
#define TBS_NUM 1
#define TBS_DEN 10
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
#define INTDRIVE_FLAG 0
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
 
#define FRAME_BUFFER_DEVICE 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
LEVEL EDF_level;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_level = EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
TBS_register_level(TBS_ENABLE_ALL, 1, TBS_NUM, TBS_DEN);
TBS_register_level(TBS_ENABLE_ALL, 1, TBS_NUM*3, TBS_DEN);
CBS_register_level(CBS_ENABLE_ALL, EDF_level);
dummy_register_level();
 
SEM_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(1);
}
 
}
 
int device_drivers_init() {
 
KEYB_PARMS kparms = BASE_KEYB;
LINUXC26_register_module(TRUE);
 
INPUT26_init();
 
keyb_def_ctrlC(kparms, NULL);
 
KEYB26_init(&kparms);
 
return 0;
 
}
 
int device_drivers_close() {
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
/demos/tags/rel_1_5_4/base/iaster6.c
0,0 → 1,222
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: iaster6.c,v 1.8 2006-07-03 13:12:06 tullio Exp $
 
File: $File$
Revision: $Revision: 1.8 $
Last update: $Date: 2006-07-03 13:12:06 $
------------
 
System initialization file
 
h3pips.c
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a RR (Round Robin) level
a CBS (Costant Bandwidth Server) level
a PS (Polling Server) level
a Dummy level
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
NRT_TASK_MODEL at level 1
SOFT_TASK_MODEL (met, period) at level 2
SOFT_TASK_MODEL (periodicity=APERIODIC) at level 3
 
**/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
 
 
#include "kernel/kern.h"
 
#include "intdrive/intdrive/intdrive.h"
#include "edf/edf/edf.h"
#include "cbs/cbs/cbs.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
#include "ps/ps/ps.h"
 
#include "sem/sem/sem.h"
#include "cabs/cabs/cabs.h"
#include "pi/pi/pi.h"
#include "pc/pc/pc.h"
#include "srp/srp/srp.h"
#include "npp/npp/npp.h"
#include "nop/nop/nop.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
 
/*+ sysyem tick in us +*/
#define TICK 1000
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
LEVEL EDF_level;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_level = EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
CBS_register_level(CBS_ENABLE_ALL, EDF_level);
PS_register_level(2 /*PS_ENABLE_ALL_EDF*/,1,500,100000);
dummy_register_level();
 
SEM_register_module();
 
CABS_register_module();
 
PI_register_module();
PC_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(1);
}
 
}
 
int device_drivers_init() {
 
KEYB_PARMS kparms = BASE_KEYB;
LINUXC26_register_module(TRUE);
 
INPUT26_init();
 
keyb_def_ctrlC(kparms, NULL);
 
KEYB26_init(&kparms);
 
return 0;
 
}
 
int device_drivers_close() {
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
 
 
/demos/tags/rel_1_5_4/base/aster4.c
0,0 → 1,404
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: aster4.c,v 1.6 2006-07-03 13:08:29 tullio Exp $
 
Test Number 13 (D):
 
this is a part of the classic Hartik demo Aster, and it is based on aster 3.
 
The demo creates:
- a set of TBS tasks assigned to 2 TBS servers initialized with different bandwidth.
 
- a set of periodic tasks, just to make noise (function asteroide)
 
- a set of CBS tasks that are created to fill the available free
bandwidth (function soft_aster)
 
- a few service task (the one that creates the CBS tasks (aster), a clock,
JET info visualization
 
- a set of never ending "system tasks" that simulate a device driver
task that will end only at shutdown (function aper_asteroid)
 
- a keyboard task that will execute an hook to terminate the system
 
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
#include "kernel/kern.h"
#include "edf/edf/edf.h"
#include "cbs/cbs/cbs.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
#define PER_MAX 5
#define APER_MAX 8
 
// These numbers works on a Pentium 133 */
#define PER_WCET 25000
#define APER_WCET 53000
#define CLOCK_WCET 1000
#define ASTER_WCET 1000
#define SOFT_MET 6300
 
#define APER_REP 22000
 
PID aper_table[APER_MAX];
 
int shutting_down = 0;
 
TASK asteroide(void)
{
int i;
int y = rand() % 7 + 1;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
for (;;) {
i = 1;
while (i < ASTER_LIM) {
load1 = 10000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
//num_aster--;
}
 
TASK aper_asteroid(void *a)
{
int i;
int y = rand() % 7 + 1;
 
int load1,j;
int c;
 
char s[2];
 
c = (int)a;
s[0] = '*'; s[1] = 0;
 
for (;;) {
i = 1;
while (i < ASTER_LIM) {
load1 = APER_REP; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
s[0] = c;
puts_xy(i,y,rand()%15+1,s);
 
if (shutting_down) {
cprintf("Ending System Task %d\n",exec_shadow);
return 0;
}
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
}
 
TASK soft_aster(void)
{
int i;
int y = rand() % 7 + 1;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
i = 1;
while (i < ASTER_LIM) {
load1 = 1000 + rand()%9000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
s[0] = 1;
puts_xy(i,y,rand()%15+1,s);
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
num_aster--;
return 0;
}
 
TASK aster()
{
PID p;
 
HARD_TASK_MODEL m;
SOFT_TASK_MODEL m_soft;
int r;
int x; // adaptive bandwidth...
 
srand(7);
 
/* create a set of periodic tasks, just to make noise */
hard_task_default_model(m);
hard_task_def_wcet(m,PER_WCET);
hard_task_def_ctrl_jet(m);
for (x=0; x<PER_MAX; x++) {
r = (rand() % 200);
hard_task_def_mit(m, (64+r)*1000);
p = task_create("per",asteroide,&m,NULL);
if (p!=-1) task_activate(p);
}
 
soft_task_default_model(m_soft);
soft_task_def_met(m_soft,SOFT_MET);
soft_task_def_ctrl_jet(m_soft);
 
x = 64;
 
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
soft_task_def_period(m_soft, (x+r)*1000);
p = task_create("aaa",soft_aster,&m_soft,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc),errno);
}
else {
num_aster++;
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(1));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(5));
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(1));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(5));
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 == 5)
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)CBS_get_nact(4,p), (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
else
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
kern_sti();
i++;
}
}
}
 
void endfun(KEY_EVT *k)
{
exit(0);
}
 
void exiting(void *arg)
{
cprintf("System shut down...\n");
shutting_down = 1;
}
 
int main(int argc, char **argv)
{
KEY_EVT k;
 
PID p1,p2,p3;
HARD_TASK_MODEL m;
SOFT_TASK_MODEL m_aper;
SOFT_TASK_MODEL m_soft;
int i;
 
k.ascii = 'c';
k.scan = KEY_C;
k.flag = CNTL_BIT;
k.status = KEY_PRESSED;
keyb_hook(k,endfun,FALSE);
k.flag = CNTR_BIT;
k.status = KEY_PRESSED;
keyb_hook(k,endfun,FALSE);
 
clear();
cprintf("Press Ctrl-C to end the demo...");
 
sys_atrunlevel(exiting, NULL, RUNLEVEL_SHUTDOWN);
hard_task_default_model(m);
hard_task_def_wcet(m,ASTER_WCET);
hard_task_def_mit(m,10000);
hard_task_def_group(m,1);
hard_task_def_ctrl_jet(m);
 
soft_task_default_model(m_soft);
soft_task_def_met(m_soft,1000);
soft_task_def_period(m_soft,100000);
soft_task_def_group(m_soft,1);
soft_task_def_ctrl_jet(m_soft);
soft_task_def_aperiodic(m_soft);
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
sys_shutdown_message("aster4.c(main): Could not create task <aster> ...");
exit(0);
}
 
hard_task_def_mit(m,500000);
hard_task_def_wcet(m,CLOCK_WCET);
p2 = task_create("Clock",clock,&m,NULL);
if (p2 == -1) {
sys_shutdown_message("aster4.c(main): Could not create task <Clock> ...");
exit(0);
}
 
p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
if (p3 == -1) {
sys_shutdown_message("aster4.c(main): Could not create task <JetControl> ...");
exit(0);
}
 
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 + 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) {
sys_shutdown_message("aster4.c(main): Could not create task <aper> ...");
exit(0);
}
}
 
group_activate(1);
return 0;
}
 
/demos/tags/rel_1_5_4/base/aster6.c
0,0 → 1,448
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai, Gerardo Lamastra and Giuseppe Lipari
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: aster6.c,v 1.8 2006-07-03 13:11:52 tullio Exp $
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 17 (h), and the JobControl Task uses an
SOFT_TASK_MODEL served by a polling server
 
*/
 
#include "kernel/kern.h"
#include "edf/edf/edf.h"
#include "cbs/cbs/cbs.h"
 
#include <drivers/shark_keyb26.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);
 
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) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
soft_task_def_period(m_soft, (x+r)*1000);
p = task_create("aaa",soft_aster,&m_soft,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc),errno);
mutex_unlock(&m1);
}
else {
num_aster++;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
mutex_unlock(&m1);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(1));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(3));
 
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(1));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(3));
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 == 3)
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)
{
 
exit(0);
 
}
 
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;
emerg.ascii = 'c';
emerg.scan = KEY_C;
emerg.flag = CNTL_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,fine,FALSE);
emerg.flag = CNTR_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,fine,FALSE);
 
clear();
 
hard_task_default_model(m);
hard_task_def_mit(m,100000);
hard_task_def_wcet(m,ASTER_WCET);
hard_task_def_group(m,1);
hard_task_def_ctrl_jet(m);
 
// nrt_task_default_model(m_nrt);
// nrt_task_def_group(m_nrt,1);
// nrt_task_def_ctrl_jet(m_nrt);
 
 
soft_task_default_model(m_aper);
soft_task_def_group(m_aper,1);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,100000);
soft_task_def_met(m_soft,JET_WCET);
soft_task_def_group(m_soft,1);
soft_task_def_ctrl_jet(m_soft);
soft_task_def_aperiodic(m_soft);
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <aster> ...");
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) {
sys_shutdown_message("test7.c(main): Could not create task <Clock> ...");
exit(1);
}
 
// p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
p3 = task_create("JetControl",jetcontrol,&m_aper,NULL);
if (p3 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <JetControl> ...");
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 = 20;
fineprg.tv_nsec = 0;
kern_event_post(&fineprg,(void (*)(void *))fine,NULL);
group_activate(1);
 
return 0;
}
 
/demos/tags/rel_1_5_4/base/iaster7.c
0,0 → 1,209
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: iaster7.c,v 1.8 2006-07-03 12:57:33 tullio Exp $
 
File: $File$
Revision: $Revision: 1.8 $
Last update: $Date: 2006-07-03 12:57:33 $
------------
 
System initialization file
 
The tick is set to TICK ms.
 
This file contains the 2 functions needed to initialize the system.
 
These functions register a set of scheduling modules, in a fixed or
dynamic priority way...
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
SOFT_TASK_MODEL (periodicity=APERIODIC) at level 1
NRT_TASK_MODEL at level 2
SOFT_TASK_MODEL (periodicity=APERIODIC, wcet (only if TBS) ) at level 3,4
 
**/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
 
 
#include "kernel/kern.h"
#include "intdrive/intdrive/intdrive.h"
#include "edf/edf/edf.h"
#include "tbs/tbs/tbs.h"
 
#include "rm/rm/rm.h"
#include "rr/rr/rr.h"
#include "ps/ps/ps.h"
 
#include "dummy/dummy/dummy.h"
 
#include "sem/sem/sem.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
 
/*+ sysyem tick in us +*/
#define TICK 0
 
#define RRTICK 10000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
RM_register_level(RM_ENABLE_ALL);
PS_register_level(PS_ENABLE_ALL_RM,1,1000,100000);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
PS_register_level(4,1,10000,100000);
PS_register_level(4,1,30000,100000);
 
dummy_register_level();
 
SEM_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(1);
}
 
}
 
int device_drivers_init() {
 
KEYB_PARMS kparms = BASE_KEYB;
LINUXC26_register_module(TRUE);
 
INPUT26_init();
 
keyb_def_ctrlC(kparms, NULL);
 
KEYB26_init(&kparms);
 
return 0;
 
}
 
int device_drivers_close() {
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
 
 
 
 
/demos/tags/rel_1_5_4/base/iaster8.c
0,0 → 1,224
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: iaster8.c,v 1.8 2006-07-03 12:53:41 tullio Exp $
 
File: $File$
Revision: $Revision: 1.8 $
Last update: $Date: 2006-07-03 12:53:41 $
------------
 
System initialization file
 
h3piss.c
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a CBS (Costant Bandwidth Server) level
a SS (Sporadic Server) level
a RR (Round Robin) level
a Dummy level
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
SOFT_TASK_MODEL (met, period) at level 1
SOFT_TASK_MODEL (periodicity=APERIODIC) at level 2
NRT_TASK_MODEL at level 3
 
**/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
 
 
#include "kernel/kern.h"
#include "intdrive/intdrive/intdrive.h"
#include "rm/rm/rm.h"
#include "edf/edf/edf.h"
#include "cbs/cbs/cbs.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
#include "ss/ss/ss.h"
 
#include "sem/sem/sem.h"
#include "cabs/cabs/cabs.h"
#include "pi/pi/pi.h"
#include "pc/pc/pc.h"
#include "srp/srp/srp.h"
#include "npp/npp/npp.h"
#include "nop/nop/nop.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
 
/*+ system tick in us +*/
#define TICK 1000
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
LEVEL EDF_level;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_level = EDF_register_level(EDF_ENABLE_ALL);
CBS_register_level(CBS_ENABLE_ALL, EDF_level);
SS_register_level(SS_ENABLE_GUARANTEE_EDF,1,5000,20000);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
 
CABS_register_module();
 
PC_register_module();
PI_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(1);
}
 
}
 
int device_drivers_init() {
 
KEYB_PARMS kparms = BASE_KEYB;
LINUXC26_register_module(TRUE);
 
INPUT26_init();
 
keyb_def_ctrlC(kparms, NULL);
 
KEYB26_init(&kparms);
 
return 0;
 
}
 
int device_drivers_close() {
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
 
 
 
 
/demos/tags/rel_1_5_4/base/aster7.c
0,0 → 1,314
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai, Massimiliano Giorgi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: aster7.c,v 1.7 2006-07-03 12:57:05 tullio Exp $
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 10(A), and test the PS with RM.
 
The JetControl is served by a dedicated Polling Server, too.
 
There are APER_MAX tasks sleeping, and when an asteroide task finish
the current activation, it activate also an aperiodic task chosen
randomly (if the task chosen is already active, the task_activate do
nothing!)
 
*/
 
#include "kernel/kern.h"
#include "edf/edf/edf.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
#define APER_MAX 8
 
/* Pentium 133 / Celeron 366 */
#define PER_WCET 25000 /* 7800 */
#define APER_WCET 5500 /* 1400 */
#define CLOCK_WCET 500 /* 200 */
#define ASTER_WCET 500 /* 200 */
 
#define APER_REP 2200
 
PID aper_table[APER_MAX];
 
TASK asteroide(void)
{
int i;
int y = rand() % 7 + 1;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < ASTER_LIM) {
load1 = 10000; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_activate(aper_table[rand()%APER_MAX]);
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
num_aster--;
return 0;
}
 
TASK aper_asteroid(void *a)
{
int i;
int y = rand() % 7 + 1;
 
int load1,j;
int c;
 
char s[2];
 
c = (int)a;
s[0] = '*'; s[1] = 0;
 
for (;;) {
i = 1;
while (i < ASTER_LIM) {
load1 = APER_REP; //8000 + rand()%2000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
s[0] = c;
puts_xy(i,y,rand()%15+1,s);
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
}
 
TASK aster()
{
PID p;
 
HARD_TASK_MODEL m;
int r;
int x; // adaptive bandwidth...
 
hard_task_default_model(m);
hard_task_def_wcet(m,PER_WCET);
hard_task_def_ctrl_jet(m);
 
x = 200;
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (x+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc),errno);
}
else {
num_aster++;
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(1));
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(1));
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)
{
exit(0);
}
 
 
int main(int argc, char **argv)
{
PID p1,p2,p3; //,p4,p5,p6;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
SOFT_TASK_MODEL m_aper;
int i;
 
KEY_EVT emerg;
 
clear();
 
cprintf("Press Ctrl-C to end the demo...");
 
emerg.ascii = 'c';
emerg.scan = KEY_C;
emerg.flag = CNTL_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,fine,FALSE);
emerg.flag = CNTR_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,fine,FALSE);
 
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) {
sys_shutdown_message("test7.c(main): Could not create task <aster> ...");
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) {
sys_shutdown_message("test7.c(main): Could not create task <Clock> ...");
exit(1);
}
 
soft_task_default_model(m_aper);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_level(m_aper, 2);
soft_task_def_group(m_aper,1);
soft_task_def_aperiodic(m_aper);
p3 = task_create("JetControl",jetcontrol,&m_aper,NULL);
if (p3 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <JetControl> ...");
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 + 4);
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) {
sys_shutdown_message("test7.c(main): Could not create task <aper> ...");
exit(1);
}
}
 
group_activate(1);
return 0;
}
 
/demos/tags/rel_1_5_4/base/aster8.c
0,0 → 1,505
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai, Massimiliano Giorgi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: aster8.c,v 1.7 2006-07-03 12:53:13 tullio Exp $
 
Test for Sporadic Server (ss):
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 17 (h), and the JobControl Task uses an
SOFT_TASK_MODEL served by a sporadic server
There are two "dummy" tasks that increment a counter and print
the value. One uses a SOFT_TASK_MODEL served by sporadic server,
the other uses a NRT_TASK_MODEL handled by RR module.
 
*/
 
#include "kernel/kern.h"
#include "edf/edf/edf.h"
#include "cbs/cbs/cbs.h"
#include "ss/ss/ss.h"
 
#include <drivers/shark_keyb26.h>
 
int num_aster = 0;
#define EDF_LEV 1
#define CBS_LEV 2
#define SS_LEV 3
 
#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;
 
SOFT_TASK_MODEL m_soft;
int r;
int x; // adaptive bandwidth...
 
srand(7);
 
 
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) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
soft_task_def_period(m_soft, (x+r)*1000);
p = task_create("aaa",soft_aster,&m_soft,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc), errno);
mutex_unlock(&m1);
}
else {
num_aster++;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u ",x);
mutex_unlock(&m1);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(EDF_LEV));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(CBS_LEV));
printf_xy(62,5,WHITE,"CSss=%6d",SS_availCs(SS_LEV));
mutex_unlock(&m1);
 
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(EDF_LEV));
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_usedbandwidth(CBS_LEV));
printf_xy(62,5,WHITE,"CSss=%6d",SS_availCs(SS_LEV));
mutex_unlock(&m1);
task_endcycle();
}
}
 
 
 
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
and plot on the screen the elapsed times... */
TASK jetcontrol()
{
int i; /* a counter */
TIME sum, max, curr, last[5];
int nact;
int j; /* the elements set by jet_gettable */
PID p;
 
 
mutex_lock(&m1);
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
mutex_unlock(&m1);
 
for (;;) {
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1 /*||
(proc_table[p].pclass & 0xFF00) == APERIODIC_PCLASS ||
(proc_table[p].pclass & 0xFF00) == PERIODIC_PCLASS*/ ) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
mutex_lock(&m1);
if (proc_table[p].task_level == 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++;
task_activate(p3);
task_endcycle();
}
}
}
 
void fine(KEY_EVT *e)
{
 
exit(0);
 
}
 
void mydummyaper(void) {
int i=0;
while(1) {
mutex_lock(&m1);
printf_xy(1,24,RED,"dummyAPER pid=%d: %d",p4,i++);
mutex_unlock(&m1);
task_activate(p4);
task_endcycle();
}
}
 
void mydummynrt(void) {
int i=0;
while(1) {
mutex_lock(&m1);
printf_xy(40,24,RED,"dummyNRT pid=%d: %d",p5,i++);
mutex_unlock(&m1);
}
}
 
int main(int argc, char **argv)
{
// PID p1,p2,p5;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
SOFT_TASK_MODEL m_aper;
SOFT_TASK_MODEL m_soft;
 
#ifdef PIMUTEX
PI_mutexattr_t a;
#endif
 
#ifdef PCMUTEX
PC_mutexattr_t a;
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_t a;
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_t a;
#endif
 
 
KEY_EVT emerg;
emerg.ascii = 'c';
emerg.scan = KEY_C;
emerg.flag = CNTL_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,fine,FALSE);
emerg.flag = CNTR_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,fine,FALSE);
 
clear();
 
cprintf("Press Ctrl-C to end the demo...");
 
hard_task_default_model(m);
hard_task_def_mit(m,100000);
hard_task_def_wcet(m,ASTER_WCET);
hard_task_def_group(m,1);
hard_task_def_ctrl_jet(m);
 
nrt_task_default_model(m_nrt);
nrt_task_def_group(m_nrt,1);
nrt_task_def_ctrl_jet(m_nrt);
 
soft_task_default_model(m_aper);
soft_task_def_group(m_aper,1);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,10000);
soft_task_def_met(m_soft,JET_WCET);
soft_task_def_group(m_soft,1);
soft_task_def_ctrl_jet(m_soft);
soft_task_def_aperiodic(m_soft);
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <aster> ...");
exit(1);
return 0;
}
 
hard_task_def_mit(m,50000);
hard_task_def_wcet(m,CLOCK_WCET);
p2 = task_create("Clock",clock,&m,NULL);
if (p2 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <Clock> ...");
exit(1);
return 0;
}
 
p3 = task_create("JetControl",jetcontrol,&m_aper,NULL);
if (p3 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <JetControl> ...");
exit(1);
return 0;
}
 
p4 = task_create("MyDummyAper",(void *(*)(void*))mydummyaper,&m_aper,NULL);
if (p4 == -1) {
sys_shutdown_message("Could not create task <MyDummyAper> ...");
exit(1);
return 0;
}
 
p5 = task_create("MyDummyNRT",(void *(*)(void*))mydummynrt,&m_nrt,NULL);
if (p5 == -1) {
sys_shutdown_message("Could not create task <MyDummyNRT> ...");
exit(1);
return 0;
}
 
#ifdef PIMUTEX
PI_mutexattr_default(a);
#endif
 
#ifdef PCMUTEX
PC_mutexattr_default(a);
#endif
 
#ifdef NPPMUTEX
NPP_mutexattr_default(a);
#endif
 
#ifdef NOPMUTEX
NOP_mutexattr_default(a);
#endif
 
mutex_init(&m1, &a);
 
group_activate(1);
return 0;
}
 
/demos/tags/rel_1_5_4/base/ego.c
0,0 → 1,204
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: ego.c,v 1.8 2006-07-03 12:47:33 tullio Exp $
 
File: $File$
Revision: $Revision: 1.8 $
Last update: $Date: 2006-07-03 12:47:33 $
------------
**/
 
/*
* Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
/****************************************************************/
/* PERIODIC PROCESS TEST */
/****************************************************************/
 
#include <kernel/kern.h>
 
#include <drivers/shark_keyb26.h>
#include <drivers/shark_fb26.h>
#define X0 10
 
/* task periods */
#define PERIOD_T1 100000
#define PERIOD_T2 200000
#define PERIOD_T3 300000
 
/* X position of the text printed by each task */
int y[3] = {100, 180, 260};
 
/* text printed by each task */
char talk[3][50] = { "I am ego1 and I print a character every 100 ms",
"I am ego2 and I print a character every 200 ms",
"I am ego3 and I print a character every 300 ms"};
 
/***************************************************************/
 
TASK ego(void *arg)
{
int i = (int)arg;
int leng;
char s[2];
int x;
int j = 0;
 
/* compute the length of the string to print */
leng = 0;
while (talk[i][leng] != 0) leng++;
 
x = X0;
s[1] = 0;
task_endcycle();
 
while (1) {
s[0] = talk[i][j];
grx_text(s,x,y[i],rgb16(255,255,255),0);
x += 8;
if (++j == leng) {
j = 0;
x = X0;
y[i] += 8;
if (y[i]>340) y[i]=100;
}
task_endcycle();
}
}
 
 
/****************************************************************/
 
/* This function is called when Alt-X is pressed.
*/
void my_end(KEY_EVT* e)
{
exit(0);
}
 
/******************************************************************/
 
/* This function is called when the system exit correctly after Alt-X.
It exits from the graphic mode and then it prints a small greeting.
Note that:
- The function calls grx_exit, so it must be registered using
RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because
at that point the kernel is already returned in real mode!!!)
- When an exception is raised, the exception handler is called.
Since the exception handler already exits from the graphic mode,
this funcion has not to be called. For this reason:
. we registered byebye using the flag NO_AT_ABORT
. the exception handler exits using exit; in that way byebye is
NOT called
*/
 
/****************************** MAIN ******************************/
 
int main(int argc, char **argv)
{
PID pid1, pid2, pid3;
KEY_EVT emerg;
HARD_TASK_MODEL m1, m2, m3;
 
/* set the keyboard handler to exit correctly */
emerg.ascii = 'c';
emerg.scan = KEY_C;
emerg.flag = CNTL_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,my_end,FALSE);
emerg.flag = CNTR_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,my_end,FALSE);
 
/* a small banner */
grx_text("EGO Test",8,8,rgb16(255,255,255),0);
grx_text("Press Ctrl-C to exit",8,16,rgb16(255,255,255),0);
 
/* ego1 creation */
hard_task_default_model(m1);
hard_task_def_ctrl_jet (m1);
hard_task_def_arg (m1, (void *)0);
hard_task_def_wcet (m1, 5000);
hard_task_def_mit (m1, PERIOD_T1);
hard_task_def_group (m1,1);
pid1 = task_create("ego1", ego, &m1, NULL);
if (pid1 == NIL) {
sys_shutdown_message("Could not create task <ego1>");
exit(1);
}
 
/* ego2 creation */
hard_task_default_model(m2);
hard_task_def_ctrl_jet (m2);
hard_task_def_arg (m2, (void *)1);
hard_task_def_wcet (m2, 5000);
hard_task_def_mit (m2, PERIOD_T2);
hard_task_def_group (m2,1);
pid2 = task_create("ego2", ego, &m2, NULL);
if (pid2 == NIL) {
sys_shutdown_message("Could not create task <ego2>");
exit(1);
}
 
/* ego3 creation */
hard_task_default_model(m3);
hard_task_def_ctrl_jet (m3);
hard_task_def_arg (m3, (void *)2);
hard_task_def_wcet (m3, 5000);
hard_task_def_mit (m3, PERIOD_T3);
hard_task_def_group (m3,1);
pid3 = task_create("ego3", ego, &m3, NULL);
if (pid3 == NIL) {
sys_shutdown_message("Could not create task <ego3>");
exit(1);
}
 
/* and finally we activate the three threads... */
group_activate(1);
 
/*
now the task main ends, but the system does not shutdown because
there are the three task ego1, ego2, and ego3 running.
 
The demo will finish if a Alt-X key is pressed.
*/
 
return 0;
}
 
/****************************************************************/
/demos/tags/rel_1_5_4/base/initgraph.c
0,0 → 1,194
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* 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 "intdrive/intdrive/intdrive.h"
#include "edf/edf/edf.h"
#include "hardcbs/hardcbs/hardcbs.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
 
#include "sem/sem/sem.h"
#include "cabs/cabs/cabs.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_pci26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#define FRAME_BUFFER_DEVICE 0
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 2000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
LEVEL EDF_level;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_level = EDF_register_level(EDF_ENABLE_ALL);
HCBS_register_level(HCBS_ENABLE_ALL, EDF_level);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
CABS_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
exit(0);
}
 
}
 
int device_drivers_init() {
 
int res;
KEYB_PARMS kparms = BASE_KEYB;
LINUXC26_register_module(TRUE);
 
PCI26_init();
 
INPUT26_init();
 
keyb_def_ctrlC(kparms, NULL);
 
KEYB26_init(&kparms);
 
FB26_init();
res = FB26_open(FRAME_BUFFER_DEVICE);
if (res) {
cprintf("Error: Cannot open graphical mode\n");
KEYB26_close();
INPUT26_close();
exit(0);
}
FB26_use_grx(FRAME_BUFFER_DEVICE);
FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
return 0;
 
}
 
int device_drivers_close() {
FB26_close(FRAME_BUFFER_DEVICE);
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
return NULL;
 
}
/demos/tags/rel_1_5_4/base/aster5.c
0,0 → 1,476
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai, Gerardo Lamastra and Giuseppe Lipari
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: aster5.c,v 1.7 2006-07-03 11:14:56 tullio Exp $
 
this is a part of the classic Hartik demo Aster.
 
it is based on test 13 (d), and use the CBS to serve the periodic tasks.
 
There are not periodic tasks, only CBS tasks.
 
The tasks use a PI, NPP or NOP mutex to access the video memory.
 
A flag (LONGSC) is provided to try long and short critical sections.
 
This demo is really interesting because you can note the behavior of
the system, and the differences between the various protocols...
 
*/
 
#include "kernel/kern.h"
#include "edf/edf/edf.h"
#include "cbs/cbs/cbs.h"
 
#include <drivers/shark_keyb26.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) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
soft_task_def_period(m_soft, (x+r)*1000);
p = task_create("aaa",soft_aster,&m_soft,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc),errno);
mutex_unlock(&m1);
}
else {
num_aster++;
mutex_lock(&m1);
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
mutex_unlock(&m1);
 
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
mutex_lock(&m1);
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"Uedf=%12u",EDF_usedbandwidth(1));
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(1));
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)
{
exit(0);}
 
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;
emerg.ascii = 'c';
emerg.scan = KEY_C;
emerg.flag = CNTL_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,fine,FALSE);
emerg.flag = CNTR_BIT;
emerg.status = KEY_PRESSED;
keyb_hook(emerg,fine,FALSE);
 
clear();
 
hard_task_default_model(m);
hard_task_def_wcet(m,ASTER_WCET);
hard_task_def_mit(m,100000);
hard_task_def_group(m,1);
hard_task_def_ctrl_jet(m);
 
// nrt_task_default_model(m_nrt);
// nrt_task_def_group(m_nrt,1);
// nrt_task_def_ctrl_jet(m_nrt);
 
 
soft_task_default_model(m_aper);
soft_task_def_group(m_aper,1);
soft_task_def_ctrl_jet(m_aper);
soft_task_def_aperiodic(m_aper);
 
soft_task_default_model(m_soft);
soft_task_def_period(m_soft,JET_PERIOD);
soft_task_def_met(m_soft,JET_WCET);
soft_task_def_group(m_soft,1);
soft_task_def_ctrl_jet(m_soft);
soft_task_def_aperiodic(m_soft);
 
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <aster> ...");
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) {
sys_shutdown_message("test7.c(main): Could not create task <Clock> ...");
exit(1);
}
 
// p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
p3 = task_create("JetControl",jetcontrol,&m_soft,NULL);
if (p2 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <JetControl> ...");
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> ...");
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;
group_activate(1);
return 0;
}
 
/demos/tags/rel_1_5_4/base/imdemo.c
0,0 → 1,102
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: imdemo.c,v 1.5 2005-05-10 17:21:17 mauro Exp $
**/
 
#include "kernel/kern.h"
 
#include "intdrive/intdrive/intdrive.h"
#include "edf/edf/edf.h"
#include "cbs/cbs/cbs.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
 
#include "sem/sem/sem.h"
#include "hartport/hartport/hartport.h"
#include "cabs/cabs/cabs.h"
#include "pi/pi/pi.h"
#include "pc/pc/pc.h"
#include "srp/srp/srp.h"
#include "npp/npp/npp.h"
#include "nop/nop/nop.h"
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_U 1000
#define INTDRIVE_FLAG 0
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
CBS_register_level(CBS_ENABLE_ALL, 1);
dummy_register_level();
 
SEM_register_module();
 
CABS_register_module();
 
PI_register_module();
PC_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
__call_main__(mb);
 
return (void *)0;
 
}
 
/demos/tags/rel_1_5_4/base/aster2.c
0,0 → 1,241
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: aster2.c,v 1.6 2005-02-25 11:10:46 pj Exp $
 
this is a part of the classic Hartik demo Aster.
 
It checks:
- jet functions
- The EDF level with many task, with almost full bandwidth used
 
*/
 
 
#include "kernel/kern.h"
#include "edf/edf/edf.h"
 
int num_aster = 0;
#define ASTER_LIM 60
#define DISPLAY_MAX 15
#define ASTER_MAX 70
#define STAT_Y 9
 
// first numbers for wcet and periods are for a 486/25, the others for a
// celeron 366
 
#define PER_WCET 13000 /*6200*/
#define CLOCK_WCET 1200 /* 100*/
#define ASTER_WCET 1200 /* 100*/
 
#define ASTER_MEAN_PERIOD 64 /*64*/
 
#define END_TEST_TIME 60
 
TASK asteroide(void)
{
int i;
int y = rand() % 7 + 1;
 
int load1,j;
 
char s[2];
 
s[0] = '*'; s[1] = 0;
 
/*for (;;)*/ {
i = 1;
while (i < ASTER_LIM) {
load1 = 1000; //10000; // 5000 + rand()%5000;
for (j=0; j<load1; j++) {
s[0] = '*' + rand() % 100;
puts_xy(i,y,rand()%15+1,s);
}
 
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
}
num_aster--;
return 0;
}
 
TASK aster()
{
PID p;
 
HARD_TASK_MODEL m;
int r;
int x; // adaptive bandwidth...
 
hard_task_default_model(m);
hard_task_def_wcet(m,PER_WCET);
hard_task_def_ctrl_jet(m);
 
x = ASTER_MEAN_PERIOD;
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 200);
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (x+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
if (p == -1)
{
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1;
printf_xy(62,3,WHITE,"adapt=%3u err=%d",
iq_query_first(&freedesc),errno);
}
else {
num_aster++;
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno);
task_activate(p);
x /= 2;
if (x<50) x = 50;
}
}
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster);
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(1));
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(1));
task_endcycle();
}
}
 
 
 
/* we consider the first ASTER_MAX + 2 tasks from the PID 2
and plot on the screen the elapsed times... */
TASK jetcontrol()
{
int i; /* a counter */
TIME sum, max, curr, last[5];
int nact;
int j; /* the elements set by jet_gettable */
PID p;
 
 
kern_cli();
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5");
kern_sti();
 
for (;;) {
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) {
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue;
 
for (j=0; j<5; j++) last[j] = 0;
jet_gettable(p, &last[0], 5);
kern_cli();
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6d ³ %-6d ³ %-4d ³ %-7d ³ %-5d ³ %-5d ³ %-5d ³ %-5d ³ %-5d",
p, (int)sum/(nact==0 ? 1 : nact), (int)max, nact, (int)curr, (int)last[0], (int)last[1], (int)last[2], (int)last[3], (int)last[4]);
kern_sti();
i++;
}
}
}
 
int main(int argc, char **argv)
{
PID p1,p2,p3; //,p4,p5,p6;
HARD_TASK_MODEL m;
NRT_TASK_MODEL m_nrt;
struct timespec t;
 
clear();
 
hard_task_default_model(m);
hard_task_def_wcet(m,ASTER_WCET);
hard_task_def_mit(m,10000);
hard_task_def_group(m,1);
hard_task_def_ctrl_jet(m);
 
nrt_task_default_model(m_nrt);
nrt_task_def_group(m_nrt,1);
nrt_task_def_ctrl_jet(m_nrt);
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <aster> ...");
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) {
sys_shutdown_message("test7.c(main): Could not create task <Clock> ...");
exit(1);
}
 
p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL);
if (p2 == -1) {
sys_shutdown_message("test7.c(main): Could not create task <JetControl> ...");
exit(1);
}
 
group_activate(1);
 
do {
sys_gettime(&t);
} while (t.tv_sec < END_TEST_TIME);
 
exit(0);
 
return 0;
}
 
 
 
 
/demos/tags/rel_1_5_4/base/mdemo.c
0,0 → 1,189
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: mdemo.c,v 1.4 2005-02-25 11:10:46 pj Exp $
 
This test verify the correctness of the NOP module. It works with the
PI, PC, SRP module, too.
 
The test uses one mutex
 
the main task (NRT) creates three tasks.
 
J1 with PC priority 0
starts at t=0.5 sec and lock m0
 
J2 with PC priority 1
starts at t=1 sec and doesn't lock any mutex
 
J3 with PC priority 2
it starts and locks m0
at t=2 sec it unlocks m1
 
 
The example is similar to the scheduling diagram shown at p. 188 of the
book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
 
*/
 
#include "kernel/kern.h"
#include "srp/srp/srp.h"
 
mutex_t m0;
 
 
void startJ(void *a)
{
task_activate((PID)a);
}
 
TASK j1()
{
cprintf("J1: before locking m0\n");
mutex_lock(&m0);
cprintf("J1: locked m0\n");
mutex_unlock(&m0);
cprintf("J1: unlocked m0, end task\n");
return 0;
}
 
 
TASK j2()
{
cprintf("J2: waiting t=1.5 sec\n");
 
while (sys_gettime(NULL) < 1500000);
 
cprintf("J2: end task\n");
return 0;
}
 
 
TASK j3()
{
cprintf("J3: before locking m0\n");
mutex_lock(&m0);
cprintf("J3: locked m0, waiting to t=2 sec\n");
 
while (sys_gettime(NULL) < 2000000);
 
cprintf("J3: t = 1 sec reached, unlocking m0\n");
mutex_unlock(&m0);
cprintf("J3: unlocked m0, end task\n");
return 0;
}
 
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;
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PC_mutexattr_default(a,0);
PI_mutexattr_default(a2);
NOP_mutexattr_default(a3);
SRP_mutexattr_default(a4);
NPP_mutexattr_default(a5);
mutex_init(&m0,&a4);
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
hard_task_default_model(m);
hard_task_def_wcet(m,20000);
hard_task_def_mit(m,10000000);
PC_res_default_model(r,0);
SRP_res_default_model(srp,3);
p0 = task_createn("J1", j1, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
if (p0 == NIL)
{ cprintf("Can't create J1 task...\n"); return 1; }
 
hard_task_def_wcet(m,1600000);
hard_task_def_mit(m,21000000);
PC_res_default_model(r,1);
SRP_res_default_model(srp,2);
p1 = task_createn("J2", j2, (TASK_MODEL *)&m, &r, &srp, NULL);
if (p1 == NIL)
{ cprintf("Can't create J2 task...\n"); return 1; }
 
hard_task_def_wcet(m,3000000);
hard_task_def_mit(m,100000000);
PC_res_default_model(r,2);
SRP_res_default_model(srp,1);
p2 = task_createn("J3", j3, (TASK_MODEL *)&m, &r, &srp, SRP_usemutex(&m0), NULL);
if (p2 == NIL)
{ cprintf("Can't create J3 task...\n"); return 1; }
 
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
 
kern_cli();
kern_event_post(&t,startJ,(void *)p0);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p1);
kern_sti();
 
task_activate(p2);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 60);
exit(0);
 
return 0;
}
/demos/tags/rel_1_5_4/base/isemdemo.c
0,0 → 1,98
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: isemdemo.c,v 1.2 2005-02-25 11:10:46 pj Exp $
 
File: $File$
Revision: $Revision: 1.2 $
Last update: $Date: 2005-02-25 11:10:46 $
------------
 
The simplest initialization file
 
The tick is set to TICK ms.
 
This file contains the 2 functions needed to initialize the system.
 
These functions register the following levels:
 
a RR (Round Robin) level
a Dummy level
 
It can accept these task models:
 
NRT_TASK_MODEL at level 0
 
**/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
 
 
#include "kernel/kern.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
#include "sem/sem/sem.h"
 
 
/*+ sysyem tick in us +*/
#define TICK 300
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_1_5_4/base/cabs.c
0,0 → 1,290
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: cabs.c,v 1.9 2005-02-25 11:10:46 pj Exp $
*/
 
/*--------------------------------------------------------------*/
/* TEST ON CABS */
/*--------------------------------------------------------------*/
 
#include <kernel/kern.h>
#include <cabs/cabs/cabs.h>
#include <string.h>
 
#include <drivers/shark_fb26.h>
#include <drivers/shark_keyb26.h>
 
#define NCAB 4 /* max number of CABs */
#define NCAR 26 /* generated characters */
 
#define YP 32 /* level of arrows */
#define R 20 /* task radius */
#define YY (YP+R+32) /* level of writing */
#define DELTA (2*R+72) /* total channel hight */
#define X1 120 /* start column for P1 */
#define X2 360 /* start column for P2 */
 
#define XP1 (X1+64) /* X position of task 1 */
#define XP2 (X2+64) /* X position of task 2 */
#define XC (XP1+96) /* X position of CAB */
#define L 52 /* CAB rectangle length */
 
void my_exit(KEY_EVT *k);
void draw_channel(int i);
void create_channel(int i);
void get_data();
 
TASK producer(void *arg);
TASK consumer(void *arg);
 
char *cname[NCAB] = {"cab1", "cab2", "cab3", "cab4"};
char *pname1[NCAB] = {"wr1", "wr2", "wr3", "wr4"};
char *pname2[NCAB] = {"rd1", "rd2", "rd3", "rd4"};
 
CAB cid[NCAB]; /* CAB identifiers */
PID p1[NCAB], p2[NCAB]; /* task identifiers */
 
/* Task Periods */
TIME t1[NCAB] = {200000, 100000, 300000, 800000};
TIME t2[NCAB] = {400000, 400000, 150000, 200000};
 
/* Task WCETS */
TIME w1[NCAB] = {10000, 10000, 10000, 10000};
TIME w2[NCAB] = {10000, 10000, 10000, 10000};
 
/****************************************************************/
 
/* This function is called when Alt-X is pressed.
*/
void my_end(KEY_EVT* e)
{
exit(0);
}
 
/******************************************************************/
 
/* This function is called when the system exit correctly after Alt-X.
It exits from the graphic mode and then it prints a small greeting.
Note that:
- The function calls grx_exit, so it must be registered using
RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because
at that point the kernel is already returned in real mode!!!)
- When an exception is raised, the exception handler is called.
Since the exception handler already exits from the graphic mode,
this funcion has not to be called. For this reason:
. we registered byebye using the flag NO_AT_ABORT
. the exception handler exits using exit; in that way byebye is
NOT called
*/
 
/*--------------------------------------------------------------*/
/* Main task */
/*--------------------------------------------------------------*/
 
/****************************** MAIN ******************************/
 
int main(int argc, char **argv)
{
char c = 0; /* character from keyboard */
 
grx_clear(BLACK);
 
grx_text("Press a key [1-4]", 10, 16, rgb16(255,255,255), 0);
grx_text("to create a pair", 10, 24, rgb16(255,255,255), 0);
grx_text("ESC to exit demo", 10, 48, rgb16(255,255,255), 0);
 
while (c != 27) {
c = keyb_getch(BLOCK);
if ((c >= '1') && (c <= '1'+NCAB-1))
create_channel(c-'1');
}
exit(0);
 
return 0;
}
 
 
/*--------------------------------------------------------------*/
/* write data in a cab */
/*--------------------------------------------------------------*/
 
TASK producer(void *arg)
{
int i = (int)arg;
char c; /* message character */
char *p; /* pointer to a cab buffer */
char s[2]; /* string to display */
int k = 0;
int x, y;
int col = rgb16(0,0,255);
int ybase = YY + i*DELTA;
 
x = X1;
y = ybase;
s[1] = 0;
 
k = 0;
while (1) {
c = 'A' + k;
p = cab_reserve(cid[i]);
*p = c;
cab_putmes(cid[i], p);
 
s[0] = c;
k = (k + 1) % NCAR;
grx_text(s,x,y,col,0);
 
x += 8;
if (x >= (X1 + NCAR*8)) {
x = X1;
y = y + 8;
if (y >= ybase+16) {
y = ybase;
}
}
 
task_endcycle();
}
}
 
/*--------------------------------------------------------------*/
/* read data from a cab */
/*--------------------------------------------------------------*/
 
TASK consumer(void *arg)
{
int i = (int)arg;
char *p;
char s[2];
int x, y;
int col = 13;
int ybase = YY + i*DELTA;
 
x = X2;
y = ybase;
s[1] = 0;
 
while (1) {
p = cab_getmes(cid[i]);
s[0] = *p - 'A' + 'a';
cab_unget(cid[i], p);
 
grx_text(s,x,y,col,0);
x += 8;
 
if (x >= (X2 + NCAR*8)) {
x = X2;
y = y + 8;
if (y >= ybase+16) {
y = ybase;
col = col % 15 + 1;
}
}
task_endcycle();
}
}
 
/*--------------------------------------------------------------*/
/* create the two tasks and a channel */
/*--------------------------------------------------------------*/
 
void create_channel(int i)
{
HARD_TASK_MODEL m;
 
draw_channel(i);
cid[i] = cab_create(cname[i], 1, 2);
 
hard_task_default_model(m);
hard_task_def_ctrl_jet (m);
hard_task_def_arg (m, (void *)i);
hard_task_def_wcet (m, w1[i]);
hard_task_def_mit (m, t1[i]);
hard_task_def_usemath (m);
p1[i] = task_create(pname1[i], producer, &m, NULL);
if (p1[i] == NIL) {
sys_shutdown_message("Could not create task <producer>");
exit(1);
return;
}
task_activate(p1[i]);
 
hard_task_default_model(m);
hard_task_def_ctrl_jet (m);
hard_task_def_arg (m, (void *)i);
hard_task_def_wcet (m, w2[i]);
hard_task_def_mit (m, t2[i]);
hard_task_def_usemath (m);
p2[i] = task_create(pname2[i], consumer, &m, NULL);
if (p2[i] == NIL) {
sys_shutdown_message("Could not create task <consumer>");
exit(1);
return;
}
task_activate(p2[i]);
}
 
/*--------------------------------------------------------------*/
/* Disegna i processi e il canale di comunicazione */
/*--------------------------------------------------------------*/
 
void draw_channel(int i)
{
char buffer[32]; /* buffer per sprintf */
int yc = YP + i*DELTA; /* altezza del canale */
 
grx_circle(XP1,yc,R,rgb16(255,0,0));
grx_text("P1",XP1-8,yc-4,rgb16(255,255,255),0);
 
grx_circle(XP2,yc,R,rgb16(255,0,0));
grx_text("P2",XP2-8,yc-4,rgb16(255,255,255),0);
 
grx_rect(XC,yc-R,XC+L,yc+R,rgb16(255,255,255));
grx_text("CAB",XC+16,yc-4,rgb16(255,255,255),0);
 
grx_line(XP1+R,yc,XC,yc,rgb16(255,255,255));
grx_line(XC+L,yc,XP2-R,yc,rgb16(255,255,255));
 
grx_text("T1 = ms",X1+40,yc+R+16,rgb16(255,255,255),0);
sprintf(buffer,"%ld", t1[i]);
grx_text(buffer,X1+88,yc+R+16,rgb16(255,255,255),0);
 
grx_text("T2 = ms",X2+40,yc+R+16,rgb16(255,255,255),0);
sprintf(buffer,"%ld", t2[i]);
grx_text(buffer,X2+88,yc+R+16,rgb16(255,255,255),0);
}
/demos/tags/rel_1_5_4/base/ihello.c
0,0 → 1,95
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: ihello.c,v 1.2 2005-02-25 11:10:46 pj Exp $
 
File: $File$
Revision: $Revision: 1.2 $
Last update: $Date: 2005-02-25 11:10:46 $
------------
 
The simplest initialization file
 
The tick is set to TICK ms.
 
This file contains the 2 functions needed to initialize the system.
 
These functions register the following levels:
 
a RR (Round Robin) level
a Dummy level
 
It can accept these task models:
 
NRT_TASK_MODEL at level 0
 
**/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
 
 
#include "kernel/kern.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
 
 
/*+ sysyem tick in us +*/
#define TICK 300
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_1_5_4/base/fly.c
0,0 → 1,202
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: fly.c,v 1.11 2005-02-25 11:10:46 pj Exp $
 
File: $File$
Revision: $Revision: 1.11 $
Last update: $Date: 2005-02-25 11:10:46 $
------------
**/
 
/*
* Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
/*--------------------------------------------------------------*/
/* SIMULATION OF RANDOM FLIES */
/*--------------------------------------------------------------*/
 
#include <kernel/kern.h>
#include <sem/sem/sem.h>
#include <stdlib.h>
#include <math.h>
 
#include <drivers/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#define YMENU 10 /* menu level */
#define XMIN 50
#define XMAX 600
#define YMIN 100
#define YMAX 450
#define VEL 5 /* linear velocity (def. = 5) */
#define ANG 30 /* angolo massimo sterzata (30) */
#define D 3 /* raggio mosca */
#undef ESC
#define ESC 27 /* ASCII code of ESCAPE key */
#define MAX_P 35 /* max number of flies */
#define FLYGROUP 1
 
double tick = 1.0; /* system tick = 1 ms */
int fly_period = 40000; /* task period */
int fly_wcet = 1000; /* task wcet */
PID pid;
 
sem_t grx_mutex;
 
/*--------------------------------------------------------------*/
 
void draw_fly(int x, int y, int c)
{
grx_disc(x, y, D, c);
}
 
/******************************************************************/
 
TASK fly(void *arg)
{
int x, y;
int ox, oy;
int dx, dy, da;
int teta, col,red;
int outx, outy;
double r;
int i = (int)arg;
 
x = ox = (XMIN+XMAX)/2;
y = oy = (YMIN+YMAX)/2;
teta = 0;
red = 100+10*i;
if (red > 255) red = 255;
col = rgb16(red,0,50); /* colore fly */
 
while (1) {
 
da = rand()%(2*ANG) - ANG; /* da = [-ANG,ANG] */
teta += da;
 
if (teta > 360) teta -= 360;
if (teta < 0) teta += 360;
r = (double)teta * PI / 180.;
 
dx = (float)(VEL * cos(r));
dy = (float)(VEL * sin(r));
x += dx;
y += dy;
 
outx = (x >= XMAX) || (x <= XMIN);
outy = (y >= YMAX) || (y <= YMIN);
 
if (outx || outy) {
x = x - dx;
y = y - dy;
if (outx) teta = 180 - teta;
if (outy) teta = -teta;
if (teta > 360) teta -= 360;
if (teta < 0) teta += 360;
r = (double)teta * PI / 180.;
 
dx = (float)(VEL * cos(r));
dy = (float)(VEL * sin(r));
 
x += dx;
y += dy;
}
 
sem_wait(&grx_mutex);
draw_fly(ox, oy, 0);
draw_fly(x, y, col);
ox = x; oy = y;
sem_post(&grx_mutex);
 
task_endcycle();
}
}
 
/****************************** MAIN ******************************/
 
int main(int argc, char **argv)
{
HARD_TASK_MODEL m;
 
char c; /* character from keyboard */
int i = 0; /* number of tasks created */
TIME seme; /* used to init the random seed */
 
/* Init the mutex */
sem_init(&grx_mutex,0,1);
 
/* The scenario */
grx_rect(XMIN-D-1, YMIN-D-1, XMAX+D+1, YMAX+D+1, rgb16(255,255,255));
grx_text("Simulation of Random Flies", XMIN, YMENU+10, rgb16(255,255,255), 0);
grx_text("SPACE create a fly" , XMIN, YMENU+20, rgb16(255,255,255), 0);
grx_text("ESC exit to DOS" , XMIN, YMENU+30, rgb16(255,255,255), 0);
 
/* The program waits a space to create a fly */
c = keyb_getch(BLOCK);
 
/* randomize!!!! */
seme = sys_gettime(NULL);
srand(seme);
 
do {
if ((c == ' ') && (i < MAX_P)) {
hard_task_default_model(m);
hard_task_def_ctrl_jet (m);
hard_task_def_arg (m, (void *)i);
hard_task_def_wcet (m, fly_wcet);
hard_task_def_mit (m, fly_period);
hard_task_def_group (m, FLYGROUP);
hard_task_def_usemath (m);
pid = task_create("fly", fly, &m, NULL);
if (pid == NIL) {
sys_shutdown_message("Could not create task <fly>");
exit(1);
}
task_activate(pid);
i++;
}
c = keyb_getch(BLOCK);
 
} while (c != ESC);
 
exit(0);
 
return 0;
 
}
 
/*--------------------------------------------------------------*/
/demos/tags/rel_1_5_4/base/iaster1.c
0,0 → 1,99
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: iaster1.c,v 1.3 2005-02-25 11:10:46 pj Exp $
 
File: $File$
Revision: $Revision: 1.3 $
Last update: $Date: 2005-02-25 11:10:46 $
------------
 
System initialization file
 
The tick is set to TICK ms.
 
This file contains the 2 functions needed to initialize the system.
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a RR (Round Robin) level
a Dummy level
 
It can accept these task models (into () the mandatory fields):
 
HARD_TASK_MODEL (wcet+mit) at level 0
NRT_TASK_MODEL at level 1
 
**/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
 
 
#include "kernel/kern.h"
#include "edf/edf/edf.h"
#include "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
 
 
/*+ sysyem tick in us +*/
#define TICK 1000
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_1_5_4/base/srpdemo.c
0,0 → 1,234
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: srpdemo.c,v 1.5 2005-02-25 11:10:46 pj Exp $
 
This test verify the correctness of the SRP module.
 
There are 3 taks, Jh, Jm, Jl that uses 3 mutexes m1, m2, m3
 
the main task (NRT) creates the three tasks.
 
Jh with preemption level 3
starts at t=1.5 sec and lock m3, lock m1, unlock m1, unlock m3
 
Jm with preemption level 2
starts at t=0.5 sec and lock m3, lock m2, unlock m2, unlock m3
then lock and unlock m1
 
Jl with preemption level 1
it starts and locks m2
at t=1 sec it locks m1
at t=1.5 sec it unlocks m1
then it unlocks m2, and finally it locks and unlocks m3
 
 
The example is similar to the scheduling diagram shown at p. 210 of the
book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
 
*/
 
#include "kernel/kern.h"
 
#include "srp/srp/srp.h"
 
mutex_t m1,m2,m3;
 
void startJ(void *a)
{
task_activate((PID)a);
}
 
TASK Jlobby()
{
cprintf("(*) JLobby!!!\n");
return 0;
}
 
TASK Jh()
{
PID l;
HARD_TASK_MODEL m;
SRP_RES_MODEL r;
 
cprintf("JH: creating Jy before locking m3\n");
 
hard_task_default_model(m);
hard_task_def_mit(m,30000);
hard_task_def_wcet(m,1000);
SRP_res_default_model(r,4);
l = task_create("Jlobby",Jlobby,&m,&r);
task_activate(l);
 
mutex_lock(&m3);
cprintf("JH: locked m3, locking m1\n");
mutex_lock(&m1);
cprintf("JH: locked m1, unlocking m1\n");
mutex_unlock(&m1);
cprintf("JH: unlocked m1, unlocking m3\n");
mutex_unlock(&m3);
cprintf("JH: unlocked m3, end task\n");
return 0;
}
 
 
TASK Jm()
{
cprintf("JM: before locking m3\n");
mutex_lock(&m3);
cprintf("JM: locked m3, locking m2\n");
mutex_lock(&m2);
cprintf("JM: locked m2, unlocking m2\n");
mutex_unlock(&m2);
cprintf("JM: unlocked m2, unlocking m3\n");
mutex_unlock(&m3);
cprintf("JM: unlocked m3, locking m1\n");
mutex_lock(&m1);
cprintf("JM: locked m1, unlocking m1\n");
mutex_unlock(&m1);
cprintf("JM: unlocked m1, end task\n");
return 0;
}
 
 
TASK Jl()
{
cprintf("JL: before locking m2\n");
mutex_lock(&m2);
cprintf("JL: locked m2, waiting to t=1 sec\n");
 
while (sys_gettime(NULL) < 1000000);
 
cprintf("JL: t = 1 sec reached, locking m1\n");
mutex_lock(&m1);
cprintf("JL: locked m1, waiting to t=2 sec\n");
 
while (sys_gettime(NULL) < 2000000);
 
cprintf("JL: t = 2 sec reached, unlocking m1\n");
mutex_unlock(&m1);
cprintf("JL: unlocked m1, unlocking m2\n");
 
mutex_unlock(&m2);
 
cprintf("JL: unlocked m2, locking m3\n");
mutex_lock(&m3);
cprintf("JL: locked m3, unlocking m3\n");
mutex_unlock(&m3);
cprintf("JL: unlocked m3, end task\n");
return 0;
}
 
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;
 
clear();
cprintf("Stack resource Policy demo. It ends after 60 sec\n");
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a2);
SRP_mutexattr_default(a);
mutex_init(&m1,&a);
mutex_init(&m2,&a);
mutex_init(&m3,&a);
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
hard_task_default_model(m);
hard_task_def_mit(m, 1000000);
hard_task_def_wcet(m, 80000);
SRP_res_default_model(r, 3);
p0 = task_createn("JH", Jh, (TASK_MODEL *)&m, &r, SRP_usemutex(&m3), SRP_usemutex(&m1), NULL);
if (p0 == NIL)
{ cprintf("Can't create JH task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 2100000);
hard_task_def_wcet(m, 80000);
SRP_res_default_model(r, 2);
p1 = task_createn("JM", Jm, (TASK_MODEL *)&m, &r, SRP_usemutex(&m3), SRP_usemutex(&m1),
SRP_usemutex(&m2), NULL);
if (p1 == NIL)
{ cprintf("Can't create JM task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 10000000);
hard_task_def_wcet(m, 3000000);
SRP_res_default_model(r, 1);
p2 = task_createn("JL", Jl, (TASK_MODEL *)&m, &r, SRP_usemutex(&m3), SRP_usemutex(&m1),
SRP_usemutex(&m2), NULL);
if (p2 == NIL)
{ cprintf("Can't create JL task...\n"); return 1; }
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
 
kern_cli();
kern_event_post(&t,startJ,(void *)p1);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p0);
kern_sti();
 
task_activate(p2);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 60);
exit(0);
 
return 0;
}
/demos/tags/rel_1_5_4/base/iaster3.c
0,0 → 1,110
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: iaster3.c,v 1.3 2005-02-25 11:10:46 pj Exp $
 
File: $File$
Revision: $Revision: 1.3 $
Last update: $Date: 2005-02-25 11:10:46 $
------------
 
System initialization file
 
The tick is set to TICK ms.
 
This file contains the 2 functions needed to initialize the system.
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a RR (Round Robin) level
a TBS (Total Bandwidth Server) level 0.1 Us
a TBS (Total Bandwidth Server) level 0.3 Us
a Dummy level
 
The TBS bandwidth is TBS_NUM/TBS_DEN
 
 
It can accept these task models (into () the mandatory fields):
 
HARD_TASK_MODEL (wcet+mit) at level 0
NRT_TASK_MODEL at level 1
SOFT_TASK_MODEL (wcet, periodicity=APERIODIC) at level 2,3
 
**/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
 
 
#include "kernel/kern.h"
#include "edf/edf/edf.h"
#include "rr/rr/rr.h"
#include "tbs/tbs/tbs.h"
#include "dummy/dummy/dummy.h"
 
 
/*+ sysyem tick in us +*/
#define TICK 1200
 
#define RRTICK 5000
#define TBS_NUM 1
#define TBS_DEN 10
 
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
TBS_register_level(TBS_ENABLE_ALL, 0, TBS_NUM, TBS_DEN);
TBS_register_level(TBS_ENABLE_ALL, 0, TBS_NUM*3, TBS_DEN);
dummy_register_level();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_1_5_4/base/aster.c
0,0 → 1,378
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai, Gerardo Lamastra and Giuseppe Lipari
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: aster.c,v 1.6 2005-02-25 11:10:46 pj Exp $
 
Author: Gerardo Lamastra
Giuseppe Lipari
Date: 1/10/96
 
File: Aster.C
Revision: 1.6
 
*/
 
/*
Well, this is only a stupid demo which intend to show many
HARTIK+ capabilities; the application is structured in the followig
way: there is an ASTER task wich randomly creates some ASTEROID tasks
which are displayed into the first window; each task is HARD/PERIODIC
and auto-kills itself when it reaches the window end!
An other couple of tasks, TITLE & PUT give an example of port
communication facility; the server task creates the port, the client
task connect to it and uses the server to accomplish some stuff.
Port can be declared READ/WRITE and can model ONE-TO-ONE communication
or MANY-TO-ONE communication.
Finally a second couple of tasks realizes a communiation through CABs;
each time a key is pressed, the ascii code is posted into the CAB by the
CCC task while the second task, WRITE, displays it on the screen and
perform other silly actions.
Finally a CLOCK task is implemented to test system clock.
Please note that usually the HARTIK+ application is made up of a task
group which interacts among them, while the main() function, which
became a task itself when the kernel is activated, is suspended until
the system is ready to terminate; the MAIN task can also be used to make
other background activities, but it should not be killed; when the
application terminates, the control is passed to MAIN which kills
everybody, shut down the system and can handle other operations using
the services available with the previou operating system (I.E. the DOS).
If you need to manage sudden abort/exception you should install your own
exception handler and raise it through the exc_raise() primitive to
make the system abort safely!
Remember that the exit functions posted through sys_atexit() will be
executed in both cases, to allow clean system shutdown.
*/
 
#include <kernel/kern.h>
#include <sem/sem/sem.h>
#include <hartport/hartport/hartport.h>
#include <cabs/cabs/cabs.h>
#include <string.h>
 
#include <drivers/shark_keyb26.h>
 
//#define __VPAGING__
 
#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 "..................... S.Ha.R.K. ....................."\
" 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 "\
" "\
"Programmers : Gerardo Lamastra (lamastra@sssup2.sssup.it) "\
" Giuseppe Lipari (lipari@sssup2.sssup.it) "\
"Research coordinator: Giorgio Buttazzo (giorgio@sssup1.sssup.it)"\
" "\
" "\
" "
 
static char GreetMsg[1600];
 
TASK put(void)
{
PORT p;
 
strcpy(GreetMsg,STR);
p = port_create("title",strlen(GreetMsg),1,STREAM,WRITE);
while(1) {
port_send(p,GreetMsg,BLOCK);
task_endcycle();
}
}
 
TASK ccc(void)
{
WIN w;
char *m;
 
win_init(&w,68,3,10,3);
win_frame(&w,BLACK,WHITE,"CCC",2);
puts_xy(70,4,WHITE,"Cab");
 
while(1) {
m = cab_getmes(cc);
puts_xy(72,5,WHITE,m);
cab_unget(cc,m);
task_endcycle();
}
}
TASK write_keyb()
{
BYTE c;
char *msg;
 
while (1) {
c = keyb_getchar();
if (c == ESC) {
esc = TRUE;
task_endcycle();
}
else {
#ifdef __VPAGING__
if (c == 's') {
if (get_visual_page() == 0) set_visual_page(1);
else if (get_visual_page() == 1) set_visual_page(0);
}
#endif
msg = cab_reserve(cc);
msg[0] = c;
msg[1] = 0;
cab_putmes(cc,msg);
}
}
}
 
#define DELTA 200000.0
double carico(double rif,BYTE init)
{
double i;
DWORD t1 = 0,t2 = 1000;
double u;
 
i = 0.0;
do {
i += 1;
} while (i <= DELTA);
 
u = i / ((double) (t2 - t1));
 
if (init) return u;
else return (1.0 - u/rif);
}
 
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;
 
struct timespec t;
#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>");
exit(-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) {
sys_shutdown_message("Aster.C(main): Could not create task <Clock>");
exit(1);
}
 
soft_task_def_period(m_soft, 50000);
p3 = task_create("Title",title,&m_soft, NULL);
if (p3 == -1) {
sys_shutdown_message("Aster.C(main): Could not create task <Title>");
exit(1);
}
 
soft_task_def_period(m_soft, 1000000);
p4 = task_create("Put",put,&m_soft, NULL);
if (p4 == -1) {
sys_shutdown_message("Aster.C(main): Could not create task <Put>");
exit(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) {
sys_shutdown_message("Aster.C(main): Could not create task <Write>");
exit(1);
}
 
hard_task_def_mit(m_per, 50000);
p6 = task_create("CabTask",ccc,&m_per,NULL);
if (p6 == -1) {
sys_shutdown_message("Aster.C(main): Could not create task <CabTask>\n");
exit(1);
}
 
group_activate(1);
 
while (!esc) {
sys_gettime(&t);
printf_xy(0,21,WHITE,"Clock : %-9ds %-9dns",(int)t.tv_sec, (int)t.tv_nsec);
}
 
group_kill(1);
clear();
CRSR_STD();
#ifdef __VPAGING__
set_active_page(0);
set_visual_page(0);
#endif
 
exit(0);
 
return 0;
 
}
 
/demos/tags/rel_1_5_4/base/makefile
0,0 → 1,92
#
#
#
 
ifndef BASE
BASE=../..
endif
include $(BASE)/config/config.mk
 
PROGS = sig time preempt
PROGS += aster aster1 aster2 aster3 aster4 aster5 aster6 aster7 aster8
PROGS += pcidemo
PROGS += jointest condtest intsem semdemo pidemo pcdemo srpdemo mdemo
PROGS += ego fly cabs
 
include $(BASE)/config/example.mk
 
# Text applications
time:
make -f $(SUBMAKE) APP=time INIT= OTHEROBJS="ihello.o" OTHERINCL= SHARKOPT=
 
sig:
make -f $(SUBMAKE) APP=sig INIT= OTHEROBJS="ihello.o" OTHERINCL= SHARKOPT=
 
preempt:
make -f $(SUBMAKE) APP=preempt INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __INPUT__"
 
semdemo:
make -f $(SUBMAKE) APP=semdemo INIT= OTHEROBJS="isemdemo.o" OTHERINCL= SHARKOPT=
 
pidemo:
make -f $(SUBMAKE) APP=pidemo INIT= OTHEROBJS="imdemo.o" OTHERINCL= SHARKOPT=
 
pcdemo:
make -f $(SUBMAKE) APP=pcdemo INIT= OTHEROBJS="imdemo.o" OTHERINCL= SHARKOPT=
 
srpdemo:
make -f $(SUBMAKE) APP=srpdemo INIT= OTHEROBJS="imdemo.o" OTHERINCL= SHARKOPT=
 
mdemo:
make -f $(SUBMAKE) APP=mdemo INIT= OTHEROBJS="imdemo.o" OTHERINCL= SHARKOPT=
 
aster:
make -f $(SUBMAKE) APP=aster INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __INPUT__"
 
aster1:
make -f $(SUBMAKE) APP=aster1 INIT= OTHEROBJS="iaster1.o" OTHERINCL= SHARKOPT=
 
aster2:
make -f $(SUBMAKE) APP=aster2 INIT= OTHEROBJS="iaster1.o" OTHERINCL= SHARKOPT=
 
aster3:
make -f $(SUBMAKE) APP=aster3 INIT= OTHEROBJS="iaster3.o" OTHERINCL= SHARKOPT=
 
aster4:
make -f $(SUBMAKE) APP=aster4 INIT= OTHEROBJS="iaster4.o" OTHERINCL= SHARKOPT="__LINUXC26__ __INPUT__"
 
aster5:
make -f $(SUBMAKE) APP=aster5 INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __INPUT__"
 
aster6:
make -f $(SUBMAKE) APP=aster6 INIT= OTHEROBJS="iaster6.o" OTHERINCL= SHARKOPT="__LINUXC26__ __INPUT__"
 
aster7:
make -f $(SUBMAKE) APP=aster7 INIT= OTHEROBJS="iaster7.o" OTHERINCL= SHARKOPT="__LINUXC26__ __INPUT__"
 
aster8:
make -f $(SUBMAKE) APP=aster8 INIT= OTHEROBJS="iaster8.o" OTHERINCL= SHARKOPT="__LINUXC26__ __INPUT__"
 
pcidemo:
make -f $(SUBMAKE) APP=pcidemo INIT= OTHEROBJS="ipcidemo.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__"
 
jointest:
make -f $(SUBMAKE) APP=jointest INIT= OTHEROBJS="imdemo.o" OTHERINCL= SHARKOPT=
 
condtest:
make -f $(SUBMAKE) APP=condtest INIT= OTHEROBJS="imdemo.o" OTHERINCL= SHARKOPT=
 
intsem:
make -f $(SUBMAKE) APP=intsem INIT= OTHEROBJS="imdemo.o" OTHERINCL= SHARKOPT=
 
# Graphical applications
 
ego:
make -f $(SUBMAKE) APP=ego INIT= OTHEROBJS="initgraph.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__"
 
fly:
make -f $(SUBMAKE) APP=fly INIT= OTHEROBJS="initgraph.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__"
 
cabs:
make -f $(SUBMAKE) APP=cabs INIT= OTHEROBJS="initgraph.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__"
 
/demos/tags/rel_1_5_4/base/jointest.c
0,0 → 1,214
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: jointest.c,v 1.3 2005-01-08 14:31:38 pj Exp $
 
This test verify the correctness of the task_join primitive. (that
function is the same as pthread_join... someday I will change the
names...)
 
There are 4 taks, J1, J2, J3, are created as joinable, J4 as detached
 
The main task:
Creates J1 and J2, locks m1 (a PI mitex), creates C3.
at t=0.8 sec it calls a task_join on J3 (that returns EDEADLK),
it unlocks m1, then it makes task_join on J3 another time.
Next it creates J4 as detached and finally it does a task_join on J4
(that returns EINVAL).
 
J1:
at t=0.2 sec it calls task_join on J2, the it ends.
 
J2:
it simply waits t=0.4 sec and it ends.
 
J3:
First, it calls task_join on J1.
Then, at t=0.6 sec it locks m1, then unlocks it
 
J4:
it simply waits t=1 sec and it ends.
 
*/
 
#include "kernel/kern.h"
 
PID j0, j1, j2, j3, j4;
mutex_t m1;
 
TASK J1()
{
int err;
void *ret;
 
cprintf("J1: started, waiting 0.2 sec\n");
 
while (sys_gettime(NULL) < 200000);
 
cprintf("J1: 0.2 sec reached, joining J2\n");
 
err = task_join(j2, &ret);
 
cprintf("J1: join J2 returns %d error %d, exiting\n",
(int)ret,err);
return (void *)11;
}
 
TASK J2()
{
cprintf("J2: started, waiting 0.4 sec\n");
 
while (sys_gettime(NULL) < 400000);
 
cprintf("J2: 0.4 sec reached, exiting\n");
 
return (void *)22;
}
 
TASK J3()
{
int err;
void *ret;
 
cprintf("J3: started, joining J1\n");
 
err = task_join(j1, &ret);
 
cprintf("J3: join J1 returns %d error %d, waiting 0.6sec\n", (int)ret, err);
 
while (sys_gettime(NULL) < 600000);
 
cprintf("J1: 0.6 sec reached, locking m1\n");
 
mutex_lock(&m1);
 
cprintf("J3: locked m1, unlocking m1\n");
 
mutex_unlock(&m1);
 
cprintf("J3: unlocked m1, exiting\n");
 
return (void *)33;
}
 
TASK J4()
{
cprintf("J4: started, waiting 1 sec\n");
 
while (sys_gettime(NULL) < 1000000);
 
cprintf("J4: 1 sec reached, exiting\n");
 
return (void *)44;
}
 
int main(int argc, char **argv)
{
NRT_TASK_MODEL m;
 
PI_mutexattr_t a;
 
int err;
void *ret;
 
struct timespec t;
 
j0 = exec_shadow;
nrt_task_default_model(m);
nrt_task_def_joinable(m);
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a);
mutex_init(&m1,&a);
 
 
/* ---------------------------------------------------------------------
Let's go !!!!
--------------------------------------------------------------------- */
 
cprintf("main: creating J1,J2,J3, locking m1\n");
 
j1 = task_create("J1", J1, &m, NULL);
if (j1 == NIL) { cprintf("Can't create J1 task...\n"); return 1; }
task_activate(j1);
 
j2 = task_create("J2", J2, &m, NULL);
if (j2 == NIL) { cprintf("Can't create J2 task...\n"); return 1; }
task_activate(j2);
 
mutex_lock(&m1);
 
j3 = task_create("J3", J3, &m, NULL);
if (j3 == NIL) { cprintf("Can't create J3 task...\n"); return 1; }
task_activate(j3);
 
cprintf("main: waiting t=0.8 sec\n");
 
while (sys_gettime(NULL) < 800000);
 
err = task_join(j3, NULL);
 
cprintf("main: join J3 error %d, unlocking m1\n",err);
 
mutex_unlock(&m1);
 
err = task_join(j3, &ret);
 
cprintf("main: join J3 returns %d error %d, unlocked m1, creating J4\n",
(int)ret,err);
 
nrt_task_def_unjoinable(m);
j4 = task_create("J4", J4, &m, NULL);
if (j4 == NIL) { cprintf("Can't create J4 task...\n"); return 1; }
 
task_activate(j4);
 
err = task_join(j4,&ret);
 
cprintf("main: join J4 returns %d error %d, exiting\n", (int)ret, err);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 10);
exit(0);
 
return 0;
 
}
/demos/tags/rel_1_5_4/base/aster1.c
0,0 → 1,174
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: aster1.c,v 1.4 2005-01-08 14:31:38 pj Exp $
 
this is a reduced verion of the classic Hartik demo Aster.
 
It uses:
- EDF module
. periodic tasks
- an high number of task executing concurrently
 
The demo ends after 6 seconds.
 
*/
 
/*
Well, this is only a stupid demo which intend to show many
HARTIK+ capabilities; the application is structured in the followig
way: there is an ASTER task wich randomly creates some ASTEROID tasks
which are displayed into the first window; each task is HARD/PERIODIC
and auto-kills itself when it reaches the window end!
Finally a CLOCK task is implemented to test system clock.
Please note that usually the HARTIK+ application is made up of a task
group which interacts among them, while the main() function, which
became a task itself when the kernel is activated, is suspended until
the system is ready to terminate; the MAIN task can also be used to make
other background activities, but it should not be killed; when the
application terminates, the control is passed to MAIN which kills
everybody, shut down the system and can handle other operations using
the services available with the previou operating system (I.E. the DOS).
If you need to manage sudden abort/exception you should install your own
exception handler and raise it through the exc_raise() primitive to
make the system abort safely!
Remember that the exit functions posted through sys_atexit() will be
executed in both cases, to allow clean system shutdown.
*/
 
#include "kernel/kern.h"
 
int num_aster = 0;
#define ASTER_LIM 67
#define ASTER_MAX 90
 
TASK asteroide(void)
{
int i = 1;
int y = rand() % 20 + 1;
while (i < ASTER_LIM) {
puts_xy(i,y,WHITE,"*");
task_endcycle();
 
puts_xy(i,y,WHITE," ");
i++;
}
num_aster--;
return 0;
}
 
DWORD taskCreated = 0;
 
TASK aster(void)
{
PID p;
 
HARD_TASK_MODEL m;
int r;
 
hard_task_default_model(m);
hard_task_def_wcet(m,500);
 
srand(7);
while (1) {
if (num_aster < ASTER_MAX) {
r = (rand() % 50) - 25;
 
hard_task_def_arg(m,(void *)((rand() % 7)+1));
hard_task_def_mit(m, (50+r)*1000);
p = task_create("aaa",asteroide,&m,NULL);
taskCreated++;
task_activate(p);
num_aster++;
}
 
task_endcycle();
}
}
 
TASK clock()
{
int s = 0, m = 0;
 
while(1) {
printf_xy(70,1,WHITE,"%2d : %2d",m,s);
task_endcycle();
 
if (++s > 59) {
s = 0;
m++;
}
printf_xy(70,1,WHITE,"%2d : %2d",m,s);
task_endcycle();
}
}
 
int main(int argc, char **argv)
{
PID p1,p2;
HARD_TASK_MODEL m;
struct timespec t;
 
clear();
 
hard_task_default_model(m);
hard_task_def_mit(m,10000);
hard_task_def_wcet(m,2000);
hard_task_def_group(m,1);
 
p1 = task_create("Aster",aster,&m,NULL);
if (p1 == -1) {
sys_shutdown_message("Aster.C(main): Could not create task <aster> ...");
exit(1);
}
 
hard_task_def_mit(m,500000);
p2 = task_create("Clock",clock,&m,NULL);
if (p2 == -1) {
sys_shutdown_message("Aster.C(main): Could not create task <Clock> ...");
exit(1);
}
 
group_activate(1);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 10);
 
exit(0);
return 0;
}
 
/demos/tags/rel_1_5_4/base/time.c
0,0 → 1,69
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: time.c,v 1.2 2005-01-08 14:31:38 pj Exp $
*
* Timer correctness test
*/
 
#include "kernel/kern.h"
 
#define NT 10
 
int main(int argc, char **argv)
{
struct timespec t[NT];
int i;
 
cprintf("Timer correctness test (1 second).\n");
 
for (i=0; i<NT; i++) NULL_TIMESPEC(&t[i]);
 
do {
for (i=0; i<NT-1; i++) t[i+1] = t[i];
 
sys_gettime(&t[0]);
 
if (TIMESPEC_A_LT_B(&t[0],&t[1])) {
for (i=0; i<NT; i++)
cprintf("%d %ld\n",i, t[i].tv_nsec);
exit(0);
}
} while (t[0].tv_sec < 1);
 
return 0;
}
 
/demos/tags/rel_1_5_4/base/intsem.c
0,0 → 1,109
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: intsem.c,v 1.3 2005-01-08 14:31:38 pj Exp $
 
this test is a simple main() function with one other task.
 
This test verify the correctness of the internal_sem functions.
 
*/
 
#include "kernel/kern.h"
 
#include <kernel/int_sem.h>
 
internal_sem_t s;
 
TASK pippo(void *a)
{
int i=0;
struct timespec t;
 
do {
sys_gettime(&t);
 
if (i==0 && t.tv_sec == (int)a) {
i = 1;
cprintf("before internal_sem_wait %d\n",(int)a);
internal_sem_wait(&s);
cprintf("after internal_sem_wait %d\n",(int)a);
}
 
if (i==1 && t.tv_sec == 2+(int)a) {
i = 2;
cprintf("before internal_sem_post %d\n",(int)a);
internal_sem_post(&s);
cprintf("after internal_sem_post %d\n",(int)a);
return 0;
}
 
 
} while (1);
}
 
int main(int argc, char **argv)
{
NRT_TASK_MODEL m;
PID p2,p3;
 
struct timespec t;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
nrt_task_def_arg(m,(void *)1);
p2 = task_create("pippo1", pippo, &m, NULL);
if (p2 == NIL)
{ cprintf("Can't create pippo1 task...\n"); return 1; }
 
nrt_task_def_arg(m,(void *)2);
p3 = task_create("pippo2", pippo, &m, NULL);
if (p3 == NIL)
{ cprintf("Can't create pippo2 task...\n"); return 1; }
 
internal_sem_init(&s,1);
 
group_activate(1);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 10);
exit(0);
 
return 0;
}
/demos/tags/rel_1_5_4/base/pcdemo.c
0,0 → 1,203
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: pcdemo.c,v 1.4 2005-01-08 14:31:38 pj Exp $
 
This test verify the correctness of the PC module.
 
The test uses 3 mutexes
m0 with ceiling 0
m1 with ceiling 0
m2 with ceiling 1
 
the main task (NRT) creates three tasks.
 
J0 with PC priority 0
starts at t=1.5 sec and lock m0, unlock m0, then lock and unlock m1
 
J1 with PC priority 1
starts at t=0.5 sec and try to lock m2
 
J2 with PC priority 2
it starts and locks m2
at t=1 sec it locks m1
at t=1.5 sec it unlocks m1
 
 
The example is similar to the scheduling diagram shown at p. 197 of the
book "Sistemi in tempo Reale", by Giorgio Buttazzo, Pitagora Editrice
 
*/
 
#include "kernel/kern.h"
 
mutex_t m0,m1,m2;
 
void startJ(void *a)
{
task_activate((PID)a);
}
 
TASK j0()
{
cprintf("J0: before locking m0\n");
mutex_lock(&m0);
cprintf("J0: locked m0\n");
mutex_unlock(&m0);
cprintf("J0: unlocked m0, locking m1\n");
 
mutex_lock(&m1);
cprintf("J0: locked m1\n");
mutex_unlock(&m1);
cprintf("J0: unlocked m1, end task\n");
return 0;
}
 
 
TASK j1()
{
cprintf("J1: before locking m2\n");
mutex_lock(&m2);
cprintf("J1: locked m2\n");
mutex_unlock(&m2);
cprintf("J1: unlocked m2, end task\n");
return 0;
}
 
 
TASK j2()
{
cprintf("J2: before locking m2\n");
mutex_lock(&m2);
cprintf("J2: locked m2, waiting to t=1 sec\n");
 
while (sys_gettime(NULL) < 1000000);
 
cprintf("J2: t = 1 sec reached\n");
mutex_lock(&m1);
cprintf("J2: locked m1, waiting to t=2 sec\n");
 
while (sys_gettime(NULL) < 2000000);
 
cprintf("J2: t = 2 sec reached\n");
mutex_unlock(&m1);
cprintf("J2: unlocked m1\n");
 
mutex_unlock(&m2);
cprintf("J2: unlocked m2, end task\n");
return 0;
}
 
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;
 
clear();
 
cprintf("Priority Ceiling demo. It ends after 60 sec\n");
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
hard_task_default_model(m);
hard_task_def_mit(m, 1000000);
hard_task_def_wcet(m, 20000);
PC_res_default_model(r,0);
p0 = task_create("J0", j0, &m, &r);
if (p0 == NIL)
{ cprintf("Can't create J0 task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 2100000);
hard_task_def_wcet(m, 20000);
PC_res_default_model(r,1);
p1 = task_create("J1", j1, &m, &r);
if (p1 == NIL)
{ cprintf("Can't create J1 task...\n"); return 1; }
 
hard_task_default_model(m);
hard_task_def_mit(m, 10000000);
hard_task_def_wcet(m, 3000000);
PC_res_default_model(r,2);
p2 = task_create("J2", j2, &m, &r);
if (p2 == NIL)
{ cprintf("Can't create J2 task...\n"); return 1; }
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a2);
PC_mutexattr_default(a,0);
mutex_init(&m0,(mutexattr_t *)&a);
mutex_init(&m1,(mutexattr_t *)&a);
 
PC_mutexattr_default(a,1);
mutex_init(&m2,(mutexattr_t *)&a);
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
t.tv_sec = 0;
t.tv_nsec = 500000000;
 
kern_cli();
kern_event_post(&t,startJ,(void *)p1);
 
t.tv_sec = 1;
kern_event_post(&t,startJ,(void *)p0);
kern_sti();
 
task_activate(p2);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 10);
exit(0);
 
return 0;
 
}
/demos/tags/rel_1_5_4/base/preempt.c
0,0 → 1,149
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: preempt.c,v 1.4 2005-01-08 14:31:38 pj Exp $
 
CBS test with preemption disabling
 
*/
 
#include "kernel/kern.h"
 
void *periodic(void *arg)
{
int i;
int y = (int)arg;
 
for (i = 19; i < 60; i++) {
puts_xy(i,y,7,"*");
 
task_endcycle();
}
 
cprintf("Periodic: Task %d end.\n", exec_shadow);
 
return 0;
}
 
void *blocker(void *arg)
{
struct timespec t;
 
task_nopreempt();
cprintf("Blocker: Task nopreempt\n");
 
do {
sys_gettime(&t);
} while (t.tv_sec < 5);
 
cprintf("Blocker: Task preempt\n");
task_preempt();
 
cprintf("Blocker: end\n");
 
return 0;
}
 
 
 
int main(int argc, char **argv)
{
struct timespec t;
NRT_TASK_MODEL m;
SOFT_TASK_MODEL m_aper;
PID p;
 
clear();
cprintf("Preemption Test.\n");
cprintf("Start time: two periodic tasks and a blocker are created and activated.\n");
cprintf("2 seconds : blocker calls task_nopreempt.\n");
cprintf("5 seconds : task_preempt is called.\n");
cprintf(" The blocked task exec its pending activations.\n");
cprintf("10 seconds: the test stops.\n");
puts_xy(1,20,7,"save task:");
puts_xy(1,21,7,"skip task:");
 
nrt_task_default_model(m);
 
soft_task_default_model(m_aper);
soft_task_def_met(m_aper,10000);
soft_task_def_period(m_aper,200000);
soft_task_def_group(m_aper,1);
soft_task_def_arg(m_aper, (void *)20);
soft_task_def_periodic(m_aper);
 
p = task_create("save", periodic, &m_aper, NULL);
if (p == NIL)
{
sys_shutdown_message("Can't create save task...\n");
exit(1);
}
 
soft_task_def_skip_arrivals(m_aper);
soft_task_def_arg(m_aper, (void *)21);
 
p = task_create("skip", periodic, &m_aper, NULL);
if (p == NIL)
{
sys_shutdown_message("Can't create skip task...\n");
exit(1);
}
 
p = task_create("blocker", blocker, &m, NULL);
if (p == NIL)
{
sys_shutdown_message("Can't create blocker task...\n");
exit(1);
}
 
cprintf("main : save & skip tasks activated.\n");
group_activate(1);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 2);
 
cprintf("main : blocker activated.\n");
task_activate(p);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 10);
 
cprintf("main : End!!!\n");
 
return 0;
}
/demos/tags/rel_1_5_4/base/pidemo.c
0,0 → 1,123
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: pidemo.c,v 1.4 2005-01-08 14:31:38 pj Exp $
 
This test verify the correctness of the PI module.
 
the main task (NRT) lock a PI mutex.
then 2 tasks arrives, with priority higher than the main
 
the first try to lock the mutex, but it can't, so the main inherit
his priority. The second simply prints a string.
 
If all works, the string of the second task is printed after the end of
the first task.
 
*/
 
#include "kernel/kern.h"
 
mutex_t m1;
 
 
TASK goofy1(void *a)
{
cprintf("goofy1 before mutex_lock\n");
mutex_lock(&m1);
cprintf("goofy1 after mutex_lock\n");
 
mutex_unlock(&m1);
cprintf("goofy1 after mutex_unlock\n");
 
return 0;
}
 
TASK goofy2()
{
cprintf("goofy2 inside goofy2\n");
return 0;
}
 
int main(int argc, char **argv)
{
HARD_TASK_MODEL m;
PID p2,p3;
 
struct timespec t;
 
PI_mutexattr_t a;
 
hard_task_default_model(m);
hard_task_def_mit(m,50000);
hard_task_def_wcet(m,20000);
hard_task_def_group(m,1);
 
hard_task_def_arg(m,(void *)1);
p2 = task_create("goofy1", goofy1, &m, NULL);
if (p2 == NIL)
{ cprintf("Can't create goofy1 task...\n"); return 1; }
 
hard_task_def_mit(m,100000);
p3 = task_create("goofy2", goofy2, &m, NULL);
if (p3 == NIL)
{ cprintf("Can't create goofy2 task...\n"); return 1; }
 
PI_mutexattr_default(a);
mutex_init(&m1,&a);
 
cprintf("main before mutex_lock\n");
mutex_lock(&m1);
cprintf("main after mutex_lock\n");
 
group_activate(1);
 
cprintf("main after group_activate\n");
mutex_unlock(&m1);
cprintf("main after mutex_unlock\n");
 
mutex_destroy(&m1);
cprintf("main after mutex_destroy\n");
 
do {
sys_gettime(&t);
} while (t.tv_sec < 10);
 
exit(0);
 
return 0;
 
}
/demos/tags/rel_1_5_4/base/sig.c
0,0 → 1,167
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: sig.c,v 1.4 2005-01-08 14:31:38 pj Exp $
 
File: $File$
Revision: $Revision: 1.4 $
Last update: $Date: 2005-01-08 14:31:38 $
------------
**/
 
/*
* Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
/*
Test Number 5:
 
this test is a simple main() function with one other task
 
This test can be useful to test functions like:
 
sys_gettime
sigemptyset
sigaddset
hartik_deliver_pending_signals
task_sigmask
sigaction
sigqueue
task_signal
*/
 
#include "kernel/kern.h"
 
 
TASK goofy(void *arg)
{
struct timespec t;
 
cprintf("Goofy: waiting 2 secs...\n");
 
do {
sys_gettime(&t);
} while (t.tv_sec < 2); // wait until 2 sec
cprintf("Goofy: ok, I'm ready :-)\n");
 
return 0;
}
 
void catchit_RT(int signo, siginfo_t *info, void *extra)
{
cprintf("RT signal: Current Running Task = %d signo=%d code=%d value=%d from pid=%d\n",
exec_shadow,
info->si_signo, info->si_code,
info->si_value.sival_int, info->si_task);
}
 
void catchit(int signo)
{
cprintf("RT signal: Current Running Task = %d signo=%d\n",
exec_shadow, signo);
}
 
int main(int argc, char **argv)
{
struct timespec t;
NRT_TASK_MODEL m;
PID p2;
 
sigset_t newmask;
sigset_t oldmask;
struct sigaction action;
union sigval sval;
 
clear();
 
/* Set the signal action */
action.sa_flags = SA_SIGINFO;
action.sa_sigaction = catchit_RT;
action.sa_handler = 0;
action.sa_mask = 0;
 
if (sigaction(SIGUSR1, &action, NULL) == -1) {
perror("Error using sigaction.");
return -1;
}
 
action.sa_flags = 0;
action.sa_handler = (void (*)(int))catchit;
 
if (sigaction(SIGILL, &action, NULL) == -1) {
perror("Error using sigaction.");
return -1;
}
 
/* create another task */
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
p2 = task_create("goofy", goofy, &m, NULL);
if (p2 == NIL)
{
cprintf("Can't create goofy task...\n");
return 1;
}
 
group_activate(1);
 
/* block the signal for the main task */
sigemptyset(&newmask);
sigaddset(&newmask,SIGUSR1);
task_sigmask(SIG_BLOCK, &newmask, &oldmask); // pthread_sigmask
 
cprintf("main: Sending 2 signals ...\n");
 
sval.sival_int = 123;
sigqueue(0,SIGUSR1,sval);
sval.sival_int = 999;
sigqueue(0,SIGUSR1,sval);
 
cprintf("main: Now sending a signal to myself,"
" then wait until 4 secs...\n");
 
task_signal(0 /* main */, SIGILL); // pthread_kill
 
NULL_TIMESPEC(&t);
do {
sys_gettime(&t);
} while (t.tv_sec < 4); // wait until 4 s
 
cprintf("main: ending...\n");
 
return 0;
}
/demos/tags/rel_1_5_4/base/condtest.c
0,0 → 1,209
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: condtest.c,v 1.3 2005-01-08 14:31:38 pj Exp $
 
This test verify the correctness of the condition variables.
(... it doesn't test all...)
 
The test uses 1 mutex
 
the main task (NRT) creates three tasks.
 
J0, J1, J3
starts, lock the mutex, and wait on a condition variable
 
J2
at t = 0.5 lock the mutex and call cond_signal
at t = 1 lock the mutex and call cond_signal
 
*/
 
#include "kernel/kern.h"
 
mutex_t m0;
cond_t c0;
 
int number = 0;
 
PID p0,p1,p2,p3;
 
TASK j0()
{
cprintf("J0: before locking m0\n");
mutex_lock(&m0);
cprintf("J0: locked m0, waiting on c0, number =%d\n", number);
while (!number) {
cond_wait(&c0,&m0);
cprintf("J0: number = %d, if >0 unlocking m0\n",number);
}
number--;
mutex_unlock(&m0);
cprintf("J0: unlocked m0, end task\n");
return 0;
}
 
 
TASK j1()
{
cprintf("J1: before locking m0\n");
mutex_lock(&m0);
cprintf("J1: locked m0, waiting on c0, number =%d\n", number);
while (!number) {
cond_wait(&c0,&m0);
cprintf("J1: number = %d, if >0 unlocking m0\n",number);
}
number--;
mutex_unlock(&m0);
cprintf("J1: unlocked m0, end task\n");
return 0;
}
 
 
TASK j2()
{
 
cprintf("J2: started, waiting t=0.5 sec\n");
while (sys_gettime(NULL) < 500000);
 
cprintf("J2: before locking m0\n");
mutex_lock(&m0);
cprintf("J2: locked m0, number++ (was %d), cond_signal\n", number);
 
number++;
cond_signal(&c0);
 
cprintf("J2: unlocking m0\n");
mutex_unlock(&m0);
 
cprintf("J2: waiting t=1 sec\n");
while (sys_gettime(NULL) < 1000000);
 
cprintf("J2: Killing J3\n");
task_kill(p3);
cprintf("J2: before locking m0\n");
mutex_lock(&m0);
cprintf("J2: locked m0, number++ (was %d), cond_signal\n", number);
 
number++;
cond_signal(&c0);
 
cprintf("J2: unlocking m0\n");
mutex_unlock(&m0);
cprintf("J2: unlocked m0, end task\n");
return 0;
}
 
void cleanup_lock(void *arg)
{
cprintf("J3: KILL!!!\n");
mutex_unlock(&m0);
cprintf("J3: unlocked m0 by the cleanup function\n");
}
 
TASK j3()
{
cprintf("J3: before locking m0\n");
mutex_lock(&m0);
cprintf("J3: locked m0, waiting on c0, number =%d\n", number);
task_cleanup_push(cleanup_lock, (void *)&m0);
while (!number) {
cond_wait(&c0,&m0);
cprintf("J3: number = %d, if >0 unlocking m0\n",number);
}
task_cleanup_pop(0);
// I hope this task never reach this point... it is killed by J2!!!
number--;
mutex_unlock(&m0);
cprintf("J3: unlocked m0, end task\n");
return 0;
}
 
 
int main(int argc, char **argv)
{
struct timespec t;
 
NRT_TASK_MODEL m;
 
PI_mutexattr_t a;
 
/* ---------------------------------------------------------------------
Task creation
--------------------------------------------------------------------- */
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
p0 = task_create("J0", j0, &m, NULL);
if (p0 == NIL)
{ cprintf("Can't create J0 task...\n"); return 1; }
 
p1 = task_create("J1", j1, &m, NULL);
if (p1 == NIL)
{ cprintf("Can't create J1 task...\n"); return 1; }
 
p2 = task_create("J2", j2, &m, NULL);
if (p2 == NIL)
{ cprintf("Can't create J2 task...\n"); return 1; }
 
p3 = task_create("J3", j3, &m, NULL);
if (p3 == NIL)
{ cprintf("Can't create J3 task...\n"); return 1; }
 
/* ---------------------------------------------------------------------
Mutex creation
--------------------------------------------------------------------- */
 
PI_mutexattr_default(a);
mutex_init(&m0,&a);
 
cond_init(&c0);
 
/* ---------------------------------------------------------------------
Event post
--------------------------------------------------------------------- */
 
group_activate(1);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 10);
exit(1);
 
return 0;
 
}
/demos/tags/rel_1_5_4/base/semdemo.c
0,0 → 1,105
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* CVS : $Id: semdemo.c,v 1.3 2005-01-08 14:31:38 pj Exp $
 
This is a really simple semaphore demo.
 
*/
 
#include "kernel/kern.h"
 
#include "semaphore.h"
 
sem_t s;
 
void *goofy(void *a)
{
struct timespec t;
char *n = proc_table[exec_shadow].name;
 
cprintf("Task %s: Locking semaphore...\n", n);
 
sem_wait(&s);
cprintf("Task %s: Semaphore locked...\n", n);
 
do {
sys_gettime(&t);
} while (t.tv_sec < (int)a);
 
cprintf("Task %s: Unlocking semaphore...\n", n);
 
sem_post(&s);
 
cprintf("Task %s: Semaphore unlocked...\n", n);
 
return 0;
}
 
int main(int argc, char **argv)
{
NRT_TASK_MODEL m;
PID p2,p3;
 
struct timespec t;
 
nrt_task_default_model(m);
nrt_task_def_group(m,1);
 
nrt_task_def_arg(m,(void *)1);
p2 = task_create("goofy1", goofy, &m, NULL);
if (p2 == NIL)
{ cprintf("Can't create goofy1 task...\n"); return 1; }
 
nrt_task_def_arg(m,(void *)2);
p3 = task_create("goofy2", goofy, &m, NULL);
if (p3 == NIL)
{ cprintf("Can't create goofy2 task...\n"); return 1; }
cprintf("Initializing semaphore...\n");
 
sem_init(&s,0,1);
 
group_activate(1);
 
do {
sys_gettime(&t);
} while (t.tv_sec < 10);
 
exit(0);
 
return 0;
}
/demos/tags/rel_1_5_4/base/pcidemo.c
0,0 → 1,45
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
*
* 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 "unistd.h"
 
int main (int argc, char *argv[])
{
 
cprintf("Init Done...\n");
 
sleep(5);
return 0;
 
}
/demos/tags/rel_1_5_4/base/readme
0,0 → 1,44
This directory contains a set of simple examples, useful to understand
How to make a Shark application.
 
Text mode demos:
- hello.c --> a hello world application
- timer.c --> tests if the time reads are always increasing
(useful for debugging purposes)
- sig.c --> simple example that sends signals
- semdemo.c --> simple example that uses a semaphore for mutual exclusion
- pidemo.c --> simple example that uses PI mutexes between NRT and Hard tasks
- pcdemo.c --> simple example that uses PC mutexes between NRT and Hard tasks
- srpdemo.c --> simple example that uses SRP mutexes between NRT and Hard tasks
- mdemo.c --> simple example that uses a mutex, initialized with whatever
protocol you want ;-)
- aster.c --> Wow! the original Hartik ASTER demo!!! (EDF, CABs, ...)
- aster1.c --> a -lot- of periodic tasks that are created and then die
(6 seconds demo)
- aster2.c --> a simple stress test: a lot of tasks are created until Utot=1;
uses jet functions to dump statistics. (60 seconds demo)
- aster3.c --> aster2 + 8 tasks handled by 2 different TBS servers
- aster4.c --> aster3 + CBS tasks + Shutdown demo with system tasks
- aster5.c --> aster3 + only CBS tasks + mutexes... Really interesting!
- aster6.c --> aster5 + Polling Server to serve the JetCtrl task
- aster7.c --> another aster clone with Rate monotonic and Polling server
- aster8.c --> aster5 + Sporadic Server
- preempt.c --> simple test for CBS, task_preempt, task_nopreempt, and
save/skip arrivals
- pcidemo.c --> PCI Bus scan
- jointest.c--> Simple test that uses the task_join primitive
- condtest.c--> Simple test that uses condition variables
- intsem.c --> Simple test that uses internal semaphores
 
Graphical demos:
- fly.c --> Random flies going around the screen
- ego.c --> Periodic tasks that writes a phrease on the screen
- cabs.c --> Example that uses cabs
 
Note on the init files:
- ihello.c (RR+dummy)
- isemdemo.c (iaster1+Semaphores)
- iaster1.c (EDF+RR+dummy)
- iaster3.c (EDF+RR+TBS(0.1)+TBS(0.3)+dummy)
- iaster4.c (iaster3+CBS)
- initfile.c (EDF+CBS+RR+dummy, SEMaphores, CABS, HARTPORTs and Keyboard)
/demos/tags/rel_1_5_4/base/hello.c
0,0 → 1,53
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
/*
CVS : $Id: hello.c,v 1.1 2002-10-28 08:13:37 pj Exp $
 
hello.c:
 
This test is a simple hello world function.
 
*/
 
#include "kernel/kern.h"
 
int main(int argc, char **argv)
{
cprintf("Hello, world!\n");
 
return 0;
}
/demos/tags/rel_1_5_4/dosfs/initfile.c
0,0 → 1,91
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: initfile.c,v 1.2 2005-02-25 11:10:46 pj Exp $
 
File: $File$
Revision: $Revision: 1.2 $
Last update: $Date: 2005-02-25 11:10:46 $
------------
**/
 
/*
* Copyright (C) 2000 Paolo Gai and Gabriele Bolognini
*
* 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 "rr/rr/rr.h"
#include "dummy/dummy/dummy.h"
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
void read_myfile(void);
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
/* If you need to interact with the DOS Filesystem and you use
the X eXtender, this is the better place where you can use
the DOS_fXXX functions...
 
WARNING: You can call these functions only when you are in
real mode!!!
 
The system is in real mode:
- into __kernel_register_levels__()
- into sys_atrunlevel functions posted with RUNLEVEL_AFTER_EXIT
*/
read_myfile();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/tags/rel_1_5_4/dosfs/makefile
0,0 → 1,16
#
#
#
 
ifndef BASE
BASE=../..
endif
include $(BASE)/config/config.mk
 
PROGS= dosfs
 
include $(BASE)/config/example.mk
 
dosfs:
make -f $(SUBMAKE) APP=dosfs INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT=
 
/demos/tags/rel_1_5_4/dosfs/dosfs.c
0,0 → 1,174
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: dosfs.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:41 $
------------
**/
 
/*
* Copyright (C) 2000 Paolo Gai and Gabriele Bolognini
*
* 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 "string.h"
#include "ll/i386/x-dos.h"
 
 
/* This is the buffer used by read_myfile */
char myfilebuf[1000];
 
/* This is the number of bytes read by read_myfile */
int myfilebuf_length;
 
/* This function write myfile.out (up to 30 chars) */
void write_myfile(void *arg);
 
int main(int argc, char **argv)
{
int x;
 
cprintf("\nBuffer contents:\n");
 
for (x=0; x<myfilebuf_length; x++)
cputc(myfilebuf[x]);
 
/*
WARNING: You can call these functions only when you are in
real mode!!!
 
The system is in real mode:
- into __kernel_register_levels__()
- into sys_atrunlevel functions posted with RUNLEVEL_AFTER_EXIT
*/
 
if (myfilebuf_length)
sys_atrunlevel(write_myfile, NULL, RUNLEVEL_AFTER_EXIT);
 
return 0;
/*
* Since there is only one user task, the kernel will shut down after this
* task finishes...
*/
}
 
/* This function read myfile.txt (up to 1000 chars) */
void read_myfile(void)
{
/* DOS file descriptor */
DOS_FILE *f;
 
/* Error code */
int err;
 
/* open the DOS file for reading (you can specify only "r" or "w") */
f = DOS_fopen("myfile.txt","r");
 
/* check for open errors */
if (!f) {
/* error!! */
err = DOS_error();
 
/* note that if you call DOS_error() here, it return 0!!! */
cprintf("Error %d opening myfile.txt...\n", err);
myfilebuf_length = 0;
return;
}
 
/* read up to 1000 chars */
myfilebuf_length = DOS_fread(&myfilebuf,1,1000,f);
 
/* check for errors */
err = DOS_error();
 
cprintf("Read %d bytes from myfile.txt...\n", myfilebuf_length);
 
if (err) {
cprintf("Error %d reading myfile.txt...\n", err);
myfilebuf_length = 0;
/* there is not return because I want to close the file! */
}
 
/* Close the file */
DOS_fclose(f);
}
 
/* This function write myfile.out (up to 30 chars) */
void write_myfile(void *arg)
{
DOS_FILE *f; /* DOS file descriptor */
int err; /* Error code */
int maxbytes;
int writtenbytes; /* number of files written */
 
/* open the DOS file for writing (you can specify only "r" or "w") */
f = DOS_fopen("myfile.out","w");
 
/* check for open errors */
if (!f) {
/* error!! */
err = DOS_error();
 
/* note that if you call DOS_error() here, it return 0!!! */
cprintf("Error %d opening myfile.out...\n", err);
return;
}
 
/* write up to 30 bytes */
if (myfilebuf_length > 30)
maxbytes = 30;
else
maxbytes = myfilebuf_length;
 
writtenbytes = DOS_fwrite(myfilebuf,1,maxbytes,f);
 
/* check for errors */
err = DOS_error();
 
cprintf("Written %d bytes into myfile.out...\n", writtenbytes);
 
if (err) {
cprintf("Error %d writing myfile.txt...\n", err);
/* there is not return because I want to close the file! */
}
 
/* Close the file */
DOS_fclose(f);
}
 
 
/demos/tags/rel_1_5_4/dosfs/myfile.txt
0,0 → 1,3
0.2.4.6.8.0.2.4.6.8.0.2.4.6.8.0.2.4.6.8.
This is the myfile.txt file...
 
/demos/tags/rel_1_5_4/dosfs/readme.txt
0,0 → 1,46
--------------------------------------
DOS_fXXX Demo
 
by
 
Paolo Gai pj@sssup.it
and
Gabriele Bolognini gabrieleb@sssup.it
2001
 
--------------------------------------
 
The DOS_fXXX functions provided into ll/i386/x-dos.h are a few
shortcuts that can be used to call INT21's DOS calls.
 
These functions can be used to read and write files before/after
the kernel goes into i386 protected mode.
 
THEY CANNOT BE USED IF YOU BOOT WITH GRUB.
 
--------------------------------------
 
The demo is composed by:
 
MAKEFILE The makefile used to compile the application;
dosfs is the rule to compile the application
README.TXT This file
INITFILE.C The init file (only RR)
DOSFS.C The DOS_fread and DOS_fwrite demo
 
--------------------------------------
 
The demo works as follows:
- Into __kernel_register_levels__() the demo reads up to 1000 bytes from
myfile.txt
- Then, into the main() function it prints the contents of the buffer at
screen
- Finally, at the end of the system it writes a file called myfile.out
with up to 30 of the first bytes of the buffer
 
The demo should work on any processor speed, and does not use keyboard or
graphics.
 
Bug: at the moment (01 Jun 2001) sometimes the demo hangs when using
the one-shot timer.
 
/demos/tags/rel_1_5_4/network/DatagramSender.java
0,0 → 1,35
import java.net.*;
import java.util.*;
 
public class DatagramSender {
public static void main(String argv[]) throws Exception {
long i = 0;
DatagramSocket sender = new DatagramSocket();
InetAddress IP = InetAddress.getByName("192.168.121.2");
String line=("Inviato");
byte[] buffer = new byte[255];
byte[] buffer1 ;
DatagramPacket packetr;
 
while ( true ) {
//DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
//System.out.println("In attesa di messaggi...");
//receiver.receive(packet);
//String message = new String(packet.getData(), packet.getOffset(), packet.getLength());
//System.out.println("Messaggio ricevuto dall'host " + packet.getAddress() + " su porta " + packet.getPort() + ": " + message+" "+ i++);
line="Inviato"+i;
buffer1 = line.getBytes();
packetr = new DatagramPacket(buffer1, buffer1.length, IP, 100);
sender.send(packetr);
if(i++ % 10==0)
System.out.println("Inviato"+i);
Thread.sleep(508,0);
//System.out.println(message+" "+ i++);
}
 
}
}
 
 
 
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: tags/rel_1_5_4/network/notify.c
===================================================================
--- tags/rel_1_5_4/network/notify.c (nonexistent)
+++ tags/rel_1_5_4/network/notify.c (revision 1617)
@@ -0,0 +1,149 @@
+/*
+* Project: S.Ha.R.K.
+*
+* Coordinators:
+* Giorgio Buttazzo <giorgio@sssup.it>
+* Paolo Gai <pj@gandalf.sssup.it>
+*
+* Authors :
+* Tullio Facchinetti <tullio.facchinetti@unipv.it>
+* Luca M. Capisani <luca.capisani@unipv.it>
+*
+* Robotic Lab (Dipartimento di ingegneria informatica - Pavia - Italy)
+*
+* http://robot.unipv.it
+* http://www.sssup.it
+* http://retis.sssup.it
+* http://shark.sssup.it
+*/
+
+/*
+* udp_notify demo: this simple demo shows how to set up a simple UDP/IP
+* packet handler function in order to avoid busy waits or task creation
+* for the packet receiver function.
+* usage: after compiling this demo, with the "make" command, start it with:
+* x net <loc_ip> <loc_port>
+* where <loc_ip> stands for the local ip of the receiver host and
+* <loc_port> stands for the local UDP port where the receiver listens.
+*/
+
+/*
+* 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/udpip.h>
+#include <string.h> //for strcpy()
+#include <unistd.h> //for sleep()
+#include "drivers/shark_keyb26.h" //for keyboard
+
+
+//Received Packet Counter
+long recvcount=0;
+
+//The Internet Address of this Host
+char local_ip[20];
+
+//A index for the receiver socket
+int socket;
+
+//Declaring a structure containing the receiver UDP port
+UDP_ADDR local;
+
+//UDP receiver handler: this function is called upon UDP packet received.
+//No Busy waits are present.
+int recvFun(int len, unsigned char *buff, void *p){
+
+ recvcount++;
+
+ //Printing on screen the data contained, assuming that is text data
+ cprintf("Packet # %ld, len %d: %s.\n",recvcount, len,buff);
+
+ return 1;
+}
+
+/* Init the network stack */
+int init_network(char *local_ip)
+{
+ //Declaring a network model and asigning the UDP/IP model;
+ struct net_model m = net_base;
+
+
+ //Setting up the UDP/IP stack, assigning a UDP/IP/Ethernet Network Model,
+ //a host and a network broadcast address.
+ net_setudpip(m,local_ip,"255.255.255.0");
+
+ //Initializing the network stack
+ if (net_init(&m) != 1) {
+ cprintf("Network: Init Error.\n");
+ return -1;
+ }
+
+
+ //Binding of the UDP port in the system network stack
+ //without assigning a peer IP-list in the second parameter
+ socket = udp_bind(&local, NULL);
+
+ //Assigning a receiver notify handler called on packed received
+ udp_notify(socket, &recvFun,NULL);
+
+ return 0;
+
+}
+
+void program_key_end(KEY_EVT* e)
+{
+ exit(1);
+}
+
+
+int main(int argc, char **argv)
+{
+ //Assigning a CTRL+C exit key shortcut
+ KEY_EVT k;
+ k.flag = CNTL_BIT;
+ k.scan = KEY_C;
+ k.ascii = 'c';
+ k.status = KEY_PRESSED;
+ keyb_hook(k,program_key_end,FALSE);
+
+ if (argc==3){
+ //Copy the input parameters values into the UDP/IP stack
+ strcpy(local_ip, argv[1]);
+
+ //A local UDP port number where the receiver listens
+ local.s_port=atoi(argv[2]);
+ }else{
+ //The user has given a wrong number of parameters:
+ cprintf("S.Ha.R.K. udp_notify usage: x net <localIP> <localUDPport>\n");
+ return(1);
+ }
+
+ cprintf("Initializing the network stack... \n");
+
+ //Initializing the network settings
+ if (init_network(local_ip)) exit(1);
+
+ cprintf("Waiting for packets on port %d... \n",local.s_port);
+
+ //Waiting for packets
+ while(1){
+ sleep(1);
+ }
+
+
+ return 0;
+}
/tags/rel_1_5_4/network/notify.c
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: tags/rel_1_5_4/network/makefile
===================================================================
--- tags/rel_1_5_4/network/makefile (nonexistent)
+++ tags/rel_1_5_4/network/makefile (revision 1617)
@@ -0,0 +1,21 @@
+#
+#
+#
+
+ifndef BASE
+BASE=../..
+endif
+include $(BASE)/config/config.mk
+
+PROGS = net talk
+
+include $(BASE)/config/example.mk
+
+net:
+ make -f $(SUBMAKE) BASE=$(BASE) APP=net INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__PCI__ __LINUXC26__ __INPUT__ __NET__"
+
+talk:
+ make -f $(SUBMAKE) BASE=$(BASE) APP=talk INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__PCI__ __LINUXC26__ __INPUT__ __NET__"
+
+notify:
+ make -f $(SUBMAKE) BASE=$(BASE) APP=notify INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__PCI__ __LINUXC26__ __INPUT__ __NET__"
Index: tags/rel_1_5_4/network/net.c
===================================================================
--- tags/rel_1_5_4/network/net.c (nonexistent)
+++ tags/rel_1_5_4/network/net.c (revision 1617)
@@ -0,0 +1,99 @@
+/*
+ * Project: S.Ha.R.K.
+ *
+ * Coordinators:
+ * Giorgio Buttazzo <giorgio@sssup.it>
+ * Paolo Gai <pj@gandalf.sssup.it>
+ *
+ * Authors :
+ * Giacomo Guidi <giacomo@gandalf.sssup.it>
+ *
+ * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
+ *
+ * http://www.sssup.it
+ * http://retis.sssup.it
+ * http://shark.sssup.it
+ */
+
+/*
+ * 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/udpip.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/* Init the network stack */
+int init_network(char *local_ip)
+{
+
+ struct net_model m = net_base;
+
+ net_setudpip(m, local_ip, "255.255.255.255");
+
+ if (net_init(&m) != 1) {
+ cprintf("Network: Init Error.\n");
+ return -1;
+ }
+
+ return 0;
+
+}
+
+int main(int argc, char **argv)
+{
+ UDP_ADDR target, local;
+ char local_ip[20], target_ip[20], buff[10];
+ int socket, i;
+ IP_ADDR bindlist[5];
+
+ strcpy(local_ip, "192.168.1.10");
+ strcpy(target_ip, "192.168.1.1");
+
+ if (init_network(local_ip)) exit(1);
+
+ /* local IP string to addr */
+ ip_str2addr(local_ip,&(local.s_addr));
+ /* set the source port */
+ local.s_port = 100;
+
+ /* target IP string to addr */
+ ip_str2addr(target_ip,&(bindlist[0]));
+ memset(&(bindlist[1]), 0, sizeof(IP_ADDR));
+ /* bind */
+ socket = udp_bind(&local, NULL);
+
+ /* target IP string to addr */
+ ip_str2addr(target_ip,&(target.s_addr));
+ /* target port */
+ target.s_port = 100;
+
+ for (i = 0; i < 5; i++) {
+ strcpy(buff, "qwerty\n");
+ cprintf("Send packet: %s\n", buff);
+ udp_sendto(socket, buff, strlen(buff), &target);
+ sleep(1);
+ }
+
+ cprintf("The End.\n");
+
+ exit(1);
+
+ return 0;
+}
Index: tags/rel_1_5_4/network/initfile.c
===================================================================
--- tags/rel_1_5_4/network/initfile.c (nonexistent)
+++ tags/rel_1_5_4/network/initfile.c (revision 1617)
@@ -0,0 +1,162 @@
+/*
+ * Project: S.Ha.R.K.
+ *
+ * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
+ *
+ * Authors :
+ * Mauro Marinoni <mauro.marinoni@unipv.it>
+ * Tullio Facchinetti <tullio.facchinetti@unipv.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
+ */
+
+/*
+ * 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 "edf/edf/edf.h"
+#include "cbs/cbs/cbs.h"
+#include "rr/rr/rr.h"
+#include "dummy/dummy/dummy.h"
+#include "intdrive/intdrive/intdrive.h"
+
+#include "sem/sem/sem.h"
+#include "hartport/hartport/hartport.h"
+
+#include <drivers/shark_linuxc26.h>
+#include <drivers/shark_pci26.h>
+#include <drivers/shark_input26.h>
+#include <drivers/shark_keyb26.h>
+
+/*+ sysyem tick in us +*/
+#define TICK 0
+
+/*+ RR tick in us +*/
+#define RRTICK 10000
+
+/*+ Interrupt Server +*/
+#define INTDRIVE_Q 1000
+#define INTDRIVE_U 0.1*MAX_BANDWIDTH
+#define INTDRIVE_FLAG 0
+
+void call_shutdown_task(void *arg);
+int device_drivers_init();
+int device_drivers_close();
+void set_shutdown_task();
+TASK shutdown_task_body(void *arg);
+
+PID shutdown_task_PID = 1;
+
+TIME __kernel_register_levels__(void *arg)
+{
+ struct multiboot_info *mb = (struct multiboot_info *)arg;
+ LEVEL EDF_level;
+
+ INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
+ EDF_level = EDF_register_level(EDF_ENABLE_ALL);
+ CBS_register_level(CBS_ENABLE_ALL, EDF_level);
+ RR_register_level(RRTICK, RR_MAIN_YES, mb);
+ dummy_register_level();
+
+ SEM_register_module();
+
+ return TICK;
+}
+
+int device_drivers_close() {
+
+ KEYB26_close();
+ INPUT26_close();
+
+ return 0;
+
+}
+
+int device_drivers_init() {
+
+ KEYB_PARMS kparms = BASE_KEYB;
+
+ LINUXC26_register_module(TRUE);
+ PCI26_init();
+ INPUT26_init();
+
+ /*keyb_def_map(kparms, KEYMAP_IT);*/
+ keyb_def_ctrlC(kparms, NULL);
+ KEYB26_init(&kparms);
+
+ return 0;
+}
+
+TASK shutdown_task_body(void *arg) {
+
+ device_drivers_close();
+ sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
+ return NULL;
+}
+
+#define SHUTDOWN_TIMEOUT_SEC 3
+
+void set_shutdown_task() {
+
+ NRT_TASK_MODEL nrt;
+
+ nrt_task_default_model(nrt);
+ nrt_task_def_system(nrt);
+
+ shutdown_task_PID = task_create("Shutdown Task", shutdown_task_body, &nrt, NULL);
+ if (shutdown_task_PID == NIL) {
+ sys_shutdown_message("Error: Cannot create shutdown task\n");
+ exit(1);
+ }
+
+}
+
+void call_shutdown_task(void *arg) {
+
+ struct timespec t;
+
+ sys_gettime(&t);
+ t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
+
+ /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
+ kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
+
+ task_activate(shutdown_task_PID);
+}
+
+TASK __init__(void *arg)
+{
+ struct multiboot_info *mb = (struct multiboot_info *)arg;
+
+ HARTPORT_init();
+
+ set_shutdown_task();
+
+ device_drivers_init();
+
+ sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
+
+ __call_main__(mb);
+
+ return (void *)0;
+}
Index: tags/rel_1_5_4/network/talk.c
===================================================================
--- tags/rel_1_5_4/network/talk.c (nonexistent)
+++ tags/rel_1_5_4/network/talk.c (revision 1617)
@@ -0,0 +1,217 @@
+/*
+ * Project: S.Ha.R.K.
+ *
+ * Coordinators:
+ * Giorgio Buttazzo <giorgio@sssup.it>
+ * Paolo Gai <pj@gandalf.sssup.it>
+ *
+ * Authors :
+ * Paolo Gai <pj@gandalf.sssup.it>
+ * (see the web pages for full authors list)
+ *
+ * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
+ *
+ * http://www.sssup.it
+ * http://retis.sssup.it
+ * http://shark.sssup.it
+ */
+
+/*
+ * Copyright (C) 2000 Luca Abeni, Paolo Gai
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *
+ * CVS : $Id: aster1.c,v 1.1 2002/10/28 08:13:37 pj Exp
+
+ This is the talkdx.c Hartik's example.
+
+ File: Talk.C
+ Revision: 1.00
+ Author: Luca Abeni
+
+
+ Simple Netlib demo: nothing of seriously real-time, only another Unix
+ Talk clone.
+ Read it to see how the UDP/IP layers of the networ library work.
+
+*/
+
+#include <kernel/kern.h>
+#include <string.h>
+
+#include <drivers/crtwin.h>
+#include <drivers/shark_keyb26.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],tmp[5],ch;
+ int s;
+ IP_ADDR bindlist[5];
+
+ win_init(&wr,0,7,79,6);
+ win_frame(&wr,BLACK,WHITE,"Local",2);
+
+ /* 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);
+
+ 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...*/
+ while((ch = keyb_getch(BLOCK)) != 13) {
+ sprintf(tmp,"%c",ch);
+ strcat(str,tmp);
+ win_puts(&wr,tmp);
+ }
+ strcat(str,"\n");
+ win_puts(&wr,"\n");
+ /*...and send it!!! */
+ udp_sendto(s,str,strlen(str)+2,&to);
+ str[0] = 0;
+ }
+}
+
+/* This function is called when the user presses CTRL-C (stops the systems) */
+void esci(KEY_EVT *k)
+{
+ esc = TRUE;
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ KEY_EVT k;
+
+ struct net_model m = net_base;
+
+ NRT_TASK_MODEL m_nrt;
+
+ k.flag = CNTL_BIT;
+ k.scan = KEY_C;
+ k.ascii = 'c';
+ k.status = KEY_PRESSED;
+ keyb_hook(k,esci,FALSE);
+ k.flag = CNTR_BIT;
+ k.scan = KEY_C;
+ k.ascii = 'c';
+ k.status = KEY_PRESSED;
+ keyb_hook(k,esci,FALSE);
+
+ clear();
+ cprintf(" S.Ha.R.K. Talk! Ver. 1.10\n");
+
+ if (argc != 3) {
+ cprintf("S.Ha.R.K. Talk usage: talk fromIP toIP\n");
+ return 0;
+ }
+
+ strcpy(talk_myipaddr, argv[1]);
+ strcpy(talk_toipaddr, argv[2]);
+
+ /* We want a task for TX mutual exclusion */
+ net_setmode(m, TXTASK);
+ /* We use UDP/IP stack */
+ net_setudpip(m, talk_myipaddr, "255.255.255.255");
+ /* OK: let's start the NetLib! */
+ if (net_init(&m) == 1) {
+ cprintf("Net Init OK...\n");
+ } else {
+ cprintf("Net Init Failed...\n");
+ exit(300);
+ }
+
+
+ //dump_irq();
+
+ cprintf("\n\n\n\tPress ENTER\n");
+ while (!esc) {
+ keyb_getcode(&k,BLOCK);
+ if (k.ascii == 13) esc = TRUE;
+ }
+
+ esc = FALSE;
+ clear();
+ win_init(&dbg,0,20,60,3);
+ win_frame(&dbg,BLACK,WHITE,"Debug",2);
+
+ /* Start the sender and receiver tasks...*/
+ nrt_task_default_model(m_nrt);
+ task_activate(task_create("aaa",scrittore,&m_nrt,NULL));
+ task_activate(task_create("bbb",write,&m_nrt,NULL));
+
+ return 0;
+}
Index: tags/rel_1_5_4/newtrace/udp/udptrace.c
===================================================================
--- tags/rel_1_5_4/newtrace/udp/udptrace.c (nonexistent)
+++ tags/rel_1_5_4/newtrace/udp/udptrace.c (revision 1617)
@@ -0,0 +1,141 @@
+/*
+ * Project: S.Ha.R.K.
+ *
+ * Coordinators:
+ * Giorgio Buttazzo <giorgio@sssup.it>
+ * Paolo Gai <pj@gandalf.sssup.it>
+ *
+ * Authors :
+ * Giacomo Guidi <giacomo@gandalf.sssup.it>
+ * Tullio Facchinetti <tullio.facchinetti@unipv.it>
+ *
+ * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
+ *
+ * http://www.sssup.it
+ * http://retis.sssup.it
+ * http://shark.sssup.it
+ * http://robot.unipv.it
+ */
+
+/*
+ * 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 <FTrace_chunk.h>
+#include <FTrace_udp.h>
+#include <tracer.h>
+
+extern unsigned int clk_per_msec;
+
+int main(int argc, char **argv)
+{
+
+ long long i;
+
+ int a,b,c;
+ struct timespec start,end,diff;
+ SYS_FLAGS f;
+
+ /**
+ * Create 3 chunks for storing the tracer events.
+ * Explanation of flags:
+ * FTRACE_CHUNK_FLAG_FREE : the chunk is free to use
+ * FTRACE_CHUNK_FLAG_CYC : the chunk stores events in a cyclical way.
+ * When the chunk is full,
+ * it will continue from the head.
+ * FTRACE_CHUNK_FLAG_JTN : when the chunk is full,
+ * it jumps to the next chunk.
+ */
+ a = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
+ b = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_JTN);
+ c = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
+
+ /**
+ * Link the 3 chunks together.
+ * It is important to link before you can jump from one to another.
+ */
+ FTrace_chunk_link(a,b);
+ FTrace_chunk_link(b,c);
+
+ /** Select the first chunk for saving the events. */
+ FTrace_actual_chunk_select(a);
+
+ kern_gettime(&start);
+
+ /** Start the tracer. */
+ FTrace_enable();
+
+ /** Enable filtering for timer related events. */
+ FTrace_set_filter(FTrace_filter_timer, 1);
+
+ TRACER_LOGEVENT(FTrace_EVT_trace_start,proc_table[exec_shadow].context,clk_per_msec);
+
+ for (i=0;i<10;i++)
+ if (proc_table[i].context != 0) TRACER_LOGEVENT(FTrace_EVT_id,
+ (unsigned short int)proc_table[i].context,i);
+
+ for (i=0;i<1000000000;i++);
+
+ /** Enable filtering for timer related events. */
+ FTrace_set_filter(FTrace_filter_timer, 0);
+
+ /** Change the chunk where the events are stored. */
+ TRACER_LOGEVENT(FTrace_EVT_next_chunk,0,0);
+
+ f = kern_fsave();
+ __asm__("cpuid":::"eax","ebx","ecx","edx");
+ FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,1000,0);
+ FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,2000,0);
+ FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,3000,0);
+ FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,4000,0);
+ FAST_TRACER_LOGEVENT(FTrace_EVT_ipoint,5000,0);
+ __asm__("cpuid":::"eax","ebx","ecx","edx");
+ kern_frestore(f);
+
+ TRACER_LOGEVENT(FTrace_EVT_ipoint,6000,0);
+
+ for (i=0;i<1000000000;i++);
+
+ /** Store a TFrace stop event. */
+ TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
+
+ /** Stop the tracer. */
+ FTrace_disable();
+ kern_gettime(&end);
+
+ SUBTIMESPEC(&end,&start,&diff);
+
+ cprintf("Logged Time %d s %d us\n",(int)diff.tv_sec,(int)diff.tv_nsec/1000);
+
+ /** Initialize the network for remotely saving the trace. */
+ FTrace_OSD_init_udp(1, "192.168.1.10", "192.168.1.1");
+
+ /**
+ * You may want to save the events to disk. In that case, simply change
+ * the network initialization instruction with the following line:
+ *
+ * FTrace_init_disk_writer("trace.dat", 0, NULL, NULL);
+ *
+ */
+
+ /** Save the chunk. */
+ FTrace_send_chunk(a, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
+ FTrace_send_chunk(b, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_JTN);
+
+ return 0;
+
+}
Index: tags/rel_1_5_4/newtrace/udp/initfile.c
===================================================================
--- tags/rel_1_5_4/newtrace/udp/initfile.c (nonexistent)
+++ tags/rel_1_5_4/newtrace/udp/initfile.c (revision 1617)
@@ -0,0 +1,162 @@
+/*
+ * Project: S.Ha.R.K.
+ *
+ * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
+ *
+ * Authors :
+ * Mauro Marinoni <mauro.marinoni@unipv.it>
+ * Tullio Facchinetti <tullio.facchinetti@unipv.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
+ */
+
+/*
+ * 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 "edf/edf/edf.h"
+#include "cbs/cbs/cbs.h"
+#include "rr/rr/rr.h"
+#include "dummy/dummy/dummy.h"
+#include "intdrive/intdrive/intdrive.h"
+
+#include "sem/sem/sem.h"
+#include "hartport/hartport/hartport.h"
+
+#include <drivers/shark_linuxc26.h>
+#include <drivers/shark_pci26.h>
+#include <drivers/shark_input26.h>
+#include <drivers/shark_keyb26.h>
+
+/*+ sysyem tick in us +*/
+#define TICK 0
+
+/*+ RR tick in us +*/
+#define RRTICK 10000
+
+/*+ Interrupt Server +*/
+#define INTDRIVE_Q 1000
+#define INTDRIVE_U 0.1*MAX_BANDWIDTH
+#define INTDRIVE_FLAG 0
+
+void call_shutdown_task(void *arg);
+int device_drivers_init();
+int device_drivers_close();
+void set_shutdown_task();
+TASK shutdown_task_body(void *arg);
+
+PID shutdown_task_PID = 1;
+
+TIME __kernel_register_levels__(void *arg)
+{
+ struct multiboot_info *mb = (struct multiboot_info *)arg;
+ LEVEL EDF_level;
+
+ INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
+ EDF_level = EDF_register_level(EDF_ENABLE_ALL);
+ CBS_register_level(CBS_ENABLE_ALL, EDF_level);
+ RR_register_level(RRTICK, RR_MAIN_YES, mb);
+ dummy_register_level();
+
+ SEM_register_module();
+
+ return TICK;
+}
+
+int device_drivers_close() {
+
+ KEYB26_close();
+ INPUT26_close();
+
+ return 0;
+
+}
+
+int device_drivers_init() {
+
+ KEYB_PARMS kparms = BASE_KEYB;
+
+ LINUXC26_register_module(TRUE);
+ PCI26_init();
+ //INPUT26_init();
+
+ /*keyb_def_map(kparms, KEYMAP_IT);*/
+ keyb_def_ctrlC(kparms, NULL);
+ KEYB26_init(&kparms);
+
+ return 0;
+}
+
+TASK shutdown_task_body(void *arg) {
+
+ device_drivers_close();
+ sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
+ return NULL;
+}
+
+#define SHUTDOWN_TIMEOUT_SEC 3
+
+void set_shutdown_task() {
+
+ NRT_TASK_MODEL nrt;
+
+ nrt_task_default_model(nrt);
+ nrt_task_def_system(nrt);
+
+ shutdown_task_PID = task_create("Shutdown Task", shutdown_task_body, &nrt, NULL);
+ if (shutdown_task_PID == NIL) {
+ sys_shutdown_message("Error: Cannot create shutdown task\n");
+ exit(1);
+ }
+
+}
+
+void call_shutdown_task(void *arg) {
+
+ struct timespec t;
+
+ sys_gettime(&t);
+ t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
+
+ /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
+ kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
+
+ task_activate(shutdown_task_PID);
+}
+
+TASK __init__(void *arg)
+{
+ struct multiboot_info *mb = (struct multiboot_info *)arg;
+
+ HARTPORT_init();
+
+ set_shutdown_task();
+
+ device_drivers_init();
+
+ sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
+
+ __call_main__(mb);
+
+ return (void *)0;
+}
Index: tags/rel_1_5_4/newtrace/udp/makefile
===================================================================
--- tags/rel_1_5_4/newtrace/udp/makefile (nonexistent)
+++ tags/rel_1_5_4/newtrace/udp/makefile (revision 1617)
@@ -0,0 +1,16 @@
+#
+#
+#
+
+ifndef BASE
+BASE=../../..
+endif
+include $(BASE)/config/config.mk
+
+PROGS = udptrace
+
+include $(BASE)/config/example.mk
+
+udptrace:
+ make -f $(SUBMAKE) BASE=$(BASE) APP=udptrace INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __NET__"
+
Index: tags/rel_1_5_4/newtrace/instr/instr.c
===================================================================
--- tags/rel_1_5_4/newtrace/instr/instr.c (nonexistent)
+++ tags/rel_1_5_4/newtrace/instr/instr.c (revision 1617)
@@ -0,0 +1,168 @@
+/*
+ * Project: S.Ha.R.K.
+ *
+ * Coordinators:
+ * Giorgio Buttazzo <giorgio@sssup.it>
+ * Paolo Gai <pj@gandalf.sssup.it>
+ *
+ * Authors :
+ * Giacomo Guidi <giacomo@gandalf.sssup.it>
+ *
+ * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
+ *
+ * http://www.sssup.it
+ * http://retis.sssup.it
+ * http://shark.sssup.it
+ */
+
+/*
+ * 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
+ *
+ */
+
+/* The tracer instrumentation ideas come from the York PWCET analisys tool
+ *
+ * Real-Time System Group
+ * University of York
+ *
+ */
+
+#include <kernel/kern.h>
+#include <time.h>
+#include <tracer.h>
+
+#define PWCET_Automatic_Ipoint(a) TRACER_LOGEVENT(FTrace_EVT_ipoint,(a),0);
+
+extern int instrumented_function();
+
+TASK ext_call(void)
+{
+
+ while(1) {
+
+ instrumented_function();
+
+ task_testcancel();
+ task_endcycle();
+
+ }
+
+ return 0;
+
+}
+
+#define TASKMAX 4
+#define TASKDELAY 1000000
+#define TASKDELAY_DELTA 100000
+
+int exec_code() {
+
+ int num;
+ struct timespec t;
+
+ HARD_TASK_MODEL m;
+ PID p;
+
+ clear();
+
+ cprintf("Start");
+
+ hard_task_default_model(m);
+ hard_task_def_mit(m,200000 + rand() % 100000);
+ hard_task_def_wcet(m,40000);
+ hard_task_def_group(m,2);
+
+ num = 0;
+
+ while(num < TASKMAX) {
+
+ cprintf(".");
+
+ p = task_create("Instr",ext_call,&m,NULL);
+ if (p == -1) {
+ sys_shutdown_message("Could not create task <instr> ...");
+ exit(1);
+ }
+
+ num++;
+ task_activate(p);
+
+ usleep(TASKDELAY + rand() % TASKDELAY_DELTA);
+
+ }
+
+ do {
+ sys_gettime(&t);
+ } while (t.tv_sec < 12);
+
+ cprintf("End\n");
+
+ return 0;
+
+}
+
+extern unsigned int clk_per_msec;
+
+int main(int argc, char **argv)
+{
+
+ int a,b,c,i;
+ struct timespec t,start,end,diff;
+
+ srand(sys_gettime(NULL));
+
+ a = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
+ b = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_JTN);
+ c = FTrace_chunk_create(1000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
+
+ FTrace_chunk_link(a,b);
+ FTrace_chunk_link(b,c);
+
+ FTrace_actual_chunk_select(a);
+
+ kern_gettime(&start);
+ FTrace_enable();
+
+ TRACER_LOGEVENT(FTrace_EVT_trace_start,proc_table[exec_shadow].context,clk_per_msec);
+
+ for (i=0;i<10;i++)
+ if (proc_table[i].context != 0) TRACER_LOGEVENT(FTrace_EVT_id,
+ (unsigned short int)proc_table[i].context,i);
+
+ exec_code();
+
+ TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
+
+ FTrace_disable();
+ kern_gettime(&end);
+
+ SUBTIMESPEC(&end,&start,&diff);
+
+ printf_xy(1,21,WHITE,"Logged Time %d s %d us",(int)diff.tv_sec,(int)diff.tv_nsec/1000);
+
+ group_kill(2);
+
+ do {
+ sys_gettime(&t);
+ } while (t.tv_sec < 12);
+
+ FTrace_OSD_init_udp(1, "192.168.0.15", "192.168.0.12");
+
+ FTrace_send_chunk(a, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
+
+ return 0;
+
+}
+
Index: tags/rel_1_5_4/newtrace/instr/bezier.c
===================================================================
--- tags/rel_1_5_4/newtrace/instr/bezier.c (nonexistent)
+++ tags/rel_1_5_4/newtrace/instr/bezier.c (revision 1617)
@@ -0,0 +1,127 @@
+
+/*
+ * 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 <tracer.h>
+
+#define PWCET_Automatic_Ipoint(a) TRACER_LOGEVENT(FTrace_EVT_ipoint,(a),0);
+
+/* here are the bezier curves defined
+format:
+{startpoint, endpoint, controlpoint1, controlpoint}
+.
+.
+. */
+int curveno = 20;
+int data[20][4][2] = {
+ {{123,321},{ 23,432},{345,120},{123, 98}},
+ {{567, 31},{ 23, 24},{ 35,421},{123,398}},
+ {{ 0, 21},{623,532},{145,323},{153, 68}},
+ {{253,321},{ 23,432},{745,525},{423,198}},
+ {{123,456},{ 23,482},{ 0,123},{123,128}},
+ {{322, 21},{223,232},{ 45,224},{123,98}},
+ {{423, 32},{123,332},{144,329},{123,98}},
+ {{276, 35},{ 23,492},{476,423},{123,98}},
+ {{783,121},{723,139},{ 78,528},{123,98}},
+ {{723,221},{623, 98},{734,683},{123,98}},
+ {{ 60,421},{523,132},{364,753},{123,98}},
+ {{100,521},{423,432},{633,623},{123,98}},
+ {{ 23,371},{323,599},{343,533},{123,98}},
+ {{123,123},{123, 0},{343,403},{123,98}},
+ {{253,321},{490, 32},{347,393},{123,98}},
+ {{ 68,321},{260,272},{674,283},{123,98}},
+ {{500,321},{245,373},{ 98,173},{123,98}},
+ {{423,321},{198,532},{306, 63},{123,98}},
+ {{197,321},{203,432},{307,443},{123,98}},
+ {{143,321},{293,132},{334,393},{123,98}}
+};
+#define STEPWIDTH 0.01 /* draws 1/STEPWIDTH +1 points between SP and EP */
+#define XSIZE 800
+#define YSIZE 600
+
+char screen[YSIZE][XSIZE];
+int xco[4],yco[4];
+
+int init()
+{
+ int y,x;
+
+ /*initialize screen*/
+ for (x = 0;x < XSIZE;x++) {
+ for (y = 0;y < YSIZE;y++) {
+ screen[y][x] = 255; /*white*/
+ }
+ }
+
+ return 0;
+
+}
+
+void rand_init()
+{
+ int i,j,x,y;
+ for (i=0;i<20;i++)
+ for (j=0;j<4;j++) {
+ x=rand()%800;
+ y=rand()%600;
+ data[i][j][0]=x;
+ data[i][j][1]=y;
+ }
+}
+
+int bezier()
+{
+
+ int i,y,x;
+ float k;
+
+ init();
+
+ for (i = 0;i < curveno;i++) {
+ xco[3] = data[i][0][0];
+ yco[3] = data[i][0][1];
+ xco[2] = 3*(data[i][2][0] - data[i][0][0]);
+ yco[2] = 3*(data[i][2][1] - data[i][0][1]);
+ xco[1] = 3*(data[i][3][0] - data[i][2][0]) - xco[2];
+ yco[1] = 3*(data[i][3][1] - data[i][2][1]) - yco[2];
+ xco[0] = data[i][1][0] - data[i][0][0] - xco[2]- xco[1];
+ yco[0] = data[i][1][1] - data[i][0][1] - yco[2]- yco[1];
+
+ /*scan curve for t = 0 to t = 1 with STEPWIDTH*/
+ for (k = 0;k <=1;k+=STEPWIDTH) { /* PAN_FIXED_LOOP PAN_VARPATH */
+ x = (int)(((float)xco[0]*k*k*k)+((float)xco[1]*k*k)+((float)xco[2]*k)+(float)xco[3]);
+ y = (int)(((float)yco[0]*k*k*k)+((float)yco[1]*k*k)+((float)yco[2]*k)+(float)yco[3]);
+ if ((x < XSIZE)&&(x > 0)&&(y < YSIZE)&&(y > 0)) {
+ /*write dot to screen*/
+ screen[y][x] = 0; /*black*/
+ }
+ }
+ }
+
+ return 0;
+}
+
+int instrumented_function() {
+
+ rand_init();
+
+ bezier();
+
+ return 0;
+}
+
Index: tags/rel_1_5_4/newtrace/instr/bezier_i.c
===================================================================
--- tags/rel_1_5_4/newtrace/instr/bezier_i.c (nonexistent)
+++ tags/rel_1_5_4/newtrace/instr/bezier_i.c (revision 1617)
@@ -0,0 +1,137 @@
+
+/*
+ * 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 <tracer.h>
+
+#define PWCET_Automatic_Ipoint(a) TRACER_LOGEVENT(FTrace_EVT_ipoint,(a),0);
+
+/* here are the bezier curves defined
+format:
+{startpoint, endpoint, controlpoint1, controlpoint}
+.
+.
+. */
+int curveno = 20;
+int data[20][4][2] = {
+ {{123,321},{ 23,432},{345,120},{123, 98}},
+ {{567, 31},{ 23, 24},{ 35,421},{123,398}},
+ {{ 0, 21},{623,532},{145,323},{153, 68}},
+ {{253,321},{ 23,432},{745,525},{423,198}},
+ {{123,456},{ 23,482},{ 0,123},{123,128}},
+ {{322, 21},{223,232},{ 45,224},{123,98}},
+ {{423, 32},{123,332},{144,329},{123,98}},
+ {{276, 35},{ 23,492},{476,423},{123,98}},
+ {{783,121},{723,139},{ 78,528},{123,98}},
+ {{723,221},{623, 98},{734,683},{123,98}},
+ {{ 60,421},{523,132},{364,753},{123,98}},
+ {{100,521},{423,432},{633,623},{123,98}},
+ {{ 23,371},{323,599},{343,533},{123,98}},
+ {{123,123},{123, 0},{343,403},{123,98}},
+ {{253,321},{490, 32},{347,393},{123,98}},
+ {{ 68,321},{260,272},{674,283},{123,98}},
+ {{500,321},{245,373},{ 98,173},{123,98}},
+ {{423,321},{198,532},{306, 63},{123,98}},
+ {{197,321},{203,432},{307,443},{123,98}},
+ {{143,321},{293,132},{334,393},{123,98}}
+};
+#define STEPWIDTH 0.01 /* draws 1/STEPWIDTH +1 points between SP and EP */
+#define XSIZE 800
+#define YSIZE 600
+
+char screen[YSIZE][XSIZE];
+int xco[4],yco[4];
+
+void init()
+{ /*FB1*/PWCET_Automatic_Ipoint( 3157); /*FB2*/{
+ int y,x;
+
+
+ { /*forx1*/for (x = 0; x < XSIZE;x++) { /*forx2*/PWCET_Automatic_Ipoint( 3158); /*forx3*/{
+ { /*forx1*/for (y = 0;y < YSIZE;y++) { /*forx2*/PWCET_Automatic_Ipoint( 3159); /*forx3*/{
+ screen[y][x] = 255;
+ } } /*forx4*/PWCET_Automatic_Ipoint( 3160); /*forx5*/ } /*forx6*/
+ } } /*forx4*/PWCET_Automatic_Ipoint( 3161); /*forx5*/ } /*forx6*/
+
+}PWCET_Automatic_Ipoint( 3162); /*FB3*/} /*FB4*/
+
+void rand_init()
+{ /*FB1*/PWCET_Automatic_Ipoint( 33519); /*FB2*/{
+ int i,j,x,y;
+
+
+
+ { /*forx1*/for (i=0;i<20;i++)
+ { /*forx1*/ { /*forx2*/PWCET_Automatic_Ipoint( 33520); /*forx3*/for (j=0;j<4;j++) { /*forx2*/PWCET_Automatic_Ipoint( 33521); /*forx3*/{
+ x=rand()%XSIZE;
+ y=rand()%YSIZE;
+ data[i][j][0]=x;
+ data[i][j][1]=y;
+ } } /*forx4*/PWCET_Automatic_Ipoint( 33522); /*forx5*/ } /*forx6*/ } /*forx4*/PWCET_Automatic_Ipoint( 33523); /*forx5*/ } /*forx6*/
+
+
+}PWCET_Automatic_Ipoint( 33524); /*FB3*/} /*FB4*/
+
+void pepe(){ /*FB1*/PWCET_Automatic_Ipoint( 64662); /*FB2*/{
+ int a;
+
+ a=a+2;
+ }PWCET_Automatic_Ipoint( 64663); /*FB3*/} /*FB4*/
+
+int bezier()
+{ /*FB1*/PWCET_Automatic_Ipoint( 23955); /*FB2*/{
+ int i,y,x;
+ float k;
+ init();
+
+ { /*forx1*/for (i = 0;i < curveno;i++) { /*forx2*/PWCET_Automatic_Ipoint( 23956); /*forx3*/{
+ xco[3] = data[i][0][0];
+ yco[3] = data[i][0][1];
+ xco[2] = 3*(data[i][2][0] - data[i][0][0]);
+ yco[2] = 3*(data[i][2][1] - data[i][0][1]);
+ xco[1] = 3*(data[i][3][0] - data[i][2][0]) - xco[2];
+ yco[1] = 3*(data[i][3][1] - data[i][2][1]) - yco[2];
+ xco[0] = data[i][1][0] - data[i][0][0] - xco[2]- xco[1];
+ yco[0] = data[i][1][1] - data[i][0][1] - yco[2]- yco[1];
+
+
+ { /*forx1*/for (k = 0;k <=1;k+=0.01) { /*forx2*/PWCET_Automatic_Ipoint( 23957); /*forx3*/{
+ x = (int)(((float)xco[0]*k*k*k)+((float)xco[1]*k*k)+((float)xco[2]*k)+(float)xco[3]);
+ y = (int)(((float)yco[0]*k*k*k)+((float)yco[1]*k*k)+((float)yco[2]*k)+(float)yco[3]);
+ if ((x < XSIZE)&&(x > 0)&&(y < YSIZE)&&(y > 0)) { /*if1*/ PWCET_Automatic_Ipoint( 23958); /*if2*/ {
+
+ screen[y][x] = 0;
+ } } /*if3*/ PWCET_Automatic_Ipoint( 23959); /*ifxxx2*/
+ } } /*forx4*/PWCET_Automatic_Ipoint( 23960); /*forx5*/ } /*forx6*/
+ } } /*forx4*/PWCET_Automatic_Ipoint( 23961); /*forx5*/ } /*forx6*/
+ if (1==0) { /*if1*/ PWCET_Automatic_Ipoint( 23962); /*if2*/ {
+ k++;
+ pepe();
+ } } /*if3*/ PWCET_Automatic_Ipoint( 23963); /*ifxxx2*/
+
+
+ { /*returnE1*/PWCET_Automatic_Ipoint( 23964); /*returnE2*/return 0; } /*returnE3*/
+}PWCET_Automatic_Ipoint( 23965); /*FB3*/} /*FB4*/
+
+
+int instrumented_function(){ /*FB1*/PWCET_Automatic_Ipoint( 18549); /*FB2*/{
+
+ rand_init();
+ bezier();
+ { /*returnE1*/PWCET_Automatic_Ipoint( 18550); /*returnE2*/return 0; } /*returnE3*/
+}PWCET_Automatic_Ipoint( 18551); /*FB3*/} /*FB4*/
Index: tags/rel_1_5_4/newtrace/instr/initfile.c
===================================================================
--- tags/rel_1_5_4/newtrace/instr/initfile.c (nonexistent)
+++ tags/rel_1_5_4/newtrace/instr/initfile.c (revision 1617)
@@ -0,0 +1,153 @@
+/*
+ * Project: S.Ha.R.K.
+ *
+ * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
+ *
+ * Authors :
+ * Mauro Marinoni <mauro.marinoni@unipv.it>
+ * Tullio Facchinetti <tullio.facchinetti@unipv.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
+ */
+
+/*
+ * 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 "edf/edf/edf.h"
+#include "cbs/cbs/cbs.h"
+#include "rr/rr/rr.h"
+#include "dummy/dummy/dummy.h"
+#include "intdrive/intdrive/intdrive.h"
+
+#include "sem/sem/sem.h"
+#include "hartport/hartport/hartport.h"
+
+#include <drivers/shark_linuxc26.h>
+#include <drivers/shark_pci26.h>
+#include <drivers/shark_input26.h>
+#include <drivers/shark_keyb26.h>
+
+/*+ sysyem tick in us +*/
+#define TICK 0
+
+/*+ RR tick in us +*/
+#define RRTICK 10000
+
+/*+ Interrupt Server +*/
+#define INTDRIVE_Q 1000
+#define INTDRIVE_U 0.1*MAX_BANDWIDTH
+#define INTDRIVE_FLAG 0
+
+void call_shutdown_task(void *arg);
+int device_drivers_init();
+int device_drivers_close();
+void set_shutdown_task();
+TASK shutdown_task_body(void *arg);
+
+PID shutdown_task_PID = 1;
+
+TIME __kernel_register_levels__(void *arg)
+{
+ struct multiboot_info *mb = (struct multiboot_info *)arg;
+ LEVEL EDF_level;
+
+ INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
+ EDF_level = EDF_register_level(EDF_ENABLE_ALL);
+ CBS_register_level(CBS_ENABLE_ALL, EDF_level);
+ RR_register_level(RRTICK, RR_MAIN_YES, mb);
+ dummy_register_level();
+
+ SEM_register_module();
+
+ return TICK;
+}
+
+int device_drivers_close() {
+
+ return 0;
+
+}
+
+int device_drivers_init() {
+
+ LINUXC26_register_module(TRUE);
+ PCI26_init();
+
+ return 0;
+}
+
+TASK shutdown_task_body(void *arg) {
+
+ device_drivers_close();
+ sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
+
+ return NULL;
+}
+
+#define SHUTDOWN_TIMEOUT_SEC 3
+
+void set_shutdown_task() {
+
+ NRT_TASK_MODEL nrt;
+
+ nrt_task_default_model(nrt);
+ nrt_task_def_system(nrt);
+
+ shutdown_task_PID = task_create("Shutdown Task", shutdown_task_body, &nrt, NULL);
+ if (shutdown_task_PID == NIL) {
+ sys_shutdown_message("Error: Cannot create shutdown task\n");
+ exit(1);
+ }
+
+}
+
+void call_shutdown_task(void *arg) {
+
+ struct timespec t;
+
+ sys_gettime(&t);
+ t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
+
+ /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
+ kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
+
+ task_activate(shutdown_task_PID);
+}
+
+TASK __init__(void *arg)
+{
+ struct multiboot_info *mb = (struct multiboot_info *)arg;
+
+ HARTPORT_init();
+
+ set_shutdown_task();
+
+ device_drivers_init();
+
+ sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
+
+ __call_main__(mb);
+
+ return (void *)0;
+}
Index: tags/rel_1_5_4/newtrace/instr/makefile
===================================================================
--- tags/rel_1_5_4/newtrace/instr/makefile (nonexistent)
+++ tags/rel_1_5_4/newtrace/instr/makefile (revision 1617)
@@ -0,0 +1,17 @@
+#
+#
+#
+
+ifndef BASE
+BASE=../../..
+endif
+include $(BASE)/config/config.mk
+
+PROGS = instr
+
+include $(BASE)/config/example.mk
+
+instr:
+ make -f $(SUBMAKE) BASE=$(BASE) APP=instr INIT= OTHEROBJS="initfile.o bezier.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __NET__"
+ #make -f $(SUBMAKE) BASE=$(BASE) APP=instr INIT= OTHEROBJS="initfile.o bezier_i.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __NET__
+
Index: tags/rel_1_5_4/newtrace/utils/udpdump.c
===================================================================
--- tags/rel_1_5_4/newtrace/utils/udpdump.c (nonexistent)
+++ tags/rel_1_5_4/newtrace/utils/udpdump.c (revision 1617)
@@ -0,0 +1,151 @@
+/*
+ * Project: S.Ha.R.K.
+ *
+ * Coordinators:
+ * Giorgio Buttazzo <giorgio@sssup.it>
+ * Paolo Gai <pj@gandalf.sssup.it>
+ *
+ * Authors :
+ * Giacomo Guidi <giacomo@gandalf.sssup.it>
+ *
+ * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
+ *
+ * http://www.sssup.it
+ * http://retis.sssup.it
+ * http://shark.sssup.it
+ */
+
+/*
+ * 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 <netinet/in.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <unistd.h>/* close() */
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+
+#define SERVER_PORT 20000
+#define MAX_MSG 10000
+
+struct tracer_udp_header {
+ char id[12];
+ unsigned int pkt_number;
+ unsigned int events;
+ unsigned int size;
+};
+
+FILE *output_file;
+
+int miss;
+
+void close_and_exit()
+{
+
+ printf("Closing...\n");
+
+ if (miss == 1) printf("Possible error receiving packets !\n");
+
+ fclose(output_file);
+
+ exit(0);
+
+}
+
+int main(int argc, char *argv[])
+{
+ int sd, rc, n, cliLen,count;
+ struct sockaddr_in cliAddr, servAddr;
+ char msg[MAX_MSG];
+
+ struct tracer_udp_header *pkt_head = (struct tracer_udp_header *)(msg);
+
+ if (argc < 2) {
+ printf("%s: Enter the output file name [%s filename]\n",argv[0],argv[0]);
+ exit(1);
+ }
+
+ // socket creation
+ sd = socket(AF_INET, SOCK_DGRAM, 0);
+ if(sd < 0) {
+ printf("%s: cannot open socket \n",argv[0]);
+ exit(1);
+ }
+
+ output_file = fopen(argv[1],"w+b");
+ if (output_file == NULL) {
+ printf("%s: Cannot open the file\n",argv[0]);
+ exit(1);
+ }
+
+ // bind local server port
+ servAddr.sin_family = AF_INET;
+
+ servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ servAddr.sin_port = htons(SERVER_PORT);
+
+ rc = bind (sd, (struct sockaddr *)&servAddr,sizeof(servAddr));
+ if(rc < 0) {
+ printf("%s: cannot bind port number %d \n",
+ argv[0], SERVER_PORT);
+ exit(1);
+ }
+
+ signal(SIGINT, close_and_exit);
+
+ count = 1;
+ miss = 0;
+
+ while(1) {
+
+ printf("Wait packet...\n");
+
+ // receive message
+ cliLen = sizeof(cliAddr);
+ n = recvfrom(sd, msg, MAX_MSG, 0,(struct sockaddr *)&cliAddr, &cliLen);
+
+ if (strncmp(pkt_head->id,"TRACER",6)) continue;
+
+ printf("Received %d, length %d(%d), %d tracer events.\n",
+ pkt_head->pkt_number, n, pkt_head->size, pkt_head->events);
+
+ if (pkt_head->pkt_number != count) {
+ printf("Miss Packet !!!\n");
+ miss = 1;
+ }
+
+ if (n > 0) {
+
+ count++;
+
+ fwrite((void *)(msg+sizeof(struct tracer_udp_header)),n-sizeof(struct tracer_udp_header),1,output_file);
+
+ }
+
+ }
+
+ fclose(output_file);
+
+ return 0;
+
+}
+
Index: tags/rel_1_5_4/newtrace/utils/extract.c
===================================================================
--- tags/rel_1_5_4/newtrace/utils/extract.c (nonexistent)
+++ tags/rel_1_5_4/newtrace/utils/extract.c (revision 1617)
@@ -0,0 +1,1131 @@
+
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <unistd.h>
+#include <string.h>
+
+#define MAXCONTEXT 100
+#define MAXJOB 300000
+
+#define INT_CTX 1
+#define INT_PID 9999
+#define PID_NO_DEF -1
+#define SERVER_NO_DEF -1
+
+#define BACKGROUND 0
+#define PERIODICAL 1
+#define INTERRUPT 2
+
+#define DRAW_NUM 1000
+
+#define DISABLE_PLOT
+
+struct ctx_exec {
+ int ctx;
+ unsigned long long dtsc;
+ unsigned long long dnsec;
+ unsigned long long tsc_start;
+ unsigned long long nsec_start;
+};
+
+struct ctx_to_pid {
+ int ctx;
+ int pid;
+};
+
+struct ctx_server {
+ int ctx;
+ int server_id;
+
+};
+
+struct task_event {
+ int ctx;
+ unsigned long long tsc;
+ unsigned long long nsec;
+};
+
+struct server_event {
+ int server_id;
+ unsigned long long tsc;
+ unsigned long long nsec;
+};
+
+void Error(int num, int line) {
+ printf("Finite-State machine error %d at line %d\n",num,line);
+ exit(2);
+}
+
+int context_total = 0,endcycle_total = 0,job_total = 0,exec_total = 0;
+struct ctx_exec *exec_list;
+struct ctx_to_pid *context_list;
+struct task_event *endcycle_list;
+struct task_event *deadline_miss_list;
+struct task_event *wcet_miss_list;
+struct task_event *act_list;
+struct ctx_exec *job_list;
+struct ctx_server *ctx_server_list;
+
+int server_exec_total = 0, server_end_total=0, server_act_total=0, ctx_server_total = 0, server_total=0;
+struct server_event *act_server_list;
+struct server_event *server_budget_end_list;
+
+int deadline_miss = 0, wcet_miss = 0, act_total = 0;
+
+unsigned int clk_per_msec = 0;
+unsigned int skip_clk_per_msec = 0;
+
+unsigned long long log_start_tsc = 0;
+unsigned long long log_end_tsc = 0;
+unsigned long long total_tsc = 0;
+unsigned long long total_nsec = 0;
+
+/* Data for gnuplot external call */
+int draw_data[DRAW_NUM+1];
+
+int gnuplot_clear() {
+
+ int i;
+
+ for (i=0;i<DRAW_NUM;i++)
+ draw_data[i] = 0;
+
+ return 0;
+
+}
+
+int gnuplot_draw(char *title,unsigned long long max_limit,int type) {
+
+#ifndef DISABLE_PLOT
+
+ FILE *gnuplot_data, *gnuplot_command;
+ char temp_name[30];
+ int i,pid,*current_mem;
+
+ current_mem = malloc(sizeof(int)*(DRAW_NUM+1));
+ memcpy(current_mem,draw_data,sizeof(int)*(DRAW_NUM+1));
+
+ pid = fork();
+ if (pid == 0) {
+
+ srand(getpid());
+
+ sprintf(temp_name,"/tmp/pwcet%d",rand()%10000);
+
+ gnuplot_data = fopen(temp_name,"w");
+ gnuplot_command = popen("gnuplot -persist","w");
+
+ for (i=0;i<DRAW_NUM;i++)
+ fprintf(gnuplot_data,"%f\t%f\n",(double)i * (double)max_limit / (double)DRAW_NUM / 1000.0,(float)(current_mem[i]));
+
+ fflush(gnuplot_data);
+ fclose(gnuplot_data);
+
+ fprintf(gnuplot_command,"set xlabel \"Time [us]\"\n");
+ if (type == 0) {
+ fprintf(gnuplot_command,"set ylabel \"Frequency [#]\"\n");
+
+ fprintf(gnuplot_command,"plot \"%s\" using 1:2 title \"%s\" with lines\n",temp_name,title);
+ fflush(gnuplot_command);
+ } else {
+ fprintf(gnuplot_command,"set ylabel \"Time [us]\"\n");
+
+ fprintf(gnuplot_command,"plot \"%s\" using 1:2 title \"%s\" with lines\n",temp_name,title);
+ fflush(gnuplot_command);
+ }
+
+ pclose(gnuplot_command);
+ exit(0);
+
+ }
+
+#endif
+
+ return 0;
+
+}
+
+int stats_from_execs(int ctx_num, unsigned long long *tot_nsec,
+ unsigned long long *min_nsec,
+ unsigned long long *mean_nsec,
+ unsigned long long *max_nsec,
+ unsigned long long *first_nsec,
+ int *number) {
+
+ unsigned long long temp_nsec;
+ int k,i;
+
+ temp_nsec = 0;
+ *max_nsec = 0;
+ *mean_nsec = 0;
+ *min_nsec = 0xFFFFFFFF;
+ *first_nsec = 0;
+ k = 0;
+ for (i=0;i<exec_total;i++)
+ if (exec_list[i].ctx == context_list[ctx_num].ctx) {
+ if (*first_nsec == 0) *first_nsec = exec_list[i].nsec_start;
+ if (exec_list[i].dnsec > *max_nsec) *max_nsec = exec_list[i].dnsec;
+ if (exec_list[i].dnsec < *min_nsec) *min_nsec = exec_list[i].dnsec;
+ temp_nsec += exec_list[i].dnsec;
+ k++;
+ }
+
+ *number = k;
+ *tot_nsec = temp_nsec;
+ if (k != 0) *mean_nsec = temp_nsec / k;
+
+ return 0;
+
+}
+
+int stats_from_jobs(int ctx_num, unsigned long long *tot_nsec,
+ unsigned long long *min_nsec,
+ unsigned long long *mean_nsec,
+ unsigned long long *max_nsec,
+ unsigned long long *first_nsec,
+ int *number) {
+
+ unsigned long long temp_nsec;
+ int k,i;
+
+ temp_nsec = 0;
+ *max_nsec = 0;
+ *mean_nsec = 0;
+ *min_nsec = 0xFFFFFFFF;
+ *first_nsec = 0;
+ k = 0;
+ for (i=0;i<job_total;i++)
+ if (job_list[i].ctx == context_list[ctx_num].ctx) {
+ if (*first_nsec == 0) *first_nsec = job_list[i].nsec_start;
+ if (job_list[i].dnsec > *max_nsec) *max_nsec = job_list[i].dnsec;
+ if (job_list[i].dnsec < *min_nsec) *min_nsec = job_list[i].dnsec;
+ temp_nsec += job_list[i].dnsec;
+ k++;
+ }
+
+ *number = k;
+ *tot_nsec = temp_nsec;
+ if (k != 0) *mean_nsec = temp_nsec / k;
+
+ return 0;
+
+}
+
+int arr_stats_from_execs(int ctx_num, unsigned long long *min_nsec,
+ unsigned long long *mean_nsec,
+ unsigned long long *max_nsec) {
+
+ unsigned long long last_start,temp_nsec,delta_start;
+ int i,k;
+
+ last_start = 0;
+ temp_nsec = 0;
+ *max_nsec = 0;
+ *min_nsec = 0xFFFFFFFF;
+ *mean_nsec = 0;
+ k = 0;
+ for (i=0;i<exec_total;i++)
+ if (exec_list[i].ctx == context_list[ctx_num].ctx) {
+ if (last_start == 0) {
+ last_start = exec_list[i].nsec_start;
+ } else {
+ delta_start = exec_list[i].nsec_start - last_start;
+ if (delta_start > *max_nsec) *max_nsec = delta_start;
+ if (delta_start < *min_nsec) *min_nsec = delta_start;
+ temp_nsec += delta_start;
+ k++;
+ last_start = exec_list[i].nsec_start;
+ }
+ }
+
+ if (k != 0) *mean_nsec = temp_nsec / k;
+
+ return 0;
+
+}
+
+int arr_stats_from_jobs(int ctx_num, unsigned long long *min_nsec,
+ unsigned long long *mean_nsec,
+ unsigned long long *max_nsec) {
+
+ unsigned long long last_start,temp_nsec,delta_start;
+ int i,k;
+
+ last_start = 0;
+ temp_nsec = 0;
+ *max_nsec = 0;
+ *min_nsec = 0xFFFFFFFF;
+ *mean_nsec = 0;
+ k = 0;
+ for (i=0;i<job_total;i++)
+ if (job_list[i].ctx == context_list[ctx_num].ctx) {
+ if (last_start == 0) {
+ last_start = job_list[i].nsec_start;
+ } else {
+ delta_start = job_list[i].nsec_start - last_start;
+ if (delta_start > *max_nsec) *max_nsec = delta_start;
+ if (delta_start < *min_nsec) *min_nsec = delta_start;
+ temp_nsec += delta_start;
+ k++;
+ last_start = job_list[i].nsec_start;
+ }
+ }
+
+ if (k != 0) *mean_nsec = temp_nsec / k;
+
+ return 0;
+
+}
+
+int plot_exec_demand_function(int ctx_num, char *pidstr) {
+
+ unsigned long long max_limit;
+ char tmpstr[50];
+ int i;
+
+ gnuplot_clear();
+
+ max_limit = total_nsec;
+
+ for (i=0;i<exec_total;i++)
+ if (exec_list[i].ctx == context_list[ctx_num].ctx) {
+ int h1,h2,h3;
+
+ h1 = exec_list[i].nsec_start * DRAW_NUM / max_limit;
+ h2 = (exec_list[i].nsec_start+exec_list[i].dnsec) * DRAW_NUM / max_limit;
+ for (h3=h1;h3<h2;h3++)
+ if (h3 <= DRAW_NUM) draw_data[h3] += exec_list[i].dnsec/1000*(h3-h1)/(h2-h1);
+ for (h3=h2;h3<=DRAW_NUM;h3++)
+ if (h3 <= DRAW_NUM) draw_data[h3] += exec_list[i].dnsec/1000;
+
+ }
+
+ sprintf(tmpstr,"Ctx [%d:%s] Demand-Function",context_list[ctx_num].ctx,pidstr);
+ gnuplot_draw(tmpstr,max_limit,1);
+
+ return 0;
+
+}
+
+int plot_exec_c_distrib(int ctx_num, unsigned long long max_nsec, char *pidstr) {
+
+ unsigned long long max_limit;
+ char tmpstr[50];
+ int i,h;
+
+ if (max_nsec == 0) return 0;
+
+ gnuplot_clear();
+
+ max_limit = max_nsec;
+
+ for (i=0;i<exec_total;i++)
+ if (exec_list[i].ctx == context_list[ctx_num].ctx) {
+ h = exec_list[i].dnsec * DRAW_NUM / max_limit;
+ if (h <= DRAW_NUM) draw_data[h]++;
+ }
+
+ sprintf(tmpstr,"Ctx [%d:%s] Exec C-dist",context_list[ctx_num].ctx,pidstr);
+ gnuplot_draw(tmpstr,max_limit,0);
+
+ return 0;
+
+}
+
+int plot_job_c_distrib(int ctx_num, unsigned long long max_nsec, char *pidstr) {
+
+ unsigned long long max_limit;
+ char tmpstr[50];
+ int i,h;
+
+ if (max_nsec == 0) return 0;
+
+ gnuplot_clear();
+
+ max_limit = max_nsec;
+
+ for (i=0;i<job_total;i++)
+ if (job_list[i].ctx == context_list[ctx_num].ctx) {
+ h = job_list[i].dnsec * DRAW_NUM / max_limit;
+ if (h <= DRAW_NUM) draw_data[h]++;
+ }
+
+ sprintf(tmpstr,"Ctx [%d:%s] Job C-dist",context_list[ctx_num].ctx,pidstr);
+ gnuplot_draw(tmpstr,max_limit,0);
+
+ return 0;
+
+}
+
+int plot_exec_arr_distrib(int ctx_num, unsigned long long max_nsec, char *pidstr) {
+
+ unsigned long long max_limit,last_start,delta_start;
+ char tmpstr[50];
+ int i,h;
+
+ if (max_nsec == 0) return 0;
+
+ gnuplot_clear();
+
+ max_limit = max_nsec;
+
+ last_start = 0;
+ for (i=0;i<exec_total;i++)
+ if (exec_list[i].ctx == context_list[ctx_num].ctx) {
+ if (last_start == 0) {
+ last_start = exec_list[i].nsec_start;
+ } else {
+ delta_start = exec_list[i].nsec_start - last_start;
+
+ h = delta_start * DRAW_NUM / max_limit;
+ if (h <= DRAW_NUM) draw_data[h]++;
+
+ last_start = exec_list[i].nsec_start;
+ }
+ }
+
+ sprintf(tmpstr,"Ctx [%d:%s] Exec Arr.Delta",context_list[ctx_num].ctx,pidstr);
+ gnuplot_draw(tmpstr,max_limit,0);
+
+ return 0;
+
+}
+
+int plot_job_arr_distrib(int ctx_num, unsigned long long max_nsec, char *pidstr) {
+
+ unsigned long long max_limit,last_start,delta_start;
+ char tmpstr[50];
+ int i,h;
+
+ if (max_nsec == 0) return 0;
+
+ gnuplot_clear();
+
+ max_limit = max_nsec;
+
+ last_start = 0;
+ for (i=0;i<job_total;i++)
+ if (job_list[i].ctx == context_list[ctx_num].ctx) {
+ if (last_start == 0) {
+ last_start = job_list[i].nsec_start;
+ } else {
+ delta_start = job_list[i].nsec_start - last_start;
+
+ h = delta_start * DRAW_NUM / max_limit;
+ if (h <= DRAW_NUM) draw_data[h]++;
+
+ last_start = job_list[i].nsec_start;
+ }
+ }
+
+ sprintf(tmpstr,"Ctx [%d:%s] Job Arr.Delta",context_list[ctx_num].ctx,pidstr);
+ gnuplot_draw(tmpstr,max_limit,0);
+
+ return 0;
+
+}
+
+int create_lists(char *filename) {
+
+ FILE *input_file;
+
+ int type,par1,par2,k,i,state;
+
+ int current_context = 0;
+ int current_exec = 0;
+ int current_endcycle = 0;
+
+ int kill_delta = 0;
+
+ unsigned long long last_tsc, tsc;
+ unsigned long long current_nsec = 0;
+
+ input_file = fopen(filename,"r");
+
+ /* Memory alloc */
+ exec_list = malloc(sizeof(struct ctx_exec) * MAXJOB);
+ context_list = malloc(sizeof(struct ctx_to_pid) * MAXCONTEXT);
+ ctx_server_list = malloc(sizeof(struct ctx_server) * MAXCONTEXT);
+
+ endcycle_list = malloc(sizeof(struct task_event) * MAXJOB);
+ deadline_miss_list = malloc(sizeof(struct task_event) * MAXJOB);
+ wcet_miss_list = malloc(sizeof(struct task_event) * MAXJOB);
+ act_list = malloc(sizeof(struct task_event) * MAXJOB);
+
+ act_server_list = malloc(sizeof(struct server_event) * MAXJOB );
+ server_budget_end_list = malloc(sizeof(struct server_event) * MAXJOB);
+
+
+ /* Finite-State machine
+ *
+ * FS-Machine states:
+
+ 0 - Start
+ 1 - Context running
+ 2 - Interrupt running
+
+ 10 - End
+
+ */
+
+ for(i=0;i<MAXCONTEXT;i++) {
+ context_list[i].ctx = 0;
+ context_list[i].pid = PID_NO_DEF;
+ }
+
+ for(i=0; i<MAXCONTEXT; i++) {
+ ctx_server_list[i].ctx=0;
+ ctx_server_list[i].server_id=SERVER_NO_DEF;
+
+ }