/demos/tags/rel_1_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_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.8 2004-05-23 19:30:33 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.8 $ |
Last update: $Date: 2004-05-23 19:30:33 $ |
------------ |
*/ |
/* |
* 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"); |
sys_end(); |
} |
task_activate(pid); |
} |
c = keyb_getch(BLOCK); |
} while (c != ESC); |
sys_end(); |
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_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> |
* (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 "modules/intdrive.h" |
#include "modules/edf.h" |
#include "modules/hardcbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/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_T 10000 |
#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_T,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(); |
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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
int res; |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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(); |
sys_end(); |
} |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_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_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_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_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.6 2004-05-23 11:15:29 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.6 $ |
Last update: $Date: 2004-05-23 11:15:29 $ |
------------ |
*/ |
/* |
* 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() |
{ |
sys_end(); |
} |
/*--------------------------------------------------------------*/ |
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); |
} |
sys_end(); |
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_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> |
* (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 "modules/intdrive.h" |
#include "modules/edf.h" |
#include "modules/hardcbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/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_T 10000 |
#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_T,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(); |
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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
int res; |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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(); |
sys_end(); |
} |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_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_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_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_X; |
k.ascii = 'x'; |
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; |
sys_end(); |
} |
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; |
sys_end(); |
} |
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; |
sys_end(); |
} |
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); |
sys_end(); |
} |
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-X 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_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 <modules/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_X; |
k.ascii = 'x'; |
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; |
sys_end(); |
} |
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; |
sys_end(); |
} |
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; |
sys_end(); |
} |
if(!reMap()){ |
sys = 21; |
sys_end(); |
} |
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); |
sys_end(); |
} |
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-X 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_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> |
* (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 "modules/intdrive.h" |
#include "modules/edf.h" |
#include "modules/hardcbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/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_T 10000 |
#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_T,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(); |
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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
int res; |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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(); |
sys_end(); |
} |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_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_X; |
k.ascii = 'x'; |
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; |
sys_end(); |
} |
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; |
sys_end(); |
} |
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; |
sys_end(); |
} |
hard_task_def_arg(gating, (void *)C1); |
if( (c1_gate_pid = task_create("C1 Gate task", gate_body, &gating, NULL)) == NIL ){ |
sys = 22; |
sys_end(); |
} |
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-X 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); |
sys_end(); |
} |
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_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_X; |
k.ascii = 'x'; |
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; |
sys_end(); |
} |
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; |
sys_end(); |
} |
//Check if a NI board is on PCI bus |
if(!reMap()){ |
sys = 11; |
sys_end(); |
} |
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-X 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); |
sys_end(); |
} |
/* |
* 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_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_X; |
k.ascii = 'x'; |
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; |
sys_end(); |
} |
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; |
sys_end(); |
} |
if(!reMap()){ |
sys = 21; |
sys_end(); |
} |
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, show_aper_pid, FALSE); |
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-X 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); |
sys_end(); |
} |
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_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; |
sys_end(); |
} |
//Look for a National board on PCI bus |
if(!reMap()){ |
system = 21; |
sys_end(); |
} |
//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); |
sys_end(); |
} |
/*end of file: test_ppi.c*/ |
/demos/tags/rel_1_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_X; |
k.ascii = 'x'; |
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; |
sys_end(); |
} |
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; |
sys_end(); |
} |
if(!reMap()){ |
sys = 21; |
sys_end(); |
} |
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-X 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); |
sys_end(); |
} |
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_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; |
sys_end(); |
} |
//Look for a National board on PCI bus |
if(!reMap()){ |
system = 21; |
sys_end(); |
} |
//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); |
sys_end(); |
} |
/demos/tags/rel_1_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_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_4/base/fly.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 |
*/ |
/** |
------------ |
CVS : $Id: fly.c,v 1.9 2004-06-15 14:10:23 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.9 $ |
Last update: $Date: 2004-06-15 14:10:23 $ |
------------ |
**/ |
/* |
* 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 <modules/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>"); |
sys_end(); |
return 0; |
} |
task_activate(pid); |
i++; |
} |
c = keyb_getch(BLOCK); |
} while (c != ESC); |
sys_end(); |
return 0; |
} |
/*--------------------------------------------------------------*/ |
/demos/tags/rel_1_4/base/initfile.c |
---|
0,0 → 1,164 |
/* |
* 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 |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/intdrive.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/pi.h" |
#include "modules/pc.h" |
#include "modules/srp.h" |
#include "modules/npp.h" |
#include "modules/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_T 10000 |
#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_T,INTDRIVE_FLAG); |
EDF_register_level(EDF_ENABLE_ALL); |
CBS_register_level(CBS_ENABLE_ALL, 1); |
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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_4/base/iaster4.c |
---|
0,0 → 1,182 |
/* |
* 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 "modules/intdrive.h" |
#include "modules/edf.h" |
#include "modules/rr.h" |
#include "modules/tbs.h" |
#include "modules/cbs.h" |
#include "modules/rrsoft.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.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_T 10000 |
#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; |
INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG); |
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, 1); |
dummy_register_level(); |
SEM_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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_4/base/iaster6.c |
---|
0,0 → 1,226 |
/* |
* 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.4 2004-05-24 17:20:44 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.4 $ |
Last update: $Date: 2004-05-24 17:20:44 $ |
------------ |
System initialization file |
h3pips.c |
These functions register the following levels: |
an EDF (Earliest Deadline First) level |
a RR (Round Robin) level |
a CBS (Costant Bandwidth Server) level |
a PS (Polling Server) level |
a Dummy level |
It can accept these task models: |
HARD_TASK_MODEL (wcet+mit) at level 0 |
NRT_TASK_MODEL at level 1 |
SOFT_TASK_MODEL (met, period) at level 2 |
SOFT_TASK_MODEL (periodicity=APERIODIC) at level 3 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#include "kernel/kern.h" |
#include "modules/intdrive.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/ps.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "modules/pi.h" |
#include "modules/pc.h" |
#include "modules/srp.h" |
#include "modules/npp.h" |
#include "modules/nop.h" |
#include <drivers/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_T 10000 |
#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_T,INTDRIVE_FLAG); |
EDF_register_level(EDF_ENABLE_ALL); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
CBS_register_level(CBS_ENABLE_ALL, 1); |
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; |
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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_4/base/iaster7.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 |
*/ |
/** |
------------ |
CVS : $Id: iaster7.c,v 1.4 2004-05-24 17:20:45 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.4 $ |
Last update: $Date: 2004-05-24 17:20:45 $ |
------------ |
System initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register a set of scheduling modules, in a fixed or |
dynamic priority way... |
It can accept these task models: |
HARD_TASK_MODEL (wcet+mit) at level 0 |
SOFT_TASK_MODEL (periodicity=APERIODIC) at level 1 |
NRT_TASK_MODEL at level 2 |
SOFT_TASK_MODEL (periodicity=APERIODIC, wcet (only if TBS) ) at level 3,4 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#include "kernel/kern.h" |
#include "modules/intdrive.h" |
#include "modules/edf.h" |
#include "modules/tbs.h" |
#include "modules/rm.h" |
#include "modules/rr.h" |
#include "modules/ps.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include <drivers/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_T 10000 |
#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_T,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; |
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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_4/base/iaster8.c |
---|
0,0 → 1,228 |
/* |
* 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.4 2004-05-24 17:20:45 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.4 $ |
Last update: $Date: 2004-05-24 17:20:45 $ |
------------ |
System initialization file |
h3piss.c |
These functions register the following levels: |
an EDF (Earliest Deadline First) level |
a CBS (Costant Bandwidth Server) level |
a SS (Sporadic Server) level |
a RR (Round Robin) level |
a Dummy level |
It can accept these task models: |
HARD_TASK_MODEL (wcet+mit) at level 0 |
SOFT_TASK_MODEL (met, period) at level 1 |
SOFT_TASK_MODEL (periodicity=APERIODIC) at level 2 |
NRT_TASK_MODEL at level 3 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#include "kernel/kern.h" |
#include "modules/intdrive.h" |
#include "modules/rm.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/ss.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "modules/pi.h" |
#include "modules/pc.h" |
#include "modules/srp.h" |
#include "modules/npp.h" |
#include "modules/nop.h" |
#include <drivers/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_T 10000 |
#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_T,INTDRIVE_FLAG); |
EDF_register_level(EDF_ENABLE_ALL); |
CBS_register_level(CBS_ENABLE_ALL, 1); |
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; |
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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_4/base/ipcidemo.c |
---|
0,0 → 1,133 |
/* |
* 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 |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/hardcbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/intdrive.h" |
#include "modules/sem.h" |
#include "modules/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_T 10000 |
#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_T,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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
LINUXC26_register_module(); |
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"); |
sys_abort_shutdown(0); |
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_4/base/makefile |
---|
0,0 → 1,95 |
# |
# |
# |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
PROGS = hello 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 |
hello: |
make -f $(SUBMAKE) APP=hello INIT= OTHEROBJS="ihello.o" OTHERINCL= SHARKOPT= |
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_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.7 2004-04-23 07:57:33 giacomo Exp $ |
*/ |
/*--------------------------------------------------------------*/ |
/* TEST ON CABS */ |
/*--------------------------------------------------------------*/ |
#include <kernel/kern.h> |
#include <modules/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) |
{ |
sys_end(); |
} |
/******************************************************************/ |
/* 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 sys_abort; 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'); |
} |
sys_end(); |
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>"); |
sys_end(); |
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>"); |
sys_end(); |
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_4/base/aster6.c |
---|
0,0 → 1,447 |
/* |
* 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.5 2004-04-21 14:55:05 giacomo Exp $ |
this is a part of the classic Hartik demo Aster. |
it is based on test 17 (h), and the JobControl Task uses an |
SOFT_TASK_MODEL served by a polling server |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include <drivers/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) |
{ |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
PID p1,p2,p3; //,p4,p5,p6; |
HARD_TASK_MODEL m; |
// NRT_TASK_MODEL m_nrt; |
SOFT_TASK_MODEL m_aper; |
SOFT_TASK_MODEL m_soft; |
// int i; |
struct timespec fineprg; |
#ifdef PIMUTEX |
PI_mutexattr_t a; |
#endif |
#ifdef NPPMUTEX |
NPP_mutexattr_t a; |
#endif |
#ifdef NOPMUTEX |
NOP_mutexattr_t a; |
#endif |
KEY_EVT emerg; |
emerg.ascii = 'x'; |
emerg.scan = KEY_X; |
emerg.flag = ALTL_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> ..."); |
sys_end(); |
return 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("test7.c(main): Could not create task <Clock> ..."); |
sys_end(); |
return 0; |
} |
// 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> ..."); |
sys_end(); |
return 0; |
} |
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_4/base/aster7.c |
---|
0,0 → 1,315 |
/* |
* 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.4 2004-04-21 14:55:05 giacomo Exp $ |
this is a part of the classic Hartik demo Aster. |
it is based on test 10(A), and test the PS with RM. |
The JetControl is served by a dedicated Polling Server, too. |
There are APER_MAX tasks sleeping, and when an asteroide task finish |
the current activation, it activate also an aperiodic task chosen |
randomly (if the task chosen is already active, the task_activate do |
nothing!) |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include <drivers/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) |
{ |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
PID p1,p2,p3; //,p4,p5,p6; |
HARD_TASK_MODEL m; |
NRT_TASK_MODEL m_nrt; |
SOFT_TASK_MODEL m_aper; |
int i; |
KEY_EVT emerg; |
clear(); |
cprintf("Press Alt-x to end the demo..."); |
//keyb_set_map(itaMap); |
emerg.ascii = 'x'; |
emerg.scan = KEY_X; |
emerg.flag = ALTL_BIT; |
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> ..."); |
sys_end(); |
return 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("test7.c(main): Could not create task <Clock> ..."); |
sys_end(); |
return 0; |
} |
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> ..."); |
sys_end(); |
return 0; |
} |
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> ..."); |
sys_end(); |
return 0; |
} |
} |
group_activate(1); |
return 0; |
} |
/demos/tags/rel_1_4/base/aster8.c |
---|
0,0 → 1,501 |
/* |
* 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.4 2004-04-21 14:55:05 giacomo Exp $ |
Test for Sporadic Server (ss): |
this is a part of the classic Hartik demo Aster. |
it is based on test 17 (h), and the JobControl Task uses an |
SOFT_TASK_MODEL served by a sporadic server |
There are two "dummy" tasks that increment a counter and print |
the value. One uses a SOFT_TASK_MODEL served by sporadic server, |
the other uses a NRT_TASK_MODEL handled by RR module. |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "modules/ss.h" |
#include <drivers/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) |
{ |
sys_end(); |
} |
void mydummyaper(void) { |
int i=0; |
while(1) { |
mutex_lock(&m1); |
printf_xy(1,24,RED,"dummyAPER pid=%d: %d",p4,i++); |
mutex_unlock(&m1); |
task_activate(p4); |
task_endcycle(); |
} |
} |
void mydummynrt(void) { |
int i=0; |
while(1) { |
mutex_lock(&m1); |
printf_xy(40,24,RED,"dummyNRT pid=%d: %d",p5,i++); |
mutex_unlock(&m1); |
} |
} |
int main(int argc, char **argv) |
{ |
// PID p1,p2,p5; |
HARD_TASK_MODEL m; |
NRT_TASK_MODEL m_nrt; |
SOFT_TASK_MODEL m_aper; |
SOFT_TASK_MODEL m_soft; |
#ifdef PIMUTEX |
PI_mutexattr_t a; |
#endif |
#ifdef PCMUTEX |
PC_mutexattr_t a; |
#endif |
#ifdef NPPMUTEX |
NPP_mutexattr_t a; |
#endif |
#ifdef NOPMUTEX |
NOP_mutexattr_t a; |
#endif |
KEY_EVT emerg; |
emerg.ascii = 'x'; |
emerg.scan = KEY_X; |
emerg.flag = ALTL_BIT; |
emerg.status = KEY_PRESSED; |
keyb_hook(emerg,fine,FALSE); |
clear(); |
cprintf("Press Alt-x to end the demo..."); |
hard_task_default_model(m); |
hard_task_def_mit(m,100000); |
hard_task_def_wcet(m,ASTER_WCET); |
hard_task_def_group(m,1); |
hard_task_def_ctrl_jet(m); |
nrt_task_default_model(m_nrt); |
nrt_task_def_group(m_nrt,1); |
nrt_task_def_ctrl_jet(m_nrt); |
soft_task_default_model(m_aper); |
soft_task_def_group(m_aper,1); |
soft_task_def_ctrl_jet(m_aper); |
soft_task_def_aperiodic(m_aper); |
soft_task_default_model(m_soft); |
soft_task_def_period(m_soft,10000); |
soft_task_def_met(m_soft,JET_WCET); |
soft_task_def_group(m_soft,1); |
soft_task_def_ctrl_jet(m_soft); |
soft_task_def_aperiodic(m_soft); |
p1 = task_create("Aster",aster,&m,NULL); |
if (p1 == -1) { |
sys_shutdown_message("test7.c(main): Could not create task <aster> ..."); |
sys_end(); |
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> ..."); |
sys_end(); |
return 0; |
} |
p3 = task_create("JetControl",jetcontrol,&m_aper,NULL); |
if (p3 == -1) { |
sys_shutdown_message("test7.c(main): Could not create task <JetControl> ..."); |
sys_end(); |
return 0; |
} |
p4 = task_create("MyDummyAper",(void *(*)(void*))mydummyaper,&m_aper,NULL); |
if (p4 == -1) { |
sys_shutdown_message("Could not create task <MyDummyAper> ..."); |
sys_end(); |
return 0; |
} |
p5 = task_create("MyDummyNRT",(void *(*)(void*))mydummynrt,&m_nrt,NULL); |
if (p5 == -1) { |
sys_shutdown_message("Could not create task <MyDummyNRT> ..."); |
sys_end(); |
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_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_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.4 2004-04-19 14:48:04 giacomo Exp $ |
this is a part of the classic Hartik demo Aster. |
It checks: |
- jet functions |
- The EDF level with many task, with almost full bandwidth used |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
int num_aster = 0; |
#define ASTER_LIM 60 |
#define DISPLAY_MAX 15 |
#define ASTER_MAX 70 |
#define STAT_Y 9 |
// first numbers for wcet and periods are for a 486/25, the others for a |
// celeron 366 |
#define PER_WCET 13000 /*6200*/ |
#define CLOCK_WCET 1200 /* 100*/ |
#define ASTER_WCET 1200 /* 100*/ |
#define ASTER_MEAN_PERIOD 64 /*64*/ |
#define END_TEST_TIME 60 |
TASK asteroide(void) |
{ |
int i; |
int y = rand() % 7 + 1; |
int load1,j; |
char s[2]; |
s[0] = '*'; s[1] = 0; |
/*for (;;)*/ { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 1000; //10000; // 5000 + rand()%5000; |
for (j=0; j<load1; j++) { |
s[0] = '*' + rand() % 100; |
puts_xy(i,y,rand()%15+1,s); |
} |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
num_aster--; |
return 0; |
} |
TASK aster() |
{ |
PID p; |
HARD_TASK_MODEL m; |
int r; |
int x; // adaptive bandwidth... |
hard_task_default_model(m); |
hard_task_def_wcet(m,PER_WCET); |
hard_task_def_ctrl_jet(m); |
x = ASTER_MEAN_PERIOD; |
srand(7); |
while (1) { |
if (num_aster < ASTER_MAX) { |
r = (rand() % 200); |
hard_task_def_arg(m,(void *)((rand() % 7)+1)); |
hard_task_def_mit(m, (x+r)*1000); |
p = task_create("aaa",asteroide,&m,NULL); |
if (p == -1) |
{ |
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
printf_xy(62,3,WHITE,"adapt=%3u err=%d", |
iq_query_first(&freedesc),errno); |
} |
else { |
num_aster++; |
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno); |
task_activate(p); |
x /= 2; |
if (x<50) x = 50; |
} |
} |
task_endcycle(); |
} |
} |
TASK clock() |
{ |
int s = 0, m = 0; |
while(1) { |
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(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> ..."); |
sys_end(); |
} |
hard_task_def_mit(m,500000); |
hard_task_def_wcet(m,CLOCK_WCET); |
p2 = task_create("Clock",clock,&m,NULL); |
if (p2 == -1) { |
sys_shutdown_message("test7.c(main): Could not create task <Clock> ..."); |
sys_end(); |
} |
p3 = task_create("JetControl",jetcontrol,&m_nrt,NULL); |
if (p2 == -1) { |
sys_shutdown_message("test7.c(main): Could not create task <JetControl> ..."); |
sys_end(); |
} |
group_activate(1); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < END_TEST_TIME); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_4/base/aster3.c |
---|
0,0 → 1,300 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* |
* CVS : $Id: aster3.c,v 1.5 2004-04-19 14:48:04 giacomo Exp $ |
Test Number 10 (A): |
this is a part of the classic Hartik demo Aster. |
it is based on aster2.c, with the use of TBS to serve a set of aperiodic |
tasks. |
There are APER_MAX tasks sleeping, and when an asteroide task finish |
the current activation, it activate also an aperiodic task chosen |
randomly (if the task chosen is already active, the task_activate do |
nothing!) |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
int num_aster = 0; |
#define ASTER_LIM 60 |
#define DISPLAY_MAX 15 |
#define ASTER_MAX 70 |
#define STAT_Y 9 |
#define APER_MAX 8 |
/* first numbers runs on a pentium 133, second numbers on a celeron 366 */ |
#define PER_WCET 30000 /* 6200 */ |
#define APER_WCET 50000 /* 18400 */ |
#define CLOCK_WCET 1000 /* 200 */ |
#define ASTER_WCET 1000 /* 200 */ |
#define MIN_PERIOD 200 /* 64, in ms */ |
#define APER_REP 22000 |
PID aper_table[APER_MAX]; |
TASK asteroide(void) |
{ |
int i; |
int y = rand() % 7 + 1; |
int load1,j; |
char s[2]; |
s[0] = '*'; s[1] = 0; |
/*for (;;)*/ { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 10000; //8000 + rand()%2000; |
for (j=0; j<load1; j++) { |
s[0] = '*' + rand() % 100; |
puts_xy(i,y,rand()%15+1,s); |
} |
task_activate(aper_table[rand()%APER_MAX]); |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
num_aster--; |
return 0; |
} |
TASK aper_asteroid(void *a) |
{ |
int i; |
int y = rand() % 7 + 1; |
int load1,j; |
int c; |
char s[2]; |
c = (int)a; |
s[0] = '*'; s[1] = 0; |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = APER_REP; //8000 + rand()%2000; |
for (j=0; j<load1; j++) { |
s[0] = '*' + rand() % 100; |
puts_xy(i,y,rand()%15+1,s); |
} |
s[0] = c; |
puts_xy(i,y,rand()%15+1,s); |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK aster() |
{ |
PID p; |
HARD_TASK_MODEL m; |
int r; |
int x; // adaptive bandwidth... |
hard_task_default_model(m); |
hard_task_def_wcet(m,PER_WCET); |
hard_task_def_ctrl_jet(m); |
x = MIN_PERIOD; |
srand(7); |
while (1) { |
if (num_aster < ASTER_MAX) { |
r = (rand() % 200); |
hard_task_def_arg(m,(void *)((rand() % 7)+1)); |
hard_task_def_mit(m, (x+r)*1000); |
p = task_create("aaa",asteroide,&m,NULL); |
if (p == -1) |
{ |
if (x < 500 && errno != ENO_AVAIL_TASK) x += 1; |
printf_xy(62,3,WHITE,"adapt=%3u err=%d", |
iq_query_first(&freedesc),errno); |
} |
else { |
num_aster++; |
printf_xy(62,3,WHITE,"adapt=%3u ",x);//,errno); |
task_activate(p); |
x /= 2; |
if (x<50) x = 50; |
} |
} |
task_endcycle(); |
} |
} |
TASK clock() |
{ |
int s = 0, m = 0; |
while(1) { |
printf_xy(62,1,WHITE,"%2d:%2d ast=%d",m,s, num_aster); |
printf_xy(62,2,WHITE,"U=%12u",EDF_usedbandwidth(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("test7.c(main): Could not create task <aster> ..."); |
sys_end(); |
} |
hard_task_def_mit(m,500000); |
hard_task_def_wcet(m,CLOCK_WCET); |
p2 = task_create("Clock",clock,&m,NULL); |
if (p2 == -1) { |
sys_shutdown_message("test7.c(main): Could not create task <Clock> ..."); |
sys_end(); |
} |
soft_task_default_model(m_aper); |
soft_task_def_wcet(m_aper,APER_WCET); |
soft_task_def_ctrl_jet(m_aper); |
soft_task_def_aperiodic(m_aper); |
soft_task_def_level(m_aper, 3); |
aper_table[0] = task_create("JetControl",jetcontrol,&m_aper,NULL); |
if (aper_table[0] == -1) { |
sys_shutdown_message("test7.c(main): Could not create task <JetControl> ..."); |
sys_end(); |
} |
for (i=1; i<APER_MAX; i++) { |
soft_task_def_level(m_aper, i/4 + 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("test7.c(main): Could not create task <aper> ..."); |
sys_end(); |
} |
} |
group_activate(1); |
{ |
struct timespec t; |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 60); |
} |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_4/base/aster4.c |
---|
0,0 → 1,389 |
/* |
* 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.3 2004-04-19 14:48:04 giacomo Exp $ |
Test Number 13 (D): |
this is a part of the classic Hartik demo Aster, and it is based on aster 3. |
The demo creates: |
- a set of TBS tasks assigned to 2 TBS servers initialized with different bandwidth. |
- a set of periodic tasks, just to make noise (function asteroide) |
- a set of CBS tasks that are created to fill the available free |
bandwidth (function soft_aster) |
- a few service task (the one that creates the CBS tasks (aster), a clock, |
JET info visualization |
- a set of never ending "system tasks" that simulate a device driver |
task that will end only at shutdown (function aper_asteroid) |
- a keyboard task that will execute an hook to terminate the system |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include <drivers/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]; |
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); |
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) |
{ |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
KEY_EVT k; |
PID p1,p2,p3; |
HARD_TASK_MODEL m; |
SOFT_TASK_MODEL m_aper; |
SOFT_TASK_MODEL m_soft; |
int i; |
k.flag = 0; |
k.scan = KEY_ENT; |
k.ascii = 13; |
k.status = KEY_PRESSED; |
keyb_hook(k, endfun, FALSE); |
clear(); |
cprintf("Press ENTER to end the demo..."); |
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> ..."); |
sys_end(); |
return 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> ..."); |
sys_end(); |
return 0; |
} |
p3 = task_create("JetControl",jetcontrol,&m_soft,NULL); |
if (p3 == -1) { |
sys_shutdown_message("aster4.c(main): Could not create task <JetControl> ..."); |
sys_end(); |
return 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> ..."); |
sys_end(); |
return 0; |
} |
} |
group_activate(1); |
return 0; |
} |
/demos/tags/rel_1_4/base/aster5.c |
---|
0,0 → 1,477 |
/* |
* 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.4 2004-04-19 14:48:04 giacomo Exp $ |
this is a part of the classic Hartik demo Aster. |
it is based on test 13 (d), and use the CBS to serve the periodic tasks. |
There are not periodic tasks, only CBS tasks. |
The tasks use a PI, NPP or NOP mutex to access the video memory. |
A flag (LONGSC) is provided to try long and short critical sections. |
This demo is really interesting because you can note the behavior of |
the system, and the differences between the various protocols... |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include <drivers/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) |
{ |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
PID p1,p2,p3;//,p4,p5,p6; |
HARD_TASK_MODEL m; |
// NRT_TASK_MODEL m_nrt; |
SOFT_TASK_MODEL m_aper; |
SOFT_TASK_MODEL m_soft; |
// int i; |
struct timespec fineprg; |
#ifdef PIMUTEX |
PI_mutexattr_t a; |
#endif |
#ifdef NPPMUTEX |
NPP_mutexattr_t a; |
#endif |
#ifdef NOPMUTEX |
NOP_mutexattr_t a; |
#endif |
KEY_EVT emerg; |
emerg.ascii = 'x'; |
emerg.scan = KEY_X; |
emerg.flag = ALTL_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> ..."); |
sys_end(); |
return 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("test7.c(main): Could not create task <Clock> ..."); |
sys_end(); |
return 0; |
} |
// 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> ..."); |
sys_end(); |
return 0; |
} |
/* |
aperiodic_task_default_model(m_aper,APER_WCET); |
aperiodic_task_def_ctrl_jet(m_aper); |
aperiodic_task_def_system(m_aper); |
for (i=0; i<APER_MAX; i++) { |
aperiodic_task_def_level(m_aper, i/4 + 2); |
aperiodic_task_def_arg(m_aper, (i/4 ? 'Û' : '±')); |
aper_table[i] = task_create("aper",aper_asteroid,&m_aper,NULL); |
if (aper_table[i] == -1) { |
perror("test7.c(main): Could not create task <aper> ..."); |
sys_end(); |
l1_exit(-1); |
} |
} |
*/ |
task_nopreempt(); |
#ifdef PIMUTEX |
PI_mutexattr_default(a); |
#endif |
#ifdef NPPMUTEX |
NPP_mutexattr_default(a); |
#endif |
#ifdef NOPMUTEX |
NOP_mutexattr_default(a); |
#endif |
mutex_init(&m1, &a); |
fineprg.tv_sec = 1800; |
fineprg.tv_nsec = 0; |
group_activate(1); |
return 0; |
} |
/demos/tags/rel_1_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.3 2004-04-19 14:48:05 giacomo Exp $ |
**/ |
#include "kernel/kern.h" |
#include "modules/intdrive.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "modules/pi.h" |
#include "modules/pc.h" |
#include "modules/srp.h" |
#include "modules/npp.h" |
#include "modules/nop.h" |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
/*+ Interrupt Server +*/ |
#define INTDRIVE_Q 1000 |
#define INTDRIVE_T 10000 |
#define INTDRIVE_FLAG 0 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,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_4/base/ego.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 |
*/ |
/** |
------------ |
CVS : $Id: ego.c,v 1.6 2004-04-19 14:48:05 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.6 $ |
Last update: $Date: 2004-04-19 14:48:05 $ |
------------ |
**/ |
/* |
* 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) |
{ |
sys_end(); |
} |
/******************************************************************/ |
/* 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 sys_abort; 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 = 'x'; |
emerg.scan = KEY_X; |
emerg.flag = ALTL_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 Alt-X 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>"); |
sys_end(); |
return 0; |
} |
/* 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>"); |
sys_end(); |
return 0; |
} |
/* 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>"); |
sys_end(); |
return 0; |
} |
/* 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_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.3 2004-04-19 14:48:05 giacomo 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"); |
sys_end(); |
} |
soft_task_def_skip_arrivals(m_aper); |
soft_task_def_arg(m_aper, (void *)21); |
p = task_create("skip", periodic, &m_aper, NULL); |
if (p == NIL) |
{ |
sys_shutdown_message("Can't create skip task...\n"); |
sys_end(); |
} |
p = task_create("blocker", blocker, &m, NULL); |
if (p == NIL) |
{ |
sys_shutdown_message("Can't create blocker task...\n"); |
sys_end(); |
} |
cprintf("main : save & skip tasks activated.\n"); |
group_activate(1); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 2); |
cprintf("main : blocker activated.\n"); |
task_activate(p); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 10); |
cprintf("main : End!!!\n"); |
return 0; |
} |
/demos/tags/rel_1_4/base/initgraph.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> |
* (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 "modules/intdrive.h" |
#include "modules/edf.h" |
#include "modules/hardcbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/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_T 10000 |
#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_T,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(); |
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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
int res; |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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(); |
sys_end(); |
} |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_4/base/aster.c |
---|
0,0 → 1,383 |
/* |
* 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.4 2004-04-18 19:46:29 giacomo 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 <modules/sem.h> |
#include <modules/hartport.h> |
#include <modules/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>"); |
sys_abort(-1); |
} |
hard_task_default_model(m_per); |
hard_task_def_mit(m_per,500000); |
hard_task_def_wcet(m_per,1000); |
hard_task_def_group(m_per, 1); |
p2 = task_create("Clock",clock,&m_per,NULL); |
if (p2 == -1) { |
sys_shutdown_message("Aster.C(main): Could not create task <Clock>"); |
sys_end(); |
return 0; |
} |
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>"); |
sys_end(); |
return 0; |
} |
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>"); |
sys_end(); |
return 0; |
} |
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>"); |
sys_end(); |
return 0; |
} |
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"); |
sys_end(); |
return 0; |
} |
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 |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.2 2004-04-17 11:36:14 giacomo 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); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.3 2004-04-17 11:36:12 giacomo 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> ..."); |
sys_end(); |
} |
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> ..."); |
sys_end(); |
} |
group_activate(1); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 10); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.2 2004-04-17 11:36:14 giacomo 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 "modules/srp.h" |
mutex_t m0; |
void startJ(void *a) |
{ |
task_activate((PID)a); |
} |
TASK j1() |
{ |
cprintf("J1: before locking m0\n"); |
mutex_lock(&m0); |
cprintf("J1: locked m0\n"); |
mutex_unlock(&m0); |
cprintf("J1: unlocked m0, end task\n"); |
return 0; |
} |
TASK j2() |
{ |
cprintf("J2: waiting t=1.5 sec\n"); |
while (sys_gettime(NULL) < 1500000); |
cprintf("J2: end task\n"); |
return 0; |
} |
TASK j3() |
{ |
cprintf("J3: before locking m0\n"); |
mutex_lock(&m0); |
cprintf("J3: locked m0, waiting to t=2 sec\n"); |
while (sys_gettime(NULL) < 2000000); |
cprintf("J3: t = 1 sec reached, unlocking m0\n"); |
mutex_unlock(&m0); |
cprintf("J3: unlocked m0, end task\n"); |
return 0; |
} |
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); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.2 2004-04-17 11:36:14 giacomo 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); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.3 2004-04-17 11:36:14 giacomo 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); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.3 2004-04-17 11:36:15 giacomo 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 "modules/srp.h" |
mutex_t m1,m2,m3; |
void startJ(void *a) |
{ |
task_activate((PID)a); |
} |
TASK Jlobby() |
{ |
cprintf("(*) JLobby!!!\n"); |
return 0; |
} |
TASK Jh() |
{ |
PID l; |
HARD_TASK_MODEL m; |
SRP_RES_MODEL r; |
cprintf("JH: creating Jy before locking m3\n"); |
hard_task_default_model(m); |
hard_task_def_mit(m,30000); |
hard_task_def_wcet(m,1000); |
SRP_res_default_model(r,4); |
l = task_create("Jlobby",Jlobby,&m,&r); |
task_activate(l); |
mutex_lock(&m3); |
cprintf("JH: locked m3, locking m1\n"); |
mutex_lock(&m1); |
cprintf("JH: locked m1, unlocking m1\n"); |
mutex_unlock(&m1); |
cprintf("JH: unlocked m1, unlocking m3\n"); |
mutex_unlock(&m3); |
cprintf("JH: unlocked m3, end task\n"); |
return 0; |
} |
TASK Jm() |
{ |
cprintf("JM: before locking m3\n"); |
mutex_lock(&m3); |
cprintf("JM: locked m3, locking m2\n"); |
mutex_lock(&m2); |
cprintf("JM: locked m2, unlocking m2\n"); |
mutex_unlock(&m2); |
cprintf("JM: unlocked m2, unlocking m3\n"); |
mutex_unlock(&m3); |
cprintf("JM: unlocked m3, locking m1\n"); |
mutex_lock(&m1); |
cprintf("JM: locked m1, unlocking m1\n"); |
mutex_unlock(&m1); |
cprintf("JM: unlocked m1, end task\n"); |
return 0; |
} |
TASK Jl() |
{ |
cprintf("JL: before locking m2\n"); |
mutex_lock(&m2); |
cprintf("JL: locked m2, waiting to t=1 sec\n"); |
while (sys_gettime(NULL) < 1000000); |
cprintf("JL: t = 1 sec reached, locking m1\n"); |
mutex_lock(&m1); |
cprintf("JL: locked m1, waiting to t=2 sec\n"); |
while (sys_gettime(NULL) < 2000000); |
cprintf("JL: t = 2 sec reached, unlocking m1\n"); |
mutex_unlock(&m1); |
cprintf("JL: unlocked m1, unlocking m2\n"); |
mutex_unlock(&m2); |
cprintf("JL: unlocked m2, locking m3\n"); |
mutex_lock(&m3); |
cprintf("JL: locked m3, unlocking m3\n"); |
mutex_unlock(&m3); |
cprintf("JL: unlocked m3, end task\n"); |
return 0; |
} |
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); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.2 2004-04-17 11:36:13 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2004-04-17 11:36:13 $ |
------------ |
System initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register the following levels: |
an EDF (Earliest Deadline First) level |
a RR (Round Robin) level |
a TBS (Total Bandwidth Server) level 0.1 Us |
a TBS (Total Bandwidth Server) level 0.3 Us |
a Dummy level |
The TBS bandwidth is TBS_NUM/TBS_DEN |
It can accept these task models (into () the mandatory fields): |
HARD_TASK_MODEL (wcet+mit) at level 0 |
NRT_TASK_MODEL at level 1 |
SOFT_TASK_MODEL (wcet, periodicity=APERIODIC) at level 2,3 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/rr.h" |
#include "modules/tbs.h" |
#include "modules/dummy.h" |
/*+ 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_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_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.3 2004-04-17 11:36:14 giacomo 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); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.2 2004-04-17 11:36:13 giacomo 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); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.2 2004-04-17 11:36:15 giacomo 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); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_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.2 2003-04-15 10:21:22 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2003-04-15 10:21:22 $ |
------------ |
System initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register the following levels: |
an EDF (Earliest Deadline First) level |
a RR (Round Robin) level |
a Dummy level |
It can accept these task models (into () the mandatory fields): |
HARD_TASK_MODEL (wcet+mit) at level 0 |
NRT_TASK_MODEL at level 1 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
/*+ sysyem tick in us +*/ |
#define TICK 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_4/base/sig.c |
---|
0,0 → 1,168 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: sig.c,v 1.3 2003-01-07 17:10:15 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.3 $ |
Last update: $Date: 2003-01-07 17:10:15 $ |
------------ |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
/* |
Test Number 5: |
this test is a simple main() function with one other task |
This test can be useful to test functions like: |
sys_gettime |
sigemptyset |
sigaddset |
hartik_deliver_pending_signals |
sys_end |
task_sigmask |
sigaction |
sigqueue |
task_signal |
*/ |
#include "kernel/kern.h" |
TASK goofy(void *arg) |
{ |
struct timespec t; |
cprintf("Goofy: waiting 2 secs...\n"); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 2); // wait until 2 sec |
cprintf("Goofy: ok, I'm ready :-)\n"); |
return 0; |
} |
void catchit_RT(int signo, siginfo_t *info, void *extra) |
{ |
cprintf("RT signal: Current Running Task = %d signo=%d code=%d value=%d from pid=%d\n", |
exec_shadow, |
info->si_signo, info->si_code, |
info->si_value.sival_int, info->si_task); |
} |
void catchit(int signo) |
{ |
cprintf("RT signal: Current Running Task = %d signo=%d\n", |
exec_shadow, signo); |
} |
int main(int argc, char **argv) |
{ |
struct timespec t; |
NRT_TASK_MODEL m; |
PID p2; |
sigset_t newmask; |
sigset_t oldmask; |
struct sigaction action; |
union sigval sval; |
clear(); |
/* Set the signal action */ |
action.sa_flags = SA_SIGINFO; |
action.sa_sigaction = catchit_RT; |
action.sa_handler = 0; |
action.sa_mask = 0; |
if (sigaction(SIGUSR1, &action, NULL) == -1) { |
perror("Error using sigaction."); |
return -1; |
} |
action.sa_flags = 0; |
action.sa_handler = (void (*)(int))catchit; |
if (sigaction(SIGILL, &action, NULL) == -1) { |
perror("Error using sigaction."); |
return -1; |
} |
/* create another task */ |
nrt_task_default_model(m); |
nrt_task_def_group(m,1); |
p2 = task_create("goofy", goofy, &m, NULL); |
if (p2 == NIL) |
{ |
cprintf("Can't create goofy task...\n"); |
return 1; |
} |
group_activate(1); |
/* block the signal for the main task */ |
sigemptyset(&newmask); |
sigaddset(&newmask,SIGUSR1); |
task_sigmask(SIG_BLOCK, &newmask, &oldmask); // pthread_sigmask |
cprintf("main: Sending 2 signals ...\n"); |
sval.sival_int = 123; |
sigqueue(0,SIGUSR1,sval); |
sval.sival_int = 999; |
sigqueue(0,SIGUSR1,sval); |
cprintf("main: Now sending a signal to myself," |
" then wait until 4 secs...\n"); |
task_signal(0 /* main */, SIGILL); // pthread_kill |
NULL_TIMESPEC(&t); |
do { |
sys_gettime(&t); |
} while (t.tv_sec < 4); // wait until 4 s |
cprintf("main: ending...\n"); |
return 0; |
} |
/demos/tags/rel_1_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.1 2002-11-11 08:22:45 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2002-11-11 08:22:45 $ |
------------ |
The simplest initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register the following levels: |
a RR (Round Robin) level |
a Dummy level |
It can accept these task models: |
NRT_TASK_MODEL at level 0 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#include "kernel/kern.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
/*+ sysyem tick in us +*/ |
#define TICK 300 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
SEM_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
__call_main__(mb); |
return (void *)0; |
} |
/demos/tags/rel_1_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.1 2002-10-28 08:13:37 pj Exp $ |
* |
* Timer correctness test |
*/ |
#include "kernel/kern.h" |
#define NT 10 |
int main(int argc, char **argv) |
{ |
struct timespec t[NT]; |
int i; |
cprintf("Timer correctness test (1 second).\n"); |
for (i=0; i<NT; i++) NULL_TIMESPEC(&t[i]); |
do { |
for (i=0; i<NT-1; i++) t[i+1] = t[i]; |
sys_gettime(&t[0]); |
if (TIMESPEC_A_LT_B(&t[0],&t[1])) { |
for (i=0; i<NT; i++) |
cprintf("%d %ld\n",i, t[i].tv_nsec); |
sys_end(); |
} |
} while (t[0].tv_sec < 1); |
return 0; |
} |
/demos/tags/rel_1_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_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.1 2002-10-28 08:13:37 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2002-10-28 08:13:37 $ |
------------ |
The simplest initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register the following levels: |
a RR (Round Robin) level |
a Dummy level |
It can accept these task models: |
NRT_TASK_MODEL at level 0 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#include "kernel/kern.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
/*+ sysyem tick in us +*/ |
#define TICK 300 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
__call_main__(mb); |
return (void *)0; |
} |
/demos/tags/rel_1_4/readme.txt |
---|
0,0 → 1,7 |
Hi, these are the S.Ha.R.K. demos... |
the old examples directory is now called demos/oldexamples... |
Enjoy |
PJ |
/demos/tags/rel_1_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_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_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_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.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 "modules/rr.h" |
#include "modules/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_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_4/bttvdemo/bttv.c |
---|
0,0 → 1,340 |
/* |
* 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 |
*/ |
/* |
* Copyright (C) 2003 Giacomo Guidi |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
*/ |
#include "kernel/kern.h" |
#include "stdlib.h" |
#include "unistd.h" |
#include "drivers/shark_keyb26.h" |
#include "drivers/shark_videodev26.h" |
#include "drivers/shark_fb26.h" |
#include "tracer.h" |
#define WIDTH 640 |
#define HEIGHT 480 |
#define BYTES_PP 2 |
//#define COLOR |
#define MAX_SPEED |
#define FRAME_GRABBER_NUMBER 0 |
#define FG_PERIOD 40000 //ONLY IF MAX_SPEED IS DISABLED |
#define FG_WCET 30000 |
#define FG_W 320 |
#define FG_H 240 |
unsigned int frame_number = 0; |
void program_end(void *arg) |
{ |
sys_end(); |
} |
void elaborate_image(void *imageptr); |
void start_frame_grabber(PID elaborate_task_PID, int channel, struct video_buffer *fbuf) { |
struct video_window win; |
struct video_channel chan; |
struct video_tuner tuner; |
struct video_picture vpic; |
int res; |
/* Init videodev driver */ |
VIDEODEV26_open(FRAME_GRABBER_NUMBER); |
/* Select the input channel */ |
res = VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCGCHAN,(unsigned long)&chan); |
//cprintf("res = %d\n",res); |
chan.channel = channel; |
chan.type = VIDEO_VC_TUNER; |
chan.norm = VIDEO_TYPE_CAMERA; |
res = VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSCHAN,(unsigned long)&chan); |
//cprintf("res = %d\n",res); |
/* Enable the tuner */ |
tuner.tuner = 0; |
tuner.mode = VIDEO_MODE_PAL; |
res = VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSTUNER,(unsigned long)&tuner); |
//cprintf("res = %d\n",res); |
/* Select palette and depth */ |
res = VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCGPICT,(unsigned long)&vpic); |
//cprintf("res = %d\n",res); |
#ifdef COLOR |
vpic.palette = VIDEO_PALETTE_RGB24; |
vpic.depth = 24; |
#else |
vpic.palette = VIDEO_PALETTE_GREY; |
vpic.depth = 8; |
#endif |
vpic.brightness = 35000; |
vpic.hue = 32000; |
vpic.contrast = 32000; |
vpic.colour = 32000; |
res = VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSPICT,(unsigned long)&vpic); |
//cprintf("res = %d\n",res); |
res = VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCGWIN,(unsigned long)&win); |
//cprintf("res = %d\n",res); |
win.x = 0; |
win.y = 0; |
win.width = FG_W; |
win.height = FG_H; |
res = VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSWIN,(unsigned long)&win); |
//cprintf("res = %d\n",res); |
/* Set the buffer */ |
res = VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSFBUF,(unsigned long)(fbuf)); |
//cprintf("res = %d\n",res); |
/* IMPORTANT: Set the aperiodic elaboration task |
* This is a SHARK change on VIDIOCSYNC. When the |
* new frame is ready, the task elaborate_task_PID |
* is activated. Elabortate_task must be aperiodic !! |
* To link the task to BTTV use this function: */ |
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSYNC,(unsigned long)(elaborate_task_PID)); |
} |
/* Check if the frame grabber is ready */ |
volatile int ready_to_grab = 1; |
void grab_command(void *arg) { |
SYS_FLAGS f; |
f = kern_fsave(); |
int on = 1; |
VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCCAPTURE,(unsigned long)&on); |
kern_frestore(f); |
} |
/* Elaboration task, it is called when the frame |
grabber buffer is ready */ |
TASK elaborate_task(void *arg) { |
struct video_buffer *fbuf = (struct video_buffer *)(arg); |
char txt[100]; |
while(1) { |
elaborate_image(fbuf->base); |
//cprintf("E"); |
//Text version |
//printf_xy(1,20,WHITE,"%08x", |
// *(unsigned int *)(fbuf->base+50*320*3+50*3)); |
frame_number++; |
sprintf(txt,"Elapsed Time = %u us Frame = %u",(int)(sys_gettime(NULL)),frame_number); |
grx_text(txt, 10, 250, rgb16(255,255,255), 0); |
ready_to_grab = 1; |
#ifdef MAX_SPEED |
grab_command(NULL); |
#endif |
task_testcancel(); |
task_endcycle(); |
} |
return NULL; |
} |
/* Send the grab command */ |
TASK grab_task(void *arg) { |
while(1) { |
if (ready_to_grab) { |
/* Grab */ |
grab_command(NULL); |
//cprintf("G"); |
ready_to_grab = 0; |
} else { |
//cprintf("S"); |
/* Frame skipped */ |
} |
task_testcancel(); |
task_endcycle(); |
} |
return NULL; |
} |
extern void *video_memory; |
void elaborate_image(void *imageptr) |
{ |
WORD x,y; |
BYTE *col; |
#ifdef COLOR |
for(y = 0; y < FG_H; y++) |
for(x = 0; x < FG_W; x++) { |
col = (BYTE *)(imageptr + y * FG_W * 3 + x * 3); |
*(WORD *)(video_memory + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col+2),*(BYTE *)(col+1),*(BYTE *)(col+0)); |
} |
#else |
for(y = 0; y < FG_H; y++) |
for(x = 0; x < FG_W; x++) { |
col = (BYTE *)(imageptr + y * FG_W + x); |
*(WORD *)(video_memory + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col)); |
} |
#endif |
} |
int main(int argc, char **argv) |
{ |
HARD_TASK_MODEL gt; |
SOFT_TASK_MODEL et; |
PID grab_task_pid,elaborate_task_pid; |
struct video_buffer fbuf; |
int channel = 0; |
if (argc < 2) { |
sys_shutdown_message("ERROR: Enter the input channel [ex> %s 0]\n",argv[0]); |
sys_end(); |
} |
channel = atoi(argv[1]); |
soft_task_default_model(et); |
soft_task_def_period(et,FG_PERIOD); |
soft_task_def_arg(et,(void *)(&fbuf)); |
soft_task_def_met(et,FG_WCET); |
soft_task_def_aperiodic(et); |
soft_task_def_ctrl_jet(et); |
hard_task_default_model(gt); |
hard_task_def_mit(gt,FG_PERIOD); |
hard_task_def_wcet(gt,5000); |
hard_task_def_ctrl_jet(gt); |
grab_task_pid = task_create("GrabTask",grab_task,>,NULL); |
if (grab_task_pid == NIL) { |
sys_shutdown_message("ERROR: Cannot create grab task\n"); |
sys_end(); |
} |
elaborate_task_pid = task_create("ElaborateTask",elaborate_task,&et,NULL); |
if (grab_task_pid == NIL) { |
sys_shutdown_message("ERROR: Cannot create elaborate task\n"); |
sys_end(); |
} |
#ifdef COLOR |
fbuf.base = malloc(FG_W*FG_H*3); |
fbuf.height = FG_H; |
fbuf.width = FG_W; |
fbuf.bytesperline = FG_W*3; |
fbuf.depth = 24; |
#else |
fbuf.base = malloc(FG_W*FG_H); |
fbuf.height = FG_H; |
fbuf.width = FG_W; |
fbuf.bytesperline = FG_W; |
fbuf.depth = 8; |
#endif |
start_frame_grabber(elaborate_task_pid,channel,&fbuf); |
#ifndef MAX_SPEED |
/* Activate periodic grabbing */ |
task_activate(grab_task_pid); |
#else |
/* Grab */ |
grab_command(NULL); |
#endif |
while(keyb_getch(BLOCK) != ESC); |
#ifndef MAX_SPEED |
task_kill(grab_task_pid); |
#endif |
sleep(1); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_4/bttvdemo/initfile.c |
---|
0,0 → 1,177 |
/* |
* 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 |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/intdrive.h" |
#include "modules/sem.h" |
#include "modules/hartport.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> |
#include <drivers/shark_i2c26.h> |
#include <drivers/shark_bttv26.h> |
#include <drivers/shark_videodev26.h> |
#define FRAME_BUFFER_DEVICE 0 |
#define FRAME_GRABBER_DEVICE 0 |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
/*+ Interrup Server */ |
#define INTDRIVE_Q 1000 |
#define INTDRIVE_T 10000 |
#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_T,INTDRIVE_FLAG); |
EDF_register_level(EDF_ENABLE_ALL); |
CBS_register_level(CBS_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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
int res; |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
PCI26_init(); |
I2C26_init(); |
INPUT26_init(); |
keyb_def_ctrlC(kparms, NULL); |
KEYB26_init(&kparms); |
BTTV26_init(); |
FB26_init(); |
res = FB26_open(FRAME_BUFFER_DEVICE); |
if (res) { |
cprintf("Error: Cannot open graphical mode\n"); |
KEYB26_close(); |
INPUT26_close(); |
sys_end(); |
} |
FB26_use_grx(FRAME_BUFFER_DEVICE); |
FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16"); |
return 0; |
} |
int device_drivers_close() { |
BTTV26_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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_4/bttvdemo/readme.txt |
---|
0,0 → 1,31 |
-------------------------------------- |
BTTV Frame Grabber Demo |
by |
Giacomo Guidi <giacomo@gandalf.sssup.it> |
Last update 12/05/2004 |
-------------------------------------- |
Ex: |
x bttv [channel number] |
if the channel is not specified 0 is taken. |
If you don't see a grabbed image, you |
can try to set a channel number from 0 to 4. |
This is a simple demo for the BTTV driver. |
It starts the frame grabber at 25 fps 320x200. |
-------------------------------------- |
The demo is composed by: |
MAKEFILE The makefile used to compile the application |
README.TXT This file |
INITFILE.C The init file |
BTTV.C The BTTV Demo |
-------------------------------------- |
/demos/tags/rel_1_4/bttvdemo/makefile |
---|
0,0 → 1,16 |
# |
# |
# |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
PROGS = bttv |
include $(BASE)/config/example.mk |
bttv: |
make -f $(SUBMAKE) APP=bttv INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__ __I2C__ __BTTV__" |
/demos/tags/rel_1_4/advtimer/initfile.c |
---|
0,0 → 1,178 |
/* |
* 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 "modules/intdrive.h" |
#include "modules/edf.h" |
#include "modules/hardcbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "drivers/shark_linuxc26.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 |
/*+ IntDrive Server +*/ |
#define INTDRIVE_Q 1000 |
#define INTDRIVE_T 10000 |
#define INTDRIVE_FLAGS 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_T, INTDRIVE_FLAGS); |
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(); |
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); |
//sys_set_reboot(EXIT_MODE_HALT); |
__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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
/demos/tags/rel_1_4/advtimer/makefile |
---|
0,0 → 1,17 |
# |
# |
# |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
PROGS = advtimer |
include $(BASE)/config/example.mk |
# Text applications |
advtimer: |
make -f $(SUBMAKE) APP=advtimer INIT= OTHEROBJS="initfile.o" SHARKOPT="__LINUXC26__ __PCI__ __INPUT__" |
/demos/tags/rel_1_4/advtimer/advtimer.c |
---|
0,0 → 1,161 |
/* |
* 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 |
*/ |
/* |
* Advanced Timer Demo |
* |
*/ |
#include "kernel/kern.h" |
#include "ll/i386/cons.h" |
#include "ll/i386/advtimer.h" |
#include "drivers/shark_keyb26.h" |
#define UPDATE_PERIOD 10000 |
#define UPDATE_WCET 1000 |
extern unsigned int clk_per_msec; |
extern unsigned int apic_clk_per_msec; |
TASK Update(void *arg) |
{ |
struct timespec actual_timer; |
long nsec,sec,min,hrs,day; |
long mean_delay,tot_delay,num_delay; |
signed long long start,end,res; |
struct timespec s_test,startts,endts; |
task_nopreempt(); |
num_delay = tot_delay = mean_delay = 0; |
while (1) { |
if (clk_per_msec != 0) { |
rdtscll(start); |
sys_gettime(&actual_timer); |
rdtscll(end); |
res = end - start; |
rdtscll(start); |
rdtscll(end); |
res -= (end - start); |
s_test.tv_nsec = res * 1000000 / clk_per_msec; |
} else { |
sys_gettime(&startts); |
sys_gettime(&actual_timer); |
sys_gettime(&endts); |
SUBTIMESPEC(&endts,&startts,&s_test); |
sys_gettime(&startts); |
sys_gettime(&endts); |
SUBTIMESPEC(&endts,&startts,&endts); |
SUBTIMESPEC(&s_test,&endts,&s_test); |
} |
if (tot_delay < 1000000000) { |
tot_delay += s_test.tv_nsec; |
num_delay ++; |
mean_delay = tot_delay / num_delay; |
} |
nsec = actual_timer.tv_nsec; |
sec = actual_timer.tv_sec; |
min = sec / 60; |
sec %= 60; |
hrs = min / 60; |
min %= 60; |
day = hrs / 24; |
hrs %= 24; |
printf_xy(0,5,WHITE,"Actual CPU Clk/msec: %12d",clk_per_msec); |
printf_xy(0,6,WHITE,"Actual APIC Clk/msec: %12d",apic_clk_per_msec); |
printf_xy(0,7,WHITE,"Actual Timer: %2ld d %2ld h %2ld m %2ld s %12ld ns",day,hrs,min,sec,(long)nsec); |
printf_xy(0,9,WHITE,"Timer Access Delay: %12ld ns",mean_delay); |
task_endcycle(); |
} |
} |
void set_screen() |
{ |
clear(); |
printf_xy(20,0,WHITE," Advanced Timer Demo "); |
printf_xy(20,1,WHITE,"Giacomo Guidi <giacomo@gandalf.sssup.it>"); |
printf_xy(20,2,WHITE," Press Alt + c to exit "); |
} |
void program_key_end(KEY_EVT* e) |
{ |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
HARD_TASK_MODEL mp; //Show current setting |
PID update; |
KEY_EVT k; |
k.flag = ALTL_BIT; |
k.scan = KEY_C; |
k.ascii = 'c'; |
k.status = KEY_PRESSED; |
keyb_hook(k,program_key_end,FALSE); |
set_screen(); |
hard_task_default_model(mp); |
hard_task_def_ctrl_jet(mp); |
hard_task_def_group(mp, 1); |
hard_task_def_wcet(mp,UPDATE_WCET); |
hard_task_def_mit(mp,UPDATE_PERIOD); |
hard_task_def_usemath(mp); |
update = task_create("Update", Update, &mp, NULL); |
if (update != NIL) task_activate(update); |
return 0; |
} |
/demos/tags/rel_1_4/advtimer/readme.txt |
---|
0,0 → 1,31 |
-------------------------------------- |
Advanced Timer Demo |
by |
Giacomo Guidi <giacomo@gandalf.sssup.it> |
Last update 23/04/2003 |
-------------------------------------- |
This demo shows the new timer management |
code of S.Ha.R.K. |
-------------------------------------- |
The demo is composed by: |
MAKEFILE The makefile used to compile the application |
README.TXT This file |
INITFILE.C The init file |
ADVTIMER.C The Advanced Timer Demo |
-------------------------------------- |
To change the timer mode, you have to |
modify shark.cfg and to recompile the |
system |
make clean |
make |
/demos/tags/rel_1_4/servo/load.c |
---|
0,0 → 1,46 |
#include "kernel/kern.h" |
#include "drivers/shark_keyb26.h" |
#include "unistd.h" |
#include "servo.h" |
#define N_SEND 10000 |
int main () { |
int res, i = 0, k; |
srand(sys_gettime(NULL)); |
cprintf("(Open Com2)"); |
res = servo_open(COM2, 19200); |
cprintf("(Res = %d)",res); |
cprintf("(Servo Turn On 0)"); |
res = servo_turn_on(COM2, 0); |
cprintf("(Res = %d)",res); |
while(i < N_SEND) { |
cprintf("(Cycle = %d)",i); |
k = rand() % 180 - 90; |
cprintf("(Set Servo 0 %d)",k); |
res = servo_set_angle_sec(COM2, 0, ANGLE2SEC(k,0,0)); |
cprintf("(Res = %d)",res); |
udelay(100000); |
i++; |
} |
servo_close(COM2); |
sys_end(); |
return 0; |
} |
/demos/tags/rel_1_4/servo/initfile.c |
---|
0,0 → 1,152 |
/* |
* 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 |
*/ |
#include "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/intdrive.h" |
#include "modules/sem.h" |
#include "modules/hartport.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_T 10000 |
#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_T,INTDRIVE_FLAG); |
EDF_register_level(EDF_ENABLE_ALL); |
CBS_register_level(CBS_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(); |
/* 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"); |
sys_end(); |
} |
} |
int device_drivers_init() { |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
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"); |
sys_abort_shutdown(0); |
return NULL; |
} |
Property changes: |
Added: svn:executable |
## -0,0 +1 ## |
+* |
\ No newline at end of property |
Index: rel_1_4/servo/makefile |
=================================================================== |
--- rel_1_4/servo/makefile (nonexistent) |
+++ rel_1_4/servo/makefile (revision 1488) |
@@ -0,0 +1,15 @@ |
+# |
+# |
+# |
+ |
+ifndef BASE |
+BASE=../.. |
+endif |
+include $(BASE)/config/config.mk |
+ |
+PROGS = load |
+ |
+include $(BASE)/config/example.mk |
+ |
+load: |
+ make -f $(SUBMAKE) APP=load INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __INPUT__ __SERVO__" |
/rel_1_4/servo/makefile |
---|
Property changes: |
Added: svn:executable |
## -0,0 +1 ## |
+* |
\ No newline at end of property |
Index: rel_1_4/servo/README |
=================================================================== |
--- rel_1_4/servo/README (nonexistent) |
+++ rel_1_4/servo/README (revision 1488) |
@@ -0,0 +1,2 @@ |
+TODO |
+ |
Index: rel_1_4/bca/initfile.c |
=================================================================== |
--- rel_1_4/bca/initfile.c (nonexistent) |
+++ rel_1_4/bca/initfile.c (revision 1488) |
@@ -0,0 +1,230 @@ |
+/* |
+ * 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 |
+ * |
+ */ |
+ |
+#define PI_MUTEX |
+ |
+#include "kernel/kern.h" |
+#include "modules/intdrive.h" |
+#include "modules/edf.h" |
+#include "modules/hardcbs.h" |
+#include "modules/rr.h" |
+#include "modules/dummy.h" |
+ |
+#include "modules/sem.h" |
+#include "modules/hartport.h" |
+#include "modules/cabs.h" |
+ |
+#include "modules/pi.h" |
+#include "modules/nop.h" |
+ |
+#include "bca.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_T 10000 |
+#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_T,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(); |
+ CABS_register_module(); |
+ |
+ PI_register_module(); |
+ NOP_register_module(); |
+ |
+ kern_init_bca(); |
+ |
+ 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; |
+} |
+ |
+#ifdef PI_MUTEX |
+int app_mutex_init(mutex_t *m) |
+{ |
+ PI_mutexattr_t attr; |
+ |
+ PI_mutexattr_default(attr); |
+ |
+ return mutex_init(m, &attr); |
+} |
+#else |
+int app_mutex_init(mutex_t *m) |
+{ |
+ NOP_mutexattr_t attr; |
+ |
+ NOP_mutexattr_default(attr); |
+ |
+ return mutex_init(m, &attr); |
+} |
+#endif |
+ |
+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"); |
+ sys_end(); |
+ } |
+ |
+} |
+ |
+int device_drivers_init() { |
+ |
+ int res; |
+ KEYB_PARMS kparms = BASE_KEYB; |
+ |
+ LINUXC26_register_module(); |
+ |
+ 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(); |
+ sys_end(); |
+ } |
+ |
+ 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"); |
+ |
+ sys_abort_shutdown(0); |
+ |
+ return NULL; |
+ |
+} |
Index: rel_1_4/bca/esplo.c |
=================================================================== |
--- rel_1_4/bca/esplo.c (nonexistent) |
+++ rel_1_4/bca/esplo.c (revision 1488) |
@@ -0,0 +1,94 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: esplo.c,v 1.5 2004-05-26 09:25:06 giacomo Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+//************************ |
+//* file: esplo.c * |
+//* included by: bca.c * |
+//************************ |
+ |
+#include <time.h> |
+ |
+PID crea_soft_esplo(int index) |
+{ |
+ SOFT_TASK_MODEL m; |
+ PID pid; |
+ |
+ soft_task_default_model(m); |
+ soft_task_def_arg(m,(void*)index); |
+ soft_task_def_period(m,ESPLO_PERIOD*2); |
+ soft_task_def_wcet(m,ESPLO_WCET*10); |
+ soft_task_def_met(m,ESPLO_MET*10); |
+ |
+ pid = task_create("esplo", esplo, &m, NULL); |
+ return pid; |
+} |
+ |
+TASK esplo(void *argv) |
+{ |
+ int i; |
+ int index; |
+ WORD xx0, yy0, xx1, yy1; |
+ struct timespec delay; |
+ |
+ |
+ delay.tv_sec = 0; |
+ delay.tv_nsec = 20000000; |
+ i=0; |
+ index = (int)argv; |
+ xx0 = aereo_table[index].x - ESPLO_LX/2; |
+ yy0 = aereo_table[index].y - ESPLO_LY/2; |
+ xx1 = xx0 + ESPLO_LX-1; |
+ yy1 = yy0 + ESPLO_LY-1; |
+ |
+ for(i=0;i<5;i++) { |
+ mutex_lock(&grx_mutex); |
+ FAB_image_put_within(image_esplo[i],xx0,yy0,X0,Y0,X1,Y1); |
+ mutex_unlock(&grx_mutex); |
+ task_endcycle(); |
+ } |
+ |
+ mutex_lock(&grx_mutex); |
+ FAB_image_put_within(image_bca,X0,Y0,xx0,yy0,xx1,yy1); |
+ mutex_unlock(&grx_mutex); |
+ |
+ return 0; |
+ |
+} |
Index: rel_1_4/bca/missile.c |
=================================================================== |
--- rel_1_4/bca/missile.c (nonexistent) |
+++ rel_1_4/bca/missile.c (revision 1488) |
@@ -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> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: missile.c,v 1.3 2004-05-25 18:24:59 giacomo Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+//************************** |
+//* file: missile.c * |
+//* included by: bca.c * |
+//************************** |
+ |
+PID crea_hard_missile(int index); |
+PID crea_soft_missile(int index); |
+PID crea_soft_esplo(int index); |
+ |
+TASK missile(void *arg) |
+{ |
+ PID esplo_pid; |
+ int img; |
+ int i, index; // indice nella cannone_table |
+ int distx, disty; |
+ int xx0,yy0,xx1,yy1; |
+ double vel, acc; |
+ double a; |
+ double y; |
+ double x; |
+ double old_x; // [pixel]: conserva valore x prima di aggiornare |
+ double old_y; |
+ double dx; // [pixel/us]: spostamento periodico |
+ double dy; |
+ int first_time; |
+ int killing; |
+ |
+ index = (int)arg; |
+ img=0; |
+ y = MISSILE_Y_MAX; |
+ x = cannone_table[index].x; |
+ a = FAB_rad(270); |
+ vel = MISSILE_V_MIN; |
+ acc = MISSILE_ACC_MIN; |
+ dx = 0; |
+ dy = 0; |
+ |
+ first_time = 1; |
+ killing = 0; |
+ |
+ while(1){ |
+ |
+ old_x = x; |
+ old_y = y; |
+ |
+ if (vel<MISSILE_V_MAX) { |
+ vel += acc*MISSILE_PERIOD/(60*60*1000000.0); |
+ if (vel>MISSILE_V_MAX) vel = MISSILE_V_MAX; |
+ } |
+ if (acc<MISSILE_ACC_MAX) { |
+ acc += MISSILE_ACC_MIN; |
+ if (acc>MISSILE_ACC_MAX) acc = MISSILE_ACC_MAX; |
+ } |
+ |
+ cannone_table[index].missile_vel=vel; |
+ |
+ dx = cos(a)*vel * (X1-X0) / (double)BASE_L |
+ * (MISSILE_PERIOD / (60*60*1000000.0)); |
+ dy = sin(a)*vel * (Y1-Y0) / ((double)BASE_H/1000) |
+ * (MISSILE_PERIOD / (60*60*1000000.0)); |
+ |
+ x += dx; |
+ y += dy; |
+ |
+ xx0 = old_x - MISSILE_LX/2; |
+ yy0 = old_y - MISSILE_LY/2; |
+ xx1 = xx0 + MISSILE_LX-1; |
+ yy1 = yy0 + MISSILE_LY-1; |
+ |
+ if (x<MISSILE_X_MIN || x>MISSILE_X_MAX |
+ || y<MISSILE_Y_MIN || y>MISSILE_Y_MAX) { |
+ killing = 1; |
+ } |
+ |
+ if (killing) { |
+ if (!first_time) { |
+ mutex_lock(&grx_mutex); |
+ FAB_image_put_within(image_bca,X0,Y0,xx0,yy0,xx1,yy1); |
+ mutex_unlock(&grx_mutex); |
+ } |
+ cannone_table[index].fire = 0; |
+ //il task cannone si accorge che il suo missile ha finito |
+ // quindi ne ricreer uno nuovo in caso di bersaglio!!! |
+ return NULL; |
+ } |
+ |
+ if ( (int)x != (int)old_x |
+ ||(int)y != (int)old_y ) {//...se c' lo spostamento reale |
+ // di almeno un pixel... |
+ mutex_lock(&grx_mutex); //...aggiorna disegno... |
+ if (first_time) { |
+ first_time=0; |
+ } |
+ else { |
+ if (yy1<Y1-CANNONE_LY) FAB_image_put_within(image_bca,X0,Y0,xx0,yy0,xx1,yy1); |
+ else FAB_image_put_within(image_bca,X0,Y0,xx0,yy0,xx1,Y1-CANNONE_LY); |
+ } |
+ |
+ FAB_image_put_within(image_missile[img++], x - MISSILE_LX/2, y - MISSILE_LY/2, |
+ X0, Y0, |
+ X1, Y1-CANNONE_LY); |
+ mutex_unlock(&grx_mutex); |
+ if (img==2) img = 0; |
+ } |
+ |
+ //Ha colpito un aereo? |
+ for (i=0; i<AEREO_N_MAX; i++) |
+ if (aereo_table[i].status){ |
+ distx = aereo_table[i].x-x; |
+ disty = aereo_table[i].y-y; |
+ if (distx<0) distx *= -1; |
+ if (disty<0) disty *= -1; |
+ if ( distx<(AEREO_LX+MISSILE_LX)/2-1 |
+ &&disty<(AEREO_LY+MISSILE_LY)/2-1 ) { // BERSAGLIO COLPITO! |
+ esplo_pid = crea_soft_esplo(i); |
+ task_activate(esplo_pid); |
+ killing=1; |
+ aereo_table[i].killing=1; |
+ break; |
+ } |
+ } |
+ |
+ task_endcycle(); |
+ } |
+ |
+return NULL; |
+} |
+ |
+ |
+PID crea_hard_missile(int index) |
+{ |
+ HARD_TASK_MODEL m; |
+ PID pid; |
+ |
+ hard_task_default_model(m); |
+ hard_task_def_level(m,1); |
+ hard_task_def_arg(m,(void*)index); |
+ hard_task_def_periodic(m); |
+ hard_task_def_wcet(m, MISSILE_WCET); |
+ hard_task_def_mit(m,MISSILE_PERIOD); |
+ |
+ pid = task_create("hard_missile", missile, &m, NULL); |
+ return pid; |
+} |
+ |
+PID crea_soft_missile(int index) |
+{ |
+ SOFT_TASK_MODEL m; |
+ PID pid; |
+ |
+ soft_task_default_model(m); |
+ soft_task_def_level(m,2); |
+ soft_task_def_arg(m,(void*)index); |
+ soft_task_def_periodic(m); |
+ soft_task_def_period(m,MISSILE_PERIOD); |
+ soft_task_def_wcet(m, MISSILE_WCET); |
+ soft_task_def_met(m,MISSILE_MET); |
+ |
+ pid = task_create("soft_missile", missile, &m, NULL); |
+ return pid; |
+} |
Index: rel_1_4/bca/cannone.c |
=================================================================== |
--- rel_1_4/bca/cannone.c (nonexistent) |
+++ rel_1_4/bca/cannone.c (revision 1488) |
@@ -0,0 +1,218 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: cannone.c,v 1.3 2004-05-25 18:24:59 giacomo Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+//************************** |
+//* file: cannone.c * |
+//* included by: bca.c * |
+//************************** |
+ |
+TASK cannone_creator(void * arg) |
+{ int i, index, last; |
+ WORD count; |
+ PID pid=-1; |
+ |
+ while(1){ |
+ |
+ count=0; |
+ index=-1; |
+ last=-1; |
+ |
+ for (i=0; i<CANNONE_N_MAX; i++) // Conteggio aerei attivi |
+ if (cannone_table[i].status) { |
+ count++; |
+ last=i; //...ultima posizione occupata in tabella... |
+ } |
+ else { |
+ if (index==-1) index=i; //...prima posizione libera in tabella... |
+ } |
+ |
+ if (count<cannone_count && index!=-1) { // Richiesta nuovo cannone |
+ cannone_table[index].status = 1; //...occupa posizione... |
+ cannone_table[index].killing = 0; //...disattiva richiesta di kill... |
+ if (index==0) pid = crea_hard_cannone(index); // sempre il 1ø hard |
+ else pid = crea_soft_cannone(index); // tutti gli altri soft |
+ cannone_table[index].pid = pid; |
+ if (pid!=NIL) task_activate(pid); |
+ else { //ripristino il posto libero in tabella; |
+ cannone_table[index].status = -2; |
+ cannone_table[index].killing = -2; |
+ } |
+ } |
+ |
+ else if (count>cannone_count) { // Richiesta cancellazione cannone |
+ cannone_table[last].killing = 1; |
+ } |
+ |
+ task_endcycle(); |
+ } |
+ return NULL; |
+} |
+ |
+PID crea_soft_cannone_creator(); |
+PID crea_hard_cannone(int index); |
+PID crea_hard_cannone(int index); |
+ |
+PID crea_hard_missile(int index); |
+PID crea_soft_missile(int index); |
+ |
+TASK cannone(void *arg) |
+{ |
+ PID missile_pid=-2; |
+ int i, index; // indice nella aereo_table e cannone_table |
+ int d, dir; |
+ int xx0,yy0,xx1,yy1; |
+ int first_time; |
+ |
+ index = (int)arg; |
+ first_time = 1; |
+ if (index%2) { |
+ //indice dispari |
+ xx0 = X0 + 500/2 - CANNONE_LX/2 + 500/(CANNONE_N_MAX+1)*(index+1)/2; |
+ } |
+ else { |
+ //indice pari |
+ xx0 = X0 + 500/2 - CANNONE_LX/2 - 500/(CANNONE_N_MAX+1)*(index/2); |
+ } |
+ xx1 = xx0 + CANNONE_LX; |
+ yy0= Y1 - CANNONE_LY; |
+ yy1= Y1; |
+ |
+ cannone_table[index].x = xx0 + CANNONE_LX/2; |
+ |
+ while(1){ |
+ |
+ if (cannone_table[index].killing) { |
+ if (!first_time) { |
+ mutex_lock(&grx_mutex); |
+ FAB_image_put_within(image_bca,X0,Y0,xx0,yy0,xx1,yy1); |
+ mutex_unlock(&grx_mutex); |
+ } |
+ cannone_table[index].status=0; |
+ cannone_table[index].pid=-2; |
+ cannone_table[index].killing=0; |
+ //il task aereo_creator si accorge che c' un aereo in meno |
+ // quindi ne ricreer uno nuovo!!! |
+ return NULL; |
+ } |
+ |
+ if (first_time) { |
+ mutex_lock(&grx_mutex); //...aggiorna disegno... |
+ if (index==0) FAB_image_put(image_cannone[1], xx0, yy0); |
+ else FAB_image_put(image_cannone[0], xx0, yy0); |
+ mutex_unlock(&grx_mutex); |
+ first_time=0; |
+ } |
+ |
+ if (!cannone_table[index].fire) { |
+ for (i=0; i<AEREO_N_MAX; i++) { |
+ if (aereo_table[i].status) { |
+ d = aereo_table[i].x - (xx0+CANNONE_LX/2); |
+ dir = aereo_table[i].dir; |
+ if (d*dir<0 && FAB_ABS(d)<=CANNONE_SENSIBILITA/1000.0*500/BASE_L) { |
+ // FA F U O C O |
+ if (index==0) missile_pid=crea_hard_missile(index); |
+ else missile_pid=crea_soft_missile(index); |
+ if (missile_pid!=NIL) { |
+ cannone_table[index].fire = 1; |
+ task_activate(missile_pid); |
+ break; |
+ } |
+ } |
+ } |
+ } |
+ } |
+ |
+ task_endcycle(); |
+ } |
+ |
+return NULL; |
+} |
+ |
+ |
+ |
+PID crea_soft_cannone_creator() |
+{ |
+ SOFT_TASK_MODEL m; |
+ PID pid; |
+ |
+ soft_task_default_model(m); |
+ soft_task_def_periodic(m); |
+ soft_task_def_period(m,CANNONE_CREATOR_PERIOD); |
+ soft_task_def_wcet(m,CANNONE_CREATOR_WCET); |
+ soft_task_def_met(m,CANNONE_CREATOR_MET); |
+ |
+ pid = task_create("cannone_creator", cannone_creator, &m, NULL); |
+ return pid; |
+} |
+ |
+PID crea_hard_cannone(int index) |
+{ |
+ HARD_TASK_MODEL m; |
+ PID pid; |
+ |
+ hard_task_default_model(m); |
+ hard_task_def_level(m,1); |
+ hard_task_def_arg(m,(void*)index); |
+ hard_task_def_periodic(m); |
+ hard_task_def_wcet(m, CANNONE_WCET); |
+ hard_task_def_mit(m,CANNONE_PERIOD); |
+ |
+ pid = task_create("hard_cannone", cannone, &m, NULL); |
+ return pid; |
+} |
+ |
+PID crea_soft_cannone(int index) |
+{ |
+ SOFT_TASK_MODEL m; |
+ PID pid; |
+ |
+ soft_task_default_model(m); |
+ soft_task_def_level(m,2); |
+ soft_task_def_arg(m,(void*)index); |
+ soft_task_def_periodic(m); |
+ soft_task_def_period(m,CANNONE_PERIOD); |
+ soft_task_def_wcet(m, CANNONE_WCET); |
+ soft_task_def_met(m,CANNONE_MET); |
+ |
+ pid = task_create("soft_cannone", cannone, &m, NULL); |
+ return pid; |
+} |
+ |
Index: rel_1_4/bca/aereo.c |
=================================================================== |
--- rel_1_4/bca/aereo.c (nonexistent) |
+++ rel_1_4/bca/aereo.c (revision 1488) |
@@ -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> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: aereo.c,v 1.2 2004-05-25 18:24:59 giacomo Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+//************************ |
+//* file: aereo.c * |
+//* included by: bca.c * |
+//************************ |
+ |
+TASK aereo_creator(void * arg) |
+{ int i, index, last; |
+ WORD count; |
+ PID pid=-1; |
+ COLOR col; |
+ double vel; |
+ int dir; |
+ WORD h; |
+ double l; |
+ WORD x, y; |
+ |
+ while(1){ |
+ |
+ count=0; |
+ index=-1; |
+ last=-1; |
+ |
+ for (i=0; i<AEREO_N_MAX; i++) // Conteggio aerei attivi |
+ if (aereo_table[i].status) { |
+ count++; |
+ last=i; //...ultima posizione occupata in tabella... |
+ } |
+ else { |
+ if (index==-1) index=i; //...prima posizione libera in tabella... |
+ } |
+ |
+ if (count<aereo_count && index!=-1) { // Richiesta nuovo aereo |
+ aereo_table[index].status = 1; //...occupa posizione... |
+ aereo_table[index].killing = 0; //...disattiva richiesta di kill... |
+ col = FAB_rgb(FAB_int_rand(50,255), //...nuovo colore... |
+ FAB_int_rand(50,255), |
+ FAB_int_rand(50,255)); |
+ vel = FAB_double_rand(AEREO_V_MIN,AEREO_V_MAX); //...velocita'... |
+ dir = FAB_sign_rand(); //...direzione... |
+ h = FAB_int_rand(AEREO_H_MIN,AEREO_H_MAX); //...altezza... |
+ y = Y0 + 500 - h*500/BASE_H; |
+ l = (dir>0) ? AEREO_L_MIN : AEREO_L_MAX; //...posizione iniz... |
+ x = (dir>0) ? AEREO_X_MIN : AEREO_X_MAX; |
+ // ... settaggio valori in tabella ... |
+ aereo_table[index].color = col; |
+ if (index>0) { |
+ if (dir>0) FAB_image_copy(image_aereo[0],aereo_table[index].image); |
+ else FAB_image_copy(image_aereo[1],aereo_table[index].image); |
+ } |
+ else { |
+ if (dir>0) FAB_image_copy(image_aereo[2],aereo_table[index].image); |
+ else FAB_image_copy(image_aereo[3],aereo_table[index].image); |
+ } |
+ FAB_image_color_change(aereo_table[index].image,AEREO_BASE_COL,col); |
+ aereo_table[index].vel = vel; |
+ aereo_table[index].dir = dir; |
+ aereo_table[index].h = h; |
+ aereo_table[index].l = l; |
+ aereo_table[index].x = x; |
+ aereo_table[index].y = y; |
+ if (index==0) pid = crea_hard_aereo(index); // sempre il 1ø hard |
+ else pid = crea_soft_aereo(index); // tutti gli altri soft |
+ aereo_table[index].pid = pid; |
+ if (pid!=NIL) task_activate(pid); |
+ else { //ripristino il posto libero in tabella; |
+ aereo_table[index].status = 0; |
+ aereo_table[index].killing = 0; |
+ } |
+ } |
+ |
+ else if (count>aereo_count) { // Richiesta cancellazione aereo |
+ aereo_table[last].killing = 1; |
+ } |
+ |
+ task_endcycle(); |
+ } |
+ return NULL; |
+} |
+ |
+TASK aereo(void *arg) |
+{ |
+ int index; // indice nella aereo_table |
+ FAB_IMAGE* image; |
+ int xx0,yy0,xx1,yy1; |
+ int y; |
+ double x; |
+ double old_x; // [pixel]: conserva valore x prima di aggiornare |
+ double dx; // [pixel/us]: spostamento periodico |
+ int first_time; |
+ |
+ index = (int)arg; |
+ image = aereo_table[index].image; |
+ y = aereo_table[index].y; |
+ x = aereo_table[index].x; |
+ dx = aereo_table[index].vel * (AEREO_X_MAX-AEREO_X_MIN) / (double)BASE_L |
+ * (AEREO_PERIOD / (60*60*1000000.0)) |
+ * aereo_table[index].dir; |
+ first_time = 1; |
+ |
+ while(1){ |
+ |
+ old_x = x; |
+ x += dx; |
+ |
+ xx0 = old_x - AEREO_LX/2; |
+ yy0 = y - AEREO_LY/2; |
+ xx1 = xx0 + AEREO_LX - 1; |
+ yy1 = yy0 + AEREO_LY - 1; |
+ |
+ aereo_table[index].x = x; //...aggiornamento posizione in tabella... |
+ |
+ if (x<AEREO_X_MIN || x>AEREO_X_MAX) { |
+ aereo_table[index].killing = 1; |
+ } |
+ |
+ if (aereo_table[index].killing) { |
+ if (!first_time) { |
+ mutex_lock(&grx_mutex); |
+ FAB_image_put_within(image_bca,X0,Y0,xx0,yy0,xx1,yy1); |
+ mutex_unlock(&grx_mutex); |
+ } |
+ aereo_table[index].status=0; |
+ aereo_table[index].pid=-2; |
+ aereo_table[index].killing=0; |
+ //il task aereo_creator si accorge che c' un aereo in meno |
+ // quindi ne ricreer uno nuovo!!! |
+ return NULL; |
+ } |
+ |
+ if(aereo_table[index].x!=(int)old_x) {//...se c' lo spostamento reale |
+ // di almeno un pixel... |
+ mutex_lock(&grx_mutex); //...aggiorna disegno... |
+ if (first_time) { |
+ first_time=0; |
+ } |
+ else { |
+ FAB_image_put_within(image_bca,X0,Y0,xx0,yy0,xx1,yy1); |
+ } |
+ |
+ FAB_image_put_within(image, x - AEREO_LX/2, y - AEREO_LY/2, |
+ X0, Y0, X1, Y1); |
+ mutex_unlock(&grx_mutex); |
+ } |
+ |
+ task_endcycle(); |
+ } |
+ |
+return NULL; |
+} |
+ |
+PID crea_soft_aereo_creator() |
+{ |
+ SOFT_TASK_MODEL m; |
+ PID pid; |
+ |
+ soft_task_default_model(m); |
+ soft_task_def_periodic(m); |
+ soft_task_def_period(m,AEREO_CREATOR_PERIOD); |
+ soft_task_def_wcet(m,AEREO_CREATOR_WCET); |
+ soft_task_def_met(m,AEREO_CREATOR_MET); |
+ |
+ pid = task_create("aereo_creator", aereo_creator, &m, NULL); |
+ return pid; |
+} |
+ |
+PID crea_hard_aereo(int index) |
+{ |
+ HARD_TASK_MODEL m; |
+ PID pid; |
+ |
+ hard_task_default_model(m); |
+ hard_task_def_level(m,1); |
+ hard_task_def_arg(m,(void*)index); |
+ hard_task_def_periodic(m); |
+ hard_task_def_wcet(m, AEREO_WCET); |
+ hard_task_def_mit(m,AEREO_PERIOD); |
+ hard_task_def_usemath(m); |
+ |
+ pid = task_create("hard_aereo", aereo, &m, NULL); |
+ return pid; |
+} |
+ |
+PID crea_soft_aereo(int index) |
+{ |
+ SOFT_TASK_MODEL m; |
+ PID pid; |
+ |
+ soft_task_default_model(m); |
+ soft_task_def_level(m,2); |
+ soft_task_def_arg(m,(void*)index); |
+ soft_task_def_periodic(m); |
+ soft_task_def_period(m,AEREO_PERIOD); |
+ soft_task_def_wcet(m, AEREO_WCET); |
+ soft_task_def_met(m,AEREO_MET); |
+ soft_task_def_usemath(m); |
+ |
+ pid = task_create("soft aereo", aereo, &m, NULL); |
+ return pid; |
+} |
+ |
Index: rel_1_4/bca/bca_lib.c |
=================================================================== |
--- rel_1_4/bca/bca_lib.c (nonexistent) |
+++ rel_1_4/bca/bca_lib.c (revision 1488) |
@@ -0,0 +1,412 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: bca_lib.c,v 1.4 2004-05-23 08:59:27 giacomo Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+/**************************************************** |
+ * * |
+ * file: BCA_LIB.c * |
+ * libreria: BCA_LIB * |
+ * creato da: Fabio CALABRESE * |
+ * * |
+ ****************************************************/ |
+ |
+#ifndef __BCA_LIB_c__ |
+#define __BCA_LIB_c__ |
+//-------------------BEGIN--------------------------- |
+ |
+// *** Librerie S.Ha.R.K *** |
+#include<kernel/kern.h> |
+ |
+#include<drivers/shark_fb26.h> |
+ |
+// *** Librerie Standard C *** |
+// *** Librerie FAB *** |
+#include"fab_lib/fab_msg.h" |
+// *** Librerie BCA *** |
+#include"bca.h" |
+ |
+char * titolo[10]={" UNIVERSITA' DEGLI \0", |
+ " STUDI DI \0", |
+ " PAVIA \0", |
+ "Progetto S.Ha.R.K.\0", |
+ " 'BaseContrAerea' \0", |
+ "-------------------\0", |
+ " PAVIA 2002 \0", |
+ "by Fabio CALABRESE \0", |
+ "<fabiocalabrese77 \0", |
+ " @yahoo.it>\0"}; |
+ |
+void kern_alloc_images(); // richiede DISABLED_INTERUPTS |
+void kern_free_images(); // richiede DISABLED_INTERUPTS |
+void kern_load_images(); // solo in __kernel_register_levels__() |
+ |
+void kern_alloc_borders(); // richiede DISABLED_INTERUPTS |
+void kern_free_borders(); // richiede DISABLED_INTERUPTS |
+void kern_set_border(); // consigliato in __kernel_register-levels__() |
+ |
+void kern_alloc_frames(); // richiede DISABLED_INTERUPTS |
+void kern_free_frames(); // richiede DISABLED_INTERUPTS |
+void kern_set_frames(); // consigliato in __kernel_register-levels__() |
+ |
+void kern_alloc_ballframes(); // richiede DISABLED_INTERUPTS |
+void kern_free_ballframes(); // richiede DISABLED_INTERUPTS |
+void kern_set_ballframes(); // consigliato in __kernel_register-levels__() |
+ |
+void kern_alloc_task_tables(); // richiede DISABLED_INTERUPTS |
+void kern_free_task_tables(); // richiede DISABLED_INTERUPTS |
+void kern_set_task_tables(); // consigliato in __kernel_register-levels__() |
+ |
+void kern_alloc_task_tables() |
+{ |
+ int test=0,j; |
+ |
+ FAB_print("TASKS'TABLES","allocazione..."); |
+ for (j=0; j<AEREO_N_MAX; j++) { |
+ aereo_table[j].image=FAB_image_alloc(AEREO_LX,AEREO_LY); |
+ if(aereo_table[j].image==NULL) test=1; |
+ } |
+ FAB_msg(test,"fatto","almeno un elemento della tabella non allocato"); |
+} |
+void kern_free_task_tables() |
+{ int j; |
+ |
+ for (j=0; j<AEREO_N_MAX; j++) { |
+ FAB_image_free(aereo_table[j].image); |
+ } |
+} |
+void kern_set_task_tables() |
+{ int j; |
+ |
+ FAB_print(NULL,"settaggio..."); |
+ for (j=0; j<AEREO_N_MAX; j++) { |
+ aereo_table[j].status = 0; |
+ aereo_table[j].killing = 0; |
+ aereo_table[j].image->trasparent = 1; |
+ aereo_table[j].image->trasparent_col = AEREO_TRASPARENT_COL; |
+ } |
+ |
+ FAB_print(NULL,"fatto"); |
+} |
+ |
+ |
+void kern_alloc_ballframes() |
+{ |
+ int test=0,j; |
+ |
+ FAB_print("FAB_BALLFRAMEs","allocazione..."); |
+ ballframe_radar = FAB_ballframe_alloc(); |
+ if (ballframe_radar==NULL) test=1; |
+ for (j=0; j<3; j++) { |
+ ballframe_lucerossa[j] = FAB_ballframe_alloc(); |
+ if (ballframe_lucerossa[j]==NULL) test=1; |
+ } |
+ FAB_msg(test,"fatto","almeno un ballframe non allocato"); |
+} |
+void kern_free_ballframes() |
+{ int j; |
+ |
+ FAB_ballframe_free(ballframe_radar); |
+ for (j=0; j<3; j++) |
+ FAB_ballframe_free(ballframe_lucerossa[j]); |
+} |
+void kern_set_ballframes() |
+{ int j; |
+ |
+ FAB_print(NULL,"settaggio..."); |
+ FAB_ballframe_border_set(ballframe_radar,border_verde7,7, |
+ FRAME_MISURE_LINE_COLOR); |
+ FAB_ballframe_color_set(ballframe_radar,0,FAB_blue); |
+ for(j=0; j<3; j++) { |
+ FAB_ballframe_border_set(ballframe_lucerossa[j],border_verde7,7, |
+ FRAME_MISURE_LINE_COLOR); |
+ FAB_ballframe_color_set(ballframe_lucerossa[j],0,FAB_red); |
+ } |
+ FAB_print(NULL,"fatto"); |
+} |
+ |
+void kern_alloc_frames() |
+{ |
+ int test=0; |
+ |
+ FAB_print("FAB_FRAMEs","allocazione..."); |
+ frame_bca = FAB_frame_alloc(); |
+ if (frame_bca==NULL) test=1; |
+ frame_misure_oriz = FAB_frame_alloc(); |
+ if (frame_misure_oriz==NULL) test=1; |
+ frame_misure_vert = FAB_frame_alloc(); |
+ if (frame_misure_vert==NULL) test=1; |
+ frame_titolo = FAB_frame_alloc(); |
+ if (frame_titolo==NULL) test=1; |
+ frame_comandi = FAB_frame_alloc(); |
+ if (frame_comandi==NULL) test=1; |
+ frame_control = FAB_frame_alloc(); |
+ if (frame_control==NULL) test=1; |
+ |
+ FAB_msg(test,"fatto","almeno un frame non allocato"); |
+} |
+void kern_free_frames() |
+{ |
+ FAB_frame_free(frame_bca); |
+ FAB_frame_free(frame_misure_oriz); |
+ FAB_frame_free(frame_misure_vert); |
+ FAB_frame_free(frame_titolo); |
+ FAB_frame_free(frame_comandi); |
+ FAB_frame_free(frame_control); |
+ |
+} |
+ |
+void kern_set_frames() |
+{ |
+ FAB_print(NULL,"settaggio..."); |
+ FAB_frame_border_set(frame_bca,border_blu7,7,FAB_rgb(255,0,0)); |
+ FAB_frame_color_set(frame_bca,0,image_bca,FAB_green); |
+ FAB_frame_border_set(frame_misure_oriz,border_verde7,7,FRAME_MISURE_LINE_COLOR); |
+ FAB_frame_color_set(frame_misure_oriz,0,NULL,FRAME_MISURE_BACK_COLOR); |
+ FAB_frame_border_set(frame_misure_vert,border_verde7,7,FRAME_MISURE_LINE_COLOR); |
+ FAB_frame_color_set(frame_misure_vert,0,NULL,FRAME_MISURE_BACK_COLOR); |
+ FAB_frame_border_set(frame_titolo,border_bianco7,7,FAB_white); |
+ FAB_frame_color_set(frame_titolo,0,NULL,FRAME_TITOLO_BACK_COLOR1); |
+ FAB_frame_border_set(frame_comandi,border_giallo7,7,FAB_yellow); |
+ FAB_frame_color_set(frame_comandi,0,NULL,FRAME_COMANDI_BACK_COLOR1); |
+ FAB_frame_border_set(frame_control,border_verde7,7,FAB_green); |
+ FAB_frame_color_set(frame_control,0,NULL,FRAME_CONTROL_BACK_COLOR); |
+ |
+ FAB_print(NULL,"fatto"); |
+} |
+ |
+void kern_alloc_borders() |
+{ |
+ int test=0; |
+ |
+ FAB_print("FAB_BORDERs","allocazione..."); |
+ border_blu7 = FAB_border_alloc(7); |
+ if (border_blu7==NULL) test=1; |
+ border_verde7 = FAB_border_alloc(7); |
+ if (border_verde7==NULL) test=1; |
+ border_rosso7 = FAB_border_alloc(7); |
+ if (border_rosso7==NULL) test=1; |
+ border_bianco7 = FAB_border_alloc(7); |
+ if (border_bianco7==NULL) test=1; |
+ border_giallo7 = FAB_border_alloc(7); |
+ if (border_giallo7==NULL) test=1; |
+ |
+ FAB_msg(test,"fatto","almeno un bordo non allocato"); |
+} |
+void kern_free_borders() |
+{ |
+ FAB_border_free(border_blu7); |
+ FAB_border_free(border_verde7); |
+ FAB_border_free(border_rosso7); |
+ FAB_border_free(border_bianco7); |
+ FAB_border_free(border_giallo7); |
+} |
+ |
+void kern_set_borders() |
+{ |
+ FAB_print(NULL,"settaggio..."); |
+ border_blu7->buf[0]=FAB_rgb( 0, 0, 50); |
+ border_blu7->buf[1]=FAB_rgb( 0, 50,200); |
+ border_blu7->buf[2]=FAB_rgb( 50,100,255); |
+ border_blu7->buf[3]=FAB_rgb(100,150,255); |
+ border_blu7->buf[4]=FAB_rgb( 50,100,255); |
+ border_blu7->buf[5]=FAB_rgb( 0, 50,200); |
+ border_blu7->buf[6]=FAB_rgb( 0, 0, 50); |
+ |
+ border_verde7->buf[0]=FAB_rgb( 0, 50, 0); |
+ border_verde7->buf[1]=FAB_rgb( 0,100, 50); |
+ border_verde7->buf[2]=FAB_rgb( 50,255,100); |
+ border_verde7->buf[3]=FAB_rgb(100,255,150); |
+ border_verde7->buf[4]=FAB_rgb( 50,255,100); |
+ border_verde7->buf[5]=FAB_rgb( 0,100, 50); |
+ border_verde7->buf[6]=FAB_rgb( 0, 50, 0); |
+ |
+ border_rosso7->buf[0]=FAB_rgb( 50, 0, 0); |
+ border_rosso7->buf[1]=FAB_rgb(200, 25, 25); |
+ border_rosso7->buf[2]=FAB_rgb(255, 75, 75); |
+ border_rosso7->buf[3]=FAB_rgb(255,125,125); |
+ border_rosso7->buf[4]=FAB_rgb(255, 75, 75); |
+ border_rosso7->buf[5]=FAB_rgb(200, 25, 25); |
+ border_rosso7->buf[6]=FAB_rgb( 50, 0, 0); |
+ |
+ border_bianco7->buf[0]=FAB_rgb( 25, 25, 25); |
+ border_bianco7->buf[1]=FAB_rgb( 75, 75, 75); |
+ border_bianco7->buf[2]=FAB_rgb(125,125,125); |
+ border_bianco7->buf[3]=FAB_rgb(255,255,255); |
+ border_bianco7->buf[4]=FAB_rgb(125,125,125); |
+ border_bianco7->buf[5]=FAB_rgb( 75, 75, 75); |
+ border_bianco7->buf[6]=FAB_rgb( 25, 25, 25); |
+ |
+ border_giallo7->buf[0]=FAB_rgb( 25, 25, 0); |
+ border_giallo7->buf[1]=FAB_rgb(115,115, 25); |
+ border_giallo7->buf[2]=FAB_rgb(170,170, 75); |
+ border_giallo7->buf[3]=FAB_rgb(255,255,100); |
+ border_giallo7->buf[4]=FAB_rgb(170,170, 75); |
+ border_giallo7->buf[5]=FAB_rgb(115,115, 25); |
+ border_giallo7->buf[6]=FAB_rgb( 25, 25, 0); |
+ |
+ FAB_print(NULL,"fatto"); |
+} |
+ |
+void kern_alloc_images() |
+{ |
+ int j,test=0; |
+ |
+ FAB_print("FAB_IMAGEs","allocazione..."); |
+ |
+ image_missile[0] = FAB_image_alloc(MISSILE_LX,MISSILE_LY); |
+ if (image_missile[0]==NULL) test=1; |
+ image_missile[1] = FAB_image_alloc(MISSILE_LX,MISSILE_LY); |
+ if (image_missile[1]==NULL) test=1; |
+ |
+ for (j=0; j<2; j++) { |
+ image_cannone[j] = FAB_image_alloc(CANNONE_LX,CANNONE_LY); |
+ if (image_cannone[j]==NULL) test=1; |
+ } |
+ |
+ for (j=0; j<4; j++) { |
+ image_aereo[j] = FAB_image_alloc(AEREO_LX,AEREO_LY); |
+ if (image_aereo[j]==NULL) test=1; |
+ } |
+ |
+ for (j=0; j<5; j++) { |
+ image_esplo[j] = FAB_image_alloc(ESPLO_LX,ESPLO_LY); |
+ if (image_esplo[j]==NULL) test=1; |
+ } |
+ |
+ image_sfondo = FAB_image_alloc(96,96); |
+ if (image_sfondo==NULL) test=1; |
+ |
+ image_bca = FAB_image_alloc(500,500); |
+ if (image_bca==NULL) test=1; |
+ |
+ FAB_msg(test,"fatto","almeno un'immagine non allocata"); |
+} |
+void kern_free_images() |
+{ |
+ int j; |
+ |
+ FAB_image_free(image_missile[0]); |
+ FAB_image_free(image_missile[1]); |
+ for (j=0; j<2; j++) FAB_image_free(image_cannone[j]); |
+ for (j=0; j<4; j++) FAB_image_free(image_aereo[j]); |
+ for (j=0; j<5; j++) FAB_image_free(image_esplo[j]); |
+ FAB_image_free(image_sfondo); |
+ FAB_image_free(image_bca); |
+} |
+ |
+void kern_load_images() |
+{ int test=0; |
+ |
+ FAB_print(NULL,"caricamento dai file..."); |
+ |
+ FAB_print(NULL," [missile1.raw]..."); |
+ if(FAB_image_load(image_missile[0],"BCA_raw/missile1.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_missile[0],MISSILE_TRASPARENT_COL); |
+ FAB_print(NULL," [missile2.raw]..."); |
+ if(FAB_image_load(image_missile[1],"BCA_raw/missile2.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_missile[1],MISSILE_TRASPARENT_COL); |
+ |
+ FAB_print(NULL," [aereo1.raw]..."); |
+ if(FAB_image_load(image_aereo[0],"BCA_raw/aereo1.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_aereo[0],AEREO_TRASPARENT_COL); |
+ FAB_print(NULL," [aereo2.raw]..."); |
+ if(FAB_image_load(image_aereo[1],"BCA_raw/aereo2.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_aereo[1],AEREO_TRASPARENT_COL); |
+ FAB_print(NULL," [aereo1_h.raw]..."); |
+ if(FAB_image_load(image_aereo[2],"BCA_raw/aereo1_h.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_aereo[2],AEREO_TRASPARENT_COL); |
+ FAB_print(NULL," [aereo2_h.raw]..."); |
+ if(FAB_image_load(image_aereo[3],"BCA_raw/aereo2_h.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_aereo[3],AEREO_TRASPARENT_COL); |
+ |
+ FAB_print(NULL," [cannon.raw]..."); |
+ if(FAB_image_load(image_cannone[0],"BCA_raw/cannon.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_cannone[0],CANNONE_TRASPARENT_COL); |
+ FAB_print(NULL," [cannon_h.raw]..."); |
+ if(FAB_image_load(image_cannone[1],"BCA_raw/cannon_h.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_cannone[1],CANNONE_TRASPARENT_COL); |
+ |
+ FAB_print(NULL," [esplo1.raw]..."); |
+ if(FAB_image_load(image_esplo[0],"BCA_raw/esplo1.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_esplo[0],ESPLO_TRASPARENT_COL); |
+ FAB_print(NULL," [esplo2.raw]..."); |
+ if(FAB_image_load(image_esplo[1],"BCA_raw/esplo2.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_esplo[1],ESPLO_TRASPARENT_COL); |
+ FAB_print(NULL," [esplo3.raw]..."); |
+ if(FAB_image_load(image_esplo[2],"BCA_raw/esplo3.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_esplo[2],ESPLO_TRASPARENT_COL); |
+ FAB_print(NULL," [esplo4.raw]..."); |
+ if(FAB_image_load(image_esplo[3],"BCA_raw/esplo4.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_esplo[3],ESPLO_TRASPARENT_COL); |
+ FAB_print(NULL," [esplo5.raw]..."); |
+ if(FAB_image_load(image_esplo[4],"BCA_raw/esplo5.raw")==-1) test=1; |
+ FAB_image_trasparent_set(image_esplo[4],ESPLO_TRASPARENT_COL); |
+ |
+ FAB_print(NULL," [sfondo.raw]..."); |
+ if(FAB_image_load(image_sfondo,"BCA_raw/sfondo.raw")==-1) test=1; |
+ FAB_image_no_trasparent_set(image_sfondo); |
+ |
+ FAB_print(NULL," [bca.raw]..."); |
+ if(FAB_image_load(image_bca,"BCA_raw/bca.raw")==-1) test=1; |
+ FAB_image_no_trasparent_set(image_bca); |
+ |
+ FAB_msg(test,"fatto","almeno un file non esiste oppure ha un formato incompatibile"); |
+} |
+ |
+// *** Corpo delle funzioni in CA.h *** // |
+void kern_init_bca() |
+{ |
+ FAB_clr(); |
+ |
+ kern_alloc_task_tables(); |
+ kern_set_task_tables(); |
+ |
+ kern_alloc_borders(); |
+ kern_set_borders(); |
+ kern_alloc_images(); |
+ kern_load_images(); |
+ kern_alloc_frames(); |
+ kern_set_frames(); |
+ kern_alloc_ballframes(); |
+ kern_set_ballframes(); |
+} |
+ |
+//----------------------END-------------------------- |
+#endif |
Index: rel_1_4/bca/fab_lib.c |
=================================================================== |
--- rel_1_4/bca/fab_lib.c (nonexistent) |
+++ rel_1_4/bca/fab_lib.c (revision 1488) |
@@ -0,0 +1,424 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: fab_lib.c,v 1.4 2004-05-23 08:59:27 giacomo Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+/**************************************************** |
+ * * |
+ * file: FAB_lib.c * |
+ * libreria: FAB_LIB * |
+ * version: 1.0 25/08/2002 * |
+ * creato da: Fabio CALABRESE * |
+ * * |
+ ****************************************************/ |
+ |
+#ifndef __FAB_LIB_c__ |
+#define __FAB_LIB_c__ |
+//-------------------BEGIN--------------------------- |
+ |
+// *** Librerie di S.Ha.R.K. *** |
+#include<kernel/kern.h> |
+#include<kernel/mem.h> |
+ |
+#include<drivers/shark_fb26.h> |
+ |
+#include<ll/sys/types.h> |
+#include<ll/i386/x-dos.h> |
+// *** Librerie Standard C *** |
+// *** Librerie FAB *** |
+#include"fab_lib/fab_msg.h" |
+#include"fab_lib/fab_tool.h" |
+#include"fab_lib/fab_grx.h" |
+ |
+// *** Corpo delle funzioni in FAB_msg.h *** // |
+ |
+void FAB_print(char * InitMsg, char * msg) |
+{ if (InitMsg!=NULL) {kern_printf("\n[%s]",(InitMsg));} |
+ if (msg!=NULL) {kern_printf("\n %s.",msg);} |
+} |
+void __FAB_go(int test, char * OkMsg, char * ErrorMsg,int EXITflag) |
+{ |
+ if (OkMsg==NULL) OkMsg=FAB_EMPTY_MSG; |
+ if (ErrorMsg==NULL) ErrorMsg=FAB_EMPTY_MSG; |
+ |
+ if (!test) {kern_printf("\n OK: %s.",OkMsg);} |
+ else {kern_printf("\n ERROR: %s!",ErrorMsg); |
+ if (EXITflag==FAB_EXIT_YES) sys_end(); |
+ } |
+} |
+ |
+// *** Corpo delle funzioni in FAB_tool.h *** // |
+ |
+// nessun corpo! |
+ |
+// *** Corpo delle funzioni in FAB_show.h *** // |
+ |
+void FAB_show_sched_modules() |
+{ //int i; |
+ |
+ FAB_print("MODULI DI SCHEDULAZIONE",NULL); |
+ kern_printf("\n (livello) (nome)"); |
+ kern_printf("Names non more available!"); |
+ //for (i=0; i<sched_levels; i++) |
+ // {kern_printf("\n %-9d %s",i,(level_table[i])->level_name); |
+ // } |
+ FAB_newline(); |
+} |
+ |
+// *** Corpo delle funzioni in FAB_grx.h *** |
+ |
+FAB_BALLFRAME* FAB_ballframe_alloc() |
+{ FAB_BALLFRAME* frame; |
+ |
+ frame=(FAB_BALLFRAME*)kern_alloc(sizeof(FAB_BALLFRAME)); |
+ if (frame==NULL) { |
+ FAB_print(NULL,"BALLFRAME CREATING... ERROR #1"); |
+ return NULL; |
+ } |
+ return frame; |
+} |
+void FAB_ballframe_free(FAB_BALLFRAME * frame) |
+{ if (frame!=NULL) |
+ { kern_free(frame,sizeof(FAB_BALLFRAME)); |
+ } |
+} |
+ |
+FAB_FRAME* FAB_frame_alloc() |
+{ FAB_FRAME* frame; |
+ |
+ frame=(FAB_FRAME*)kern_alloc(sizeof(FAB_FRAME)); |
+ if (frame==NULL) { |
+ FAB_print(NULL,"FRAME CREATING... ERROR #1"); |
+ return NULL; |
+ } |
+ |
+ return frame; |
+} |
+void FAB_frame_free(FAB_FRAME * frame) |
+{ if (frame!=NULL) |
+ { kern_free(frame,sizeof(FAB_FRAME)); |
+ } |
+} |
+void FAB_ballborder_put(FAB_BORDER* border, WORD cx, WORD cy, WORD r_int) |
+{ int i; |
+ |
+ for (i=0; i<border->dim; i++) |
+ grx_circle(cx, cy, r_int+i, border->buf[i]); |
+} |
+void FAB_border_put(FAB_BORDER* border, WORD x0, WORD y0, WORD x1, WORD y1) |
+{ int i; |
+ |
+ for (i=0; i<border->dim; i++) |
+ grx_rect(x0-i, y0-i, x1+i, y1+i, border->buf[i]); |
+} |
+FAB_BORDER* FAB_border_alloc(WORD dim) |
+{ FAB_BORDER* border; |
+ |
+ border=(FAB_BORDER*)kern_alloc(sizeof(FAB_BORDER)); |
+ if (border==NULL) { |
+ FAB_print(NULL,"BORDER CREATING... ERROR #1"); |
+ return NULL; |
+ } |
+ |
+ border->buf=(COLOR*)kern_alloc(dim*sizeof(COLOR)); |
+ if (border->buf==NULL) { |
+ FAB_print(NULL,"BORDER CREATING... ERROR #2"); |
+ return NULL; |
+ } |
+ |
+ border->dim = dim; |
+ |
+ return border; |
+} |
+void FAB_border_free(FAB_BORDER * border) |
+{ if (border!=NULL) |
+ { kern_free(border->buf,border->dim*sizeof(COLOR)); |
+ kern_free(border,sizeof(FAB_BORDER)); |
+ } |
+} |
+void FAB_image_free(FAB_IMAGE* image) |
+{ if (image!=NULL) |
+ { kern_free(image->buf,image->lx*image->ly*sizeof(COLOR)); |
+ kern_free(image,sizeof(FAB_IMAGE)); |
+ } |
+} |
+FAB_IMAGE* FAB_image_alloc(WORD lx, WORD ly) |
+{ FAB_IMAGE* image; |
+ |
+ image=(FAB_IMAGE*)kern_alloc(sizeof(FAB_IMAGE)); |
+ if (image==NULL) { |
+ FAB_print(NULL,"IMAGE CREATING... ERROR #1"); |
+ return NULL; |
+ } |
+ |
+ image->buf=(COLOR*)kern_alloc(lx*ly*sizeof(COLOR)); |
+ if (image->buf==NULL) { |
+ FAB_print(NULL,"IMAGE CREATING... ERROR #2"); |
+ return NULL; |
+ } |
+ FAB_image_no_trasparent_set(image); |
+ image->lx = lx; |
+ image->ly = ly; |
+ |
+ return image; |
+} |
+int FAB_image_load(FAB_IMAGE* image, char* file_name) |
+{ |
+ DOS_FILE* file; |
+ BYTE rgb[3]; |
+ COLOR * buf; |
+ int i; |
+ |
+ file=DOS_fopen(file_name,"r"); |
+ if (file==NULL) return -1; |
+ |
+ buf = image->buf; |
+ for (i=0; i<image->lx*image->ly; i++) |
+ { DOS_fread(&rgb[0],sizeof(BYTE),3,file); |
+ *buf = FAB_rgb(rgb[0],rgb[1],rgb[2]); |
+ buf++; |
+ } |
+ |
+ DOS_fclose(file); |
+ return(0); |
+} |
+void FAB_image_get(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly) |
+{ WORD x, y; |
+ COLOR* buf; |
+ |
+ buf = image->buf; |
+ for (y=0; y<image->ly; y++) |
+ for (x=0; x<image->lx; x++) { |
+ *buf = (COLOR) grx_getpixel(x0+x,y0+y); |
+ buf++; |
+ } |
+ FAB_image_no_trasparent_set(image); |
+} |
+void FAB_image_put(FAB_IMAGE* image, WORD x0, WORD y0) |
+{ WORD x, y; |
+ COLOR* buf; |
+ |
+ buf = image->buf; |
+ if (!image->trasparent) { |
+ for (y=0; y<image->ly; y++) |
+ for (x=0; x<image->lx; x++) |
+ grx_plot(x0+x,y0+y,*buf++); |
+ } |
+ else { |
+ for (y=0; y<image->ly; y++) |
+ for (x=0; x<image->lx; x++) { |
+ if (*buf!=image->trasparent_col) |
+ grx_plot(x0+x,y0+y,*buf); |
+ buf++; |
+ } |
+ } |
+} |
+void FAB_image_put_within(FAB_IMAGE* image, WORD x0, WORD y0, |
+ WORD xx0, WORD yy0, WORD xx1, WORD yy1) |
+{ int step_x0_xx0; |
+ int step_y0_yy0; |
+ int step_xx1_x1; |
+ int step_yy1_y1; |
+ WORD xx, yy; |
+ COLOR* buf; |
+ |
+ step_x0_xx0 = xx0 - x0; |
+ step_y0_yy0 = yy0 - y0; |
+ step_xx1_x1 = (x0 + image->lx - 1) - xx1; |
+ step_yy1_y1 = (y0 + image->ly - 1) - yy1; |
+ |
+ if (step_x0_xx0 < 0) step_x0_xx0 = 0; |
+ if (step_y0_yy0 < 0) step_y0_yy0 = 0; |
+ if (step_xx1_x1 < 0) step_xx1_x1 = 0; |
+ if (step_yy1_y1 < 0) step_yy1_y1 = 0; |
+ |
+ buf = image->buf + step_y0_yy0*image->lx; |
+ if (!image->trasparent) { |
+ for(yy=step_y0_yy0; yy<image->ly-step_yy1_y1; yy++) { |
+ buf += step_x0_xx0; |
+ for(xx=step_x0_xx0; xx<image->lx-step_xx1_x1; xx++) |
+ grx_plot(x0+xx,y0+yy,*buf++); |
+ buf += step_xx1_x1; |
+ } |
+ } |
+ else { |
+ for(yy=step_y0_yy0; yy<image->ly-step_yy1_y1; yy++) { |
+ buf += step_x0_xx0; |
+ for(xx=step_x0_xx0; xx<image->lx-step_xx1_x1; xx++) { |
+ if (*buf!=image->trasparent_col) |
+ grx_plot(x0+xx,y0+yy,*buf); |
+ buf++; |
+ } |
+ buf += step_xx1_x1; |
+ } |
+ } |
+} |
+//...funzione usata da FAB_image_fill()... |
+void __FAB_image_put_into(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly) |
+{ WORD x, y; |
+ WORD skipped_pixels; |
+ COLOR* buf; |
+ |
+ if (lx < image->lx) skipped_pixels = image->lx - lx; |
+ else skipped_pixels = 0; |
+ buf = image->buf; |
+ |
+ if (!image->trasparent) { |
+ for (y=0; y<ly; y++, buf+=skipped_pixels) { |
+ if (y > image->ly -1) break; |
+ for (x=0; x<lx; x++, buf++) { |
+ if (x < image->lx) grx_plot(x0+x,y0+y,*buf); |
+ else break; |
+ } |
+ } |
+ } |
+ else { |
+ for (y=0; y<ly; y++, buf+=skipped_pixels) { |
+ if (y > image->ly -1) break; |
+ for (x=0; x<lx; x++, buf++) { |
+ if (x < image->lx) { |
+ if (*buf!=image->trasparent_col) |
+ grx_plot(x0+x,y0+y,*buf); |
+ } |
+ else break; |
+ } |
+ } |
+ } |
+} |
+void FAB_image_fill(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly) |
+{ WORD x, y; |
+ WORD sub_lx, sub_ly; |
+ |
+ for (y=0; y<ly; y+=image->ly) { |
+ sub_ly = ly - y; // spazio verticale disponibile |
+ if (sub_ly > image->ly) sub_ly = image->ly; |
+ for (x=0; x<lx; x+=image->lx) { |
+ sub_lx = lx - x; // spazio orizzontale disponibile |
+ if (sub_lx > image->lx) sub_lx = image->lx; |
+ __FAB_image_put_into(image,x0+x,y0+y,sub_lx,sub_ly); |
+ } |
+ } |
+} |
+void FAB_frame_put(FAB_FRAME* frame, WORD x0, WORD y0, WORD lx, WORD ly) |
+{ |
+ WORD eff_dim; |
+ int j; |
+ |
+ //BORDO DEL FRAME |
+ if (frame->border!=NULL) eff_dim = frame->border->dim; |
+ else eff_dim = frame->border_dim; |
+ frame->x0 = x0 + eff_dim; |
+ frame->y0 = y0 + eff_dim; |
+ frame->x1 = x0 + lx - eff_dim - 1; |
+ frame->y1 = y0 + ly - eff_dim - 1; |
+ if (frame->border!=NULL) { |
+ FAB_border_put(frame->border, frame->x0-1, frame->y0-1, |
+ frame->x1+1, frame->y1+1); |
+ } |
+ else { |
+ for (j=0; j<eff_dim; j++) |
+ grx_rect(frame->x0-1-j, frame->y0-1-j, |
+ frame->x1+1+j, frame->y1+1+j, frame->border_col); |
+ } |
+ |
+ //PANNELLO DEL FRAME |
+ if (!frame->trasparent) { |
+ if (frame->image==NULL) grx_box(frame->x0, frame->y0, |
+ frame->x1, frame->y1, frame->color); |
+ else FAB_image_fill(frame->image, |
+ frame->x0, frame->y0, |
+ lx-eff_dim*2, ly-eff_dim*2); |
+ } |
+} |
+ |
+void FAB_ballframe_put(FAB_BALLFRAME* frame, WORD cx, WORD cy, WORD r) |
+{ |
+ int j; |
+ WORD eff_dim; |
+ |
+ //BORDO DEL FRAME |
+ if (frame->border!=NULL) eff_dim = frame->border->dim; |
+ else eff_dim = frame->border_dim; |
+ frame->cx = cx; |
+ frame->cy = cy; |
+ frame->r = r - eff_dim; |
+ |
+ if (frame->border!=NULL) { |
+ FAB_ballborder_put(frame->border,frame->cx,frame->cy,frame->r+1); |
+ } |
+ else { |
+ for (j=0; j<eff_dim; j++) |
+ grx_circle(frame->cx,frame->cy,frame->r+1+j,frame->border_col); |
+ } |
+ |
+ //PANNELLO DEL FRAME |
+ if (!frame->trasparent) { |
+ grx_disc(frame->cx,frame->cy,frame->r,frame->color); |
+ } |
+} |
+ |
+void FAB_image_copy(FAB_IMAGE* orig_image, FAB_IMAGE* dest_image) |
+{ |
+ COLOR* orig_buf; |
+ COLOR* dest_buf; |
+ int j,n; |
+ |
+ n = orig_image->lx * orig_image->ly; |
+ if (n==(dest_image->lx * dest_image->ly)) { |
+ orig_buf = orig_image->buf; |
+ dest_buf = dest_image->buf; |
+ for(j=0; j<n; j++) { |
+ *dest_buf = *orig_buf; |
+ orig_buf++; |
+ dest_buf++; |
+ } |
+ } |
+} |
+void FAB_image_color_change(FAB_IMAGE* image, COLOR old_col, COLOR new_col) |
+{ COLOR* buf; |
+ int j,n; |
+ |
+ buf = image->buf; |
+ n = image->lx * image->ly; |
+ for(j=0; j<n; j++, buf++) |
+ if (*buf==old_col) |
+ *buf=new_col; |
+} |
+//----------------------END-------------------------- |
+#endif |
Index: rel_1_4/bca/bca.c |
=================================================================== |
--- rel_1_4/bca/bca.c (nonexistent) |
+++ rel_1_4/bca/bca.c (revision 1488) |
@@ -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> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: bca.c,v 1.5 2004-05-23 08:59:27 giacomo Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+/**************************************************** |
+ * * |
+ * file: bca.c * |
+ * header file: bca.h * |
+ * data: 15/09/2002 * |
+ * creato da: Fabio CALABRESE * |
+ * * |
+ ****************************************************** |
+ * * |
+ * descrizione: e' il file in cui è descritto il task* |
+ * main del programma S.Ha.R.K. * |
+ * "(B)ase(C)ontr(A)rea". * |
+ * Il codice del programma comprende * |
+ * anche l'implementazione di altri task* |
+ * distribuiti nei seguenti file che * |
+ * quindi sono inclusi: * |
+ * dummy.c * |
+ * control.c * |
+ * aereo.c * |
+ * cannone.c * |
+ * missile.c * |
+ * esplo.c * |
+ * Inoltre è incluso anche il file: * |
+ * scenario.c * |
+ * che descrive come disegnare lo * |
+ * scenario grafico iniziale * |
+ * * |
+ ******************************************************/ |
+ |
+ |
+// *** Librerie S.Ha.R.K *** |
+#include <kernel/kern.h> |
+#include <ll/i386/cons.h> |
+ |
+#include <drivers/shark_fb26.h> |
+#include <drivers/shark_keyb26.h> |
+ |
+// *** Librerie Standard C *** |
+#include <stdlib.h> |
+// *** Librerie FAB *** |
+#include "fab_lib/fab_msg.h" |
+#include "fab_lib/fab_show.h" |
+#include "fab_lib/fab_tool.h" |
+#include "fab_lib/fab_grx.h" |
+// *** Librerie BCA *** |
+#include "bca.h" |
+ |
+ |
+char * titolo[10]; |
+ |
+void scenario(); |
+void info(); |
+#include"scenario.c" |
+ |
+PID crea_soft_dummy_radar (); |
+TASK dummy_radar(void *); |
+#include"dummy.c" |
+ |
+PID crea_soft_control(); |
+TASK control(void *); |
+#include"control.c" |
+ |
+PID crea_soft_aereo_creator(); |
+TASK aereo_creator(); |
+PID crea_hard_aereo(int index); |
+PID crea_soft_aereo(int index); |
+TASK aereo(void * index); |
+#include"aereo.c" |
+ |
+PID crea_soft_cannone_creator(); |
+TASK cannone_creator(); |
+PID crea_hard_cannone(int index); |
+PID crea_soft_cannone(int index); |
+TASK cannone(void * index); |
+#include"cannone.c" |
+ |
+PID crea_hard_missile(); |
+PID crea_soft_missile(); |
+TASK missile(); |
+#include"missile.c" |
+ |
+PID crea_soft_esplo(); |
+TASK esplo(void *); |
+#include"esplo.c" |
+ |
+void end_fun(KEY_EVT* k) |
+{ sys_shutdown_message("Ending...\n"); |
+ sys_end(); |
+} |
+void incrementa_aerei_fun(KEY_EVT* k) |
+{ if (aereo_count<AEREO_N_MAX) aereo_count++; |
+} |
+void decrementa_aerei_fun(KEY_EVT* k) |
+{ if (aereo_count>AEREO_N_MIN) aereo_count--; |
+} |
+void incrementa_cannoni_fun(KEY_EVT* k) |
+{ if (cannone_count<CANNONE_N_MAX) cannone_count++; |
+} |
+void decrementa_cannoni_fun(KEY_EVT* k) |
+{ if (cannone_count>CANNONE_N_MIN) cannone_count--; |
+} |
+ |
+int main(int argc, char **argv) |
+{ |
+ PID pid; |
+ |
+ KEY_EVT k; |
+ |
+ k.flag = 0; |
+ k.scan = KEY_ENT; |
+ k.ascii = 13; |
+ k.status = KEY_PRESSED; |
+ keyb_hook(k,end_fun,FALSE); |
+ k.flag = 0; |
+ k.scan = KEY_1; |
+ k.ascii = '1'; |
+ k.status = KEY_PRESSED; |
+ keyb_hook(k,incrementa_aerei_fun,FALSE); |
+ k.flag = 0; |
+ k.scan = KEY_2; |
+ k.ascii = '2'; |
+ k.status = KEY_PRESSED; |
+ keyb_hook(k,decrementa_aerei_fun,FALSE); |
+ k.flag = 0; |
+ k.scan = KEY_3; |
+ k.ascii = '3'; |
+ k.status = KEY_PRESSED; |
+ keyb_hook(k,incrementa_cannoni_fun,FALSE); |
+ k.flag = 0; |
+ k.scan = KEY_4; |
+ k.ascii = '4'; |
+ k.status = KEY_PRESSED; |
+ keyb_hook(k,decrementa_cannoni_fun,FALSE); |
+ |
+ /* inizializza il mutex grafico */ |
+ app_mutex_init(&grx_mutex); |
+ |
+ scenario(); |
+ |
+ //---init--- |
+ srand(sys_gettime(NULL)); |
+ aereo_count = AEREO_N_MIN; |
+ cannone_count = CANNONE_N_MIN; |
+ |
+ pid=crea_soft_dummy_radar(); |
+ task_activate(pid); |
+ |
+ pid=crea_soft_aereo_creator(); |
+ task_activate(pid); |
+ |
+ pid=crea_soft_cannone_creator(); |
+ task_activate(pid); |
+ |
+ pid=crea_soft_control(); |
+ task_activate(pid); |
+ //---------- |
+ |
+ return 0; |
+ |
+} |
+ |
+ |
Index: rel_1_4/bca/makefile |
=================================================================== |
--- rel_1_4/bca/makefile (nonexistent) |
+++ rel_1_4/bca/makefile (revision 1488) |
@@ -0,0 +1,16 @@ |
+# |
+# |
+# |
+ |
+ifndef BASE |
+BASE=../.. |
+endif |
+include $(BASE)/config/config.mk |
+ |
+PROGS= bca |
+ |
+include $(BASE)/config/example.mk |
+ |
+bca: |
+ make -f $(SUBMAKE) APP=bca INIT= OTHEROBJS="initfile.o fab_lib.o bca_lib.o" SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__" |
+ |
Index: rel_1_4/bca/fab_lib/fab_msg.h |
=================================================================== |
--- rel_1_4/bca/fab_lib/fab_msg.h (nonexistent) |
+++ rel_1_4/bca/fab_lib/fab_msg.h (revision 1488) |
@@ -0,0 +1,94 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: fab_msg.h,v 1.2 2004-05-23 08:59:28 giacomo Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+/**************************************************** |
+ * * |
+ * file: FAB_msg.h * |
+ * libreria: FAB_LIB * |
+ * version: 1.0 25/08/2002 * |
+ * creato da: Fabio CALABRESE * |
+ * * |
+ **************************************************** |
+ * * |
+ * descrizione: libreria di funzioni per stampare * |
+ * messaggi circa il corretto esito * |
+ * dell'esecuzione delle istruzioni; * |
+ * stampa semplici stringhe colorate; * |
+ * aiuta a fare il debbuging. * |
+ * * |
+ ****************************************************/ |
+ |
+#ifndef __FAB_LIB__FAB_msg_h__ |
+#define __FAB_LIB__FAB_msg_h__ |
+//-------------------BEGIN--------------------------- |
+ |
+// *** Librerie di S.Ha.R.K. *** |
+#include <ll/i386/cons.h> |
+// *** Librerie Standard C *** |
+// *** Librerie FAB *** |
+ |
+// ----------- |
+// Definizioni |
+//---------------------- |
+#define FAB_EXIT_YES 1 |
+#define FAB_EXIT_NO 0 |
+#define FAB_EMPTY_MSG "" |
+//---------------------- |
+ |
+// ---------------- |
+// Funzioni & Macro |
+//------------------------------------------------- |
+#define FAB_newline() NL() |
+#define FAB_home() HOME() |
+#define FAB_clr() clear() |
+ |
+void FAB_print(char * InitMsg, char * msg); |
+#define FAB_msg(TEST,OKMSG,ERRORMSG) __FAB_go((TEST),(OKMSG),(ERRORMSG),FAB_EXIT_NO) |
+#define FAB_go(TEST,OKMSG,ERRORMSG,EXITFLAG) __FAB_go((TEST),(OKMSG),(ERRORMSG),(EXITFLAG)) |
+//-------------------------------------------------- |
+ |
+ |
+// Altro... |
+ |
+void __FAB_go(int test, char * OkMsg, char * ErrorMsg,int EXITflag); |
+ |
+//----------------------END-------------------------- |
+#endif |
Index: rel_1_4/bca/fab_lib/fab_grx.h |
=================================================================== |
--- rel_1_4/bca/fab_lib/fab_grx.h (nonexistent) |
+++ rel_1_4/bca/fab_lib/fab_grx.h (revision 1488) |
@@ -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> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: fab_grx.h,v 1.3 2004-05-23 08:59:28 giacomo Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+/**************************************************** |
+ * * |
+ * file: FAB_grx.h * |
+ * libreria: FAB_LIB * |
+ * version: 1.0 25/08/2002 * |
+ * creato da: Fabio CALABRESE * |
+ * * |
+ **************************************************** |
+ * * |
+ * descrizione: libreria di funzioni grafiche: * |
+ * permette di gestire con facilita' * |
+ * immagini, cornici, e veri e propri * |
+ * pannelli colorati. * |
+ * Il contesto di grafica va avviato * |
+ * con FAB_grx_open() e alla fine * |
+ * chiuso correttamente con la funz. * |
+ * FAB_grx_close(). L'ambiente di * |
+ * grafica e'impostato a 16bit per * |
+ * default, comunque e' sempre * |
+ * possibile scegliere la profondita' * |
+ * di colori preferita tra 15/16/24/32* |
+ * definendo semplicemente solo una * |
+ * delle seguenti costanti all'inizio * |
+ * del proprio programma che include * |
+ * questa libreria grafica: * |
+ * FAB_GRX_15 * |
+ * FAB_GRX_16 (default) * |
+ * FAB_GRX_24 * |
+ * FAB_GRX_32 * |
+ * * |
+ ****************************************************/ |
+ |
+#ifndef __FAB_LIB_fab_grx_h__ |
+#define __FAB_LIB_fab_grx_h__ |
+//-------------------BEGIN--------------------------- |
+ |
+// *** Librerie di S.Ha.R.K. *** |
+#include <kernel/kern.h> |
+#include <ll/sys/types.h> |
+ |
+#include <drivers/shark_fb26.h> |
+ |
+// *** Librerie Standard C *** |
+// *** Librerie FAB *** |
+#include"fab_grx.sys" |
+ |
+//#define FAB_GRX_15 |
+//#define FAB_GRX_16 |
+//#define FAB_GRX_24 |
+//#define FAB_GRX_32 |
+ |
+typedef __FAB_COLOR COLOR; |
+ |
+typedef struct { |
+ WORD lx,ly; |
+ COLOR * buf; |
+ int trasparent; |
+ COLOR trasparent_col; |
+ } FAB_IMAGE; |
+ |
+typedef struct { |
+ WORD dim; |
+ COLOR * buf; |
+ } FAB_BORDER; |
+ |
+typedef struct { |
+ FAB_BORDER * border; //default = NULL |
+ WORD border_dim; //default = 0 |
+ COLOR border_col; |
+ |
+ BYTE trasparent; //default = 0 |
+ FAB_IMAGE * image; //default = NULL |
+ COLOR color; |
+ |
+ WORD x0,y0,x1,y1; //spigoli pannello interno |
+ //cornice esclusa: vengono settati |
+ //automaticamente con FAB_frame_put(). |
+ } FAB_FRAME; |
+typedef struct { |
+ FAB_BORDER * border; //default = NULL |
+ WORD border_dim; //default = 0 |
+ COLOR border_col; |
+ |
+ BYTE trasparent; //default = 0 |
+ COLOR color; |
+ |
+ WORD cx,cy,r; //centro e raggio del pannello |
+ //circolare: vengono settati |
+ //automaticamente con FAB_ballframe_put(). |
+ } FAB_BALLFRAME; |
+ |
+// ----------- |
+// Definizioni |
+//---------------------- |
+#define FAB_BPP __FAB_BPP |
+#define FAB_rgb(R24,G24,B24) __FAB_rgb((R24),(G24),(B24)) |
+ |
+// Colori base |
+#define FAB_white FAB_rgb(255,255,255) |
+#define FAB_black FAB_rgb( 0, 0, 0) |
+#define FAB_red FAB_rgb(255, 0, 0) |
+#define FAB_green FAB_rgb( 0,255, 0) |
+#define FAB_blue FAB_rgb( 0, 0,255) |
+#define FAB_yellow FAB_rgb(255,255, 0) |
+#define FAB_gray FAB_rgb(100,100,100) |
+ |
+//---------------------- |
+ |
+// ---------------- |
+// Funzioni & Macro |
+//-------------------------------------------------- |
+int FAB_grx_open(WORD lx, WORD ly); |
+void FAB_grx_close(); |
+ |
+FAB_IMAGE* FAB_image_alloc(WORD lx, WORD ly); //richiede DISABLED INTERRUPTS |
+void FAB_image_free(FAB_IMAGE* image); //richiede DISABLED INTERRUPTS |
+FAB_BORDER* FAB_border_alloc(WORD dim); //richiede DISABLED INTERRUPTS |
+void FAB_border_free(FAB_BORDER * border);//richiede DISABLED INTERRUPTS |
+FAB_FRAME* FAB_frame_alloc(); //richiede DISABLED INTERRUPTS |
+void FAB_frame_free(FAB_FRAME * frame); //richiede DISABLED INTERRUPTS |
+FAB_BALLFRAME* FAB_ballframe_alloc(); //richiede DISABLED INTERRUPTS |
+void FAB_ballframe_free(FAB_BALLFRAME * frame);//richiede DISABLED INTERRUPTS |
+ |
+// Permette di riempire lo spazio allocato ad un FAB_IMAGE |
+// leggendo le sequenze rgb a 24bit da un file immagine binario. |
+// Un formato perfettamente compatibile quello |
+// "RAW"(con header=0 e sequenza ad ordinamento RGB-RGB-RGB...): |
+int FAB_image_load(FAB_IMAGE* image, char* file_name); // solo in __kernel_register_levels__() |
+// Per default un FAB_IMAGE non ha il colore di trasparenza: |
+#define FAB_image_no_trasparent_set(IMAGE) (IMAGE)->trasparent=0 |
+#define FAB_image_trasparent_set(IMAGE,TRASPARENT_COL) (IMAGE)->trasparent=1;(IMAGE)->trasparent_col=(TRASPARENT_COL) |
+ |
+// Settaggio FAB_BORDER deve essere fatto manualmente! |
+// esempio: |
+// mio_border->buf[i] = FAB_rgb(0,100,0); |
+// ... |
+// mio_border->buf[N] = FAB_rgb(0,100,255); |
+// (non esiste una funzione FAB_border_set) |
+ |
+#define FAB_frame_border_set(FRAME,BORDER,BORDER_DIM,BORDER_COL) (FRAME)->border=(BORDER);(FRAME)->border_dim=(BORDER_DIM);(FRAME)->border_col=(BORDER_COL); |
+#define FAB_frame_color_set(FRAME,TRASPARENT_FLAG,IMAGE,COLOR) (FRAME)->trasparent=(TRASPARENT_FLAG);(FRAME)->image=(IMAGE);(FRAME)->color=(COLOR); |
+#define FAB_ballframe_border_set(FRAME,BORDER,BORDER_DIM,BORDER_COL) (FRAME)->border=(BORDER);(FRAME)->border_dim=(BORDER_DIM);(FRAME)->border_col=(BORDER_COL); |
+#define FAB_ballframe_color_set(FRAME,TRASPARENT_FLAG,COLOR) (FRAME)->trasparent=(TRASPARENT_FLAG);(FRAME)->color=(COLOR); |
+ |
+void FAB_ball_put(WORD cx, WORD cy, WORD r, COLOR c); |
+void FAB_image_get(FAB_IMAGE* image, WORD x, WORD y, WORD lx, WORD ly); |
+void FAB_image_put(FAB_IMAGE* image, WORD x, WORD y); |
+void FAB_image_put_within(FAB_IMAGE* image, WORD x0, WORD y0, |
+ WORD xx0, WORD yy0, WORD xx1, WORD yy1); |
+void FAB_image_copy(FAB_IMAGE* orig_image, FAB_IMAGE* dest_image); |
+void FAB_image_color_change(FAB_IMAGE* image, COLOR old_col, COLOR new_col); |
+void FAB_image_fill(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly); |
+void FAB_border_put(FAB_BORDER* border, WORD x0, WORD y0, WORD x1, WORD y1); |
+void FAB_ballborder_put(FAB_BORDER* border, WORD cx, WORD cy, WORD r_int); |
+void FAB_frame_put(FAB_FRAME* frame, WORD x0, WORD y0, WORD lx, WORD ly); |
+void FAB_ballframe_put(FAB_BALLFRAME* frame, WORD cx, WORD cy, WORD r); |
+//-------------------------------------------------- |
+ |
+// Altro... |
+ |
+//---------------------END--------------------------- |
+#endif |
Index: rel_1_4/bca/fab_lib/fab_show.h |
=================================================================== |
--- rel_1_4/bca/fab_lib/fab_show.h (nonexistent) |
+++ rel_1_4/bca/fab_lib/fab_show.h (revision 1488) |
@@ -0,0 +1,83 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: fab_show.h,v 1.2 2002-10-01 10:33:52 pj Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+/**************************************************** |
+ * * |
+ * file: FAB_show.h * |
+ * libreria: FAB_LIB * |
+ * version: 1.0 25/08/2002 * |
+ * creato da: Fabio CALABRESE * |
+ * * |
+ **************************************************** |
+ * * |
+ * descrizione: libreria di funzioni per stampare * |
+ * specifiche informazioni utili * |
+ * riguardo lo stato del sistema. * |
+ * * |
+ ****************************************************/ |
+ |
+#ifndef __FAB_LIB__FAB_show_h__ |
+#define __FAB_LIB__FAB_show_h__ |
+//-------------------BEGIN--------------------------- |
+ |
+// *** Librerie S.Ha.R.K *** |
+ |
+// *** Librerie Standard C *** |
+ |
+// *** Librerie FAB *** |
+#include "fab_msg.h" |
+ |
+// ----------- |
+// Definizioni |
+//---------------------- |
+//---------------------- |
+ |
+// ---------------- |
+// Funzioni & Macro |
+//------------------------------------------------- |
+void FAB_show_sched_modules(); |
+//-------------------------------------------------- |
+ |
+ |
+// Altro... |
+ |
+//----------------------END-------------------------- |
+#endif |
Index: rel_1_4/bca/fab_lib/fab_grx.sys |
=================================================================== |
--- rel_1_4/bca/fab_lib/fab_grx.sys (nonexistent) |
+++ rel_1_4/bca/fab_lib/fab_grx.sys (revision 1488) |
@@ -0,0 +1,71 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: fab_grx.sys,v 1.1 2002-10-01 10:25:02 pj Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+// file incluso da FAB_grx.h |
+// ------------------------- |
+ |
+typedef BYTE COLOR8; |
+typedef WORD COLOR15; |
+typedef WORD COLOR16; |
+typedef DWORD COLOR24; |
+typedef DWORD COLOR32; |
+ |
+#if defined FAB_GRX_15 |
+ #define __FAB_BPP 15 |
+ #define __FAB_rgb(R24,G24,B24) rgb15((R24),(G24),(B24)) |
+ typedef COLOR15 __FAB_COLOR; |
+#elif defined FAB_GRX_16 |
+ #define __FAB_BPP 16 |
+ #define __FAB_rgb(R24,G24,B24) rgb16((R24),(G24),(B24)) |
+ typedef COLOR16 __FAB_COLOR; |
+#elif defined FAB_GRX_24 |
+ #define __FAB_BPP 24 |
+ #define __FAB_rgb(R24,G24,B24) rgb24((R24),(G24),(B24)) |
+ typedef COLOR24 __FAB_COLOR; |
+#elif defined FAB_GRX_32 |
+ #define __FAB_BPP 32 |
+ #define __FAB_rgb(R24,G24,B24) rgb32((R24),(G24),(B24)) |
+ typedef COLOR32 __FAB_COLOR; |
+#else |
+ #define __FAB_BPP 16 |
+ #define __FAB_rgb(R24,G24,B24) rgb16((R24),(G24),(B24)) |
+ typedef COLOR16 __FAB_COLOR; |
+#endif |
Index: rel_1_4/bca/fab_lib/fab_tool.h |
=================================================================== |
--- rel_1_4/bca/fab_lib/fab_tool.h (nonexistent) |
+++ rel_1_4/bca/fab_lib/fab_tool.h (revision 1488) |
@@ -0,0 +1,90 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: fab_tool.h,v 1.1 2002-10-01 10:25:03 pj Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+/**************************************************** |
+ * * |
+ * file: FAB_tool.h * |
+ * libreria: FAB_LIB * |
+ * version: 1.0 25/08/2002 * |
+ * creato da: Fabio CALABRESE * |
+ * * |
+ **************************************************** |
+ * * |
+ * descrizione: tool di funzioni d'utilita' * |
+ * * |
+ ****************************************************/ |
+ |
+#ifndef __FAB_LIB__FAB_tool_h__ |
+#define __FAB_LIB__FAB_tool_h__ |
+//-------------------BEGIN--------------------------- |
+ |
+// *** Librerie S.Ha.R.K *** |
+// *** Librerie Standard C *** |
+#include <stdlib.h> |
+#include <math.h> |
+// *** Librerie FAB *** |
+ |
+// ----------- |
+// Definizioni |
+//---------------------- |
+//---------------------- |
+ |
+// ---------------- |
+// Funzioni & Macro |
+//------------------------------------------------- |
+#define FAB_PI 3.141592654 |
+#define FAB_grad(RADIANTI) RADIANTI/FAB_PI*180 |
+#define FAB_rad(GRADI) GRADI/180.0*FAB_PI |
+#define FAB_set_ang360(ANGOLO,X,Y) if ((X)>0) {if((Y)>0) (ANGOLO)=atan((Y)/(double)(X));else if((Y)<0) (ANGOLO)=atan((Y)/(double)(X))+2*FAB_PI;else (ANGOLO)=0;}else if ((X)<0) (ANGOLO)=atan((Y)/(double)(X))+FAB_PI;else /* X==0 */if ((Y)>0) (ANGOLO)=FAB_PI/2;else if ((Y)<0) (ANGOLO)=FAB_PI/2+FAB_PI;else /* Y==0 */ (ANGOLO)=-1; /* X=Y=0 */ |
+#define FAB_set_xy360(X,Y,MODULO,ANGOLO) (X)=(MODULO)*cos(ANGOLO);(Y)=(MODULO)*sin(ANGOLO); |
+ |
+#define FAB_ABS(X) ((X) > 0 ? (X) : (X)*-1) |
+ |
+#define FAB_sign_rand() (rand()%2 ? -1 : +1) |
+#define FAB_int_rand(MIN,MAX ) ((MIN) + rand()%((MAX)-(MIN)+1)) |
+#define FAB_double_rand(MIN,MAX) ((MIN) + ((MAX)-(MIN))*((double)rand()/RAND_MAX)) |
+//-------------------------------------------------- |
+ |
+ |
+// Altro... |
+ |
+//----------------------END-------------------------- |
+#endif |
Index: rel_1_4/bca/bca.h |
=================================================================== |
--- rel_1_4/bca/bca.h (nonexistent) |
+++ rel_1_4/bca/bca.h (revision 1488) |
@@ -0,0 +1,288 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: bca.h,v 1.2 2002-10-01 10:33:51 pj Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+/**************************************************** |
+ * * |
+ * file: bca.h * |
+ * included by: bca.c & bca_lib di cui fa da header* |
+ * data: 15/09/2002 * |
+ * creato da: Fabio CALABRESE * |
+ * * |
+ ****************************************************** |
+ * * |
+ * descrizione: contiene la definizione di variabili * |
+ * e strutture globali, con un corredo * |
+ * di macro e funzioni per la loro * |
+ * gestione, usate nel programma SHaRK * |
+ * "(B)ase(C)ontr(A)rea", il cui codice * |
+ * e' scritto nel file bca.c; * |
+ * il file bca_lib.c contiene il corpo * |
+ * di tutte le funzioni qui dichiarate. * |
+ * * |
+ ******************************************************/ |
+ |
+#ifndef __BCA_H__ |
+#define __BCA_H__ |
+//----------------BEGIN------------------ |
+ |
+// *** Librerie S.Ha.R.K *** |
+// *** Librerie Standard C *** |
+// *** Librerie FAB *** |
+#include"fab_lib/fab_grx.h" |
+#include"fab_lib/fab_tool.h" |
+// *** Librerie BCA *** |
+ |
+ |
+// --------------------------------- |
+// *** Elementi Grafici Generici *** |
+// --------------------------------- |
+ |
+// IMMAGINI: |
+FAB_IMAGE* image_sfondo; |
+FAB_IMAGE* image_bca; |
+FAB_IMAGE* image_aereo[4]; // 1 aereo per ogni direzione(soft e hard) |
+FAB_IMAGE* image_esplo[5]; // 5 immagini in sequenza simulanti |
+FAB_IMAGE* image_cannone[2]; // un esplosione |
+FAB_IMAGE* image_missile[2]; |
+ |
+// BORDI: |
+FAB_BORDER* border_blu7; |
+FAB_BORDER* border_verde7; |
+FAB_BORDER* border_rosso7; |
+FAB_BORDER* border_bianco7; |
+FAB_BORDER* border_giallo7; |
+ |
+// FRAME: |
+FAB_FRAME* frame_bca; |
+FAB_FRAME* frame_misure_oriz; |
+FAB_FRAME* frame_misure_vert; |
+FAB_FRAME* frame_misure_vert; |
+FAB_FRAME* frame_titolo; |
+FAB_FRAME* frame_comandi; |
+FAB_FRAME* frame_control; |
+ |
+// BALLFRAME: |
+FAB_BALLFRAME* ballframe_radar; |
+FAB_BALLFRAME* ballframe_lucerossa[3]; |
+ |
+// Base ContrAerea |
+#define BASE_L 1.0 // [Km]: lunghezza |
+#define BASE_H 2100 // [m]: altezza max di visibilita' |
+ |
+// Finestra Virtuale sullo schermo |
+#define FIN_X_MIN 20 // [pixel] |
+#define FIN_X_MAX 520-1 // [pixel] |
+#define FIN_Y_MIN 20 // [pixel] |
+#define FIN_Y_MAX 520-1 // [pixel] |
+// Inoltre si possono usare le seguenti + comode define |
+// con gli stessi valori: |
+#define X0 FIN_X_MIN |
+#define X1 FIN_X_MAX |
+#define Y0 FIN_Y_MIN |
+#define Y1 FIN_Y_MAX |
+// NB: non e' necessaria la proporzionalita' tra finestra |
+// reale(BASE_L*BASE_H) e virtuale((X1-X0)*(Y1-Y0))! |
+ |
+// Finestra Misure |
+#define FRAME_MISURE_LINE_COLOR FAB_green |
+#define FRAME_MISURE_BACK_COLOR FAB_black |
+#define FRAME_MISURE_ORIZ_LY 30 |
+#define FRAME_MISURE_VERT_LX 52 |
+ |
+// Finestra Titolo |
+#define FRAME_TITOLO_TEXT_COLOR1 FAB_yellow |
+#define FRAME_TITOLO_TEXT_COLOR2 FAB_white |
+#define FRAME_TITOLO_BACK_COLOR1 FAB_gray |
+#define FRAME_TITOLO_BACK_COLOR2 FAB_blue |
+ |
+// Finestra Comandi |
+#define FRAME_COMANDI_TEXT_COLOR1 FAB_yellow |
+#define FRAME_COMANDI_TEXT_COLOR2 FAB_white |
+#define FRAME_COMANDI_TEXT_COLOR3 FAB_red |
+#define FRAME_COMANDI_BACK_COLOR1 FAB_gray |
+#define FRAME_COMANDI_BACK_COLOR2 FAB_yellow |
+ |
+// Finestra Control |
+#define FRAME_CONTROL_TEXT_COLOR1 FAB_rgb( 50,255, 50) |
+#define FRAME_CONTROL_TEXT_COLOR2 FAB_rgb(150,255,150) |
+#define FRAME_CONTROL_BACK_COLOR FAB_black |
+ |
+// --------------------------------- |
+// *** Elementi Task Dummy_radar *** |
+// --------------------------------- |
+#define DUMMY_RADAR_GROUP 3 |
+#define DUMMY_RADAR_PERIOD 50000 |
+#define DUMMY_RADAR_WCET 400 |
+#define DUMMY_RADAR_MET 200 |
+ |
+// --------------------------------- |
+// *** Elementi Task Control *** |
+// --------------------------------- |
+#define CONTROL_PERIOD 50000 |
+#define CONTROL_WCET 400 |
+#define CONTROL_MET 300 |
+ |
+// --------------------------- |
+// *** Elementi Task Esplo *** |
+// --------------------------- |
+#define ESPLO_TRASPARENT_COL FAB_white |
+#define ESPLO_LX 40 |
+#define ESPLO_LY 40 |
+ |
+#define ESPLO_PERIOD 80000 |
+#define ESPLO_WCET 300 |
+#define ESPLO_MET 100 |
+ |
+// ----------------------------------- |
+// *** Elementi Task Aereo_Creator *** |
+// ----------------------------------- |
+#define AEREO_CREATOR_PERIOD 200000 |
+#define AEREO_CREATOR_WCET 300 |
+#define AEREO_CREATOR_MET 100 |
+ |
+// ----------------------------------- |
+// *** Elementi Task Cannone_Creator *** |
+// ----------------------------------- |
+#define CANNONE_CREATOR_PERIOD 1000000 |
+#define CANNONE_CREATOR_WCET 150 |
+#define CANNONE_CREATOR_MET 50 |
+ |
+// --------------------------- |
+// *** Elementi Task Aereo *** |
+// --------------------------- |
+#define AEREO_N_MAX 10 |
+#define AEREO_N_MIN 1 |
+ |
+#define AEREO_TRASPARENT_COL FAB_white |
+#define AEREO_BASE_COL FAB_green |
+#define AEREO_LX 32 |
+#define AEREO_LY 19 |
+#define AEREO_H_MIN 500 // [m]: altezza min di volo |
+#define AEREO_H_MAX 2000 // [m]: altezza max di volo (<BASE_H) |
+#define AEREO_L_MIN 0 // [km]: posizione 0 nella base |
+#define AEREO_L_MAX BASE_L // [km] posizione max nella base |
+#define AEREO_V_MIN 300.0 // [Km/h]: velocit min di volo |
+#define AEREO_V_MAX 500.0 // [Km/h]: velocit max di volo |
+#define AEREO_X_MIN X0 - AEREO_LX/2 |
+#define AEREO_X_MAX X1 + AEREO_LX/2 |
+ |
+#define AEREO_PERIOD 30000 |
+#define AEREO_WCET 1250 //Verificato! |
+#define AEREO_MET 800 |
+ |
+struct { BYTE status; //[0=free/1=occupato] |
+ BYTE killing; //richiesta uscita se 1 altrimenti 0 |
+ PID pid; |
+ COLOR color; |
+ FAB_IMAGE* image; |
+ double vel; //[km/h] |
+ int dir; //[+1/-1] |
+ WORD h; //[m] |
+ double l; //[km] |
+ WORD x, y; //[pixel] |
+ } aereo_table[AEREO_N_MAX]; |
+ |
+int aereo_count; |
+ |
+// ----------------------------- |
+// *** Elementi Task Cannone *** |
+// ----------------------------- |
+#define CANNONE_N_MAX 9 |
+#define CANNONE_N_MIN 1 |
+ |
+#define CANNONE_SENSIBILITA 200 //[m] |
+ |
+#define CANNONE_TRASPARENT_COL FAB_white |
+#define CANNONE_LX 33 |
+#define CANNONE_LY 15 |
+ |
+#define CANNONE_PERIOD 100000 |
+#define CANNONE_WCET 1000 |
+#define CANNONE_MET 100 |
+ |
+struct { BYTE status; //[0=free/1=occupato] |
+ BYTE killing; //richiesta uscita se 1 altrimenti 0 |
+ PID pid; |
+ BYTE fire; |
+ WORD x; |
+ double missile_vel; |
+ } cannone_table[CANNONE_N_MAX]; |
+ |
+int cannone_count; |
+ |
+// ----------------------------- |
+// *** Elementi Task Missile *** |
+// ----------------------------- |
+#define MISSILE_V_MIN 300.0 //[km/h] |
+#define MISSILE_V_MAX 5000.0 //[km/h] |
+#define MISSILE_ACC_MIN 100000.0 //[km/(h*h)] |
+#define MISSILE_ACC_MAX 10000000.0 //[km/(h*h)] |
+#define MISSILE_X_MAX X1 + MISSILE_LX/2 //[pixel] |
+#define MISSILE_X_MIN X0 - MISSILE_LX/2 //[pixel] |
+#define MISSILE_Y_MAX Y1 + MISSILE_LY/2 //[pixel] |
+#define MISSILE_Y_MIN Y0 - MISSILE_LY/2 //[pixel] |
+ |
+#define MISSILE_TRASPARENT_COL FAB_white |
+ |
+#define MISSILE_LX 7 //[pixel] |
+#define MISSILE_LY 15 //[pixel] |
+ |
+#define MISSILE_PERIOD 10000 |
+#define MISSILE_WCET 500 |
+#define MISSILE_MET 100 |
+ |
+ |
+ |
+ |
+ |
+// MUTEX: |
+mutex_t grx_mutex; //per l'accesso alla grafica |
+int app_mutex_init(mutex_t *m); |
+ |
+ |
+ |
+// FUNZIONI GESTIONE RISORSE DI MEMORIA: |
+void kern_init_bca(); |
+ |
+ |
+ |
+//------------------END------------------ |
+#endif |
Index: rel_1_4/bca/scenario.c |
=================================================================== |
--- rel_1_4/bca/scenario.c (nonexistent) |
+++ rel_1_4/bca/scenario.c (revision 1488) |
@@ -0,0 +1,168 @@ |
+/* |
+ * Project: S.Ha.R.K. |
+ * |
+ * Coordinators: |
+ * Giorgio Buttazzo <giorgio@sssup.it> |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * |
+ * Authors : |
+ * Paolo Gai <pj@gandalf.sssup.it> |
+ * Massimiliano Giorgi <massy@gandalf.sssup.it> |
+ * Luca Abeni <luca@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: scenario.c,v 1.1 2002-10-01 10:25:01 pj Exp $ */ |
+ |
+/* |
+ * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.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 |
+ * |
+ */ |
+ |
+//*************************** |
+//* file: scenario.c * |
+//* included by: bca.c * |
+//*************************** |
+ |
+void scenario_ca() |
+{ //SFONDO |
+ FAB_image_fill(image_sfondo,0,0,800,600); |
+ |
+ //FRAME_BCA |
+ FAB_frame_put(frame_bca,X0-7,Y0-7,500+7*2,500+7*2); |
+} |
+void scenario_misure() |
+{ int x, y, cx, cy; |
+ char* str_km ="X.Xkm"; |
+ char* str_m ="XXXXm"; |
+ int h; |
+ |
+ //FRAME_MISURE orizzontale |
+ FAB_frame_put(frame_misure_oriz, X0-7, Y1+7+20-7, |
+ 500+7*2, FRAME_MISURE_ORIZ_LY+7*2); |
+ cy = frame_misure_oriz->y0 + 10; |
+ cx = frame_misure_oriz->x0 + |
+ (frame_misure_oriz->x1 - frame_misure_oriz->x0) / 2; |
+ for(x=frame_misure_oriz->x0 ;x<frame_misure_oriz->x1+1 ;x+=5) |
+ grx_line(x,cy,x+2,cy,FRAME_MISURE_LINE_COLOR); |
+ for(y=frame_misure_oriz->y0; y<cy-1; y+=5) { |
+ grx_line(frame_misure_oriz->x0,y,frame_misure_oriz->x0,y+2,FRAME_MISURE_LINE_COLOR); |
+ grx_line(cx,y,cx,y+2,FRAME_MISURE_LINE_COLOR); |
+ grx_line(frame_misure_oriz->x1,y,frame_misure_oriz->x1,y+2,FRAME_MISURE_LINE_COLOR); |
+ } |
+ sprintf(str_km,"%02.1fkm",0.0); |
+ grx_text(str_km,frame_misure_oriz->x0+10,cy+2,FRAME_MISURE_LINE_COLOR,frame_misure_oriz->color); |
+ sprintf(str_km,"%02.1fkm",BASE_L/2.0); |
+ grx_text(str_km,cx-10,cy+2,FRAME_MISURE_LINE_COLOR,frame_misure_oriz->color); |
+ sprintf(str_km,"%02.1fkm",BASE_L); |
+ grx_text(str_km,frame_misure_oriz->x1-FRAME_MISURE_ORIZ_LY,cy+2,FRAME_MISURE_LINE_COLOR,frame_misure_oriz->color); |
+ |
+ //FRAME_MISURE verticale |
+ FAB_frame_put(frame_misure_vert, X1+7+20-7, Y0-7, |
+ FRAME_MISURE_VERT_LX+7*2, 500+7*2); |
+ cy = frame_misure_vert->y0 + |
+ (frame_misure_vert->y1 - frame_misure_vert->y0) / 2; |
+ cx = frame_misure_vert->x0 + 10; |
+ for(y=frame_misure_vert->y1; y>frame_misure_vert->y0-1; y-=5) |
+ grx_line(cx,y,cx,y-2,FRAME_MISURE_LINE_COLOR); |
+ h=0; |
+ for(y=frame_misure_vert->y1; y>frame_misure_vert->y0-1; |
+ y-=500.0*(X1-X0)/BASE_H, h+=500) { |
+ for(x=frame_misure_vert->x0; x<cx-1; x+=5) |
+ grx_line(x,y,x+2,y,FRAME_MISURE_LINE_COLOR); |
+ sprintf(str_m,"%dm",h); |
+ grx_text(str_m, cx+2, y-6, |
+ FRAME_MISURE_LINE_COLOR, frame_misure_vert->color); |
+ } |
+} |
+void scenario_radar() |
+{ FAB_ballframe_put(ballframe_radar, |
+ frame_bca->x1+7+30, frame_bca->y1+7+30, 30); |
+ FAB_ballframe_put(ballframe_lucerossa[2],605,546,20); |
+ FAB_ballframe_put(ballframe_lucerossa[1],594,578,15); |
+ FAB_ballframe_put(ballframe_lucerossa[0],574,591,10); |
+} |
+void scenario_titolo() |
+{ int x0,y0; |
+ x0 = frame_misure_vert->x1+7+20-7; |
+ y0 = frame_bca->y0-7; |
+ FAB_frame_put(frame_titolo,x0,y0,800-x0-20+7,170); |
+ x0 = frame_titolo->x0; |
+ y0 = frame_titolo->y0; |
+ grx_text(titolo[0],x0+2,y0+10,FRAME_TITOLO_TEXT_COLOR2,FRAME_TITOLO_BACK_COLOR1); |
+ grx_text(titolo[1],x0+2,y0+20,FRAME_TITOLO_TEXT_COLOR2,FRAME_TITOLO_BACK_COLOR1); |
+ grx_text(titolo[2],x0+2,y0+30,FRAME_TITOLO_TEXT_COLOR2,FRAME_TITOLO_BACK_COLOR1); |
+ grx_text(titolo[3],x0+2,y0+46,FRAME_TITOLO_TEXT_COLOR2,FRAME_TITOLO_BACK_COLOR1); |
+ grx_text(titolo[4],x0+2,y0+66,FRAME_TITOLO_TEXT_COLOR1,FRAME_TITOLO_BACK_COLOR2); |
+ grx_text(titolo[5],x0+2,y0+81,FRAME_TITOLO_TEXT_COLOR2,FRAME_TITOLO_BACK_COLOR1); |
+ grx_text(titolo[6],x0+2,y0+96,FRAME_TITOLO_TEXT_COLOR2,FRAME_TITOLO_BACK_COLOR1); |
+ grx_text(titolo[7],x0+2,y0+116,FRAME_TITOLO_TEXT_COLOR2,FRAME_TITOLO_BACK_COLOR1); |
+ grx_text(titolo[8],x0+2,y0+133,FRAME_TITOLO_TEXT_COLOR2,FRAME_TITOLO_BACK_COLOR1); |
+ grx_text(titolo[9],x0+2,y0+141,FRAME_TITOLO_TEXT_COLOR2,FRAME_TITOLO_BACK_COLOR1); |
+} |
+void scenario_comandi() |
+{ int x0, y0; |
+ x0 = frame_misure_vert->x1+7+20-7; |
+ y0 = frame_titolo->y1+7+20-7; |
+ FAB_frame_put(frame_comandi,x0,y0,800-x0-20+7,100+7*2); |
+ x0 = frame_comandi->x0; |
+ y0 = frame_comandi->y0; |
+ grx_text(" COMANDI \0",x0+2,y0+10,FRAME_COMANDI_TEXT_COLOR1,FRAME_COMANDI_BACK_COLOR1); |
+ grx_text("-------------------\0",x0+2,y0+20,FRAME_COMANDI_TEXT_COLOR2,FRAME_COMANDI_BACK_COLOR1); |
+ grx_text(" esci \0",x0+2,y0+40,FRAME_COMANDI_TEXT_COLOR2,FRAME_COMANDI_BACK_COLOR1); |
+ grx_text("[INVIO]",x0+2,y0+40,FRAME_COMANDI_TEXT_COLOR3,FRAME_COMANDI_BACK_COLOR2); |
+ grx_text(" +/- aerei \0",x0+2,y0+60,FRAME_COMANDI_TEXT_COLOR2,FRAME_COMANDI_BACK_COLOR1); |
+ grx_text("[1/2]",x0+2,y0+60,FRAME_COMANDI_TEXT_COLOR3,FRAME_COMANDI_BACK_COLOR2); |
+ grx_text(" +/- cannoni\0",x0+2,y0+80,FRAME_COMANDI_TEXT_COLOR2,FRAME_COMANDI_BACK_COLOR1); |
+ grx_text("[3/4]",x0+2,y0+80,FRAME_COMANDI_TEXT_COLOR3,FRAME_COMANDI_BACK_COLOR2); |
+} |
+void scenario_control() |
+{ int x0,y0; |
+ |
+ x0 = frame_misure_vert->x1+7+20-7; |
+ y0 = frame_comandi->y1+7+20-7; |
+ FAB_frame_put(frame_control,x0,y0,800-x0-20+7,frame_misure_vert->y1+7-y0); |
+ x0 = frame_control->x0; |
+ y0 = frame_control->y0; |
+ grx_text(" CONTROL \0",x0+2, y0+5,FRAME_CONTROL_TEXT_COLOR2,FRAME_CONTROL_BACK_COLOR); |
+ grx_line(x0-3, y0+15, |
+ frame_control->x1+3, y0+15, |
+ FRAME_CONTROL_TEXT_COLOR1); |
+ |
+ grx_line(x0-3, frame_control->y1-81, |
+ frame_control->x1+3, frame_control->y1-81, |
+ FRAME_CONTROL_TEXT_COLOR1); |
+} |
+void scenario() |
+{ scenario_ca(); |
+ scenario_misure(); |
+ scenario_radar(); |
+ scenario_titolo(); |
+ scenario_comandi(); |
+ scenario_control(); |
+} |
+ |
+void info() |
+{ int i; |
+ for(i=0; i<10; i++) kern_printf("%s\n",titolo[i]); |
+} |
Index: rel_1_4/bca/readme |
=================================================================== |
--- rel_1_4/bca/readme (nonexistent) |
+++ rel_1_4/bca/readme (revision 1488) |
@@ -0,0 +1,11 @@ |
+Hi, |
+ |
+This is a nice simulation made by Fabio Calabrese |
+(fabiocalabrese77@yahoo.it). |
+ |
+Documentation is also available in PDF form on the shark website (only |
+in italian, sorry). |
+ |
+Enjoy |
+ |
+PJ |
Index: rel_1_4/bca/bca_raw/esplo5.raw |
=================================================================== |
--- rel_1_4/bca/bca_raw/esplo5.raw (nonexistent) |
+++ rel_1_4/bca/bca_raw/esplo5.raw (revision 1488) |
@@ -0,0 +1,65 @@ |
+ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ)&ÿÿÿÿÿÿÿÿÿ |
+ÿÿÿÿÿÿ +*#! |
+.*% ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ):'+) :-65/1&&ÿÿÿÿÿÿ *-"&* %!&$)"%+-&% &!+%)&ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ |
+ ?.'O==D58F><$!ÿÿÿ=<EF&23FJ'16EI.;>)58%:=,10&$ +.(B= 7342)& |
+ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ $ )&.(:/G7'H7/@3-) 62& +* EE HJ MRNSHNOS2JN7Y\K<=/0/@@('& |
+<9B=D?SO)75-* ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ-.YW.uqDYP)[M3P@0SE8J>2/(1-XUzz$(v{!rv)Z^!BDWYC=>0=>0KK3BC#;;DEA?SP'JHVT#2/,) + ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ + +-ba3`{tHl_?cT=\L<`SBSH2`Y/xr(509z}&kn)QR*OO7VTGIJ:DE&EHJL47@?RQ!]\&[Z"KHTR, ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ !IGTQ$^W-ZM-aS9zkVj[Dj_Ai^1zq,.2}}aa;: LJ#CA*@>/A@+HJ"HMAF=BORBBXW!po9spEvsPÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ + *'! .(OD(cW?o`Ik]BylJqd8pc,x1>{"MJ 0/ 0,#!41 ,,;>EJOTZ_RU MOVU%_^0\Z4gfH$#ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ -)( +/,")#+#?4 i]GcU:i[6}nEmEuDzo-xr(^ZDB :6'%30//3627 9=BE`a7**! *'1-KH7*'ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ |
+-(.2-*A=4<8,*$ + &QC(eW2o`9E4]M,QE[Uzv9eb/63#!+*#% 47 |
+$& |