demod_hamaro.c

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

C
1,447
字号
        trace_new( TL_VERBOSE, "There were %d acquisition failures\n", DEMOD_CONNECT_COUNTDOWN-acq_failure_countdown[unit] );

        if ( callbacks[unit] )
        {
            parm.parm.type = DEMOD_CONNECTED;
            callbacks[unit]( my_module, unit, DEMOD_CONNECT_STATUS, &parm );
        }

        /* Now clear the pending interrupts from the demod, and re-enable
           interrupts for a loss of sync. */
        API_ClearPendingInterrupts( &NIMs[unit] );
        API_SetInterruptOptions( &NIMs[unit], HAMARO_CONNECTED_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_connecting_state!\n" );
            error_log( ERROR_FATAL | RC_SDM_SYSERR );
        }
#endif
    }

    /* We got an acquisition interrupt, but the new acquisition state is not
       locked and tracking, so count down to determine status. */
    else
    {
        /* If not completely through, reset the interrupt and keep going. */
        if ( acq_failure_countdown[unit] )
        {
            --acq_failure_countdown[unit];
            API_ClearPendingInterrupts( &NIMs[unit] );
#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_connecting_state!\n" );
                error_log( ERROR_FATAL | RC_SDM_SYSERR );
            }
#endif
        }
        else
        {
            local_state[unit] = DISCONNECTED;

            rc = tick_stop( hHamaroTick[unit] );
            if ( rc != RC_OK )
            {
                trace_new( TL_ERROR, "Hamaro can't stop tick timer!\n" );
                error_log( ERROR_WARNING | RC_SDM_SYSERR );
            }

            if ( callbacks[unit] )
            {
                parm.parm.type = DEMOD_FAILED;
                callbacks[unit]( my_module, unit, DEMOD_CONNECT_STATUS, &parm );
            }
        }
    }
}

/*****************************************************************************/
/*  FUNCTION:    hamaro_connected_state                                       */
/*                                                                           */
/*  PARAMETERS:  unit - the unit to process in the CONNECTED state.          */
/*               pending - the mask of currently pending interrupts.         */
/*               old - the previous acquisition state.                       */
/*               new - the new (current) acquisition state.                  */
/*                                                                           */
/*  DESCRIPTION: This function implements the processing required on receipt */
/*               of an interrupt in the CONNECTED state.                     */
/*                                                                           */
/*  RETURNS:     Nothing.                                                    */
/*                                                                           */
/*  CONTEXT:     Will be run in task context.                                */
/*                                                                           */
/*****************************************************************************/
static void hamaro_connected_state( u_int32 unit, INTEROPTS pending, ACQSTATE old, ACQSTATE new )
{
    DEMOD_CALLBACK_DATA parm;

    trace_new( TL_FUNC, "CONNECTED state processing for unit %d\n", unit );

    /* If we got a loss of sync interrupt, and the new acquisition state is not
       locked and tracking, then we will transition to the signal fade state. */
    if ( (NewLock[unit].reedsolomon == False) && (new != ACQ_LOCKED_AND_TRACKING) )
    {
        trace_new( TL_FUNC, "Switching to FADE state for unit %d\n", unit );
        local_state[unit] = FADE;

        if ( callbacks[unit] )
        {
            parm.parm.type = DEMOD_DRIVER_LOST_SIGNAL;
            callbacks[unit]( my_module, unit, DEMOD_CONNECT_STATUS, &parm );
        }

        /* Now clear the pending interrupts from the demod, and re-enable
           interrupts for regaining sync. */
        API_ClearPendingInterrupts( &NIMs[unit] );
        API_SetInterruptOptions( &NIMs[unit], HAMARO_CONNECTING_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_connected_state!\n" );
            error_log( ERROR_FATAL | RC_SDM_SYSERR );
        }
#endif
    }

    /* We got a loss of sync interrupt, but the new acquisition state is
       locked and tracking, so wait for the next interrupt. */
    else
    {
        API_ClearPendingInterrupts( &NIMs[unit] );
#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_connected_state!\n" );
            error_log( ERROR_FATAL | RC_SDM_SYSERR );
        }
#endif
    }
}

/*****************************************************************************/
/*  FUNCTION:    hamaro_scanning_state                                        */
/*                                                                           */
/*  PARAMETERS:  unit - the unit to process in the SCANNING state.           */
/*               pending - the mask of currently pending interrupts.         */
/*               old - the previous acquisition state.                       */
/*               new - the new (current) acquisition state.                  */
/*                                                                           */
/*  DESCRIPTION: This function implements the processing required on receipt */
/*               of an interrupt in the SCANNING state.                      */
/*                                                                           */
/*  RETURNS:     Nothing.                                                    */
/*                                                                           */
/*  CONTEXT:     Will be run in task context.                                */
/*                                                                           */
/*****************************************************************************/
static void hamaro_scanning_state( u_int32 unit, INTEROPTS pending, ACQSTATE old, ACQSTATE new )
{
    int rc;
    DEMOD_CALLBACK_DATA parm;
    u_int32 msg[4];
    int return_code;
    CODERATE coderate;

    trace_new( TL_FUNC, "SCANNING state processing for unit %d\n", unit );

    /* If we got an acquisition interrupt, and the new acquisition state is
       either locked and tracking or fade, then we will transition to the
       connected state. */
    if ( (NewLock[unit].reedsolomon == True) && ((new == ACQ_LOCKED_AND_TRACKING) || (new == ACQ_FADE)) )
    {
        local_state[unit] = CONNECTED;

        rc = tick_stop( hHamaroTick[unit] );
        if ( rc != RC_OK )
        {
            trace_new( TL_ERROR, "Hamaro can't stop tick timer!\n" );
            error_log( ERROR_WARNING | RC_SDM_SYSERR );
        }

        API_GetViterbiRate( &NIMs[unit], &coderate );
        local_tuning[unit].tune.nim_satellite_tune.fec = xlat_fec_out( coderate );
        trace_new( TL_FUNC, "Switching to CONNECTED state for unit %d\n", unit );
        trace_new( TL_VERBOSE, "There were %d acquisition failures\n", DEMOD_SCAN_COUNTDOWN-acq_failure_countdown[unit] );

        if ( callbacks[unit] )
        {
            parm.parm.type = DEMOD_SCAN_COMPLETE;
            callbacks[unit]( my_module, unit, DEMOD_SCAN_STATUS, &parm );
        }

        /* Now clear the pending interrupts from the demod, and re-enable
           interrupts for a loss of sync. */
        API_ClearPendingInterrupts( &NIMs[unit] );
        API_SetInterruptOptions( &NIMs[unit], HAMARO_CONNECTED_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_scanning_state!\n" );
            error_log( ERROR_FATAL | RC_SDM_SYSERR );
        }
#endif
    }

    /* Either we got an acquisition interrupt, but the new acquisition state is
       neither locked and tracking nor fade, or we got an acquisition failure;
       count down to determine status. */
    else
    {
        /* If not completely through, reset the interrupt and keep going. */
        if ( acq_failure_countdown[unit] )
        {
            --acq_failure_countdown[unit];
            API_ClearPendingInterrupts( &NIMs[unit] );
#if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
#else
            int_enable( demod_interrupt );
#endif
        }
        /* Enough is enough; try something else or give up completely. */
        else
        {
            /* Send a control message to the Hamaro demod task to signal the timeout. */
            msg[0] = unit;
            msg[1] = msg[2] = 0;
            msg[3] = HAMARO_TIMEOUT;
            return_code = qu_send( hamaro_message_q, msg );
            if (return_code != RC_OK)
            {
                trace_new( TL_ERROR, "Hamaro can't send message in hamaro_scanning_state!\n" );
                error_log( ERROR_WARNING | RC_SDM_QFULL );
                global_timeout_flag |= (unit == 0) ? 1 : 2;
            }
        }
    }
}

/*****************************************************************************/
/*  FUNCTION:    hamaro_fade_state                                            */
/*                                                                           */
/*  PARAMETERS:  unit - the unit to process in the FADE state.               */
/*               pending - the mask of currently pending interrupts.         */
/*               old - the previous acquisition state.                       */
/*               new - the new (current) acquisition state.                  */
/*                                                                           */
/*  DESCRIPTION: This function implements the processing required on receipt */
/*               of an interrupt in the FADE state.                          */
/*                                                                           */
/*  RETURNS:     Nothing.                                                    */
/*                                                                           */
/*  CONTEXT:     Will be run in task context.                                */
/*                                                                           */
/*****************************************************************************/
static void hamaro_fade_state( u_int32 unit, INTEROPTS pending, ACQSTATE old, ACQSTATE new )
{
    DEMOD_CALLBACK_DATA parm;

    trace_new( TL_FUNC, "FADE state processing for unit %d\n", unit );

    /* If we got an acquisition interrupt, and the new acquisition state is
       locked and tracking, then we will transition to the connected state. */
    if ( (NewLock[unit].reedsolomon == True) && (new == ACQ_LOCKED_AND_TRACKING) )
    {
        local_state[unit] = CONNECTED;
        trace_new( TL_FUNC, "Switching to CONNECTED state for unit %d\n", unit );

        if ( callbacks[unit] )
        {
            parm.parm.type = DEMOD_DRIVER_REACQUIRED_SIGNAL;
            callbacks[unit]( my_module, unit, DEMOD_CONNECT_STATUS, &parm );
        }

        /* Now clear the pending interrupts from the demod, and re-enable
           interrupts for a loss of sync. */
        API_ClearPendingInterrupts( &NIMs[unit] );
        API_SetInterruptOptions( &NIMs[unit], HAMARO_CONNECTED_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_connecting_state!\n" );
            error_log( ERROR_FATAL | RC_SDM_SYSERR );
        }
#endif
    }

    /* We got an acquisition interrupt, but the new acquisition state is not
       locked and tracking.  Clear the pending interrupts and wait for another. */
    else
    {
        API_ClearPendingInterrupts( &NIMs[unit] );
#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_connecting_state!\n" );
            error_log( ERROR_FATAL | RC_SDM_SYSERR );
        }
#endif
    }
}

/*****************************************************************************/
/*  FUNCTION:    hamaro_timeout_msg                                           */

⌨️ 快捷键说明

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