Subversion Repositories shark

Rev

Rev 1189 | Rev 1424 | 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"
37
 
1423 giacomo 38
#include "drivers/shark_keyb26.h"
39
#include "drivers/shark_videodev26.h"
40
 
1174 giacomo 41
#define WIDTH 640
42
#define HEIGHT 480
43
#define BYTES_PP 2
44
 
45
unsigned char *video_buf = NULL; //Video Buffer
46
unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16
47
unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem
48
 
49
#define FG_PERIOD 40000
50
#define FG_WCET 30000
51
#define FG_W 320                
52
#define FG_H 200
53
 
1423 giacomo 54
void program_end(void *arg)
55
{
1174 giacomo 56
 
1423 giacomo 57
  sys_end();
58
 
59
}
1174 giacomo 60
 
1423 giacomo 61
TASK grab_task(void *arg) {
1174 giacomo 62
 
1423 giacomo 63
  struct video_picture vpic;
64
  struct video_buffer fbuf;
65
  struct video_window win;
66
  struct video_channel chan;
1174 giacomo 67
 
1423 giacomo 68
  task_nopreempt();
1174 giacomo 69
 
1423 giacomo 70
  VIDEODEV26_open(0);
71
 
72
  VIDEODEV26_ioctl(0,VIDIOCGCHAN,(unsigned long)&chan);
73
 
74
  chan.channel = (int)(arg);
75
 
76
  VIDEODEV26_ioctl(0,VIDIOCSCHAN,(unsigned long)&chan);
77
 
78
  VIDEODEV26_ioctl(0,VIDIOCGPICT,(unsigned long)&vpic);
79
 
80
  vpic.palette = VIDEO_PALETTE_RGB565;
81
 
82
  VIDEODEV26_ioctl(0,VIDIOCSPICT,(unsigned long)&vpic);
83
 
84
  fbuf.base = malloc(640*480*2);
85
  fbuf.width = 320;
86
  fbuf.height = 200;
87
  fbuf.bytesperline = 640*2;
88
  fbuf.depth = 16;
89
 
90
  VIDEODEV26_ioctl(0,VIDIOCSFBUF,(unsigned long)&fbuf);
1174 giacomo 91
 
1423 giacomo 92
  VIDEODEV26_ioctl(0,VIDIOCGWIN,(unsigned long)&win);
1189 giacomo 93
 
1423 giacomo 94
  win.x = 0;
95
  win.y = 0;
96
  win.width = 320;
97
  win.height = 200;
98
 
99
  VIDEODEV26_ioctl(0,VIDIOCSWIN,(unsigned long)&win);
1174 giacomo 100
 
1423 giacomo 101
  task_preempt();
102
 
103
  while(1) {
104
 
105
    task_nopreempt();
106
 
107
    VIDEODEV26_ioctl(0,VIDIOCCAPTURE,NULL);
108
 
109
    task_preempt();
110
 
111
    task_endcycle();
112
 
113
  }
114
 
1174 giacomo 115
}
116
 
117
void elaborate_image(void *imageptr)
118
{
1423 giacomo 119
/*
1174 giacomo 120
  WORD x,y;
121
  BYTE *col;
122
 
123
  if (color == FG_MONO) {
124
 
125
    for(y = 0; y < FG_H; y++)
126
      for(x = 0; x < FG_W; x++) {
127
 
128
        col = (BYTE *)(imageptr + y*FG_W + x);
129
        *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col));
130
 
131
    }
132
 
133
  }
134
 
135
  if (color == FG_RGB24) {
136
 
137
    for(y = 0; y < FG_H; y++)
138
      for(x = 0; x < FG_W; x++) {
139
 
140
        col = (BYTE *)(imageptr + y*(FG_W*3) + (x*3));
141
        *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col+1),*(BYTE *)(col+2));
142
 
143
    }
144
 
145
  }
1423 giacomo 146
*/
147
  printf_xy(0,0,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 50*FG_W + 50));
148
  printf_xy(0,1,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 51*FG_W + 50));
1174 giacomo 149
 
150
}
151
 
152
int main(int argc, char **argv)
153
{
154
 
1423 giacomo 155
  SOFT_TASK_MODEL st;
156
  PID grab_task_pid;
1174 giacomo 157
 
1423 giacomo 158
  soft_task_default_model(st);
159
  soft_task_def_period(st,50000);
160
  soft_task_def_met(st,10000);
161
  soft_task_def_arg(st, (void *)(1));
162
  soft_task_def_ctrl_jet(st);
1174 giacomo 163
 
1423 giacomo 164
  grab_task_pid = task_create("GrabTask",grab_task,&st,NULL);
165
  if (grab_task_pid == NIL) {
166
        cprintf("ERROR: Cannot create grab task\n");
167
        sys_end();
168
  }
1174 giacomo 169
 
1423 giacomo 170
  task_activate(grab_task_pid);
1174 giacomo 171
 
1189 giacomo 172
  while(keyb_getch(BLOCK) != ESC);
173
 
1423 giacomo 174
  sys_end();
1189 giacomo 175
 
1174 giacomo 176
  return 0;
177
 
178
}