Subversion Repositories shark

Rev

Rev 1154 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Project: S.Ha.R.K.
 *
 * Coordinators:
 *   Giorgio Buttazzo    <giorgio@sssup.it>
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *
 * Authors     :
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
 *
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


#include <drivers/vga.h>
#include <drivers/keyb.h>

#include <math.h>
#include <stdlib.h>

#include <kernel/log.h>
#include <kernel/kern.h>

#define WIDTH 800
#define HEIGHT 600
#define BYTES_PP 2
#define INITSTR G800x600x64K //SVGAlib standard mode definitions
#define CARD VESA //Video driver

unsigned char *rgb_565_buf = NULL; //RGB 16 bpp Buffer
unsigned char *video_buf = NULL; //Video Buffer
unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16
unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem

unsigned long int PERIOD_REFRESH = 100000;
unsigned long int PERIOD_DISEGNA = 100000;

unsigned long int WCET_REFRESH, WCET_DISEGNA;

TASK refesh(void);
TASK disegna(void);

PID refresh_PID, disegna_PID;

static int screen(int mode)
{

  vga_modeinfo *minf;

  vga_setmode(mode,CARD);
  minf = vga_getmodeinfo(mode);
  if(! (minf->flags & CAPABLE_LINEAR)){
    vga_setmode(TEXT,CARD);
    printk(KERN_INFO "The mode %d is not capable of linear\n",mode);
    return 1;
  }
  vga_setpage(0);
  if(vga_setlinearaddressing() == -1) {
    vga_setmode(TEXT,CARD);
    printk(KERN_INFO "Could not set linear addressing for mode %d\n",mode);
    return 1;
  }
 
  video_buf = vga_getgraphmem();
  rgb_565_buf = malloc(RGB565MEM);

  grx_setbuffer(rgb_565_buf, WIDTH, HEIGHT);    //Init of RGBA version of grx functions
                                                //created to work with Mesa buffer
  return 0;
 
}

void program_end(void *arg)
{
 
  free(rgb_565_buf);

  vga_setmode(TEXT,CARD);

  sys_end();

}

void program_key_end(KEY_EVT *k)
{

  sys_end();

}

TASK refresh(void)
{

  while(1) {

    copy_videomem_16to16(rgb_565_buf, video_buf, VMEMLONG);
    task_endcycle();

  }

  sys_end();

}


TASK disegna(void)
{

  char text[100];
  TIME disegna_TIME, refresh_TIME;
 
  while(1) {
   
    jet_gettable(refresh_PID, &refresh_TIME, 1);
    jet_gettable(disegna_PID, &disegna_TIME, 1);
 
    sprintf(text,"Hard Task Refresh PER:%6d us EX:%6d us",(int)PERIOD_REFRESH,(int)refresh_TIME);
    grx_text(text,10,5,rgb16(0,0,255),0);    
    sprintf(text,"Hard Task Draw    PER:%6d us EX:%6d us",(int)PERIOD_DISEGNA,(int)disegna_TIME);
    grx_text(text,10,15,rgb16(0,0,255),0);

    grx_text("SVGADEMO", 10,25,rgb16(255,0,0), 0);
    grx_line(50,50,100,100,rgb16(0,255,0));
    grx_box(110,50,160,100,rgb16(0,0,255));
    grx_rect(170,50,220,100,rgb16(0,255,255));

    task_endcycle();

  }

  sys_end();

}

int main (int argc, char *argv[])
{
   
    HARD_TASK_MODEL ht_refresh, ht_disegna;

    sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT);

    clear();
   
    WCET_REFRESH =((long int) PERIOD_REFRESH * (0.45));
    WCET_DISEGNA =((long int) PERIOD_DISEGNA * (0.45));

    hard_task_default_model(ht_refresh);
    hard_task_def_wcet(ht_refresh,WCET_REFRESH);
    hard_task_def_mit(ht_refresh,PERIOD_REFRESH);
    hard_task_def_usemath(ht_refresh);
    hard_task_def_group(ht_refresh,1);
    hard_task_def_ctrl_jet(ht_refresh);

    refresh_PID = task_create("refresh", refresh, &ht_refresh, NULL);
    if (refresh_PID == -1) {
      sys_end();
      exit(4);
    }

    hard_task_default_model(ht_disegna);
    hard_task_def_mit(ht_disegna,PERIOD_DISEGNA);
    hard_task_def_wcet(ht_disegna,WCET_DISEGNA);
    hard_task_def_group(ht_disegna,1);
    hard_task_def_ctrl_jet(ht_disegna);
    hard_task_def_usemath(ht_disegna);

    disegna_PID = task_create("disegna", disegna, &ht_disegna, NULL);
    if (disegna_PID == -1) {
      sys_end();
      exit(4);
    }

    {
      KEY_EVT k;
      k.flag = ALTL_BIT;
      k.scan = KEY_C;
      k.ascii = 'c';
      keyb_hook(k,program_key_end);
    }
       
    if (screen(INITSTR)) {
        printk(KERN_INFO "Graphical initialization failed !!\n");
        sys_end();
    }

    memset(rgb_565_buf, 0, RGB565MEM);

    group_activate(1);

    return 0;
       
}