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

📄 tmhpidemod_hpi.c

📁 卫星接收机器卫星 自动搜索, 包括优化处理
💻 C
📖 第 1 页 / 共 5 页
字号:
            pDemodCtx->DemodEvent_S.EventType = DEMOD_CARRIER_FOUND;
            
            // send the Front-End Event to the upper layer.
            pDemodCtx->pCarrierEvtCallback(&pDemodCtx->DemodEvent_S);

            break;
            
        case TMDL_FE_EVENT_CARRIER_LOST: 
            APP_DBG_PRINT_MSG(FE_DBG_HPI, FE_DBG_HPI_LEVEL, FE_DBG_HPI_CALLBACK_DLFE, FE_DBG_HPI_CB_DLFE_CARRIER_LOST, 0, 0);

            pDemodCtx->DemodEvent_S.EventType = DEMOD_CARRIER_LOST;

            // send the Front-End Event to the upper layer.
            pDemodCtx->pCarrierEvtCallback(&pDemodCtx->DemodEvent_S);

            break;
            
        case TMDL_FE_EVENT_END_OF_SEARCH:
            APP_DBG_PRINT_MSG(FE_DBG_HPI, FE_DBG_HPI_LEVEL, FE_DBG_HPI_CALLBACK_DLFE, FE_DBG_HPI_CB_DLFE_END_OF_SEARCH, 0, 0);
	    
	    // Testing if a scanning of Dual KU Band is taking place and if a second scan is needed.
	    // Testing of SwitchType is only a precaution: use of HPIv2_eDemodSatSwitchManual does not make sense for Dual KU band;
	    if ((pDemodCtx->DriverConfig_S.Specific.uDrvCfg.Sat.OlBand.BandType == HPIv2_eDemodSatDualBandKU)
                && (bChangeBand) && (pDemodCtx->DriverConfig_S.Specific.uDrvCfg.Sat.Switch.SwitchType != HPIv2_eDemodSatSwitchManual))
	    {      		  
		 // call front-end function
	     if (AutoScan)
		 {
		 	ErrorCode = tmdlFeStartAutoScan( pDemodCtx->dlFeInstance_U, (tmdlFeSearchConfig_t*) &(pDemodCtx->DualKUSearchConfig));
		 	DV_DBG_ASSERT(ErrorCode == TM_OK);
		 	bChangeBand = False;
		 }
		 else
		 {
		 	ErrorCode = tmdlFeStartScan( pDemodCtx->dlFeInstance_U, (tmdlFeSearchConfig_t*) &(pDemodCtx->DualKUSearchConfig));
		 	DV_DBG_ASSERT(ErrorCode == TM_OK);
			bChangeBand = False;
		 }
	    } 	
	    else
	    {	
            	 pDemodCtx->DemodEvent_S.EventType = DEMOD_END_OF_SEARCH;

            	 // send the Front-End Event to the upper layer.
            	 pDemodCtx->pChangeEvtCallback(&pDemodCtx->DemodEvent_S);
	    }
	    
            break;
            
        case TMDL_FE_EVENT_NO_CARRIER:
            APP_DBG_PRINT_MSG(FE_DBG_HPI, FE_DBG_HPI_LEVEL, FE_DBG_HPI_CALLBACK_DLFE, FE_DBG_HPI_CB_DLFE_CARRIER_NO_FOUND, 0, 0);

            pDemodCtx->DemodEvent_S.EventType = DEMOD_CARRIER_NONE;

            // send the Front-End Event to the upper layer.
            pDemodCtx->pCarrierEvtCallback(&pDemodCtx->DemodEvent_S);
            
            break;
          
        case TMDL_FE_EVENT_TUNE_FAILED:
            APP_DBG_PRINT_MSG(FE_DBG_HPI, FE_DBG_HPI_LEVEL, FE_DBG_HPI_CALLBACK_DLFE, FE_DBG_HPI_CB_DLFE_TUNE_FAILED, 0, 0);        
        
           pDemodCtx->DemodEvent_S.EventType = DEMOD_TUNE_FAILED;

            // send the Front-End Event to the upper layer.
            pDemodCtx->pCarrierEvtCallback(&pDemodCtx->DemodEvent_S);
            
            break;            
            
    }
    
    if (gtmhpiDemodStrCb.pfCarrierState != Null)
    {
        gtmhpiDemodStrCb.pfCarrierState (pDemodCtx->DemodEvent_S.EventType);
    }
 }


//-----------------------------------------------------------------------------
// Exported functions:
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// FUNCTION     : HPIv2_DemodOpen
//
// DESCRIPTION  : This function initializes the hardware & software functions
//                to the right media and return an instance for the other
//                devlib functions.
//
// RETURN       : HPIv2_tDEMOD_REPORT
//
// NOTES        : reentrant
//-----------------------------------------------------------------------------
HPIv2_tDEMOD_REPORT HPIv2_DemodOpen (	
                                            HPIv2_eDemodType			DemodType_E,
                                            HPIv2_uiDemodInstance*		pDemodInstance_U,
                                            HPIv2_DemodCarrierEventNotifyFn 	pCarrierFn,
                                            HPIv2_DemodChangeEventNotifyFn 	pChangeFn
                                       )
{
    Int32             timeOut_L = 1000;
    tmErrorCode_t     ErrorCode;
	
    // test input parameter
     if( pCarrierFn == NULL || pChangeFn == NULL)
     return HPIv2_eDEMOD_BAD_PARAMETER;
    
    // FA on the 31th of March => Access to the device library shall be protected
    // create the mutex to protect the access to the demodulator Device Library
    ErrorCode = tmosalMutexCreate(&DemodContext.DemodMutex_H, tmosalMutexCreateFlagNone);
    DV_DBG_ASSERT(ErrorCode == TM_OK);
    if (TM_OK != ErrorCode) return HPIv2_eDEMOD_COMMAND_FAILED;

    // take the mutex
    ErrorCode = tmosalMutexEnter(DemodContext.DemodMutex_H, &timeOut_L);
    DV_DBG_ASSERT(ErrorCode == TM_OK);
    if (ErrorCode != TM_OK)
        return HPIv2_eDEMOD_COMMAND_FAILED;
    
    // initialize the BSL
    ErrorCode = tmdlFeOpen(DemodType_E, &DemodContext.dlFeInstance_U);
    DV_DBG_ASSERT(ErrorCode == TM_OK);
    if (ErrorCode != TM_OK)
    {
        DemodContext.Instance_U = 0;
        DV_DBG_ASSERT(ErrorCode == TM_OK);
        return HPIv2_eDEMOD_COMMAND_FAILED;
    }

    // instance registration for the others functions.
    DemodContext.Instance_U = (tmdlFeInstance_t)(&DemodContext);  
    DemodContext.DemodType_E = DemodType_E;
    
    // callbacks registration
    DemodContext.pCarrierEvtCallback = pCarrierFn;
    DemodContext.pChangeEvtCallback = pChangeFn;
		
    // update instance with the address context
    *pDemodInstance_U = (HPIv2_uiDemodInstance)(&DemodContext);
		
    // set callback
    ErrorCode = tmdlFeRegisterCallback( DemodContext.dlFeInstance_U,
                                        (tmdlCallback_t*)tmDemodCallBackEventStatus,
                                        (UInt32)(&DemodContext));
    DV_DBG_ASSERT(ErrorCode == TM_OK);

    // set mask for callback
    ErrorCode = tmdlFeSetEventMask (  DemodContext.dlFeInstance_U,
                                      TMDL_FE_EVENT_CARRIER_TUNED |
                                      TMDL_FE_EVENT_CARRIER_FOUND |
                                      TMDL_FE_EVENT_CARRIER_LOST  |
                                      TMDL_FE_EVENT_END_OF_SEARCH |
                                      TMDL_FE_EVENT_NO_CARRIER |
                                      TMDL_FE_EVENT_TUNE_FAILED);
    DV_DBG_ASSERT(ErrorCode == TM_OK);


    // Verify if the HPIv2_DemodSetDriverConfig function has been called
    // for the HPIv2_DemodGetCapability function
    DemodContext.DriverCfgCall_F = False;

    // FA on the 31th of March => Access to the device library shall be protected
    // release the mutex
    ErrorCode = tmosalMutexExit(DemodContext.DemodMutex_H);
    DV_DBG_ASSERT(ErrorCode == TM_OK);
    
	return HPIv2_eDEMOD_OK;
}


//-----------------------------------------------------------------------------
// FUNCTION     : HPIv2_DemodClose
//
// DESCRIPTION  : This function is used to disconnect all the clients attached
//                to the demodulation.
//
// RETURN       : HPIv2_tDEMOD_REPORT
//
// NOTES        : reentrant
//-----------------------------------------------------------------------------
HPIv2_tDEMOD_REPORT HPIv2_DemodClose (HPIv2_uiDemodInstance   DemodInstance_U )
{
    tmErrorCode_t     ErrorCode;
	tmhpiDemodCtx_t*  pDemodCtx = (tmhpiDemodCtx_t*)DemodInstance_U;

    // test if initialized
    if ( DemodInstance_U != pDemodCtx->Instance_U )
        return HPIv2_eDEMOD_NOT_INITIALIZED;

    // close the front-end devlib
    ErrorCode = tmdlFeClose(pDemodCtx->dlFeInstance_U);
    DV_DBG_ASSERT(ErrorCode == TM_OK);

    // destroy the mutex
    ErrorCode = tmosalMutexDestroy(pDemodCtx->DemodMutex_H);
    DV_DBG_ASSERT(ErrorCode == TM_OK);

    // free memory
    pDemodCtx->Instance_U = 0;
    DV_DBG_ASSERT(ErrorCode == TM_OK);

    return HPIv2_eDEMOD_OK;
}


