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