Rev 1425 | Rev 1427 | 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 | |
1423 | giacomo | 75 | VIDEODEV26_open(0); |
76 | |||
77 | VIDEODEV26_ioctl(0,VIDIOCGCHAN,(unsigned long)&chan); |
||
78 | |||
1424 | giacomo | 79 | chan.channel = (int)(arg); |
80 | |||
1423 | giacomo | 81 | VIDEODEV26_ioctl(0,VIDIOCSCHAN,(unsigned long)&chan); |
82 | |||
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 | |
1425 | giacomo | 90 | fbuf[0].base = malloc(320*200); |
91 | fbuf[0].height = 200; |
||
92 | fbuf[0].width = 320; |
||
93 | fbuf[0].bytesperline = 320; |
||
94 | fbuf[0].depth = 8; |
||
95 | |||
96 | fbuf[1].base = malloc(320*200); |
||
97 | fbuf[1].height = 200; |
||
98 | fbuf[1].width = 320; |
||
99 | fbuf[1].bytesperline = 320; |
||
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 | |||
1423 | giacomo | 105 | VIDEODEV26_ioctl(0,VIDIOCGWIN,(unsigned long)&win); |
1424 | giacomo | 106 | |
1423 | giacomo | 107 | win.x = 0; |
108 | win.y = 0; |
||
109 | win.width = 320; |
||
110 | win.height = 200; |
||
111 | |||
112 | VIDEODEV26_ioctl(0,VIDIOCSWIN,(unsigned long)&win); |
||
1424 | giacomo | 113 | |
1423 | giacomo | 114 | task_preempt(); |
1425 | giacomo | 115 | |
116 | display = 1; |
||
117 | save = 0; |
||
118 | |||
1423 | giacomo | 119 | while(1) { |
120 | |||
121 | task_nopreempt(); |
||
1424 | giacomo | 122 | |
1425 | giacomo | 123 | VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&(fbuf[save])); |
1423 | giacomo | 124 | |
1424 | giacomo | 125 | on = 1; |
126 | VIDEODEV26_ioctl(0,VIDIOCCAPTURE,(unsigned long)&on); |
||
1425 | giacomo | 127 | |
1423 | giacomo | 128 | task_preempt(); |
129 | |||
1425 | giacomo | 130 | elaborate_image(fbuf[display].base); |
1423 | giacomo | 131 | |
1425 | giacomo | 132 | temp = display; |
133 | display = save; |
||
134 | save = temp; |
||
1424 | giacomo | 135 | |
136 | task_endcycle(); |
||
137 | |||
1423 | giacomo | 138 | } |
139 | |||
1424 | giacomo | 140 | return NULL; |
141 | |||
1174 | giacomo | 142 | } |
143 | |||
1424 | giacomo | 144 | extern void *video_memory; |
145 | |||
1174 | giacomo | 146 | void elaborate_image(void *imageptr) |
147 | { |
||
1424 | giacomo | 148 | |
1174 | giacomo | 149 | WORD x,y; |
150 | BYTE *col; |
||
151 | |||
152 | for(y = 0; y < FG_H; y++) |
||
153 | for(x = 0; x < FG_W; x++) { |
||
154 | |||
1424 | giacomo | 155 | col = (BYTE *)(imageptr + y * FG_W + x); |
156 | *(WORD *)(video_memory + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col)); |
||
1174 | giacomo | 157 | |
158 | } |
||
159 | |||
160 | } |
||
161 | |||
162 | int main(int argc, char **argv) |
||
163 | { |
||
164 | |||
1423 | giacomo | 165 | SOFT_TASK_MODEL st; |
166 | PID grab_task_pid; |
||
1174 | giacomo | 167 | |
1423 | giacomo | 168 | soft_task_default_model(st); |
1426 | giacomo | 169 | soft_task_def_period(st,40000); |
170 | soft_task_def_met(st,30000); |
||
1423 | giacomo | 171 | soft_task_def_arg(st, (void *)(1)); |
172 | soft_task_def_ctrl_jet(st); |
||
1174 | giacomo | 173 | |
1423 | giacomo | 174 | grab_task_pid = task_create("GrabTask",grab_task,&st,NULL); |
175 | if (grab_task_pid == NIL) { |
||
176 | cprintf("ERROR: Cannot create grab task\n"); |
||
177 | sys_end(); |
||
178 | } |
||
1174 | giacomo | 179 | |
1423 | giacomo | 180 | task_activate(grab_task_pid); |
1174 | giacomo | 181 | |
1189 | giacomo | 182 | while(keyb_getch(BLOCK) != ESC); |
183 | |||
1423 | giacomo | 184 | sys_end(); |
1189 | giacomo | 185 | |
1174 | giacomo | 186 | return 0; |
187 | |||
188 | } |