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

📄 jpeg_mjpeg_system.c

📁 这个是balckfin533/561的MPEG和Mjpeg的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	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
	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));
	// 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));
	
	// Install the USB driver	
	InstallUSBdriver();

	return;
}

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

    Function:       InstallUSBdriver

    Description:    Installs USB device

*********************************************************************/
section("sdram0_bank1_nocache")
void InstallUSBdriver(void)	
{
    
	// open the NET2272
	ezErrorCheck( adi_dev_Open(	DeviceManagerHandle,			// DevMgr handle
								&ADINET2272EntryPoint,			// pdd entry point
								0,								// device instance
								(void*)0x01,					// client handle callback identifier
								&USBDeviceHandle,				// DevMgr handle for this device
								ADI_DEV_DIRECTION_BIDIRECTIONAL,// data direction for this device
								DMAManagerHandle,				// handle to DmaMgr for this device
								NULL,							// handle to deferred callback service
								NET2272_Callback));				// client's callback function    

	// configure the NET2272 mode
	ezErrorCheck( adi_dev_Control(USBDeviceHandle, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void*)ADI_DEV_MODE_CHAINED) );
	// enable data flow
	ezErrorCheck( adi_dev_Control(USBDeviceHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)TRUE) );

	return;
}

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

    Function:       InstallVideoEncoder
    Description:    Installs Video Encoder (ADV717x)

*********************************************************************/
section("sdram0_bank1_cache")
void InstallVideoEncoder()
{
   
	// ADV717x register to switch btwn NTSC and PAL
    ADI_DEV_ACCESS_REGISTER ADV717x_Cfg;
	// ADV717x register address to switch btwn NTSC & PAL    
    ADV717x_Cfg.Address = ADV717x_MR0;
        					
#if defined(__ADSPBF561__)
	
    // open the ADV7179 driver for video output
   	ezErrorCheck(adi_dev_Open(  DeviceManagerHandle,     		// Dev manager Handle
                		   		&ADIADV7179EntryPoint,          // Device Entry point
                            	0,                              // Device number
	                            NULL,                           // No client handle
    	                        &ADV717xDeviceHandle,           // Device manager handle address
        	                    ADI_DEV_DIRECTION_OUTBOUND,     // Data Direction (video out)
            	                DMAManagerHandle,               // Handle to DMA Manager
                	            DCBManagerHandle,				// Callback Manager
                    	        VideoOutCallback));				// callback function
                    	        
#elif defined(__ADSPBF533__)

    // open the AD7171 driver for video output
    ezErrorCheck(adi_dev_Open(  DeviceManagerHandle,            // Dev manager Handle
                 		   		&ADIADV7171EntryPoint,          // Device Entry point
                            	0,                              // Device number
	                            NULL,                           // No client handle
    	                        &ADV717xDeviceHandle,           // Device manager handle address
        	                    ADI_DEV_DIRECTION_OUTBOUND,     // Data Direction (video out)
            	                DMAManagerHandle,               // Handle to DMA Manager
                	            DCBManagerHandle,      			// Callback Manager
                    	        VideoOutCallback));				// callback function

#else
#error "*** ERROR: Processor not yet supported ***"
#endif
	
	// TWI Configuration table
	ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_ADV717x_CMD_SET_TWI_CONFIG_TABLE, (void *) TWIConfig));

	// update the output video mode
	VideoMode = OutputVideoMode;
	UpdateVideoMode ();
	
	// ADV717x register Configuration    
	// Check Output video mode
	if (VideoMode == ITU656_PAL)
	{
    	// Config ADV717x in PAL mode (SCFR with PAL config values)
		ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_ADV717x_CMD_SET_SCF_REG, (void *)ADV717x_SCF_VALUE_PAL_BI));
		// MR0 value to set ADV717x in PAL mode
		ADV717x_Cfg.Data = 0x05;
		// Config other internal regs of ADV717x to PAL video mode
		ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_DEV_CMD_REGISTER_WRITE, (void *)&ADV717x_Cfg));
	}
	else // VideoMode must be ITU656_NTSC
	{
    	// Config ADV717x in PAL mode (SCFR with NTSC config values)
		ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_ADV717x_CMD_SET_SCF_REG, (void *)ADV717x_SCF_VALUE_NTSC));
		// MR0 value to set ADV717x in NTSC mode
		ADV717x_Cfg.Data = 0x00;				
		// Config other internal regs of ADV717x to NTSC video mode
		ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_DEV_CMD_REGISTER_WRITE, (void *)&ADV717x_Cfg));		
	}

// Set PPI port for video out
#if defined(__ADSPBF561__)
	// BF561 - PPI 1 used for Video out
	ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_ADV717x_CMD_SET_PPI_DEVICE_NUMBER, (void *) 1));
#elif defined (__ADSPBF533__)
	// BF533 - PPI 0 used for Video out
	ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_ADV717x_CMD_SET_PPI_DEVICE_NUMBER, (void *) 0));
#endif

	// Open PPI device for video out
	ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_ADV717x_CMD_SET_PPI_STATUS, (void *)ADI_ADV717x_PPI_OPEN));	
	// Set Dataflow method
	ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *) ADI_DEV_MODE_CHAINED_LOOPBACK));

	// Enable streaming
	ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_DEV_CMD_SET_STREAMING, (void *) TRUE));
				
	return;
}

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

    Function:       InstallVideoDecoder
    Description:    Installs Video Decoder (ADV7183)

*********************************************************************/
section("sdram0_bank1_cache")
void InstallVideoDecoder()	
{
    // open the ADV7183 driver for video input
   	ezErrorCheck(adi_dev_Open(  DeviceManagerHandle,     		// Dev manager Handle
               		   			&ADIADV7183EntryPoint,          // Device Entry point
                          		0,                              // Device number
	                            NULL,                           // No client handle
   		                        &ADV7183DeviceHandle,           // Device manager handle address
       		                    ADI_DEV_DIRECTION_INBOUND,      // Data Direction (video in)
           		                DMAManagerHandle,               // Handle to DMA Manager
               		            DCBManagerHandle,				// Callback Manager
                   		        VideoInCallback));				// callback function

	// Open PPI device for video in
	ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_AD7183_CMD_OPEN_PPI, (void *) 0));
	
	// TWI Configuration for video decoder
	ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_AD7183_CMD_SET_TWI_CONFIG_TABLE, (void *) TWIConfig));

	// Update Input Video Mode
	UpdateInputVideoMode();

	// for JPEG, only one should be captured
	if (Coding_Algorithm == CODING_ALGORITHM_JPEG)
	{
		// Set Dataflow method
		ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *) ADI_DEV_MODE_CHAINED));
		// Disable streaming
		ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_DEV_CMD_SET_STREAMING, (void *) FALSE));
	}
	else	// for MJPEG, continue capturing video
	{	    
		// Set Dataflow method		
		ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *) ADI_DEV_MODE_CHAINED_LOOPBACK));	
		// Enable streaming
		ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_DEV_CMD_SET_STREAMING, (void *) TRUE));		
	}
		
	return;
}

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

    Function:       UpdateInputVideoMode
    Description:    Reads ADV7183 Status1 Reg to auto-detect
    				Input Video Mode

	Status1 Reg:
	bit 0 => ADV7183 is in Lock (1) with video / lost(0)
	bit 1 => ADV7183 have lost sync (1) since previous read
	bits 6,5,4 => Autodetection Result (value 0,1=NTSC / 2,3,4,6=PAL)	

