Rev 1426 | Rev 1428 | 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 | /* Open VideoDev */ |
1423 | giacomo | 76 | VIDEODEV26_open(0); |
1427 | giacomo | 77 | |
78 | /* Select input channel */ |
||
1423 | giacomo | 79 | VIDEODEV26_ioctl(0,VIDIOCGCHAN,(unsigned long)&chan); |
80 | |||
1424 | giacomo | 81 | chan.channel = (int)(arg); |
82 | |||
1423 | giacomo | 83 | VIDEODEV26_ioctl(0,VIDIOCSCHAN,(unsigned long)&chan); |
1427 | giacomo | 84 | |
85 | /* Select palette and depth */ |
||
1423 | giacomo | 86 | VIDEODEV26_ioctl(0,VIDIOCGPICT,(unsigned long)&vpic); |
87 | |||
1424 | giacomo | 88 | vpic.palette = VIDEO_PALETTE_GREY; |
89 | vpic.depth = 8; |
||
90 | |||
1423 | giacomo | 91 | VIDEODEV26_ioctl(0,VIDIOCSPICT,(unsigned long)&vpic); |
1424 | giacomo | 92 | |
1427 | giacomo | 93 | /* Double Buffering Strategy */ |
94 | |||
1425 | giacomo | 95 | fbuf[0].base = malloc(320*200); |
96 | fbuf[0].height = 200; |
||
97 | fbuf[0].width = 320; |
||
98 | fbuf[0].bytesperline = 320; |
||
99 | fbuf[0].depth = 8; |
||
100 | |||
101 | fbuf[1].base = malloc(320*200); |
||
102 | fbuf[1].height = 200; |
||
103 | fbuf[1].width = 320; |
||
104 | fbuf[1].bytesperline = 320; |
||
105 | fbuf[1].depth = 8; |
||
106 | |||
107 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[0])); |
||
108 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[1])); |
||
109 | |||
1427 | giacomo | 110 | /* Set grabbing window */ |
1423 | giacomo | 111 | VIDEODEV26_ioctl(0,VIDIOCGWIN,(unsigned long)&win); |
1424 | giacomo | 112 | |
1423 | giacomo | 113 | win.x = 0; |
114 | win.y = 0; |
||
115 | win.width = 320; |
||
116 | win.height = 200; |
||
117 | |||
118 | VIDEODEV26_ioctl(0,VIDIOCSWIN,(unsigned long)&win); |
||
1424 | giacomo | 119 | |
1423 | giacomo | 120 | task_preempt(); |
1425 | giacomo | 121 | |
122 | display = 1; |
||
123 | save = 0; |
||
124 | |||
1423 | giacomo | 125 | while(1) { |
126 | |||
127 | task_nopreempt(); |
||
1424 | giacomo | 128 | |
1427 | giacomo | 129 | /* Set the current buffer */ |
1425 | giacomo | 130 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[save])); |
1423 | giacomo | 131 | |
1427 | giacomo | 132 | |
133 | /* Start grabbing */ |
||
1424 | giacomo | 134 | on = 1; |
135 | VIDEODEV26_ioctl(0,VIDIOCCAPTURE,(unsigned long)&on); |
||
1425 | giacomo | 136 | |
1423 | giacomo | 137 | task_preempt(); |
138 | |||
1425 | giacomo | 139 | elaborate_image(fbuf[display].base); |
1423 | giacomo | 140 | |
1427 | giacomo | 141 | /* Buffer switch */ |
1425 | giacomo | 142 | temp = display; |
143 | display = save; |
||
144 | save = temp; |
||
1424 | giacomo | 145 | |
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 | |
1423 | giacomo | 178 | soft_task_default_model(st); |
1426 | giacomo | 179 | soft_task_def_period(st,40000); |
180 | soft_task_def_met(st,30000); |
||
1423 | giacomo | 181 | soft_task_def_arg(st, (void *)(1)); |
182 | soft_task_def_ctrl_jet(st); |
||
1174 | giacomo | 183 | |
1423 | giacomo | 184 | grab_task_pid = task_create("GrabTask",grab_task,&st,NULL); |
185 | if (grab_task_pid == NIL) { |
||
186 | cprintf("ERROR: Cannot create grab task\n"); |
||
187 | sys_end(); |
||
188 | } |
||
1174 | giacomo | 189 | |
1423 | giacomo | 190 | task_activate(grab_task_pid); |
1174 | giacomo | 191 | |
1189 | giacomo | 192 | while(keyb_getch(BLOCK) != ESC); |
193 | |||
1423 | giacomo | 194 | sys_end(); |
1189 | giacomo | 195 | |
1174 | giacomo | 196 | return 0; |
197 | |||
198 | } |