Subversion Repositories shark

Compare Revisions

Regard whitespace Rev 1450 → Rev 1451

/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);
}