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

📄 example_full.c

📁 用于DRX3973或DRX39系列的芯片的控制
💻 C
📖 第 1 页 / 共 2 页
字号:
/**
* \file $Id: example_full.c,v 1.16 2005/11/29 16:24:03 jasper Exp $
*
* \brief example of a application with extensive usage of the drxdriver
*
* \author Jasper Schrader
*
*
* $(c) 2004-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.                                                        $
*
*/

/*-----------------------------------------------------------------------------
INCLUDES
------------------------------------------------------------------------------*/

/* application include */
#include "example_aux.c.inc"  /* for logging text output */

/* driver includes */
#include "drx3973d.h"      /* drx397xd specific drxdriver include    */
#include "drx3973d_mc.h"   /* file containg the microcode (firmware) */


/*-----------------------------------------------------------------------------
DEFINES
------------------------------------------------------------------------------*/

#define DESIRED_FREQUENCY  578000              /* center freq. [kHz] of desired channel */
#define DESIRED_BANDWIDTH  DRX_BANDWIDTH_8MHZ  /* bandwidth of desired channel          */
#define LOCK_TIMEOUT_ANY      700              /* timeout [msec] for 'any type of lock' */
#define LOCK_TIMEOUT_MPEG    3000              /* timeout [msec] for MPEG lock          */

/* signal quality display options */
#define SHOW_SIGNAL_QUALITY_AS_FLOATS     1    /* set to 1 for floating-point display  */
#define SHOW_SIGNAL_QUALITY_AS_INTEGERS   1    /* set to 1 for integer display         */
#define SHOW_SIGNAL_QUALITY_AS_INDICATORS 1    /* set to 1 for 'OSD-indicator' display */

#if (SHOW_SIGNAL_QUALITY_AS_FLOATS)
#include <math.h>
#endif


/*------------------------------------------------------------------------------
TUNER SELECTION
------------------------------------------------------------------------------*/

/* using pre-configured tuner */
#define  TUNER_THOMSON_DTT_759X
#include "bsp_tuner_tables.h"


/*------------------------------------------------------------------------------
VARABLES
------------------------------------------------------------------------------*/

/* declare demod instance */
static I2CDeviceAddr_t     demodAddr;
static DRXCommonAttr_t     demodCommAttr;
static DRXDemodInstance_t  demod;

/* declare list for one demod instance */
static pDRXDemodInstance_t demodulators[] = { NULL, NULL };


/*------------------------------------------------------------------------------
MAIN APPLICATION
------------------------------------------------------------------------------*/
/*  This example application steps through the following phases:

    (1) Customize demodulator attributes
    (2) Initialize system and open demodulator
    (3) Configure hardware dependent settings 
    (4) Program channel and wait for lock
    (5) Retrieve channel parameters
    (6) Show signal quality and strength
    (7) Terminate system
*/

int main ( void )
{
   /* declare local variables */
   DRXLockStatus_t   lockStatus;        /* used in step (4)       */
   u32_t             start, delta;      /* used in step (4)       */
   Bool_t            everLocked;        /* used in step (4)       */
   DRXChannel_t      channelParams;     /* used in step (4) & (5) */
   DRXTPSInfo_t      TPSInfo;           /* used in step (5)       */
   DRXSigQuality_t   sigQuality;        /* used in step (6)       */
   u16_t             sigStrength;       /* used in step (6)       */
   pDRXVersionList_t versionList = NULL;


   /*-----------------------------------------------------------------------*/
   /* (1) Customize demodulator attributes                                  */
   /*-----------------------------------------------------------------------*/

   /* prepare demod data structure; start with default values */
   demodAddr       = DRX3973DDefaultAddr_g;
   demodCommAttr   = DRX3973DDefaultCommAttr_g;
   demod           = DRX3973DDefaultDemod_g;

   /* connect datastructures through pointers */
   demod.myI2CDevAddr            = &demodAddr;       /* connect address and ID to demod data structure          */
   demod.myCommonAttr            = &demodCommAttr;   /* connect common attributes to demod data structure       */
   demod.myTuner                 = &PRE_CONF_TUNER;  /* connect pre-configured tuner to demod data structure    */
   demodulators[0]               = &demod;           /* add demod to list of demodulators                       */

   /* assign firmware attributes */
   demodCommAttr.microcode       = MC_IMAGE_ADDR;   /* pointer to array containing firmware                     */
   demodCommAttr.microcodeSize   = MC_IMAGE_SIZE;   /* size of the firmware image                               */

   /* modify device address and ID */
   demodAddr.i2cAddr             = 0xE0;            /* i2c address                                              */
   demodAddr.i2cDevId            = 1;               /* device ID                                                */

   /* set clock attributes */
   demodCommAttr.sysClockFreq    = 48000;           /* system clock frequency in kHz                            */
   demodCommAttr.oscClockFreq    = 20000;           /* oscillator/crystal frequency kHz                         */

   /* set tuner i2c bus connection */
   demodCommAttr.tunerPortNr     = 1;               /* 0 = tuner on main i2c bus, 1 = tuner behind i2c bridge   */
                                                    /* NOTE: only the XCeive XC3028 uses portNr = 0             */   

   /* modify MPEG output attributes */
   demodCommAttr.enableMPEGOutput = TRUE;           /* switch to enable MPEG out                                */
   demodCommAttr.insertRSByte     = FALSE;          /* switch to insert RS byte into MPEG-TS                    */
   demodCommAttr.enableParallel   = TRUE;           /* select parallel (TRUE) or serial (FALSE) output          */


   /*-----------------------------------------------------------------------*/
   /* (2) Initialize system and open demodulator                            */
   /*-----------------------------------------------------------------------*/

   /* enable I2C communication */
   if( DRXBSP_I2C_Init() != DRX_STS_OK )
   {
      XERROR( "failure: error initializing i2c\n" );
   }
   XPRINTF("success: I2C initialized\n");

   /* initialize host bsp module */
   if( DRXBSP_HST_Init() != DRX_STS_OK )
   {
      XERROR("failure: error initializing host bsp\n");
   }
   XPRINTF("success: Host bsp initialized\n");

   /* initialize DRX driver */
   if ( DRX_Init( demodulators ) != DRX_STS_OK )
   {
      XERROR("failure: error initializing driver\n");
   }
   XPRINTF("success: DRX driver initialized\n");
   
   /* probe function for demod, can be called before demod is opened */
   if ( DRX_Ctrl( &demod, DRX_CTRL_PROBE_DEVICE, NULL ) != DRX_STS_OK )
   {
      XERROR("failure: no DRX397xD detected\n");
   }
   XPRINTF("success: DRX397xD detected\n");

   /* open demodulator instance */
   if ( DRX_Open( &demod ) != DRX_STS_OK )
   {
      XERROR("failure: error opening demodulator\n");
   }
   XPRINTF("success: demodulator instance opened\n");

   /* show version information */
   if ( DRX_Ctrl( &demod, DRX_CTRL_VERSION, &versionList ) != DRX_STS_OK )
   {
      XERROR("failure: error retrieving version information\n");
   }
   XPRINTF("\nVersion Info:\n");
   while ( versionList != NULL )
   {
      pDRXVersion_t version = versionList->version;
      if (version)
      {
         XPRINTF( "%s :  %s\n", version->moduleName, version->vString );
      }
      versionList = versionList->next;
   }

   XPRINTF( "\n" );

   /*-----------------------------------------------------------------------*/
   /* (3) Configure hardware dependent settings                             */
   /*-----------------------------------------------------------------------*/

#if 0
   /* if required, enable the RF-AGC */
   /* - For most of the supplied configurations of MOPLL based tuners their internal   */
   /*   RF-AGC loop is used and the DRX397xD's RF-AGC should remain disabled.          */
   /* - When using the Microtune MT2060 silicon tuner, the RF-AGC should be enabled.   */
   /* - When using the XCeive XC3028 silicon tuner, the RF-AGC should remain disabled. */
   {
      DRX3973DCfgAgc_t  RfAgc;
      DRXCfg_t          config = { DRX3973D_CFG_RF_AGC, NULL };

      /* set RF-AGC mode to "_AUTO", default mode is "_OFF" */
      config.cfgData    = &RfAgc;
      RfAgc.ctrlMode    = DRX3973D_AGC_CTRL_AUTO;
      RfAgc.settleLevel = 544;

      if ( DRX_Ctrl( &demod, DRX_CTRL_SET_CFG, &config ) != DRX_STS_OK )
      {
         XERROR("failure: error enabling RF-AGC\n");
      }
      XPRINTF("success: enabled RF-AGC\n" );
   }
#endif


#if 0 
   /* if required, enable the PGA (Programmable Gain Amplifier) */
   /* - The PGA is only available for the types: DRX3973D, DRX3974D and DRX3977D */
   /* - If available, the PGA should be enabled when not using an IF-amplifier   */
   {
      Bool_t   enablePGA = TRUE;
      DRXCfg_t config    = { DRX3973D_CFG_PGA, NULL };

      config.cfgData = &enablePGA;
      if ( DRX_Ctrl( &demod, DRX_CTRL_SET_CFG, &config ) != DRX_STS_OK )
      {
         XERROR("failure: error enabling PGA\n");
      }
      XPRINTF("success: enabled PGA\n" );
   }
#endif


#if 0
   /* if required, re-configure the IF-AGC */
   {
      DRX3973DCfgAgc_t  IfAgc;
      DRXCfg_t          config = { DRX3973D_CFG_IF_AGC, NULL };

      /* re-configure IF-AGC, default ctrlMode is "_AUTO" */
      config.cfgData       = &IfAgc;
      IfAgc.ctrlMode       = DRX3973D_AGC_CTRL_AUTO;
      IfAgc.settleLevel    =  140;  /* range [0, ... , 1023], 1/n of fullscale range */
      IfAgc.minOutputLevel =    0;  /* range [0, ... , 1023], 1/n of fullscale range */
      IfAgc.maxOutputLevel = 1023;  /* range [0, ... , 1023], 1/n of fullscale range */
      IfAgc.speed          =  904;  /* range [0, ... , 1023], 1/n of fullscale range */

      if ( DRX_Ctrl( &demod, DRX_CTRL_SET_CFG, &config ) != DRX_STS_OK )
      {
         XERROR("failure: error configuring IF-AGC\n");
      }
      XPRINTF("success: configured IF-AGC\n" );
   }
#endif

#if 0
   /* if required, use the user I/O pin (UIO) for output/input */
   {
      DRXUIOCfg_t  uioCfg  = { DRX_UIO1, DRX_UIO_MODE_READWRITE };
      DRXUIOData_t uioData = { DRX_UIO1, FALSE };

⌨️ 快捷键说明

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