Rev 1427 | Rev 1432 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1174 | 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" |
||
1424 | giacomo | 37 | #include "stdlib.h" |
1174 | giacomo | 38 | |
1423 | giacomo | 39 | #include "drivers/shark_keyb26.h" |
40 | #include "drivers/shark_videodev26.h" |
||
1424 | giacomo | 41 | #include "drivers/shark_fb26.h" |
1423 | giacomo | 42 | |
1174 | giacomo | 43 | #define WIDTH 640 |
44 | #define HEIGHT 480 |
||
45 | #define BYTES_PP 2 |
||
46 | |||
47 | unsigned char *video_buf = NULL; //Video Buffer |
||
48 | unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16 |
||
49 | unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem |
||
50 | |||
51 | #define FG_PERIOD 40000 |
||
52 | #define FG_WCET 30000 |
||
53 | #define FG_W 320 |
||
54 | #define FG_H 200 |
||
55 | |||
1423 | giacomo | 56 | void program_end(void *arg) |
57 | { |
||
1174 | giacomo | 58 | |
1423 | giacomo | 59 | sys_end(); |
60 | |||
61 | } |
||
1174 | giacomo | 62 | |
1424 | giacomo | 63 | void elaborate_image(void *imageptr); |
64 | |||
1423 | giacomo | 65 | TASK grab_task(void *arg) { |
1174 | giacomo | 66 | |
1423 | giacomo | 67 | struct video_picture vpic; |
1425 | giacomo | 68 | struct video_buffer fbuf[2]; |
1423 | giacomo | 69 | struct video_window win; |
70 | struct video_channel chan; |
||
1425 | giacomo | 71 | int on,display,temp,save; |
1174 | giacomo | 72 | |
1423 | giacomo | 73 | task_nopreempt(); |
1174 | giacomo | 74 | |
1427 | giacomo | 75 | /* Select input channel */ |
1423 | giacomo | 76 | VIDEODEV26_ioctl(0,VIDIOCGCHAN,(unsigned long)&chan); |
77 | |||
1424 | giacomo | 78 | chan.channel = (int)(arg); |
79 | |||
1423 | giacomo | 80 | VIDEODEV26_ioctl(0,VIDIOCSCHAN,(unsigned long)&chan); |
1427 | giacomo | 81 | |
82 | /* Select palette and depth */ |
||
1423 | giacomo | 83 | VIDEODEV26_ioctl(0,VIDIOCGPICT,(unsigned long)&vpic); |
84 | |||
1424 | giacomo | 85 | vpic.palette = VIDEO_PALETTE_GREY; |
86 | vpic.depth = 8; |
||
87 | |||
1423 | giacomo | 88 | VIDEODEV26_ioctl(0,VIDIOCSPICT,(unsigned long)&vpic); |
1424 | giacomo | 89 | |
1427 | giacomo | 90 | /* Double Buffering Strategy */ |
91 | |||
1425 | giacomo | 92 | fbuf[0].base = malloc(320*200); |
93 | fbuf[0].height = 200; |
||
94 | fbuf[0].width = 320; |
||
95 | fbuf[0].bytesperline = 320; |
||
96 | fbuf[0].depth = 8; |
||
97 | |||
98 | fbuf[1].base = malloc(320*200); |
||
99 | fbuf[1].height = 200; |
||
100 | fbuf[1].width = 320; |
||
101 | fbuf[1].bytesperline = 320; |
||
102 | fbuf[1].depth = 8; |
||
103 | |||
104 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[0])); |
||
105 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[1])); |
||
106 | |||
1427 | giacomo | 107 | /* Set grabbing window */ |
1423 | giacomo | 108 | VIDEODEV26_ioctl(0,VIDIOCGWIN,(unsigned long)&win); |
1424 | giacomo | 109 | |
1423 | giacomo | 110 | win.x = 0; |
111 | win.y = 0; |
||
112 | win.width = 320; |
||
113 | win.height = 200; |
||
114 | |||
115 | VIDEODEV26_ioctl(0,VIDIOCSWIN,(unsigned long)&win); |
||
1424 | giacomo | 116 | |
1423 | giacomo | 117 | task_preempt(); |
1425 | giacomo | 118 | |
119 | display = 1; |
||
120 | save = 0; |
||
121 | |||
1423 | giacomo | 122 | while(1) { |
123 | |||
124 | task_nopreempt(); |
||
1424 | giacomo | 125 | |
1427 | giacomo | 126 | /* Set the current buffer */ |
1425 | giacomo | 127 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[save])); |
1423 | giacomo | 128 | |
1427 | giacomo | 129 | /* Start grabbing */ |
1424 | giacomo | 130 | on = 1; |
131 | VIDEODEV26_ioctl(0,VIDIOCCAPTURE,(unsigned long)&on); |
||
1425 | giacomo | 132 | |
1423 | giacomo | 133 | task_preempt(); |
1428 | giacomo | 134 | |
135 | /* |
||
136 | printf_xy(1,1,WHITE,"%08x%08x", |
||
137 | *(unsigned int *)(fbuf[display].base+50*320+50), |
||
138 | *(unsigned int *)(fbuf[display].base+50*320+54)); |
||
139 | */ |
||
140 | |||
1425 | giacomo | 141 | elaborate_image(fbuf[display].base); |
1423 | giacomo | 142 | |
1427 | giacomo | 143 | /* Buffer switch */ |
1425 | giacomo | 144 | temp = display; |
145 | display = save; |
||
146 | save = temp; |
||
1424 | giacomo | 147 | |
148 | task_endcycle(); |
||
149 | |||
1423 | giacomo | 150 | } |
151 | |||
1424 | giacomo | 152 | return NULL; |
153 | |||
1174 | giacomo | 154 | } |
155 | |||
1424 | giacomo | 156 | extern void *video_memory; |
157 | |||
1174 | giacomo | 158 | void elaborate_image(void *imageptr) |
159 | { |
||
1424 | giacomo | 160 | |
1174 | giacomo | 161 | WORD x,y; |
162 | BYTE *col; |
||
163 | |||
164 | for(y = 0; y < FG_H; y++) |
||
165 | for(x = 0; x < FG_W; x++) { |
||
166 | |||
1424 | giacomo | 167 | col = (BYTE *)(imageptr + y * FG_W + x); |
168 | *(WORD *)(video_memory + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col)); |
||
1174 | giacomo | 169 | |
170 | } |
||
171 | |||
172 | } |
||
173 | |||
174 | int main(int argc, char **argv) |
||
175 | { |
||
176 | |||
1423 | giacomo | 177 | SOFT_TASK_MODEL st; |
178 | PID grab_task_pid; |
||
1174 | giacomo | 179 | |
1423 | giacomo | 180 | soft_task_default_model(st); |
1426 | giacomo | 181 | soft_task_def_period(st,40000); |
182 | soft_task_def_met(st,30000); |
||
1423 | giacomo | 183 | soft_task_def_arg(st, (void *)(1)); |
184 | soft_task_def_ctrl_jet(st); |
||
1174 | giacomo | 185 | |
1423 | giacomo | 186 | grab_task_pid = task_create("GrabTask",grab_task,&st,NULL); |
187 | if (grab_task_pid == NIL) { |
||
188 | cprintf("ERROR: Cannot create grab task\n"); |
||
189 | sys_end(); |
||
190 | } |
||
1174 | giacomo | 191 | |
1423 | giacomo | 192 | task_activate(grab_task_pid); |
1174 | giacomo | 193 | |
1189 | giacomo | 194 | while(keyb_getch(BLOCK) != ESC); |
195 | |||
1423 | giacomo | 196 | sys_end(); |
1189 | giacomo | 197 | |
1174 | giacomo | 198 | return 0; |
199 | |||
200 | } |