Subversion Repositories shark

Rev

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