demod_hamaro.c

来自「QPSK Tuner details, for conexant chipset」· C语言 代码 · 共 1,447 行 · 第 1/5 页

C
1,447
字号
/*                                                                           */
/*  PARAMETERS:  unit - the unit that experienced the timeout.               */
/*                                                                           */
/*  DESCRIPTION: This function implements the processing required on receipt */
/*               of a TIMEOUT message.                                       */
/*                                                                           */
/*  RETURNS:     Nothing.                                                    */
/*                                                                           */
/*  CONTEXT:     Will be run in task context.                                */
/*                                                                           */
/*****************************************************************************/
static void hamaro_timeout_msg( u_int32 unit )
{
    DEMOD_CALLBACK_DATA parm;
    int more_scanning = 1;
    CHANOBJ chan;
    BOOL APIresult;
    int rc;
    int api_error;
    CMPLXNO esno;
    MSTATUS status;

    trace_new( TL_FUNC, "New cobra timeout message for unit %d\n", unit );

    switch( local_state[unit] )
    {
        case CONNECTING:
            /* Since we timed out in CONNECTING, we don't want any more
               interrupts and we announce the failure. */
            API_SetInterruptOptions( &NIMs[unit], HAMARO_NO_INTERRUPTS );
            local_state[unit] = DISCONNECTED;
            if ( callbacks[unit] )
            {
                parm.parm.type = DEMOD_FAILED;
                callbacks[unit]( my_module, unit, DEMOD_CONNECT_STATUS, &parm );
            }
            break;

        case SCANNING:
            /* Since we timed out in SCANNING, check to see if there are more
               settings to try before we declare failure. */
            if ( ++scan_parms[unit].current_symbol_rate >= local_scan[unit].scan.satellite.num_symrates )
            {
                scan_parms[unit].current_symbol_rate = 0;
                scan_parms[unit].current_frequency += local_scan[unit].scan.satellite.hop_value;
                if ( scan_parms[unit].current_frequency > local_scan[unit].scan.satellite.end_frequency )
                {
                    scan_parms[unit].current_frequency = local_scan[unit].scan.satellite.start_frequency;
                    if ( ++scan_parms[unit].current_polarity >= local_scan[unit].scan.satellite.num_pols )
                    {
                        API_SetInterruptOptions( &NIMs[unit], HAMARO_NO_INTERRUPTS );
                        local_state[unit] = DISCONNECTED;
                        if ( callbacks[unit] )
                        {
                            parm.parm.type = DEMOD_SCAN_NO_SIGNAL;
                            callbacks[unit]( my_module, unit, DEMOD_SCAN_STATUS, &parm );
                        }
                        more_scanning = 0;
                    }
                }
            }

            /* More to try, so set up the next tuning operation and let fly. */
            if ( more_scanning )
            {
                local_scan[unit].current.tune.nim_satellite_tune.symbol_rate = local_symrates[unit][scan_parms[unit].current_symbol_rate];
                local_scan[unit].current.tune.nim_satellite_tune.frequency = scan_parms[unit].current_frequency;
                local_scan[unit].current.tune.nim_satellite_tune.polarisation = local_polarizations[unit][scan_parms[unit].current_polarity];
                local_tuning[unit] = local_scan[unit].current;
                cnxt_set_lnb( &NIMs[unit], &(local_scan[unit].current), &chan.frequency );
                chan.modtype = MOD_QPSK;
                chan.coderate = xlat_fec_in( local_scan[unit].current.tune.nim_satellite_tune.fec );
                chan.symbrate = local_scan[unit].current.tune.nim_satellite_tune.symbol_rate;
                chan.specinv = SPEC_INV_ON_BOTH; /* Fix me! wjj */
                //chan.samplerate = SAMPLE_FREQ_NOM;
                chan.viterbicoderates = local_viterbis[unit];

                /* Make sure all interrupts (including acq_fail) are reset, then
                   call API_ChangeChannel to accomplish the tuning. */
                API_AcqBegin( &NIMs[unit] );
                API_ClearPendingInterrupts( &NIMs[unit] );
                acq_failure_countdown[unit] = DEMOD_SCAN_COUNTDOWN;
                APIresult = API_ChangeChannel( &NIMs[unit], &chan );

                if ( APIresult )
                {
                    trace_new( TL_VERBOSE, "API_ChangeChannel succeeded for unit %d\n", unit );

                    /* Start the demod monitoring signal quality. */
                    if ( !API_GetChannelEsNo( &NIMs[0], ESNOMODE_SNAPSHOT, &esno, &status ) )
                    {
                        trace_new( TL_ERROR, "API_GetChannelEsNo failed\n" );
                        trace_new( TL_ERROR, "File: %s, line: %d\n", API_GetErrorFilename(&NIMs[0]), API_GetErrorLineNumber(&NIMs[0]) );
                        api_error = API_GetLastError( &NIMs[0] );
                        trace_new( TL_ERROR, "Error %d, %s\n", api_error, API_GetErrorMessage(&NIMs[0], (APIERRNO)api_error) );
                    }
    
                    rc = tick_set( hHamaroTick[unit], HAMARO_SCANNING_TIMEOUT, TRUE );
                    if ( rc != RC_OK )
                    {
                        trace_new( TL_ERROR, "Hamaro can't set tick timer for scan continue!\n" );
                        error_log( ERROR_FATAL | RC_SDM_SYSERR );
                    }
                    else
                    {
                        rc = tick_start( hHamaroTick[unit] );
                        if ( rc != RC_OK )
                        {
                            trace_new( TL_ERROR, "Hamaro can't start tick timer for scan continue!\n" );
                            error_log( ERROR_FATAL | RC_SDM_SYSERR );
                        }
                    }
                    API_SetInterruptOptions( &NIMs[unit], HAMARO_SCANNING_INTERRUPTS );
#if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
#else
                    if ( RC_OK != int_enable( demod_interrupt ) )
                    {
                        trace_new( TL_ERROR, "Hamaro can't enable NIM interrupt in hamaro_timeout_msg!\n" );
                        error_log( ERROR_FATAL | RC_SDM_SYSERR );
                    }
#endif
                }
                else
                {
                    API_SetInterruptOptions( &NIMs[unit], HAMARO_NO_INTERRUPTS );
                    trace_new( TL_ERROR, "API_ChangeChannel failed for unit %d\n", unit );
                    trace_new( TL_ERROR, "File: %s, line: %d\n", API_GetErrorFilename(&NIMs[unit]), API_GetErrorLineNumber(&NIMs[unit]) );
                    api_error = API_GetLastError( &NIMs[unit] );
                    trace_new( TL_ERROR, "Error %d, %s\n", api_error, API_GetErrorMessage(&NIMs[unit], (APIERRNO)api_error) );
                    if ( callbacks[unit] )
                    {
                        parm.parm.type = DEMOD_FAILED;
                        callbacks[unit]( my_module, unit, DEMOD_SCAN_STATUS, &parm );
                    }
                }
            }
            break;

        case CONNECTED:
            break;

        case UNINITIALIZED:
        case DISCONNECTED:
        default:
            break;
    }
}

/*****************************************************************************/
/*  FUNCTION:    hamaro_interrupt_msg                                         */
/*                                                                           */
/*  PARAMETERS:  None.                                                       */
/*                                                                           */
/*  DESCRIPTION: This function implements the processing required on receipt */
/*               of an INTERRUPT message.                                    */
/*                                                                           */
/*  RETURNS:     Nothing.                                                    */
/*                                                                           */
/*  CONTEXT:     Will be run in task context.                                */
/*                                                                           */
/*****************************************************************************/
static void hamaro_interrupt_msg( void )
{
    int ii;
    INTEROPTS pending;

    trace_new( TL_FUNC, "New cobra interrupt message\n" );

    for ( ii=0; ii<local_unit_count; ++ii )
    {
        API_GetPendingInterrupts( &NIMs[ii], &pending );
        trace_new( TL_VERBOSE, "Pending interrupts for unit %d: 0x%02x\n", ii, pending );

        API_Monitor( &NIMs[ii], &NewAcqState[ii], &NewLock[ii] );
        if ( NewAcqState[ii] != OldAcqState[ii] )
        {
            trace_new( TL_FUNC, "OldAcqState = %d, NewAcqState = %d\n", OldAcqState[ii], NewAcqState[ii] );
        }
        else
        {
            trace_new( TL_VERBOSE, "OldAcqState = %d, NewAcqState = %d\n", OldAcqState[ii], NewAcqState[ii] );
        }

        switch( local_state[ii] )
        {
            case CONNECTING:
                hamaro_connecting_state( ii, pending, OldAcqState[ii], NewAcqState[ii] );
                break;

            case CONNECTED:
                hamaro_connected_state( ii, pending, OldAcqState[ii], NewAcqState[ii] );
                break;

            case SCANNING:
                hamaro_scanning_state( ii, pending, OldAcqState[ii], NewAcqState[ii] );
                break;

            case FADE:
                hamaro_fade_state( ii, pending, OldAcqState[ii], NewAcqState[ii] );
                break;

            /* Interrupts in unexpected states can be ignored.  The ISR already
               disabled any further interrupts. */
            case UNINITIALIZED:
            case DISCONNECTED:
            default:
                break;
        }

        /* New (current) state becomes the old state. */
        OldAcqState[ii] = NewAcqState[ii];
        OldLock[ii] = NewLock[ii];
    }
}

extern int g_nReceiveTicks;
extern int g_nDiSEqCCmdTicks;
int hamaro_connect_ticks;
int hamaro_scan_ticks;
int hamaro_change_channel_ticks;
/*****************************************************************************/
/*  FUNCTION:    hamaro_connect_msg                                           */
/*                                                                           */
/*  PARAMETERS:  unit - the unit specified in the CONNECT message.           */
/*               tune - the tuning specification in the CONNECT messsage.    */
/*                                                                           */
/*  DESCRIPTION: This function implements the processing required on receipt */
/*               of a CONNECT message.                                       */
/*                                                                           */
/*  RETURNS:     Nothing.                                                    */
/*                                                                           */
/*  CONTEXT:     Will be run in task context.                                */
/*                                                                           */
/*****************************************************************************/
static void hamaro_connect_msg( u_int32 unit, TUNING_SPEC *tune )
{
    CHANOBJ chan;
    int api_error;
    DEMOD_CALLBACK_DATA parm;
    BOOL APIresult;
    int rc;
    CMPLXNO esno;
    MSTATUS status;

	hamaro_connect_ticks = CSGetTickCount();
	//MyPrint("from receive to hamaro connect is %d ticks\n", hamaro_connect_ticks-g_nReceiveTicks);
		
    trace_new( TL_FUNC, "New connect message for unit %d\n", unit );

    local_state[unit] = CONNECTING;

    cnxt_set_lnb( &NIMs[unit], tune, &chan.frequency );

    chan.modtype = MOD_QPSK;
     if((tune->tune.nim_satellite_tune.fec != M_RATE_AUTO)&&
     			(tune->tune.nim_satellite_tune.fec != M_RATE_NONE))
     {
          /* Manual mode. */
          chan.coderate = xlat_fec_in( tune->tune.nim_satellite_tune.fec );       
          /* Not sure why we do this but I'll leave it there as it dosent cause much harm! */
          chan.viterbicoderates = CODERATE_2DIV3 | CODERATE_3DIV4; /* only for testing - should be 0 */
     }
     else
     {
         /* Automatic mode, try all code rates. *//*自动模式,所有CODE RATES 都会 试一下*/
         chan.coderate = CODERATE_1DIV2;
          chan.viterbicoderates = viterbicoderates;
     }
    chan.symbrate = tune->tune.nim_satellite_tune.symbol_rate;
    chan.specinv = xlat_spectrum_in( tune->tune.nim_satellite_tune.spectrum );
    //chan.samplerate = SAMPLE_FREQ_NOM;
    chan.transpec = SPEC_DVB;
    /* Hack H/V reverse */
#if 0
    if( tune->tune.nim_satellite_tune.polarisation == 1 )
    {
        chan.lnbpol = HAMARO_LNB_LOW;
    }
    else    
    {
        chan.lnbpol = HAMARO_LNB_HIGH;
    }
#endif
    if( tune->tune.nim_satellite_tune.polarisation == 1 )
   {
   
      chan.lnbpol = ( lnb_parameters.right_volt

⌨️ 快捷键说明

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