Go to most recent revision |
Blame |
Last modification |
View Log
| RSS feed
/* Project: HARTIK 3.0 */
/* Description: Hard Real TIme Kernel for 386 & higher machines */
/* Author: Paolo Gai <pgai@rsk.it> */
/* Advanced Linux Sound Architecture (ALSA) */
/* Copyright (c) by Jaroslav Kysela <perex@jcu.cz> */
/* Luca Abeni */
/* FFTW by M. Frigo and S. G. Johnson */
/* Date: 08/09/1999 */
/* File: fftplay.c */
/* Revision: 1.00 (Kernel 0.1.4; Library 0.0.9; Util 0.0.4) */
#include "demo.h"
//#include <kernel/types.h>
//#include <kernel/model.h>
#include <kernel/func.h>
//#include <modules/cabs.h>
#include <string.h>
#include <stdlib.h>
#include <drivers/keyb.h>
//#include <drivers/crtwin.h>
#include <drivers/glib.h>
//#include <drivers/sound.h>
//#include <ports/rfftw.h>
/* Informations about the sampling rate and buffers */
WORD rawdata_nsamples
;
WORD rawdata_buffer_size
;
WORD rawdata_freq
;
/* graphic mutex... */
mutex_t mutex
;
/* useful colors... */
int white
;
int black
;
int red
;
int gray
;
void app_mutex_init
(mutex_t
*m
);
static void version
( void )
{
cprintf
( "Hartik FFT Play 1.0\n" );
cprintf
( "-----------------------\n" );
cprintf
( "by Paolo Gai 1999\n" );
cprintf
( " <pj@hartik.sssup.it>\n" );
cprintf
( "-----------------------\n" );
}
void reverse
(char s
[])
{
int c
, i
, j
;
for (i
= 0, j
= strlen(s
)-1; i
<j
; i
++, j
--)
{
c
= s
[i
];
s
[i
] = s
[j
];
s
[j
] = c
;
}
}
char * itoa(int n
, char *s
)
{
int i
, sign
;
if ((sign
= n
) < 0)
n
= -n
;
i
= 0;
do
{
s
[i
++] = n
% 10 + '0';
} while ((n
/= 10) > 0);
if (sign
< 0)
s
[i
++] = '-';
s
[i
] = 0;
reverse
(s
);
return s
;
}
void display_jet
(PID i
)
{
char st
[200];
TIME sum
, max
;
int n
;
if (jet_getstat
(i
, &sum
, &max
, &n
, NULL
) != -1) {
if (n
==0) n
=1;
sprintf(st
, "PID=%2d st=%3d Mean=%5d Max=%5d na=%10s",
(int)i
,
(int)proc_table
[i
].
status, (int)sum
/n
, (int)max
,
proc_table
[i
].
name);
mutex_lock
(&mutex
);
grx_text
(st
, 0, 400+i
*8, 255, 0);
mutex_unlock
(&mutex
);
}
}
void scenario
(int f
)
{
grx_text
("HARTIK 4.0 - LEGO Version" , 0,0, rgb16
(0,255,0), black
);
grx_text
("Thesis Demo", 0,8, rgb16
(0,255,0), black
);
#ifdef FFT_ON
scenario_fftplay
(f
);
#endif
#ifdef FRAMEGRABBER_ON
scenario_framegrabber
();
#endif
#ifdef JET_ON
scenario_jetcontrol
();
#endif
#ifdef BALL_ON
scenario_ball
();
#endif
}
void demo_exc_handler
(int signo
, siginfo_t
*info
, void *extra
)
{
struct timespec t
;
grx_close
();
/* Default action for an kern exception is */
kern_cli
();
ll_gettime
(TIME_EXACT
, &t
),
kern_printf
("\nHartik Exception raised!!!"
"\nTime (s:ns) :%ld:%ld"
"\nException number:%d"
"\nPID :%d\n",
t.
tv_sec, t.
tv_nsec, info
->si_value.
sival_int,
info
->si_task
);
sys_end
();
// ll_abort(5);
}
void my_close
(void *arg
)
{
grx_close
();
// sys_status(3);
}
void endfun
(KEY_EVT
*k
)
{
grx_close
();
cprintf
("Ctrl-Brk pressed! Ending...\n");
sys_end
();
}
void zerofun
(KEY_EVT
*k
)
{
int i
;
for (i
=0; i
<MAX_PROC
; i
++) jet_delstat
(i
);
}
void printeventqueue
(void *arg
)
{
struct event
*p
;
extern struct event
*firstevent
;
kern_cli
();
grx_close
();
kern_cli
();
for (p
= firstevent
; p
!= NULL
; p
= p
->next
) {
kern_printf
("par:%d time:%ld.%ld p:%d handler:%d\n",
(int)p
->par
, p
->time.
tv_sec, p
->time.
tv_nsec/1000, (int)p
, (int)p
->handler
);
}
kern_sti
();
}
int main
(int argc
, char **argv
)
{
int modenum
;
int f
;
KEY_EVT k
;
struct sigaction action
;
srand(4);
version
();
#ifdef FRAMEGRABBER_ON
if (argc
== 1)
{
cprintf
("type x fftplay <freq>");
return 0;
}
f
= atoi(argv
[1]);
compute_params
(&f
,&rawdata_nsamples
);
#endif
keyb_set_map
(itaMap
);
k.
flag = CNTR_BIT
;
k.
scan = KEY_C
;
k.
ascii = 'c';
keyb_hook
(k
,endfun
);
k.
flag = CNTL_BIT
;
k.
scan = KEY_C
;
k.
ascii = 'c';
keyb_hook
(k
,endfun
);
k.
flag = ALTL_BIT
;
k.
scan = KEY_C
;
k.
ascii = 'c';
keyb_hook
(k
,zerofun
);
k.
flag = 0;
k.
scan = KEY_ENT
;
k.
ascii = 13;
keyb_hook
(k
,endfun
);
/* Init the standard Hartik exception handler */
/* Set the signal action */
action.
sa_flags = SA_SIGINFO
;
action.
sa_sigaction = demo_exc_handler
;
action.
sa_handler = 0;
sigfillset
(&action.
sa_mask); /* we block all the other signals... */
if (sigaction
(SIGHEXC
, &action
, NULL
) == -1) {
perror("Error initializing signals...");
sys_end
();
}
sys_atrunlevel
(my_close
, NULL
, RUNLEVEL_BEFORE_EXIT
);
grx_init
();
modenum
= grx_getmode
(640, 480, 16);
grx_setmode
(modenum
);
/* init the graphic mutex */
app_mutex_init
(&mutex
);
/* useful colors ... */
white
= rgb16
(255,255,255);
black
= rgb16
(0,0,0);
red
= rgb16
(255,0,0);
gray
= rgb16
(128,128,128);
scenario
(f
/2);
// grx_close();
// clear();
#ifdef FFT_ON
init_fftplay
(f
);
#endif
#ifdef FRAMEGRABBER_ON
init_framegrabber
();
#endif
#ifdef JET_ON
init_jetcontrol
();
#endif
#ifdef BALL_ON
init_ball
();
#endif
group_activate
(1);
#ifdef FRAMEGRABBER_ON
start_framegrabber
();
#endif
return 0;
}