/*******************************************************************************
|
* File Name : PointTable.h
|
* Description :
|
* Created on : 2019Äê5ÔÂ12ÈÕ
|
* Author : www.hido-studio.com
|
*******************************************************************************/
|
#ifndef _HIDO_FSM_H_
|
#define _HIDO_FSM_H_
|
|
/*******************************************************************************
|
* Include Files *
|
*******************************************************************************/
|
#include "HIDO_TypeDef.h"
|
#include "stdarg.h"
|
|
/*******************************************************************************
|
* Macro *
|
*******************************************************************************/
|
#define HIDO_FSM_DECLARE(name) \
|
extern HIDO_FSMStruct g_stFSM##name /* ÉùÃ÷Ò»¸ö״̬»ú */
|
|
#define HIDO_FSM_STATE_EXTERN(name) \
|
extern const HIDO_StateStruct g_stState##name /* ÉùÃ÷Ò»¸ö״̬ */
|
|
#define HIDO_FSM_DECLARE_IMPLEMENT(name) \
|
HIDO_FSMStruct g_stFSM##name = { HIDO_NULL }; /* ʵÏÖÒ»¸ö״̬»ú */
|
|
#define HIDO_FSM_STATE_DECLARE(name) \
|
extern const HIDO_StateStruct g_stState##name; \
|
HIDO_INT32 name##Proc(HIDO_FSMStruct *_pstFSM, HIDO_UINT32 _u32Event, void *_pArg);
|
/* ÉùÃ÷״̬»úµÄÒ»¸ö״̬,[name]״̬µÄÃû×Ö */
|
|
#define HIDO_FSM_DETACHED_STATE(name) \
|
extern HIDO_StateStruct g_stState##name; \
|
HIDO_INT32 name##Proc(HIDO_FSMStruct *_pstFSM, HIDO_UINT32 _u32Event, void *_pArg);
|
/* ÉùÃ÷״̬»úµÄÒ»¸ö״̬,[name]״̬µÄÃû×Ö */
|
|
#define HIDO_FSM_STATE_FULL_DECLARE(parent, name) HIDO_FSM_STATE_DECLARE(name)
|
|
#define HIDO_FSM_STATE_IMPLEMENT(name, parent, init) \
|
const HIDO_StateStruct g_stState##name = { #name, parent, init, name##Proc }; \
|
HIDO_INT32 name##Proc(HIDO_FSMStruct *_pstFSM, HIDO_UINT32 _u32Event, void *_pArg)
|
/* ʵÏÖÒ»¸ö״̬ */
|
|
#define HIDO_FSM_DETACHED_STATE_IMPLEMENT(name, parent, init) \
|
HIDO_StateStruct g_stState##name = { #name, parent, init, name##Proc }; \
|
HIDO_INT32 name##Proc(HIDO_FSMStruct *_pstFSM, HIDO_UINT32 _u32Event, void *_pArg)
|
/* ʵÏÖÒ»¸ö״̬ */
|
#define HIDO_FSM_DETACHED_STATE_SETTLE(name, parent, init) \
|
g_stState##name.m_pstParent = (parent);\
|
g_stState##name.m_pstInit = (init);
|
/* ¶¯Ì¬ÐÞ¸Ä״̬µÄ¹ØÁª¹ØÏµ£¬ÐÞ¸ÄËüµÄ·ò״̬ºÍ×Ó״̬ */
|
#define HIDO_FSM(name) (&g_stFSM##name)
|
#define HIDO_FSM_STATE(name) (&g_stState##name)
|
|
#define HIDO_EVENT_ENTRY 0 /* ½øÈë״̬µÄʼþ */
|
#define HIDO_EVENT_EXIT 1 /* Í˳ö״̬µÄʼþ */
|
#define HIDO_EVENT_ENTRY_NAME "EVENT_ENTRY" /* ½øÈë״̬µÄʼþÃû×Ö */
|
#define HIDO_EVENT_EXIT_NAME "EVENT_EXIT" /* Í˳ö״̬µÄʼþÃû×Ö */
|
|
#define HIDO_EVENT_OK 0 /* ʼþÖ´ÐÐOK */
|
#define HIDO_EVENT_NO_PROC 1 /* µ±Ç°×´Ì¬²»ÄÜ´¦ÀíÄ¿±êʼþ£¬ÐèÒªÓɸ¸×´Ì¬Íê³É */
|
#define HIDO_STATE_MAX_DEPTH 10 /* ״̬»ú״̬ǶÌ×µÄ×î´óÉî¶È */
|
|
/*******************************************************************************
|
* Type Definition *
|
*******************************************************************************/
|
typedef struct HIDO_StateStruct HIDO_StateStruct;
|
typedef struct HIDO_StateListStruct HIDO_StateListStruct;
|
typedef struct HIDO_FSMStruct HIDO_FSMStruct;
|
typedef struct HIDO_FSMQueueStruct HIDO_FSMQueueStruct;
|
typedef struct HIDO_FSMQueueDataStruct HIDO_FSMQueueDataStruct;
|
|
/* ״̬²ÎÊý */
|
typedef struct
|
{
|
HIDO_VOID *m_pArg; /* Óû§²ÎÊýÖ¸Õë */
|
const HIDO_StateStruct *m_pstAfterState; /* ʼþÖ´ÐÐÍê½øÈëµÄÏÂÒ»¸ö״̬ */
|
} HIDO_StateArgStruct;
|
|
/* ״̬µÄʵÏÖ */
|
typedef HIDO_INT32 (* HIDO_DebugFunc)(HIDO_FSMStruct *_pstStateMachine, HIDO_INT32 _i32Level, HIDO_CHAR *_pcFmt, va_list _ap);
|
typedef HIDO_INT32 (* HIDO_StateFunc)(HIDO_FSMStruct *, HIDO_UINT32, void *);
|
struct HIDO_StateStruct
|
{
|
const char *m_pcName;
|
const HIDO_StateStruct *m_pstParent;
|
const HIDO_StateStruct *m_pstInit;
|
HIDO_StateFunc m_fnProc;
|
};
|
|
/* δʹÓà */
|
struct HIDO_FSMQueueDataStruct
|
{
|
HIDO_UINT32 m_u32Event;
|
void *m_pArg;
|
};
|
|
/* δʹÓà */
|
struct HIDO_FSMQueueStruct
|
{
|
HIDO_UINT32 m_u32Cnt;
|
HIDO_UINT32 m_u32Rear;
|
HIDO_UINT32 m_u32Front;
|
HIDO_UINT32 m_u32Size;
|
HIDO_FSMQueueDataStruct *m_pstBuff;
|
};
|
|
/* ״̬»úµÄʵÏֽṹÌå */
|
struct HIDO_FSMStruct
|
{
|
#define HIDO_FSM_DBG_FLAG_OFF 0 /* ¿ªÈÕÖ¾ */
|
#define HIDO_FSM_DBG_FLAG_ON 1 /* ¹ØÈÕÖ¾ */
|
|
HIDO_UINT16 m_u16ID; /* ״̬»úID δʹÓà */
|
HIDO_UINT16 m_u16DbgFlag; /* ״̬»úµ÷ÊÔ´òÓ¡¿ª¹Ø */
|
const HIDO_StateStruct *m_pstCurrentState; /* ״̬»úµ±Ç°µÄ״̬ */
|
void *m_pPrivateData; /* ״̬»ú˽ÓÐÊý¾Ý */
|
const char *m_pcName; /* ״̬»úÃû×Ö */
|
const char * const*m_ppcEventName; /* ״̬»úʼþÃû×ÖÃû×Ö */
|
HIDO_FSMStruct *m_pstNext; /* δʹÓà */
|
HIDO_FSMQueueStruct m_stEventQueue; /* δʹÓà */
|
HIDO_DebugFunc m_fnDebugFunc;
|
};
|
|
/* δʹÓà */
|
struct HIDO_StateListStruct
|
{
|
const HIDO_StateStruct *m_pstState;
|
HIDO_StateListStruct *m_pstNext;
|
};
|
|
/*******************************************************************************
|
* Global Function *
|
*******************************************************************************/
|
/*******************************************************************************
|
* Function Name : HIDO_FSMEventExecute
|
* Description : ״̬»úÖ´ÐÐÒ»¸öʼþ
|
* Input : _ptStatMachine ״̬»ú½á¹¹ÌåÖ¸Õë
|
* _uEvent ״̬»úµÄʼþ
|
* _pArg ״̬»úÖ´ÐÐʼþʱ´«µÝµÄ²ÎÊý
|
* Output : None
|
* Return : None
|
* Author : www.hido-studio.com
|
* Modified Date: : 2019Äê07ÔÂ15ÈÕ
|
*******************************************************************************/
|
void HIDO_FSMEventExecute(HIDO_FSMStruct *_ptStateMachine, HIDO_UINT32 _uEvent, void *_pArg);
|
|
/*******************************************************************************
|
* Function Name : HIDO_FSMRegister
|
* Description : ״̬»ú×¢²á
|
* Input : _ptStatMachine ״̬»ú½á¹¹ÌåÖ¸Õë
|
* _ptInitState ״̬»úµÄ³õʼ״̬
|
* _pcName ״̬»úµÄÃû×Ö(ÓÃÓÚµ÷ÊÔ´òÓ¡)
|
* _ppcEventName ״̬»úʱ¼äµÄÃû×Ö(ÓÃÓÚµ÷ÊÔ´òÓ¡)
|
* _pPrivateData ״̬»ú˽ÓÐÊý¾Ý,¿ÉÒÔ¸ø×´Ì¬»ú¹ØÁªÒ»¸ö˽ÓÐÊý¾Ý
|
* _u16DbgFlag µ÷ÊÔ¿ª¹Ø HIDO_FSM_DBG_FLAG_OFF=¹Ø HIDO_FSM_DBG_FLAG_ON=¿ª
|
* Output : None
|
* Return : None
|
* Author : www.hido-studio.com
|
* Modified Date: : 2019Äê07ÔÂ15ÈÕ
|
*******************************************************************************/
|
void HIDO_FSMRegister(HIDO_FSMStruct *_ptStatMachine, const HIDO_StateStruct *_ptInitState, const char *_pcName, const char * const*_ppcEventName,
|
void *_pPrivateData, HIDO_UINT16 _u16DbgFlag);
|
|
/*******************************************************************************
|
* Function Name : DB_FSMRegisterDebugFunc
|
* Description :
|
* Input :
|
* Output :
|
* Return :
|
* Author : DuJian
|
* Modified Date: : 2019Äê11ÔÂ18ÈÕ
|
*******************************************************************************/
|
HIDO_INT32 HIDO_FSMRegisterDebugFunc(HIDO_FSMStruct *_pstStatMachine, HIDO_DebugFunc _fnDebugFunc);
|
|
/*******************************************************************************
|
* Function Name : HIDO_FSMStateChange
|
* Description : ״̬»ú×´Ì¬Ç¨ÒÆ½Ó¿Ú
|
* Input : _ptStateMachine ״̬»ú½á¹¹ÌåÖ¸Õë
|
* _ptNewState еÄ״̬(×´Ì¬Ç¨ÒÆµÄÄ¿±ê״̬)
|
* _pData ×´Ì¬Ç¨ÒÆÊ±Ð¯´øµÄÊý¾Ý
|
* Output : None
|
* Return : None
|
* Author : www.hido-studio.com
|
* Modified Date: : 2019Äê07ÔÂ15ÈÕ
|
*******************************************************************************/
|
void HIDO_FSMStateChange(HIDO_FSMStruct *_ptStateMachine, const HIDO_StateStruct *_ptNewState, void *_pData);
|
|
/*******************************************************************************
|
* Function Name : HIDO_FSMStartTimer
|
* Description : ״̬»úÆô¶¯¶¨Ê±Æ÷½Ó¿Ú
|
* Input : _eTimerID ¶¨Ê±Æ÷µÄID
|
* _u8Type ¶¨Ê±Æ÷µÄÀàÐÍ(ͬHIDO_Timer¡£hÖеÄÀàÐÍ)
|
* _uTick ¶¨Ê±Æ÷µÄ¶¨Ê±tick(µ¥Î»ms)
|
* _ptStatMachine ״̬»ú½á¹¹ÌåÖ¸Õë
|
* _uEvent ¶¨Ê±Æ÷³¬Ê±ºó,Ïò״̬»ú·¢Ë͵Äʼþ
|
* Output : None
|
* Return : None
|
* Author : www.hido-studio.com
|
* Modified Date: : 2019Äê07ÔÂ15ÈÕ
|
*******************************************************************************/
|
void HIDO_FSMStartTimer(HIDO_UINT32 _eTimerID, HIDO_UINT8 _u8Type, HIDO_UINT32 _uTick, HIDO_FSMStruct *_ptStatMachine, HIDO_UINT32 _uEvent);
|
|
#endif
|