⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 corea.c

📁 ADI的ADSP-BF561下实现多媒体开发的通用框架。
💻 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/ppi/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(void);
extern void buffer_init(void);
extern void Setup_VideoIn(void);
extern void Setup_VideoOut(void);

/*********************************************************************

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_MB_IN[NUM_BUFFERS_L1][MBCOLS*(MBROWS)];
unsigned char L1_MB_OUT[NUM_BUFFERS_L1][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;
			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
	
	volatile 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_frame_in,offset_frame_out;
	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_MB_IN[0]);
	L1BufferInit(&Buffer2D_DMA1_L1_MB, L1_MB_OUT[0]);
	
	//Create a blank frame. Now, only active video needs to copied into the output
	//frame area
	
	NtscVideoOutFrameBuffInit((char*)subFrame2);//char* needed by video.c utility function. Since this file is also used by other device driver examples, not modifying video.c file
	FillFrame((char*)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_MB_IN[0];
		offset_frame_out=0;
		offset_frame_in=0;
		for(rowIndex=0;rowIndex<L2NUMROWS;rowIndex+=MBROWS)
		{
				offset_frame_in=276;
				offset_frame_out=276;
				//transfer the first buffer
				Buffer2D_DMA0_L1_MB.StartAddress=L1_MB_IN[0];
				Buffer2D_DMA0_L2.StartAddress = pBuffer0_L2+offset_frame_in;
				BufferL2toL1(&Buffer2D_DMA0_L1_MB,&Buffer2D_DMA0_L2,StreamHandle1);
				offset_frame_in+=MBCOLS;
				
				Buffer2D_DMA1_L1_MB.StartAddress=L1_MB_OUT[0];
				//Skip BufferL1toL1 if processed buffer is placed in L1_MB1
				BufferL1toL1(&Buffer2D_DMA1_L1_MB, &Buffer2D_DMA0_L1_MB,StreamHandle1);
				
				Buffer2D_DMA0_L1_MB.StartAddress=L1_MB_IN[1];
				Buffer2D_DMA0_L2.StartAddress = pBuffer0_L2+offset_frame_in;
				BufferL2toL1(&Buffer2D_DMA0_L1_MB,&Buffer2D_DMA0_L2,StreamHandle);
				offset_frame_in+=MBCOLS;
				
				for(MBIndex=1;MBIndex<NUM_MB;MBIndex++)
				{
				
					Buffer2D_DMA0_L2.StartAddress = pBuffer0_L3+offset_frame_out;
					BufferL1toL2(&Buffer2D_DMA0_L2,&Buffer2D_DMA1_L1_MB, StreamHandle1);
					offset_frame_out+=MBCOLS;
											
					Buffer2D_DMA1_L1_MB.StartAddress=L1_MB_OUT[MBIndex%NUM_BUFFERS_L1];
					/*Place application code here
					 *Process L1 buffer.
					 *Prototype 
					 */
					 //Skip BufferL1toL1 if processed buffer is placed in L1_MB1
					BufferL1toL1(&Buffer2D_DMA1_L1_MB, &Buffer2D_DMA0_L1_MB,StreamHandle);
					
					//transfer subsequent buffers
					Buffer2D_DMA0_L1_MB.StartAddress=L1_MB_IN[MBIndex%NUM_BUFFERS_L1];
					Buffer2D_DMA0_L2.StartAddress = pBuffer0_L2+offset_frame_in;
					BufferL2toL1(&Buffer2D_DMA0_L1_MB,&Buffer2D_DMA0_L2,StreamHandle);
					offset_frame_in+=MBCOLS;
					
				  }//end of for(MBIndex;...)
			//transfer last buffer
			Buffer2D_DMA0_L2.StartAddress = pBuffer0_L3+offset_frame_out;
			BufferL1toL2(&Buffer2D_DMA0_L2,&Buffer2D_DMA1_L1_MB, StreamHandle1);
			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 + -