*********************************************************************/
section("sdram0_bank1_cache")
void	UpdateInputVideoMode(void)
{
  
    ADI_DEV_ACCESS_REGISTER		Status1;		// read ADV7183 Status1 reg
        
    Status1.Address		= ADV7183_STATUS1_RO;	// Status1 reg address
   	Status1.Data	= 0;					// clear the location where the data will be read to    
   	
	// call Device Access to read Status1 reg
	ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_DEV_CMD_REGISTER_READ, (void *) &Status1));
   
    // retrive ITU656 Input video mode
	switch ((Status1.Data >> 4) & 0x07)	
	{
		// case (NTSC video)
    	case 0:
    	case 1:	        
			// update VideoMode flag to ITU656 NTSC
			VideoMode = ITU656_NTSC;
    		break;
	    	
    	// case (PAL video)
    	case 2:
    	case 3:
    	case 4:
    	case 6:
			// update VideoMode flag to ITU656 PAL
			VideoMode = ITU656_PAL;
			break;
			
		// other video modes not supported. NTSC mode is set as default
    	default:
    		printf("\nNo valid Video Input was found!. System will return to default settings"); 
    		VideoMode = ITU656_NTSC;
    		break;
	}
		
	// check if ADV7183 have lost sync since previous reg read
	if (Status1.Data & 2)
	{
	    // yes. This must be a new video input mode. Update video parameters
		// Check video mode
		if (VideoMode == ITU656_PAL)
		{
		    printf ("\nConfiguring system for ITU656 PAL Video Input (720 x 576)...\n");
	    	// Config ADV7183 PPI in PAL mode
			ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_AD7183_CMD_SET_VIDEO_FORMAT, (void *)1));
		}
		else // video mode must be ITU656_NTSC
		{
		    printf ("\nConfiguring system for ITU656 NTSC Video Input  (720 x 486)...\n");
	    	// Config ADV7183 PPI in NTSC mode
			ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_AD7183_CMD_SET_VIDEO_FORMAT, (void *)0));
		}
		// update video parameters
		UpdateVideoMode();		
	}
	
	return;
}

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

    Function:       UpdateVideoMode
    Description:    Updates video parameters to selected video mode
    				Selects Video In/Out between ITU656 NTSC and PAL
    				In/Out Video will be set to NTSC when VideoMode = 0
    				In/Out Video will be set to PAL when VideoMode = 1

*********************************************************************/
section("sdram0_bank1_cache")
void UpdateVideoMode (void)
{
	// update video parameters
	// Check video mode
	if (VideoMode == ITU656_PAL)
	{
		// video mode is ITU656 PAL
	  	// Video data per line (bytes)
		DataPerLine		= PAL_DATA_PER_LINE;
		// Number of lines per ITU656 video frame (bytes)
		FrameLines		= PAL_FRAME_LINES;
		// Number of Active lines per ITU656 video frame (bytes)
		ActiveFrameLines= PAL_ACTIVE_LINES;
		// Number of bytes to skip to reach active video data in a single line
		ActiveVideoSkip	= PAL_ACTIVE_VIDEO_SKIP;
		// Number of bytes to skip to reach active video frame field1 (odd frame)
		Field1Skip		= PAL_F1_SKIP;
		// Number of bytes to skip to reach active video frame field2 (even frame)
		Field2Skip		= PAL_F2_SKIP;
	}	
	else if (VideoMode == ITU656_NTSC)
	{
   		// Video mode must be ITU656 NTSC
   		// Video data per line (bytes)
		DataPerLine		= NTSC_DATA_PER_LINE;
		// Number of lines per ITU656 video frame (bytes)
		FrameLines		= NTSC_FRAME_LINES;
		// Number of Active lines per ITU656 video frame (bytes)
		ActiveFrameLines= NTSC_ACTIVE_LINES;
		// Number of bytes to skip to reach active video data in a single line
		ActiveVideoSkip	= NTSC_ACTIVE_VIDEO_SKIP;
		// Number of bytes to skip to reach active video frame field1 (odd frame)
		Field1Skip		= NTSC_F1_SKIP;
		// Number of bytes to skip to reach active video frame field2 (even frame)
		Field2Skip		= NTSC_F2_SKIP;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -