Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1126 | 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 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | #include <drivers/vga.h> |
||
20 | #include <drivers/keyb.h> |
||
21 | |||
22 | #include <math.h> |
||
23 | #include <stdlib.h> |
||
24 | |||
25 | #include <kernel/log.h> |
||
26 | #include <kernel/kern.h> |
||
27 | |||
28 | #define WIDTH 640 |
||
29 | #define HEIGHT 480 |
||
30 | #define BYTES_PP 2 |
||
31 | #define INITSTR G640x480x64K //SVGAlib standard mode definitions |
||
32 | #define CARD NV3 //Video driver (Supported SAVAGE, NV3, R128 from SVGALib) |
||
33 | |||
34 | unsigned char *rgb_565_buf = NULL; //RGB 16 bpp Buffer |
||
35 | unsigned char *video_buf = NULL; //Video Buffer |
||
36 | unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16 |
||
37 | unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem |
||
38 | |||
39 | unsigned long int PERIOD_REFRESH = 40000; //fps = 25 |
||
40 | unsigned long int PERIOD_DISEGNA = 80000; |
||
41 | |||
42 | unsigned long int WCET_REFRESH, WCET_DISEGNA; |
||
43 | |||
44 | TASK refesh(void); |
||
45 | TASK disegna(void); |
||
46 | |||
47 | PID refresh_PID, disegna_PID; |
||
48 | |||
49 | static int screen(int mode) |
||
50 | { |
||
51 | |||
52 | vga_modeinfo *minf; |
||
53 | |||
54 | vga_setmode(mode,CARD); |
||
55 | minf = vga_getmodeinfo(mode); |
||
56 | if(! (minf->flags & CAPABLE_LINEAR)){ |
||
57 | vga_setmode(TEXT,CARD); |
||
58 | printk(KERN_INFO "The mode %d is not capable of linear\n",mode); |
||
59 | return 1; |
||
60 | } |
||
61 | vga_setpage(0); |
||
62 | if(vga_setlinearaddressing() == -1) { |
||
63 | vga_setmode(TEXT,CARD); |
||
64 | printk(KERN_INFO "Could not set linear addressing for mode %d\n",mode); |
||
65 | return 1; |
||
66 | } |
||
67 | |||
68 | video_buf = vga_getgraphmem(); |
||
69 | rgb_565_buf = malloc(RGB565MEM); |
||
70 | |||
71 | grx_setbuffer(rgb_565_buf, WIDTH, HEIGHT); //Init of RGBA version of grx functions |
||
72 | //created to work with Mesa buffer |
||
73 | return 0; |
||
74 | |||
75 | } |
||
76 | |||
77 | void program_end(void *arg) |
||
78 | { |
||
79 | |||
80 | free(rgb_565_buf); |
||
81 | |||
82 | vga_setmode(TEXT,CARD); |
||
83 | |||
84 | sys_end(); |
||
85 | |||
86 | } |
||
87 | |||
88 | void program_key_end(KEY_EVT *k) |
||
89 | { |
||
90 | |||
91 | sys_end(); |
||
92 | |||
93 | } |
||
94 | |||
95 | TASK refresh(void) |
||
96 | { |
||
97 | |||
98 | while(1) { |
||
99 | |||
100 | copy_videomem_16to16(rgb_565_buf, video_buf, VMEMLONG); |
||
101 | task_endcycle(); |
||
102 | |||
103 | } |
||
104 | |||
105 | sys_end(); |
||
106 | |||
107 | } |
||
108 | |||
109 | |||
110 | TASK disegna(void) |
||
111 | { |
||
112 | |||
113 | char text[100]; |
||
114 | TIME disegna_TIME, refresh_TIME; |
||
115 | |||
116 | while(1) { |
||
117 | |||
118 | jet_gettable(refresh_PID, &refresh_TIME, 1); |
||
119 | jet_gettable(disegna_PID, &disegna_TIME, 1); |
||
120 | |||
121 | sprintf(text,"Hard Task Refresh PER:%6d us EX:%6d us",(int)PERIOD_REFRESH,(int)refresh_TIME); |
||
122 | grx_text(text,10,5,rgb16(0,0,255),0); |
||
123 | sprintf(text,"Hard Task Draw PER:%6d us EX:%6d us",(int)PERIOD_DISEGNA,(int)disegna_TIME); |
||
124 | grx_text(text,10,15,rgb16(0,0,255),0); |
||
125 | |||
126 | grx_text("SVGADEMO", 10,25,rgb16(255,0,0), 0); |
||
127 | grx_line(50,50,100,100,rgb16(0,255,0)); |
||
128 | grx_box(110,50,160,100,rgb16(0,0,255)); |
||
129 | grx_rect(170,50,220,100,rgb16(0,255,255)); |
||
130 | |||
131 | task_endcycle(); |
||
132 | |||
133 | } |
||
134 | |||
135 | sys_end(); |
||
136 | |||
137 | } |
||
138 | |||
139 | int main (int argc, char *argv[]) |
||
140 | { |
||
141 | |||
142 | HARD_TASK_MODEL ht_refresh, ht_disegna; |
||
143 | |||
144 | sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT); |
||
145 | |||
146 | clear(); |
||
147 | |||
148 | WCET_REFRESH =((long int) PERIOD_REFRESH * (0.7)); |
||
149 | WCET_DISEGNA =((long int) PERIOD_DISEGNA * (0.15)); |
||
150 | |||
151 | hard_task_default_model(ht_refresh); |
||
152 | hard_task_def_wcet(ht_refresh,WCET_REFRESH); |
||
153 | hard_task_def_mit(ht_refresh,PERIOD_REFRESH); |
||
154 | hard_task_def_usemath(ht_refresh); |
||
155 | hard_task_def_group(ht_refresh,1); |
||
156 | hard_task_def_ctrl_jet(ht_refresh); |
||
157 | |||
158 | refresh_PID = task_create("refresh", refresh, &ht_refresh, NULL); |
||
159 | if (refresh_PID == -1) { |
||
160 | sys_end(); |
||
161 | exit(4); |
||
162 | } |
||
163 | |||
164 | hard_task_default_model(ht_disegna); |
||
165 | hard_task_def_mit(ht_disegna,PERIOD_DISEGNA); |
||
166 | hard_task_def_wcet(ht_disegna,WCET_DISEGNA); |
||
167 | hard_task_def_group(ht_disegna,1); |
||
168 | hard_task_def_ctrl_jet(ht_disegna); |
||
169 | hard_task_def_usemath(ht_disegna); |
||
170 | |||
171 | disegna_PID = task_create("disegna", disegna, &ht_disegna, NULL); |
||
172 | if (disegna_PID == -1) { |
||
173 | sys_end(); |
||
174 | exit(4); |
||
175 | } |
||
176 | |||
177 | { |
||
178 | KEY_EVT k; |
||
179 | k.flag = ALTL_BIT; |
||
180 | k.scan = KEY_C; |
||
181 | k.ascii = 'c'; |
||
182 | keyb_hook(k,program_key_end); |
||
183 | } |
||
184 | |||
185 | if (screen(INITSTR)) { |
||
186 | printk(KERN_INFO "Graphical initialization failed !!\n"); |
||
187 | sys_end(); |
||
188 | } |
||
189 | |||
190 | memset(rgb_565_buf, 0, RGB565MEM); |
||
191 | |||
192 | group_activate(1); |
||
193 | |||
194 | return 0; |
||
195 | |||
196 | } |