//-----------------------------------------------------------------------------
// FUNCTION     : HPIv2_DemodGetCapability
//
// DESCRIPTION  : This function returns the Hardware capability  issued from 
//                Hardware configuration.
//
// RETURN       : HPIv2_tDEMOD_REPORT
//
// NOTES        : reentrant
//-----------------------------------------------------------------------------
HPIv2_tDEMOD_REPORT HPIv2_DemodGetCapability(
                                                    HPIv2_uiDemodInstance   DemodInstance_U,
                                                    HPIv2_tDemodCapability* pDemodCapability_S
                                               )
{
    
    tmErrorCode_t           ErrorCode;
    Int32                   timeOut_L = 1000;
    tmhpiDemodCtx_t*        pDemodCtx = (tmhpiDemodCtx_t*)DemodInstance_U;
    tmdlFeInstanceSetup_t   FrontEndSetUp_S;
    Bool                    HwCfgModified_F = False;
    
    // test if initialized
    if ( DemodInstance_U != pDemodCtx->Instance_U )
        return HPIv2_eDEMOD_NOT_INITIALIZED;

    // take the mutex
    ErrorCode = tmosalMutexEnter(pDemodCtx->DemodMutex_H, &timeOut_L);
    DV_DBG_ASSERT(ErrorCode == TM_OK);
    if (ErrorCode != TM_OK)
        return HPIv2_eDEMOD_COMMAND_FAILED;

    // get the devlib instance setup especially, the demodulator name
    ErrorCode = tmdlFeGetInstanceSetup(pDemodCtx->dlFeInstance_U, &FrontEndSetUp_S);
    DV_DBG_ASSERT(ErrorCode == TM_OK);
    if (ErrorCode != TM_OK)
    {
        // release the mutex
        ErrorCode = tmosalMutexExit(pDemodCtx->DemodMutex_H);
        DV_DBG_ASSERT(ErrorCode == TM_OK);
        return HPIv2_eDEMOD_COMMAND_FAILED;
    }

    
    // Verify if the HPIv2_DemodSetDriverConfig function has been called.
    // if it is the case, then, Front-End type must be controlled.
    // If it is changed, then, the capabilities are taken regarding
    // the driver config and no more in the tmdlFecfg.h file.
    if ( 
    	    ( pDemodCtx->DriverCfgCall_F == True ) 
    	    &&
    	    (
    		( FrontEndSetUp_S.HwCfg_S.FeType_E != pDemodCtx->DemodType_E )
    		||
    		( 
    		    (pDemodCtx->DemodType_E == HPIv2_eDemodTerrestrial) 
    		    && 
    		    ( pDemodCtx->DriverConfig_S.Specific.uDrvCfg.Ter.Standard != TMDL_FE_CFG_STD_TER )
    		)
    	    )
       ) 
    	HwCfgModified_F = True;

    
    // Verify the soft/hard coherence.
    if ( 
            ( pDemodCtx->DriverCfgCall_F == False ) 
            &&
            ( FrontEndSetUp_S.HwCfg_S.FeType_E != pDemodCtx->DemodType_E )
       ) 
    {
        
        DV_DBG_PRINT("HPI FE: Error -> The Front-End type does not correspond to the default configuration.\n");
        DV_DBG_PRINT("HPI FE: The HPIv2_DemodSetDriverConfig function must be used to change the default configuration.\n");
        // release the mutex
        ErrorCode = tmosalMutexExit(pDemodCtx->DemodMutex_H);
        DV_DBG_ASSERT(ErrorCode == TM_OK);
        return HPIv2_eDEMOD_COMMAND_FAILED;
    }

        
    // If the default cfg is equal to the soft cfg
    if ( HwCfgModified_F == False )
    {
       pDemodCapability_S->DemodType = FrontEndSetUp_S.HwCfg_S.FeType_E;
    }
//     If the default cfg is dirent to the soft
    else
    {	    
    	pDemodCapability_S->DemodType = pDemodCtx->DemodType_E;
    }
    
    
    switch (pDemodCapability_S->DemodType)
    {
        case HPIv2_eDemodTerrestrial:

            pDemodCapability_S->TunerMinFrequency     = TMDL_FE_CFG_FREQ_TUNER_MIN_TER;
            pDemodCapability_S->TunerMaxFrequency     = TMDL_FE_CFG_FREQ_TUNER_MAX_TER;
            pDemodCapability_S->MinFSymb_BW           = TMDL_FE_CFG_FS_BW_MIN_TER;
            pDemodCapability_S->MaxFSymb_BW           = TMDL_FE_CFG_FS_BW_MAX_TER;
            pDemodCapability_S->NbOfConst             = TMDL_FE_CFG_NBOFCONST_TER;
            pDemodCapability_S->Const[0]              = HPIv2_eDemodConstellationAuto;
            pDemodCapability_S->Const[1]              = HPIv2_eDemodConstellationQpsk;
            pDemodCapability_S->Const[2]              = HPIv2_eDemodConstellationQam16;
            pDemodCapability_S->Const[3]              = HPIv2_eDemodConstellationQam64;            
            

⌨️ 快捷键说明

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