📄 hamaro_findfall.c
字号:
/* hamaro_findfall.c */
/*+++ *******************************************************************\
*
* Abstract:
*
* Hamaro find fall edge and find fall range 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_findfall.c, 4, 2006-4-8 0:26:20, ShenWei Wang$
*
* Copyright (c) 2005 Conexant Systems, Inc.
* All rights reserved.
*
\******************************************************************* ---*/
#include "hamaro_findfall.h"
#include "hamaro_findrise.h"
#if HAMARO_SCAN_THE_SKY
#include "hamaro_fsm.h"
#include "hamaro_sts.h"
#if 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 fall_edge_fsm = {&sts_fsm_coding, 0x000F0000, 0, 0, 0, 0};
FSM fall_range_fsm = {&sts_fsm_coding, 0x00F00000, 0, 0, 0, 0};
static HAMARO_STS_CURVATURE_POINTS s_find_fall_range_curvature;
static short s_pattern_delta = STS_PATTERN_TEST_DELTA;
static BOOL s_abort = False;
static BOOL s_step_forward = True;
/*****************************************************************************/
/* FALL EDGE FSM */
/*****************************************************************************/
/* Function prototypes */
/* Fall edge Reset state */
static void FALLEDGE_ResetEnter();
static void FALLEDGE_Reset();
static BOOL FALLEDGE_Reset2AbortCriterion();
static STATE* FALLEDGE_Reset2Abort();
static BOOL FALLEDGE_Reset2FallUphillCriterion();
static STATE* FALLEDGE_Reset2FallUphill();
static BOOL FALLEDGE_Reset2FallHumpCriterion();
static STATE* FALLEDGE_Reset2FallHump();
static BOOL FALLEDGE_Reset2FallDownHillCriterion();
static STATE* FALLEDGE_Reset2FallDownHill();
static BOOL FALLEDGE_Reset2FallTroughCriterion();
static STATE* FALLEDGE_Reset2FallTrough();
static BOOL FALLEDGE_Reset2FallFlatCriterion();
static STATE* FALLEDGE_Reset2FallFlat();
static BOOL FALLEDGE_Reset2FallUnknownCriterion();
static STATE* FALLEDGE_Reset2FallUnknown();
/* Fall edge uphill state */
static void FALLEDGE_Uphill();
static BOOL FALLEDGE_Uphill2RiseReadyCriterion();
static STATE* FALLEDGE_Uphill2RiseReady();
static BOOL FALLEDGE_Uphill2FallHumpCriterion();
static STATE* FALLEDGE_Uphill2FallHump();
static BOOL FALLEDGE_Uphill2FallDownHillCriterion();
static STATE* FALLEDGE_Uphill2FallDownHill();
static BOOL FALLEDGE_Uphill2FallTroughCriterion();
static STATE* FALLEDGE_Uphill2FallTrough();
static BOOL FALLEDGE_Uphill2FallFlatCriterion();
static STATE* FALLEDGE_Uphill2FallFlat();
static BOOL FALLEDGE_Uphill2FallUnknownCriterion();
static STATE* FALLEDGE_Uphill2FallUnknown();
/* Fall edge hump state */
static void FALLEDGE_Hump();
static BOOL FALLEDGE_Hump2FallUphillCriterion();
static STATE* FALLEDGE_Hump2FallUphill();
static BOOL FALLEDGE_Hump2FallDownHillCriterion();
static STATE* FALLEDGE_Hump2FallDownHill();
static BOOL FALLEDGE_Hump2FallTroughCriterion();
static STATE* FALLEDGE_Hump2FallTrough();
static BOOL FALLEDGE_Hump2FallFlatCriterion();
static STATE* FALLEDGE_Hump2FallFlat();
static BOOL FALLEDGE_Hump2FallUnknownCriterion();
static STATE* FALLEDGE_Hump2FallUnknown();
/* Fall edge trough state */
static void FALLEDGE_Trough();
static BOOL FALLEDGE_Trough2FallUphillCriterion();
static STATE* FALLEDGE_Trough2FallUphill();
static BOOL FALLEDGE_Trough2FallHumpCriterion();
static STATE* FALLEDGE_Trough2FallHump();
static BOOL FALLEDGE_Trough2FallDownhillCriterion();
static STATE* FALLEDGE_Trough2FallDownhill();
static BOOL FALLEDGE_Trough2FallFlatCriterion();
static STATE* FALLEDGE_Trough2FallFlat();
static BOOL FALLEDGE_Trough2FallUnknownCriterion();
static STATE* FALLEDGE_Trough2FallUnknown();
/* Fall edge downhill state */
static void FALLEDGE_DownhillEnter();
static BOOL FALLEDGE_Downhill2RiseReadyCriterion();
static STATE* FALLEDGE_Downhill2RiseReady();
/* Rise edge ready state */
static void FALLEDGE_ReadyEnter();
/* Rise edge ready state */
static void FALLEDGE_AbortEnter();
/* Fall edge flat state */
static void FALLEDGE_Flat(); /* Regular task */
static BOOL FALLEDGE_Flat2FallUphillCriterion();
static STATE* FALLEDGE_Flat2FallUphill();
static BOOL FALLEDGE_Flat2FallHumpCriterion();
static STATE* FALLEDGE_Flat2FallHump();
static BOOL FALLEDGE_Flat2FallDownhillCriterion();
static STATE* FALLEDGE_Flat2FallDownhill();
static BOOL FALLEDGE_Flat2FallTroughCriterion();
static STATE* FALLEDGE_Flat2FallTrough();
static BOOL FALLEDGE_Flat2FallUnknownCriterion();
static STATE* FALLEDGE_Flat2FallUnknown();
/* Fall edge unknown state */
static void FALLEDGE_UnknownEnter();
static BOOL FALLEDGE_Unknown2ResetCriterion();
static STATE* FALLEDGE_Unknown2Reset();
/* State tables */
STATE fall_edge_reset_state = /* FIND_FALL_EDGE FSM, RESET state */
{
FALLEDGE_ResetEnter, /* Entry task */
{
{FALLEDGE_Reset2AbortCriterion, FALLEDGE_Reset2Abort}, /* Criterion1 and Exit task */
{FALLEDGE_Reset2FallUphillCriterion, FALLEDGE_Reset2FallUphill},
{FALLEDGE_Reset2FallHumpCriterion, FALLEDGE_Reset2FallHump},
{FALLEDGE_Reset2FallDownHillCriterion, FALLEDGE_Reset2FallDownHill},
{FALLEDGE_Reset2FallTroughCriterion, FALLEDGE_Reset2FallTrough},
{FALLEDGE_Reset2FallFlatCriterion, FALLEDGE_Reset2FallFlat},
{FALLEDGE_Reset2FallUnknownCriterion, FALLEDGE_Reset2FallUnknown},
{0,0} /* End of Criterion/Exit task */
},
FALLEDGE_Reset, /* Regular/Routine task */
0, /* No counter */
FALLEDGE_RESET_STATE /* state code */
};
STATE fall_edge_downhill_state = /* FIND_FALL_EDGE FSM, DOWNHILL state */
{
FALLEDGE_DownhillEnter, /* Entry task */
{
{FALLEDGE_Downhill2RiseReadyCriterion, FALLEDGE_Downhill2RiseReady},
{0,0} /* No Criterion/Exit task */
},
0, /* Regular task */
0,
FALLEDGE_DOWNHILL_STATE
};
STATE fall_edge_ready_state = /* FIND_FALL_EDGE FSM, READY state */
{
FALLEDGE_ReadyEnter, /* Entry task */
{
{0,0} /* No Criterion/Exit task */
},
0, /* Regular task */
0,
FALLEDGE_READY_STATE
};
STATE fall_edge_abort_state = /* FIND_FALL_EDGE FSM, ABORT state */
{
FALLEDGE_AbortEnter, /* Entry task */
{
{0,0} /* No Criterion/Exit task */
},
0, /* Regular task */
0,
FALLEDGE_ABORT_STATE
};
STATE fall_edge_uphill_state = /* FIND_FALL_EDGE FSM, UPHILL state */
{
0, /* Entry task */
{
{FALLEDGE_Uphill2RiseReadyCriterion, FALLEDGE_Uphill2RiseReady},
{FALLEDGE_Uphill2FallHumpCriterion, FALLEDGE_Uphill2FallHump},
{FALLEDGE_Uphill2FallDownHillCriterion, FALLEDGE_Uphill2FallDownHill},
{FALLEDGE_Uphill2FallTroughCriterion, FALLEDGE_Uphill2FallTrough},
{FALLEDGE_Uphill2FallFlatCriterion, FALLEDGE_Uphill2FallFlat},
{FALLEDGE_Uphill2FallUnknownCriterion, FALLEDGE_Uphill2FallUnknown},
{0,0} /* End of Criterion/Exit task */
},
FALLEDGE_Uphill, /* Regular/Routine task */
0, /* No counter */
FALLEDGE_UPHILL_STATE /* state code */
};
STATE fall_edge_hump_state = /* FIND_FALL_EDGE FSM, HUMP state */
{
0, /* Entry task */
{
{FALLEDGE_Hump2FallUphillCriterion, FALLEDGE_Hump2FallUphill}, /* Criterion1 and Exit task */
{FALLEDGE_Hump2FallDownHillCriterion, FALLEDGE_Hump2FallDownHill},/* Criterion2 and Exit task */
{FALLEDGE_Hump2FallTroughCriterion, FALLEDGE_Hump2FallTrough}, /* Criterion3 and Exit task */
{FALLEDGE_Hump2FallFlatCriterion, FALLEDGE_Hump2FallFlat}, /* Criterion4 and Exit task */
{FALLEDGE_Hump2FallUnknownCriterion, FALLEDGE_Hump2FallUnknown}, /* Criterion5 and Exit task */
{0,0} /* No Criterion/Exit task */
},
FALLEDGE_Hump, /* Regular task */
0,
FALLEDGE_HUMP_STATE
};
STATE fall_edge_trough_state = /* FIND_FALL_EDGE FSM, TROUGH state */
{
0, /* Entry task */
{
{FALLEDGE_Trough2FallUphillCriterion, FALLEDGE_Trough2FallUphill}, /* Criterion1 and Exit task */
{FALLEDGE_Trough2FallHumpCriterion, FALLEDGE_Trough2FallHump}, /* Criterion2 and Exit task */
{FALLEDGE_Trough2FallDownhillCriterion, FALLEDGE_Trough2FallDownhill},/* Criterion3 and Exit task */
{FALLEDGE_Trough2FallFlatCriterion, FALLEDGE_Trough2FallFlat}, /* Criterion4 and Exit task */
{FALLEDGE_Trough2FallUnknownCriterion, FALLEDGE_Trough2FallUnknown}, /* Criterion5 and Exit task */
{0,0} /* No Criterion/Exit task */
},
FALLEDGE_Trough, /* Regular task */
0,
FALLEDGE_TROUGH_STATE
};
STATE fall_edge_flat_state = /* FIND_FALL_EDGE FSM, FLAT state */
{
0, /* Entry task */
{
{FALLEDGE_Flat2FallUphillCriterion, FALLEDGE_Flat2FallUphill}, /* Criterion1 and Exit task */
{FALLEDGE_Flat2FallHumpCriterion, FALLEDGE_Flat2FallHump}, /* Criterion2 and Exit task */
{FALLEDGE_Flat2FallDownhillCriterion, FALLEDGE_Flat2FallDownhill},/* Criterion3 and Exit task */
{FALLEDGE_Flat2FallTroughCriterion, FALLEDGE_Flat2FallTrough}, /* Criterion4 and Exit task */
{FALLEDGE_Flat2FallUnknownCriterion, FALLEDGE_Flat2FallUnknown}, /* Criterion5 and Exit task */
{0,0} /* No Criterion/Exit task */
},
FALLEDGE_Flat, /* Regular task */
0,
FALLEDGE_FLAT_STATE
};
STATE fall_edge_unknown_state = /* FIND_FALL_EDGE FSM, UNKNOWN state */
{
FALLEDGE_UnknownEnter, /* Entry task */
{
{FALLEDGE_Unknown2ResetCriterion, FALLEDGE_Unknown2Reset}, /* Criterion1 and Exit task */
{0,0} /* No Criterion/Exit task */
},
0, /* Regular task */
0,
FALLEDGE_UNKNOWN_STATE
};
/*****************************************************************************/
/* FALLEDGE_Start() */
/* Main FSM function */
/*****************************************************************************/
static unsigned short s_jump_step_size;
unsigned short
FALLEDGE_GetJumpStepSize()
{
return s_jump_step_size;
}
/*****************************************************************************/
/* FALLEDGE_Start() */
/* Main FSM function */
/*****************************************************************************/
static unsigned short s_step_size;
void
FALLEDGE_Start(FSM *fsm)
{
s_jump_step_size = 0;
fsm->p_curr = &fall_edge_reset_state;
s_abort = False;
s_step_forward = True;
}
/* Fall edge Reset state */
/*****************************************************************************/
/* FALLEDGE_ResetEnter() */
/* Main FSM function */
/*****************************************************************************/
static HAMARO_STS_PATTERN s_pattern = PATTERN_UNKNOWN;
static void
FALLEDGE_ResetEnter()
{
unsigned short left_concave_point_power;
unsigned short start_index = 0;
unsigned short concave_point_index;
HAMARO_STS_CURVATURE_POINTS* p_curvature_points = 0;
/* USE RISING EDGE CONCAVE POINT POWER AS THRESHOLD FOR DETERMINING THE JUMP INDEX */
p_curvature_points = FINDRISE_GetRiseCurvaturePoints();
concave_point_index = STS_GetIndexFromFreq(p_curvature_points->concave);
left_concave_point_power = STS_GetPowerFromIndex(concave_point_index);
/* REVISIT : Consider moving start_index a few indices back */
if (STS_JumpToPowerLevel(left_concave_point_power, concave_point_index, &start_index) == False)
{
/* Out of buffer */
}
STSDBG_WR_UNSIGNED_LN("[FALLEDGE_ResetEnter] p_curvature_points->concave = ", p_curvature_points->concave);
STSDBG_WR_UNSIGNED_LN("[FALLEDGE_ResetEnter] left_concave_point_power = ", left_concave_point_power);
STSDBG_WR_UNSIGNED_LN("[FALLEDGE_ResetEnter] concave_point_index = ", concave_point_index);
STSDBG_WR_UNSIGNED_LN("[FALLEDGE_ResetEnter] start_index = ", start_index);
if (start_index == 0)
{
s_abort = True;
}
else
{
s_step_size = STS_FINDFALL_DEFAULT_STEP_SIZE;
STS_StartAllOver(s_step_size, start_index);
s_pattern_delta = STS_GetPatternDelta();
}
}
static void
FALLEDGE_Reset()
{
HAMARO_STS_SAMPLE* p_samples;
p_samples = STS_GetSamples();
s_pattern = STS_PatternTest(*p_samples->p_power[0],
*p_samples->p_power[1],
*p_samples->p_power[2],
s_pattern_delta);
}
static BOOL
FALLEDGE_Reset2AbortCriterion()
{
return (s_abort);
}
static STATE*
FALLEDGE_Reset2Abort()
{
DBG_CHECK_FSM_LIMITS(&fall_edge_abort_state);
return &fall_edge_abort_state;
}
static BOOL
FALLEDGE_Reset2FallUphillCriterion()
{
if (s_pattern == PATTERN_UPHILL)
{
return (True);
}
return (False);
}
static STATE*
FALLEDGE_Reset2FallUphill()
{
DBG_CHECK_FSM_LIMITS(&fall_edge_uphill_state);
return &fall_edge_uphill_state;
}
static BOOL
FALLEDGE_Reset2FallHumpCriterion()
{
if (s_pattern == PATTERN_HUMP)
{
return (True);
}
return (False);
}
static STATE*
FALLEDGE_Reset2FallHump()
{
DBG_CHECK_FSM_LIMITS(&fall_edge_hump_state);
return &fall_edge_hump_state;
}
static BOOL
FALLEDGE_Reset2FallDownHillCriterion()
{
if (s_pattern == PATTERN_DOWNHILL)
{
return (True);
}
return (False);
}
static STATE*
FALLEDGE_Reset2FallDownHill()
{
DBG_CHECK_FSM_LIMITS(&fall_edge_downhill_state);
return &fall_edge_downhill_state;
}
static BOOL
FALLEDGE_Reset2FallTroughCriterion()
{
if (s_pattern == PATTERN_TROUGH)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -