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

📄 corea_ppitosdramtol2tosdramtoppi_pingponginl2.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 "VideoInOut.h"
#include "core.h"

#define ADI_NUM_SECONDARY_HANDLERS 2
#define ADI_NUM_DEVICES 1



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

Static data

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


// storage for interrupt manager secondary handlers
static u8 IntMgrData[(ADI_INT_SECONDARY_MEMORY * ADI_NUM_SECONDARY_HANDLERS)];	


// DMA Manager data (base memory + memory for 1 DMA channel)
static 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)
static u8 DCBMgrData[ADI_DCB_QUEUE_SIZE + (ADI_DCB_ENTRY_SIZE)*4];
#endif

// Device Manager data (base memory + memory for 1 device)
static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * ADI_NUM_DEVICES)];

ADI_DEV_DEVICE_HANDLE 	DeviceHandle;	// handle to the device driver	
/*********************************************************************

	Function:		ExceptionHandler
					HWErrorHandler

	Description:	We should never get an exception or hardware error, 
					but just in case we'll catch them and simply turn 
					on all the LEDS should one ever occur.

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

static ADI_INT_HANDLER(ExceptionHandler)	// exception handler
{
		ezErrorCheck(1);
		return(ADI_INT_RESULT_PROCESSED);
}
		
	
static ADI_INT_HANDLER(HWErrorHandler)		// hardware error handler
{
		ezErrorCheck(1);
		return(ADI_INT_RESULT_PROCESSED);
}


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

	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)
{
	
	static unsigned int Counter = 0;	// count the number of input buffers processed
	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;
		//	ezErrorCheck(adi_dev_Read(DeviceHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)&pBuffer));
			// increment our counter
			Counter++;
			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) {

   	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
	// bufferS to be sent to PPI Driver
	ADI_DEV_2D_BUFFER FirstBuffer2D, SecondBuffer2D, ThirdBuffer2D; 
	ADI_DEV_2D_BUFFER FirstBuffer2DOUT,SecondBuffer2DOUT;
	u32 			i, ResponseCount;		// response counter
	
	
	ADI_DMA_STREAM_HANDLE  StreamHandle;      // handle to the memory stream
	ADI_DMA_STREAM_HANDLE  StreamHandle1;      // handle to the memory stream
	
	ADI_DMA_2D_TRANSFER 		L3_Buffer2D0_DMA;
	ADI_DMA_2D_TRANSFER 		L3_Buffer2D1_DMA;
	
	ADI_DMA_2D_TRANSFER 		Buffer2D0_DMA;
	ADI_DMA_2D_TRANSFER 		Buffer2D1_DMA;
	
	int toggle,rowIndex;
	unsigned int offset;
	// table of configuration values for the PPI on input	
	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 *)0x0084				},
		{ ADI_PPI_CMD_SET_LINES_PER_FRAME_REG,	(void *)525			},
		{ ADI_DEV_CMD_END,		NULL					},
	};
	

	// initialize the Interrupt Manager 
	ezErrorCheck(adi_int_Init(IntMgrData, sizeof(IntMgrData), &ResponseCount, NULL));

	// enable core B to run (not necessary with VisualDSP debugger,
	// but is necessary when booting from or executing from external memory.
	*pSICA_SYSCR &= 0xFFDF;	
	
	// Initialize buttons, LEDs, power
	ezInit(2);
	
	ezTurnOffAllLEDs();
	
	ButtonPressed = FALSE;

 //	adi_pwr_SetFreq(0,0,ADI_PWR_DF_NONE);
 	
	// 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 Deferred Callback Manager and setup a queue
#if defined(USE_DEFERRED_CALLBACKS)
	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));
#else
	DCBManagerHandle = NULL;
#endif

	// 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));

	// populate the buffers that we'll use for the PPI input
	FirstBuffer2D.Data = sFrame0IN;
	FirstBuffer2D.ElementWidth = 2;
	FirstBuffer2D.XCount = 858;
	FirstBuffer2D.XModify = 2;
	FirstBuffer2D.YCount = NUMROWS;
	FirstBuffer2D.YModify = 2;
	FirstBuffer2D.CallbackParameter = NULL;
	//FirstBuffer2D.pNext = &SecondBuffer2D;
	FirstBuffer2D.pNext = NULL;

	SecondBuffer2D.Data = sFrame1IN;
	SecondBuffer2D.ElementWidth = 2;
	SecondBuffer2D.XCount = 858;
	SecondBuffer2D.XModify = 2;
	SecondBuffer2D.YCount = NUMROWS;
	SecondBuffer2D.YModify = 2;
	SecondBuffer2D.CallbackParameter = &sFrame0IN;
	SecondBuffer2D.pNext = NULL;//&ThirdBuffer2D;

	ThirdBuffer2D.Data = sFrame2IN;
	ThirdBuffer2D.ElementWidth = 2;
	ThirdBuffer2D.XCount = 858;
	ThirdBuffer2D.XModify = 2;
	ThirdBuffer2D.YCount = NUMROWS;
	ThirdBuffer2D.YModify = 2;
	ThirdBuffer2D.CallbackParameter = NULL;
	ThirdBuffer2D.pNext = NULL; 
	
	// populate the buffers that we'll use for the PPI output
	//No need for these two buffers as of now..
	FirstBuffer2DOUT.Data = sFrame0OUT;
	FirstBuffer2DOUT.ElementWidth = 2;
	FirstBuffer2DOUT.XCount = 858;
	FirstBuffer2DOUT.XModify = 2;
	FirstBuffer2DOUT.YCount = NUMROWS;
	FirstBuffer2DOUT.YModify = 2;
	FirstBuffer2DOUT.CallbackParameter = NULL;
	FirstBuffer2DOUT.pNext = &SecondBuffer2D;
	FirstBuffer2DOUT.pNext = NULL;

	SecondBuffer2DOUT.Data = sFrame1OUT;
	SecondBuffer2DOUT.ElementWidth = 2;
	SecondBuffer2DOUT.XCount = 858;
	SecondBuffer2DOUT.XModify = 2;
	SecondBuffer2DOUT.YCount = NUMROWS;
	SecondBuffer2DOUT.YModify = 2;
	SecondBuffer2DOUT.CallbackParameter = NULL;
	SecondBuffer2DOUT.pNext = NULL;//&ThirdBuffer2D;
	
	
	L2BufferInit(&Buffer2D0_DMA, L2_slice0);
	L2BufferInit(&Buffer2D1_DMA, L2_slice1);
	
	L3BufferInit(&L3_Buffer2D0_DMA, sFrame0IN);
	L3BufferInit(&L3_Buffer2D1_DMA, sFrame0OUT);
	
	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 *)&FirstBuffer2D));
 
	// 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;
	
	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));
	toggle = 0x1;
	while(ButtonPressed == FALSE)
	{//transfer L3 -> L2 -> L3
		//use two DMA channels..maintain just 2 buffers in L2
	//	BufferL3toL2(&L3_Buffer2D0_DMA,&Buffer2D0_DMA,&StreamHandle);
		//can be done in core B..but keeping the application sequential for now
	//	BufferL2toL3(&L3_Buffer2D1_DMA,&Buffer2D0_DMA,&StreamHandle);
	offset=0;
	
	//if(toggle)	
	//{
	for(rowIndex=0;rowIndex<NUMROWS;rowIndex+=L2NUMROWS){
		L3_Buffer2D0_DMA.StartAddress=sFrame0IN+offset;
		L3_Buffer2D1_DMA.StartAddress=sFrame0OUT+offset;
		//if(rowIndex==1)
		//	L3_Buffer2D1_DMA.StartAddress=sFrame0OUT;		
				
		if(toggle)
		{
			BufferL3toL2(&L3_Buffer2D0_DMA,&Buffer2D0_DMA,StreamHandle);
			BufferL2toL3(&L3_Buffer2D1_DMA,&Buffer2D1_DMA,StreamHandle1);
			toggle^=0x1;
		}
		else
		{
			BufferL3toL2(&L3_Buffer2D0_DMA,&Buffer2D1_DMA,StreamHandle);
			BufferL2toL3(&L3_Buffer2D1_DMA,&Buffer2D0_DMA,StreamHandle1);
			toggle^=0x1;
		}
		
		offset+=1716*L2NUMROWS;
						 
		
	//	L3_Buffer2D0_DMA.StartAddress=sFrame1IN;
	//	L3_Buffer2D1_DMA.StartAddress=sFrame1OUT;
	
	//}
	/*
	else 
	{
		adi_dma_MemoryCopy2D(StreamHandle, 
						 &L3_Buffer2D1_DMA,
						 &Buffer2D0_DMA,
						 1, 
						 NULL);
		toggle^=0x1;
		L3_Buffer2D0_DMA.StartAddress=sFrame0IN;
		L3_Buffer2D1_DMA.StartAddress=sFrame0OUT;
	}*/
		//BufferL3toL3(&L3_Buffer2D0_DMA, &L3_Buffer2D1_DMA,&StreamHandle);
	}//end of for
  }
	
	//close memdma
	adi_dma_MemoryClose(StreamHandle,TRUE);
	
	// 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 + -