Subversion Repositories shark

Rev

Rev 188 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
170 giacomo 1
/* Fast Frame Grabber for SHARK
2
 *
3
 * Giacomo Guidi
4
 * <giacomo@gandalf.sssup.it>
5
 *
6
 */
7
 
8
#include <drivers/bttv.h>
177 giacomo 9
#include <drivers/fg.h>
170 giacomo 10
#include <kernel/kern.h>
173 giacomo 11
#include <unistd.h>
170 giacomo 12
 
13
extern void bttv_start(struct bttv *btv);
14
extern int bttv_ioctl(struct bttv *btv, unsigned int cmg, void *arg);
15
extern void bttv_close(struct bttv *btv);
16
 
17
extern unsigned int gbufsize;
18
 
19
static struct bttv btv;
20
static struct video_mmap vmm;
173 giacomo 21
static void * fbuf_pointer;
170 giacomo 22
 
177 giacomo 23
PID refresh_PID;
24
HARD_TASK_MODEL ht_refresh;
25
 
173 giacomo 26
static void (*elaborate_frame_hook)(void * ptrframe);
27
 
28
void dummy_elaborate_frame(void * ptrframe)
29
{
30
}
31
 
170 giacomo 32
TASK FG_refresh(void)
33
{
34
 
231 giacomo 35
  int err;
36
 
170 giacomo 37
  while(1) {
38
 
39
    if (vmm.frame == 0) {
40
            vmm.frame = 1;
41
            fbuf_pointer = btv.fbuffer;
177 giacomo 42
            *(BYTE *)fbuf_pointer = 255;
43
            *(BYTE *)(fbuf_pointer+1) = 0;
170 giacomo 44
    } else {
45
            vmm.frame = 0;
46
            fbuf_pointer = btv.fbuffer+gbufsize;
177 giacomo 47
            *(BYTE *)fbuf_pointer = 0;
48
            *(BYTE *)(fbuf_pointer+1) = 255;
170 giacomo 49
    }
50
 
231 giacomo 51
    err = bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
52
    if (err) kern_printf("(BTTV_IOCTL Error: %d)",err);
53
 
173 giacomo 54
    elaborate_frame_hook(fbuf_pointer);
55
 
170 giacomo 56
    task_endcycle();
57
 
58
  }
59
 
60
}
61
 
182 giacomo 62
int FG_init(unsigned int period, unsigned int wcet, unsigned int width,
63
                unsigned int height, unsigned int color, unsigned int channel) {
170 giacomo 64
 
231 giacomo 65
  int err;
66
 
170 giacomo 67
  struct video_window vw;
68
  struct video_picture p;
69
  struct video_channel ch;
70
 
71
  hard_task_default_model(ht_refresh);
72
  hard_task_def_wcet(ht_refresh, wcet);
73
  hard_task_def_mit(ht_refresh, period);
74
  hard_task_def_ctrl_jet(ht_refresh);
75
 
76
  refresh_PID = task_create("FG_refresh", FG_refresh, &ht_refresh, NULL);
77
  if (refresh_PID == -1) {
78
    sys_end();
79
  }
179 giacomo 80
 
170 giacomo 81
  bttv_start(&btv);
231 giacomo 82
 
83
  err = bttv_ioctl(&btv, VIDIOCGWIN, &vw);
84
  if (err) kern_printf("(BTTV_IOCTL Error: %d)",err);
170 giacomo 85
  vw.x = 0;
86
  vw.y = 0;
87
  vw.width = width;
88
  vw.height = height;
231 giacomo 89
  err = bttv_ioctl(&btv, VIDIOCSWIN, &vw);
90
  if (err) kern_printf("(BTTV_IOCTL Error: %d)",err);
170 giacomo 91
 
231 giacomo 92
  err = bttv_ioctl(&btv, VIDIOCGPICT, &p);
93
  if (err) kern_printf("(BTTV_IOCTL Error: %d)",err);
177 giacomo 94
  if (color == FG_RGB24) {
95
    p.palette = VIDEO_PALETTE_RGB24;
96
    p.depth = 24;
97
  }
98
  if (color == FG_MONO) {
99
    p.palette = VIDEO_PALETTE_GREY;
100
    p.depth = 8;
101
  }    
231 giacomo 102
  err = bttv_ioctl(&btv, VIDIOCSPICT, &p);
103
  if (err) kern_printf("(BTTV_IOCTL Error: %d)",err);
170 giacomo 104
 
231 giacomo 105
  err = bttv_ioctl(&btv, VIDIOCGCHAN, &ch);
106
  if (err) kern_printf("(BTTV_IOCTL Error: %d)",err);
182 giacomo 107
  ch.channel = channel;
170 giacomo 108
  ch.norm = 3;
231 giacomo 109
  err = bttv_ioctl(&btv, VIDIOCSCHAN, &ch);
110
  if (err) kern_printf("(BTTV_IOCTL Error: %d)",err);
170 giacomo 111
 
112
  vmm.frame = 0;
113
  vmm.height = vw.height;
114
  vmm.width = vw.width;
115
  vmm.format = p.palette;
231 giacomo 116
  err = bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
117
  if (err) kern_printf("(BTTV_IOCTL Error: %d)",err);
173 giacomo 118
 
119
  elaborate_frame_hook = dummy_elaborate_frame;
170 giacomo 120
 
173 giacomo 121
  sleep(1);
122
 
170 giacomo 123
  return 0;
124
 
125
}
126
 
177 giacomo 127
void FG_start_grabbing(void)
128
{
129
 
130
  task_activate(refresh_PID);
179 giacomo 131
 
177 giacomo 132
}
133
 
178 giacomo 134
void FG_close(void)
177 giacomo 135
{
188 giacomo 136
 
137
  task_kill(refresh_PID);  
170 giacomo 138
  bttv_close(&btv);
186 giacomo 139
 
170 giacomo 140
}
141
 
142
void * FG_getbuffer(void)
143
{
144
 
145
  return fbuf_pointer;
146
 
147
}
148
 
173 giacomo 149
void FG_set_hook(void * funptr)
150
{
151
 
152
  elaborate_frame_hook = (void *)funptr;
153
 
154
}