-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_generator.c
222 lines (199 loc) · 6.78 KB
/
video_generator.c
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//----------------------------------------------------------------
// _____
// / \
// /____ \____
// / \===\ \==/
// /___\===\___\/ AVNET
// \======/
// \====/
//---------------------------------------------------------------
//
// This design is the property of Avnet. Publication of this
// design is not authorized without written consent from Avnet.
//
// Please direct any questions to: technical.support@avnet.com
//
// Disclaimer:
// Avnet, Inc. makes no warranty for the use of this code or design.
// This code is provided "As Is". Avnet, Inc assumes no responsibility for
// any errors, which may appear in this code, nor does it make a commitment
// to update the information contained herein. Avnet, Inc specifically
// disclaims any implied warranties of fitness for a particular purpose.
// Copyright(c) 2011 Avnet, Inc.
// All rights reserved.
//
//----------------------------------------------------------------
//
// Create Date: Dec 09, 2011
// Design Name: Video Generator
// Module Name: video_generator.c
// Project Name: FMC-IMAGEON
// Target Devices: Zynq-7000 SoC
// Avnet Boards: FMC-IMAGEON
//
// Tool versions: ISE 14.3
//
// Description: Video Timing Generator using:
// - Xilinx Video Timing Controller (VTC)
//
// Dependencies:
//
// Revision: Dec 09, 2011: 1.00 Initial version
// Nov 02, 2012: 1.01 Add call to XVtc_RegUpdate()
//
//----------------------------------------------------------------
#include "video_generator.h"
#include "video_resolution.h"
/*****************************************************************************/
/**
*
* vgen_init
* - initializes the VTC generator
*
* @param VtcDeviceID is the device ID of the Video Timing Controller core.
* pVtc is a pointer to a VTC instance
*
* @return 0 if all tests pass, 1 otherwise.
*
* @note None.
*
******************************************************************************/
int vgen_init(XVtc *pVtc, u16 VtcDeviceID)
{
XVtc_Config *VtcCfgPtr;
int Status;
/* Look for the device configuration info for the Video Timing
* Controller.
*/
VtcCfgPtr = XVtc_LookupConfig( VtcDeviceID );
if (VtcCfgPtr == NULL) {
return 1;
}
/* Initialize the Video Timing Controller instance */
Status = XVtc_CfgInitialize(pVtc, VtcCfgPtr,
VtcCfgPtr->BaseAddress);
if (Status != XST_SUCCESS) {
return 1;
}
return 0;
}
/*****************************************************************************/
/**
*
* vgen_config
* - configures the generator to generate missing syncs
*
* @param pVtc is a pointer to an initialized VTC instance
* ResolutionId identified a video resolution
* vVerbose = 0 no verbose, 1 minimal verbose, 2 most verbose
*
* @return 0 if all tests pass, 1 otherwise.
*
* @note None.
*
******************************************************************************/
int vgen_config(XVtc *pVtc, int ResolutionId, int bVerbose)
{
vres_timing_t VideoTiming;
int HFrontPorch;
int HSyncWidth;
int HSyncPol;
int HBackPorch;
int VFrontPorch;
int VSyncWidth;
int VSyncPol;
int VBackPorch;
int LineWidth;
int FrameHeight;
XVtc_Signal Signal; /* VTC Signal configuration */
XVtc_Polarity Polarity; /* Polarity configuration */
XVtc_SourceSelect SourceSelect; /* Source Selection configuration */
/* Get Video Resolution timing */
if ( bVerbose )
{
xil_printf( "\tVideo Resolution = %s\n\r", vres_get_name(ResolutionId) );
}
vres_get_timing(ResolutionId, &VideoTiming);
HFrontPorch = VideoTiming.HFrontPorch;
HSyncWidth = VideoTiming.HSyncWidth;
HSyncPol = VideoTiming.HSyncPolarity;
HBackPorch = VideoTiming.HBackPorch;
VFrontPorch = VideoTiming.VFrontPorch;
VSyncWidth = VideoTiming.VSyncWidth;
VSyncPol = VideoTiming.VSyncPolarity;
VBackPorch = VideoTiming.VBackPorch;
LineWidth = VideoTiming.HActiveVideo;
FrameHeight = VideoTiming.VActiveVideo;
/* Disable/Reset VTC */
XVtc_Disable(pVtc, XVTC_EN_GENERATOR);
XVtc_Reset(pVtc);
/* Set up Polarity of all outputs */
memset((void *)&Polarity, 0, sizeof(Polarity));
Polarity.ActiveChromaPol = 1;
Polarity.ActiveVideoPol = 1;
Polarity.FieldIdPol = 0;
Polarity.VBlankPol = 1;
Polarity.VSyncPol = VSyncPol;
Polarity.HBlankPol = 1;
Polarity.HSyncPol = HSyncPol;
/* Set up Generator */
memset((void *)&Signal, 0, sizeof(XVtc_Signal));
Signal.OriginMode = 1; //Set Frame Origin to Start of Active Video
Signal.HTotal = HFrontPorch + HSyncWidth + HBackPorch + LineWidth;
Signal.HActiveStart = 0;
Signal.HFrontPorchStart = LineWidth;
Signal.HSyncStart = LineWidth + HFrontPorch;
Signal.HBackPorchStart = LineWidth + HFrontPorch + HSyncWidth;
Signal.V0Total = FrameHeight + VFrontPorch + VSyncWidth + VBackPorch;
Signal.V0ChromaStart = 0;
Signal.V0ActiveStart = 0;
Signal.V0FrontPorchStart = FrameHeight;
Signal.V0SyncStart = FrameHeight + VFrontPorch;
Signal.V0BackPorchStart = FrameHeight + VFrontPorch + VSyncWidth;
/* Set up source select */
memset((void *)&SourceSelect, 0, sizeof(SourceSelect));
SourceSelect.VBlankPolSrc = 1;
SourceSelect.VSyncPolSrc = 1;
SourceSelect.HBlankPolSrc = 1;
SourceSelect.HSyncPolSrc = 1;
SourceSelect.ActiveVideoPolSrc = 1;
SourceSelect.ActiveChromaPolSrc= 1;
SourceSelect.VChromaSrc = 1;
SourceSelect.VActiveSrc = 1;
SourceSelect.VBackPorchSrc = 1;
SourceSelect.VSyncSrc = 1;
SourceSelect.VFrontPorchSrc = 1;
SourceSelect.VTotalSrc = 1;
SourceSelect.HActiveSrc = 1;
SourceSelect.HBackPorchSrc = 1;
SourceSelect.HSyncSrc = 1;
SourceSelect.HFrontPorchSrc = 1;
SourceSelect.HTotalSrc = 1;
if ( bVerbose == 2 )
{
xil_printf("\tVTC Generator Configuration\n\r" );
xil_printf("\t\tHorizontal Timing:\n\r" );
xil_printf("\t\t\tHActiveStart = %d\r\n", Signal.HActiveStart);
xil_printf("\t\t\tHFrontPorchStart %d\r\n", Signal.HFrontPorchStart);
xil_printf("\t\t\tHSyncStart %d\r\n", Signal.HSyncStart);
xil_printf("\t\t\tHBackPorchStart %d\r\n", Signal.HBackPorchStart);
xil_printf("\t\t\tHTotal = %d\r\n", Signal.HTotal);
xil_printf("\t\tVertical Timing:\n\r" );
xil_printf("\t\t\tV0ActiveStart %d\r\n", Signal.V0ActiveStart);
xil_printf("\t\t\tV0FrontPorchStart %d\r\n", Signal.V0FrontPorchStart);
xil_printf("\t\t\tV0SyncStart %d\r\n", Signal.V0SyncStart);
xil_printf("\t\t\tV0BackPorchStart %d\r\n", Signal.V0BackPorchStart);
xil_printf("\t\t\tV0Total %d\r\n", Signal.V0Total);
}
/* Write configuration to hardware */
XVtc_SetPolarity(pVtc, &Polarity);
XVtc_SetGenerator(pVtc, &Signal);
XVtc_SetSource(pVtc, &SourceSelect);
/* Enable the generator module */
XVtc_DisableSync(pVtc);
//XVtc_SetFSync(pVtc, 0, Signal.V0SyncStart, 1);
XVtc_Enable(pVtc, XVTC_EN_GENERATOR);
XVtc_RegUpdate(pVtc);
/* Return success */
return 0;
}