summaryrefslogtreecommitdiff
path: root/2004/n/fpga/doc/dcd/ovcam/rdcam.c
blob: 85842822f2bac84f14be1f4fcb6e5079b2efa80b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* rdcam.c contient les fonctions qui enregistre l'image
 */

#include "rdcam.h"
#include <sys/ports.h>
#include <sys/sio.h>
#include <sys/interrupts.h>

#define CAM_PCLK BITN(1)
#define CAM_HREF BITN(2)
#define CAM_VSYNC BITN(3)

void
cam_init(void)
{
	// configuration des lignes en entr�e;
	//_io_ports[M6811_DDRA] &= ~0x07 ;
	_io_ports[M6811_DDRG] = 0;
}

unsigned char
test_portcam(unsigned char bit)
{
	if ((_io_ports[M6811_PORTA] & bit) !=0)
		return 1;
	else
		return 0;
}

/* 352*288 = 101376 octect 
 * le 68 hc ne dispose que de 64ko de RAM !!! PB --> on segmente en 4
 * parties :
 * 288 /4 = 72
 * 
 * 352 * 72
 */

void
cam_get(unsigned char * tab, unsigned char part)
{
	unsigned char ligne;
	unsigned char *p;
	// attend que CAM_VSYNC passe � 1
	while (!(_io_ports[M6811_PORTA] & 0x04))
		;
	for (ligne=0;ligne < 72 * part;ligne++)
	{
		// attend que CAM_HREF passe � 1
		while(!(_io_ports[M6811_PORTA] & 0x02))
			;
		// attend que CAM_HREF passe � 0
		while((_io_ports[M6811_PORTA] & 0x02))
			;
	}
	for (ligne=0;ligne<72;ligne++)
	{
		p = tab;
		// attend que CAM_HREF passe � 1
		while(!(_io_ports[M6811_PORTA] & 0x02))
			;
		// tant que CAM_HREF est � 1
		while(_io_ports[M6811_PORTA] & 0x02)
		{
			// si CAM_PCLK passe � 1
			if(_io_ports[M6811_PORTA] & 0x01)
			{
				*p++ = _io_ports[M6811_PORTG];
				// attend que CAM_PCK passe � 0
				while(_io_ports[M6811_PORTA] & 0x01)
					;
			}
		}
		tab += 352;
	}
}

void
cam_count_href_pclk(int *tab)
{
	int i = 0;
	int c;
	// attend que CAM_VSYNC passe � 1
	while (!(_io_ports[M6811_PORTA] & 0x04))
		;
	// attend que CAM_HREF passe � 1
	while(!(_io_ports[M6811_PORTA] & 0x02))
		;
	// attend que CAM_HREF passe � 0
	while(_io_ports[M6811_PORTA] & 0x02)
		;
	// attend que CAM_HREF passe � 1
	while(!(_io_ports[M6811_PORTA] & 0x02))
		;
	for (i = 0; i < 288; i++)
	{
		c = 0;
		// tant que CAM_HREF est � 1
		while(_io_ports[M6811_PORTA] & 0x02)
		{
			// attend que PCLK passe � 1
			while(!(_io_ports[M6811_PORTA] & 0x01))
				;
			// attend que PCLK passe � 0
			while(_io_ports[M6811_PORTA] & 0x01)
				;
			c++;
		}
		*tab++ = c;
	}
}

void
cam_skip_frames(int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		// attend que CAM_VSYNC passe � 1 puis 0
		while (!(_io_ports[M6811_PORTA] & 0x04))
			;
		while ((_io_ports[M6811_PORTA] & 0x04))
			;
	}
}