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

📄 hamaro_sdc.c

📁 QPSK Tuner details, for conexant chipset.
💻 C
📖 第 1 页 / 共 5 页
字号:
        meanagc /= 2;
    else if (meanagc<108/2)
      meanagc *= 2;
    else
      meanagc += 20;
    
    meanagc += 2;
          
    trace_new( TRACE_FLAG, "meanagc = %02d\r\n", meanagc);    
    i = 0;
    j = 0;
//    while(i<segl)
//    { 
//       if (s_pwrscan_buffer_info[i].agcacc>108)
//              break;
//              
//       if (s_pwrscan_buffer_info[i].agcacc>meanagc) 
//       {
//             if (s_pwrscan_buffer_info[i+1].agcacc>meanagc) 
//               break;
//       }
//
////         if ((s_pwrscan_buffer_info_delta[i]>10) &&
////                            (s_pwrscan_buffer_info_delta[i+1]>10))
////             break;
//       i++;
//    }
    j = 0;
    i = segl;
    
    s_power_spectrum_data.filled_buffer_len = s_pwrscan_buffer_info[i-1].end_freq_index;
    trace_new( TRACE_FLAG, "Last Frequency = %d\r\n", s_pwrscan_buffer_info[i-1].end_freq_hz);   
    mean = MeanValue(s_power_spectrum_data.power, s_power_spectrum_data.filled_buffer_len);
    s_mean = mean;
    //std = GetStdNumber(s_power_spectrum_data.power, s_power_spectrum_data.filled_buffer_len, mean);
    
    counts = FindTransponders(s_power_spectrum_data.power, s_power_spectrum_data.abs_freq,
                            s_power_spectrum_data.filled_buffer_len, mean+HIGH_WAVE_THRESHOLD, 0);
    s_counts = counts;
    countw = FindTransponders(s_power_spectrum_data.power, s_power_spectrum_data.abs_freq,
                            s_power_spectrum_data.filled_buffer_len, mean-LOW_WAVE_THRESHOLD, 1);
    
    trace_new( TRACE_FLAG, "mean = %05d  std = %05d\r\n", mean, std);
    trace_new( TRACE_FLAG, "**********************************\r\n");
        trace_new( TRACE_FLAG, "********Short Raw Data**************\r\n");
        CandidateTPOutput(g_tp_data0, counts);

    trace_new( TRACE_FLAG, "**********************************\r\n");
        trace_new( TRACE_FLAG, "********Wide Raw Data*************\r\n");
        CandidateTPOutput(g_tp_data1, countw);  
        
//      ParseCandidateTPByLowHump(s_power_spectrum_data.power, g_tp_data0,
//                          counts, mean-HIGH_WAVE_THRESHOLD);

//      ParseCandidateTPByLowHump(s_power_spectrum_data.power, g_tp_data1,
//                          countw, mean-std.high/2+std.mid-std.low);
//    
//    countw = countw - DeleteRemovedNodes(g_tp_data1, countw);
//    ParseCandidateTPByLowHump(s_power_spectrum_data.power, g_tp_data1,
//                          countw, mean-std);
//    trace_new( TRACE_FLAG, "**********************************\r\n");
//      trace_new( TRACE_FLAG, "*****Short Parsed by LowHump*******\r\n");  
//      CandidateTPOutput(g_tp_data0, counts);
                                
//    ParseCandidateTPByPeak(s_power_spectrum_data.power, g_tp_data1,
//                          countw, mean);
//    trace_new( TRACE_FLAG, "**********************************\r\n");
//      trace_new( TRACE_FLAG, "*****Wide Parsed by Peak*******\r\n");  
//      CandidateTPOutput(g_tp_data1, countw);      
        
    MergeCandidateTPAdv(g_tp_data1, countw, g_tp_data0, counts);
    trace_new( TRACE_FLAG, "**********************************\r\n");
        trace_new( TRACE_FLAG, "************Final*****************\r\n");  
        CandidateTPOutput(g_tp_data0, counts);         

    i=0;
    j=0;
    while(i<countw)
    {
      if( (counts+j) >= STS_MAX_SCAN_CANDIDATES )
         break; /* The candidates array is full */
         
        if ((g_tp_data1[i].remove==0)&&(g_tp_data1[i].bw>1200000)
                        && (g_tp_data1[i].bw<SRBIN_MAX_SR_KHZ*1000)) 
        {
            g_tp_data0[counts+j] = g_tp_data1[i];
            g_tp_data0[counts+j].bw += 500000;
            j++;
        }
      i++;
    }
    s_counts = counts + j;
    trace_new( TRACE_FLAG, "**********************************\r\n");
        trace_new( TRACE_FLAG, "**********Final Wide+Short**********\r\n");  
        CandidateTPOutput(g_tp_data0, s_counts);
        
    if(s_counts >= CANDIDATES_NUM_THRESHOLD )
    {
        k = ParseCandidateTPByBW(g_tp_data0, s_counts);
    }
        
    i=0;    
    j=0;        
//    while(i<counts)
//    {
//      if ( (g_tp_data0[i].remove == 1) || (g_tp_data0[i].bw<MIN_SYMBOL_RATE) ||
//                  (g_tp_data0[i].bw>MAX_SYMBOL_RATE))
//      {
//          i++;
//          continue;
//      }
//      
//      s_sts_channel_info[j].carrier_freq_hz = g_tp_data0[i].mid;
//      s_sts_channel_info[j].symbol_rate_hz  = g_tp_data0[i].bw;
//      s_sts_channel_info[j].code_rate = 0x0;
//      s_sts_channel_info[j].good_channel = False;
//
//      b_channel_found = True; 
//
//      task_time_sleep(10);
//      i++;
//      j++;
//    }    
//      s_channel_info_index = j;
 
    trace_new( TRACE_FLAG, "**********************************\r\n");
        
}

void
STS_CheckCandidateWithStitcheddata()
{
    unsigned short mean=0;
    unsigned int counts=0;
    unsigned int i=0, j=0;
    TP_CANDIDATE *sd, *sd_stitch;
    int delta_freq;
    //STD_NUM std;
          
    mean = MeanValue(s_power_spectrum_data.power, s_power_spectrum_data.filled_buffer_len);
    //std = GetStdNumber(s_power_spectrum_data.power, s_power_spectrum_data.filled_buffer_len, mean);
    
    counts = FindTransponders(s_power_spectrum_data.power, s_power_spectrum_data.abs_freq,
                            s_power_spectrum_data.filled_buffer_len, mean*2/3, 1);   
    
    trace_new( TRACE_FLAG, "mean = %05d\r\n", mean);
    trace_new( TRACE_FLAG, "**********************************\r\n");
    trace_new( TRACE_FLAG, "********Stitched Raw Data************\r\n");
    CandidateTPOutput(g_tp_data1, counts);
    
    /* remove thoese candidates not in Stitched Raw Data */
    sd = g_tp_data0;
    i=0;
    j=0;
    while( j < s_counts )
    {
        if( !sd->remove )
        {
            sd_stitch = g_tp_data1;
            i = 0;
            while( i < counts )
            {
                delta_freq = abs(sd->mid - sd_stitch->mid);
                if( (delta_freq <= sd->bw/2)
                    ||(sd_stitch->f1 <=sd->mid && sd->mid<=sd_stitch->f2)
                    ||(sd->f1 <= sd_stitch->mid && sd_stitch->mid <= sd->f2) )
                {
                    break;
                }
                i++;
                sd_stitch++;
            }
            
            if(i >= counts)
            {
                sd->remove = 1;
            }
        }
        sd++;
        j++;
    }

    trace_new( TRACE_FLAG, "**********************************\r\n");
    trace_new( TRACE_FLAG, "********Final Candidate Data********\r\n");
    CandidateTPOutput(g_tp_data0, s_counts);
    trace_new( TRACE_FLAG, "**********************************\r\n");
}

static BOOL   
STS_PowerScan2BinarySearchCriterion()
{
    FSM_Poll(&pwr_scan_fsm);    
    if (FSM_CheckState(&pwr_scan_fsm, PWRSCAN_READY_STATE) == True)
    {
        STSDBG_WR_ELAPSED_TIME();
        FSM_Init(&pwr_scan_fsm); /* IDLE state */
        STSDBG_WR_STR("STS FSM::POWER SCAN FSM is DISABLED", True);
        //PWRSCAN_SmoothingMedianFilter();
        STS_UpdateProgress(HAMARO_STS_CHANNEL_SENSING);
        //STS_Cleanup();
#if 0        
        STS_ParsePowerDataInMainBuffer();
        STSDBG_WR_ELAPSED_TIME();
#endif        
        //p_find_fall_range_curvature = FINDFALL_GetFallCurvaturePoints();
        //p_find_rise_range_curvature = FINDRISE_GetRiseCurvaturePoints();
               
        s_current_tp_index = 1;
        s_current_sd = GetCandidateNextAdv(g_tp_data0, s_counts, s_current_tp_index);
        
//        if (s_current_sd != NULL)
//        {
//            p_find_rise_range_curvature->concave = s_current_sd->f1-  DEFAULT_EDGE_RANGE;
//            p_find_rise_range_curvature->convex = s_current_sd->f1 + DEFAULT_EDGE_RANGE;
//        }
        STS_SetEdge(STS_EDGE_RISING); 
        
    return (True);
    }

    return (False); 
}

static STATE* 
STS_PowerScan2BinarySearch()
{
    DBG_CHECK_FSM_LIMITS(&sts_binary_search_state);
    return &sts_binary_search_state;
}



static BOOL   
STS_PowerScan2ResetCriterion()
{
    FSM_Poll(&pwr_scan_fsm);
    if (FSM_CheckState(&pwr_scan_fsm, PWRSCAN_ABORT_STATE) == True)
    {
        if (PWRSCAN_IsBufferEmpty() == True)
        {
            STSDBG_WR_STR("STS FSM::POWER SCAN BUFFER IS EMPTY", True);
            s_skip_scan = True;
            return (True);
        }
    }
    return (False);
}

static STATE* 
STS_PowerScan2Reset()
{
    DBG_CHECK_FSM_LIMITS(&sts_reset_state);
    //return &sts_reset_state;
    return &sts_reset_state;
}

static BOOL   
STS_PowerScan2CompleteCriterion()
{
    if (power_scan_input.tuner_freq_hz >= s_freq_limit)
    {
        return (True);
    }
    return (False);
}

static STATE* 
STS_PowerScan2Complete()
{
    DBG_CHECK_FSM_LIMITS(&sts_complete_state);
    return &sts_complete_state;
}

static BOOL 
STS_StartSRBinning()
{
    /* Disable all FSMs (other than SR binning) */
    //FSM_Init(&rise_edge_fsm);
    //FSM_Init(&rise_range_fsm);
    //FSM_Init(&fall_edge_fsm);
    //FSM_Init(&fall_range_fsm);
    FSM_Init(&bin_search_fsm);
    FSM_Init(&pwr_scan_fsm);

    STS_UpdateProgress(HAMARO_STS_CHANNEL_EXTRACTION);
    
    return (True);
}

/* binary search state */
static void  
STS_BinarySearchEnter()
{
    FSM_Init(&bin_search_fsm);
    BINSRCH_Start(&bin_search_fsm);
    STSDBG_WR_STR("STS FSM::BinSearch FSM is STARTED", True);
}

/*******************************************************
In order to integrate the SDC algrithms into this FSM,
and we want to 
this criterion has to be implemented as blow:
1) Check if bin_search_fsm is in READY state.
2) If not in READY, just return False.
3) If so, at first, check if current edge is falling edge
                if not, set up the environment to make a feint of
                leaving a falling edge, and return False.
          if yes, check if there are still candidate transponders in
        the array, if no others, just return True. At this time
        the FSM will go into the stage of Ready state.
        if there are still other candidates left, set up the environment
        to make a feint of leaving a rising edge, and return False.

Another solution is to add a regular task in this state, and let that task
handle the jobs above so that the following criterion could just focus on
what it should do.        
********************************************************/
static BOOL  
STS_BinarySearch2ReadyCriterion()
{
    //if ( (s_current_sd) && ((s_current_sd->f2 - s_current_sd->f1)<25000000 ) )
    if(1)
    {
        FSM_Init(&bin_search_fsm);
        STS_SetEdge(STS_EDGE_RISING);
        STSDBG_WR_STR("STS FSM::BinSearch FSM is DISABLED", True);
        if( !s_current_sd )
        {
            s_abs_right_inflection_point_hz = 0;
            s_abs_left_inflection_point_hz = 0;
        }
        else
        {
            s_abs_right_inflection_point_hz = s_current_sd->f2;
            s_abs_left_inflection_point_hz = s_current_sd->f1;
            //STSDBG_WR_UNSIGNED_LN("Bineary2ReadyCri::s_abs_right_inflection_point_hz = ", s_abs_right_inflection_point_hz);
        }
        return (True);      
    }
    FSM_Poll(&bin_search_fsm);
    if ( (FSM_CheckState(&bin_search_fsm, BINSEARCH_READY_STATE) == True) && (STS_GetEdge() == STS_EDGE_FALLING) )
    {        
        //FSM_Init(&bin_search_fsm); /* IDLE state */
        STS_SetEdge(STS_EDGE_UNKNOWN);
        STSDBG_WR_STR("STS FSM::BinSearch FSM is DISABLED", True);
        s_abs_right_inflection_point_hz = BINSRCH_GetInflectionPoint();
        STSDBG_WR_UNSIGNED_LN("STS FSM::s_abs_right_inflection_point_hz = ", s_abs_right_inflection_point_hz);
        return (True);
    }
    return (False);
}

static STATE* 
STS_BinarySearch2Ready()
{
    DBG_CHECK_FSM_LIMITS(&sts_ready_state);
    return &sts_ready_state;
}

static BOOL  
STS_BinarySearch2BinarySearchCriterion()
{
    FSM_Poll(&bin_search_fsm);
    if ( (FSM_CheckState(&bin_search_fsm, BINSEARCH_READY_STATE) == True) && (STS_GetEdge() == STS_EDGE_RISING) )
    {        
        FSM_Init(&bin_search_fsm); /* IDLE state */
        STSDBG_WR_STR("STS FSM::BinSearch FSM is DISABLED", True);
        s_abs_left_inflection_point_hz = BINSRCH_GetInflectionPoint();
        STSDBG_WR_UNSIGNED_LN("STS FSM::s_abs_left_inflection_point_hz = ", s_abs_left_inflection_point_hz);
                  
                //s_current_sd = GetCandidateNextAdv(g_tp_data0, s_counts, s_current_tp_index);
                //p_find_fall_range_curvature->concave = s_current_sd->f2;
                //p_find_fall_range_curvature->convex = s_current_sd->f2 - DEFAULT_EDGE_RANGE;
                STS_SetEdge(STS_EDGE_FALLING);
        BINSRCH_Start(&bin_search_fsm);
        
        if (s_current_sd)
                return (True);
    }
    return (False);
}

static STATE*
STS_BinarySearch2BinarySearch()
{

    DBG_CHECK_FSM_LIMITS(&sts_binary_search_state);
    return &sts_binary_search_state;
}



/* rescan state */

⌨️ 快捷键说明

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