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