Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1450 → Rev 1451

/demos/trunk/mix/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/mix/makefile
12,5 → 12,5
include $(BASE)/config/example.mk
 
mix:
make -f $(SUBMAKE) APP=mix INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __GRX__"
make -f $(SUBMAKE) APP=mix INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__"
 
/demos/trunk/mix/mix.c
18,11 → 18,11
 
/*
------------
CVS : $Id: mix.c,v 1.4 2003-03-24 11:18:19 pj Exp $
CVS : $Id: mix.c,v 1.5 2004-05-23 10:15:12 giacomo Exp $
 
File: $File$
Revision: $Revision: 1.4 $
Last update: $Date: 2003-03-24 11:18:19 $
Revision: $Revision: 1.5 $
Last update: $Date: 2004-05-23 10:15:12 $
------------
*/
 
50,14 → 50,15
/*--------------------------------------------------------------*/
 
#include <kernel/kern.h>
#include <drivers/glib.h>
#include <drivers/keyb.h>
 
#include <drivers/shark_fb26.h>
#include <drivers/shark_keyb26.h>
 
#include <semaphore.h>
#include <stdlib.h>
#include <math.h>
 
#define PIG 3.1415
#define ESC 27 /* ASCII code for ESCAPE */
#define DURATA 10000 /* counter duration in tick */
 
#define LW 200 /* window length */
73,7 → 74,6
#define YWM 165 /* top Y of MIDDLE window */
#define YWL 325 /* top Y of LOW window */
 
char fbuf[1000]; /* buffer for reading a file */
int flen; /* file length */
int fine = 0; /* ending flag */
 
90,6 → 90,21
" HARD REAL-TIME DEMO ",
" June 5, 2001 "};
 
char fbuf[1000] = "\
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\
------------------------------------------";
 
extern int vga16color[16];
 
/*------------------------------------------------------*/
/* file reading */
/*------------------------------------------------------*/
133,14 → 148,6
 
/*--------------------------------------------------------------*/
 
void byebye()
{
grx_close();
kern_printf("Bye Bye!\n");
}
 
/*--------------------------------------------------------------*/
 
void finish1()
{
sys_end();
188,7 → 195,7
sem_post(&mx_mat);
 
sem_wait(&mx_grf);
grx_line(x0, y0, xg, yg, 0);
grx_line(x0, y0, xg, yg, vga16color[0]);
sem_post(&mx_grf);
 
xg = x;
195,16 → 202,16
yg = y;
 
sem_wait(&mx_grf);
grx_line(x0, y0, xg, yg, 14);
grx_line(x0, y0, xg, yg, vga16color[14]);
sem_post(&mx_grf);
 
sem_wait(&mx_grf);
grx_text("0 :0 ", xt, yt, 14, 0);
grx_text("0 :0 ", xt, yt, vga16color[14], vga16color[0]);
sprintf(s, "%d", min);
grx_text(s, xt+8, yt, 14, 0);
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, 14, 0);
grx_text(s, xt+d, yt, vga16color[14], vga16color[0]);
sem_post(&mx_grf);
 
task_endcycle();
241,7 → 248,7
for (i=0; i<2; i++) { /* disegna goccia */
while (y < liv) {
sem_wait(&mx_grf);
grx_plot(x,y,col);
grx_plot(x,y,vga16color[col]);
sem_post(&mx_grf);
y++;
}
251,7 → 258,7
 
liv--;
sem_wait(&mx_grf);
grx_line(x0+1, liv, x0+DREC-1, liv, cliq);
grx_line(x0+1, liv, x0+DREC-1, liv, vga16color[cliq]);
sem_post(&mx_grf);
 
if (liv <= CIMA+1) { /* swap colors */
326,8 → 333,8
}
xg = x; yg = y;
sem_wait(&mx_grf);
grx_disc(ox,oy,LP,0);
grx_disc(xg,yg,LP,10);
grx_disc(ox,oy,LP,vga16color[0]);
grx_disc(xg,yg,LP,vga16color[10]);
sem_post(&mx_grf);
oy = yg; ox = xg;
t += dt;
387,7 → 394,7
y = y + Ay;
}
sem_wait(&mx_grf);
grx_plot(x+x0, y+y0, 10);
grx_plot(x+x0, y+y0, vga16color[10]);
sem_post(&mx_grf);
task_endcycle();
}
417,7 → 424,7
while (1) {
s[0] = talk[r][i];
sem_wait(&mx_grf);
grx_text(s,x+i*8,y+r*8,col+10,1);
grx_text(s,x+i*8,y+r*8,vga16color[col+10],vga16color[1]);
sem_post(&mx_grf);
i++;
if (i == leng) {
454,13 → 461,13
sem_post(&mx_mat);
 
sem_wait(&mx_grf);
grx_disc(xg, yg, 4, 0);
grx_disc(xg, yg, 4, vga16color[0]);
sem_post(&mx_grf);
 
xg = x; yg = y;
 
sem_wait(&mx_grf);
grx_disc(xg, yg, 4, 13);
grx_disc(xg, yg, 4, vga16color[13]);
sem_post(&mx_grf);
 
grad = (grad + 1) % 360;
495,7 → 502,7
y = (y + 10)%(HW-10);
*/
sem_wait(&mx_grf);
grx_box(x, y, x+9, y+9, col);
grx_box(x, y, x+9, y+9, vga16color[col]);
sem_post(&mx_grf);
 
task_endcycle();
540,17 → 547,17
sem_post(&mx_mat);
 
sem_wait(&mx_grf);
grx_line(x0, y0, xg, yg, 0);
grx_circle(xg, yg, 5, 0);
grx_disc(xg, yg, 4, 0);
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, col);
grx_circle(xg, yg, 5, col+2);
grx_disc(xg, yg, 4, col+1);
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();
648,23 → 655,24
NRT_TASK_MODEL m2;
KEY_EVT eva, evx, evs;
 
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT);
 
/* set the keyboard handler */
eva.ascii = 'a';
eva.scan = KEY_A;
eva.flag = 0;
keyb_hook(eva,kboar);
eva.status = KEY_PRESSED;
keyb_hook(eva,kboar,FALSE);
 
evx.ascii = 'x';
evx.scan = KEY_X;
evx.flag = ALTL_BIT;
keyb_hook(evx,finish1);
evx.status = KEY_PRESSED;
keyb_hook(evx,finish1,FALSE);
 
evs.ascii = ESC;
evs.scan = KEY_ESC;
evs.flag = 0;
keyb_hook(evs,finish2);
evs.status = KEY_PRESSED;
keyb_hook(evs,finish2,FALSE);
 
sem_init(&mx_mat,0,1);
sem_init(&mx_grf,0,1);
675,47 → 683,44
get_par();
keyb_getch(BLOCK);
 
grx_init();
grx_open(640, 480, 8);
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,YWH,XWL+LW,YWH+HW,14);
grx_rect(XWM,YWH,XWM+LW,YWH+HW,14);
grx_rect(XWR,YWH,XWR+LW,YWH+HW,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,YWM,XWL+LW,YWM+HW,14);
grx_rect(XWM,YWM,XWM+LW,YWM+HW,14);
grx_rect(XWR,YWM,XWR+LW,YWM+HW,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]);
 
grx_rect(XWL,YWL,XWL+LW,YWL+HW,14);
grx_rect(XWM,YWL,XWM+LW,YWL+HW,14);
grx_rect(XWR,YWL,XWR+LW,YWL+HW,14);
 
x0 = XWL + LW/2;
y0 = YWH + HW/2;
grx_circle(x0, y0, LLAN+3, 12);
grx_rect(XWL+74, YWH+7, XWL+120, YWH+22, 12);
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, 15);
grx_line(x0+DREC, CIMA, x0+DREC, FONDO, 15);
grx_line(x0, FONDO, x0+DREC, FONDO, 15);
grx_box(x0+1, CIMA, x0+DREC-1, FONDO-1, 14);
grx_text("Press A", XWM+16, YWH+48, 10, 0);
grx_text("to fill", XWM+16, YWH+64, 10, 0);
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, 10, 0);
grx_text("ESC to exit", XWM+18, YWM+HW-40, 10, 0);
grx_text("SPACE to create", XWM+18, YWM+HW-30, 10, 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, 14);
grx_disc(x0, y0, LLAN/3-1, 12);
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, 12);
grx_text("SYSTEM WORKLOAD:", x0+5, YWL+HLOAD-10, 10, 0);
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);
730,11 → 735,11
car = load(count);
y = (double)LLOAD*car;
sem_wait(&mx_grf);
grx_line(x0+x, y0-LLOAD+1, x0+x, y0, 0);
grx_line(x0+x, y0-y, x0+x, y0, 15);
grx_text(" ", x0+LW-60, YWL+HLOAD-10, 0, 0);
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, 15, 0);
grx_text(s, x0+LW-50, YWL+HLOAD-10, vga16color[15], vga16color[0]);
sem_post(&mx_grf);
x = (x + 1) % (LW-10);
}