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

📄 corea_example.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/adi_ppi.h>
#include "..\Buffers.h"
#include "buffer_init.h"
#include "video.h"
#include "CoreA.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 * 8)];

// 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_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];
//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];

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

	Function:		Callback

	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.  We 
				don't really need the callback function as the main 
				code uses the ProcessedFlag field of the buffer to 
				determine when the inbound buffer has completed 
				processing, but it's included here for illustrative 
				purposes.  
					
				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.  That non-NULL value is then passed to the 
				callback function as the pArg parameter.  In the example,
				the CallbackParameter is set to be the address of the 
				buffer itself.  That allows	the callback function to 
				determine which buffer was processed.  Often the 
				CallbackParameter value is set to NULL for every buffer 
				except the last buffer in a chain. That technique causes 
				the callback function to get called only when the last 
				buffer in the chain has been processed.  

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


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:
		
			// point to the buffer
			//pBuffer = (ADI_DEV_BUFFER *)pArg;
	
			// increment our counter
			Counter+=L2NUMROWS;
			free_counter++;
			if(Counter>525)//NUMROWS/2)
			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:	main

	Description:	This function is the starting point for Core A.
		

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


void main(void) {

	
	// bufferS to be sent to PPI Driver
	
	u32 			i, ResponseCount;		// response counter
	ADI_DEV_DEVICE_HANDLE 	DeviceHandle;	// handle to the device driver	
	
	ADI_DMA_2D_TRANSFER Buffer2D_DMA0_L2;
	ADI_DMA_2D_TRANSFER Buffer2D_DMA_L2_MB_IN;
	ADI_DMA_2D_TRANSFER Buffer2D_DMA_L2_MB_OUT;
	
	ADI_DMA_2D_TRANSFER Buffer2D_DMA_L2_IN;
	ADI_DMA_2D_TRANSFER Buffer2D_DMA_L2_OUT;
	
	
	ADI_DMA_2D_TRANSFER Buffer2D_DMA0_L1_MB;
	ADI_DMA_2D_TRANSFER Buffer2D_DMA1_L1_MB;
	
	ADI_DMA_2D_TRANSFER Buffer2D_DMA20_L1_MB;
	ADI_DMA_2D_TRANSFER Buffer2D_DMA21_L1_MB;
	
	ADI_DMA_2D_TRANSFER Buffer2D_Copy_DMA0_L2;
	unsigned int rowIndex,MBIndex,offset,offset_frame;
	unsigned char *pBuffer0_L2;
	unsigned char*pBuffer0_L1;
	unsigned char*pBuffer1_L1;
	unsigned char*pBuffer0_L3;
	unsigned int countermod525;
	int result;
	
	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					},
	};
	
	sys_init();
	
	buffer_init();
	
	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));
	
	// They shouldn't have had time to press a button, but just in case
	ButtonPressed = FALSE;
	
	
	L2BufferInit(&Buffer2D_DMA0_L2, subFrame1);
	

	L2Buffer_FullMBInit(&Buffer2D_DMA_L2_MB_IN,subFrame1);
	L2Buffer_FullMBInit(&Buffer2D_DMA_L2_MB_OUT,subFrame2);
	
	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);
	
	NtscVideoOutFrameBuffInit(subFrame2);
	FillFrame(subFrame2,0x10801080);
	
	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(Counter<1);
		while(curr_Counter==Counter);
		curr_Counter=Counter;
		switch(curr_Counter%15)
		{
			case 5: pBuffer0_L2=subFrame1;
					pBuffer0_L3=subFrame2+(curr_Counter)*1716;
					pBuffer0_L1=L1_MB0;
					break;
			case 10:pBuffer0_L2=subFrame3;
					pBuffer0_L3=subFrame2+(curr_Counter)*1716;
					pBuffer0_L1=L1_MB0;
					break;
			case 0: pBuffer0_L2=subFrame5;
					pBuffer0_L3=subFrame2+(curr_Counter)*1716;
					pBuffer0_L1=L1_MB0;
					break;
		}
		offset=0;
		offset_frame=0;
		for(rowIndex=0;rowIndex<L2NUMROWS;rowIndex+=MBROWS)
		{
			if(Counter >20 && Counter <= 265 || Counter > 285 && Counter < 525)
			{
				offset_frame=279;
				
				for(MBIndex=2;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
				   	sobel_fast(L1_MB0, MBROWS, MBCOLS/2, L1_MB1, 2);
				//	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	
					sobel_fast(L1_MB20, MBROWS, MBCOLS/2, L1_MB21, 2);
				//	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
				//add the last (5th) set of colomns...
			}//end of if ..Counter >25...
			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 + -