Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

#include <kernel/kern.h>
#include <drivers/glib.h>
#include <drivers/keyb.h>
#include <kernel/func.h>
#include <modules/cabs.h>
#include <semaphore.h>
#include <stdlib.h>
#include <math.h>

#define  MAX_TRAIN      25 /* max number of trains*/
#define  MAX_CITY       4 /* max number of cities*/
#define  MAX_TRACK      12 /* max number of TRACKS*/
#define NCAB    10              /* max number of CABs   */
#define NCAR    26              /* generated characters */

#define sgn(x) ((x<0)?-1:((x>0)?1:0)) /* macro to return the sign of a
                                         number */
#define YMENU    10             /* menu level                   */
#define XMIN     50
#define XMAX     1000
#define YMIN     200
#define YMAX     700
#define VEL      5              /* linear velocity (def. = 5)   */
#define ANG      30             /* angolo massimo sterzata (30) */
#define D        3              /* raggio mosca                 */
#define ESC      27             /* ASCII code of ESCAPE key     */
#define MAX_P    35             /* max number of flies          */
#define FLYGROUP 1

struct{
int source,desti,tracknum,check;
} train[MAX_TRAIN];

struct{
int id,col;
} param;


struct{
      int cx,cy,source,destination,track;
} traininfo[MAX_TRAIN];

static int count = 0;
static  int start = 0;

char    *cname[NCAB] = {"cab1", "cab2", "cab3", "cab4","cab5","cab6","cab7","cab8","cab10","cab11","cab12"};
char    *pname1[NCAB] = {"wr1", "wr2", "wr3", "wr4"};
char    *pname2[NCAB] = {"rd1", "rd2", "rd3", "rd4"};

CAB     cid[NCAB];              /* CAB identifiers      */
PID     p1[NCAB], p2[NCAB];     /* task identifiers     */

/* Task Periods */
TIME    t1 = 100000; //for producer
TIME    t2[NCAB] = {400000, 400000, 150000, 200000}; /*for telling the reached station */

/* Task WCETS */
TIME    w1 = 10000;
TIME    w2[NCAB] = {10000, 10000, 10000, 10000};

TIME     my_time;
PID     ptas_for_train[MAX_TRAIN];
PID     controller;


sem_t   mx_segments[10], mx_graphics, mx_flag[MAX_TRACK];     /** mutex semaphores      */
sem_t   mx_track[MAX_CITY];
int status[MAX_TRAIN];              /** THIS IS USED BY THE CONTROLLER*/
int speed[MAX_TRAIN];                  /** THIS IS USED BY THE CONTROLLER*/
int plan[MAX_CITY][MAX_CITY][10];       /** THIS IS USED BY THE CONTROLLER*/
int flag[MAX_TRACK];
// variable for track
int graph[MAX_CITY][2] ={
                         { 195,250 },
                         { 500,250},
                         { 500,600 },
                         { 195,600}
                          };

int source[MAX_CITY][2] ={
                         { 200,250 },
                         { 500,255},
                         { 495,600 },
                         { 195,595}
                          };
int destination[MAX_CITY][2] ={
                        { 195,255 },
                         { 495,250},
                         { 500,595 },
                         { 200,600}
                          };


                         // look for illa.c for previous working version
int track_taken;

double  tick = 1.0;             /* system tick = 1 ms           */
int     H_fly_period = 20000;     /* task period                  */
int     H_fly_wcet = 1000;        /* task wcet                    */
int     S_fly_period = 30000;     /* task period                  */
int     S_fly_wcet = 1000;        /* task wcet                    */
PID     pid;
sem_t   mutex;
float _i_blocking[MAX_TRAIN];