Subversion Repositories shark

Rev

Rev 1085 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed



#include <ll/ll.h>
#include <kernel/types.h>
#include <kernel/descr.h>
#include <math.h>
#include <drivers/glib.h>
#include <drivers/keyb.h>


#define FFT_ON
#define FRAMEGRABBER_ON
#define JET_ON
#define BALL_ON

/*
 *
 * WCET, Periods and Models
 *
 */



/* define if you want NRT or SOFT... */
#define TASK_TYPE SOFT
//#define TASK_TYPE NRT

// on Celeron 366
#define WCET_WAVE          450
#define WCET_FFT           722
#define WCET_EQU          1000
#define WCET_EQU2D         318

#define PERIOD_WAVE      40000
#define PERIOD_FFT        3000
#define PERIOD_EQU       40000
#define PERIOD_EQU2D      3000




#define WCET_TRACKING     4000
#define WCET_CAMERA       7000

#define PERIOD_TRACKING  40000
#define PERIOD_CAMERA    40000


#define WCET_JETCTRL      2600
#define WCET_JETDUMMY     1000
#define WCET_JETSLIDE     1000

#define PERIOD_JETCTRL  100000
#define PERIOD_JETDUMMY 100000
#define PERIOD_JETSLIDE 100000


#define WCET_BALL          60

#define PERIOD_BALL      10000


/*
 *
 * Soundcard related defines
 *
 */



/* Samples are 16-bit signed integers */
typedef short SAMPLE;
#define MAX_SAMPLE 32768



/*
 *
 * FFT defines
 *
 */


/* Numbers of samples of the sample window */
#define WINDATA_NSAMPLES  512

/* task WAVE */
/* the point (wave_x,wave_y) is on the center left of the area... */
#define WAVE_NSAMPLES 384
#define WAVE_X        0
#define WAVE_Y        64
#define WAVE_HEIGHT   32

/* task FFT */
#define FFT_NSAMPLES  512
#define PWR_NSAMPLES  (FFT_NSAMPLES/2+1)

/* task EQU */
/* the point (equ_x, equ_y) is the top right corner */
#define EQU_NSAMPLES  PWR_NSAMPLES
#define EQU_X         64
#define EQU_Y         128
#define EQU_HEIGHT    64
#define EQU_SHADE

/* task EQU2D */
/* the point (equ2d_x, equ2d_y) is the top left corner */
#define EQU2D_NSAMPLES  EQU_NSAMPLES
#define EQU2D_X         128
#define EQU2D_Y         EQU_Y
#define EQU2D_WIDTH     255
#define EQU2D_CLIP      255

/* scenario */
#define SCENARIO_NLABEL 16

/* Scale factors */
#define FFT_SCALE   (16384.0)
#define EQU_SCALE   (32.0)
#define EQU2D_SCALE (8.0)
//#define EQU_SCALE   (64.0)
//#define EQU2D_SCALE (16.0)



/* Informations about the sampling rate and buffers */
extern WORD rawdata_nsamples;
extern WORD rawdata_buffer_size;
extern WORD rawdata_freq;



/*
 *
 * Global Stuffs
 *
 */


/* graphic mutex... */
extern mutex_t mutex;

/* useful colors... */
extern int white;
extern int black;
extern int red;
extern int gray;

/* define if shorts critical sections wanted */
#define SHORT_CRITICAL_SECTIONS(x) \
  if (!((x)%64))                   \
    {                              \
      mutex_lock(&mutex);          \
      mutex_unlock(&mutex);        \
    }


void init_fftplay(int freq);
void init_framegrabber();
void init_jetcontrol();
void init_ball(void);
void start_framegrabber();


void scenario_jetcontrol(void);
void scenario_fftplay(int f);
void scenario_framegrabber();
void scenario_ball();

void compute_params(int *freq,WORD *nsamp);

char * itoa(int n, char *s);

/*
 *
 * Framegrabber stuffs
 *
 */


// if defined... object black on a white background
#ifndef __BLACK_ON_WHITE
#define __BLACK_ON_WHITE
#endif

#define ABS_NUM(a) ((a >= 0) ? a : -a)
#define MIN_NUM(a, b) ((a < b) ? a : b)
#define MAX_NUM(a, b) ((a > b) ? a : b)


// Cols and rows  of the framegrabber image
#define N_COL         384
#define N_ROW         288
#define N_BPS           8   // Bits per pixel
#define N_GRIGI       256

#define N_FRAMES      100

/* pixel of the video image */
#define IMG_COL       256
#define IMG_ROW       192

/* position of the video image */
#define IMG_X         384
#define IMG_Y         32

// I singoli pixel sono caratteri a 8 bit
typedef unsigned char TPixel;

typedef struct {
  int x1, y1;
  int x2, y2;
  int xb, yb;
  TIME time_stamp;
} TDataObj;

typedef struct {
  int found;
  int top_frame;
  int vx,vy;
  int predx;
  int predy;
  TDataObj current;
} TTracking;


float distance(unsigned int x1, unsigned int y1,
               unsigned int x2, unsigned int y2);

char scan_all_frame(TDataObj *data, TPixel *in_frame);

char scan_window_frame(TDataObj *data, TPixel *in_frame,
                       unsigned int xc, unsigned int yc, int border);

void threshold_up_function(KEY_EVT key);
void threshold_down_function(KEY_EVT key);

void border_up_function(KEY_EVT key);
void border_down_function(KEY_EVT key);

void tracking(int top_frame, int *track_x, int *track_y, int *int_vx, int *int_vy, int time_to);

TASK elab_image_TASK(void);



/*
 *
 * JETCONTROL stuffs
 *
 */


#define JET_NTASK   18
#define JET_Y_NAME 320

#define DUMMY_PID    1

#define JET_DUMMY_WIDTH    210
#define JET_DUMMY_HEIGHT    40

/* the point (x, y) is the top left corner */
#define JET_DUMMY_X        428
#define JET_DUMMY_Y        264

#define JET_SLIDE_WIDTH     50
#define JET_SLIDE_X        576




/*
 *
 * BALL stuffs
 *
 */


// x and y corners are specified whithout consider a border of 3 pixels
#define BALL_Y     475          /* position of the floor        */
#define BALL_HEIGHT 70          /* initial height of the ball   */
#define BALL_XMIN    3          /* min position X of the ball   */
#define BALL_XMAX  380          /* max position X of the ball   */
#define BALL_VELX    5.         /* horizontal ball velocity     */
#define BALL_VYMIN  11.         /* velocitÂ… minima per suono    */
#define BALL_MAX_P  50          /* max number of balls          */

#define BALL_GROUP   2          /* task group of the balls */