This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

how to make VICP work

I have few questions about VICP. I have modified the example code from “VisionMid_embeddedVisionFramework” and put it in the code run in vpss_m3.

My question is why the control never come back once I call “CPIS_sobel” no matter I use CPIS_SYNC or CPIS_ASYNC mode. It seems the code is still waiting the result from the VICP hardware.

TMS320DM814x is the chip I used and CCS5 is my environment.


The following code is the way I active VICP.

Thanks

/*******************************************************************************
 *                                                                             *
 * Copyright (c) 2011 Texas Instruments Incorporated - http://www.ti.com/      *
 *                        ALL RIGHTS RESERVED                                  *
 *                                                                             *
 ******************************************************************************/

/*
 *   @file  dei.c
 *
 *   @brief	Deinterlace module
 *
 *   @brief
 */

#include <ti/sysbios/BIOS.h>

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include <xdc/std.h>
#include <xdc/runtime/System.h>

#include "error_codes.h"
#include "common_defs.h"
#include "dei.h"
#include "ioutil.h"


#include "platform_support.h"
// VICP header files
#include <tistdtypes.h>     // at VICP '/inc' folder
#include <cpisCore.h>       // at VICP '/inc' folder
#include <cpisImgproc.h>    // at VICP '/inc' folder, basic VICP API
#include <cpisVision.h>     // at VICP '/inc' folder, vision related VICP API

///////////////////////////add by ancre /////////////////////
/* Local defines for the test file */
#define BLOCK_WIDTH 16
#define BLOCK_HEIGHT 16

#define NUM_BLOCK_HORIZ 2
#define NUM_BLOCK_VERT  2

#define WIDTH (BLOCK_WIDTH*NUM_BLOCK_HORIZ)
#define HEIGHT (BLOCK_HEIGHT*NUM_BLOCK_VERT)

/* Global pointers used by the test application */
char *SRC;
char *DST;
char *DST_X;
char *DST_Y;
//char *COEFF;
char *REF_DST;
char *REF_DST_X;
char *REF_DST_Y;

/* 
    Flag used to synchronize between the test applicaton and the VICP 
    VICP signals the completion of requested procesisng by driving the 
    CPU interrupt. In this example code, the ISR only sets the below flag. 
    The flag is polled by the example code to check for the completion.
    In actual application, user can chose to drive Semaphores in the ISR.
*/

/* Set the flag to 0 to start with */
volatile Uint16 VICPIntFlag = 0;
/* 
    The below fxn is used as VICP ISR. 
    This is configured using the ECM module in the test code 
*/
void CPIS_isr() {
    VICPIntFlag= 1;
}

/* 
    The VICP Lib API CPIS_wait allows the user to specify a wait function.
    In the below wait function used by the example code, we only pole for VICPIntFlag.
    In actual application, this should be replaced with Semaphore. 
*/
Int32 CPIS_wait_Fxn(void *arg) {
    /* Wait callback function that ensures the VICP procesing is done 
     * Current approach is to busy wait for the flag VICPIntFlag to be set
     * by the interrupt service routine CPIS_isr().
     * Better way is to use semaphore instead of flag.
     * In Linux environment, the wait is efficiently handled by the library itself so
     * the function can be left empty.  
     */ 
#if !( defined(LINUX) || defined(_DEBUG_VICP) || defined (_BIOS))
    while (VICPIntFlag==0);
        VICPIntFlag= 0;
#endif
    return 0;

}

static void Mem2File(char *filename, UINT8 *buf, int size)
{
    FILE *pf;
	int i=0;
    pf = fopen (filename,"w");
    if (NULL == pf) {
        printf("can not create file %s.\n", filename);
        return;
    }
	for(i=0;i<size;i++){
		if(WIDTH % i == 1){
			fprintf (pf,"%d\n", buf[i]);
		}else{
			fprintf (pf,"%d\n", buf[i]);
		}
	}
    fclose(pf);
}
int sobel(void){
	/* Parameter structures required to interface with the lib */
    CPIS_Init vicpInit;
    CPIS_BaseParms base;
    CPIS_BaseParms baseRef;
    // CPIS_filterParms params;
    CPIS_SobelParms params;
    CPIS_Handle handle;

    /* Local variables */
    Int32 i, errorFlag;
    Int32 retVal;
    Uint16 dstSize;
	
    unsigned long setupTimerDiff, resetTimerDiff, execTimerDiff;
    unsigned long timerStart, timerEnd;
    memInit();
    timerInit();
    /* Allocate the memory needed for the buffers */
    if ((SRC = (char*)memAlloc( 2*WIDTH*HEIGHT + 2*4*WIDTH*HEIGHT))==NULL){
        printf("Error allocating SRC\n");
        exit(-1);
    }
    
    DST= SRC + 2*WIDTH*HEIGHT;
    DST_X= DST;
    DST_Y= DST_X + 2*WIDTH*HEIGHT;
    REF_DST= DST + 4*WIDTH*HEIGHT;
    REF_DST_X= REF_DST;
    REF_DST_Y= REF_DST_X + 2*WIDTH*HEIGHT;


    /* Set up the ISR for the VICP, function defined in platform_supportXXXX.c */
    intSetup(CPIS_isr);
    /* Enable interrupt for the VICP, function defined in platform_supportXXXX.c */
    intEnable();

    /* Initialize the library */
    vicpInit.cacheWbInv = (CacheWbInv) cacheWb;
    vicpInit.staticDmaAlloc= 1;
    vicpInit.maxNumDma= CPIS_MAX_CHANNELS;
    vicpInit.maxNumProcFunc= 1;
    vicpInit.memSize= CPIS_getMemSize(vicpInit.maxNumProcFunc);
    vicpInit.mem= memAlloc(vicpInit.memSize);

    /* 
    In this test, we don't need to lock/unlock VICP usage 
    but if there are other software components in the system using VICP HW,
    then need to implement lock/unlock through semaphore function
    */
    vicpInit.lock= NULL; 
    vicpInit.unlock= NULL;
		
	// vicpInit.lock= &Semaphore_pend;
	// vicpInit.lockArg= Semaphore_handle; /* created by Semaphore_create() */
	// vicpInit.unlock= &Semaphore_post;
	// vicpInit.unlockArg= Semaphore_handle;
	
    /*
    On DM365, this member initFC is used to tell the VICP library
    if it should also initialize components related
    to the framework components: IRES manager, codec engine.
    Setting it to CPIS_INIT_FC_NONE means that VICP lib doesn't do any FC related initialization.
    The application may need to do it itself. 
    Setting it to CPIS_INIT_FC_ALL means that VICP lib does all the FC related initialization.
    Selective initializaiton is possible by setting corresponding bits. See 
    description of CPIS_Init in header file or documentation,
    */

    if (CPIS_init(&vicpInit)== -1) {
        printf("\nCPIS_init error\n");
        exit(-1);
    };

    

    /* Initialize the call back function that the library will use to synchronize */
    //CPIS_setWaitCB(&CPIS_wait_Fxn, NULL);


    base.srcFormat[0] = CPIS_U8BIT;
    base.dstFormat[0] = CPIS_8BIT;
    params.separateXYplanes = TRUE;
    params.sat_high = 127;
    params.sat_high_set = 127;
    params.sat_low = -128;
    params.sat_low_set = -128;
    params.qShift = 3;
 
	/* 
	Initialize the remianing fields of the base params and the 
	module parameter structure
	*/
	base.srcBuf[0].ptr= (Uint8*)SRC;
	base.srcBuf[0].stride= WIDTH + (3 - 1);

	/* On Centaurus platform, we need to round stride to next multiple of 16 bytes
	 * No need to do this on DMVA platform
	 * */
	if (CPIS_sizeof(base.srcFormat[0])== 1){
		base.srcBuf[0].stride= (base.srcBuf[0].stride + 15) & ~15; // 8-bit case
	}else{
		base.srcBuf[0].stride= (base.srcBuf[0].stride + 7) & ~7; // 16-bit case
	}
	
	if (params.separateXYplanes== FALSE) {
		base.dstBuf[0].ptr= (Uint8*)DST;
		base.dstBuf[0].stride= WIDTH;
	}else {
		base.dstFormat[1]= base.dstFormat[0];
		base.dstBuf[0].ptr= (Uint8*)DST_X;
		base.dstBuf[0].stride= WIDTH;
		base.dstBuf[1].ptr= (Uint8*)DST_Y;
		base.dstBuf[1].stride= WIDTH;
	}

	// params.coeffPtr= (Int16 *)COEFF; 

	base.roiSize.width= WIDTH;
	base.roiSize.height= HEIGHT;
	base.procBlockSize.width= 0;//BLOCK_WIDTH;
	base.procBlockSize.height= 0;//BLOCK_HEIGHT;

	/* Fill input with random data; Fill Coeff with random data */
	/* Zero out dest buffer.  */
	for (i=0;i<2*2*WIDTH*HEIGHT;i++){
		*(base.srcBuf[0].ptr+i)= rand(); // 100*(i%3); // (i==0); // (i%3); // (3 + ((-i)%3))%3; // rand(); //
	}

	dstSize= CPIS_sizeof(base.dstFormat[0]);

	if (params.separateXYplanes== FALSE) {
		for (i=0;i<2*dstSize*WIDTH*HEIGHT;i++){
			*(base.dstBuf[0].ptr+i)= 0;
		}
	}else {
		for (i=0;i<dstSize*WIDTH*HEIGHT;i++){
			*(base.dstBuf[0].ptr+i)= 0;
		}
		for (i=0;i<dstSize*WIDTH*HEIGHT;i++){
			*(base.dstBuf[1].ptr+i)= 0;
		}
	}

	/* Clear the cache */
	cacheWbInvAll ();

	/* Benchmark the setup time */
	timerStart= timerReadStart (); 

	/* 
		Call the module in asynchronous mode. This means only setup of 
		hardware is done. Execution will have to be triggered by CPIS_start
	*/
	// if (CPIS_filter(
	if (CPIS_sobel(
		&handle,
		&base,
		&params,
		CPIS_SYNC	//CPIS_SYNC
		)== -1) {
		printf("\nCPIS_sobel() error %d\n", CPIS_errno);
		exit(-1);
	};
	timerEnd= timerReadEnd ();
	setupTimerDiff= timerEnd-timerStart;

	/* Benchmark the actual processing */
	timerStart= timerReadStart ();

	/* Trigger the start of processing */
	//CPIS_start(handle);
	//CPIS_wait(handle);
	

	timerEnd= timerReadEnd ();
	execTimerDiff= timerEnd-timerStart;
	
	Mem2File("src.txt",SRC,WIDTH*HEIGHT);
	Mem2File("X.txt",DST_X,WIDTH*HEIGHT);
	Mem2File("Y.txt",DST_Y,WIDTH*HEIGHT);
	CPIS_reset(handle);
	
	/* Delete the function and its associated set of parameters once done */
	CPIS_delete(handle);
	/* Clear the cache */
	cacheWbInvAll ();
	
	/* Close the module and free the resources */
    CPIS_deInit();
    intDisable();

    memFree(SRC, 0);
	return 0;
}
///////////////////////////add by ancre /////////////////////
/*end dei.c*/