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

📄 video_example_bf561.c

📁 BlackFin处理器视频演示代码
💻 C
字号:
/**
 *@file video_example.c
 *@author Zlatan Stanojevic
 *
 *This file contains the example of a possible init procedure and interrupt handlers.
 */

/******************************************************
 
 This file contains several example setups for both
 video input and output. A reference of the used API
 functions can be found in the included Doxygen 
 documentation. Feel free to modify this file.

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


#include "analog_video.h"
#include "blt.h"
#include "../../misc/clock_query.h"
#include <stdio.h>
#include <stdlib.h>
#include <gpio_global.h>
#include "video_boards.h"

// SELECT THE VIDEO STANDARD ------------------------
//#define NTSC
#define PAL
// --------------------------------------------------
// SELECT MODE --------------------------------------
#define _USE_OUTPUT_
//#define _USE_LOOP_THROUGH_
// --------------------------------------------------

// *******************************************************************
// ADD THE _USE_TESTPIC_ MACRO TO THE PREPROCESSOR DEFINITIONS WITHIN
// THE PROJECT SETTINGS TO GET A TEST PICTURE ON OUTPUT. OTHERWISE A
// TESTSCREEN WITH RED AND BLUE STRIPES IS SHOWN
// *******************************************************************

#if defined (NTSC)
#define VIDEO_STANDARD		NTSC_443
#define VIDEO_STRUCT		g_pNTSCstd
#define Y_RES				484
#elif defined (PAL)
#define VIDEO_STANDARD		PAL_BGHID
#define VIDEO_STRUCT		g_pPALstd
#define Y_RES				576
#else
#error "video standard not supported"
#endif


#define DEBUG

#ifdef DEBUG
EX_INTERRUPT_HANDLER( dma_err )
{
	asm( "nop;" );
}
#else
#define dma_err 0
#endif

#if   defined( __ADSPBF533__ )
#define MDMA_CHANNEL ADI_DMA_MDMA_0
#elif defined( __ADSPBF537__ )
#define MDMA_CHANNEL ADI_DMA_MDMA_0
#elif defined( __ADSPBF561__ )
#define MDMA_CHANNEL ADI_DMA_MDMA2_0
#endif

static BLTBufferDesc screen1, screen2, output, testpic;

AV_EVENT_HANDLER( frameHandler )
{
//  *pDMA1_1_IRQ_STATUS = 1; //clear dma interrupt flag - this really is necessary, but is done by the ppi-dma driver
    
    int which;
    av_tell( 0, &which );
    //Map the input screen 9 times onto the output buffer
    if( which )
    {
        blt( MDMA_CHANNEL, &screen1, &output, 0, 0, 0, 0, 240, 192 );
        blt( MDMA_CHANNEL, &screen1, &output, 0, 0, 240, 0, 240, 192 );
        blt( MDMA_CHANNEL, &screen1, &output, 0, 0, 480, 0, 240, 192 );
        blt( MDMA_CHANNEL, &screen1, &output, 0, 0, 0, 192, 240, 192 );
        blt( MDMA_CHANNEL, &screen1, &output, 0, 0, 240, 192, 240, 192 );
        blt( MDMA_CHANNEL, &screen1, &output, 0, 0, 480, 192, 240, 192 );
        blt( MDMA_CHANNEL, &screen1, &output, 0, 0, 0, 384, 240, 192 );
        blt( MDMA_CHANNEL, &screen1, &output, 0, 0, 240, 384, 240, 192 );
        blt( MDMA_CHANNEL, &screen1, &output, 0, 0, 480, 384, 240, 192 );
    }
    else
    {
        blt( MDMA_CHANNEL, &screen2, &output, 0, 0, 0, 0, 240, 192 );
        blt( MDMA_CHANNEL, &screen2, &output, 0, 0, 240, 0, 240, 192 );
        blt( MDMA_CHANNEL, &screen2, &output, 0, 0, 480, 0, 240, 192 );
        blt( MDMA_CHANNEL, &screen2, &output, 0, 0, 0, 192, 240, 192 );
        blt( MDMA_CHANNEL, &screen2, &output, 0, 0, 240, 192, 240, 192 );
        blt( MDMA_CHANNEL, &screen2, &output, 0, 0, 480, 192, 240, 192 );
        blt( MDMA_CHANNEL, &screen2, &output, 0, 0, 0, 384, 240, 192 );
        blt( MDMA_CHANNEL, &screen2, &output, 0, 0, 240, 384, 240, 192 );
        blt( MDMA_CHANNEL, &screen2, &output, 0, 0, 480, 384, 240, 192 );
    }
    
    return AV_HANDLER_RESULT_PROCESSED;
}


AV_EVENT_HANDLER( frameHandlerLoopThrough )
{
    return AV_HANDLER_RESULT_PROCESSED;
}


void Handler_Output( unsigned short flags )
{
#ifdef DEBUG
#endif
}


static char *output_matrix;
static char *input_double_buffer;


AV_EVENT_HANDLER( Handler_DirectLoop )
{
#ifdef DEBUG
    printf( "Sync lost!ddd\n" );
#endif
    if( pa_eEvent == AV_EVENT_PPI_FT_ERR )
    {
        AV_RESULT result;
        result = av_restart( 0 );
        long loops = querySystemClock() / 20, i;
        for( i = 0; i < loops; i++ )
            asm( "ssync;" );
        if( ! av_input_locked() )
        {
            AV_SRC_FIELD video_source;
            result = av_stop( 0 );
            while( AV_RESULT_OK != av_find_input( 1, &video_source, 
            	EXT_VIDEO_INPUTS, VIDEO_STANDARD ) );
            result = av_start( 0 );
        }
        return AV_HANDLER_RESULT_NOT_PROCESSED;
    }
    
    return AV_HANDLER_RESULT_NOT_PROCESSED;
}

AV_EVENT_HANDLER( Handler_BufferedLoop )
{
#ifdef DEBUG
    printf( "Sync lost!aaa\n" );
#endif
    if( pa_eEvent == AV_EVENT_PPI_FT_ERR )
    {
        av_restart( 0 );
        long loops = querySystemClock() / 20, i;
        for( i = 0; i < loops; i++ )
            asm( "ssync;" );
        if( ! av_input_locked() )
        {
            AV_SRC_FIELD video_source;
            av_stop( 0 );
            while( AV_RESULT_OK != av_find_input( 1, &video_source, 
            	EXT_VIDEO_INPUTS, VIDEO_STANDARD ) );
            av_start( 0 );
        }
        return AV_HANDLER_RESULT_NOT_PROCESSED;
    }
    return AV_HANDLER_RESULT_NOT_PROCESSED;
}


void InitVideoExample( void )
{
    AV_RESULT result;
    AV_SRC_FIELD video_source;
    
    blt_init();
    
    result = av_base_init( 12, 13 );
 
#ifdef _USE_LOOP_THROUGH_
    // uncomment this section for a direct loop through ---------------------
    
    av_init_input( _PF36, 0, false );
    
    while( AV_RESULT_OK != av_find_input( 1, &video_source, 
    	EXT_VIDEO_INPUTS, VIDEO_STANDARD ) );
    
    result = av_setup_output( 0, 0, g_pInputStd, false );
    
    output_matrix = malloc( AV_SIZEOF_TOTAL_FRAME( g_pInputStd ) );
    
    av_init_matrix( output_matrix, &output, g_pInputStd );
    
    result = av_open( 0, output_matrix, g_pInputStd, 1, 0, 0, 0, Handler_DirectLoop, 1 );
    result = av_open( 1, output_matrix, g_pInputStd, 1, 1, 0, 0, 0, 1 );
   
    // ----------------------------------------------------------------------
#endif
    

#ifdef _USE_OUTPUT_
    // uncomment this section to output a standard test screen
#ifdef _USE_TESTPIC_     
    extern char testpic_array [];
#else  
    // create a testscreen (red and blue stripes) ------------------
    char *test_pic_place = (char *)0x4;
    char *test_pic_buffer_start = test_pic_place;
    unsigned short lines;
    unsigned short xpos;
    unsigned short ypos;
    for (ypos=0; ypos<Y_RES; ypos+=16) {
        for (lines=0; lines<8; lines++) {
	    	for (xpos=0;xpos<720;xpos+=2) {
	    	    *test_pic_place=0xef;
	    	    test_pic_place++;
	    	    *test_pic_place=0x2d;
	    	    test_pic_place++;
	    	    *test_pic_place=0x67;
	    	    test_pic_place++;
	    	    *test_pic_place=0x2d;
	    	    test_pic_place++;
	    	}
        }
        for (lines=0; lines<8; lines++) {
	    	for (xpos=0;xpos<720;xpos+=2) {
	    	    *test_pic_place=0x5a;
	    	    test_pic_place++;
	    	    *test_pic_place=0x5c;
	    	    test_pic_place++;
	    	    *test_pic_place=0xf0;
	    	    test_pic_place++;
	    	    *test_pic_place=0x5c;
	    	    test_pic_place++;
	    	}
        }
    }
    // ------------------------------------------------------------    
#endif

    result = av_setup_output( 0, 0, VIDEO_STRUCT, false );
	
    output_matrix = malloc( AV_SIZEOF_TOTAL_FRAME( VIDEO_STRUCT ) );
    
    result = av_init_matrix( output_matrix, &output, VIDEO_STRUCT );
    
#ifdef _USE_TESTPIC_    
    testpic = blt_makeLinearSurface( testpic_array, 720, Y_RES );
#else    
    testpic = blt_makeLinearSurface( test_pic_buffer_start, 720, Y_RES );
#endif    
    
    blt( MDMA_CHANNEL, &testpic, &output, 0, 0, 0, 0, 720, Y_RES );
    
    result = av_open( 1, output_matrix, VIDEO_STRUCT, 1, 1, 0, 0, 0, 1 );
    // ----------------------------------------------------------------------
#endif

}


⌨️ 快捷键说明

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