Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1163 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
18
/*
19
 * Copyright (C) 2003 Giacomo Guidi
20
 *
21
 * This program is free software; you can redistribute it and/or modify
22
 * it under the terms of the GNU General Public License as published by
23
 * the Free Software Foundation; either version 2 of the License, or
24
 * (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34
 */
35
 
36
#include "kernel/kern.h"
37
#include <drivers/fg.h>
38
#include <drivers/vga.h>
39
#include <drivers/keyb.h>
40
#include <unistd.h>
41
#include <stdlib.h>
42
 
43
#define WIDTH 640
44
#define HEIGHT 480
45
#define BYTES_PP 2
46
#define INITSTR G640x480x64K //SVGAlib standard mode definitions
47
#define CARD VESA //Video driver
48
 
49
unsigned char *video_buf = NULL; //Video Buffer
50
unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16
51
unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem
52
 
53
unsigned long int PERIOD_REFRESH = 50000;
54
unsigned long int WCET_REFRESH = 20000;
55
 
56
void * fg_buffer;
57
 
58
int fg_p = 40000;
59
int fp_c = 15000;
60
int fg_w = 320;
61
int fg_h = 200;
62
 
63
static int screen(int mode)
64
{
65
 
66
  vga_modeinfo *minf;
67
 
68
  vga_setmode(mode,CARD);
69
  minf = vga_getmodeinfo(mode);
70
  if(! (minf->flags & CAPABLE_LINEAR)){
71
    vga_setmode(TEXT,CARD);
72
    printk(KERN_INFO "The mode %d is not capable of linear\n",mode);
73
    return 1;
74
  }
75
  vga_setpage(0);
76
  if(vga_setlinearaddressing() == -1) {
77
    vga_setmode(TEXT,CARD);
78
    printk(KERN_INFO "Could not set linear addressing for mode %d\n",mode);
79
    return 1;
80
  }
81
 
82
  video_buf = vga_getgraphmem();
83
 
84
  memset(video_buf, 0, RGB565MEM);
85
 
86
  grx_setbuffer(video_buf, WIDTH, HEIGHT);      //Init of RGBA version of grx functions
87
                                                //created to work with Mesa buffer
88
  return 0;
89
 
90
}
91
 
92
void program_end(void *arg)
93
{
94
 
95
  vga_setmode(TEXT,CARD);
96
 
97
  FG_close();
98
 
99
  sys_end();
100
 
101
}
102
 
103
void program_key_end(KEY_EVT *k)
104
{
105
 
106
  sys_end();
107
 
108
}
109
 
110
TASK ref(void)
111
{
112
 
113
  WORD col,x,y;
114
 
115
  while(1) {
116
 
117
    fg_buffer = FG_getbuffer();
118
 
119
    for(y = 0; y < fg_h; y++)
120
        for(x = 0; x < fg_w; x++) {
121
 
122
                col = *(BYTE *)(fg_buffer + y*fg_w + x);
123
                *(WORD *)(video_buf + y*(WIDTH*2) + x*2) = (WORD)rgb16(col,col,col);
124
 
125
        }
126
 
127
    task_endcycle();
128
 
129
  }
130
 
131
  sys_end();
132
 
133
}
134
 
135
int main(int argc, char **argv)
136
{
137
 
138
  HARD_TASK_MODEL ht_ref;
139
  PID ref_PID;
140
 
141
  sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT);
142
 
143
  hard_task_default_model(ht_ref);
144
  hard_task_def_wcet(ht_ref,WCET_REFRESH);
145
  hard_task_def_mit(ht_ref,PERIOD_REFRESH);
146
  hard_task_def_usemath(ht_ref);
147
  hard_task_def_group(ht_ref,1);
148
  hard_task_def_ctrl_jet(ht_ref);
149
 
150
  ref_PID = task_create("HT_ref", ref, &ht_ref, NULL);
151
  if (ref_PID == -1) {
152
    sys_end();
153
  }
154
 
155
  {
156
      KEY_EVT k;
157
      k.flag = ALTL_BIT;
158
      k.scan = KEY_C;
159
      k.ascii = 'c';
160
      keyb_hook(k,program_key_end);
161
  }
162
 
163
  screen(INITSTR);
164
 
165
  sleep(5);
166
 
167
  FG_init(fg_p, fp_c, fg_w, fg_h);
168
 
169
  task_activate(ref_PID);
170
 
171
  return 0;
172
 
173
}