📄 vportcap.c
字号:
/********************************************************************/
/* 深圳市奇想达科技有限公司QXD-DM642开发板四路视频 */
/* 实时分屏显示源程序, */
/* http://www.szqxd.com */
/********************************************************************/
/*以下的程序是用DMA方式采集图的的设置、中断、以及数据传输的函数*/
/**********************************************************/
/* Capture parameter definitions based on 525/60 format */
/**********************************************************/
/*NTSC*/
//#define VCA_HBLNK_SIZE 138 /* (858-720),horizontal blanking */
//#define VCA_IMG_VSIZE1 244 /* (263-20+1), fld1 vertical image size */
//#define VCA_IMG_VSIZE2 243 /* (525-283+1), fld2 vertical image size */
/*PAL*/
#define VCA_HBLNK_SIZE 144 /* (864-720),horizontal blanking */
/*确定第一场图像的重直像素为288*/
#define VCA_IMG_VSIZE1 288 /* (311-24+1), fld1 vertical image size */
/*确定第一场图像的重直像素为288*/
#define VCA_IMG_VSIZE2 288 /* (625-338+1), fld2 vertical image size */
/*确定第一场图像的水平像素为720*/
#define VCA_IMG_HSIZE1 720 /* field1 horizontal image size */
/*确定第二场图像的水平像素为720*/
#define VCA_IMG_HSIZE2 720 /* field2 horizontal image size */
/* 确定一场像素的大小为720×288 */
#define VCA_IMAGE_SIZE1 (VCA_IMG_HSIZE1 * VCA_IMG_VSIZE1)
/* 确定二场像素的大小为720×288 */
#define VCA_IMAGE_SIZE2 (VCA_IMG_HSIZE2 * VCA_IMG_VSIZE2)
/* Define threshold values in double.words. Both fields should have same threshold value*/
/* 确定FIFO的事件的门槛,为一行的长度,因为DM642为64位DMA,所以长度/8 */
#define VCA_VDTHRLD1 (VCA_IMG_HSIZE1/8) /* line length in */
#define VCA_VDTHRLD2 VCA_VDTHRLD1 /* double.words */
/*PAL2*/
#define VCB_HBLNK_SIZE 144 /* (864-720),horizontal blanking */
/*确定第一场图像的重直像素为288*/
#define VCB_IMG_VSIZE1 288 /* (311-24+1), fld1 vertical image size */
/*确定第一场图像的重直像素为288*/
#define VCB_IMG_VSIZE2 288 /* (625-338+1), fld2 vertical image size */
/*确定第一场图像的水平像素为720*/
#define VCB_IMG_HSIZE1 720 /* field1 horizontal image size */
/*确定第二场图像的水平像素为720*/
#define VCB_IMG_HSIZE2 720 /* field2 horizontal image size */
/* 确定一场像素的大小为720×288 */
#define VCB_IMAGE_SIZE1 (VCB_IMG_HSIZE1 * VCB_IMG_VSIZE1)
/* 确定二场像素的大小为720×288 */
#define VCB_IMAGE_SIZE2 (VCB_IMG_HSIZE2 * VCB_IMG_VSIZE2)
/* Define threshold values in double.words. Both fields should have same threshold value*/
/* 确定FIFO的事件的门槛,为一行的长度,因为DM642为64位DMA,所以长度/8 */
#define VCB_VDTHRLD1 (VCB_IMG_HSIZE1/8) /* line length in */
#define VCB_VDTHRLD2 VCB_VDTHRLD1 /* double.words */
/* ....................................................... */
/* Define channel A capture window co-ordinates for Field1 */
/* ....................................................... */
/*设置图像的采集框channala*/
/* HRST = 0, start of horizontal blanking,HCOUNT在EAV后复位
即一行是从EAV之后开始 ,那行消隐在前,图像在后*/
#define VCA_XSTART1 (VCA_HBLNK_SIZE-2)/*EAV*/
#define VCA_XSTOP1 (VCA_XSTART1 + VCA_IMG_HSIZE1-1)
/* VRST = 1, end of vertical blanking */
#define VCA_YSTART1 1
#define VCA_YSTOP1 (VCA_YSTART1 + VCA_IMG_VSIZE1-1)
/*设置图像的采集框channalb for Field1*/
/* HRST = 0, start of horizontal blanking,HCOUNT在EAV后复位
即一行是从EAV之后开始 ,那行消隐在前,图像在后*/
#define VCB_XSTART1 (VCB_HBLNK_SIZE-2)/*EAV*/
#define VCB_XSTOP1 (VCB_XSTART1 + VCB_IMG_HSIZE1-1)
/* VRST = 1, end of vertical blanking */
#define VCB_YSTART1 1
#define VCB_YSTOP1 (VCB_YSTART1 + VCB_IMG_VSIZE1-1)
/* ....................................................... */
/* Define channel A capture window co-ordinates for Field2 */
/* ....................................................... */
/* HRST = 0, start of horizontal blanking */
#define VCA_XSTART2 (VCA_HBLNK_SIZE-2/*EAV*/)
#define VCA_XSTOP2 (VCA_XSTART2 + VCA_IMG_HSIZE2-1)
/* VRST = 1, end of vertical blanking */
#define VCA_YSTART2 1
#define VCA_YSTOP2 (VCA_YSTART2 + VCA_IMG_VSIZE2-1)
/* HRST = 0, start of horizontal blanking (channalb)*/
#define VCB_XSTART2 (VCB_HBLNK_SIZE-2/*EAV*/)
#define VCB_XSTOP2 (VCB_XSTART2 + VCB_IMG_HSIZE2-1)
/* VRST = 1, end of vertical blanking */
#define VCB_YSTART2 1
#define VCB_YSTOP2 (VCB_YSTART2 + VCB_IMG_VSIZE2-1)
/* Define threshold values in double-words. Both fields should same threshold value */
/* 确定FIFO触发的长度*/
#define VCA_THRLD_FIELD1 (VCA_IMG_HSIZE1/8) /* line length in */
#define VCA_THRLD_FIELD2 VCA_THRLD_FIELD1 /* double-words */
/* Define number of events to be generated for field1 and field2
定义奇场(244)与偶场的行数(243)*/
#define VCA_CAPEVT1 (VCA_IMAGE_SIZE1 / (VCA_VDTHRLD1 * 8))
#define VCA_CAPEVT2 (VCA_IMAGE_SIZE2 / (VCA_VDTHRLD2 * 8))
/* in this example 定义采1帧 */
#define CAPCHA_FRAME_COUNT 1
//'channalb'
/* Define threshold values in double-words. Both fields should same threshold value */
/* 确定FIFO触发的长度*/
#define VCB_THRLD_FIELD1 (VCB_IMG_HSIZE1/8) /* line length in */
#define VCB_THRLD_FIELD2 VCB_THRLD_FIELD1 /* double-words */
/* Define number of events to be generated for field1 and field2
定义奇场(244)与偶场的行数(243)*/
#define VCB_CAPEVT1 (VCB_IMAGE_SIZE1 / (VCB_VDTHRLD1 * 8))
#define VCB_CAPEVT2 (VCB_IMAGE_SIZE2 / (VCB_VDTHRLD2 * 8))
/* in this example 定义采1帧 */
#define CAPCHA_FRAME_COUNT 1
/* ............................................ */
/* EDMA parameters for capture Y event that are */
/* specific to this example. */
/* ............................................ */
/* because VCA_THRLD_FIELDn is in double-words and element size is 32-bit */
#define VCA_Y_EDMA_ELECNT (VCA_THRLD_FIELD1 * 2)
#define VCA_Y_EDMA_FRMCNT ((VCA_CAPEVT1 + VCA_CAPEVT2) * CAPCHA_FRAME_COUNT)
#define VCA_Y_EDMA_ELECNT2 (VCA_THRLD_FIELD1 * 2)
#define VCA_Y_EDMA_FRMCNT2 ((VCA_CAPEVT1 + VCA_CAPEVT2) * CAPCHA_FRAME_COUNT)
/* ............................................'channalb' */
/* EDMA parameters for capture Y event that are */
/* specific to this example. */
/* ............................................ */
/* because VCB_THRLD_FIELDn is in double-words and element size is 32-bit */
#define VCB_Y_EDMA_ELECNT (VCB_THRLD_FIELD1 * 2)
#define VCB_Y_EDMA_FRMCNT ((VCB_CAPEVT1 + VCB_CAPEVT2) * CAPCHA_FRAME_COUNT)
#define VCB_Y_EDMA_ELECNT2 (VCB_THRLD_FIELD1 * 2)
#define VCB_Y_EDMA_FRMCNT2 ((VCB_CAPEVT1 + VCB_CAPEVT2) * CAPCHA_FRAME_COUNT)
/******************************************************************/
/* Description : 8.bit BT.656 non.continuous frame capture */
/* */
/* Some important field descriptions: */
/* */
/* CMODE = 000, 8.bit BT.656 mode */
/* CON = 0 */
/* FRAME = 1, capture frame */
/* CF2 = 0 */
/* CF1 = 0, (8-bit non.continuous frame capture) */
/* SCALE = 0, no scaling */
/* RESMPL= 0, no resampling */
/* 10BPK = X, not used in 8-bit capture */
/* EXC = 0, use EAV/SAV codes */
/* VRST = 1, end of vertical blanking */
/* HRST = 0, start of horizontal blanking */
/* FLDD = 0, 1st line EAV or FID input */
/* FINV = 0, no field invert */
/* RDFE = X, used in Raw mode only(Enable field identification) */
/* SSE = X, used in Raw mode only(Startup synch enable) */
/******************************************************************/
#include <vportcap.h>
/*................................................................ */
/* global variable declarations */
/* ............................................................... */
#pragma DATA_SECTION(capChaAYSpacec, ".capChaAYSpacec")
/* buffer to store captured Y-data */
Uint8 capChaAYSpacec[720*588];
#pragma DATA_SECTION(capChaACbSpacec, ".capChaACbSpacec")
/* buffer to store captured Cb-data */
Uint8 capChaACbSpacec[360*588];
#pragma DATA_SECTION(capChaACrSpacec, ".capChaACrSpacec")
/* buffer to store captured Cr-data */
Uint8 capChaACrSpacec[360*588];
#pragma DATA_SECTION(capChaAYSpaced, ".capChaAYSpaced")
/* buffer to store captured Y-data */
Uint8 capChaAYSpaced[720*588];
#pragma DATA_SECTION(capChaACbSpaced, ".capChaACbSpaced")
/* buffer to store captured Cb-data */
Uint8 capChaACbSpaced[360*588];
#pragma DATA_SECTION(capChaACrSpaced, ".capChaACrSpaced")
/* buffer to store captured Cr-data */
Uint8 capChaACrSpaced[360*588];
/* handle of vp that to be configured */
VP_Handle vpCaptureHandle,vpCaptureHandle2;
/*设置Y、Cb、Cr的EDMA通路的句柄*/
EDMA_Handle hEdmaVPCapChaAY;
EDMA_Handle hEdmaVPCapChaACb;
EDMA_Handle hEdmaVPCapChaACr;
EDMA_Handle hEdmaVPCapChaAYb;
EDMA_Handle hEdmaVPCapChaACbb;
EDMA_Handle hEdmaVPCapChaACrb;
EDMA_Handle hEdmaVPCapChaA2Y;
EDMA_Handle hEdmaVPCapChaA2Cb;
EDMA_Handle hEdmaVPCapChaA2Cr;
EDMA_Handle hEdmaVPCapChaA2Yb;
EDMA_Handle hEdmaVPCapChaA2Cbb;
EDMA_Handle hEdmaVPCapChaA2Crb;
/* EDMA tcc for Y channel */
Int32 edmaCapChaAYTccNum = 0;
/* EDMA tcc for Cb channel */
Int32 edmaCapChaACbTccNum = 0;
/* EDMA tcc for Cb channel */
Int32 edmaCapChaACrTccNum = 0;
Int32 edmaCapChaAYTccNum2 = 0;
/* EDMA tcc for Cb channel */
Int32 edmaCapChaACbTccNum2 = 0;
/* EDMA tcc for Cb channel */
Int32 edmaCapChaACrTccNum2 = 0;
/* no of frames captured */
volatile Uint32 capChaAFrameCount = 0;
/* Error flags */
volatile Uint32 capChaAOverrun = 0;
volatile Uint32 capChaASyncError = 0;
volatile Uint32 capChaAShortFieldDetect = 0;
volatile Uint32 capChaALongFieldDetect = 0;
volatile Uint32 capNewFrame = 0;
//volatile Uint32 capNewFrameb = 0;
// volatile Uint32 displayFrameCount = 0; /* no of frames that are */
VP_Handle bt656_8bit_ncfc2( int portNumber)
{
/* Open video port for capture ,打开一个视频端口*/
vpCaptureHandle2 = VP_open(portNumber, VP_OPEN_RESET);
if(vpCaptureHandle2 == INV)
{
return (VP_Handle)0xffff;
}
/*将VP设置为双通路*/
VP_FSETH(vpCaptureHandle2,VPCTL,DCHNL,VP_VPCTL_DCHNL_OF(1));
/* Enable video port functionality in VP Peripheral Control Reg(PCR),使能视频端口*/
VP_FSETH(vpCaptureHandle2, PCR, PEREN, VP_PCR_PEREN_ENABLE);
/* ..................... */
/* Enable all interrupts */
/* ..................... */
/*便能VCA的中断源*/
/* Enable capture overrun interrupt(COVRA) for VP channel A */
VP_FSETH(vpCaptureHandle2, VPIE, COVRA, VP_VPIE_COVRA_ENABLE);
VP_FSETH(vpCaptureHandle2, VPIE, COVRB, VP_VPIE_COVRB_ENABLE);
/* Enable capture complete interrupt(CCMPA) for VP channel A */
VP_FSETH(vpCaptureHandle2, VPIE, CCMPA, VP_VPIE_CCMPA_ENABLE);
VP_FSETH(vpCaptureHandle2, VPIE, CCMPB, VP_VPIE_CCMPB_ENABLE);
/* Enable channel synchronization error interrupt(SERRA) for */
/* VP channel A */
VP_FSETH(vpCaptureHandle2, VPIE, SERRA, VP_VPIE_SERRA_ENABLE);
VP_FSETH(vpCaptureHandle2, VPIE, SERRB, VP_VPIE_SERRB_ENABLE);
/* Enable short field detect interrupt(SFDA) for VP channel A */
VP_FSETH(vpCaptureHandle2, VPIE, SFDA, VP_VPIE_SFDA_ENABLE);
VP_FSETH(vpCaptureHandle2, VPIE, SFDB, VP_VPIE_SFDB_ENABLE);
// Enable video port global interrupt enable
VP_FSETH(vpCaptureHandle2, VPIE, VIE, VP_VPIE_VIE_ENABLE);
VP_FSETH(vpCaptureHandle2, VCACTL, SFDE, VP_VCACTL_SFDE_ENABLE);
VP_FSETH(vpCaptureHandle2, VCBCTL, SFDE, VP_VCBCTL_SFDE_ENABLE);
VP_RSETH(vpCaptureHandle2, VCASTOP1,VP_VCASTOP1_RMK(VCA_YSTOP1, VCA_XSTOP1));
VP_RSETH(vpCaptureHandle2, VCBSTOP1,VP_VCASTOP1_RMK(VCB_YSTOP1, VCB_XSTOP1));
VP_RSETH(vpCaptureHandle2, VCASTOP2,VP_VCASTOP2_RMK(VCA_YSTOP2, VCA_XSTOP2));
VP_RSETH(vpCaptureHandle2, VCBSTOP2,VP_VCBSTOP2_RMK(VCB_YSTOP2, VCB_XSTOP2));
VP_RSETH(vpCaptureHandle2, VCASTRT1, VP_VCASTRT1_RMK(VCA_YSTART1,VP_VCASTRT1_SSE_ENABLE, VCA_XSTART1));
VP_RSETH(vpCaptureHandle2, VCBSTRT1, VP_VCBSTRT1_RMK(VCB_YSTART1,VP_VCBSTRT1_SSE_ENABLE, VCB_XSTART1));
/* Set first pixel to be captured in Field2 (VCA_STRT2 reg) */
//设置第二场的第一个像素的Y轴与X轴的坐标
VP_RSETH(vpCaptureHandle2, VCASTRT2,VP_VCASTRT2_RMK(VCA_YSTART2, VCA_XSTART2));
VP_RSETH(vpCaptureHandle2, VCBSTRT2,VP_VCBSTRT2_RMK(VCB_YSTART2, VCB_XSTART2));
// Set threshold values ,设置EDMA启动的门限
VP_RSETH(vpCaptureHandle2, VCATHRLD,VP_VCATHRLD_RMK(VCA_THRLD_FIELD2, VCA_THRLD_FIELD1));
VP_RSETH(vpCaptureHandle2, VCBTHRLD,VP_VCBTHRLD_RMK(VCB_THRLD_FIELD2, VCB_THRLD_FIELD1));
// Set capture event.register values,设置一场的需要的EDMA的次数
VP_RSETH(vpCaptureHandle2, VCAEVTCT,VP_VCAEVTCT_RMK(VCA_CAPEVT2,VCA_CAPEVT1));
VP_RSETH(vpCaptureHandle2, VCBEVTCT,VP_VCBEVTCT_RMK(VCB_CAPEVT2,VCB_CAPEVT1));
// Vertical interrupts (VCA_INT) are not enabled in this example.
//Set CMODE to 8.bit BT.656,采用BT656格式的数据流
VP_FSETH(vpCaptureHandle2, VCACTL, CMODE, VP_VCACTL_CMODE_BT656B);
VP_FSETH(vpCaptureHandle2, VCBCTL, CMODE, VP_VCBCTL_CMODE_BT656B);
//Set non.continuous frame capture,设置为电视显示格式的采集,即不连续的采集,
// CON/FRAME/CF2/CF1的值为0100
VP_FSETH(vpCaptureHandle2, VCACTL, CON, VP_VCACTL_CON_DISABLE);
VP_FSETH(vpCaptureHandle2, VCACTL, FRAME, VP_VCACTL_FRAME_FRMCAP);
VP_FSETH(vpCaptureHandle2, VCACTL, CF2, VP_VCACTL_CF2_NONE);
VP_FSETH(vpCaptureHandle2, VCACTL, CF1, VP_VCACTL_CF1_NONE);
VP_FSETH(vpCaptureHandle2, VCBCTL, CON, VP_VCBCTL_CON_DISABLE);
VP_FSETH(vpCaptureHandle2, VCBCTL, FRAME, VP_VCBCTL_FRAME_FRMCAP);
VP_FSETH(vpCaptureHandle2, VCBCTL, CF2, VP_VCBCTL_CF2_NONE);
VP_FSETH(vpCaptureHandle2, VCBCTL, CF1, VP_VCBCTL_CF1_NONE);
//Let FLDD and FINV to be their defaults
// Set VRST to end of vertical blanking,VCOUNT复位在场消隐之后
VP_FSETH(vpCaptureHandle2, VCACTL, VRST, VP_VCACTL_VRST_V0EAV);
VP_FSETH(vpCaptureHandle2, VCBCTL, VRST, VP_VCBCTL_VRST_V0EAV);
// Set HRST to start of horizontal blanking,行计数复位在EAV之后
VP_FSETH(vpCaptureHandle2, VCACTL, HRST, VP_VCACTL_HRST_OF(0));
VP_FSETH(vpCaptureHandle2, VCBCTL, HRST, VP_VCBCTL_HRST_OF(0));
//初始化EDMA通路
// IRQ_enable(IRQ_EVT_VINT1);
/* Enable video port interrupts */
// IRQ_enable(vpCaptureHandle->eventId);
//初始化EDMA通路
IRQ_enable(IRQ_EVT_VINT2);
/* Enable video port interrupts */
IRQ_enable(vpCaptureHandle2->eventId);
//Setup Y, Cb and Cr EDMA channels
setupVPCapChaAEDMA2(portNumber);
// Clear VPHLT in VP_CTL to make video port function,清除VPHLT位
// 使能其它位
VP_FSETH(vpCaptureHandle2, VPCTL, VPHLT, VP_VPCTL_VPHLT_CLEAR);
// set VCEN bit to enable capture,使能VCA口
VP_FSETH(vpCaptureHandle2, VCACTL, VCEN, VP_VCACTL_VCEN_ENABLE);
VP_FSETH(vpCaptureHandle2, VCBCTL, VCEN, VP_VCBCTL_VCEN_ENABLE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -