Subversion Repositories shark

Rev

Rev 170 | Rev 177 | Go to most recent revision | 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>
9
#include <kernel/kern.h>
173 giacomo 10
#include <unistd.h>
170 giacomo 11
 
12
extern void bttv_start(struct bttv *btv);
13
extern int bttv_ioctl(struct bttv *btv, unsigned int cmg, void *arg);
14
extern void bttv_close(struct bttv *btv);
15
 
16
extern unsigned int gbufsize;
17
 
18
static struct bttv btv;
19
static struct video_mmap vmm;
173 giacomo 20
static void * fbuf_pointer;
170 giacomo 21
 
173 giacomo 22
static void (*elaborate_frame_hook)(void * ptrframe);
23
 
24
void dummy_elaborate_frame(void * ptrframe)
25
{
26
}
27
 
170 giacomo 28
TASK FG_refresh(void)
29
{
30
 
31
  while(1) {
32
 
33
    if (vmm.frame == 0) {
34
            vmm.frame = 1;
35
            fbuf_pointer = btv.fbuffer;
36
    } else {
37
            vmm.frame = 0;
38
            fbuf_pointer = btv.fbuffer+gbufsize;
39
    }
40
 
41
    bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
173 giacomo 42
 
43
    elaborate_frame_hook(fbuf_pointer);
44
 
170 giacomo 45
    task_endcycle();
46
 
47
  }
48
 
49
}
50
 
51
int FG_init(unsigned int period, unsigned int wcet, unsigned int width, unsigned int height) {
52
 
53
  HARD_TASK_MODEL ht_refresh;
54
  PID refresh_PID;
55
 
56
  struct video_window vw;
57
  struct video_picture p;
58
  struct video_channel ch;
59
 
60
  hard_task_default_model(ht_refresh);
61
  hard_task_def_wcet(ht_refresh, wcet);
62
  hard_task_def_mit(ht_refresh, period);
63
  hard_task_def_ctrl_jet(ht_refresh);
64
 
65
  refresh_PID = task_create("FG_refresh", FG_refresh, &ht_refresh, NULL);
66
  if (refresh_PID == -1) {
67
    sys_end();
68
  }
69
 
70
  bttv_start(&btv);
71
 
72
  bttv_ioctl(&btv, VIDIOCGWIN, &vw);
73
  vw.x = 0;
74
  vw.y = 0;
75
  vw.width = width;
76
  vw.height = height;
77
  bttv_ioctl(&btv, VIDIOCSWIN, &vw);
78
 
79
  bttv_ioctl(&btv, VIDIOCGPICT, &p);
80
  p.palette = VIDEO_PALETTE_GREY; //GREY mode 8 bpp
81
  p.depth = 8;
82
  bttv_ioctl(&btv, VIDIOCSPICT, &p);
83
 
84
  bttv_ioctl(&btv, VIDIOCGCHAN, &ch);
85
  ch.channel = 0;
86
  ch.norm = 3;
87
  bttv_ioctl(&btv, VIDIOCSCHAN, &ch);
88
 
89
  vmm.frame = 0;
90
  vmm.height = vw.height;
91
  vmm.width = vw.width;
92
  vmm.format = p.palette;
93
  bttv_ioctl(&btv, VIDIOCMCAPTURE, &vmm);
173 giacomo 94
 
95
  elaborate_frame_hook = dummy_elaborate_frame;
170 giacomo 96
 
173 giacomo 97
  sleep(1);
98
 
170 giacomo 99
  task_activate(refresh_PID);
100
 
101
  return 0;
102
 
103
}
104
 
105
void FG_close(void)
106
{
107
 
108
  bttv_close(&btv);
109
 
110
}
111
 
112
void * FG_getbuffer(void)
113
{
114
 
115
  return fbuf_pointer;
116
 
117
}
118
 
173 giacomo 119
void FG_set_hook(void * funptr)
120
{
121
 
122
  elaborate_frame_hook = (void *)funptr;
123
 
124
}