📄 videoinvideoout.c
字号:
/*********************************************************************************
Copyright(c) 2006 Analog Devices, Inc. All Rights Reserved.
This software is proprietary and confidential. By using this software you agree
to the terms of the associated Analog Devices License Agreement.
***********************************************************************
********* MACROS ************************************************************************/
#define USE_LOOPBACK // chained or chained with loopback buffers
//#define PAL_FRAME // Video frame is of PAL format
//#define READ_REG_VALUE // read/print register value enable/disable
/*********************************************************************
Include files
*********************************************************************/
#include <drivers/adi_dev.h> // Device manager includes
#include <drivers/decoder/adi_adv7183.h> // AD7183 device driver includes
#include <drivers/encoder/adi_adv717x.h> // ADV7179 device driver includes
#include <drivers/twi/adi_twi.h> // TWI device driver includes
#include <adi_ssl_Init.h>
#include <SDK-ezkitutilities.h>
#include "stdio.h"
/*********************************************************************
Prototypes
*********************************************************************/
/*****************************************************************************
Static data
*****************************************************************************/
#define NTSC 0
#define PAL 1
#if defined(PAL_FRAME)
#define FRAME_DATA_LEN 864 // Number of pixels(entire field) per line for PAL video format
#define NUM_LINES 625 // Number of lines per frame
#else // its NTSC Frame
#define FRAME_DATA_LEN 858 // Number of pixels(entire field) per line for NYSC video format
#define NUM_LINES 525 // Number of lines per frame
#endif
#define FRAMESIZE FRAME_DATA_LEN * NUM_LINES
/*********************************************************************
memory for buffers and data
*********************************************************************/
// Define the DMA buffers for each frame.
// Because of SDRAM performance, each frame must be in a different bank.
section("vd0_sdram") volatile u16 sFrame0[FRAMESIZE];
section("vd1_sdram") volatile u16 sFrame1[FRAMESIZE];
section("vd2_sdram") volatile u16 sFrame2[FRAMESIZE];
section("vd3_sdram") volatile u16 sFrame3[FRAMESIZE];
// 4 input buffers used by AD7183
ADI_DEV_2D_BUFFER In1_Buffer2D, In2_Buffer2D, In3_Buffer2D, In4_Buffer2D;
// 4 output buffers used by AD7179
ADI_DEV_2D_BUFFER Out1_Buffer2D, Out2_Buffer2D, Out3_Buffer2D, Out4_Buffer2D;
// Pseudo TWI Configuration
// Pseudo TWI will be used to access ADV7183 and ADV7179 registers.
// BF561 Ports (PF0=SCL,PF1=SDA) & Timer(Timer 3) used for Pseudo TWI
adi_twi_pseudo_port TWIPseudo= {ADI_FLAG_PF0,ADI_FLAG_PF1,ADI_TMR_GP_TIMER_3,(ADI_INT_PERIPHERAL_ID)NULL};
ADI_DEV_CMD_VALUE_PAIR PseudoTWIConfig[]={
{ADI_TWI_CMD_SET_PSEUDO,(void *)(&TWIPseudo)},
{ADI_DEV_CMD_SET_DATAFLOW_METHOD,(void *)ADI_DEV_MODE_SEQ_CHAINED},
{ADI_DEV_CMD_SET_DATAFLOW,(void *)TRUE},
{ADI_DEV_CMD_END,NULL}
};
/*********************************************************************
memory for initialization of system services and device manager
*********************************************************************/
/*********************************************************************
handles to device drivers
*********************************************************************/
ADI_DEV_DEVICE_HANDLE AD7183DriverHandle;// handle to the ad7183 driver
ADI_DEV_DEVICE_HANDLE AD7179DriverHandle;// handle to the ad7179 driver
/*********************************************************************
static function prototypes
*********************************************************************/
static void InitSystemServices(void); // system services initialization
static void CallbackFunction( void *AppHandle, u32 Event,void *pArg);// device driver callback function
static void StartADV7179(void); // Configure ADV7179 driver, buffer etc
static void StartADV7183(void); // Configure ADV7183 driver, buffer etc
static void Set7179ToNTSC(void); //Configure AD7179 to NTSC mode
static void Set7179ToPAL(void);//Configure AD7179 to PAL mode
static void Read7179Regs(void);// Read AD7179 register
static void Read7183StatusReg(void); // Read AD7183 Status register
/*********************************************************************
*
* Function: main
* Description: Using the AD7183 and AD7179 device drivers,this
program demonstrates a simple video stream program.
The video data is captured into SDRAM from the AD7183 decoder,
then output through AD7179 encoder.
In this example,no processing is done on the video data.
*********************************************************************/
void main(void)
{
unsigned int i,Result; // index
u32 ResponseCount; // response count
// initialize the system services
InitSystemServices();
ezInitButton(EZ_LAST_BUTTON); // enables the last button
// turn off LED's
ezTurnOffAllLEDs();
StartADV7183();
StartADV7179();
// keep going until the last push button is pressed
while (ezIsButtonPushed(EZ_LAST_BUTTON) == FALSE) ;
// close the device
ezErrorCheck(adi_dev_Close(AD7183DriverHandle));
// close the device
ezErrorCheck(adi_dev_Close(AD7179DriverHandle));
// close the Device Manager
ezErrorCheck(adi_dev_Terminate(adi_dev_ManagerHandle));
// close down the DMA Manager
ezErrorCheck(adi_dma_Terminate(adi_dma_ManagerHandle));
}
/*********************************************************************
Function: InitSystemServices
Description: Initializes the necessary system services.
*********************************************************************/
void InitSystemServices(void) {
// initialize the ezKit power,EBIU,DMA....
adi_ssl_Init();
// enable and configure async memory
ezInit(1);
// return
}
/*********************************************************************
Function: CallbackFunction
Description: Each type of callback event has it's own unique ID
so we can use a single callback function for all
callback events. The switch statement tells us
which event has occurred.
Note that in the device driver model, in order to
generate a callback for buffer completion, the
CallbackParameter of the buffer must be set to a non-NULL
value.
*********************************************************************/
static void CallbackFunction(void *AppHandle,u32 Event,void *pArg)
{
switch (Event)
{
// CASE (buffer processed)
case ADI_DEV_EVENT_BUFFER_PROCESSED:
// IF (it's an outbound buffer that's been sent out from AD7179 encoder)
if (AppHandle == (void *)0x7179) {
#ifndef USE_LOOPBACK // chained buffer
// requeue outbound buffer to ADV7179
adi_dev_Write(AD7179DriverHandle, ADI_DEV_2D, pArg);
#endif
// ELSE (it's an inbound buffer that's been filled by the AD7183 decoder)
} else {
#ifndef USE_LOOPBACK // chained buffer
// requeue inbound buffer to ADV7183
adi_dev_Read(AD7183DriverHandle, ADI_DEV_2D, pArg);
#endif
// ENDIF
}
break;
}
// return
}
/*********************************************************************
Function: StartADV7183
Description: Initialise Video Decoder ADV7183, set up buffers and
configure the decoder
*********************************************************************/
static void StartADV7183(void){
ezEnableVideoDecoder();// enable AD7183
//ezDisableVideoDecoder();// enable AD7183
// open the ad7183 driver
ezErrorCheck(adi_dev_Open(adi_dev_ManagerHandle, // DevMgr handle
&ADIADV7183EntryPoint, // pdd entry point
0, // device instance
(void *)0x7183, // client handle (0x7183 will be given to the AD7183 decoder driver)
&AD7183DriverHandle, // DevMgr handle for this device
ADI_DEV_DIRECTION_INBOUND,// data direction for this device
adi_dma_ManagerHandle, // handle to DmaMgr for this device
NULL, // handle to deferred callback service
CallbackFunction)); // client's callback function
/********* open AD7183-PPI ****************************************/
// open the AD7183-PPI device 0 (see Schematic)
ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_AD7183_CMD_OPEN_PPI, (void *)0));
// command PPI to work in NTSC or PAL mode
#if defined(PAL_FRAME)
ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_AD7183_CMD_SET_VIDEO_FORMAT, (void *)PAL));
#else
ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_AD7183_CMD_SET_VIDEO_FORMAT, (void *)NTSC));
#endif
/******************* AD7183 Inbound Buffers ***********************************************/
// populate the buffers that we'll use for the PPI input
In1_Buffer2D.Data = (void*)sFrame0;
In1_Buffer2D.ElementWidth =sizeof(u32);
In1_Buffer2D.XCount = (FRAME_DATA_LEN/2);
In1_Buffer2D.XModify = 4;
In1_Buffer2D.YCount = NUM_LINES;
In1_Buffer2D.YModify = 4;
In1_Buffer2D.CallbackParameter = NULL;
In1_Buffer2D.pNext = &In2_Buffer2D;
In2_Buffer2D.Data = (void*)sFrame1;
In2_Buffer2D.ElementWidth = sizeof(u32);
In2_Buffer2D.XCount = (FRAME_DATA_LEN/2);
In2_Buffer2D.XModify = 4;
In2_Buffer2D.YCount = NUM_LINES;
In2_Buffer2D.YModify = 4;
#ifdef USE_LOOPBACK
In1_Buffer2D.CallbackParameter = NULL;
In2_Buffer2D.pNext = &In3_Buffer2D;
#else // chained buffer
In2_Buffer2D.CallbackParameter = &In1_Buffer2D;
In2_Buffer2D.pNext = NULL;
#endif
In3_Buffer2D.Data = (void*)sFrame2;
In3_Buffer2D.ElementWidth = sizeof(u32);
In3_Buffer2D.XCount = (FRAME_DATA_LEN/2);
In3_Buffer2D.XModify = 4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -