Rev 1444 | Rev 1470 | 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" |
1432 | giacomo | 38 | #include "unistd.h" |
1174 | giacomo | 39 | |
1423 | giacomo | 40 | #include "drivers/shark_keyb26.h" |
41 | #include "drivers/shark_videodev26.h" |
||
1424 | giacomo | 42 | #include "drivers/shark_fb26.h" |
1423 | giacomo | 43 | |
1174 | giacomo | 44 | #define WIDTH 640 |
45 | #define HEIGHT 480 |
||
46 | #define BYTES_PP 2 |
||
47 | |||
1443 | giacomo | 48 | //#define COLOR |
49 | |||
1444 | giacomo | 50 | #define FRAME_GRABBER_NUMBER 0 |
51 | |||
1174 | giacomo | 52 | #define FG_PERIOD 40000 |
53 | #define FG_WCET 30000 |
||
54 | #define FG_W 320 |
||
55 | #define FG_H 200 |
||
56 | |||
1423 | giacomo | 57 | void program_end(void *arg) |
58 | { |
||
1174 | giacomo | 59 | |
1423 | giacomo | 60 | sys_end(); |
61 | |||
62 | } |
||
1174 | giacomo | 63 | |
1424 | giacomo | 64 | void elaborate_image(void *imageptr); |
65 | |||
1423 | giacomo | 66 | TASK grab_task(void *arg) { |
1174 | giacomo | 67 | |
1423 | giacomo | 68 | struct video_picture vpic; |
1425 | giacomo | 69 | struct video_buffer fbuf[2]; |
1423 | giacomo | 70 | struct video_window win; |
71 | struct video_channel chan; |
||
1443 | giacomo | 72 | struct video_tuner tuner; |
1425 | giacomo | 73 | int on,display,temp,save; |
1174 | giacomo | 74 | |
1423 | giacomo | 75 | task_nopreempt(); |
1174 | giacomo | 76 | |
1432 | giacomo | 77 | /* Init videodev driver */ |
1444 | giacomo | 78 | VIDEODEV26_open(FRAME_GRABBER_NUMBER); |
1432 | giacomo | 79 | |
1444 | giacomo | 80 | /* Select the input channel */ |
81 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCGCHAN,(unsigned long)&chan); |
||
1443 | giacomo | 82 | |
1432 | giacomo | 83 | chan.channel = (int)(arg); |
1443 | giacomo | 84 | chan.type = VIDEO_VC_TUNER; |
1432 | giacomo | 85 | chan.norm = VIDEO_TYPE_CAMERA; |
1423 | giacomo | 86 | |
1444 | giacomo | 87 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSCHAN,(unsigned long)&chan); |
1432 | giacomo | 88 | |
1444 | giacomo | 89 | /* Enable the tuner */ |
90 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCGTUNER,(unsigned long)&tuner); |
||
1443 | giacomo | 91 | |
92 | tuner.mode = VIDEO_MODE_PAL; |
||
93 | |||
1444 | giacomo | 94 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSTUNER,(unsigned long)&tuner); |
1443 | giacomo | 95 | |
1427 | giacomo | 96 | /* Select palette and depth */ |
1444 | giacomo | 97 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCGPICT,(unsigned long)&vpic); |
1443 | giacomo | 98 | |
99 | #ifdef COLOR |
||
100 | vpic.palette = VIDEO_PALETTE_RGB24; |
||
101 | vpic.depth = 24; |
||
102 | #else |
||
103 | vpic.palette = VIDEO_PALETTE_GREY; |
||
104 | vpic.depth = 8; |
||
105 | #endif |
||
106 | |||
107 | vpic.brightness = 35000; |
||
108 | vpic.hue = 32000; |
||
109 | vpic.contrast = 32000; |
||
110 | vpic.colour = 32000; |
||
1424 | giacomo | 111 | |
1444 | giacomo | 112 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSPICT,(unsigned long)&vpic); |
1424 | giacomo | 113 | |
1427 | giacomo | 114 | /* Double Buffering Strategy */ |
115 | |||
1443 | giacomo | 116 | #ifdef COLOR |
117 | |||
118 | fbuf[0].base = malloc(FG_W*FG_H*3); |
||
119 | fbuf[0].height = FG_H; |
||
120 | fbuf[0].width = FG_W; |
||
121 | fbuf[0].bytesperline = FG_W*3; |
||
122 | fbuf[0].depth = 24; |
||
1425 | giacomo | 123 | |
1443 | giacomo | 124 | fbuf[1].base = malloc(FG_W*FG_H*3); |
125 | fbuf[1].height = FG_H; |
||
126 | fbuf[1].width = FG_W; |
||
127 | fbuf[1].bytesperline = FG_W*3; |
||
128 | fbuf[1].depth = 24; |
||
1425 | giacomo | 129 | |
1443 | giacomo | 130 | #else |
1425 | giacomo | 131 | |
1443 | giacomo | 132 | fbuf[0].base = malloc(FG_W*FG_H); |
133 | fbuf[0].height = FG_H; |
||
134 | fbuf[0].width = FG_W; |
||
135 | fbuf[0].bytesperline = FG_W; |
||
136 | fbuf[0].depth = 8; |
||
137 | |||
138 | fbuf[1].base = malloc(FG_W*FG_H); |
||
139 | fbuf[1].height = FG_H; |
||
140 | fbuf[1].width = FG_W; |
||
141 | fbuf[1].bytesperline = FG_W; |
||
142 | fbuf[1].depth = 8; |
||
143 | |||
144 | #endif |
||
145 | |||
1427 | giacomo | 146 | /* Set grabbing window */ |
1444 | giacomo | 147 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCGWIN,(unsigned long)&win); |
1424 | giacomo | 148 | |
1423 | giacomo | 149 | win.x = 0; |
150 | win.y = 0; |
||
1432 | giacomo | 151 | win.width = FG_W; |
152 | win.height = FG_H; |
||
1423 | giacomo | 153 | |
1444 | giacomo | 154 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSWIN,(unsigned long)&win); |
1424 | giacomo | 155 | |
1423 | giacomo | 156 | task_preempt(); |
1425 | giacomo | 157 | |
158 | display = 1; |
||
159 | save = 0; |
||
160 | |||
1423 | giacomo | 161 | while(1) { |
162 | |||
163 | task_nopreempt(); |
||
1443 | giacomo | 164 | |
1444 | giacomo | 165 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCSFBUF,(unsigned long)&(fbuf[save])); |
1424 | giacomo | 166 | |
1427 | giacomo | 167 | /* Start grabbing */ |
1424 | giacomo | 168 | on = 1; |
1444 | giacomo | 169 | VIDEODEV26_ioctl(FRAME_GRABBER_NUMBER,VIDIOCCAPTURE,(unsigned long)&on); |
1425 | giacomo | 170 | |
1423 | giacomo | 171 | task_preempt(); |
1443 | giacomo | 172 | |
1428 | giacomo | 173 | /* |
1443 | giacomo | 174 | printf_xy(1,20,WHITE,"%08x", |
175 | *(unsigned int *)(fbuf[display].base+50*320*3+50*3)); |
||
1428 | giacomo | 176 | */ |
177 | |||
1425 | giacomo | 178 | elaborate_image(fbuf[display].base); |
1423 | giacomo | 179 | |
1427 | giacomo | 180 | /* Buffer switch */ |
1425 | giacomo | 181 | temp = display; |
182 | display = save; |
||
183 | save = temp; |
||
1424 | giacomo | 184 | |
1432 | giacomo | 185 | task_testcancel(); |
1424 | giacomo | 186 | task_endcycle(); |
187 | |||
1423 | giacomo | 188 | } |
189 | |||
1424 | giacomo | 190 | return NULL; |
191 | |||
1174 | giacomo | 192 | } |
193 | |||
1424 | giacomo | 194 | extern void *video_memory; |
195 | |||
1174 | giacomo | 196 | void elaborate_image(void *imageptr) |
197 | { |
||
1424 | giacomo | 198 | |
1174 | giacomo | 199 | WORD x,y; |
200 | BYTE *col; |
||
201 | |||
1443 | giacomo | 202 | #ifdef COLOR |
203 | |||
1174 | giacomo | 204 | for(y = 0; y < FG_H; y++) |
205 | for(x = 0; x < FG_W; x++) { |
||
206 | |||
1443 | giacomo | 207 | col = (BYTE *)(imageptr + y * FG_W * 3 + x * 3); |
208 | *(WORD *)(video_memory + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col+2),*(BYTE *)(col+1),*(BYTE *)(col+0)); |
||
1174 | giacomo | 209 | |
210 | } |
||
211 | |||
1443 | giacomo | 212 | #else |
213 | |||
214 | for(y = 0; y < FG_H; y++) |
||
215 | for(x = 0; x < FG_W; x++) { |
||
216 | |||
217 | col = (BYTE *)(imageptr + y * FG_W + x); |
||
218 | *(WORD *)(video_memory + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col)); |
||
219 | |||
220 | } |
||
221 | |||
222 | #endif |
||
223 | |||
1174 | giacomo | 224 | } |
225 | |||
226 | int main(int argc, char **argv) |
||
227 | { |
||
228 | |||
1423 | giacomo | 229 | SOFT_TASK_MODEL st; |
230 | PID grab_task_pid; |
||
1174 | giacomo | 231 | |
1444 | giacomo | 232 | if (argc < 2) { |
1445 | giacomo | 233 | sys_shutdown_message("ERROR: Enter the input channel [ex> %s 0]\n",argv[0]); |
1444 | giacomo | 234 | sys_end(); |
235 | } |
||
1432 | giacomo | 236 | |
1423 | giacomo | 237 | soft_task_default_model(st); |
1426 | giacomo | 238 | soft_task_def_period(st,40000); |
239 | soft_task_def_met(st,30000); |
||
1432 | giacomo | 240 | soft_task_def_arg(st, (void *)(atoi(argv[1]))); |
1423 | giacomo | 241 | soft_task_def_ctrl_jet(st); |
1174 | giacomo | 242 | |
1423 | giacomo | 243 | grab_task_pid = task_create("GrabTask",grab_task,&st,NULL); |
244 | if (grab_task_pid == NIL) { |
||
1444 | giacomo | 245 | sys_shutdown_message("ERROR: Cannot create grab task\n"); |
1423 | giacomo | 246 | sys_end(); |
247 | } |
||
1174 | giacomo | 248 | |
1423 | giacomo | 249 | task_activate(grab_task_pid); |
1174 | giacomo | 250 | |
1189 | giacomo | 251 | while(keyb_getch(BLOCK) != ESC); |
252 | |||
1432 | giacomo | 253 | task_kill(grab_task_pid); |
254 | |||
255 | sleep(1); |
||
256 | |||
1423 | giacomo | 257 | sys_end(); |
1189 | giacomo | 258 | |
1174 | giacomo | 259 | return 0; |
260 | |||
261 | } |