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

📄 example_scan.c

📁 用于DRX3973或DRX39系列的芯片的控制
💻 C
字号:
/**
* \file $Id: example_scan.c,v 1.11 2005/11/29 16:24:03 jasper Exp $
*
* \brief example of a channel scan
*
* \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  FREQUENCY_PLAN_EUROPE         /* standard European frequency plan is used for scanning */
#include "frequency_plans.h"
#define MAX_NR_OF_CHANNELS     100     /* max number of channels to store   */


/*------------------------------------------------------------------------------
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
-----------------------------------------------------------------------------*/

int main ( void )
{
   /* declare neccesary variables */
   DRXChannel_t    channelParams;
   DRXScanParam_t  scanParams;
   DRXStatus_t     scanStatus   = DRX_STS_BUSY;    /* event status of channelscan */
   u16_t           scanProgress = 0;
   u16_t           i;

   /* Allocate storage for channels found */
   DRXChannel_t    channelList[MAX_NR_OF_CHANNELS];
   u16_t           nChannels    = 0;               /* number of channels found so far */

   /* using default demod instance */
   demodAddr       = DRX3973DDefaultAddr_g;
   demodCommAttr   = DRX3973DDefaultCommAttr_g;
   demod           = DRX3973DDefaultDemod_g;
   demodulators[0] = &demod;

   /* connect data structures */
   demod.myI2CDevAddr                = &demodAddr;
   demod.myCommonAttr                = &demodCommAttr;
   demod.myCommonAttr->microcode     = MC_IMAGE_ADDR;
   demod.myCommonAttr->microcodeSize = MC_IMAGE_SIZE;
   demod.myTuner                     = &PRE_CONF_TUNER;

   /* set scan parameters */
   scanParams.frequencyPlan     = FREQUENCY_PLAN_SELECTED;
   scanParams.frequencyPlanSize = (u16_t) ( sizeof(FREQUENCY_PLAN_SELECTED) / sizeof(DRXFrequencyPlan_t) );
   scanParams.numTries          = 5;      /* maximum number of channels to try before return */

   /* 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");
   
   /* open demodulator instance */
   if ( DRX_Open( &demod ) != DRX_STS_OK )
   {
      XERROR("failure: error opening demodulator\n");
   }
   XPRINTF("success: demodulator instance opened\n");

   /* start scanning until frequency plan has been fully searched */
   if ( DRX_Ctrl( &demod, DRX_CTRL_SCAN_INIT, &scanParams ) != DRX_STS_OK )
   {
      XERROR("failure: error initializing the scan\n");
   }
   do
   {
      scanStatus = DRX_Ctrl( &demod, DRX_CTRL_SCAN_NEXT , &scanProgress );
 
      switch ( scanStatus )
      {
        case DRX_STS_OK:
           /* wait for system to stabilize */
           XWAITMSECS(200);

           /* retrieve channel parameters */
           DRX_Ctrl( &demod, DRX_CTRL_GET_CHANNEL, &channelParams );
 
           /* store channel parameters in channel list*/
           channelList[nChannels] = channelParams;
           channelList[nChannels].classification = DRX_AUTO;
           nChannels ++;
 
           /* show the channel parameters on stdout */
           XPRINTF("\n%3d.) Channel found \n", nChannels);
           XPRINTF("%20s : %d\n",   "frequency (kHz)",(int)channelParams.frequency );
           XPRINTF("%20s : %s\n",   "bandwidth",      DRX_STR_BANDWIDTH( channelParams.bandwidth ) );
           XPRINTF("%20s : %s\n",   "mirroring",      DRX_STR_MIRROR( channelParams.mirror ) );
           XPRINTF("%20s : %s\n",   "constellation",  DRX_STR_CONSTELLATION( channelParams.constellation ) );
           XPRINTF("%20s : %s\n",   "hierarchy",      DRX_STR_HIERARCHY( channelParams.hierarchy ) );
           XPRINTF("%20s : %s\n",   "priority",       DRX_STR_PRIORITY( channelParams.priority ) );
           XPRINTF("%20s : %s\n",   "coderate",       DRX_STR_CODERATE( channelParams.coderate ) );
           XPRINTF("%20s : %s\n",   "guard",          DRX_STR_GUARD( channelParams.guard ) );
           XPRINTF("%20s : %s\n",   "fftmode",        DRX_STR_FFTMODE( channelParams.fftmode ) );
 
        case DRX_STS_BUSY:
           /* update progress bar */
           XPRINTF("Progress %3d %%\n", scanProgress/10);
           break;
 
        case DRX_STS_ERROR:
           /* report error */
           XERROR("failure: error during scan\n");
           break;
        default:
           break;
      }
   }while ( (scanStatus != DRX_STS_READY) && (nChannels < MAX_NR_OF_CHANNELS) );

   /* Autozap through channels found */
   XPRINTF("\nstarting to zap throught the channels found\n\n");
   for (i = 0 ; i < nChannels ; i++)
   {
      if ( DRX_Ctrl( &demod, DRX_CTRL_SET_CHANNEL, &(channelList[i]) ) != DRX_STS_OK )
      {
         XERROR("failure: error setting channel\n\n");
      }
      XPRINTF("Channel %3d out of %3d\n", i+1, nChannels);
 
      /* wait for permission to select the next channel */
      if ( (i+1) < nChannels )
      {
         XWAITKEYPRESSED("press enter to see next channel\n\n");
      }
      else
      {
         XWAITKEYPRESSED("press enter to exit program\n\n");
      }
   }

   /* close system */
   DRX_Close( &demod );
   DRX_Term();
   DRXBSP_HST_Term();
   DRXBSP_I2C_Term();
   
   return 0;
}

/*============================================================================*/
/* END OF FILE */

⌨️ 快捷键说明

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