Subversion Repositories shark

Compare Revisions

Regard whitespace Rev 1452 → Rev 1453

/demos/trunk/orbit/orbit.c
18,11 → 18,11
 
/*
------------
CVS : $Id: orbit.c,v 1.4 2003-05-01 19:44:07 pj Exp $
CVS : $Id: orbit.c,v 1.5 2004-05-23 11:27:29 giacomo Exp $
 
File: $File$
Revision: $Revision: 1.4 $
Last update: $Date: 2003-05-01 19:44:07 $
Revision: $Revision: 1.5 $
Last update: $Date: 2004-05-23 11:27:29 $
------------
*/
 
50,26 → 50,28
/****************************************************************/
 
#include <kernel/kern.h>
#include <drivers/glib.h>
#include <drivers/keyb.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 ESC 27 /* codice ASCII tasto ESCAPE */
#define XMAX 639 /* valore massimo coordinata X */
#define YMAX 479 /* valore massimo coordinata Y */
 
extern int vga16color[16];
 
struct coord {
double x;
double y;
};
 
char fbuf[1000]; // buffer for reading a file
int flen; // file length
 
double mass[MAX]; /* vettore masse pianeti */
float mass[MAX]; /* vettore masse pianeti */
struct coord pos[MAX]; /* vettore posizioni attuali */
struct coord vel[MAX]; /* vettore velocita' iniziali */
 
76,11 → 78,33
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 */
float G; /* Gravitazione Universale */
float tick; /* tick di sistema */
float delta; /* incremento temporale */
float scala; /* fattore grafico di scala */
 
char fbuf[1000] ="\
----------------------------------------------------\n\
period: 10000 wcet: 100\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: 6.0e21 0. 0. 0. 0.\n\
1: 1.0e21 10000. 8000. -60. 0.\n\
2: 1.0e8 5000. 0. 0. 80.\n\
3: 5.0e18 10000. 8000. -50. 0.\n\
4: 1.0e9 10000. 8000. -40. 20.\n\
5: 1.0e15 1000. 5000. -80. 0.\n\
6: 1.0e5 1000. 5000. -80. 0.\n\
7: 1.0e17 1000. 5000. -80. 0.\n\
8: 1.0e5 1000. 5000. -80. 0.\n\
9: 1.0e5 1000. 5000. -80. 0.\n\
10: 1.0e5 1000. 5000. -80. 0.\n\
----------------------------------------------------\n";
 
// -------------------------------------------------------
// NOTA: %f o %lf significa double e %nf significa float
// -------------------------------------------------------
95,13 → 119,6
 
/*--------------------------------------------------------------*/
 
void my_fine(void *arg)
{
grx_close();
}
 
/*--------------------------------------------------------------*/
 
int inside(int x, int y)
{
return ((x > RP) && (x < XMAX-RP) &&
161,8 → 178,8
col = i + 1;
 
sem_wait(&mutex);
grx_disc(ox,oy,r,0);
grx_disc(gx,gy,r,col);
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;
173,9 → 190,9
} while ((dist0 > 0) && inside(gx,gy));
 
sem_wait(&mutex);
grx_disc(ox,oy,r,0);
grx_disc(XGS,YGS,RT,12);
grx_circle(XGS,YGS,RT,14);
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;
190,19 → 207,13
HARD_TASK_MODEL m;
char c; /* carattere letto da tastiera */
 
sys_atrunlevel(my_fine, NULL, RUNLEVEL_BEFORE_EXIT);
 
sem_init(&mutex,0,1);
 
get_par();
keyb_getch(BLOCK);
 
grx_init();
grx_open(640, 480, 8);
grx_disc(XGS,YGS,RT,vga16color[12]);
grx_circle(XGS,YGS,RT,vga16color[14]);
 
grx_disc(XGS,YGS,RT,12);
grx_circle(XGS,YGS,RT,14);
 
np = 0;
 
do {
261,52 → 272,45
{
int x = 0;
int i;
double vx, vy;
float vx, vy;
 
flen = strlen(fbuf);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &period);
cprintf("period = %d\n", period);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &wcet);
cprintf("wcet = %d\n", wcet);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%f", &delta);
cprintf("delta = %f\n", delta);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%f", &scala);
cprintf("scala = %f\n", scala);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%f", &G);
cprintf("G = %20.15f\n", G);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &RP);
cprintf("RP = %d\n", RP);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &RT);
cprintf("RT = %d\n", RT);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &XGS);
cprintf("XGS = %d\n", XGS);
 
while ((fbuf[x] != ':') && (x < flen)) x++;
x++;
sscanf(&fbuf[x], "%d", &YGS);
cprintf("YGS = %d\n", YGS);
 
for (i=0; i<MAX; i++) {
while ((fbuf[x] != ':') && (x < flen)) x++;
330,10 → 334,6
x++;
sscanf(&fbuf[x], "%f", &vy);
vel[i].x = vx; vel[i].y = vy;
 
cprintf("mass[%d] = %f\t", i, mass[i]);
cprintf("pos: %f, %f\t", pos[i].x, pos[i].y);
cprintf("vel: %f, %f\n", vel[i].x, vel[i].y);
}
}
 
/demos/trunk/orbit/initfile.c
6,7 → 6,7
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
17,39 → 17,6
*/
 
/*
------------
CVS : $Id: initfile.c,v 1.1.1.1 2002-09-02 09:37:45 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:45 $
------------
 
System initialization file
 
This file contains the 2 functions needed to initialize the system.
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a RR (Round Robin) level
a CBS (Costant Bandwidth Server) level
a Dummy level
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
SOFT_TASK_MODEL (met, period) at level 1
NRT_TASK_MODEL at level 2
 
This file is similar to the configuration of kernel/init/hartik3.c
 
TICK is set to 0 (one-shot timer is used)
*/
 
/*
* 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
67,8 → 34,9
*/
 
#include "kernel/kern.h"
#include "modules/intdrive.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "modules/hardcbs.h"
#include "modules/rr.h"
#include "modules/dummy.h"
 
76,31 → 44,47
#include "modules/hartport.h"
#include "modules/cabs.h"
 
#include "drivers/keyb.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 10000
#define RRTICK 2000
 
void read_file();
/*+ 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;
 
EDF_register_level(0);
CBS_register_level(0, 0);
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();
//read_file();
 
return TICK;
}
109,16 → 93,108
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
KEYB_PARMS kparms = BASE_KEYB;
 
HARTPORT_init();
 
keyb_def_ctrlC(kparms, NULL);
keyb_def_map(kparms,itaMap);
KEYB_init(&kparms);
/* 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/trunk/orbit/makefile
12,5 → 12,5
include $(BASE)/config/example.mk
 
orbit:
make -f $(SUBMAKE) APP=orbit INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __GRX__"
make -f $(SUBMAKE) APP=orbit INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__"