📄 videoinedgedetection_system.c
字号:
/*****************************************************************************
Copyright (c) 2006 Analog Devices, Inc. All Rights Reserved.
This software is proprietary and confidential to Analog Devices, Inc.
and its licensors.
*****************************************************************************
$RCSfile: VideoInEdgeDetection_System.c,v $
$Revision: 1.3 $
$Date: 2006/07/06 07:26:28 $
Project: BlackfinSDK (Edge Detection on ITU656 Video In)
Title: System service routines
Author(s): bmk
Revised by:
Description:
Configures system, start devices and manages PPI/Pushbutton callbacks
for Edge Detection on ITU 656 Video Input.
References:
None
*****************************************************************************
Tab Setting: 4
Target Processor: ADSP-BF5xx
Target Tools Revision: ADSP VisualDSP++ v4.5
******************************************************************************
Modification History:
====================
$Log: VideoInEdgeDetection_System.c,v $
Revision 1.3 2006/07/06 07:26:28 bmk
modified project to use video utility file macros
Revision 1.2 2006/07/04 05:33:19 bmk
added Slide-show mode for BF533
Revision 1.1 2006/06/30 01:33:55 bmk
Initial entry
******************************************************************************
Include files
*****************************************************************************/
#include <VideoInEdgeDetection_System.h> // Video In Edge Detection system includes
#include <drivers\encoder\adi_adv717x.h> // video encoder driver includes
#include <drivers\decoder\adi_adv7183.h> // video decoder driver includes
#include <drivers\twi\adi_twi.h> // TWI driver includes
#include <SDK-ezkitutilities.h> // EZ-Kit utility definitions
// Place all data in SDRAM
#pragma default_section (DATA,"sdram_bank1")
/*****************************************************************************
Macros
*****************************************************************************/
//local data and handles
#if defined(__ADSPBF533__)
// DMA Manager data :base memory +
// memory for 1 PPI DMA channels (For Video In or Video out) +
// memory for 2 MEMDMA channels (part of video from L3 to L1 for edge detection) +
// memory for 2 MEMDMA channels (Edge detected output from L1 to L3)
static u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 5)];
// Device Manager data (base memory + memory for 1 video encoder/decoder, 1 twi, 1 PPI)
static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * 3)];
// Interrupt Manager data
// (secondary interrupt for 3 Flags used as Push Buttons)
static u8 IntMgrData[(ADI_INT_SECONDARY_MEMORY * 3)];
// Flag Manager data - Flag pins used for Ez-Kit buttons (Callback memory for 3 flags)
static u8 FlagMgrData[(ADI_FLAG_CALLBACK_MEMORY * 3)];
#elif defined(__ADSPBF561__)
// DMA Manager data :base memory +
// memory for 2 PPI DMA channels (1 for Video In, 1 for Video out) +
// memory for 2 MEMDMA channels (part of video from L3 to L1 for edge detection) +
// memory for 2 MEMDMA channels (Edge detected output from L1 to L3)
static u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 6)];
// Device Manager data (base memory + memory for 1 video encoder, 1 video decoder, 1 twi, 2 PPI)
static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * 5)];
// Interrupt Manager data
// (secondary interrupt memory for 2 DMA1 MDMA streams for sobel edge detection
// + 4 Flags used as Push buttons)
static u8 IntMgrData[(ADI_INT_SECONDARY_MEMORY * 6)]; // storage for interrupt manager
// Flag Manager data - Flag pins used for Ez-Kit buttons (Callback memory for 4 flags)
static u8 FlagMgrData[(ADI_FLAG_CALLBACK_MEMORY * 4)];
#else
#error "*** ERROR: Application doesnot support this processor yet ***"
#endif
// Deferred Callback Manager data (memory for 1 service plus 6 posted callbacks)
static u8 DCBMgrData[ADI_DCB_QUEUE_SIZE + (ADI_DCB_ENTRY_SIZE)*6];
/*********************************************************************
Local function prototypes
*********************************************************************/
// initialises Ez-Kit button
void InitButton (ADI_FLAG_ID);
/*****************
Callback functions
******************/
// Exception handler
static ADI_INT_HANDLER (ExceptionHandler);
// Hardware error handler
static ADI_INT_HANDLER (HWErrorHandler);
// Video In callback function (for ADV7183)
static void VideoInCallback (void *AppHandle, u32 Event, void *pArg);
// Video Out callback function (for ADV717x)
static void VideoOutCallback (void *AppHandle, u32 Event, void *pArg);
// Ez-Kit Button press callback function
static void ButtonPressCallback (void *AppHandle, u32 Event, void *pArg);
/*********************************************************************
Globals
**********************************************************************
Device Driver and System Services Handles
*****************************************/
ADI_DCB_HANDLE DCBManagerHandle; // handle to the callback service Manager
ADI_DMA_MANAGER_HANDLE DMAManagerHandle; // handle to the DMA Manager
ADI_DEV_MANAGER_HANDLE DeviceManagerHandle; // handle to the Device Manager
ADI_DEV_DEVICE_HANDLE ADV7183DeviceHandle; // handle to the ADV7183 device driver
ADI_DEV_DEVICE_HANDLE ADV717xDeviceHandle; // handle to the ADV717x device driver
EDGE_DETECTION_SYSTEM_FLAGS SystemFlag; // System Flags
/*****************************************************************************
Device Configuration tables
*****************************************************************************/
#if defined(__ADSPBF533__)
// BF533 Ports (PF0=SCL,PF1=SDA) & Timer(Timer 0) used for Pseudo TWI
adi_twi_pseudo_port port={ADI_FLAG_PF0,ADI_FLAG_PF1,ADI_TMR_GP_TIMER_0,(ADI_INT_PERIPHERAL_ID)NULL};
#elif defined(__ADSPBF561__)
// BF561 Ports (PF0=SCL,PF1=SDA) & Timer(Timer 2) used for Pseudo TWI
adi_twi_pseudo_port port={ADI_FLAG_PF0,ADI_FLAG_PF1,ADI_TMR_GP_TIMER_2,(ADI_INT_PERIPHERAL_ID)NULL};
#endif
#if defined(__ADSPBF533__) || defined (__ADSPBF561__)
// Pseudo TWI Configuration to access video encoder/decoder registers
// Run TWI clock at 100MHz & 50% Duty Cycle
adi_twi_bit_rate rate={100,50};
ADI_DEV_CMD_VALUE_PAIR TWIConfig[]={ // configuration table for the TWI driver
{ ADI_TWI_CMD_SET_PSEUDO, (void *)(&port) },
{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *)ADI_DEV_MODE_SEQ_CHAINED},
{ ADI_TWI_CMD_SET_FIFO, (void *)0x0000 },
{ ADI_TWI_CMD_SET_RATE, (void *)(&rate) },
{ ADI_TWI_CMD_SET_LOSTARB, (void *)1 },
{ ADI_TWI_CMD_SET_ANAK, (void *)0 },
{ ADI_TWI_CMD_SET_DNAK, (void *)0 },
{ ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE },
{ ADI_DEV_CMD_END, NULL }
};
#else
#error "*** ERROR: Application doesnot support this processor yet ***"
#endif
/**************************************
ADV717x Register Configuration Tables
**************************************/
// ADV717x register configuration table for PAL mode
ADI_DEV_ACCESS_REGISTER ADV717x_PAL_Cfg[]={
{ADV717x_MR0, 0x05}, // register address, configuration data
{ADV717x_MR1, 0x10},
{ADV717x_MR2, 0x00},
{ADV717x_MR3, 0x00},
{ADV717x_MR4, 0x00},
{ADV717x_TMR0, 0x08},
{ADV717x_TMR1, 0x00},
{ADI_DEV_REGEND,0 }}; // End of register access
// ADV717x register configuration table for NTSC mode
ADI_DEV_ACCESS_REGISTER ADV717x_NTSC_Cfg[]={
{ADV717x_MR0, 0x00}, // register address, configuration data
{ADV717x_MR1, 0x58},
{ADV717x_MR2, 0x00},
{ADV717x_MR3, 0x00},
{ADV717x_MR4, 0x10},
{ADV717x_TMR0, 0x00},
{ADV717x_TMR1, 0x00},
{ADI_DEV_REGEND,0 }}; // End of register access
// Video Encoder configuration table
ADI_DEV_CMD_VALUE_PAIR VideoEncoderConfigTable [] = {
{ ADI_ADV717x_CMD_SET_TWI_CONFIG_TABLE, (void *) TWIConfig }, // TWI Configuration used for video encoder
// Set PPI Device number for video out
#if defined(__ADSPBF561__)
{ ADI_ADV717x_CMD_SET_PPI_DEVICE_NUMBER,(void *) 1 }, // BF561 - PPI 1 used for Video out
#else
{ ADI_ADV717x_CMD_SET_PPI_DEVICE_NUMBER,(void *) 0 }, // BF533 has only PPI 0
#endif
{ ADI_DEV_CMD_END, NULL },
};
// Video Decoder configuration table (leave the video format to default setting (NTSC))
ADI_DEV_CMD_VALUE_PAIR VideoDecoderConfigTable [] = {
{ ADI_AD7183_CMD_SET_TWI_CONFIG_TABLE, (void *) TWIConfig }, // TWI Configuration used for video decoder
{ ADI_AD7183_CMD_OPEN_PPI, (void *) 0 }, // Open PPI device for video in
{ ADI_DEV_CMD_END, NULL },
};
/*********************************************************************
Function: init_system
Description: Initialises EZ kit & Video Parameters
*********************************************************************/
section("sdram_bank1")
void InitSystem(void)
{
ezInit (1); // Initialise Ez kit (This app uses only one core)
ezTurnOffAllLEDs (); // Turn off all LEDs
// For BF533 & BF561, pull the video codec from reset mode
#if defined(__ADSPBF561__)
// enable video encoder (7179)
ezEnableVideoEncoder();
// enable video decoder (7183)
ezEnableVideoDecoder();
// For BF533 pull the video decoder from reset mode
#elif defined(__ADSPBF533__)
// enable video decoder (7183)
ezEnableVideoDecoder();
// delay to stabilise 7183
ezDelay(ADV7183_DELAY);
#endif // (__ADSPBF561__)
return;
}
/*********************************************************************
Function: install_system_services
Description: Installs system services
*********************************************************************/
// function implementations
section("sdram_bank1")
void InstallSystemServices(void)
{
u32 ResponseCount; // response counter
// initialize the Interrupt Manager and hook the exception and hardware error interrupts
ezErrorCheck(adi_int_Init(IntMgrData, sizeof(IntMgrData), &ResponseCount, NULL));
ezErrorCheck(adi_int_CECHook(3, ExceptionHandler, NULL, FALSE));
ezErrorCheck(adi_int_CECHook(5, HWErrorHandler, NULL, FALSE));
// initialize the Deferred Callback Manager and setup a queue
ezErrorCheck(adi_dcb_Init(&DCBMgrData[0], ADI_DCB_QUEUE_SIZE, &ResponseCount, NULL));
ezErrorCheck(adi_dcb_Open(14, &DCBMgrData[ADI_DCB_QUEUE_SIZE], (ADI_DCB_ENTRY_SIZE)*4, &ResponseCount, &DCBManagerHandle));
// initialize the Flag manager
ezErrorCheck(adi_flag_Init(FlagMgrData, sizeof(FlagMgrData), &ResponseCount, NULL));
// initialize the DMA Manager
ezErrorCheck(adi_dma_Init(DMAMgrData, sizeof(DMAMgrData), &ResponseCount, &DMAManagerHandle, NULL));
// initialize the Device Manager
ezErrorCheck(adi_dev_Init(DevMgrData, sizeof(DevMgrData), &ResponseCount, &DeviceManagerHandle, NULL));
/*** Initialise flags corresponding to the Ez-Kit buttons ***/
// Initialise the Termination button
InitButton(TERMINATE_BUTTON);
#if defined(__ADSPBF561__)
// Initialise the Update video mode button system status flag
InitButton(UPDATE_VIDEO_MODE_BUTTON);
// Clear Update Video Mode button
PBFlag.Video_Mode = FALSE;
// Initialise the Pause video button
InitButton(PAUSE_FRAME_CAPTURE_BUTTON);
#elif defined(__ADSPBF533__)
#if !defined(VIDEO_IN_SLIDE_SHOW) // Conditional compilation macro to enable slide show mode
// Initialise the Frame capture video button only when slide show mode is disabled
InitButton(PAUSE_FRAME_CAPTURE_BUTTON);
// Clear Frame capture button system status flag
PBFlag.Frame_Capture = FALSE;
#endif
#endif
// Initialise the toggle display button
InitButton(TOGGLE_DISPLAY_BUTTON);
// Clear Toggle display button system status flag
PBFlag.Toggle_Display= FALSE;
SystemFlag.SobelDone = TRUE; // Mark sobel flag as done to start sobel conversion
SystemFlag.SobelEnable = TRUE; // Enable sobel out
SystemFlag.UpdateVideoMode = FALSE; // clear update video mode flag
SystemFlag.Pause_Frame_Capture = FALSE; // clear pause video/frame capture flag
SystemFlag.FieldcopyDone = FALSE; // clear field copy done flag
SystemFlag.UpdateVideoInBufs = FALSE; // clear buffer update flag (video in callback)
SystemFlag.UpdateVideoOutBufs = FALSE; // clear buffer update flag (video out callback)
pPausedBuffer = NULL; // pointer to paused video 2D buffer
ADV717xDeviceHandle = NULL; // clear ADV717xDeviceHandle to indicate this is a cold start
return;
}
/*********************************************************************
Function: InitButton
Description: Initialises Blackfin Flags connected to
EZ-kit buttons
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -