📄 hamaro_sts.c
字号:
/* hamaro_sts.c */
/*+++ *******************************************************************\
*
* Abstract:
*
* Hamaro Scan-the-sky Main 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_sts.c, 3, 2005-12-27 1:03:48, Sunbey (VSS Migration)$
*
* Copyright (c) 2005 Conexant Systems, Inc.
* All rights reserved.
*
\******************************************************************* ---*/
#include "hamaro_sts.h"
#if HAMARO_SCAN_THE_SKY
#include "hamaro_binsrch.h"
#include "hamaro_findfall.h"
#include "hamaro_findrise.h"
#include "hamaro_srbin.h"
#include "hamaro_bcd.h"
#include <stdlib.h> /* ANSI Standard */
#define STS_TEST_DO_REG_PROGRAMMING 1
#define STS_ENABLE_REG_IO_TRACE 0
#define STS_ENABLE_SENSE_CHANNEL_TRACE 0
#define STS_DISPLAY_BINARY 0
#define STS_ENABLE_VERBOSE_LOG 0
unsigned long sts_fsm_coding = 0;
/* Instantiate the FSM object(s) */
FSM sts_fsm = {&sts_fsm_coding, 0x0000000F, 0, 0, 0, 0};
static HAMARO_STSDATA hamaro_sts_data;
static HAMARO_STS_POWER_SPECTRUM_DATA s_power_spectrum_data;
static HAMARO_STS_CHANNEL_INFO s_sts_channel_info[STS_MAX_SCAN_CHANNELS];
static unsigned short s_channel_info_index = 0;
static unsigned long s_abs_left_inflection_point_hz, s_abs_right_inflection_point_hz;
static BOOL
STS_FullScan(unsigned long demod_handle,
unsigned char match_filter_clk_mhz,
unsigned short desired_step_size_khz);
static BOOL
STS_Scan(unsigned long demod_handle,
unsigned long tuner_freq_hz,
unsigned char match_filter_clk_mhz,
unsigned short desired_step_size_khz,
unsigned char search_span_mhz);
/* Function prototypes */
/* reset state */
void STS_ResetEnter();
static BOOL STS_Reset2RisingEdgeCriterion(unsigned long);
static STATE* STS_Reset2RisingEdge();
/* rise edge state */
static void STS_RisingEdgeEnter();
static void STS_RisingEdge();
static BOOL STS_RisingEdge2BinarySearchCriterion(unsigned long);
static STATE* STS_RisingEdge2BinarySearch();
static BOOL STS_RisingEdge2RescanCriterion(unsigned long);
static STATE* STS_RisingEdge2Rescan();
/* fall edge state */
static void STS_FallingEdgeEnter();
static void STS_FallingEdge();
static BOOL STS_FallingEdge2BinarySearchCriterion(unsigned long);
static STATE* STS_FallingEdge2BinarySearch();
/* binary search state */
static void STS_BinarySearchEnter();
static BOOL STS_BinarySearch2ReadyCriterion(unsigned long);
static STATE* STS_BinarySearch2Ready();
static BOOL STS_BinarySearch2FallingEdgeCriterion(unsigned long);
static STATE* STS_BinarySearch2FallingEdge();
/* rescan state */
static void STS_RescanEnter();
static BOOL STS_Rescan2ResetCriterion(unsigned long);
static STATE* STS_Rescan2Reset();
/* ready state */
static void STS_ReadyEnter();
static BOOL STS_Ready2ResetCriterion(unsigned long);
static STATE* STS_Ready2Reset();
static BOOL STS_Ready2CompleteCriterion(unsigned long);
static STATE* STS_Ready2Complete();
/* scan complete state */
static void STS_CompleteEnter();
static void STS_Complete();
/*****************************************************************************/
/* State tables */
/*****************************************************************************/
STATE sts_reset_state = /* MAIN STS FSM, RESET state */
{
STS_ResetEnter, /* Entry task */
{
{STS_Reset2RisingEdgeCriterion, STS_Reset2RisingEdge}, /* Criterion1 and Exit task */
{0, 0} /* End of Criterion/Exit task */
},
0, /* Regular task (none) */
0, /* no counter */
STS_RESET_STATE /* state code (first 4 lsb used for main FSM state) */
};
STATE sts_rising_edge_state = /* MAIN STS FSM, RISING EDGE state */
{
STS_RisingEdgeEnter, /* Entry task */
{
{STS_RisingEdge2RescanCriterion, STS_RisingEdge2Rescan}, /* Criterion1 and Exit task */
{STS_RisingEdge2BinarySearchCriterion, STS_RisingEdge2BinarySearch}, /* Criterion2 and Exit task */
{0, 0} /* End of Criterion/Exit task */
},
STS_RisingEdge, /* Regular task */
0, /* no counter */
STS_RISING_EDGE_STATE /* state code (first 4 lsb used for main FSM state) */
};
STATE sts_falling_edge_state = /* MAIN STS FSM, FALLING EDGE state */
{
STS_FallingEdgeEnter, /* Entry task */
{
{STS_FallingEdge2BinarySearchCriterion, STS_FallingEdge2BinarySearch}, /* Criterion2 and Exit task */
{0, 0} /* End of Criterion/Exit task */
},
STS_FallingEdge, /* Regular task */
0, /* no counter */
STS_FALLING_EDGE_STATE /* state code (first 4 lsb used for main FSM state) */
};
STATE sts_binary_search_state = /* MAIN STS FSM, BINARY SEARCH state */
{
STS_BinarySearchEnter, /* Entry task */
{
{STS_BinarySearch2ReadyCriterion, STS_BinarySearch2Ready}, /* Criterion1 and Exit task */
{STS_BinarySearch2FallingEdgeCriterion, STS_BinarySearch2FallingEdge}, /* Criterion2 and Exit task */
{0, 0} /* End of Criterion/Exit task */
},
0, /* Regular task */
0, /* no counter */
STS_BINARY_SEARCH_STATE /* state code (first 4 lsb used for main FSM state) */
};
STATE sts_rescan_state = /* MAIN STS FSM, RESCAN state */
{
STS_RescanEnter, /* Entry task */
{
{STS_Rescan2ResetCriterion, STS_Rescan2Reset},
{0, 0} /* End of Criterion/Exit task */
},
0, /* Regular task */
0, /* no counter */
STS_RESCAN_STATE /* state code (first 4 lsb used for main FSM state) */
};
STATE sts_ready_state = /* MAIN STS FSM, READY state */
{
STS_ReadyEnter, /* Entry task */
{
{STS_Ready2CompleteCriterion, STS_Ready2Complete},
{STS_Ready2ResetCriterion, STS_Ready2Reset},
{0, 0} /* End of Criterion/Exit task */
},
0, /* Regular task */
0, /* no counter */
STS_READY_STATE /* state code (first 4 lsb used for main FSM state) */
};
STATE sts_complete_state = /* MAIN STS FSM, COMPLETE state */
{
STS_CompleteEnter, /* Entry task */
{
{0, 0} /* End of Criterion/Exit task */
},
STS_Complete, /* Regular task */
0, /* no counter */
STS_COMPLETE_STATE /* state code (first 4 lsb used for main FSM state) */
};
/* Function Implementation */
/*****************************************************************************/
/* STS_Start() */
/* MAIN FSM function */
/*****************************************************************************/
static BOOL b_first_channel = True;
void
STS_Start(FSM *fsm)
{
fsm->p_curr = &sts_reset_state;
b_first_channel = True;
memset(&s_sts_channel_info, 0, sizeof(HAMARO_STS_CHANNEL_INFO)*STS_MAX_SCAN_CHANNELS);
s_channel_info_index = 0;
STS_BTLAccumClearSelect(SRBIN_BTL_RESET_WHEN_REACQUIRE);
}
/*****************************************************************************/
/* FSM state functions */
/*****************************************************************************/
/* reset state */
static BOOL b_channel_found = False;
static unsigned long s_symbol_rate_hz;
static unsigned long s_carrier_freq_hz;
static unsigned long STS_GetLastCarrierFreqHz()
{
return s_carrier_freq_hz;
}
/*****************************************************************************/
/* STS_GetStartTunerFreq() */
/* */
/*****************************************************************************/
static unsigned long prev_tuner_freq = 0;
static unsigned long s_freq_start = STS_START_FREQ_HZ;
static BOOL s_rescan = False;
static unsigned long
STS_GetStartTunerFreq()
{
unsigned long local_tuner_freq_hz;
if (b_first_channel == True)
{
local_tuner_freq_hz = s_freq_start;
prev_tuner_freq = s_freq_start;
s_rescan = False;
}
else
{
/* MAKE SURE THE FREQ IS NOT ON DOWNHILL (MUST BE EITHER FLAT OR UPHILL) */
/* Right inflection point + ((beta * SR)/2) */
//tuner_freq_hz = (s_abs_right_inflection_point_hz + ((FALLEDGE_GetJumpStepSize() * 2) * STS_STEP_SIZE_KHZ_MAIN * 1000));
if (s_rescan == True)
{
s_rescan = False;
local_tuner_freq_hz = FINDRISE_GetAbsLeftEdgeFreq();
}
else
{
local_tuner_freq_hz = STS_GetLastCarrierFreqHz() + (STS_GetLastCarrierFreqHz() - FINDRISE_GetAbsLeftEdgeFreq());
}
if (local_tuner_freq_hz < prev_tuner_freq) /* re-start from last */
{
local_tuner_freq_hz = prev_tuner_freq;
}
else
{
prev_tuner_freq = local_tuner_freq_hz;
}
s_carrier_freq_hz = 0;
s_symbol_rate_hz = 0;
}
return local_tuner_freq_hz;
}
/*****************************************************************************/
/* STS_ResetEnter() */
/* */
/*****************************************************************************/
void
STS_ResetEnter()
{
unsigned long tuner_freq_hz;
/* Disable all FSMs */
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(&sr_bin_fsm);
b_channel_found = False;
#if 1
tuner_freq_hz = STS_GetStartTunerFreq();
STSDBG_WR_UNSIGNED_LN("STS_ResetEnter::tuner_freq_hz = ", tuner_freq_hz);
STS_SetUseMainBuffer(True); /* use main buffer */
STS_Scan(0, tuner_freq_hz, STS_MATCH_FILTER_CLK_MAIN, STS_STEP_SIZE_KHZ_MAIN, STS_SEARCH_SPAN_MHZ_MAIN);
STS_LogPowerSpectrum(1);
while (STS_GetMaxRawPowerReading() < 4000)
{
STSDBG_WR_STR("=== DISCARDING THE LAST SET ===", True);
STS_GetLastFreq(&prev_tuner_freq);
STS_Scan(0, prev_tuner_freq, STS_MATCH_FILTER_CLK_MAIN, STS_STEP_SIZE_KHZ_MAIN, STS_SEARCH_SPAN_MHZ_MAIN);
STS_LogPowerSpectrum(1);
}
// STS_LogPowerSpectrum(1);
#else
STS_FullScan(0, STS_MATCH_FILTER_CLK_MAIN, STS_STEP_SIZE_KHZ_MAIN);
#endif
}
/*****************************************************************************/
/* STS_Reset2RisingEdgeCriterion() */
/* */
/*****************************************************************************/
static BOOL
STS_Reset2RisingEdgeCriterion(unsigned long timeout)
{
timeout = 0;
return (True);
}
/*****************************************************************************/
/* STS_Reset2RisingEdge() */
/* */
/*****************************************************************************/
static STATE*
STS_Reset2RisingEdge()
{
//DBG_CHECK_FSM_LIMITS(&sts_ready_state); // Jump to SR BIN FSM.
//return &sts_ready_state;
DBG_CHECK_FSM_LIMITS(&sts_rising_edge_state);
return &sts_rising_edge_state;
}
/* rise edge state */
/*****************************************************************************/
/* STS_RisingEdgeEnter() */
/* */
/*****************************************************************************/
static void
STS_RisingEdgeEnter()
{
s_abs_left_inflection_point_hz = s_abs_right_inflection_point_hz = 0;
FSM_Init(&rise_edge_fsm);
RISEEDGE_Start(&rise_edge_fsm);
STSDBG_WR_STR("STS FSM::RiseEdge FSM is STARTED", True);
}
/*****************************************************************************/
/* STS_RisingEdge() */
/* Routine task */
/*****************************************************************************/
static void
STS_RisingEdge()
{
FSM_Poll(&rise_edge_fsm);
if (FSM_CheckState(&rise_edge_fsm, RISEEDGE_READY_STATE) == True)
{
if (FINDRISE_HasCompleteSpectrum() == True)
{
FSM_Init(&rise_edge_fsm); /* IDLE state */
STSDBG_WR_STR("STS FSM::RiseEdge FSM is DISABLED", True);
FSM_Init(&rise_range_fsm);
STS_SetEdge(STS_EDGE_RISING); // REVISIT : added. Nov 22.
RISERANGE_Start(&rise_range_fsm);
STSDBG_WR_STR("STS FSM::RiseRange FSM is STARTED", True);
s_rescan = False;
}
else
{
FSM_Init(&rise_edge_fsm); /* IDLE state */
s_rescan = True;
}
}
}
static BOOL
STS_RisingEdge2RescanCriterion(unsigned long timeout)
{
timeout = 0;
if (s_rescan == True)
{
return (True);
}
return (False);
}
static STATE*
STS_RisingEdge2Rescan()
{
DBG_CHECK_FSM_LIMITS(&sts_rescan_state);
return &sts_rescan_state;
}
/*****************************************************************************/
/* STS_RisingEdge2BinarySearchCriterion() */
/* */
/*****************************************************************************/
static BOOL
STS_RisingEdge2BinarySearchCriterion(unsigned long timeout)
{
timeout = 0; /* not used */
FSM_Poll(&rise_range_fsm);
if (FSM_CheckState(&rise_range_fsm, RISERANGE_READY_STATE) == True)
{
//STS_SetEdge(STS_EDGE_RISING); // REVISIT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -