📄 corea_2bufferloop.c
字号:
/*************************************************************************
Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.
Please refer to the "readme" file for a description of this example.
************************************************************************/
/*********************************************************************
Include files
*********************************************************************/
#include <services/services.h>
#include <ezkitutilities.h>
#include <drivers/adi_dev.h>
#include <drivers/adi_ppi.h>
#include "..\Buffers.h"
#include "buffer_init.h"
#include "video.h"
#include "CoreA.h"
//for cycle count
#include <ccblkfn.h>
#include <sysreg.h>
extern void sobel_fast(unsigned char*, int, int, unsigned char*, int);
extern void sys_init();
/*********************************************************************
data
*********************************************************************/
// storage for interrupt manager secondary handlers
u8 IntMgrData[(ADI_INT_SECONDARY_MEMORY * ADI_NUM_SECONDARY_HANDLERS)];
// DMA Manager data (base memory + memory for 1 DMA channel)
u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 12)];
// Deferred Callback Manager data (memory for 1 service plus 4 posted callbacks)
#if defined(USE_DEFERRED_CALLBACKS)
u8 DCBMgrData[ADI_DCB_QUEUE_SIZE + (ADI_DCB_ENTRY_SIZE)*4];
#endif
// Device Manager data (base memory + memory for 1 device)
u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * ADI_NUM_DEVICES)];
ADI_DCB_HANDLE DCBManagerHandle; // handle to the callback service
ADI_DMA_MANAGER_HANDLE DMAManagerHandle; // handle to the DMA Manager
ADI_DEV_MANAGER_HANDLE DeviceManagerHandle; // handle to the Device Manager
ADI_DEV_DEVICE_HANDLE DeviceHandle; // handle to the device driver
ADI_DMA_STREAM_HANDLE StreamHandle; // handle to the memory stream
ADI_DMA_STREAM_HANDLE StreamHandle1; // handle to the memory stream
ADI_DMA_STREAM_HANDLE StreamHandle2; // handle to the memory stream
ADI_DEV_2D_BUFFER Buffer2D_IN[NUM_BUFFERS_L2];
ADI_DEV_2D_BUFFER Buffer2D_OUT[NUM_BUFFERS_L2];
//volatile unsigned int Counter = 0; // count the number of input buffers processed
volatile static unsigned int curr_Counter = 0;
volatile static unsigned int count_slice_processed=0;
volatile static unsigned int free_counter = 0; // count the number of input buffers processed
unsigned char L1_MB0[MBCOLS*(MBROWS+10)];
unsigned char L1_MB1[MBCOLS*(MBROWS+10)];
unsigned char L1_MB20[MBCOLS*(MBROWS+10)];
unsigned char L1_MB21[MBCOLS*MBROWS];
volatile unsigned int cycle_count;
volatile unsigned int net_cycles;
/*********************************************************************
Function: Callback
Description:A callback is generated when the PPI
has completed processing of the input buffer.
Increment the counter for number of rows processed
at completion of every slice of frame
*********************************************************************/
static void Callback(
void *AppHandle,
u32 Event,
void *pArg)
{
ADI_DEV_BUFFER *pBuffer; // pointer to the buffer that was processed
// CASEOF (event type)
switch (Event) {
// CASE (buffer processed)
case ADI_DEV_EVENT_BUFFER_PROCESSED:
// increment our counter
Counter+=L2NUMROWS;
cycle_count=sysreg_read(reg_CYCLES);
sysreg_write(reg_CYCLES,0x0);
sysreg_write(reg_CYCLES2,0x0);
if(Counter>NUMROWS)
Counter=L2NUMROWS;
break;
// CASE (an error)
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
case ADI_PPI_EVENT_ERROR_INTERRUPT:
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
// ENDCASE
}
// return
}
/*********************************************************************
Function: ButtonCallback
Description: This function is called when a button is pressed.
*********************************************************************/
static void ButtonCallback(
void *AppHandle,
u32 Event,
void *pArg)
{
ButtonPressed = TRUE;
}
/************************************************************************
Function:Setup_VideoIn
Description:
************************************************************************/
void Setup_VideoIn()
{
ADI_DEV_CMD_VALUE_PAIR InboundConfigurationTable [] = {
{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *) ADI_DEV_MODE_CHAINED_LOOPBACK },
{ ADI_PPI_CMD_SET_CONTROL_REG, (void *)0x0184 },
{ ADI_PPI_CMD_SET_LINES_PER_FRAME_REG, (void *)525 },
{ ADI_DEV_CMD_END, NULL },
};
ezEnableVideoDecoder();
// open the PPI driver for input
ezErrorCheck(adi_dev_Open(DeviceManagerHandle, &ADIPPIEntryPoint, 0, NULL, &DeviceHandle, ADI_DEV_DIRECTION_INBOUND, DMAManagerHandle, DCBManagerHandle, Callback));
// configure the PPI driver with the values from the inbound configuration table
ezErrorCheck(adi_dev_Control(DeviceHandle, ADI_DEV_CMD_TABLE, InboundConfigurationTable));
// give the PPI driver the buffer to process
ezErrorCheck(adi_dev_Read(DeviceHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)&Buffer2D_IN[0]));
// tell the PPI driver to enable data flow
ezErrorCheck(adi_dev_Control(DeviceHandle, ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE));
}
/************************************************************************
Function:Setup_VideoIn
Description:
************************************************************************/
void Setup_VideoOut()
{
ADI_DEV_CMD_VALUE_PAIR OutboundConfigurationTable [] = {
{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *)ADI_DEV_MODE_CHAINED_LOOPBACK },
{ ADI_PPI_CMD_SET_CONTROL_REG, (void *)0x0182 },
{ ADI_PPI_CMD_SET_LINES_PER_FRAME_REG, (void *)525 },
{ ADI_DEV_CMD_END, NULL },
};
ezEnableVideoEncoder();
// open the PPI driver for output
ezErrorCheck(adi_dev_Open(DeviceManagerHandle, &ADIPPIEntryPoint, 1, NULL, &DeviceHandle, ADI_DEV_DIRECTION_OUTBOUND, DMAManagerHandle, DCBManagerHandle, Callback));
// configure the PPI driver with the values from the outbound configuration table
ezErrorCheck(adi_dev_Control(DeviceHandle, ADI_DEV_CMD_TABLE, OutboundConfigurationTable));
// give the PPI driver the buffer to process
ezErrorCheck(adi_dev_Write(DeviceHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)&Buffer2D_OUT[0]));
ezErrorCheck(adi_dev_Control(DeviceHandle, ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE));
}
/*********************************************************************
Function: main
Description:Calls the init routines for initialiazing system
services and buffers.
Transfer data from PPI to L2 to L1 to SDRAM(L3) to PPI on a
macro-block basis. The video output buffer in SDRAM is a full
frame buffer.
*********************************************************************/
void main(void) {
// bufferS to be sent to PPI Driver
u32 i, ResponseCount; // response counter
ADI_DMA_2D_TRANSFER Buffer2D_DMA0_L2; // Input L2 buffer
ADI_DMA_2D_TRANSFER Buffer2D_DMA0_L1_MB; //Input L1 buffer 1
ADI_DMA_2D_TRANSFER Buffer2D_DMA1_L1_MB; //Output L1 buffer 1
ADI_DMA_2D_TRANSFER Buffer2D_DMA20_L1_MB; //Input L1 buffer 2
ADI_DMA_2D_TRANSFER Buffer2D_DMA21_L1_MB; //Output L1 buffer 2
unsigned int rowIndex,MBIndex,offset,offset_frame;
unsigned char *pBuffer0_L2;
unsigned char*pBuffer0_L1;
unsigned char*pBuffer1_L1;
unsigned char*pBuffer0_L3;
int result;
//Initialize interrupts, DMA etc.
sys_init();
//Initialize the Video In/Out buffer chain
buffer_init();
//Configures PPI0 and sets up the input video buffer chain
Setup_VideoIn();
//Configures PPI1 and sets up the output video buffer chain
Setup_VideoOut();
ButtonPressed = FALSE;
//Initialise DMA transfer buffers with X, Y count and modify values
L2BufferInit(&Buffer2D_DMA0_L2, subFrame1);
L1BufferInit(&Buffer2D_DMA0_L1_MB, L1_MB0);
L1BufferInit(&Buffer2D_DMA1_L1_MB, L1_MB1);
L1BufferInit(&Buffer2D_DMA20_L1_MB, L1_MB20);
L1BufferInit(&Buffer2D_DMA21_L1_MB, L1_MB21);
//Create a blank frame. Now, only active video needs to copied into the output
//frame area
NtscVideoOutFrameBuffInit(subFrame2);
FillFrame(subFrame2,0x10881088);
//Open MEMDMA channels
ezErrorCheck(adi_dma_MemoryOpen(DMAManagerHandle,
ADI_DMA_MDMA2_0,
(void *)0x12345678,
&StreamHandle2,
NULL));
ezErrorCheck(adi_dma_MemoryOpen(DMAManagerHandle,
ADI_DMA_MDMA1_0,
(void *)0x12345678,
&StreamHandle,
NULL));
ezErrorCheck(adi_dma_MemoryOpen(DMAManagerHandle,
ADI_DMA_MDMA1_1,
(void *)0x12345678,
&StreamHandle1,
NULL));
while(Counter<1);
curr_Counter=Counter;
while(ButtonPressed == FALSE)
{
while(curr_Counter==Counter);
curr_Counter=Counter;
switch(curr_Counter%15)
{
case 5: pBuffer0_L2=subFrame1;
break;
case 10:pBuffer0_L2=subFrame3;
break;
case 0: pBuffer0_L2=subFrame5;
break;
}
pBuffer0_L3=subFrame2+curr_Counter*1716;
pBuffer0_L1=L1_MB0;
offset=0;
offset_frame=0;
for(rowIndex=0;rowIndex<L2NUMROWS;rowIndex+=MBROWS)
{
offset_frame=276;
for(MBIndex=0;MBIndex<NUM_MB;MBIndex++)
{
//transfer the first buffer
Buffer2D_DMA0_L2.StartAddress = pBuffer0_L2+offset_frame;
BufferL2toL1(&Buffer2D_DMA0_L1_MB,&Buffer2D_DMA0_L2,StreamHandle);
//transfer second buffer
offset_frame+=MBCOLS;
Buffer2D_DMA0_L2.StartAddress = pBuffer0_L2+offset_frame;
BufferL2toL1(&Buffer2D_DMA20_L1_MB,&Buffer2D_DMA0_L2,StreamHandle1);
//process the first buffer
/*Place application code here
*Process L1_MB0 buffer
*Place processed buffer in L1_MB1
*/
//Skip BufferL1toL1 if processed buffer is placed in L1_MB1
BufferL1toL1(&Buffer2D_DMA1_L1_MB, &Buffer2D_DMA0_L1_MB,StreamHandle);
//transfer back first buffer
offset_frame-=MBCOLS;
Buffer2D_DMA0_L2.StartAddress = pBuffer0_L3+offset_frame;
BufferL1toL2(&Buffer2D_DMA0_L2,&Buffer2D_DMA1_L1_MB, StreamHandle1);
//process the second buffer
/*Place application code here
*Process L1_MB20 buffer
*Place processed buffer in L1_MB21
*/
//Skip BufferL1toL1 if processed buffer is placed in L1_MB21
BufferL1toL1(&Buffer2D_DMA21_L1_MB, &Buffer2D_DMA20_L1_MB,StreamHandle);
//transfer back second buffer
offset_frame+=MBCOLS;
Buffer2D_DMA0_L2.StartAddress = pBuffer0_L3+offset_frame;
BufferL1toL2(&Buffer2D_DMA0_L2,&Buffer2D_DMA21_L1_MB, StreamHandle1);
offset+=MBCOLS;
offset_frame+=MBCOLS;
}//end of for .. MBIndex
count_slice_processed++;
}//end of for; rowIndex
}
// close the PPI driver
ezErrorCheck(adi_dev_Close(DeviceHandle));
// close the Device Manager
ezErrorCheck(adi_dev_Terminate(DeviceManagerHandle));
// close down the DMA Manager
ezErrorCheck(adi_dma_Terminate(DMAManagerHandle));
// close down the Deferred Callback Manager
#if defined(USE_DEFERRED_CALLBACKS)
ezErrorCheck(adi_dcb_Terminate());
#endif
// return
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -