Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /* Project: HARTIK 3.0 */ |
2 | /* Description: Hard Real TIme Kernel for 386 & higher machines */ |
||
3 | /* Author: Paolo Gai <pgai@rsk.it> */ |
||
4 | /* Advanced Linux Sound Architecture (ALSA) */ |
||
5 | /* Copyright (c) by Jaroslav Kysela <perex@jcu.cz> */ |
||
6 | /* Luca Abeni */ |
||
7 | /* FFTW by M. Frigo and S. G. Johnson */ |
||
8 | |||
9 | /* Date: 08/09/1999 */ |
||
10 | |||
11 | /* File: fftplay.c */ |
||
12 | /* Revision: 1.00 (Kernel 0.1.4; Library 0.0.9; Util 0.0.4) */ |
||
13 | |||
14 | |||
15 | |||
16 | #include "demo.h" |
||
17 | |||
18 | //#include <kernel/types.h> |
||
19 | //#include <kernel/model.h> |
||
20 | #include <kernel/func.h> |
||
21 | |||
22 | //#include <modules/cabs.h> |
||
23 | |||
24 | #include <string.h> |
||
25 | #include <stdlib.h> |
||
26 | |||
27 | #include <drivers/keyb.h> |
||
28 | //#include <drivers/crtwin.h> |
||
29 | #include <drivers/glib.h> |
||
30 | //#include <drivers/sound.h> |
||
31 | //#include <ports/rfftw.h> |
||
32 | |||
33 | |||
34 | |||
35 | /* Informations about the sampling rate and buffers */ |
||
36 | WORD rawdata_nsamples; |
||
37 | WORD rawdata_buffer_size; |
||
38 | WORD rawdata_freq; |
||
39 | |||
40 | /* graphic mutex... */ |
||
41 | mutex_t mutex; |
||
42 | |||
43 | /* useful colors... */ |
||
44 | int white; |
||
45 | int black; |
||
46 | int red; |
||
47 | int gray; |
||
48 | |||
49 | void app_mutex_init(mutex_t *m); |
||
50 | |||
51 | |||
52 | static void version( void ) |
||
53 | { |
||
54 | cprintf( "Hartik FFT Play 1.0\n" ); |
||
55 | cprintf( "-----------------------\n" ); |
||
56 | cprintf( "by Paolo Gai 1999\n" ); |
||
57 | cprintf( " <pj@hartik.sssup.it>\n" ); |
||
58 | cprintf( "-----------------------\n" ); |
||
59 | } |
||
60 | |||
61 | void reverse(char s[]) |
||
62 | { |
||
63 | int c, i, j; |
||
64 | |||
65 | for (i = 0, j = strlen(s)-1; i<j; i++, j--) |
||
66 | { |
||
67 | c = s[i]; |
||
68 | s[i] = s[j]; |
||
69 | s[j] = c; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | char * itoa(int n, char *s) |
||
74 | { |
||
75 | int i, sign; |
||
76 | |||
77 | if ((sign = n) < 0) |
||
78 | n = -n; |
||
79 | |||
80 | i = 0; |
||
81 | |||
82 | do |
||
83 | { |
||
84 | s[i++] = n % 10 + '0'; |
||
85 | } while ((n /= 10) > 0); |
||
86 | |||
87 | if (sign < 0) |
||
88 | s[i++] = '-'; |
||
89 | |||
90 | s[i] = 0; |
||
91 | |||
92 | reverse(s); |
||
93 | |||
94 | return s; |
||
95 | } |
||
96 | |||
97 | void display_jet(PID i) |
||
98 | { |
||
99 | char st[200]; |
||
100 | TIME sum, max; |
||
101 | int n; |
||
102 | |||
103 | if (jet_getstat(i, &sum, &max, &n, NULL) != -1) { |
||
104 | if (n==0) n=1; |
||
105 | sprintf(st, "PID=%2d st=%3d Mean=%5d Max=%5d na=%10s", |
||
106 | (int)i, |
||
107 | (int)proc_table[i].status, (int)sum/n, (int)max, |
||
108 | proc_table[i].name); |
||
109 | mutex_lock(&mutex); |
||
110 | grx_text(st, 0, 400+i*8, 255, 0); |
||
111 | mutex_unlock(&mutex); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | |||
116 | |||
117 | void scenario(int f) |
||
118 | { |
||
119 | grx_text("HARTIK 4.0 - LEGO Version" , 0,0, rgb16(0,255,0), black ); |
||
120 | grx_text("Thesis Demo", 0,8, rgb16(0,255,0), black ); |
||
121 | |||
122 | #ifdef FFT_ON |
||
123 | scenario_fftplay(f); |
||
124 | #endif |
||
125 | |||
126 | #ifdef FRAMEGRABBER_ON |
||
127 | scenario_framegrabber(); |
||
128 | #endif |
||
129 | |||
130 | #ifdef JET_ON |
||
131 | scenario_jetcontrol(); |
||
132 | #endif |
||
133 | |||
134 | #ifdef BALL_ON |
||
135 | scenario_ball(); |
||
136 | #endif |
||
137 | } |
||
138 | |||
139 | |||
140 | void demo_exc_handler(int signo, siginfo_t *info, void *extra) |
||
141 | { |
||
142 | struct timespec t; |
||
143 | |||
144 | grx_close(); |
||
145 | |||
146 | /* Default action for an kern exception is */ |
||
147 | kern_cli(); |
||
148 | ll_gettime(TIME_EXACT, &t), |
||
149 | kern_printf("\nHartik Exception raised!!!" |
||
150 | "\nTime (s:ns) :%ld:%ld" |
||
151 | "\nException number:%d" |
||
152 | "\nPID :%d\n", |
||
153 | t.tv_sec, t.tv_nsec, info->si_value.sival_int, |
||
154 | info->si_task); |
||
155 | sys_end(); |
||
156 | // ll_abort(5); |
||
157 | } |
||
158 | |||
159 | void my_close(void *arg) |
||
160 | { |
||
161 | grx_close(); |
||
162 | // sys_status(3); |
||
163 | } |
||
164 | |||
165 | |||
166 | void endfun(KEY_EVT *k) |
||
167 | { |
||
168 | grx_close(); |
||
169 | cprintf("Ctrl-Brk pressed! Ending...\n"); |
||
170 | sys_end(); |
||
171 | } |
||
172 | |||
173 | void zerofun(KEY_EVT *k) |
||
174 | { |
||
175 | int i; |
||
176 | for (i=0; i<MAX_PROC; i++) jet_delstat(i); |
||
177 | } |
||
178 | |||
179 | void printeventqueue(void *arg) |
||
180 | { |
||
181 | struct event *p; |
||
182 | extern struct event *firstevent; |
||
183 | |||
184 | kern_cli(); |
||
185 | grx_close(); |
||
186 | kern_cli(); |
||
187 | for (p = firstevent; p != NULL; p = p->next) { |
||
188 | kern_printf("par:%d time:%ld.%ld p:%d handler:%d\n", |
||
189 | (int)p->par, p->time.tv_sec, p->time.tv_nsec/1000, (int)p, (int)p->handler); |
||
190 | } |
||
191 | kern_sti(); |
||
192 | } |
||
193 | |||
194 | int main(int argc, char **argv) |
||
195 | { |
||
196 | int modenum; |
||
197 | |||
198 | int f; |
||
199 | |||
200 | KEY_EVT k; |
||
201 | |||
202 | struct sigaction action; |
||
203 | |||
204 | srand(4); |
||
205 | |||
206 | version(); |
||
207 | |||
208 | #ifdef FRAMEGRABBER_ON |
||
209 | if (argc == 1) |
||
210 | { |
||
211 | cprintf("type x fftplay <freq>"); |
||
212 | return 0; |
||
213 | } |
||
214 | |||
215 | f = atoi(argv[1]); |
||
216 | compute_params(&f,&rawdata_nsamples); |
||
217 | #endif |
||
218 | |||
219 | keyb_set_map(itaMap); |
||
220 | k.flag = CNTR_BIT; |
||
221 | k.scan = KEY_C; |
||
222 | k.ascii = 'c'; |
||
223 | keyb_hook(k,endfun); |
||
224 | k.flag = CNTL_BIT; |
||
225 | k.scan = KEY_C; |
||
226 | k.ascii = 'c'; |
||
227 | keyb_hook(k,endfun); |
||
228 | k.flag = ALTL_BIT; |
||
229 | k.scan = KEY_C; |
||
230 | k.ascii = 'c'; |
||
231 | keyb_hook(k,zerofun); |
||
232 | k.flag = 0; |
||
233 | k.scan = KEY_ENT; |
||
234 | k.ascii = 13; |
||
235 | keyb_hook(k,endfun); |
||
236 | |||
237 | /* Init the standard Hartik exception handler */ |
||
238 | /* Set the signal action */ |
||
239 | action.sa_flags = SA_SIGINFO; |
||
240 | action.sa_sigaction = demo_exc_handler; |
||
241 | action.sa_handler = 0; |
||
242 | sigfillset(&action.sa_mask); /* we block all the other signals... */ |
||
243 | |||
244 | if (sigaction(SIGHEXC, &action, NULL) == -1) { |
||
245 | perror("Error initializing signals..."); |
||
246 | sys_end(); |
||
247 | } |
||
248 | |||
249 | sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT); |
||
250 | |||
251 | |||
252 | grx_init(); |
||
253 | modenum = grx_getmode(640, 480, 16); |
||
254 | |||
255 | grx_setmode(modenum); |
||
256 | |||
257 | /* init the graphic mutex */ |
||
258 | app_mutex_init(&mutex); |
||
259 | |||
260 | /* useful colors ... */ |
||
261 | white = rgb16(255,255,255); |
||
262 | black = rgb16(0,0,0); |
||
263 | red = rgb16(255,0,0); |
||
264 | gray = rgb16(128,128,128); |
||
265 | |||
266 | scenario(f/2); |
||
267 | // grx_close(); |
||
268 | // clear(); |
||
269 | #ifdef FFT_ON |
||
270 | init_fftplay(f); |
||
271 | #endif |
||
272 | |||
273 | #ifdef FRAMEGRABBER_ON |
||
274 | init_framegrabber(); |
||
275 | #endif |
||
276 | |||
277 | #ifdef JET_ON |
||
278 | init_jetcontrol(); |
||
279 | #endif |
||
280 | |||
281 | #ifdef BALL_ON |
||
282 | init_ball(); |
||
283 | #endif |
||
284 | |||
285 | group_activate(1); |
||
286 | |||
287 | #ifdef FRAMEGRABBER_ON |
||
288 | start_framegrabber(); |
||
289 | #endif |
||
290 | |||
291 | return 0; |
||
292 | } |
||
293 | |||
294 |