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

📄 tmmp.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    MpInfo[instance].mpLineSize = (pictinfo->lineSize & 0xfff);
    MpInfo[instance].mpIQSel0   = pictinfo->IQSel0;
    MpInfo[instance].mpIQSel1   = pictinfo->IQSel1;
    if(_mpCurInstance == instance){
      mpSetPI(mp_pict_info_reg);
      mpSetPI0(mp_pict_info_mc);
      iqSetPI(iq_pic_info);
      if(pictinfo->halfResMode){
	mpSetIQ_SEL0(MpInfo[instance].mpIQSel0);
	mpSetIQ_SEL1(MpInfo[instance].mpIQSel1);
      }

      if ((((MMIO(TM32_BLOCK_ID)) >> DVP_MOD_ID_SHIFT) & DVP_MOD_ID_MASK) == TM3218_2B80_MOD_ID) 
	mpSetMMI_LINE_SIZE(VIPER_MMI_LINE_SIZE, pictinfo->lineSize & 0xfff);   
      else
	mpSetMMI_LINE_SIZE(MMI_LINE_SIZE, pictinfo->lineSize & 0xfff);

    }
    MPEXT(instance);
    return TMLIBDEV_OK;
}

/****************************************************************************
    tmLibdevErr_t mpSetSliceInfo(Int instance, UInt8 sliceCode, UInt8 quantScale)

    Setup slice row number and quant scale for MP
****************************************************************************/
extern tmLibdevErr_t 
mpSetSliceInfo(Int instance, UInt8 sliceCode, UInt8 quantScale)
{
  MPENT(instance);
  STD_ASSERTS(instance);

  MpInfo[instance].mpContext.quantScale = quantScale;

  if(_mpCurInstance == instance){
    /* strobe + start code;*/
    mpSetCTLSliceCode(sliceCode);
    mpSetQS(quantScale);
  }

  MPEXT(instance);

  return TMLIBDEV_OK;
  
}


/****************************************************************************
    tmLibdevErr_t mpGetValidLineSize(Int instance, Int Picture_Width)

    Get a valid mmi line size for specified picture width
****************************************************************************/
extern tmLibdevErr_t 
mpGetValidLineSize(Int instance, Int PictureWidth, UInt32 *LineSize)
{
  UInt32 i;

  
  MPENT(instance);
  STD_ASSERTS(instance);
  for(i=0; i < 10; i++){
    if(PictureWidth <= _valid_line_size[i]){
      *LineSize = _valid_line_size[i];
      MPEXT(instance);
      return TMLIBDEV_OK;
    }
  }
  MPEXT(instance);
  return MP_ERR_LINE_SIZE_TOO_LARGE;
}

/****************************************************************************
    tmLibdevErr_t mpReadMMIO(Int instance, UInt32 address, UInt32 *value)

    read given MMIO location
****************************************************************************/
extern tmLibdevErr_t 
mpReadMMIO(Int instance, UInt32 address, UInt32 *value)
{

  tmLibdevErr_t rval = TMLIBDEV_OK;
  MPENT(instance);
  STD_ASSERTS(instance);

  LOCK_MPEG_PIPE(instance);

  *value = mpGetMMIO(address - tmMPGlobalBase);  

  UNLOCK_MPEG_PIPE();
  MPEXT(instance);
  return rval;
}
/****************************************************************************
    tmLibdevErr_t mpFlushPipe(Int instance)

    Flushes all remaining macroblocks out of MP
****************************************************************************/
extern tmLibdevErr_t 
mpFlushPipe(Int instance)
{

  MPENT(instance);
  STD_ASSERTS(instance);
  tmAssert(_mpInterruptActive == 0, MP_ERR_INTERRUPT_LEVEL_CALL);

  LOCK_MPEG_PIPE(instance);
  MpInfo[instance].callBackStatus = TMMPCALLBACK_OK;

  mpSetIE(MP_VLD_MC_STATUS_ANY_ERROR | MP_VLD_IE_DONE_FLUSH);

  mpSetMC_COMMAND(MP_MC_COMMAND_FLUSH);
  MpInfo[_mpCurInstance].suspended = True;
  SUSPEND_SELF();
  
  mpSetIE(0);
  UNLOCK_MPEG_PIPE();
  MPEXT(instance);
  return (MpInfo[instance].callBackStatus == TMMPCALLBACK_OK ?
	  TMLIBDEV_OK: MP_ERR_CALLBACK_FAILED);

}

/****************************************************************************
    tmLibdevErr_t mpSetRefPtrs(Int instance, mpRefPtrs_t *ref)

    Set the MC reference pointers
****************************************************************************/
extern tmLibdevErr_t 
mpSetRefPtrs(Int instance, mpRefPtrs_t *ref )
{
  MPENT(instance);
  STD_ASSERTS(instance);
  tmAssert((( ((int) ref->lumaDestF0      & 0xf) == 0) &&
	    ( ((int) ref->lumaDestF1      & 0xf) == 0) && 
	    ( ((int) ref->chromaDestF0    & 0xf) == 0) &&
	    ( ((int) ref->chromaDestF1    & 0xf) == 0) &&
	    ( ((int) ref->lumaForwRefF0   & 0xf) == 0) &&
	    ( ((int) ref->lumaForwRefF1   & 0xf) == 0) &&
	    ( ((int) ref->chromaForwRefF0 & 0xf) == 0) &&
	    ( ((int) ref->chromaForwRefF1 & 0xf) == 0) &&
	    ( ((int) ref->lumaBackRefF0   & 0xf) == 0) &&
	    ( ((int) ref->lumaBackRefF1   & 0xf) == 0) &&
	    ( ((int) ref->chromaBackRefF0 & 0xf) == 0) &&
	    ( ((int) ref->chromaBackRefF0 & 0xf) == 0)), MP_ERR_UNALIGNED_FRAME_PTR);

  /*Record into global for later use */
  MpInfo[instance].MC_Info = *ref;
  
  if(_mpCurInstance == instance){
    mpSetMC_DESTY0( (UInt32) ref->lumaDestF0);
    mpSetMC_DESTUV0((UInt32) ref->chromaDestF0);
    mpSetMC_DESTY1( (UInt32) ref->lumaDestF1);
    mpSetMC_DESTUV1((UInt32) ref->chromaDestF1);
    mpSetMC_FREFY0( (UInt32) ref->lumaForwRefF0);
    mpSetMC_FREFUV0((UInt32) ref->chromaForwRefF0);
    mpSetMC_FREFY1( (UInt32) ref->lumaForwRefF1);
    mpSetMC_FREFUV1((UInt32) ref->chromaForwRefF1);
    mpSetMC_BREFY0( (UInt32) ref->lumaBackRefF0);
    mpSetMC_BREFUV0((UInt32) ref->chromaBackRefF0);
    mpSetMC_BREFY1( (UInt32) ref->lumaBackRefF1);
    mpSetMC_BREFUV1((UInt32) ref->chromaBackRefF1);
  }
  MPEXT(instance);
  return TMLIBDEV_OK;
}

/****************************************************************************
    tmLibdevErr_t mpErrorCon(Int instance,Int startRow, Int startCol, 
                                 Int endRow, Int endCol)

    Issues an error concealment command to MP.  The type of command issued
    depends on the value of endRow and endCol.  If both are 0 then error
    concealment 1 is issued.  If either are non-zero, then error concealment
    2 is issued.
****************************************************************************/
extern tmLibdevErr_t 
mpErrorCon(Int instance, Int startRow, Int startCol, Int endRow, Int endCol)
{
    UInt32 MBHeight,MBWidth;
    tmLibdevErr_t status=TMLIBDEV_OK;

    MPENT(instance);
    STD_ASSERTS(instance);
    MBHeight = mcExtractPI0_MB_HEIGHT(MpInfo[instance].mpMCPictInfo0);
    MBWidth  = mcExtractPI0_MB_WIDTH (MpInfo[instance].mpMCPictInfo0);
    DP(("Enter mpErrorCon %x %x %x %x %x\n",startRow,startCol,endRow,endCol,mpGetMC_COMMAND()));

    if (!(startRow >= 0 && startRow < MBHeight)) {
      status = MP_ERR_START_ROW_BOUND;
      goto localExit;
    }
    if (!(startCol >= 0 && startCol < MBWidth)){
      status = MP_ERR_START_COL_BOUND;
      goto localExit;
    }

    LOCK_MPEG_PIPE(instance);
    if((mpGetMC_COMMAND() & 7) || _mpErrorCon1Pending || _mpErrorCon2Pending ){
      UNLOCK_MPEG_PIPE();
      MPEXT(instance);
      return MP_ERR_ERROR_CON_PENDING;
    }
    MpInfo[instance].callBackStatus = TMMPCALLBACK_OK;

    mpSetSTATUS(MP_VLD_MC_STATUS_ERRCON_DONE);
    mpSetIE(MP_VLD_MC_STATUS_ERRCON_DONE | MP_VLD_MC_STATUS_ANY_ERROR);
    if((endRow == 0) && (endCol == 0)){

      /* ERROR CON 1 */
      DP(("Issue errorcon1 command %x \n",(startRow << 8) | startCol));
      _mpErrorCon2Pending = False;
      _mpErrorCon1Pending = True;
      mpSetMC_PICINFO2((startRow << 8) | startCol);
      mpSetMC_COMMAND(MP_MC_COMMAND_ERRCON1);
      /* dont release pipe until ERRCON1 Done */
      MPDBG(1,0,(startRow << 8) | startCol);
    }
    else{
      tmAssert(_mpInterruptActive == 0, MP_ERR_INTERRUPT_LEVEL_CALL);
      /* ERROR CON 2 */
      if (!(endRow >= startRow && endRow <= MBHeight)) {
	status = MP_ERR_END_ROW_BOUND;
        goto localExit;
      }

      if (endRow == MBHeight) {      
	if(endCol != 0){
	  status = MP_ERR_END_COL_BOUND;
	  goto localExit;
	}
      }
      else {
	if(endRow == startRow){
	  if (!(endCol >= startCol && endCol <= MBWidth)) {	     
	    status = MP_ERR_END_COL_BOUND;
	    goto localExit;
	  }
	}
	else {
	  if (endCol >= MBWidth) {
	    status  = MP_ERR_END_COL_BOUND;
	    goto localExit;
	  }
	}
      }	      
      DP(("Issue Error con 2 command %x\n",(endRow << 24) | (endCol << 16) | (startRow << 8) | startCol));
      _mpErrorCon1Pending = False;
      _mpErrorCon2Pending = True;
      
      mpSetMC_PICINFO2((endRow << 24) | (endCol << 16) | (startRow << 8) | startCol);
      MpInfo[_mpCurInstance].suspended = True;
      MpInfo[_mpCurInstance].aSyncPending = False;
      mpSetMC_COMMAND(MP_MC_COMMAND_ERRCON2);
      MPDBG(1,0,(endRow << 24) | (endCol << 16) | (startRow << 8) | startCol);

      SUSPEND_SELF();

      UNLOCK_MPEG_PIPE();
      MPEXT(instance);
      return (MpInfo[instance].callBackStatus == TMMPCALLBACK_OK ?
	  TMLIBDEV_OK: MP_ERR_CALLBACK_FAILED);
      }

 localExit:

    MPEXT(instance);
    return(status);
}
/****************************************************************************
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!INTERNAL ROUTINES ONLY BELOW THIS POINT!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
****************************************************************************/

/****************************************************************************
     void _mpISR(void)

    Standard MP ISR
****************************************************************************/

static void __mpISR(mpIsrInfo_t *isrEntry)
{
  unsigned status       = isrEntry->status;
  unsigned mp_imask     = isrEntry->imask;
  unsigned next_imask   = mp_imask & ~status;
  UInt32   next_command = 0;
  Bool     errorCondition = False;
  _mpInterruptActive ++;

  /* ack first s.t. new INT not missed */
  mpSetSTATUS((status & mp_imask) & ~(MP_VLD_MC_STATUS_SUCCESS));

  DP(("MPINTERRUPT: stat 0x%08x imask 0x%x bit cnt %u shift reg 0x%x  dma addr 0x%x dma cnt 0x%x\n",
      status,mp_imask,mpGetBIT_CNT(),mpGetSR_VALUE(),mpGetINP_ADR(),mpGetINP_CNT()));

  MPENT(_mpCurInstance); 

  /* VLD does not check for startcode alignement. Workaround here */
  if((((mp_imask & MP_VLD_MC_STATUS_STARTCODE) != 0) &
     ((status & MP_VLD_MC_STATUS_STARTCODE) != 0)) && (mpGetBIT_CNT() & 0x7)) {
    next_command = mpGetCOMMAND();
    DP(("Detected unaligned startcode cmd %x  \n",next_command));
    if (((next_command & 0xf00) == MP_VLD_COMMAND_PARSE) || ((next_command & 0xf00) == MP_VLD_COMMAND_PARSE_LINE)) {      
      /* We are parsing. Report error */
      next_command = 0;
      errorCondition = True;
    }
    else {
      if ((((next_command & 0xf00) == MP_VLD_COMMAND_GIVEN_START_CODE) || 
	  ((next_command & 0xf00) == MP_VLD_COMMAND_STARTCODE)) && (status  & MP_VLD_MC_STATUS_SUCCESS)) {
	/* We are searching for a startcode. Resume command */
	status = status & ~(MP_VLD_MC_STATUS_STARTCODE | MP_VLD_MC_STATUS_SUCCESS);
	next_imask = mp_imask | MP_VLD_MC_STATUS_DMA_IN_DONE | MP_VLD_MC_STATUS_SUCCESS;      
      }
      else {
	/* error case */
	DP(("Error: startcode int should not be raised\n"));
	next_command = 0;
	errorCondition = True;
      }
      mpSetSTATUS(MP_VLD_MC_STATUS_STARTCODE);
    }
  }
  /* End workaround */


  /* case 1 ERROR */
  if(((mp_imask & MP_VLD_MC_STATUS_ANY_ERROR) &&
     (status & MP_VLD_MC_STATUS_ANY_ERROR)) ||
     errorCondition) {

    MpInfo[_mpCurInstance].callBackStatus =
      (*MpInfo[_mpCurInstance].mpSetup.mpErrorFunc) (MpInfo[_mpCurInstance].mpSetup.parentID);
    _mpIntNotifyCaller();
    mp_imask = 0;
    
    if(_mpErrorCon1Pending == True || _mpErrorCon2Pending == True){
      DP(("ERRor x2 clearing errorCon Pending\n"));
      _mpErrorCon1Pending = False;
      _mpErrorCon2Pending = False;
    }
    mpSetIE(mp_imask);
  }  
  /* All non error cases are handled together */
  else {
  /* case 2 DMA INPUT DONE */    
    if(((mp_imask & MP_VLD_MC_STATUS_DMA_IN_DONE) != 0) &
       ((status & MP_VLD_MC_STATUS_DMA_IN_DONE) != 0)) {
      if(TMMPCALLBACK_OK != 
	 (MpInfo[_mpCurInstance].callBackStatus =
	  (*MpInfo[_mpCurInstance].mpContext.mpEmptyFunc) (MpInfo[_mpCurInstance].mpSetup.parentID))) {
	_mpIntNotifyCaller();
	mp_imask = 0;
	mpSetIE(mp_imask);
      }
      else{
	next_imask |= MP_VLD_IE_DMA_IN_DONE;
	mpSetIE(next_imask);
      }
    }

    /* case 3 SUCCESS and START CODE */
    /*        Indicates search for next startcode command (0x3) 
	      or search for given startcode command (0x6) success */
    if(((mp_imask & MP_VLD_MC_STATUS_SUCCESS) != 0) &
       ((status & MP_VLD_MC_STATUS_SUCCESS) != 0) &
       (!(status & MP_VLD_MC_STATUS_STARTCODE) |
	!(mp_imask & MP_VLD_MC_STATUS_STARTCODE))) {
      unsigned long row;

      if(status & MP_VLD_MC_STATUS_STARTCODE){
	mpSetSTATUS(MP_VLD_MC_STATUS_STARTCODE);
      }
      
      row = mpGetMC_STATUS_MB_ROW();
      if(row < MpInfo[_mpCurInstance].endRow){
	next_command = (MP_VLD_COMMAND_PARSE | (( MpInfo[_mpCurInstance].mpMCPictInfo0 & MP_MC_PI0_MB_WIDTH)));
	next_imask |= MP_VLD_MC_STATUS_SUCCESS;
      }
      else{
	MpInfo[_mpCurInstance].endRow = 0;
	MpInfo[_mpCurInstance].callBackStatus =
	 (*MpInfo[_mpCurInstance].mpSetup.mpSuccessFunc) (MpInfo[_mpCurInstance].mpSetup.parentID);
	_mpIntNotifyCaller();
	mp_imask = 0;
	mpSetIE(mp_imask);
      }
    }

    /* case 4 START CODE FOUND */
    /*        VLD found start code during parse */
    if(((mp_imask & MP_VLD_MC_STATUS_STARTCODE) != 0) &
       ((status & MP_VLD_MC_STATUS_STARTCODE) != 0)) {
      unsigned long code;

      code = (mpGetSR_VALUE() >> 8) & 0xff;
      /* Slice start code */
      if((code >= SLICE_START_CODE_MIN) & (code <= SLICE_START_CODE_MAX) &
	 (code < MpInfo[_mpCurInstance].endRow)) {
	mpSetIE(mpGetIE() | MP_VLD_MC_STATUS_DMA_IN_DONE);
	if(TMMPCALLBACK_OK != 
	   (MpInfo[_mpCurInstance].callBackStatus =
	    (*MpInfo[_mpCurInstance].mpSetup.mpSliceFunc) (MpInfo[_mpCurInstance].mpSetup.parentID))) {
	  MpInfo[_mpCurInstance].endRow = 0;
	  _mpIntNotifyCaller();
	  mp_imask = 0;
	  mpSetIE(mp_imask);
	}
	else{
	  next_imask |= MP_VLD_MC_STATUS_SUCCESS | MP_VLD_MC_STATUS_STARTCODE;
	  next_command = (MP_VLD_COMMAND_PARSE_LINE |  
			  ((MpInfo[_mpCurInstance].mpMCPictInfo0 & 0xff) + 1));
	}
      }
      /* Not a slice startcode was found */
      /* assume this is end of current picture or parse command,
       * flush the pipe  */      
      else { 
	if(MpInfo[_mpCurInstance].endRow != 0){

	  MpInfo[_mpCurInstance].endRow = 0;

	    DP(("MPINTERRUPT: issued MC command 0x%x set imask 0x%x %u\n",
		(MP_MC_COMMAND_FLUSH),(MP_VLD_MC_STATUS_FLUSH_DONE | MP_VLD_MC_STATUS_ANY_ERROR),CYCLES()));
	    
	    mpSetMC_COMMAND(MP_MC_COMMAND_FLUSH);

	    mpSetIE(MP_VLD_MC_STATUS_FLUSH_DONE | MP_VLD_MC_STATUS_ANY_ERROR);

	}
	/* NO parse has been issued (endRow == 0)*/
	else{
	  _mpIntNotifyCaller();
	  mp_imask = 0;
	  mpSetIE(mp_imask);
	}
      }
    }
    
    /* case 5 MC Flush command completion */
    if(((mp_imask & MP_VLD_MC_STATUS_FLUSH_DONE) != 0) & 
       ((status & MP_VLD_MC_STATUS_FLUSH_DONE) != 0)) {
      _mpIntNotifyCaller();
      mp_imask = 0;
      mpSetIE(mp_imask);
    }
    
    /* case

⌨️ 快捷键说明

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