📄 mt9t001_main.c
字号:
/*
* Copyright 2004 by Texas Instruments Incorporated.
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
*/
/* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */
#include <std.h>
#include <tsk.h>
#include <sem.h>
#include <gio.h>
#include <csl_dat.h>
#include <csl_cache.h>
#include <csl_edma.h>
#include <csl_timer.h>
#include <fvid.h>
#include <edc.h>
#include <vport.h>
#include <vportcap.h>
#include <vportdis.h>
#include <saa7105.h>
#include <saa7115.h>
#include <evmdm642.h>
#include "evmdm642_vcapparams.h"
#include "evmdm642_vdisparams.h"
#include "MT9T001_utils.h"
#include "MT9T001_init.h"
#define ONE_SECOND 0x23C3460
// HWI Function Prototype
void HWI_Timer1(Uint32 funcArg, Uint32 eventId);
/* heap IDs defined in the BIOS configuration file */
extern Int EXTERNALHEAP;
MT9T001_Params params;
/******************************************************/
/* Timer Variables for Frame Counting */
/******************************************************/
TIMER_Config myFrameTimer;
TIMER_Handle hTimer1;
Uint32 TimerEventId;
int frames = 0;
/*
* ======== main ========
*/
main()
{
CSL_init();
CACHE_clean(CACHE_L2ALL, 0, 0);
CACHE_setL2Mode(CACHE_256KCACHE);
CACHE_enableCaching(CACHE_EMIFA_CE00);
CACHE_enableCaching(CACHE_EMIFA_CE01);
/******************************************************/
/* Initialize Timer for Frame Counting */
/******************************************************/
myFrameTimer.ctl = TIMER_CTL_RMK(TIMER_CTL_INVINP_NO,
TIMER_CTL_CLKSRC_OF(1),
TIMER_CTL_CP_CLOCK,
TIMER_CTL_HLD_YES,
TIMER_CTL_GO_NO,
TIMER_CTL_PWID_DEFAULT,
TIMER_CTL_DATOUT_DEFAULT,
TIMER_CTL_INVOUT_DEFAULT,
TIMER_CTL_FUNC_TOUT);
myFrameTimer.cnt = TIMER_CNT_OF(0);
myFrameTimer.prd = TIMER_PRD_OF(ONE_SECOND*10);
hTimer1 = TIMER_open(TIMER_DEV1, TIMER_OPEN_RESET);
TIMER_config(hTimer1, &myFrameTimer);
TimerEventId = TIMER_getEventId(hTimer1);
IRQ_clear(TimerEventId);
IRQ_enable(TimerEventId);
// Start Timer
TIMER_start(hTimer1);
}
/*
* ======== tskVideoLoopback ========
* video loopback function.
*/
void tskVideoLoopback()
{
Int status;
#ifdef MODE_20BIT
// display channel
FVID_Handle disChan;
FVID_Frame *disFrameBuf;
Uint16 *ptrDisRaw;
// capture channel
FVID_Handle capChan;
FVID_Frame *capFrameBuf;
Uint32 *ptrBayerSrc;
#ifdef PIP
// capture channel PIP
FVID_Handle capChanPIP;
FVID_Frame *capFrameBufPIP;
Uint32 *ptrBayerSrcPIP;
#endif
#endif
#ifdef MODE_16BIT
// display channel
FVID_Handle disChan;
FVID_Frame *disFrameBuf;
Uint16 *ptrDisRaw;
// capture channel
FVID_Handle capChan;
FVID_Frame *capFrameBuf;
Uint16 *ptrBayerSrc;
#ifdef PIP
// capture channel PIP
FVID_Handle capChanPIP;
FVID_Frame *capFrameBufPIP;
Uint16 *ptrBayerSrcPIP;
#endif
#endif
#ifdef MODE_10BIT
// display channel
FVID_Handle disChan;
FVID_Frame *disFrameBuf;
Uint16 *ptrDisRaw;
// capture channel
FVID_Handle capChan;
FVID_Frame *capFrameBuf;
Uint16 *ptrBayerSrc;
#ifdef PIP
// capture channel PIP
FVID_Handle capChanPIP;
FVID_Frame *capFrameBufPIP;
Uint16 *ptrBayerSrcPIP;
#endif
#endif
#ifdef MODE_8BIT
// display channel
FVID_Handle disChan;
FVID_Frame *disFrameBuf;
Uint16 *ptrDisRaw;
// capture channel
FVID_Handle capChan;
FVID_Frame *capFrameBuf;
Uint8 *ptrBayerSrc;
#ifdef PIP
// capture channel PIP
FVID_Handle capChanPIP;
FVID_Frame *capFrameBufPIP;
Uint8 *ptrBayerSrcPIP;
#endif
#endif
// Number of lines for display and capture
Int numLinesDis;
Int numLinesCap;
// Line Size for display and capture
Int lineSizeCap;
Int lineSizeDis;
// Background Fill Frame Counter.
int tmpFrameCnt = 0;
#ifdef MODE_640x480_VGA
MT9T001_configCapParams(&EVMDM642_vCapParamsChan, ¶ms, 480, 640, 21, 15, 388);
MT9T001_configColorGain(¶ms, 0x8, 0, 0x8, 0, 0x8, 0, 0x3F, 0, 0xA8);
#endif
#ifdef MODE_320x240
MT9T001_configCapParams(&EVMDM642_vCapParamsChan, ¶ms, 240, 320, 21, 15, 564);
MT9T001_configColorGain(¶ms, 0x8, 0, 0x8, 0, 0x8, 0, 0x3F, 0, 0xA8);
#endif
#ifdef MODE_1280x720_HDTV
MT9T001_configCapParams(&EVMDM642_vCapParamsChan, ¶ms, 720, 1280, 21, 15, 719);
MT9T001_configColorGain(¶ms, 0x8, 0, 0x8, 0, 0x8, 0, 0x2F, 0, 0xA8);
#endif
#ifdef MODE_1920x1080_HDTV
MT9T001_configCapParams(&EVMDM642_vCapParamsChan, ¶ms, 1080, 1920, 21, 15, 1039);
MT9T001_configColorGain(¶ms, 0x8, 0, 0x8, 0, 0x8, 0, 0x10, 0, 0xA8);
#endif
#ifdef MODE_CUSTOM
MT9T001_configCapParams(&EVMDM642_vCapParamsChan, ¶ms, 1200, 1600, 21, 15, 1206);
MT9T001_configColorGain(¶ms, 0x8, 0, 0x8, 0, 0x8, 0, 0xF, 0, 0xA8);
#endif
/******************************************************
Set the Threshold
******************************************************/
#ifdef MODE_8BIT
EVMDM642_vCapParamsChan.thrld = EVMDM642_vCapParamsChan.thrld >> 3;
#endif
#ifdef MODE_10BIT
EVMDM642_vCapParamsChan.thrld = EVMDM642_vCapParamsChan.thrld >> 3;
#endif
#ifdef MODE_16BIT
EVMDM642_vCapParamsChan.thrld = EVMDM642_vCapParamsChan.thrld >> 3;
#endif
#ifdef MODE_20BIT
EVMDM642_vCapParamsChan.thrld = EVMDM642_vCapParamsChan.thrld >> 1;
#endif
// Number of lines for display and capture
numLinesDis = EVMDM642_vDisParamsChan.imgVSizeFld1;
numLinesCap = EVMDM642_vCapParamsChan.fldYStop1;
// Line Size for display and capture
lineSizeCap = EVMDM642_vCapParamsChan.fldXStop1+1;
lineSizeDis = EVMDM642_vDisParamsChan.imgHSizeFld1;
// turn on leds
EVMDM642_rset(EVMDM642_LED, 0x00);
/******************************************************/
/* allocate both capture and display frame buffers */
/* in external heap memory */
/******************************************************/
EVMDM642_vCapParamsChan.segId = EXTERNALHEAP;
EVMDM642_vDisParamsChan.segId = EXTERNALHEAP;
// Set to handle of I2C
EVMDM642_vDisParamsSAA7105.hI2C = EVMDM642_I2C_hI2C;
/******************************************************/
/* initialization of capture driver 1 Channel A */
/* and capture driver 0 Channel A */
/* FVID object must match BIOS Driver Name */
/******************************************************/
capChan = FVID_create("/VP1CAPTURE/A/1", IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan, NULL);
#ifdef PIP
capChanPIP = FVID_create("/VP0CAPTURE/A/0", IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan, NULL);
#endif
/******************************************************/
/* initialization of display driver */
/******************************************************/
disChan = FVID_create("/VP2DISPLAY", IOM_OUTPUT, &status, (Ptr)&EVMDM642_vDisParamsChan, NULL);
/******************************************************/
/* configure video encoder & MT9T001 */
/******************************************************/
FVID_control(capChan, VPORT_CMD_EDC_BASE + EDC_CONFIG, (Ptr)¶ms);
#ifdef PIP
FVID_control(capChanPIP, VPORT_CMD_EDC_BASE + EDC_CONFIG, (Ptr)¶ms);
#endif
FVID_control(disChan, VPORT_CMD_EDC_BASE + EDC_CONFIG, (void *)&EVMDM642_vDisParamsSAA7105);
// Begin snapshot mode and run continuously
FVID_control(capChan, VPORT_CMD_EDC_BASE + EDC_START, NULL);
#ifdef PIP
FVID_control(capChanPIP, VPORT_CMD_EDC_BASE + EDC_START, NULL);
#endif
/******************************************************/
/* start capture & display operation */
/******************************************************/
FVID_control(disChan, VPORT_CMD_START, NULL);
FVID_control(capChan, VPORT_CMD_START, NULL);
#ifdef PIP
FVID_control(capChanPIP, VPORT_CMD_START, NULL);
#endif
/********************************************************/
/* request a frame buffer from display & capture driver */
/********************************************************/
FVID_alloc(disChan, &disFrameBuf);
FVID_alloc(capChan, &capFrameBuf);
#ifdef PIP
FVID_alloc(capChanPIP, &capFrameBufPIP);
#endif
// turn off LEDS
EVMDM642_rset(EVMDM642_LED, 0xFF);
CACHE_clean(CACHE_L2ALL, 0, 0);
while(1)
{/* loop forever */
// Set pointers
#ifdef MODE_8BIT
ptrBayerSrc = (Uint8 *)capFrameBuf->frame.rpFrm.buf;
#ifdef PIP
ptrBayerSrcPIP = (Uint8 *)capFrameBufPIP->frame.rpFrm.buf;
#endif
#endif
#ifdef MODE_10BIT
ptrBayerSrc = (Uint16 *)capFrameBuf->frame.rpFrm.buf;
#ifdef PIP
ptrBayerSrcPIP = (Uint16 *)capFrameBufPIP->frame.rpFrm.buf;
#endif
#endif
#ifdef MODE_16BIT
ptrBayerSrc = (Uint16 *)capFrameBuf->frame.rpFrm.buf;
#ifdef PIP
ptrBayerSrcPIP = (Uint16 *)capFrameBufPIP->frame.rpFrm.buf;
#endif
#endif
#ifdef MODE_20BIT
ptrBayerSrc = (Uint32 *)capFrameBuf->frame.rpFrm.buf;
#ifdef PIP
ptrBayerSrcPIP = (Uint32 *)capFrameBufPIP->frame.rpFrm.buf;
#endif
#endif
ptrDisRaw = (Uint16 *)disFrameBuf->frame.rpFrm.buf;
/***************************************************/
/* copy data from capture buffer to display buffer */
/***************************************************/
// Fill buffers with background color.
if(tmpFrameCnt != EVMDM642_vDisParamsChan.numFrmBufs)
{
fillBackgroundSVGA(numLinesDis, lineSizeDis, ptrDisRaw, 0x00);
tmpFrameCnt++;
}
// Convert Bayer pattern souce data to RGB565 for SVGA out
#ifdef MODE_8BIT
Bayer_2_RGB565(ptrBayerSrc, ptrDisRaw, numLinesCap, lineSizeCap, numLinesDis, lineSizeDis, 1, 1);
#ifdef PIP
Bayer_2_RGB565(ptrBayerSrcPIP, ptrDisRaw, numLinesCap, lineSizeCap, numLinesDis, lineSizeDis, 2, 2);
#endif
#endif
#ifdef MODE_10BIT
Bayer_2_RGB565_10Bit(ptrBayerSrc, ptrDisRaw, numLinesCap, lineSizeCap, numLinesDis, lineSizeDis, 1, 1);
#ifdef PIP
Bayer_2_RGB565_10Bit(ptrBayerSrcPIP, ptrDisRaw, numLinesCap, lineSizeCap, numLinesDis, lineSizeDis, 2, 2);
#endif
#endif
#ifdef MODE_16BIT
Bayer_2_RGB565_10Bit(ptrBayerSrc, ptrDisRaw, numLinesCap, lineSizeCap, numLinesDis, lineSizeDis, 1, 1);
#ifdef PIP
Bayer_2_RGB565_10Bit(ptrBayerSrcPIP, ptrDisRaw, numLinesCap, lineSizeCap, numLinesDis, lineSizeDis, 2, 2);
#endif
#endif
#ifdef MODE_20BIT
Bayer_2_RGB565_20Bit(ptrBayerSrc, ptrDisRaw, numLinesCap, lineSizeCap, numLinesDis, lineSizeDis, 1, 1);
#ifdef PIP
Bayer_2_RGB565_20Bit(ptrBayerSrcPIP, ptrDisRaw, numLinesCap, lineSizeCap, numLinesDis, lineSizeDis, 2, 2);
#endif
#endif
CACHE_clean(CACHE_L2ALL, 0, 0);
FVID_exchange(capChan, &capFrameBuf);
#ifdef PIP
FVID_exchange(capChanPIP, &capFrameBufPIP);
#endif
FVID_exchange(disChan, &disFrameBuf);
frames ++;
}
}
/***************************************************
HWI for counting the number of FPS. Set a breakpoint
here and ANIMATE (don't RUN). Open a watch window
and watch variable 'frames'. It will settle to a
steady state value after about 1 minute. That is
the number of FPS the DSP is operating at.
To find the number of FPS the DSP is capturing, comment
out FVID_exchange(disChan, &disFrameBuf) and repeat the
above procedure.
****************************************************/
void HWI_Timer1(Uint32 funcArg, Uint32 eventId)
{
IRQ_clear(TimerEventId);
frames = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -