Rev 1428 | Rev 1443 | 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 | |||
48 | #define FG_PERIOD 40000 |
||
49 | #define FG_WCET 30000 |
||
50 | #define FG_W 320 |
||
51 | #define FG_H 200 |
||
52 | |||
1423 | giacomo | 53 | void program_end(void *arg) |
54 | { |
||
1174 | giacomo | 55 | |
1423 | giacomo | 56 | sys_end(); |
57 | |||
58 | } |
||
1174 | giacomo | 59 | |
1424 | giacomo | 60 | void elaborate_image(void *imageptr); |
61 | |||
1423 | giacomo | 62 | TASK grab_task(void *arg) { |
1174 | giacomo | 63 | |
1423 | giacomo | 64 | struct video_picture vpic; |
1425 | giacomo | 65 | struct video_buffer fbuf[2]; |
1423 | giacomo | 66 | struct video_window win; |
67 | struct video_channel chan; |
||
1425 | giacomo | 68 | int on,display,temp,save; |
1174 | giacomo | 69 | |
1423 | giacomo | 70 | task_nopreempt(); |
1174 | giacomo | 71 | |
1432 | giacomo | 72 | /* Init videodev driver */ |
73 | VIDEODEV26_open(0); |
||
74 | |||
75 | chan.channel = (int)(arg); |
||
76 | chan.norm = VIDEO_TYPE_CAMERA; |
||
1423 | giacomo | 77 | |
78 | VIDEODEV26_ioctl(0,VIDIOCSCHAN,(unsigned long)&chan); |
||
1432 | giacomo | 79 | |
1427 | giacomo | 80 | /* Select palette and depth */ |
1423 | giacomo | 81 | VIDEODEV26_ioctl(0,VIDIOCGPICT,(unsigned long)&vpic); |
82 | |||
1424 | giacomo | 83 | vpic.palette = VIDEO_PALETTE_GREY; |
84 | vpic.depth = 8; |
||
85 | |||
1423 | giacomo | 86 | VIDEODEV26_ioctl(0,VIDIOCSPICT,(unsigned long)&vpic); |
1424 | giacomo | 87 | |
1427 | giacomo | 88 | /* Double Buffering Strategy */ |
89 | |||
1432 | giacomo | 90 | fbuf[0].base = malloc(FG_W*FG_H); |
91 | fbuf[0].height = FG_H; |
||
92 | fbuf[0].width = FG_W; |
||
93 | fbuf[0].bytesperline = FG_W; |
||
1425 | giacomo | 94 | fbuf[0].depth = 8; |
95 | |||
1432 | giacomo | 96 | fbuf[1].base = malloc(FG_W*FG_H); |
97 | fbuf[1].height = FG_H; |
||
98 | fbuf[1].width = FG_W; |
||
99 | fbuf[1].bytesperline = FG_W; |
||
1425 | giacomo | 100 | fbuf[1].depth = 8; |
101 | |||
102 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[0])); |
||
103 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[1])); |
||
104 | |||
1427 | giacomo | 105 | /* Set grabbing window */ |
1423 | giacomo | 106 | VIDEODEV26_ioctl(0,VIDIOCGWIN,(unsigned long)&win); |
1424 | giacomo | 107 | |
1423 | giacomo | 108 | win.x = 0; |
109 | win.y = 0; |
||
1432 | giacomo | 110 | win.width = FG_W; |
111 | win.height = FG_H; |
||
1423 | giacomo | 112 | |
113 | VIDEODEV26_ioctl(0,VIDIOCSWIN,(unsigned long)&win); |
||
1424 | giacomo | 114 | |
1423 | giacomo | 115 | task_preempt(); |
1425 | giacomo | 116 | |
117 | display = 1; |
||
118 | save = 0; |
||
119 | |||
1423 | giacomo | 120 | while(1) { |
121 | |||
122 | task_nopreempt(); |
||
1424 | giacomo | 123 | |
1427 | giacomo | 124 | /* Set the current buffer */ |
1425 | giacomo | 125 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[save])); |
1423 | giacomo | 126 | |
1427 | giacomo | 127 | /* Start grabbing */ |
1424 | giacomo | 128 | on = 1; |
129 | VIDEODEV26_ioctl(0,VIDIOCCAPTURE,(unsigned long)&on); |
||
1425 | giacomo | 130 | |
1423 | giacomo | 131 | task_preempt(); |
1428 | giacomo | 132 | /* |
1432 | giacomo | 133 | printf_xy(1,20,WHITE,"%08x%08x", |
1428 | giacomo | 134 | *(unsigned int *)(fbuf[display].base+50*320+50), |
135 | *(unsigned int *)(fbuf[display].base+50*320+54)); |
||
136 | */ |
||
137 | |||
1425 | giacomo | 138 | elaborate_image(fbuf[display].base); |
1423 | giacomo | 139 | |
1427 | giacomo | 140 | /* Buffer switch */ |
1425 | giacomo | 141 | temp = display; |
142 | display = save; |
||
143 | save = temp; |
||
1424 | giacomo | 144 | |
1432 | giacomo | 145 | task_testcancel(); |
1424 | giacomo | 146 | task_endcycle(); |
147 | |||
1423 | giacomo | 148 | } |
149 | |||
1424 | giacomo | 150 | return NULL; |
151 | |||
1174 | giacomo | 152 | } |
153 | |||
1424 | giacomo | 154 | extern void *video_memory; |
155 | |||
1174 | giacomo | 156 | void elaborate_image(void *imageptr) |
157 | { |
||
1424 | giacomo | 158 | |
1174 | giacomo | 159 | WORD x,y; |
160 | BYTE *col; |
||
161 | |||
162 | for(y = 0; y < FG_H; y++) |
||
163 | for(x = 0; x < FG_W; x++) { |
||
164 | |||
1424 | giacomo | 165 | col = (BYTE *)(imageptr + y * FG_W + x); |
166 | *(WORD *)(video_memory + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col)); |
||
1174 | giacomo | 167 | |
168 | } |
||
169 | |||
170 | } |
||
171 | |||
172 | int main(int argc, char **argv) |
||
173 | { |
||
174 | |||
1423 | giacomo | 175 | SOFT_TASK_MODEL st; |
176 | PID grab_task_pid; |
||
1174 | giacomo | 177 | |
1432 | giacomo | 178 | if (argc < 2) return -1; |
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); |
||
1432 | giacomo | 183 | soft_task_def_arg(st, (void *)(atoi(argv[1]))); |
1423 | giacomo | 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 | |||
1432 | giacomo | 196 | task_kill(grab_task_pid); |
197 | |||
198 | sleep(1); |
||
199 | |||
1423 | giacomo | 200 | sys_end(); |
1189 | giacomo | 201 | |
1174 | giacomo | 202 | return 0; |
203 | |||
204 | } |