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.

tvp5158 save file problem

Other Parts Discussed in Thread: TVP5158

I use DM6764 and TVP5158 to capture the YUV data .and then save YUV date to a file. This is my code: 

#include <mcvip.h>

#include <fcntl.h>

#include <osa_cmem.h>

#include <sys/mman.h>

#include <sys/ioctl.h>

int SYS_init();

int CAPTURE_start();

int CAPTURE_loop();

void CAPTURE_stop();

void SYS_exit();

void *gMcvipHndl;

MCVIP_ChList gChInfo;

MCVIP_CreatePrm gCreatePrm;

int debug=0;

int SYSTEM_run()

{

         int status;

         status = SYS_init();

if(status != OSA_SOK)

                   printf("sys_init OK\n");

         else

                   printf("SYS_init fail!!!!\n");

         if(status==OSA_SOK)

         {

                   printf("capture start!! \n");

                   status = CAPTURE_start();

                   if(status==OSA_SOK)

                   {

                            printf("capture loop start!!!!\n");

                            status = CAPTURE_loop();

                            CAPTURE_stop();

                   }

                   else

                   {

                            printf("CAPTURE_start fail!!!!\n");

                   }

                   SYS_exit();

         }

         return status;

}

int SYS_init()

{

    int devAddr[4], status;

    // memory allocator init, needed by MCVIP

    status = CMEM_init();

    if(status == OSA_SOK)

        printf("cmem_init OK\n");

    else

        printf("cmem_init fail!!!!\n");

    // EDMA, I2C driver init

    // TVP5158 I2C device address

    devAddr[0] = 0xB0;

    devAddr[1] = 0xB8;

    devAddr[2] = 0xB0;

    devAddr[3] = 0xB8; // cascaded TVP5158, if present, else set to 0xFF

    status = MCVIP_init(devAddr, 1, 0);

    if(status == OSA_SOK)

        printf("mcvip_init OK\n");

    else

        printf("mcvip_init fail!!!!\n");

    return status;

}

int CAPTURE_start()

{

  Uint8 *virtAddr;

  int bufId;

  gCreatePrm.videoInputPort = MCVIP_VIDEO_INPUT_PORT_0;

  gCreatePrm.captureThrPri = MCVIP_CAPTURE_THR_PRI_HIGH;

  gCreatePrm.videoDecoderId = MCVIP_VIDEO_DECODER_ID_TVP5158;

  gCreatePrm.videoDecoderMode = MCVIP_VIDEO_DECODER_MODE_4CH_D1;

  gCreatePrm.videoIfMode = MCVIP_VIDEO_IF_MODE_BT656;

  gCreatePrm.videoSystem = MCVIP_VIDEO_SYSTEM_NTSC;

  gCreatePrm.numBuf = MCVIP_getNumCh(gCreatePrm.videoDecoderMode) * MCVIP_BUF_PER_CH_MIN;

  gCreatePrm.bufSize = MCVIP_getBufSize(gCreatePrm.videoDecoderMode, gCreatePrm.videoSystem);

  for(bufId=0; bufId<gCreatePrm.numBuf; bufId++)

  {

    virtAddr = OSA_cmemAlloc(gCreatePrm.bufSize, 32);

    gCreatePrm.bufVirtAddr[bufId] = virtAddr;

    gCreatePrm.bufPhysAddr[bufId] = OSA_cmemGetPhysAddr(virtAddr);

  }

  gMcvipHndl = MCVIP_create(&gCreatePrm);

  if(gMcvipHndl==NULL)

    return -1;

  MCVIP_getChList(gMcvipHndl, &gChInfo);

  MCVIP_start(gMcvipHndl);

  return 0;

}

int CAPTURE_loop()

{

         int bufId, status,chId,num=0;

         MCVIP_BufInfo *pBuf_YUV422;

         MCVIP_ChInfo *pChInfo;

         int filenum = 0;

         int nWidth,nHeight;

         //while(1)

         {

                   printf("MCVIP_getBuf\n");

                   status = MCVIP_getBuf(gMcvipHndl, &bufId, OSA_TIMEOUT_FOREVER);

                   if(status!=OSA_SOK || bufId < 0)

                            return -1;

                   pBuf_YUV422= MCVIP_getBufInfo(gMcvipHndl, bufId);

                   if(pBuf_YUV422== NULL)

                   {

                            printf("YUV422 buf is error!!\n");

                            return -1;

                   }

                   printf("YUV422 buf is ok!!\n");

                   /* process buffer pBuf

                   pBuf->chId is the channel to which this buffer belongs

                   pBuf->timestamp is buffer time stamp

                   pBuf->physAddr is the buffer physical address

                   pBuf->virtAddr is the buffer virtual address

                   */

                   /* channel info for this buffer is

                   gChInfo.info[pBuf->chId].width

                   gChInfo.info[pBuf->chId].height

                   gChInfo.info[pBuf->chId].offsetH

                   gChInfo.info[pBuf->chId].offsetV

                   */

                   if(pBuf_YUV422!= NULL)

                   {

                            chId = pBuf_YUV422->chId;

                   pChInfo = &gChInfo.info[pBuf_YUV422->chId];

                   nWidth = pChInfo->offsetH;

                   nHeight = pChInfo->offsetV;

                   int fileSize = nWidth * nHeight * 2;

                            //Save to file

                            char filename[255];

                            FILE *outfile;

                            //write to a file

                            sprintf(filename,"ch%d-n%03d-%c-%d-%d.YUV",chId,filenum++,'0'+bufId,pChInfo->offsetH,pChInfo->offsetV);

                            printf(filename);

                            outfile = fopen(filename,"wb");

                            if(outfile)

                            {

                                     fwrite(pBuf_YUV422->virtAddr,fileSize,1,outfile);

                            }

                            fclose(outfile);

                   }

                   MCVIP_putBuf(gMcvipHndl, bufId, MCVIP_FLAG_ALL_DONE);

         }

         return 0;

}

void CAPTURE_stop()

{

  int bufId;

  MCVIP_stop(gMcvipHndl);

  MCVIP_delete(gMcvipHndl);

  for(bufId=0; bufId<gCreatePrm.numBuf; bufId++)

    OSA_cmemFree(gCreatePrm.bufVirtAddr[bufId]);

}

void SYS_exit()

{

  MCVIP_exit();

  printf("MCVIP exit!!\n");

  CMEM_exit();

  printf("CMEM exit!!\n");

}

int main(int argc, char * * argv)

{

    printf("start!!!\n");

    int status;

    status = SYSTEM_run();

    if(status == OSA_SOK)

        printf("system OK\n");

    else

        printf("fail!!!!\n");

}

 

The problem is :I ruu this code ,the halt will happen.

This is debug information:

# ./save_test.out

start!!!

cmem_init OK

mcvip_init OK

SYS_init fail!!!!

capture start!!

vpif open, ***********************.

Configuring CPLD Register for HD

enabling External Clock

HD-Mode

setting std [0x4000000000]

 VPIF KERNEL: std_info->name TVP5158_NTSC_06

 VPIF KERNEL: vpif_config_params[channel_id][index].name TVP5158_NTSC_06, 728x1050

setting std [0x4000000000]

 VPIF KERNEL: std_info->name TVP5158_NTSC_06

 VPIF KERNEL: vpif_config_params[channel_id][index].name TVP5158_NTSC_06, 728x1050

setting std [0x100000000000]

 VPIF KERNEL: std_info->name TVP5158_NTSC_12

 VPIF KERNEL: vpif_config_params[channel_id][index].name TVP5158_NTSC_12, 728x2100

 MCVIP: TVP5158 init in progress for stage 0

Patch is already running.

 MCVIP: TVP5158 init done !!!

capture loop start!!!!

MCVIP_getBuf

YUV422 buf is ok!!

 

Can TI engineer tell me to how to solve it?