Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1465 → Rev 1464

/demos/trunk/fsdemo/mplay.c
0,0 → 1,393
/*
* 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) 1999 Luca Abeni and 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: mplay.c,v 1.3 2003-05-01 19:44:07 pj Exp $
*
* File: $File$
* Revision: $Revision: 1.3 $
* Last update: $Date: 2003-05-01 19:44:07 $
*/
 
#include "config.h"
 
//#include <ll/sys/types.h>
 
#include <kernel/func.h>
#include <kernel/const.h>
 
#include <trace/trace.h>
#include <trace/queues.h>
 
#include <drivers/glib.h>
#include <drivers/gd.h>
#include <drivers/keyb.h>
 
#include <fs/bdevinit.h>
#include <fs/fsinit.h>
#include <fs/bdev.h>
 
#include <sys/types.h>
#include <sys/mount.h>
 
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
 
#include "gclock.h"
#include "gvideo.h"
#include "gload.h"
#include "gbuffer.h"
#include "gphoto.h"
#include "mutex.h"
#include "xread.h"
 
void ctrlc_exit(KEY_EVT *k)
{
extern void dump_sem_table(void);
extern void dump_nop_table(void);
#ifndef NOGRX
grx_close();
#endif
cprintf("CTRL-C pressed!\n");
sys_end();
}
 
/*
*
*
*
*/
 
int __register_sub_init_prologue(void)
{
// int id;
#ifndef NOTRACE
TRC_init_phase1(NULL);
trc_register_fixed_queue();
id=trc_create_queue(TRC_FIXED_QUEUE,NULL);
trc_trace_class(TRC_CLASS_USER);
trc_assign_class_to_queue(TRC_CLASS_USER,id);
#endif
return 0;
}
 
int __register_sub_init(void)
{
#if defined(EDFSCHED)
extern void BD_EDF_register_module(void);
BD_EDF_register_module();
#elif defined(PSCANSCHED)
extern void BD_PSCAN_register_module(void);
BD_PSCAN_register_module();
#endif
return 0;
}
 
dev_t root_device=-1;
dev_t temp_device=-1;
 
int choose_root_callback(dev_t dev,u_int8_t fs)
{
if (fs==FS_MSDOS) return dev;
return -1;
}
 
int choose_temp_callback(__dev_t dev,__uint8_t fs)
{
static int flag=0;
if (fs==FS_MSDOS) {
if (flag) return dev;
flag=1;
}
return -1;
}
 
int __bdev_sub_init(void)
{
BDEV_PARMS bdev=BASE_BDEV;
bdev_def_showinfo(bdev,FALSE);
bdev_init(&bdev);
 
root_device=bdev_scan_devices(choose_root_callback);
if (root_device<0) {
sys_shutdown_message("can't find root device to mount on /!!!\n");
sys_end();
return -1;
}
 
/*
temp_device=bdev_scan_devices(choose_temp_callback);
if (temp_device<0) {
cprintf("can't find a filesystem to mount on /TEMP!!!\n");
}
*/
return 0;
}
 
int __fs_sub_init(void)
{
extern int libc_initialize(void);
FILESYSTEM_PARMS fs=BASE_FILESYSTEM;
// struct mount_opts opts;
// int res;
filesystem_def_rootdevice(fs,root_device);
filesystem_def_fs(fs,FS_MSDOS);
filesystem_def_showinfo(fs,FALSE);
filesystem_init(&fs);
 
/*
if (temp_device>=0) {
memset(&opts,0,sizeof(struct mount_opts));
opts.flags=MOUNT_FLAG_RW;
res=mount(temp_device,FS_MSDOS,"/TEMP",&opts);
if (res!=0) {
cprintf("can't mount XXX on /TEMP (errno: %i)\n",errno);
} else
cprintf("mounted /TEMP rw\n");
}
*/
libc_initialize();
 
#ifndef NOTRACE
TRC_init_phase2();
#endif
return 0;
}
 
/*
*
*
*
*/
 
struct {
char *filename;
int bitrate;
int framerate;
} mpegs[16]={
/* 0 */
{"/temp/m/2jaeger.mpg", 573225, 3000}, /* 3.27 bad*/
{"/temp/m/alien.mpg", 289000, 2500}, /* 10.12 I */
{"/temp/m/b0.mpg", 1725251, 3000}, /* 3.33 IBBPBBPBBPBB */
{"/temp/m/canyon.mpg", 237194, 3000}, /* 58.60 IBBPBB */
/* 4 */
{"/temp/m/earth-ci.mpg", 974900, 2500}, /* 28.80 IBBPBB */
{"/temp/m/flower.mpg", 1147101, 2997}, /* 5.01 bad */
{"/temp/m/frisco.mpg", 397262, 3000}, /* 1.70 bad */
{"/temp/m/hulahoop.mpg", 684126, 3000}, /* 1.33 bad */
/* 8 */
{"/temp/m/iicm.mpg", 527308, 3000}, /* 26.70 bad */
{"/temp/m/micky.mpg", 711240, 3000}, /* 0.66 bad */
{"/temp/m/mobile.mpg", 114622, 2997}, /* 5.01 bad */
{"/temp/m/redsnigh.mpg", 597776, 2500}, /* 48.40 IBBBBBBBBBPBBBBBBBBB*/
/* 12 */
{"/temp/m/son.mpg", 1134335, 2500}, /* 6.92 IBBPBBPBBPBB */
{"/temp/m/stoelend.mpg", 2248942, 3000}, /* 0.53 IBBPBB */
{"/temp/m/sukhoi.mpg", 481521, 3000}, /* 25.47 I */
{"/temp/m/us.mpg", 681599, 3000} /* 24.37 IBBPBB */
};
 
#define DEFINDEX 3
 
char *getfilename(int index)
{
return mpegs[index%16].filename;
}
 
int getbitrate(int index)
{
return mpegs[index%16].bitrate;
}
 
int getframerate(int index)
{
return mpegs[index%16].framerate;
}
 
/*
*
*
*
*/
 
#ifdef FULLCOLOR
 
#define TEXTCOLOR rgb16(0,255,0)
#define TEXTCOLOR2 rgb16(255,255,255)
#define TEXTBG rgb16(0,0,0)
 
#else
 
#define TEXTCOLOR 255
#define TEXTCOLOR2 255
#define TEXTBG 0
 
#endif
 
#define SCREENX 800
#define SCREENY 600
 
#define MAINSLEEP 20000
 
g_sem_t grxsem;
 
int main(int argc, char *argv[])
{
struct gvideoinfo info;
KEY_EVT k;
int index;
int mode;
int esc;
int pid,grp;
// int i;
int sx=20;
PID ph1,ph2,ph3;
g_sem_init(&grxsem,1);
 
/*
if (argc<2) {
cprintf("Usage: %s mpegfileordinal\n",argv[0]);
sys_abort(301);
}
*/
/* init the "file reader tasks" module */
x_init();
 
/* Init the graph... */
#ifndef NOGRX
if (grx_init()==-1) {
cprintf("No init!!!\n");
sys_abort(255);
}
#ifdef FULLCOLOR
mode=grx_getmode(SCREENX,SCREENY,16);
#else
mode=grx_getmode(SCREENX,SCREENY,8);
#endif
if (mode==-1) {
cprintf("Mode not present!!!\n");
sys_abort(255);
}
#endif
cprintf("[hit enter to continue]\n");
esc=FALSE;
while (!esc) {
keyb_getcode(&k,BLOCK);
if (k.ascii==13) esc=TRUE;
}
#ifndef NOGRX
if (grx_setmode(mode) == -1) {
cprintf("No SetMode!!!\n");
sys_abort(255);
}
#endif
 
#ifndef NOGRX
grx_text("HARTIK 4.0 (Lego)",12*2,22,TEXTCOLOR,TEXTBG);
grx_text("[Filesystem demo]",12*2,22+10,TEXTCOLOR,TEXTBG);
 
grx_text("Video : 8bit/pixel",250,450,TEXTCOLOR2,TEXTBG);
grx_text("Double buffer: YES",250,450+10,TEXTCOLOR2,TEXTBG);
grx_text("Algorithm : FCFS",250,450+20,TEXTCOLOR2,TEXTBG);
#endif
pid=gclock_init(32+64+64,540);
task_activate(pid);
 
//for (i=0;i<argc-1;i++) {
 
//index=atoi(argv[i+1]);
index=4;
 
info.x=sx+30;
info.y=80;
info.pathname=getfilename(index);
info.bitrate=getbitrate(index);
info.framerate=getframerate(index);
info.band=25;
 
grp=gvideo_init("Video: earth.mpg", &info);
//if (grp>0) group_activate(grp);
 
sx+=info.w+15;
//}
 
pid=gload_init(1);
task_activate(pid);
 
ph1=gphoto_show("Photo: galaxy","/temp/b/ph2a.bmp",500,25);
ph2=gphoto_show("Photo: canyon","/temp/b/ph3a.bmp",500,225);
ph3=gphoto_show("Photo: nicole","/temp/b/ph7a.bmp",500,425);
if (grp>0) group_activate(grp);
 
esc=0;
 
{
struct timespec delay;
 
delay.tv_sec = MAINSLEEP/1000000;
delay.tv_nsec = (MAINSLEEP%1000000)*1000;
 
while (!esc) {
if (keyb_getcode(&k,NON_BLOCK)) {
if(k.ascii==13) esc=1;
else if (k.ascii=='a') task_activate(ph1);
else if (k.ascii=='s') task_activate(ph2);
else if (k.ascii=='d') task_activate(ph3);
}
nanosleep(&delay, NULL);
}
}
 
#ifndef NOGRX
grx_close();
#endif
sys_end();
return 0;
}
/demos/trunk/fsdemo/makefile
0,0 → 1,16
#
#
#
 
ifndef BASE
BASE=../..
endif
include $(BASE)/config/config.mk
 
PROGS= mplay
 
include $(BASE)/config/example.mk
 
mplay:
make -f $(SUBMAKE) APP=mplay INIT= OTHEROBJS="xread.o gclock.o gvideo.o gload.o gbuffer.o gphoto.o initfile.o" OTHERINCL="-I$(BASE)/ports" SHARKOPT="__OLDCHAR__ __GRX__"
 
/demos/trunk/fsdemo/xread.c
0,0 → 1,240
/*
*
*
*
*
*/
 
#include "config.h"
 
#include <ll/i386/cons.h>
 
#include <kernel/func.h>
#include <kernel/int_sem.h>
#define seminit(s,v) internal_sem_init(s,v)
#define semwait(s) internal_sem_wait(s)
#define semsignal(s) internal_sem_post(s)
 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
 
#include <assert.h>
 
#include "xread.h"
 
/**/
 
/*
*/
 
#ifndef ACTIVATE
int x_fseek(FILE *file, long where, int from)
{
return fseek(file,where,from);
}
 
size_t x_fread(void *buffer, size_t size, size_t n, FILE *file)
{
return fread(buffer,size,n,file);
}
 
void x_init(void)
{}
 
int x_initbuffer(int group, FILE *f, int rate, int band)
{
return XUNUSEDPID;
}
 
#endif
 
#ifdef ACTIVATE
int x_fseek(FILE *file, long where, int from)
{
return -1;
}
 
#define BLOCKSIZE (512*4)
#define BLOCKSPERBUFFER (BUFFERMAXSIZE/BLOCKSIZE)
 
/* in millisecondi */
#define PRELOAD 500
 
struct xbuffer *table[OPEN_MAX];
 
int end_counter=0;
 
static TASK bufferfiller(void *arg)
{
struct xbuffer *ptr=(struct xbuffer *)arg;
int n;
 
for (;;) {
if (freespace(ptr)>BLOCKSIZE+8) {
//assert(ptr->writeptr>=0);
//assert(ptr->writeptr+BLOCKSIZE<=BUFFERMAXSIZE);
n=read(ptr->handle,ptr->buffer+ptr->writeptr,BLOCKSIZE);
#ifdef NOGRX
cprintf("²");
#endif
kern_cli();
ptr->writeptr+=n;
/* ipotesi: non si legge mai piu' di BUFFERMAXSIZE */
if (ptr->writeptr>=BUFFERMAXSIZE) ptr->writeptr-=BUFFERMAXSIZE;
kern_sti();
if (n!=BLOCKSIZE) {
//cprintf("<XXX>");
break;
}
//assert(ptr->writeptr%512==0);
}
task_endcycle();
}
end_counter++;
return NULL;
}
 
void x_init(void)
{
int i;
for (i=0;i<OPEN_MAX;i++) table[i]=NULL;
}
 
/* rate in bits/sec */
/* band in percentuale *100 */
int x_initbuffer(int group, FILE *f, int rate, int band)
{
#ifdef EDFSCHED
BDEDF_RES_MODEL resource;
#endif
#ifdef PSCANSCHED
BDPSCAN_RES_MODEL resource;
#endif
SOFT_TASK_MODEL model;
struct xbuffer *ptr;
int handle;
int period,wcet;
int n,preload;
PID pid;
handle=fileno(f);
if (handle>OPEN_MAX||handle<0) return -11;
 
if (table[handle]!=NULL) return -2;
 
ptr=table[handle]=(struct xbuffer *)malloc(sizeof(struct xbuffer));
if (ptr==NULL) return -3;
 
ptr->handle=handle;
ptr->writeptr=ptr->readptr=0;
n=lseek(ptr->handle,0,SEEK_SET);
if (n!=0) {
cprintf("can't seek to 0\n");
return -12;
}
/* PRELOAD */
preload=rate*PRELOAD/8/1000;
if (preload<100*1024) preload=100*1024;
preload=(preload/BLOCKSIZE+1)*BLOCKSIZE;
if (preload>BUFFERMAXSIZE-BLOCKSIZE) return -4;
n=read(ptr->handle,ptr->buffer,preload);
if (n!=preload) {
cprintf("preload: request %li bytes (%li returned)\n",
(long)preload,(long)n);
return -5;
}
ptr->writeptr+=n;
 
//cprintf("%li bytes preloaded\n",(long)n);
if (rate==0) sys_abort(997);
period=1000000l*BLOCKSIZE/rate*8;
wcet=period*band/10000;
soft_task_default_model(model);
soft_task_def_met(model,wcet);
soft_task_def_wcet(model,wcet);
soft_task_def_period(model,period);
soft_task_def_periodic(model);
soft_task_def_arg(model,(void*)ptr);
soft_task_def_group(model,group);
 
#if defined(EDFSCHED)
BDEDF_res_default_model(resource);
BDEDF_res_def_dl(resource,period);
pid=task_createn("xfill", bufferfiller,(TASK_MODEL*)&model, &resource, NULL);
#elif defined(PSCANSCHED)
BDPSCAN_res_default_model(resource);
BDPSCAN_res_def_priority(resource,0);
pid=task_createn("xfill", bufferfiller,(TASK_MODEL*)&model, &resource, NULL);
#else
pid=task_create("xfill", bufferfiller, &model, NULL);
#endif
if (pid!=-1) {
cprintf("task wcet=%10li period=%10li\n",(long)wcet,(long)period);
}
return pid;
}
 
size_t x_fread(void *buffer, size_t objsize, size_t n, FILE *file)
{
struct xbuffer *ptr;
int size,sz;
int nv;
ptr=table[fileno(file)];
if (ptr==NULL) {
cprintf("x_fread with bad fd\n");
return 0;
}
size=objsize*n;
//cprintf("[for %i]",size);
REDO:
if (filledspace(ptr)<size) {
/*
cprintf("x_fread called for %li bytes (%li available)\n",
(long)size,
(long)filledspace(ptr));
*/
nv=n;
n=filledspace(ptr)/objsize;
if (n==0) {
struct timespec delay;
delay.tv_sec=0;
delay.tv_nsec=15000000;
n=nv;
nanosleep(&delay, 0);
goto REDO;
return 0;
}
size=objsize*n;
/*cprintf("%i will return\n",size);*/
}
sz=BUFFERMAXSIZE-ptr->readptr;
if (sz>=size) {
//cprintf("X");
memcpy(buffer,ptr->buffer+ptr->readptr,size);
} else {
//cprintf("Y");
memcpy(buffer,ptr->buffer+ptr->readptr,sz);
assert(size-sz>0);
memcpy(buffer+sz,ptr->buffer,size-sz);
}
 
kern_cli();
ptr->readptr+=size;
/* ipotesi: non si legge mai piu' di BUFFERMAXSIZE */
if (ptr->readptr>=BUFFERMAXSIZE) ptr->readptr-=BUFFERMAXSIZE;
kern_sti();
return n;
}
 
#endif
/demos/trunk/fsdemo/gphoto.c
0,0 → 1,302
/*
* 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) 1999 Luca Abeni and 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: gphoto.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 $
*/
 
#include "config.h"
 
#include <kernel/func.h>
#include <kernel/model.h>
#include <kernel/const.h>
 
#include <drivers/glib.h>
 
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
 
#include "mutex.h"
#include "gphoto.h"
 
#ifdef FULLCOLOR
#define COLORFG rgb16(255,255,255)
#define COLORBG rgb16(0,0,0)
#else
#define COLORFG 255
#define COLORBG 0
#endif
 
#ifdef FULLCOLOR
 
/* 16bits format 5:6:5 */
/* 24bits format 8:8:8 */
static void down24to16(int h ,
WORD *dst, BYTE *src,
int xs, int ys, int dx, int dy)
{
WORD *pdst;
BYTE *psrc;
int x,y;
int n;
/* row must be multiple of 4!!! (there are 3 bytes per pixel!)*/
for (y=0;y<dy;y++) {
psrc=src;
pdst=dst;
 
n=read(h,src,dx*3);
if (n!=dx*3) return;
for (x=0;x<dx;x++,psrc+=3,pdst++)
/* blue green red */
*pdst=((psrc[0]&0xf8)>>3)|((psrc[1]&0xfc)<<3)|((psrc[2]&0xf8)<<8);
 
#ifndef NOGRX
grxlock();
grx_putimage(xs, ys+dy-y-1, xs+dx-1, ys+dy-y-1, dst);
grxunlock();
#endif
 
}
}
 
#define downscaleimage(h,x,y,a,b,c,d) down24to16(h,(WORD*)x,y,a,b,c,d)
 
#else
 
static void down24to8(int h,
BYTE *dst, BYTE *src,
int xs, int ys, int dx, int dy)
{
BYTE *pdst;
BYTE *psrc;
int x,y;
int n;
/* row must be multiple of 4!!! (there are 3 bytes per pixel!)*/
for (y=0;y<dy;y++) {
psrc=src;
pdst=dst;
 
n=read(h,src,dx*3);
if (n!=dx*3) return;
for (x=0;x<dx;x++,psrc+=3,pdst++)
*pdst=(((int)psrc[0])*11+((int)psrc[1])*59+((int)psrc[2])*30)/100;
 
#ifndef NOGRX
grxlock();
grx_putimage(xs, ys+dy-y-1, xs+dx-1, ys+dy-y-1, dst);
grxunlock();
#endif
 
}
}
 
#define downscaleimage(h,x,y,a,b,c,d) down24to8(h,x,y,a,b,c,d)
 
#endif
 
/*
*
*/
 
struct taskinfo {
int h;
BYTE *dst,*src;
int x,y;
int dx,dy;
};
 
static TASK phototask(void *arg)
{
struct taskinfo *p=(struct taskinfo *)arg;
 
downscaleimage(p->h,p->dst,p->src,p->x,p->y,p->dx,p->dy);
 
free(p->dst);
free(p->src);
close(p->h);
 
free(arg);
return NULL;
}
 
 
/*
*
*/
 
extern void draw_frame(int x, int y, int dx, int dy);
 
int gphoto_show(char *title, char *pathname, int x, int y)
{
NRT_TASK_MODEL model;
struct BITMAPFILEHEADER *bf;
struct BITMAPINFOHEADER *bi;
struct taskinfo *info;
BYTE *src,*dst;
long l;
int h,n;
int dx,dy;
PID pid;
bf=(struct BITMAPFILEHEADER *)malloc(sizeof(struct BITMAPFILEHEADER));
bi=(struct BITMAPINFOHEADER *)malloc(sizeof(struct BITMAPINFOHEADER));
 
if (bf==NULL||bi==NULL) return -11;
 
h=open(pathname,O_RDONLY);
if (h==-1) {
free(bf);
free(bi);
return -2;
}
 
n=read(h,bf,sizeof(struct BITMAPFILEHEADER));
if (n!=sizeof(struct BITMAPFILEHEADER)) {
close(h);
free(bf);
free(bi);
return -4;
}
 
n=read(h,bi,sizeof(struct BITMAPINFOHEADER));
if (n!=sizeof(struct BITMAPINFOHEADER)) {
close(h);
free(bf);
free(bi);
return -4;
}
//grx_close();
 
/*
cprintf("type: %c %c\n",bf->bfType&0xff,bf->bfType>>8);
cprintf("size: %li\n",bf->bfSize);
cprintf("tell: %li\n\n",bf->bfOffBits);
 
cprintf("bitcoutn: %i\n",bi->biBitCount);
cprintf("compress: %li\n",bi->biCompression);
cprintf("dx: %li\n",bi->biWidth);
cprintf("dy: %li\n",bi->biHeight);
*/
//sys_end();
//return 0;
if (bf->bfType!='B'+256*'M'||
bi->biBitCount!=24||
bi->biCompression!=0||
bi->biWidth%4!=0) {
close(h);
free(bf);
free(bi);
return -5;
}
dx=bi->biWidth;
dy=bi->biHeight;
src=(BYTE*)malloc(dx*3);
if (src==NULL) {
close(h);
free(bf);
free(bi);
return -6;
}
 
dst=(BYTE*)malloc(dx*2);
if (dst==NULL) {
free(src);
close(h);
free(bf);
free(bi);
return -6;
}
 
l=lseek(h,bf->bfOffBits,SEEK_SET);
if (l!=bf->bfOffBits) {
free(dst);
free(src);
close(h);
free(bf);
free(bi);
return -7;
}
 
#ifndef NOGRX
draw_frame(x,y,dx,dy);
grxlock();
grx_text(title,x,y-14,COLORFG,COLORBG);
grxunlock();
#endif
 
free(bi);
free(bf);
 
info=(struct taskinfo *)malloc(sizeof(struct taskinfo));
if (info==NULL) {
free(dst);
free(src);
close(h);
return -8;
}
info->h=h;
info->src=src;
info->dst=dst;
info->x=x;
info->y=y;
info->dx=dx;
info->dy=dy;
nrt_task_default_model(model);
nrt_task_def_arg(model,info);
pid=task_create("Photo",phototask,&model,NULL);
return pid;
}
/demos/trunk/fsdemo/gclock.c
0,0 → 1,81
 
#include "config.h"
 
#include <kernel/func.h>
#include <kernel/const.h>
#include <kernel/model.h>
#include <kernel/types.h>
 
#include <drivers/glib.h>
 
#include <stdlib.h>
 
#include "mutex.h"
#include "gclock.h"
 
#ifdef FULLCOLOR
#define COLORFG rgb16(255,255,255)
#define COLORBG rgb16(0,0,0)
#else
#define COLORFG 255
#define COLORBG 0
#endif
 
struct info {
int x;
int y;
};
 
static TASK grxclock(struct info *ptr)
{
char buffer[16];
int min,sec;
 
min=sec=0;
for (;;) {
sprintf(buffer,"%02i:%02i",min,sec);
#ifndef NOGRX
grxlock();
grx_text(buffer,ptr->x,ptr->y,COLORFG,COLORBG);
grxunlock();
#endif
sec++;
if (sec==60) {
sec=0;
min++;
if (min==60) min=0;
}
task_endcycle();
}
return NULL;
}
 
PID gclock_init(int x, int y)
{
SOFT_TASK_MODEL model;
struct info *ptr;
 
ptr=(struct info *)malloc(sizeof(struct info));
if (ptr==NULL) return -1;
ptr->x=x+1;
ptr->y=y+1;
#ifndef NOGRX
grxlock();
grx_box(x-1,y-1,x+GCLOCKDX-1,y+GCLOCKDY-1,COLORBG);
grx_rect(x-1,y-1,x+GCLOCKDX-1,y+GCLOCKDY-1,COLORFG);
grx_text("00:00",ptr->x,ptr->y,COLORFG,COLORBG);
grx_text("Clock",ptr->x,ptr->y-12,COLORFG,COLORBG);
grxunlock();
#endif
soft_task_default_model(model);
soft_task_def_met(model,5000);
soft_task_def_wcet(model,5000);
soft_task_def_period(model,1000000);
soft_task_def_periodic(model);
soft_task_def_arg(model,(void*)ptr);
//soft_task_def_ctrl_jet(model);
return task_create("grxclock", grxclock, &model, NULL);
}
/demos/trunk/fsdemo/initfile.c
0,0 → 1,119
/*
* 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: 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 $
*/
 
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/rr.h"
#include "modules/cbs.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"
#include "modules/nopm.h"
 
#include "drivers/keyb.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;
extern int __register_sub_init_prologue(void);
extern int __register_sub_init(void);
 
__register_sub_init_prologue();
 
EDF_register_level(EDF_ENABLE_ALL);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
CBS_register_level(CBS_ENABLE_ALL, 0);
dummy_register_level();
 
SEM_register_module();
 
CABS_register_module();
 
PI_register_module();
PC_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
NOPM_register_module();
 
__register_sub_init();
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
KEYB_PARMS keyb = BASE_KEYB;
extern int __bdev_sub_init(void);
extern int __fs_sub_init(void);
extern void ctrlc_exit(KEY_EVT *k);
HARTPORT_init();
keyb_def_ctrlC(keyb, ctrlc_exit);
KEYB_init(&keyb);
 
__bdev_sub_init();
__fs_sub_init();
__call_main__(mb);
 
return (void *)0;
}
 
/demos/trunk/fsdemo/gphoto.h
0,0 → 1,42
/*
*
*
*/
 
#ifndef __GPHOTO_H
#define __GPHOTO_H
 
#include <ll/sys/types.h>
 
struct BITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} __attribute__((packed));
 
struct BITMAPINFOHEADER {
DWORD biSize;
DWORD biWidth;
DWORD biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
DWORD biXPelsPerMeter;
DWORD biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} __attribute__((packed));
 
struct RGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserverd;
} __attribute__((packed));
 
int gphoto_show(char *title, char *pathname, int x, int y);
 
#endif
/demos/trunk/fsdemo/mutex.h
0,0 → 1,32
 
#ifndef __GRXMUTEX_H
#define __GRXMUTEX_H
 
#include "config.h"
 
#ifdef GRXMUTEX
 
#include <kernel/int_sem.h>
 
#define g_sem_t internal_sem_t
 
#define g_sem_init(s,value) internal_sem_init(s,value)
#define g_sem_wait(s) internal_sem_wait(s)
#define g_sem_signal(s) internal_sem_post(s)
 
#else
 
#define g_sem_t int
 
#define g_sem_init(s,value)
#define g_sem_wait(s)
#define g_sem_signal(s)
 
#endif
 
extern g_sem_t grxsem;
 
#define grxlock() g_sem_wait(&grxsem)
#define grxunlock() g_sem_signal(&grxsem)
 
#endif
/demos/trunk/fsdemo/gclock.h
0,0 → 1,13
 
 
#ifndef __GCLOCK_H
#define __GCLOCK_H
 
#include <kernel/types.h>
 
PID gclock_init(int x, int y);
 
#define GCLOCKDX (5*8+2)
#define GCLOCKDY (1*8+2)
 
#endif
/demos/trunk/fsdemo/xread.h
0,0 → 1,46
 
#ifndef XREAD_H_
#define XREAD_H_
 
#include <stdio.h>
 
#define BUFFERMAXSIZE (128*1024l)
 
struct xbuffer {
int handle;
char buffer[BUFFERMAXSIZE+8];
int readptr;
int writeptr;
};
extern struct xbuffer *table[OPEN_MAX];
 
void x_init(void);
 
/* rate in bit/sec */
/* band in percentuale */
int x_initbuffer(int group, FILE *f, int rate, int band);
 
#define XUNUSEDPID 5821
 
/*
*
*/
 
static __inline__ int filledspace(struct xbuffer *ptr)
{
int size;
if (ptr->writeptr==ptr->readptr) return 0;
size=ptr->writeptr-ptr->readptr;
if (size<0) size+=BUFFERMAXSIZE;
return size;
}
 
static __inline__ int freespace(struct xbuffer *ptr)
{
return BUFFERMAXSIZE-filledspace(ptr);
}
 
#endif
/demos/trunk/fsdemo/config.h
0,0 → 1,44
 
/*
*
*/
 
/* if def: does not use graphics */
#define NOGRX 1
#undef NOGRX
 
/* if def: use a mutex for all graphics operations */
#define GRXMUTEX 1
#undef GRXMUTEX
 
/* if def: use full color (16bits.. sigh) else use 8 bits/pixel grayscale */
#define FULLCOLOR 1
#undef FULLCOLOR
 
/*
*
*/
 
/* if def: does not trace events (does not work) */
#define NOTRACE 1
//#undef NOTRACE
 
/*
*
*/
 
/* if def: activate task buffering */
#define ACTIVATE 1
//#undef ACTIVATE
 
/*
*
*/
 
/* if def: use bd_edf resource for I/O tasks */
#define EDFSCHED 1
#undef EDFSCHED
 
/* if def: use bd_pscan resources for I/O tasks */
#define PSCANSCHED 1
#undef PSCANSCHED
/demos/trunk/fsdemo/readme
0,0 → 1,21
S.Ha.R.K. FSDEMO
 
This demo has been made as a thesis demo by Massimiliano Giorgi
(massy@gandalf.sssup.it). The following is the translations of some itailan
notes left my Massy. For any problems, please contact us
shark-help@gandalf.sssup.it...
 
bye
 
Paolo
 
----------------------------------------------------------------------------
 
mplay is the demo I used during my thesis presentation.
 
To use the demo you need a few mpeg files (those listed into mplay.c) into the directory /temp/m/ and some BMP photos into the directory /temp/b/
 
Note that only BMP 24bpp images are supported. They MUST have a DIB header,
with a line length mujltiple of 4 pixels!!!
 
Massy
/demos/trunk/fsdemo/gvideo.c
0,0 → 1,292
/*
* 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) 1999 Luca Abeni and 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: gvideo.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 $
*/
 
#include "config.h"
 
#include <kernel/func.h>
#include <kernel/model.h>
#include <kernel/const.h>
 
#include <drivers/glib.h>
 
#include <stdlib.h>
 
#include "mpeg/video.h"
#include "mpeg/util.h"
#include "mpeg/dither.h"
#include "mpeg/mpeg.h"
 
#include "mutex.h"
#include "gvideo.h"
#include "gbuffer.h"
#include "xread.h"
 
#define STARTGROUP 513
 
#define VIDEORATE 70
#define READRATE 30
 
/*
* colors
*/
 
#ifdef FULLCOLOR
 
#define COLORFG rgb16(255,255,255)
#define COLORBG rgb16(0,0,0)
 
#define SP rgb16(0,128,0)
#define FG rgb16(255,255,255)
#define BG rgb16(0,0,0)
 
#else
 
/* for writing */
#define COLORFG 255
#define COLORBG 0
 
/* for box */
#define SP 128
#define FG 255
#define BG 0
 
#endif
 
/* border size (pixels) */
#define BO 4
 
/*
*
*/
 
#ifdef FULLCOLOR
/* 16bits format 5:6:5 */
/* 32bits format 8:8:8:0 */
void down32to16(WORD *dst, BYTE *src, int size)
{
int i;
return;
for (i=0;i<size;i+=4,dst++,src+=4)
/* blue green red */
*dst=((src[2]&0xf8)>>3)|((src[1]&0xfc)<<3)|((src[0]&0xf8)<<8);
}
#endif
 
/*
*
*/
 
void draw_frame(int x, int y, int dx, int dy)
{
#ifndef NOGRX
grxlock();
grx_box(x-1-BO,y-1-BO,x+dx+BO,y+dy+BO,SP);
grx_rect(x-1-BO,y-1-BO,x+dx+BO,y+dy+BO,FG);
grx_box(x,y,x+dx-1,y+dy-1,BG);
grx_rect(x-1,y-1,x+dx,y+dy,FG);
grxunlock();
#endif
}
 
struct info {
int x,y;
ImageDesc *img;
};
 
static TASK play(void *arg)
{
struct info *ptr=(struct info*)arg;
int x1,y1,x2,y2;
BYTE *pixels; //,*image;
int moreframes;
pixels=(BYTE*)malloc(ptr->img->Size*sizeof(BYTE));
#ifdef FULLCOLOR
image=(BYTE*)malloc(ptr->img->Size/2*sizeof(BYTE));
#endif
x1=ptr->x;
y1=ptr->y;
x2=x1+ptr->img->Width-1;
y2=y1+ptr->img->Height-1;
 
moreframes=1;
for (;;) {
while (moreframes) {
moreframes=GetMPEGFrame(ptr->img,pixels);
#ifndef NOGRX
#ifdef FULLCOLOR
down32to16((WORD*)image,pixels,ptr->img->Size);
grxlock();
grx_putimage(x1, y1, x2, y2, pixels);
grxunlock();
#else
grxlock();
grx_putimage(x1, y1, x2, y2, pixels);
grxunlock();
#endif
#else
cprintf("%c",'0');
#endif
task_endcycle();
}
break;
//if (!loop) break;
//RewindMPEG (mpeg, img);
//SetMPEGOption (img, MPEG_DITHER, GRAY_DITHER);
//moreframes = TRUE;
}
return NULL;
}
 
int gvideo_init(char *title, struct gvideoinfo *ptr)
{
// static int groupcounter=0;
struct info *info;
SOFT_TASK_MODEL model;
FILE *fin;
PID pid,pid2;
ImageDesc *img;
int res;
int i;
int period,wcet;
int group;
 
img=(ImageDesc*)malloc(sizeof(ImageDesc));
if (img==NULL) return -3;
img->vid_stream=NULL;
img->Colormap=NULL;
 
info=(struct info*)malloc(sizeof(struct info));
if (info==NULL) return -11;
info->img=img;
info->x=ptr->x;
info->y=ptr->y;
fin=fopen(ptr->pathname, "r");
if (!fin) return -1;
 
//group=STARTGROUP+groupcounter++;
group=STARTGROUP;
pid2=x_initbuffer(group,fin,ptr->bitrate,ptr->band*READRATE);
if (pid2<0) return -2;
 
#ifdef ACTIVATE
gbuffer_init(table[fileno(fin)],group,20+12,450);
#else
gbuffer_init(NULL,group,20+12,450);
#endif
res=OpenMPEG(fin,img);
if (!res) return -4;
 
#ifdef FULLCOLOR
SetMPEGOption(img,MPEG_DITHER,HALF_COLOR_DITHER);
#else
SetMPEGOption(img,MPEG_DITHER,GRAY_DITHER);
#endif
 
//cprintf("colrmap size=%8i\n",img->ColormapSize);
//cprintf("picture rate=%8i\n",img->PictureRate);
//cprintf("bit rate =%8i\n",img->BitRate);
 
#ifndef FULLCOLOR
if (group==STARTGROUP) {
ColormapEntry *cp;
cp=img->Colormap;
for (i=0;i<img->ColormapSize;i++) {
#ifndef NOGRX
grxlock();
grx_setcolor (i,img->Colormap[i].red/4,
img->Colormap[i].green/4,
img->Colormap[i].blue/4);
grxunlock();
#endif
}
}
#endif
draw_frame(info->x,info->y,img->Width,img->Height);
ptr->w=img->Width;
ptr->h=img->Height;
 
{
char buffer[256];
 
#ifndef NOGRX
grxlock();
grx_text(title,ptr->x,ptr->y-14,COLORFG,COLORBG);
grxunlock();
sprintf(buffer,"Average bit rate: %i.%03i Mb/s",
ptr->bitrate/1024/1024,(ptr->bitrate%(1024*1024))*1000/1024/1000);
grxlock();
grx_text(buffer,ptr->x,ptr->y+ptr->h+BO*2+2,COLORFG,COLORBG);
grxunlock();
sprintf(buffer,"Frame rate : %02.3f frame/sec",
(double)ptr->framerate/100.0);
grxlock();
grx_text(buffer,ptr->x,ptr->y+ptr->h+BO*2+2+9,COLORFG,COLORBG);
grxunlock();
#endif
}
period=100000000/ptr->framerate;
wcet=period*ptr->band*VIDEORATE/10000;
soft_task_default_model(model);
soft_task_def_met(model,wcet);
soft_task_def_wcet(model,wcet);
soft_task_def_period(model,period);
soft_task_def_periodic(model);
soft_task_def_arg(model,(void*)info);
soft_task_def_group(model,group);
soft_task_def_ctrl_jet(model);
pid=task_create("Video",play,&model,NULL);
if (pid==-1) return -6;
 
return group;
}
/demos/trunk/fsdemo/gbuffer.c
0,0 → 1,129
/*
*
*
*/
 
#include "config.h"
 
#include <kernel/func.h>
#include <kernel/model.h>
#include <kernel/const.h>
 
#include <drivers/glib.h>
 
#include <stdlib.h>
#include <assert.h>
 
#include "mutex.h"
#include "xread.h"
 
#define PERIOD 250000
#define WCET 1000
 
#ifdef FULLCOLOR
 
#define BARCOLOR rgb16(255,0,0)
#define BARBG rgb16(0,0,0)
 
#define TEXTCOLOR rgb16(255,255,255)
#define TEXTBG rgb16(0,0,0)
 
#else
 
#define BARCOLOR 128
#define BARBG 0
 
#define TEXTCOLOR 255
#define TEXTBG 0
 
#endif
 
//#define XC 700
//#define YC 400
#define LEN 100
#define BORDER 8
 
extern void draw_frame(int x, int y, int dx, int dy);
 
struct taskinfo{
int XC,YC;
struct xbuffer *ptr;
};
 
static TASK monitorbuffer(void *arg)
{
struct taskinfo *p=(struct taskinfo *)arg;
int XC,YC;
int oy,y;
struct xbuffer *ptr;
int sum,old;
 
ptr=p->ptr;
XC=p->XC;
YC=p->YC;
oy=YC+LEN-1;
for (;;) {
sum=freespace(ptr);
#ifndef NOGRX
y=YC+LEN*sum/BUFFERMAXSIZE-1;
if (y!=oy) {
grxlock();
if (y<oy) grx_box(XC,y,XC+BORDER-1,oy,BARCOLOR);
else grx_box(XC,oy,XC+BORDER-1,y,BARBG);
grxunlock();
oy=y;
}
#else
cprintf("@%i@",sum);
#endif
old=sum;
task_endcycle();
}
return 0;
}
 
int gbuffer_init(struct xbuffer *ptr, int group, int XC, int YC)
{
struct taskinfo *info;
SOFT_TASK_MODEL model;
PID pid;
 
#ifdef ACTIVATE
info=(struct taskinfo *)malloc(sizeof(struct taskinfo));
if (info==NULL) sys_abort(912);
info->XC=XC;
info->YC=YC;
info->ptr=ptr;
soft_task_default_model(model);
soft_task_def_met(model,WCET);
soft_task_def_wcet(model,WCET);
soft_task_def_period(model,PERIOD);
soft_task_def_periodic(model);
soft_task_def_group(model,group);
soft_task_def_arg(model,(void*)info);
/*soft_task_def_group(model,group);*/
pid=task_create("bufferload",monitorbuffer,&model,NULL);
if (pid==-1) return -6;
 
#else
pid=-1;
#endif
#ifndef NOGRX
draw_frame(XC,YC,BORDER,LEN);
grxlock();
grx_text("Buffer",XC-18,YC+LEN+BORDER*2,TEXTCOLOR,TEXTBG);
grx_text("100%",XC+BORDER*2+1,YC-4,TEXTCOLOR,TEXTBG);
grx_text(" 75%",XC+BORDER*2+1,YC+LEN/4-4,TEXTCOLOR,TEXTBG);
grx_text(" 50%",XC+BORDER*2+1,YC+LEN/4*2-4,TEXTCOLOR,TEXTBG);
grx_text(" 25%",XC+BORDER*2+1,YC+LEN/4*3-4,TEXTCOLOR,TEXTBG);
grx_text(" 0%",XC+BORDER*2+1,YC+LEN-4,TEXTCOLOR,TEXTBG);
grxunlock();
#endif
return pid;
}
 
/demos/trunk/fsdemo/gvideo.h
0,0 → 1,22
/*
*
*
*/
 
#ifndef __GVIDEO_H
#define __GVIDEO_H
 
struct gvideoinfo {
int x,y;
int h,w; /* no fill */
char *pathname;
int bitrate; /* bytes/sec */
int framerate; /* frames/sec */
int band; /* CPU band in percent */
};
 
int gvideo_init(char *title, struct gvideoinfo *info);
 
#endif
/demos/trunk/fsdemo/gbuffer.h
0,0 → 1,9
 
#ifndef __GBUFFER_H
#define __GBUFFER_H
 
#include "xread.h"
 
int gbuffer_init(struct xbuffer *ptr, int group, int XC, int YC);
 
#endif
/demos/trunk/fsdemo/gload.c
0,0 → 1,113
/*
*
*
*/
 
#include "config.h"
 
#include <kernel/func.h>
#include <kernel/model.h>
#include <kernel/const.h>
 
#include <drivers/glib.h>
 
#include <stdlib.h>
#include <assert.h>
 
#include "mutex.h"
#include "gload.h"
 
#define PERIOD 250000
#define WCET 1000
 
#ifdef FULLCOLOR
 
#define BARCOLOR rgb16(255,0,0)
#define BARBG rgb16(0,0,0)
 
#define TEXTCOLOR rgb16(255,255,255)
#define TEXTBG rgb16(0,0,0)
 
#else
 
#define BARCOLOR 128
#define BARBG 0
 
#define TEXTCOLOR 255
#define TEXTBG 0
 
#endif
 
#define XC (32+64)
#define YC 450
#define LEN 100
#define BOR 8
 
extern void draw_frame(int x, int y, int dx, int dy);
 
/* only for NRT task */
static TASK monitorload(void *arg)
{
int oy,y;
PID pid=(PID)arg;
TIME sum,old;
int res;
 
res=jet_getstat(pid,NULL,NULL,NULL,&old);
task_endcycle();
 
oy=YC+LEN-1;
for (;;) {
res=jet_getstat(pid,NULL,NULL,NULL,&sum);
if (res==-1) break;
#ifndef NOGRX
y=YC+LEN*(sum-old)/PERIOD-1;
if (y!=oy) {
grxlock();
if (y<oy) grx_box(XC,y,XC+BOR-1,oy,BARCOLOR);
else grx_box(XC,oy,XC+BOR-1,y,BARBG);
grxunlock();
oy=y;
}
#else
n++;
if (n%4==0)
cprintf("#%li,%i#",sum); //(1000-sum*1000/PERIOD);
#endif
old=sum;
task_endcycle();
}
return 0;
}
 
int gload_init(int taskpid)
{
SOFT_TASK_MODEL model;
PID pid;
soft_task_default_model(model);
soft_task_def_met(model,WCET);
soft_task_def_wcet(model,WCET);
soft_task_def_period(model,PERIOD);
soft_task_def_periodic(model);
soft_task_def_arg(model,(void*)taskpid);
/*soft_task_def_group(model,group);*/
pid=task_create("load",monitorload,&model,NULL);
if (pid==-1) return -6;
 
#ifndef NOGRX
draw_frame(XC,YC,BOR,LEN);
grxlock();
grx_text("Load",XC-10,YC+LEN+BOR*2,TEXTCOLOR,TEXTBG);
grx_text("100%",XC+BOR*2+1,YC-4,TEXTCOLOR,TEXTBG);
grx_text(" 75%",XC+BOR*2+1,YC+LEN/4-4,TEXTCOLOR,TEXTBG);
grx_text(" 50%",XC+BOR*2+1,YC+LEN/4*2-4,TEXTCOLOR,TEXTBG);
grx_text(" 25%",XC+BOR*2+1,YC+LEN/4*3-4,TEXTCOLOR,TEXTBG);
grx_text(" 0%",XC+BOR*2+1,YC+LEN-4,TEXTCOLOR,TEXTBG);
grxunlock();
#endif
return pid;
}
 
/demos/trunk/fsdemo/gphoto.ok
0,0 → 1,222
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Luca Abeni <luca@hartik.sssup.it>
* Massimiliano Giorgi <massy@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
 
/*
* Copyright (C) 1999 Luca Abeni and 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: gphoto.ok,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 $
*/
 
#include "config.h"
 
#include <kernel/func.h>
#include <kernel/model.h>
#include <kernel/const.h>
 
#include <drivers/glib.h>
 
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
 
#include "mutex.h"
#include "gphoto.h"
 
#ifdef FULLCOLOR
 
/* 16bits format 5:6:5 */
/* 24bits format 8:8:8 */
static void down24to16(WORD *dst, BYTE *src, int dx, int dy)
{
int x,y;
/* row must be multiple of 4!!! (there are 3 bytes per pixel!)*/
dst+=dx*(dy+1);
for (y=0;y<dy;y++) {
dst-=dx*2;
for (x=0;x<dx;x++,src+=3,dst++)
/* blue green red */
*dst=((src[0]&0xf8)>>3)|((src[1]&0xfc)<<3)|((src[2]&0xf8)<<8);
}
}
 
#define downscaleimage(x,y,z,k) down24to16((WORD*)x,y,z,k)
 
#else
 
static void down24to8(BYTE *dst, BYTE *src, int dx, int dy)
{
int x,y;
 
dst+=dx*(dy+1);
for (y=0;y<dy;y++) {
dst-=dx*2;
for (x=0;x<dx;x++,src+=3,dst++)
*dst=(((int)src[0])*11+((int)src[1])*59+((int)src[2])*30)/100;
}
}
 
#define downscaleimage(x,y,z,k) down24to8(x,y,z,k)
 
#endif
 
/*
*
*/
 
extern void draw_frame(int x, int y, int dx, int dy);
 
int gphoto_show(char *pathname, int x, int y)
{
struct BITMAPFILEHEADER *bf;
struct BITMAPINFOHEADER *bi;
BYTE *src,*dst;
long l;
int h,n;
int dx,dy;
bf=(struct BITMAPFILEHEADER *)malloc(sizeof(struct BITMAPFILEHEADER));
bi=(struct BITMAPINFOHEADER *)malloc(sizeof(struct BITMAPINFOHEADER));
 
if (bf==NULL||bi==NULL) return -1;
 
h=open(pathname,O_RDONLY);
if (h==-1) {
free(bf);
free(bi);
return -2;
}
 
n=read(h,bf,sizeof(struct BITMAPFILEHEADER));
if (n!=sizeof(struct BITMAPFILEHEADER)) {
close(h);
free(bf);
free(bi);
return -4;
}
 
n=read(h,bi,sizeof(struct BITMAPINFOHEADER));
if (n!=sizeof(struct BITMAPINFOHEADER)) {
close(h);
free(bf);
free(bi);
return -4;
}
//grx_close();
 
/*
cprintf("type: %c %c\n",bf->bfType&0xff,bf->bfType>>8);
cprintf("size: %li\n",bf->bfSize);
cprintf("tell: %li\n\n",bf->bfOffBits);
 
cprintf("bitcoutn: %i\n",bi->biBitCount);
cprintf("compress: %li\n",bi->biCompression);
cprintf("dx: %li\n",bi->biWidth);
cprintf("dy: %li\n",bi->biHeight);
*/
//sys_end();
//return 0;
if (bf->bfType!='B'+256*'M'||
bi->biBitCount!=24||
bi->biCompression!=0||
bi->biWidth%4!=0) {
close(h);
free(bf);
free(bi);
return -5;
}
dx=bi->biWidth;
dy=bi->biHeight;
src=(BYTE*)malloc(dx*dy*3);
if (src==NULL) {
close(h);
free(bf);
free(bi);
return -6;
}
 
dst=(BYTE*)malloc(dx*dy*2);
if (dst==NULL) {
free(src);
close(h);
free(bf);
free(bi);
return -6;
}
 
l=lseek(h,bf->bfOffBits,SEEK_SET);
if (l!=bf->bfOffBits) {
free(dst);
free(src);
close(h);
free(bf);
free(bi);
return -7;
}
 
n=read(h,src,dx*dy*3);
if (n!=dx*dy*3) {
free(dst);
free(src);
close(h);
free(bf);
free(bi);
return -8;
}
 
downscaleimage(dst,src,dx,dy);
#ifndef NOGRX
draw_frame(x,y,dx,dy);
grxlock();
grx_putimage(x, y, x+dx-1, y+dy-1, dst);
grxunlock();
#endif
 
free(dst);
free(src);
close(h);
free(bi);
free(bf);
 
return 0;
}
/demos/trunk/fsdemo/gload.h
0,0 → 1,7
 
#ifndef __GLOAD_H
#define __GLOAD_H
 
int gload_init(int pid);
 
#endif
/demos/trunk/fsdemo/oldmakefile
0,0 → 1,41
#
#
#
# TO REMAKE BETTER
#
#
 
ifndef BASE
BASE=../..
endif
include $(BASE)/config/config.mk
 
.PHONY: test all install depend clean cleanall
 
C_INC+= -I$(BASE)/ports
LINK_LIB+= -lmpeg
LINK_DEP+= $(LIB_PATH)/libmpeg.a
 
#test:: tserv tserv2
test:: mplay
 
clean::
rm -f *.o
rm -f mplay
 
OBJS= mplay.o xread.o gclock.o gvideo.o gload.o gbuffer.o gphoto.o
 
mplay: $(OBJS) $(LIB_PATH)/initfs.o $(LIB_DEP)
$(LD) $(LINK_OPT) $(LINK_STARTUP) \
$(OBJS) \
$(LIB_PATH)/initfs.o \
--start-group $(LINK_LIB) --end-group \
-o mplay
 
depend::
$(CC) $(C_OPT) -M $(OBJS:.o=.c) > deps
 
deps:
$(CC) $(C_OPT) -M $(OBJS:.o=.c) > deps
 
include deps