Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1655 giacomo 1
 
2
 
3
#include <ll/ll.h>
4
#include <kernel/types.h>
5
#include <kernel/descr.h>
6
#include <math.h>
7
#include <drivers/glib.h>
8
#include <drivers/keyb.h>
9
 
10
 
11
#define FFT_ON
12
#define FRAMEGRABBER_ON
13
#define JET_ON
14
#define BALL_ON
15
 
16
/*
17
 *
18
 * WCET, Periods and Models
19
 *
20
 */
21
 
22
 
23
/* define if you want NRT or SOFT... */
24
#define TASK_TYPE SOFT
25
//#define TASK_TYPE NRT
26
 
27
// on Celeron 366
28
#define WCET_WAVE          450
29
#define WCET_FFT           722
30
#define WCET_EQU          1000
31
#define WCET_EQU2D         318
32
 
33
#define PERIOD_WAVE      40000
34
#define PERIOD_FFT        3000
35
#define PERIOD_EQU       40000
36
#define PERIOD_EQU2D      3000
37
 
38
 
39
 
40
 
41
#define WCET_TRACKING     4000
42
#define WCET_CAMERA       7000
43
 
44
#define PERIOD_TRACKING  40000
45
#define PERIOD_CAMERA    40000
46
 
47
 
48
#define WCET_JETCTRL      2600
49
#define WCET_JETDUMMY     1000
50
#define WCET_JETSLIDE     1000
51
 
52
#define PERIOD_JETCTRL  100000
53
#define PERIOD_JETDUMMY 100000
54
#define PERIOD_JETSLIDE 100000
55
 
56
 
57
#define WCET_BALL          60
58
 
59
#define PERIOD_BALL      10000
60
 
61
 
62
/*
63
 *
64
 * Soundcard related defines
65
 *
66
 */
67
 
68
 
69
/* Samples are 16-bit signed integers */
70
typedef short SAMPLE;
71
#define MAX_SAMPLE 32768
72
 
73
 
74
 
75
/*
76
 *
77
 * FFT defines
78
 *
79
 */
80
 
81
/* Numbers of samples of the sample window */
82
#define WINDATA_NSAMPLES  512
83
 
84
/* task WAVE */
85
/* the point (wave_x,wave_y) is on the center left of the area... */
86
#define WAVE_NSAMPLES 384
87
#define WAVE_X        0
88
#define WAVE_Y        64
89
#define WAVE_HEIGHT   32
90
 
91
/* task FFT */
92
#define FFT_NSAMPLES  512
93
#define PWR_NSAMPLES  (FFT_NSAMPLES/2+1)
94
 
95
/* task EQU */
96
/* the point (equ_x, equ_y) is the top right corner */
97
#define EQU_NSAMPLES  PWR_NSAMPLES
98
#define EQU_X         64
99
#define EQU_Y         128
100
#define EQU_HEIGHT    64
101
#define EQU_SHADE
102
 
103
/* task EQU2D */
104
/* the point (equ2d_x, equ2d_y) is the top left corner */
105
#define EQU2D_NSAMPLES  EQU_NSAMPLES
106
#define EQU2D_X         128
107
#define EQU2D_Y         EQU_Y
108
#define EQU2D_WIDTH     255
109
#define EQU2D_CLIP      255
110
 
111
/* scenario */
112
#define SCENARIO_NLABEL 16
113
 
114
/* Scale factors */
115
#define FFT_SCALE   (16384.0)
116
#define EQU_SCALE   (32.0)
117
#define EQU2D_SCALE (8.0)
118
//#define EQU_SCALE   (64.0)
119
//#define EQU2D_SCALE (16.0)
120
 
121
 
122
 
123
/* Informations about the sampling rate and buffers */
124
extern WORD rawdata_nsamples;
125
extern WORD rawdata_buffer_size;
126
extern WORD rawdata_freq;
127
 
128
 
129
 
130
/*
131
 *
132
 * Global Stuffs
133
 *
134
 */
135
 
136
/* graphic mutex... */
137
extern mutex_t mutex;
138
 
139
/* useful colors... */
140
extern int white;
141
extern int black;
142
extern int red;
143
extern int gray;
144
 
145
/* define if shorts critical sections wanted */
146
#define SHORT_CRITICAL_SECTIONS(x) \
147
  if (!((x)%64))                   \
148
    {                              \
149
      mutex_lock(&mutex);          \
150
      mutex_unlock(&mutex);        \
151
    }
152
 
153
void init_fftplay(int freq);
154
void init_framegrabber();
155
void init_jetcontrol();
156
void init_ball(void);
157
void start_framegrabber();
158
 
159
 
160
void scenario_jetcontrol(void);
161
void scenario_fftplay(int f);
162
void scenario_framegrabber();
163
void scenario_ball();
164
 
165
void compute_params(int *freq,WORD *nsamp);
166
 
167
char * itoa(int n, char *s);
168
 
169
/*
170
 *
171
 * Framegrabber stuffs
172
 *
173
 */
174
 
175
// if defined... object black on a white background
176
#ifndef __BLACK_ON_WHITE
177
#define __BLACK_ON_WHITE
178
#endif
179
 
180
#define ABS_NUM(a) ((a >= 0) ? a : -a)
181
#define MIN_NUM(a, b) ((a < b) ? a : b)
182
#define MAX_NUM(a, b) ((a > b) ? a : b)
183
 
184
 
185
// Cols and rows  of the framegrabber image
186
#define N_COL         384
187
#define N_ROW         288
188
#define N_BPS           8   // Bits per pixel
189
#define N_GRIGI       256
190
 
191
#define N_FRAMES      100
192
 
193
/* pixel of the video image */
194
#define IMG_COL       256
195
#define IMG_ROW       192
196
 
197
/* position of the video image */
198
#define IMG_X         384
199
#define IMG_Y         32
200
 
201
// I singoli pixel sono caratteri a 8 bit
202
typedef unsigned char TPixel;
203
 
204
typedef struct {
205
  int x1, y1;
206
  int x2, y2;
207
  int xb, yb;
208
  TIME time_stamp;
209
} TDataObj;
210
 
211
typedef struct {
212
  int found;
213
  int top_frame;
214
  int vx,vy;
215
  int predx;
216
  int predy;
217
  TDataObj current;
218
} TTracking;
219
 
220
 
221
float distance(unsigned int x1, unsigned int y1,
222
               unsigned int x2, unsigned int y2);
223
 
224
char scan_all_frame(TDataObj *data, TPixel *in_frame);
225
 
226
char scan_window_frame(TDataObj *data, TPixel *in_frame,
227
                       unsigned int xc, unsigned int yc, int border);
228
 
229
void threshold_up_function(KEY_EVT key);
230
void threshold_down_function(KEY_EVT key);
231
 
232
void border_up_function(KEY_EVT key);
233
void border_down_function(KEY_EVT key);
234
 
235
void tracking(int top_frame, int *track_x, int *track_y, int *int_vx, int *int_vy, int time_to);
236
 
237
TASK elab_image_TASK(void);
238
 
239
 
240
 
241
/*
242
 *
243
 * JETCONTROL stuffs
244
 *
245
 */
246
 
247
#define JET_NTASK   18
248
#define JET_Y_NAME 320
249
 
250
#define DUMMY_PID    1
251
 
252
#define JET_DUMMY_WIDTH    210
253
#define JET_DUMMY_HEIGHT    40
254
 
255
/* the point (x, y) is the top left corner */
256
#define JET_DUMMY_X        428
257
#define JET_DUMMY_Y        264
258
 
259
#define JET_SLIDE_WIDTH     50
260
#define JET_SLIDE_X        576
261
 
262
 
263
 
264
 
265
/*
266
 *
267
 * BALL stuffs
268
 *
269
 */
270
 
271
// x and y corners are specified whithout consider a border of 3 pixels
272
#define BALL_Y     475          /* position of the floor        */
273
#define BALL_HEIGHT 70          /* initial height of the ball   */
274
#define BALL_XMIN    3          /* min position X of the ball   */
275
#define BALL_XMAX  380          /* max position X of the ball   */
276
#define BALL_VELX    5.         /* horizontal ball velocity     */
277
#define BALL_VYMIN  11.         /* velocit… minima per suono    */
278
#define BALL_MAX_P  50          /* max number of balls          */
279
 
280
#define BALL_GROUP   2          /* task group of the balls */