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

📄 streaming.c

📁 ADSP 地层驱动
💻 C
字号:
/*********************************************************************************

Copyright(c) 2004 Analog Devices, Inc. All Rights Reserved. 

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.  

$RCSfile: Streaming.c,v $
$Revision: 1.3 $
$Date: 2006/05/19 19:33:23 $

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


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

Include files

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

#include <services\services.h>				// system services
#include <drivers\adi_dev.h>				// device manager includes
#include <drivers\ppi\adi_ppi.h>			// ppi driver includes

#include "ezkitutilities.h"	// EZ-Kit utilities
#include "adi_itu656.h"		// ITU656 utilities


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

User configurations:

Callbacks can be either "live" meaning they happen at hardware interrupt
time, or "deferred" meaning that the Deferred Callback Service is used
to make callbacks at a lower priority interrupt level.  Deferred 
callbacks usually allow the system to process data more efficiently with
lower interrupt latencies.  

The macro below can be used to toggle between "live" and "deferred"
callbacks.  All drivers and system services that make callbacks into an 
application are passed a handle to a callback service.  If that handle
is NULL, then live callbacks are used.  If that handle is non-NULL, 
meaning the handle is a real handle into a deferred callback service, 
then callbacks are deferred using the given callback service.  

The other user controlled macro is the USE_LOOPBACK macro.  When enabled
the example will setup the buffer chains to use the chained with loopback
mode rather than the chained mode.  When loopback is enabled, buffers
are continually reused and never have to be requeued.  When loopback
is disabled, buffers must be requeued by the application or else the 
driver will starve for data.  

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

//#define USE_DEFERRED_CALLBACKS	// enables deferred callbacks

//#define USE_LOOPBACK				// enabled chained with loopback



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

Enumerations and defines

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

// ADSP-BF533/537 have only 1 PPI called PPI0
// ADSP-BF561 has 2, PPI0 connected to video decoder, PPI1 to video encoder
#if defined(__ADSPBF561__)
#define ENCODER_PPI (1)
#else
#define ENCODER_PPI (0)
#endif


#define NUM_BUFFERS (30)			// color change rate = (NUM_BUFFERS/30)/second

// color patterns
static u8 black[]     = {0x80,0x10,0x80,0x10};	// Black pixel ycbcr format
static u8 blue[]      = {0xF0,0x29,0x6E,0x29};    // Blue pixel ycbcr format
static u8 red[]       = {0x5A,0x51,0xF0,0x51};    // Red pixel ycbcr format
static u8 megenta[]   = {0xCA,0x6A,0xDE,0x6A};	// Megenta pixel ycbcr format
static u8 green[]     = {0x36,0x91,0x22,0x91};	// Green pixel ycbcr format
static u8 cyan[]      = {0xA6,0xAA,0x10,0xAA};    // Cyan pixel ycbcr format
static u8 yellow[]    = {0x10,0xD2,0x92,0xD2};	// Yellow pixel ycbcr format
static u8 white[]     = {0x80,0xEB,0x80,0xEB};	// White pixel ycbcr format


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

Static data

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

// Create two areas in SDRAM that will each hold an NTSC frame that will be
// sent out to the monitor.
//      For single-core processors, we can define the frames right here but
//      for dual-core processors, we need to declare them here but define
//      them in the sml3 project so that they get placed in SDRAM properly

#if defined(__ADSPBF561__)
extern u8 PingFrame[];
extern u8 PongFrame[];
#else
static u8 PingFrame[ADI_ITU656_NTSC_LINE_WIDTH * ADI_ITU656_NTSC_HEIGHT];
static u8 PongFrame[ADI_ITU656_NTSC_LINE_WIDTH * ADI_ITU656_NTSC_HEIGHT];
#endif



// Create two buffer chains.  One chain will be used for one of the frames,
// the other chain for the other frame.
ADI_DEV_2D_BUFFER PingBuffer[NUM_BUFFERS];
ADI_DEV_2D_BUFFER PongBuffer[NUM_BUFFERS];


// DMA Manager data (base memory + memory for 1 DMA channel)
static u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 1)];

// 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 * 1)];

// Handle to the PPI driver
static ADI_DEV_DEVICE_HANDLE 	DriverHandle;


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

	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 last buffer in the 
					Ping and Pong buffer chains.  If loopback is enabled, 
					the device driver will automatically reuse the buffer 
					chains so there's really nothing to do, in fact, 
					generating the callback	in the first place is 
					unnecessary.  However, if loopback is not used, the 
					callback function must requeue the chain that just 
					finished in order to keep the device driver saturated 
					with data.  
										
					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 this example,
					the CallbackParameter is set to be the address of the 
					first buffer in the chain.  That allows	the callback 
					function to requeue the whole chain since even though 
					the callback was generated by the last buffer in the chain,
					the pArg parameter contains the address of the first buffer
					in the chain.  See the code in the "main()" function 
					below for more information.  

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


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:
		
			// when the buffer chain was created, the CallbackParameter value for the buffer
			// that was generating the callback was set to be the address of the first buffer
			// in the chain.  So here in the callback that value is passed in as the pArg
			// parameter.  
			pBuffer = (ADI_DEV_BUFFER *)pArg;
			
			// if loopback is enabled, the driver will continually reuse the buffers so there's
			// really nothing to do.  in fact, we really don't need to generate callbacks at all
			// if loopback is enabled.  if loopback is disabled though, we need to requeue the 
			// the buffer chain that just finished
#if defined(USE_LOOPBACK)
#else
			ezErrorCheck(adi_dev_Write(DriverHandle, ADI_DEV_2D, pArg));
#endif
			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:	main
*
*********************************************************************/


void main(void) {

	
	ADI_DEV_CMD_VALUE_PAIR ConfigurationTable [] = {		// table of PPI driver configuration values
#if defined(USE_LOOPBACK)
		{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, 			(void *)ADI_DEV_MODE_CHAINED_LOOPBACK	},
#else
		{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, 			(void *)ADI_DEV_MODE_CHAINED			},
#endif
		{ ADI_PPI_CMD_SET_CONTROL_REG,	 			(void *)0x0082							},
		{ ADI_PPI_CMD_SET_LINES_PER_FRAME_REG,		(void *)ADI_ITU656_NTSC_HEIGHT          },
		{ ADI_DEV_CMD_SET_STREAMING,				(void *)TRUE							},
		{ ADI_DEV_CMD_END,							NULL									},
	};

    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_2D_BUFFER 		Buffer2D;				// buffer to be sent to PPI Driver
	u32 					ResponseCount;			// response counter
	int						i;						// counter
	
	// initialize the EZ-Kit
#if defined(__ADSPBF561__)
	ezInit(2);
#else
	ezInit(1);
#endif
	
	// turn off all LEDs
	ezTurnOffAllLEDs();
	
	// initialize the Interrupt Manager and hook the exception and hardware error interrupts
	ezErrorCheck(adi_int_Init(NULL, 0, &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
#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 flag service, memory is not passed because callbacks are not being used
	ezErrorCheck(adi_flag_Init(NULL, 0, &ResponseCount, NULL));
	//enable all LEDS
	for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
        ezInitLED(i);
	}
	

	// 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));
	
	// initialize the two frames and make them both different colors

	//NtscVideoOutFrameBuffInit(PingFrame);
	adi_itu656_FrameFormat (PingFrame,ADI_ITU656_NTSC_IL);
	
	//NtscVideoOutFrameBuffInit(PongFrame);
	adi_itu656_FrameFormat (PongFrame,ADI_ITU656_NTSC_IL);
	
	//FillFrame (PingFrame, YELLOW);
	adi_itu656_FrameFill (PingFrame,ADI_ITU656_NTSC_IL,yellow);
	
	//FillFrame (PongFrame, BLUE);
	adi_itu656_FrameFill (PongFrame,ADI_ITU656_NTSC_IL,blue);

	// create a buffer chain that points to the PingFrame.  Each buffer points to the same PingFrame
	// so the PingFrame will be displayed NUM_BUFFERS times.  NUM_BUFFERS is sized to 
	// keep the display busy for 1 second.  Place a callback on only the last buffer
	// in the chain.  Make the CallbackParameter (the value that gets passed to the callback
	// function as the pArg parameter) point to the first buffer in the chain.  This way, when
	// the callback goes off, the callback function can requeue the whole chain if the loopback
	// mode is off.  
	for (i = 0; i < NUM_BUFFERS; i++) {
		PingBuffer[i].Data = PingFrame;
		PingBuffer[i].ElementWidth = 2;
		PingBuffer[i].XCount = (ADI_ITU656_NTSC_LINE_WIDTH/2);
		PingBuffer[i].XModify = 2;
		PingBuffer[i].YCount = ADI_ITU656_NTSC_HEIGHT;
		PingBuffer[i].YModify = 2;
		PingBuffer[i].CallbackParameter = NULL;
		PingBuffer[i].pNext = &PingBuffer[i + 1];
	}
	PingBuffer[NUM_BUFFERS - 1].CallbackParameter = &PingBuffer[0];
	PingBuffer[NUM_BUFFERS - 1].pNext = NULL;
	
	// now do the same for the Pong buffers
	for (i = 0; i < NUM_BUFFERS; i++) {
		PongBuffer[i].Data = PongFrame;
		PongBuffer[i].ElementWidth = 2;
		PongBuffer[i].XCount = (ADI_ITU656_NTSC_LINE_WIDTH/2);
		PongBuffer[i].XModify = 2;
		PongBuffer[i].YCount = ADI_ITU656_NTSC_HEIGHT;
		PongBuffer[i].YModify = 2;
		PongBuffer[i].CallbackParameter = NULL;
		PongBuffer[i].pNext = &PongBuffer[i + 1];
	}
	PongBuffer[NUM_BUFFERS - 1].CallbackParameter = &PongBuffer[0];
	PongBuffer[NUM_BUFFERS - 1].pNext = NULL;
	
	// enable video encoder (717x)
	ezEnableVideoEncoder();
		
	// give the decoder time to sync
	ezDelay(300);
		
	// open the PPI driver for output
	ezErrorCheck(adi_dev_Open(DeviceManagerHandle, &ADIPPIEntryPoint, ENCODER_PPI, NULL, &DriverHandle, ADI_DEV_DIRECTION_OUTBOUND, DMAManagerHandle, DCBManagerHandle, Callback));
		
	// configure the PPI driver with the values from the configuration table
    ezErrorCheck(adi_dev_Control(DriverHandle, ADI_DEV_CMD_TABLE, ConfigurationTable));
		
	// give the device the Ping and Pong buffer chains
	ezErrorCheck(adi_dev_Write(DriverHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)PingBuffer));
	ezErrorCheck(adi_dev_Write(DriverHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)PongBuffer));
	
	// enable data flow
	ezErrorCheck(adi_dev_Control(DriverHandle, ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE));
	
	// keep going until the last push button is pressed
	while (ezIsButtonPushed(EZ_LAST_BUTTON) == FALSE) ;
		
	// 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 + -