📄 hamaro_binsrch.c
字号:
/* hamaro_binsrch.c */
/*+++ *******************************************************************\
*
* Abstract:
*
* Hamaro binary search FSM implementation.
*
* Created: 07/15/2005
*
*
* Copyright and Disclaimer:
*
* ---------------------------------------------------------------
* This software is provided "AS IS" without warranty of any kind,
* either expressed or implied, including but not limited to the
* implied warranties of noninfringement, merchantability and/or
* fitness for a particular purpose.
* ---------------------------------------------------------------
*
* Author: Amar Puttur
*
* Module Revision Id:
*
* $Header: hamaro_binsrch.c, 5, 2006-10-20 7:00:48, Sunbey (VSS Migration)$
*
* Copyright (c) 2005 Conexant Systems, Inc.
* All rights reserved.
*
\******************************************************************* ---*/
#include "hamaro.h"
#if HAMARO_SCAN_THE_SKY
#include "hamaro_fsm.h"
#include "hamaro_sts.h"
#include "hamaro_binsrch.h"
#include "hamaro_pwrscan.h"
#if (0) //HAMARO_WIN_DEBUG
#define STSDBG_WR_INT_LN(str, val) (WINDBG_WriteIntegerLn((char*)(str), val))
#define STSDBG_WR_INT(str, val) (WINDBG_WriteInteger((char*)(str), val))
#define STSDBG_WR_HEX(str, val) (WINDBG_WriteHex((char*)(str), val))
#define STSDBG_WR_UNSIGNED_LN(str, val) (WINDBG_WriteUnsignedLn((char*)(str), val))
#define STSDBG_WR_UNSIGNED(str, val) (WINDBG_WriteUnsigned((char*)(str), val))
#define STSDBG_WR_STR(str, nl) (WINDBG_WriteString((char*)(str), nl))
#define STSDBG_WR_ELAPSED_TIME() (WINDBG_FileWriteDuration())
#define STSDBG_START_TIMER() (WINDBG_SetTimer()) /* used for time measurements */
#else // HAMARO_WIN_DEBUG
#define STSDBG_WR_INT_LN(str, val) /* Expands to nothing */
#define STSDBG_WR_INT(str, val) /* Expands to nothing */
#define STSDBG_WR_UNSIGNED_LN(str, val) /* Expands to nothing */
#define STSDBG_WR_UNSIGNED(str, val) /* Expands to nothing */
#define STSDBG_WR_STR(str, nl) /* Expands to nothing */
#define STSDBG_WR_ELAPSED_TIME() /* Expands to nothing */
#define STSDBG_START_TIMER() /* Expands to nothing */
#endif /* HAMARO_WIN_DEBUG */
extern unsigned long sts_fsm_coding;
FSM bin_search_fsm = {&sts_fsm_coding, 0x000000F0, 0, 0, 0, 0};
//static HAMARO_STS_CURVATURE_POINTS binary_search_curvature;
static HAMARO_STS_CURVATURE s_curvature = CURVATURE_UNKNOWN;
static unsigned long inflection_point_hz = 0;
static unsigned short left_inflection_point_power = 0;
/*****************************************************************************/
/* BINARY SEARCH FSM */
/*****************************************************************************/
/* Function prototypes */
/* Binary search Reset state */
static void BINSRCH_ResetEnter();
static BOOL BINSRCH_Reset2StartCriterion();
static STATE* BINSRCH_Reset2Start();
/* Binary search Start state */
static void BINSRCH_BeginEnter();
static BOOL BINSRCH_Begin2ReadyCriterion();
static STATE* BINSRCH_Begin2Ready();
static BOOL BINSRCH_Begin2ConcaveCriterion();
static STATE* BINSRCH_Begin2Concave();
static BOOL BINSRCH_Begin2ConvexCriterion();
static STATE* BINSRCH_Begin2Convex();
static void BINSRCH_Begin();
/* Binary search Concave state */
static void BINSRCH_Concave();
static BOOL BINSRCH_Concave2ReadyCriterion();
static STATE* BINSRCH_Concave2Ready();
static BOOL BINSRCH_Concave2ConvexCriterion();
static STATE* BINSRCH_Concave2Convex();
/* Binary search Convex state */
static void BINSRCH_Convex();
static BOOL BINSRCH_Convex2ReadyCriterion();
static STATE* BINSRCH_Convex2Ready();
static BOOL BINSRCH_Convex2ConcaveCriterion();
static STATE* BINSRCH_Convex2Concave();
/* Binary search Ready state */
static void BINSRCH_ReadyEnter();
/* State tables */
STATE bin_search_reset_state = /* BINARY_SEARCH FSM, RESET state */
{
BINSRCH_ResetEnter, /* Entry task */
{
{BINSRCH_Reset2StartCriterion, BINSRCH_Reset2Start}, /* Criterion1 and Exit task */
{0,0} /* End of Criterion/Exit task */
},
0, /* Regular/Routine task */
0, /* No counter */
BINSEARCH_RESET_STATE /* state code */
};
STATE bin_search_begin_state = /* BINARY_SEARCH FSM, START state */
{
BINSRCH_BeginEnter, /* Entry task */
{
{BINSRCH_Begin2ReadyCriterion, BINSRCH_Begin2Ready}, /* Criterion1 and Exit task */
{BINSRCH_Begin2ConcaveCriterion, BINSRCH_Begin2Concave}, /* Criterion2 and Exit task */
{BINSRCH_Begin2ConvexCriterion, BINSRCH_Begin2Convex}, /* Criterion3 and Exit task */
{0,0} /* End of Criterion/Exit task */
},
BINSRCH_Begin, /* Regular/Routine task */
0, /* No counter */
BINSEARCH_BEGIN_STATE /* state code */
};
STATE bin_search_concave_state = /* BINARY_SEARCH FSM, CONCAVE state */
{
0, /* Entry task */
{
{BINSRCH_Concave2ReadyCriterion, BINSRCH_Concave2Ready}, /* Criterion1 and Exit task */
{BINSRCH_Concave2ConvexCriterion, BINSRCH_Concave2Convex}, /* Criterion2 and Exit task */
{0,0} /* End of Criterion/Exit task */
},
BINSRCH_Concave, /* Regular/Routine task */
0, /* No counter */
BINSEARCH_CONCAVE_STATE /* state code */
};
STATE bin_search_convex_state = /* BINARY_SEARCH FSM, CONVEX state */
{
0, /* Entry task */
{
{BINSRCH_Convex2ReadyCriterion, BINSRCH_Convex2Ready}, /* Criterion1 and Exit task */
{BINSRCH_Convex2ConcaveCriterion, BINSRCH_Convex2Concave}, /* Criterion2 and Exit task */
{0,0} /* End of Criterion/Exit task */
},
BINSRCH_Convex, /* Regular/Routine task */
0, /* No counter */
BINSEARCH_CONVEX_STATE /* state code */
};
STATE bin_search_ready_state = /* BINARY_SEARCH FSM, READY state */
{
BINSRCH_ReadyEnter, /* Entry task */
{
{0,0} /* End of Criterion/Exit task */
},
0, /* Regular/Routine task */
0, /* No counter */
BINSEARCH_READY_STATE /* state code */
};
/*****************************************************************************/
/* BINSRCH_Start() */
/* Main FSM function */
/*****************************************************************************/
void BINSRCH_Start(FSM *fsm)
{
fsm->p_curr = &bin_search_reset_state;
}
/* -- Binary search Reset state -- */
/*****************************************************************************/
/* BINSRCH_ResetEnter() */
/* BIN SEARCH FSM Reset function */
/*****************************************************************************/
static void
BINSRCH_ResetEnter()
{
HAMARO_PWRSCAN_INPUT narrow_power_scan_input;
unsigned short edge = STS_GetEdge();
unsigned long tuner_freq_hz = 0;
HAMARO_STS_CURVATURE_POINTS* p_curvature_points = 0;
/*
f0 = f_concave;
f1 = (f_concave + f_convex)/2;
f2 = f_convex;
When we enter BINARY_SEARCH_FSM from either RISE_RANGE_FSM or FALL_RANGE_FSM,
we
1) Set Tuner to (f_concave+f_convex)/2.
2) Set antialias bandwidth to abs(f_concave-f_convex)+2.0 MHz.
We can have a special functions that sets these values.
Once we reach very close to the inflection point, we need all the precision we can get for the power measurement.
The best way is to open the antialias just enough to that very narrow chunk of frequency.
*/
if (edge == STS_EDGE_FALLING)
{
//p_curvature_points = FINDFALL_GetFallCurvaturePoints();
tuner_freq_hz = p_curvature_points->convex;
}
else if (edge == STS_EDGE_RISING)
{
//p_curvature_points = FINDRISE_GetRiseCurvaturePoints();
tuner_freq_hz = p_curvature_points->concave;
}
narrow_power_scan_input.bw_symbol_rate_mhz = STS_NARROW_TUNER_BW_SYMB_RATE;
narrow_power_scan_input.observation_window = STS_OBERVATION_WINDOW_SUB;
narrow_power_scan_input.search_span_mhz = STS_SEARCH_SPAN_MHZ_SUB;
narrow_power_scan_input.step_size_hz = STS_STEP_SIZE_KHZ_SUB * 1000;
narrow_power_scan_input.symbol_rate_khz = STS_MATCH_FILTER_CLK_SUB * 1000;
narrow_power_scan_input.tuner_freq_hz = tuner_freq_hz;
narrow_power_scan_input.upper_freq_limit_hz= tuner_freq_hz + (STS_SEARCH_SPAN_MHZ_SUB * 1000000UL);
narrow_power_scan_input.full_scan = False;
narrow_power_scan_input.stitch = False;
narrow_power_scan_input.smooth = False;
STSDBG_WR_UNSIGNED_LN("BINSRCH_ResetEnter::tuner_freq_hz = ", tuner_freq_hz);
FSM_Init(&pwr_scan_fsm);
STS_SetUseMainBuffer(False); /* use sub buffer */
PWRSCAN_SetAAGCFilter(True);
PWRSCAN_Start(&pwr_scan_fsm, &narrow_power_scan_input);
STSDBG_WR_STR("BINSRCH FSM::POWER SCAN FSM is STARTED", True);
}
static BOOL
BINSRCH_Reset2StartCriterion()
{
FSM_Poll(&pwr_scan_fsm);
if (FSM_CheckState(&pwr_scan_fsm, PWRSCAN_READY_STATE) == True)
{
FSM_Init(&pwr_scan_fsm); /* IDLE state */
STSDBG_WR_STR("BINSRCH FSM::POWER SCAN FSM is DISABLED", True);
return (True);
}
return (False);
}
static STATE* BINSRCH_Reset2Start()
{
DBG_CHECK_FSM_LIMITS(&bin_search_begin_state);
return &bin_search_begin_state;
}
/* Binary search Start state */
static void
BINSRCH_BeginEnter()
{
unsigned short filled_buffer_length;
#if HAMARO_WIN_DEBUG
unsigned long freq;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -