Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed


#include "config.h"

#include <kernel/func.h>
#include <kernel/const.h>
#include <kernel/model.h>
#include <kernel/types.h>

#include <drivers/glib.h>

#include <stdlib.h>

#include "mutex.h"
#include "gclock.h"

#ifdef FULLCOLOR
#define COLORFG rgb16(255,255,255)
#define COLORBG rgb16(0,0,0)
#else
#define COLORFG 255
#define COLORBG 0
#endif

struct info {
  int x;
  int y;
};

static TASK grxclock(struct info *ptr)
{
  char buffer[16];
  int min,sec;

  min=sec=0;
  for (;;) {
    sprintf(buffer,"%02i:%02i",min,sec);
#ifndef NOGRX
    grxlock();
    grx_text(buffer,ptr->x,ptr->y,COLORFG,COLORBG);
    grxunlock();
#endif
    sec++;
    if (sec==60) {
      sec=0;
      min++;
      if (min==60) min=0;
    }
    task_endcycle();
  }
  return NULL;
}

PID gclock_init(int x, int y)
{
  SOFT_TASK_MODEL model;
  struct info *ptr;

  ptr=(struct info *)malloc(sizeof(struct info));
  if (ptr==NULL) return -1;
  ptr->x=x+1;
  ptr->y=y+1;
 
#ifndef NOGRX
  grxlock();
  grx_box(x-1,y-1,x+GCLOCKDX-1,y+GCLOCKDY-1,COLORBG);
  grx_rect(x-1,y-1,x+GCLOCKDX-1,y+GCLOCKDY-1,COLORFG);     
  grx_text("00:00",ptr->x,ptr->y,COLORFG,COLORBG);
  grx_text("Clock",ptr->x,ptr->y-12,COLORFG,COLORBG);
  grxunlock();
#endif
 
  soft_task_default_model(model);    
  soft_task_def_met(model,5000);
  soft_task_def_wcet(model,5000);
  soft_task_def_period(model,1000000);  
  soft_task_def_periodic(model);
  soft_task_def_arg(model,(void*)ptr);
  //soft_task_def_ctrl_jet(model);
   
  return task_create("grxclock", grxclock, &model, NULL);
}