📄 hamaro_fsm.h
字号:
/* hamaro_fsm.h */
/*+++ *******************************************************************\
*
* Abstract:
*
* Hamaro FSM framework header file.
*
* 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_fsm.h, 5, 2006-10-20 7:01:24, Sunbey (VSS Migration)$
*
* Copyright (c) 2005 Conexant Systems, Inc.
* All rights reserved.
*
\******************************************************************* ---*/
#ifndef _HAMARO_FSM_H_
#define _HAMARO_FSM_H_
#include "hamaro.h"
#if HAMARO_SCAN_THE_SKY
#define FSM_MAX_NUM_CRITERIA 10
/* FSM STATE CODING:
* -----------------
* bit-field assignment:
*----------------------------------------------------------------------------------
* Sub-FSM#3[15:12] | Sub-FSM#2[11:8] | Sub-FSM#1[7:4] | Main FSM[3:0] |
*----------------------------------------------------------------------------------
* Sub-FSM#7[31:28] | Sub-FSM#6[27:24] | Sub-FSM#5[23:20] | Sub-FSM#4[19:16] |
*----------------------------------------------------------------------------------
* Actual FSM mapping:
*----------------------------------------------------------------------------------
* RISE RANGE SUB-FSM | RISE EDGE SUB-FSM | BIN SEARCH SUB-FSM | STS MAIN FSM |
*----------------------------------------------------------------------------------
* POWER SCAN SUB-FSM | SR BIN SUB-FSM | FALL RANGE SUB-FSM | FALL EDGE SUB-FSM |
*----------------------------------------------------------------------------------
*/
#define FSM_IDLE_STATE 0 /* Idle state. Common for all FSMs */
/* Main FSM */
#define STS_RESET_STATE 1 /* Main scan-the-sky FSM */
#define STS_PWRSCAN_STATE 2
#define STS_RISING_EDGE_STATE 3
#define STS_BINARY_SEARCH_STATE 4
#define STS_FALLING_EDGE_STATE 5
#define STS_RESCAN_STATE 6
#define STS_READY_STATE 7
#define STS_SRBIN_STATE 8
#define STS_COMPLETE_STATE 9
/* Sub-FSMs */
#define BINSEARCH_RESET_STATE (1 << 4) /* Binary search for inflection point detection */
#define BINSEARCH_BEGIN_STATE (2 << 4)
#define BINSEARCH_CONVEX_STATE (3 << 4)
#define BINSEARCH_CONCAVE_STATE (4 << 4)
#define BINSEARCH_READY_STATE (5 << 4)
#define RISEEDGE_UPHILL_STATE (1 << 8) /* Rise edge detection */
#define RISEEDGE_DOWNHILL_STATE (2 << 8)
#define RISEEDGE_FLAT_STATE (3 << 8)
#define RISEEDGE_TROUGH_STATE (4 << 8)
#define RISEEDGE_PEAK_STATE (5 << 8)
#define RISEEDGE_UNKNOWN_STATE (6 << 8)
#define RISEEDGE_RESET_STATE (7 << 8)
#define RISEEDGE_READY_STATE (8 << 8)
#define RISERANGE_RESET_STATE (1 << 12) /* Rise range detection */
#define RISERANGE_CONVEX_STATE (2 << 12)
#define RISERANGE_CONCAVE_STATE (3 << 12)
#define RISERANGE_READY_STATE (4 << 12)
#define FALLEDGE_UPHILL_STATE (1 << 16) /* Fall edge detection */
#define FALLEDGE_DOWNHILL_STATE (2 << 16)
#define FALLEDGE_FLAT_STATE (3 << 16)
#define FALLEDGE_TROUGH_STATE (4 << 16)
#define FALLEDGE_PEAK_STATE (5 << 16)
#define FALLEDGE_UNKNOWN_STATE (6 << 16)
#define FALLEDGE_RESET_STATE (7 << 16)
#define FALLEDGE_ABORT_STATE (8 << 16)
#define FALLEDGE_READY_STATE (9 << 16)
#define FALLRANGE_RESET_STATE (1 << 20) /* Fall range detection */
#define FALLRANGE_CONVEX_STATE (2 << 20)
#define FALLRANGE_CONCAVE_STATE (3 << 20)
#define FALLRANGE_PRE_READY_STATE (4 << 20)
#define FALLRANGE_READY_STATE (5 << 20)
#define SRBIN_RESET_STATE (1 << 24) /* Symbol rate binning */
#define SRBIN_NEXT_CHANNEL_STATE (2 << 24)
#define SRBIN_NEXT_BIN_STATE (3 << 24)
#define SRBIN_LOCK_TEST_STATE (4 << 24)
#define SRBIN_CLEANUP_STATE (5 << 24)
#define SRBIN_READY_STATE (6 << 24)
#define PWRSCAN_RESET_STATE (1 << 28) /* Non-blocking Power Scan FSM */
#define PWRSCAN_TUNE_STATE (2 << 28)
#define PWRSCAN_START_STATE (3 << 28)
#define PWRSCAN_STEP_STATE (4 << 28)
#define PWRSCAN_STOP_STATE (5 << 28)
#define PWRSCAN_READY_STATE (6 << 28)
#define PWRSCAN_ABORT_STATE (7 << 28)
/* FSM constants */
#define STS_EDGE_UNKNOWN (unsigned short)(0)
#define STS_EDGE_RISING (unsigned short)(1)
#define STS_EDGE_FALLING (unsigned short)(2)
/* Maximum number of states in the log */
#define STS_MAX_STATE_SEQUENCES 40
/* FSM Data structures */
struct _State;
typedef struct _Criteria
{
BOOL (*condition)(); /* Input parameter can be void/ignored if the state does not use timers */
struct _State *(*exit_task)();
} CRITERIA;
typedef struct _State
{
void (*enter_task)();
CRITERIA criteria[FSM_MAX_NUM_CRITERIA];
void (*regular_task)();
unsigned char counter_type; /* The type of counter to pass to the function condition in criterion. This member is optional */
/* 0 - none */
/* 1 - ticks in msec */
unsigned long coding;
} STATE;
typedef struct _Fsm
{
volatile unsigned long *p_state_code;
unsigned long state_code_mask;
STATE *p_prev;
STATE *p_curr;
unsigned long time_counter; /* This member is optional. See counter_type in STATE struct. */
unsigned long last_time_value; /* This member is optional. See counter_type in STATE struct. */
} FSM;
/* Main FSM functions */
void FSM_Init(FSM *fsm);
void FSM_Poll(FSM *fsm);
/* Helper functions */
BOOL FSM_CheckState(FSM *fsm, unsigned long state);
/*******************************************************************************************************/
/* Debug Macros and functions */
/*******************************************************************************************************/
#if HAMARO_INCLUDE_DEBUG
/* Per state information available for debugging */
typedef struct _fsm_state_sequence
{
unsigned long state; /* state code */
unsigned short time_spent; /* time spent in each state */
} FSM_STATE_SEQUENCE_DATA;
void DEBUG_Init(); /* called once per STS execution */
/* Following functions called once per data point (data collected several times within a state) */
void DEBUG_UpdateTimeSpent(unsigned short time);
void DEBUG_UpdateStateSequence(unsigned long state); /* called once per state transition */
/* Can be called any time to dump (user specific implementation) the captured data */
void DEBUG_DumpStateSequence();
STATE* DEBUG_CheckFSMLimits(STATE* curr_state);
void DEBUG_SetFSMLimits(unsigned long limits);
/* Macros */
#define DBG_INIT() DEBUG_Init(); /* Call this once per scan (STS FSM run) */
#define DBG_SET_CURR_STATE(state) DEBUG_UpdateTimeSpent(state);
#define DBG_UPDATE_STATE_SEQUENCE(s) DEBUG_UpdateStateSequence(s);
#define DBG_DUMP_STATE_SEQUENCE() DEBUG_DumpStateSequence();
#define DBG_SET_FSM_LIMITS(limits) DEBUG_SetFSMLimits(limits);
#define DBG_CHECK_FSM_LIMITS(state) {\
STATE* s;\
s = DEBUG_CheckFSMLimits(state);\
return s;\
}
#else /* HAMARO_INCLUDE_DEBUG */
#define DBG_INIT() /* do nothing */
#define DBG_SET_CURR_STATE(state) /* do nothing */
#define DBG_UPDATE_STATE_SEQUENCE(s) /* do nothing */
#define DBG_DUMP_STATE_SEQUENCE() /* do nothing */
#define DBG_SET_FSM_LIMITS(limits) /* do nothing */
#define DBG_CHECK_FSM_LIMITS(state) /* do nothing */
#endif /* HAMARO_INCLUDE_DEBUG */
/* IDLE state for all FSMs */
extern STATE idle_state;
#endif /* HAMARO_SCAN_THE_SKY */
#endif /* _HAMARO_FSM_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -