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

📄 mt_userdef.c

📁 用于DRX3973或DRX39系列的芯片的控制
💻 C
字号:
/**
* \file $Id: mt_userdef.c,v 1.11 2005/10/18 16:38:15 paulja Exp $
*
* \brief MicroTuner software interface for Micronas DRX driver
*
* \author Jasper Schrader
*
* This file is based on a template provided by Microtune and has been adapted to
* the requirements for the DRX driver. This file is distributed with approval of
* Microtune but further MicroTuner driver files must be obtained from Microtune.
*
* $(c) 2005 Micronas GmbH. All rights reserved.
*
* This software and related documentation (the 'Software') are intellectual
* property owned by Micronas and are copyright of Micronas, unless specifically
* noted otherwise.
*
* Any use of the Software is permitted only pursuant to the terms of the
* license agreement, if any, which accompanies, is included with or applicable
* to the Software ('License Agreement') or upon express written consent of
* Micronas. Any copying, reproduction or redistribution of the Software in
* whole or in part by any means not in accordance with the License Agreement
* or as agreed in writing by Micronas is expressly prohibited.
*
* THE SOFTWARE IS WARRANTED, IF AT ALL, ONLY ACCORDING TO THE TERMS OF THE
* LICENSE AGREEMENT. EXCEPT AS WARRANTED IN THE LICENSE AGREEMENT THE SOFTWARE
* IS DELIVERED 'AS IS' AND MICRONAS HEREBY DISCLAIMS ALL WARRANTIES AND
* CONDITIONS WITH REGARD TO THE SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIT
* ENJOYMENT, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL
* PROPERTY OR OTHER RIGHTS WHICH MAY RESULT FROM THE USE OR THE INABILITY
* TO USE THE SOFTWARE.
*
* IN NO EVENT SHALL MICRONAS BE LIABLE FOR INDIRECT, INCIDENTAL, CONSEQUENTIAL,
* PUNITIVE, SPECIAL OR OTHER DAMAGES WHATSOEVER INCLUDING WITHOUT LIMITATION,
* DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
* INFORMATION, AND THE LIKE, ARISING OUT OF OR RELATING TO THE USE OF OR THE
* INABILITY TO USE THE SOFTWARE, EVEN IF MICRONAS HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES, EXCEPT PERSONAL INJURY OR DEATH RESULTING FROM
* MICRONAS' NEGLIGENCE.                                                        $
*
*/

/*****************************************************************************
**
**  Name: MT_UserDef.h
**
**  Description:    User-defined MicroTuner software interface
**
**  Functions
**  Requiring
**  Implementation: MT_WriteSub
**                  MT_ReadSub
**                  MT_Sleep
**
**  References:     None
**
**  Exports:        None
**
**
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   03-25-2004    DAD    Original
**
*****************************************************************************/
#include "mt_userdef.h"
#include "drx_driver.h"

/*****************************************************************************
**
**  Name: MT_WriteSub
**
**  Description:    Write values to device using a two-wire serial bus.
**
**  Parameters:     hUserData  - User-specific I/O parameter that was
**                               passed to tuner's Open function.
**                  addr       - device serial bus address  (value passed
**                               as parameter to MT2121_Open)
**                  subAddress - serial bus sub-address (Register Address)
**                  pData      - pointer to the Data to be written to the
**                               device
**                  cnt        - number of bytes/registers to be written
**
**  Returns:        status:
**                      MT_OK            - No errors
**                      MT_COMM_ERR      - Serial bus communications error
**                      user-defined
**
**  Notes:          This is a callback function that is called from the
**                  the tuning algorithm.  You MUST provide code for this
**                  function to write data using the tuner's 2-wire serial
**                  bus.
**
**                  The hUserData parameter is a user-specific argument.
**                  If additional arguments are needed for the user's
**                  serial bus read/write functions, this argument can be
**                  used to supply the necessary information.
**                  The hUserData parameter is initialized in the tuner's Open
**                  function.
**
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   03-25-2004    DAD    Original
**
*****************************************************************************/
UData_t MT_WriteSub(Handle_t hUserData,
                    UData_t addr,
                    U8Data subAddress,
                    U8Data *pData,
                    UData_t cnt)
{
   UData_t status = MT_OK;                  /* Status to be returned        */

    /*
    **  ToDo:  Add code here to implement a serial-bus write
    **         operation to the MTxxxx tuner.  If successful,
    **         return MT_OK.
    */
   I2CDeviceAddr_t devAddr = { (u16_t) (0xffff & addr), 1};
   u8_t            *wData;
   u16_t           i, wCnt;
   pTUNERInstance_t tuner=NULL;

   /* construct telegram */
   wCnt  = (u16_t) ( 0xffff & (cnt + 1) );
   wData = DRXBSP_HST_Malloc(wCnt * sizeof(u8_t));
   wData[0] = subAddress;
   for (i = 1; i<wCnt; i++)
   {
      wData[i] = pData[i-1];
   }

   /* send telegram */
   tuner = ((pTUNERInstance_t) hUserData);
   if (tuner->myFunct->i2cWriteReadFunc( tuner, &devAddr, wCnt, wData, NULL, 0, NULL ) != DRX_STS_OK)
   {
     status = MT_COMM_ERR;
   }

   /* release telegram */
   DRXBSP_HST_Free(wData);

   return status;
}


/*****************************************************************************
**
**  Name: MT_ReadSub
**
**  Description:    Read values from device using a two-wire serial bus.
**
**  Parameters:     hUserData  - User-specific I/O parameter that was
**                               passed to tuner's Open function.
**                  addr       - device serial bus address  (value passed
**                               as parameter to MT2121_Open)
**                  subAddress - serial bus sub-address (Register Address)
**                  pData      - pointer to the Data to be written to the
**                               device
**                  cnt        - number of bytes/registers to be written
**
**  Returns:        status:
**                      MT_OK            - No errors
**                      MT_COMM_ERR      - Serial bus communications error
**                      user-defined
**
**  Notes:          This is a callback function that is called from the
**                  the tuning algorithm.  You MUST provide code for this
**                  function to read data using the tuner's 2-wire serial
**                  bus.
**
**                  The hUserData parameter is a user-specific argument.
**                  If additional arguments are needed for the user's
**                  serial bus read/write functions, this argument can be
**                  used to supply the necessary information.
**                  The hUserData parameter is initialized in the tuner's Open
**                  function.
**
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   03-25-2004    DAD    Original
**
*****************************************************************************/
UData_t MT_ReadSub(Handle_t hUserData,
                   UData_t addr,
                   U8Data subAddress,
                   U8Data *pData,
                   UData_t cnt)
{
    UData_t status = MT_OK;                        /* Status to be returned        */

    /*
    **  ToDo:  Add code here to implement a serial-bus read
    **         operation to the MTxxxx tuner.  If successful,
    **         return MT_OK.
    */
   I2CDeviceAddr_t devAddr = { (u16_t) (0xffff & addr), 1};
   u8_t            wData[] = {subAddress};
   pTUNERInstance_t tuner=NULL;

   /* send telegram */
   tuner = ((pTUNERInstance_t) hUserData);
   if (tuner->myFunct->i2cWriteReadFunc( tuner, &devAddr, 1, wData, &devAddr, (u16_t) (0xffff & cnt), pData ) != DRX_STS_OK)
   {
     status = MT_COMM_ERR;
   }

   return status;
}


/*****************************************************************************
**
**  Name: MT_Sleep
**
**  Description:    Delay execution for "nMinDelayTime" milliseconds
**
**  Parameters:     hUserData     - User-specific I/O parameter that was
**                                  passed to tuner's Open function.
**                  nMinDelayTime - Delay time in milliseconds
**
**  Returns:        None.
**
**  Notes:          This is a callback function that is called from the
**                  the tuning algorithm.  You MUST provide code that
**                  blocks execution for the specified period of time.
**
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   03-25-2004    DAD    Original
**
*****************************************************************************/
void MT_Sleep(Handle_t hUserData,
              UData_t nMinDelayTime)
{
    /*
    **  ToDo:  Add code here to implement a OS blocking
    **         for a period of "nMinDelayTime" milliseconds.
    */
    u32_t startTime  = DRXBSP_HST_Clock();
    u32_t timePassed = 0;

    do{ timePassed = (DRXBSP_HST_Clock() - startTime); }while( timePassed < nMinDelayTime);
}


/*****************************************************************************
**
**  Name: MT_TunerGain  (MT2060 only)
**
**  Description:    Measure the relative tuner gain using the demodulator
**
**  Parameters:     hUserData  - User-specific I/O parameter that was
**                               passed to tuner's Open function.
**                  pMeas      - Tuner gain (1/100 of dB scale).
**                               ie. 1234 = 12.34 (dB)
**
**  Returns:        status:
**                      MT_OK  - No errors
**                      user-defined errors could be set
**
**  Notes:          This is a callback function that is called from the
**                  the 1st IF location routine.  You MUST provide
**                  code that measures the relative tuner gain in a dB
**                  (not linear) scale.  The return value is an integer
**                  value scaled to 1/100 of a dB.
**
**  Revision History:
**
**   SCR      Date      Author  Description
**  -------------------------------------------------------------------------
**   N/A   06-16-2004    DAD    Original
**   N/A   11-30-2004    DAD    Renamed from MT_DemodInputPower.  This name
**                              better describes what this function does.
**
*****************************************************************************/
UData_t MT_TunerGain(Handle_t hUserData,
                     SData_t* pMeas)
{
    u16_t   val    = 0;
    pDRXDemodInstance_t demod;

    /* Clear output value */
    *pMeas = 0;

    /* If demod is not accessible, return error */
    if ( (hUserData) == NULL)
    {
        return MT_ERROR;
    }

    /* If demod is accessible, return mapped signal strength */
    MT_Sleep(hUserData, 20); /* give the system 20 msec to settle */
    demod = (pDRXDemodInstance_t) ( ((pTUNERInstance_t) hUserData)-> myCommonAttr -> myUserData  );
    if( DRX_Ctrl( demod,  DRX_CTRL_SIG_STRENGTH, &val ) != DRX_STS_OK )
    {
        return MT_ERROR;
    }

    *pMeas = 4 * val; /* approx. (100 * 40 dB /1023) * SigStrength */

    return MT_OK;
}

#ifdef USE_DUMMY_MT2060

/*****************************************************************************
**
**  Dummy interface implementation needed to compile WITHOUT Microtune
**  source files.
**
*****************************************************************************/

UData_t MT2060_Open(UData_t MT2060_Addr,
                    Handle_t* hMT2060,
                    Handle_t hUserData)
{
   return (MT_COMM_ERR);
}

UData_t MT2060_SetGainRange(Handle_t h, UData_t range)
{
   return (MT_COMM_ERR);
}

UData_t MT2060_SetParam(Handle_t     h,
                        MT2060_Param param,
                        UData_t      nValue)
{
   return (MT_COMM_ERR);
}

UData_t MT2060_Close(Handle_t hMT2060)
{
   return (MT_COMM_ERR);
}


UData_t MT2060_ChangeFreq(Handle_t h,
                          UData_t f_in,
                          UData_t f_IF1,
                          UData_t f_out,
                          UData_t f_IFBW)
{
   return (MT_COMM_ERR);
}


UData_t MT2060_GetLocked(Handle_t h)
{
   return (MT_COMM_ERR);
}


#endif /* #if USE_DUMMY_MT2060 */

⌨️ 快捷键说明

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