?? videoinlcdout.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 NTSC_MODE // Video frame is of NTSC format
//#define READ_REG_VALUE // read/print register value enable/disable
#define NEC_LCD
/*********************************************************************
Include files
*********************************************************************/
#include <drivers/adi_dev.h> // Device manager includes
#include <drivers/decoder/adi_adv7183.h> // AD7183 device driver includes
#if defined NEC_LCD
#include <drivers/lcd/nec/adi_nl6448BC33_54.h>
#else
#include <drivers/lcd/sharp/adi_lq10d368.h>
#endif
#include <drivers/twi/adi_twi.h> // TWI device driver includes
//#include <drivers/ppi/adi_ppi.h> // PPI device driver includes
#include <SDK-ezkitutilities.h>
#include "stdio.h"
#include "math.h"
/*********************************************************************
Prototypes
*********************************************************************/
/*****************************************************************************
Static data
*****************************************************************************/
#define NTSC 0
#define PAL 1
// NTSC or PAL Video input
#define ACTIVE_FIELD_DATA_LEN 720 // Active field data length per line for PAL video format
#if defined NTSC_MODE // NTSC mode
#define ACTIVE_FIELD_LINES 507 // Number of lines per active field frame for NTSC format
#else // PAL mode
#define ACTIVE_FIELD_LINES 576 // Number of lines per active field frame for PAL format
#endif
#define ACTIVE_FIELD_FRAME_SIZE (ACTIVE_FIELD_DATA_LEN * ACTIVE_FIELD_LINES)
#define VIDEOHORZLINES ACTIVE_FIELD_DATA_LEN/2
#define CROP_HORIZONTAL_LINES 20
#if defined NTSC_MODE // NTSC mode
#define CROP_VIDEO_LINES 13
#define OFFSET_TO_ODD_FRAME ((ACTIVE_FIELD_LINES+1)/2)
#define IPOFFSET_EVEN (CROP_VIDEO_LINES*VIDEOHORZLINES)+CROP_HORIZONTAL_LINES// VIDEO buffer offset for even frame
#define IPOFFSET_ODD IPOFFSET_EVEN + (OFFSET_TO_ODD_FRAME*VIDEOHORZLINES)// VIDEO buffer offset for odd frame
#else
#define CROP_VIDEO_LINES 24
#define OFFSET_TO_ODD_FRAME 288
#define IPOFFSET_EVEN (CROP_VIDEO_LINES*VIDEOHORZLINES)+CROP_HORIZONTAL_LINES// VIDEO buffer offset for even frame
#define IPOFFSET_ODD IPOFFSET_EVEN + (OFFSET_TO_ODD_FRAME*VIDEOHORZLINES)// VIDEO buffer offset for odd frame
#endif
// VGA LCD output
#define VGA_WIDTH 640
#define VGA_PADLEFT 0
#define VGA_PADRIGHT 0
#define VGA_HEIGHT 480
#define VGA_PADTOP 33
#define VGA_PADBOTTOM 12
#define VGA_FRAME_WIDTH (VGA_WIDTH+VGA_PADLEFT+VGA_PADRIGHT) // 640
#define VGA_FRAME_HEIGHT (VGA_HEIGHT+VGA_PADTOP+VGA_PADBOTTOM) // 525
#define VGA_FRAME_SIZE (VGA_FRAME_WIDTH*VGA_FRAME_HEIGHT) // 640*525
#define LCDHORZLINES VGA_FRAME_WIDTH/2
#define OPOFFSET_EVEN (VGA_PADTOP*LCDHORZLINES)// LCD buffer offset for even frame
#define OPOFFSET_ODD ((VGA_PADTOP+1)*LCDHORZLINES)//LCD buffer offset for odd frame
/*********************************************************************
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[ACTIVE_FIELD_FRAME_SIZE];
section("vd1_sdram") volatile u16 sFrame1[ACTIVE_FIELD_FRAME_SIZE];
section("vd2_sdram") volatile u16 sFrame2[VGA_FRAME_SIZE];
// Storage for YUV to RGB565 conversion
section("L1_data_a") static unsigned long InData[512],OutData[512];
// 2 input buffers used by AD7183
ADI_DEV_2D_BUFFER In1_Buffer2D, In2_Buffer2D;
// 2 output buffers used by LCD
ADI_DEV_2D_BUFFER Out1_Buffer2D, Out2_Buffer2D;
/*********************************************************************
memory for initialization of system services and device manager
*********************************************************************/
// DMA Manager data (base memory + memory for 2 DMA channel (PPI0 and PPI1)
static u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 2)];
static ADI_DMA_MANAGER_HANDLE DMAManagerHandle; // DMAManager handle
// Device Manager data (base memory + memory for 5 devices (2xPPI,TWI,AD7183,LCD))
static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * 5)];
static ADI_DEV_MANAGER_HANDLE DeviceManagerHandle;// DevManager handle
/*********************************************************************
handles to device drivers
*********************************************************************/
ADI_DEV_DEVICE_HANDLE AD7183DriverHandle;// handle to the ad7183 driver
ADI_DEV_DEVICE_HANDLE LcdDriverHandle;// handle to the LCD driver
/*********************************************************************
static function prototypes
*********************************************************************/
// exception handlers
static ADI_INT_HANDLER(ExceptionHandler);
static ADI_INT_HANDLER(HWErrorHandler);
static void InitSystemServices(void); // system services initialization
static void CallbackFunction( void *AppHandle, u32 Event,void *pArg);// device driver callback function
static void InitADV7183_Start(void);
static void InitLcd_Start(void);
void convertFrame(u32 num);
static void convertyuvrgb(unsigned short OutSize, unsigned long *Output, unsigned short InSize, unsigned long *Input);
static void Set7183RangeReg(void);// Set AD7183 Extended Output Control register
static void Read7183StatusReg(void); // Read AD7183 Status register
volatile bool Frame0Flag;
volatile bool Frame1Flag;
/*********************************************************************
Function: main
Description: Read in ITU656 NTSC or PAL video data into SDRAM input buffer.
Convert YUV(4:2:2) to RGB565 format and store into SDRAM output buffer.
Send the output buffer to the VGA LCD.
*********************************************************************/
void main(void)
{
unsigned int i,Result; // index
u32 ResponseCount; // response count
// initialize the system services
InitSystemServices();
// enable LEDs and buttons
for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
ezInitLED(i);
}
ezInitButton(EZ_LAST_BUTTON);
// turn off LED's
ezTurnOffAllLEDs();
// initialize the device manager
ezErrorCheck(adi_dev_Init(DevMgrData, // pointer to data for the device manager to use
sizeof(DevMgrData), // size of the data in bytes
&ResponseCount, // location where the number of devices that can be managed will be stored
&DeviceManagerHandle,// location where the device manager handle will be stored
NULL)); // parameter for adi_int_EnterCriticalRegion() function (always NULL for standalone and VDK)
//reset the processed buffer flag
Frame0Flag = false;
Frame1Flag = false;
// initialize the decoder and start the input data flow
InitADV7183_Start();
// initialize the LCD and start the output data flow
InitLcd_Start();
// loop forever until the last push button is depressed
while (ezIsButtonPushed(EZ_LAST_BUTTON) == FALSE){
// convert processed buffer
if (Frame0Flag){
Frame0Flag = false;
convertFrame(0); // convert even field
}
if (Frame1Flag){
Frame1Flag = false;
convertFrame(1); // convert odd field
}
}
// close the device
ezErrorCheck(adi_dev_Close(AD7183DriverHandle));
// close the device
ezErrorCheck(adi_dev_Close(LcdDriverHandle));
// close the Device Manager
ezErrorCheck(adi_dev_Terminate(DeviceManagerHandle));
// close down the DMA Manager
ezErrorCheck(adi_dma_Terminate(DMAManagerHandle));
}
/*********************************************************************
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.
In the example, we'll get a callback when the PPI
has completed processing of the input buffer.
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)
{
ADI_DEV_2D_BUFFER *p2DBuffer; // pointer to the buffer that was processed
p2DBuffer = (ADI_DEV_2D_BUFFER *)pArg;
switch (Event)
{
// CASE (buffer processed)
case ADI_DEV_EVENT_BUFFER_PROCESSED:
if(p2DBuffer == &In1_Buffer2D){
Frame0Flag = true;
}
else if(p2DBuffer == &In2_Buffer2D){
Frame1Flag = true;
}
break;
// CASE (an error)
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
}
// return
}
/*********************************************************************
Function: InitSystemServices
Description: Initializes the necessary system services.
*********************************************************************/
static void InitSystemServices(void) {
u32 i;
ADI_EBIU_SDRAM_BANK_VALUE bank_size;
ADI_EBIU_SDRAM_BANK_VALUE bank_width;
u32 cl_threshold = 100; // set cl threshold to 100 Mhz
ADI_EBIU_TIMING_VALUE twrmin = {1,{7500, ADI_EBIU_TIMING_UNIT_PICOSEC}}; // set min TWR to 1 SCLK cycle + 7.5ns
ADI_EBIU_TIMING_VALUE refresh = {8192,{64, ADI_EBIU_TIMING_UNIT_MILLISEC}}; // set refresh period to 8192 cycles in 64ms
ADI_EBIU_TIME trasmin = {44, ADI_EBIU_TIMING_UNIT_NANOSEC}; // set min TRAS to 44ns
ADI_EBIU_TIME trpmin = {20, ADI_EBIU_TIMING_UNIT_NANOSEC}; // set min TRP to 20ns
ADI_EBIU_TIME trcdmin = {20, ADI_EBIU_TIMING_UNIT_NANOSEC}; // set min TRCD to 20ns
bank_size.value.size = ADI_EBIU_SDRAM_BANK_64MB; // set bank size to 64MB
bank_width.value.width = ADI_EBIU_SDRAM_BANK_COL_10BIT; // set column address width to 10-Bit
ADI_EBIU_COMMAND_PAIR ezkit_sdram[] = {
{ ADI_EBIU_CMD_SET_SDRAM_BANK_SIZE, (void*)&bank_size },
{ ADI_EBIU_CMD_SET_SDRAM_BANK_COL_WIDTH,(void*)&bank_width },
{ ADI_EBIU_CMD_SET_SDRAM_CL_THRESHOLD, (void*)cl_threshold },
{ ADI_EBIU_CMD_SET_SDRAM_TRASMIN, (void*)&trasmin },
{ ADI_EBIU_CMD_SET_SDRAM_TRPMIN, (void*)&trpmin },
{ ADI_EBIU_CMD_SET_SDRAM_TRCDMIN, (void*)&trcdmin },
{ ADI_EBIU_CMD_SET_SDRAM_TWRMIN, (void*)&twrmin },
{ ADI_EBIU_CMD_SET_SDRAM_REFRESH, (void*)&refresh },
{ ADI_EBIU_CMD_END, 0 }
};
ADI_PWR_COMMAND_PAIR ezkit_power[] = {
{ ADI_PWR_CMD_SET_PROC_VARIANT,(void*)ADI_PWR_PROC_BF561SKBCZ600X }, // 600Mhz ADSP-BF561 variant
{ ADI_PWR_CMD_SET_PACKAGE, (void*)ADI_PWR_PACKAGE_MBGA }, // in MBGA packaging, as on all EZ-KITS
{ ADI_PWR_CMD_SET_VDDEXT, (void*)ADI_PWR_VDEXT_EZKIT_BF561 }, // external voltage supplied to the voltage regulator is 3.3V
{ ADI_PWR_CMD_SET_CLKIN, (void*)ADI_PWR_CLKIN_EZKIT_BF561 }, // the CLKIN frequency 30 Hz
{ ADI_PWR_CMD_END, 0 }
};
ezInit(1);//see code in SDK-ezkitutilities.c
// initialize the interrupt manager
ezErrorCheck( adi_int_Init(NULL, // pointer to memory for interrupt manager to use
0, // memory size (in bytes)
&i, // location where the number of secondary handlers that can be supported will be stored
NULL)); // parameter for adi_int_EnterCriticalRegion (always NULL for VDK and standalone systems)
// and hook the exception and hardware error interrupts
ezErrorCheck(adi_int_CECHook(3,ExceptionHandler,NULL,FALSE));
ezErrorCheck(adi_int_CECHook(5,HWErrorHandler,NULL,FALSE));
// initialize the EBIU
//ezErrorCheck(adi_ebiu_Init(ezkit_sdram, // address of table containing SDRAM parameters
// 0)); // 0 - always 0 when EBIU initialized before power service
// initialize power and set frequencies to maximum
//ezErrorCheck(adi_pwr_Init( ezkit_power ));
//ezErrorCheck(adi_pwr_SetFreq (0,0, ADI_PWR_DF_NONE));
// initialize the dma manager
ezErrorCheck( adi_dma_Init(DMAMgrData, // pointer to memory for the DMA manager to use
sizeof(DMAMgrData), // memory size (in bytes)
&i, // location where # of DMA channels is stored
&DMAManagerHandle, // location where DMA manager handle is stored
NULL)); // parameter for adi_int_EnterCriticalRegion (always NULL for VDK and standalone systems)
// initialize the flag service
ezErrorCheck( adi_flag_Init(NULL, // pointer to memory the flag service can use
0, // memory size (in bytes)
&i, // location where # of simultaneous callacks is stored
NULL)); // parameter for adi_int_EnterCriticalRegion(always NULL)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -